Package br.com.objectos.rio.core

Source Code of br.com.objectos.rio.core.WorkstationsRemoteInstall

/*
* WorkstationsRemoteInstall.java criado em 05/01/2014
*
* Propriedade de Objectos Fábrica de Software LTDA.
* Reprodução parcial ou total proibida.
*/
package br.com.objectos.rio.core;

import java.io.InputStream;
import java.util.List;

import br.com.objectos.rio.core.os.Tar;
import br.com.objectos.way.base.io.Directory;
import br.com.objectos.way.ssh.RemoteCommand;
import br.com.objectos.way.ssh.WaySSH;

/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
public class WorkstationsRemoteInstall {

  private final List<Workstation> workstations;

  private final Directory source;

  WorkstationsRemoteInstall(List<Workstation> workstations, Directory source) {
    this.workstations = workstations;
    this.source = source;
  }

  public void to(Directory target) {
    for (Workstation workstation : workstations) {
      InputStream is = Tar.changeTo(source)
          .preserve()
          .add(".")
          .toStdout();

      WaySSH ssh = WaySSH.ssh()
          .toHost(workstation.getName())
          .connect();

      String cmd = String.format("sudo tar xpf - -C %s", target.getAbsolutePath());
      RemoteCommand command = ssh.execute(cmd, is);
      List<Exception> exceptions = command.getExceptions();
      for (Exception exception : exceptions) {
        exception.printStackTrace();
      }

      ssh.disconnect();
    }
  }

}
TOP

Related Classes of br.com.objectos.rio.core.WorkstationsRemoteInstall

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.