Examples of SSHCommand


Examples of com.alu.e3.installer.command.SSHCommand

    long bytesCollected = 0L;
    String ipAddress = logSource.getInternalIP();
    if(logger.isDebugEnabled()) {
      logger.debug("trying to connect to {} via ssh ...", ipAddress);
    }
    SSHCommand sshCommand = new SSHCommand();
    sshCommand.connect(logDestination.getSSHKey(), ipAddress, 22, logSource.getUser(), logSource.getPassword(), sshSessionTimeout);         
   
    // Start with E3Appender Java logs first
    // Get a local copy of the logging config file to determine log-file path
    String remoteLogPath = null;
    File localConfigFile = new File(instanceCollectionDir, "java-logging.cfg");
    String localConfigFilePath = localConfigFile.getAbsolutePath();
    if (copyRemoteConfigFile(sshCommand, localConfigFilePath, LogFileSource.JAVA)) {
      remoteLogPath = LoggingUtil.getLogFilePathFromConfigFile(localConfigFilePath, LogFileSource.JAVA, false)
    } else {
      logger.warn("Couldn't retrieve E3 Java logging config file from host {}, will try default path", ipAddress);     
    }
    if ((remoteLogPath == null) || (remoteLogPath.length() == 0)) {
      // If we can't find a logging config file with an E3Appender section,
      // look anyway in the usual servicemix log directory for any log files with the default name
      logger.warn("Instance at {} is not using E3Appender (check log-config file: {})", ipAddress, LoggingUtil.defaultConfigPath);
      remoteLogPath = LoggingUtil.defaultLogPath;
    }
    File localTargetDir = createLocalLogTargetDir(instanceCollectionDir, LogFileSource.JAVA);
    if (localTargetDir == null) {
      logger.warn("Couldn't create log-collection directory: {}", instanceCollectionDir + File.separator + LogFileSource.JAVA.toString());
    } else {
      File remoteLog = new File(remoteLogPath);
      List<FileInfo> logList = getMatchingRemoteFileList(sshCommand, remoteLog.getParent(), remoteLog.getName());
      for (FileInfo remoteFileInfo : logList) {
        File localCopy = new File(localTargetDir, targetNameForLogFile(remoteFileInfo, localTargetDir));
        try {
          bytesCollected += copyRemoteFileWithWorkingTemp(sshCommand, remoteFileInfo, localCopy.getAbsolutePath(), deleteAfterCollect);
        } catch (Exception ex) {
          // Continue copy attempts if we experience an error
          logger.warn("Failed to copy remote file: {} ({})", remoteFileInfo.filePath, ex.getLocalizedMessage());
        }
      } 
    }
   
    // Now try to get the remote serviceMix log files
    // We use the same log-config file as the java logs to parse the path
    remoteLogPath = LoggingUtil.getLogFilePathFromConfigFile(localConfigFilePath, LogFileSource.SMX, false);
    localConfigFile.delete()// no longer needed
    if ((remoteLogPath == null) || (remoteLogPath.length() == 0)) {
      // If we can't find a logging config file with the proper appender section,
      // look anyway in the usual servicemix log directory for any log files with the default name
      logger.warn("Instance at {} is not using expected appender for servicemix rootLogger (check log-config file: {})", ipAddress, LoggingUtil.defaultConfigPath);
      remoteLogPath = LoggingUtil.defaultSMXLogPath;
    }
    localTargetDir = createLocalLogTargetDir(instanceCollectionDir, LogFileSource.SMX);
    if (localTargetDir == null) {
      logger.warn("Couldn't create log-collection directory: {}", instanceCollectionDir + File.separator + LogFileSource.SMX.toString());
    } else {
      File remoteLog = new File(remoteLogPath);
      List<FileInfo> logList = getMatchingRemoteFileList(sshCommand, remoteLog.getParent(), remoteLog.getName());
      for (FileInfo remoteFileInfo : logList) {
        File localCopy = new File(localTargetDir, targetNameForLogFile(remoteFileInfo, localTargetDir));
        try {
          bytesCollected += copyRemoteFileWithWorkingTemp(sshCommand, remoteFileInfo, localCopy.getAbsolutePath(), deleteAfterCollect);
        } catch (Exception ex) {
          // Continue copy attempts if we experience an error
          logger.warn("Failed to copy remote file: {} ({})", remoteFileInfo.filePath, ex.getLocalizedMessage());
        }
      }
    }
   
    // Collect the E3-specific syslog files
    // For syslog we parse the rsyslog config file for the log-file path
    localConfigFile = new File(instanceCollectionDir, "syslog.cfg");
    localConfigFilePath = localConfigFile.getAbsolutePath();
    if (copyRemoteConfigFile(sshCommand, localConfigFilePath, LogFileSource.SYSLOG)) {
      remoteLogPath = NonJavaLogger.getLogFilePathFromConfigFile(localConfigFilePath);
      localConfigFile.delete()
    } else {
      logger.warn("Couldn't retrieve E3 syslog config file from host {}", ipAddress);     
    }
    if ((remoteLogPath == null) || (remoteLogPath.length() == 0)) {
      // Try default path
      remoteLogPath = NonJavaLogger.defaultLogFilePath;
      logger.warn("Instance at {} does not specify an E3-specific syslog file, trying default: {}", ipAddress, remoteLogPath);
    }
    localTargetDir = createLocalLogTargetDir(instanceCollectionDir, LogFileSource.SYSLOG);
    if (localTargetDir == null) {
      logger.warn("Couldn't create log-collection directory: {}", instanceCollectionDir + File.separator + LogFileSource.SYSLOG.toString());
    } else {
      File remoteLog = new File(remoteLogPath);
      List<FileInfo> logList = getMatchingRemoteFileList(sshCommand, remoteLog.getParent(), remoteLog.getName());
      for (FileInfo remoteFileInfo : logList) {
        File localCopy = new File(localTargetDir, targetNameForLogFile(remoteFileInfo, localTargetDir));
        try {
          bytesCollected += copyRemoteFileWithWorkingTemp(sshCommand, remoteFileInfo, localCopy.getAbsolutePath(), deleteAfterCollect);
        } catch (Exception ex) {
          // Continue copy attempts if we experience an error
          logger.warn("Failed to copy remote file: {} ({})", remoteFileInfo.filePath, ex.getLocalizedMessage());
        }
      }
    }
   
    // We're done - disconnect and return number of bytes copied
    sshCommand.disconnect();
    if(logger.isDebugEnabled()) {
      logger.debug("connected/disconnected!");
    }
    return bytesCollected;
  }
View Full Code Here

Examples of com.alu.e3.installer.command.SSHCommand

    // First, try to open a new SSH session to instance
    // Note: use TRACE-level logging here since our output may appear in retrieved log lines
    String ipAddress = logSource.getInternalIP();
    logger.trace("trying to connect to {} via ssh ...", ipAddress);
   
    SSHCommand sshCommand = new SSHCommand();
    sshCommand.connect(logDestination.getSSHKey(), ipAddress, 22, logSource.getUser(), logSource.getPassword(), sshSessionTimeout);         

    // Start with E3Appender Java log first
    // Get a local copy of the logging config file to determine log-file path
    String remoteLogPath = null;
    File localConfigFile = File.createTempFile("java-logging", ".cfg");
View Full Code Here

Examples of com.alu.e3.installer.command.SSHCommand

                    logger.debug("using key: " + key.getName());
                  }
                }
               
                /* Connect via ssh. */
                SSHCommand sshCommand = (SSHCommand) cmd;
                sshCommand.connect(key, localizedGatewayIP, 22, instance.getUser(), instance.getPassword());
               
                if (!sshCommand.isConnected())
                {
                  String errorSshMsg = "Error: ssh connection to " + localizedGatewayIP+  " failed (sshkey=";
                  errorSshMsg += (key == null) ? "not defined " : key.getName();
                  errorSshMsg += "user=" + instance.getUser() + ")";
                  throw new InstallerDeployException(errorSshMsg);
                }
               
                if(logger.isDebugEnabled()) {
                  logger.debug("command type: " + cmd.getImplementationType());
                }
               
                /* check if the destination directory already exists. */
                ShellCommandResult dirExistResult = cmd.execShellCommand("ls "+ config.getRemotePath() + "/bin/install.sh");
                if (dirExistResult.getExitStatus() != 0)
                {
                  /* Create the destination directory */
                  ShellCommandResult dirCreateResult = cmd.execShellCommand("mkdir -p -m 755 "+ config.getRemotePath());
                  if (dirCreateResult.getExitStatus() != 0)
                  {
                    throw new InstallerDeployException("Unable to create remote destination directory "+ config.getRemotePath() + ".");
                  }
               
                  /* Remote copy the package. */
                  if(logger.isDebugEnabled()) {
                    logger.debug("package url: " + config.getPackageUrl());
                  }
                  URL urlPackage = new URL(config.getPackageUrl());
                  String strFilename;
                  if (urlPackage.getProtocol().equals("file"))
                  {
                    strFilename = new File(urlPackage.getFile()).getName();
                    cmd.copy(urlPackage.getFile(), config.getRemotePath() + "/" + strFilename);
                   
                  } else {
                    /* TODO: handle HTTP package URL ? */
                    if(logger.isDebugEnabled()) {
                      logger.debug("URL type " + urlPackage.getProtocol() + " is not supported yet.");
                    }
                    continue;
                  }
               
                  /* Unzip TODO: instaler filename and install location in config */
                  ShellCommandResult cmdRes = cmd.execShellCommand("tar xfz " + strFilename, config.getRemotePath());
                  if (cmdRes.getExitStatus() != 0)
                  {
                    /* unzip has failed, display output. TODO: handle failure */
                    throw new InstallerDeployException("Unzip archive" + strFilename + " failed (returned code: "+ cmdRes + ")");
                  }
                } else{
                  // version already installed in the gateway                 
                  if(logger.isErrorEnabled()) {
                    logger.error("WARNING: " + config.getRemotePath() + " already exist on gateway " + localizedGatewayIP);
                  }
                 
                  report.append("WARNING: " + config.getRemotePath() + " already exist on gateway " + localizedGatewayIP + ". " +
                      "Be carefull this existing binary was used. Remove it first to use the new binary content !!! \n");

                }
               
                String fullyQualifiedInstallerCmd = replaceManagerIPPattern(config.getInstallerCmd(), managerIP);
                if(logger.isDebugEnabled()) {
                  logger.debug("Executing shell command '" + fullyQualifiedInstallerCmd + "'");
                }
               
                /* Launch Install. */
                ShellCommandResult cmdResInstallation = cmd.execShellCommand(fullyQualifiedInstallerCmd, config.getRemotePath());
                if (cmdResInstallation.getExitStatus() != 0)
                {
                  /* remote installation has failed, display output. */
                  throw new InstallerDeployException("Installation has failed while executing command [" + fullyQualifiedInstallerCmd + "]\ndetails:"+ cmdResInstallation);
                }
                 
                /* Launch sanity check. */
                ShellCommandResult cmdResSanityCheck = cmd.execShellCommand(config.getSanityCheckCmd(), config.getRemotePath());
                if (cmdResSanityCheck.getExitStatus() != 0)
                {
                  /* remote installation has failed, display output. TODO: handle failure */
                  throw new InstallerDeployException("Sanity check has failed  while executing command ["+ config.getSanityCheckCmd() + "] in the folder [" + config.getRemotePath() + "]\nDetails:"+ cmdResSanityCheck);
                }
              }
              else { // Local
                //if ("E3Gateway".equals(instance.getType())) {
               
                String generateNatureCmd = config.getGenerateNatureCmd();
                if (generateNatureCmd != null && !generateNatureCmd.isEmpty())
                {
               
                  String fullyQualifiedGenerateNatureCmd = replaceManagerIPPattern(generateNatureCmd, managerIP);
                  if(logger.isDebugEnabled()) {
                    logger.debug("Executing shell command '" + fullyQualifiedGenerateNatureCmd + "'");
                  }
                 
                  /* Get the ssh key. TODO: handle case without sshkey (eg. if user/password provided) */
                  SSHKey key = instance.getSSHKey();
                  if (key != null) {
                    if(logger.isDebugEnabled()) {
                      logger.debug("using key: " + key.getName());
                    }
                  }
                  /* Connect via ssh. */
                  SSHCommand sshCommand = (SSHCommand) cmd;
                  sshCommand.connect(key, localizedGatewayIP, 22, instance.getUser(), instance.getPassword());
                 
                  if (!sshCommand.isConnected())
                  {
                    String errorSshMsg = "Error: ssh connection to" + localizedGatewayIP+  " failed (sshkey=";
                    errorSshMsg += (key == null) ? "not defined " : key.getName();
                    errorSshMsg += "user=" + instance.getUser() + ")";
                    throw new InstallerDeployException(errorSshMsg);
View Full Code Here

Examples of com.consol.citrus.ssh.SshCommand

        }

        // Setup endpoint adapter
        sshd.setCommandFactory(new CommandFactory() {
            public Command createCommand(String command) {
                return new SshCommand(command, getEndpointAdapter());
            }
        });

        try {
            sshd.start();
View Full Code Here

Examples of io.fathom.cloud.compute.scheduler.SshCommand

            // TODO: Make suid?
            cmd = "sudo /usr/sbin/applyd";
        }

        try {
            SshCommand sshCommand = new SshCommand(sshConfig, cmd);
            sshCommand.run();
        } catch (IOException e) {
            throw new CloudException("Error applying applyd configuration", e);
        }
    }
View Full Code Here

Examples of org.apache.hive.ptest.execution.ssh.SSHCommand

        for(final NodeMetadata node : hosts) {
          executorService.submit(new Runnable() {
            @Override
            public void run() {
              String ip = publicIpOrHostname(node);
              SSHCommand command = new SSHCommand(mSSHCommandExecutor, mPrivateKey, mUser, ip, 0, "pkill -f java");
              mSSHCommandExecutor.execute(command);
              if(command.getExitCode() == Constants.EXIT_CODE_UNKNOWN ||
                  command.getException() != null) {
                LOG.error("Node " + node + " is bad on startup", command.getException());
                terminateInternal(node);
              } else {
                result.add(node);
              }
            }
View Full Code Here

Examples of org.apache.hive.ptest.execution.ssh.SSHCommand

        templateVariables);
    Templates.writeTemplateResult("batch-exec.vm", script, templateVariables);
    copyToDroneFromLocal(drone, script.getAbsolutePath(), "$localDir/$instanceName/scratch/" + scriptName);
    script.delete();
    mLogger.info(drone + " executing " + batch + " with " + command);
    RemoteCommandResult sshResult = new SSHCommand(mSSHCommandExecutor, drone.getPrivateKey(), drone.getUser(),
        drone.getHost(), drone.getInstance(), command).
        call();
    File batchLogDir = null;
    if(sshResult.getExitCode() == Constants.EXIT_CODE_UNKNOWN) {
      throw new AbortDroneException("Drone " + drone.toString() + " exited with " +
View Full Code Here

Examples of org.apache.hive.ptest.execution.ssh.SSHCommand

        for(final Drone drone : ImmutableList.copyOf(mDrones)) {
          Map<String, String> templateVariables = Maps.newHashMap(mTemplateDefaults);
          templateVariables.put("instanceName", drone.getInstanceName());
          templateVariables.put("localDir", drone.getLocalDirectory());
          String command = Templates.getTemplateResult(cmd, templateVariables);
          SSHResult result = new SSHCommand(mSSHCommandExecutor, drone.getPrivateKey(), drone.getUser(),
              drone.getHost(), drone.getInstance(), command).call();
          if(result.getExitCode() == Constants.EXIT_CODE_UNKNOWN) {
            mDrones.remove(drone); // return value not checked due to concurrent access
            mLogger.error("Aborting drone during exec " + command,
                new AbortDroneException("Drone " + drone + " exited with "
View Full Code Here

Examples of org.apache.hive.ptest.execution.ssh.SSHCommand

        public RemoteCommandResult call() throws Exception {
          Map<String, String> templateVariables = Maps.newHashMap(mTemplateDefaults);
          templateVariables.put("instanceName", drone.getInstanceName());
          templateVariables.put("localDir", drone.getLocalDirectory());
          String command = Templates.getTemplateResult(cmd, templateVariables);
          SSHResult result = new SSHCommand(mSSHCommandExecutor, drone.getPrivateKey(), drone.getUser(),
              drone.getHost(), drone.getInstance(), command).call();
          if(result.getExitCode() != Constants.EXIT_CODE_SUCCESS) {
            mDrones.remove(drone); // return value not checked due to concurrent access
            mLogger.error("Aborting drone during exec " + command,
                new AbortDroneException("Drone " + drone + " exited with "
View Full Code Here

Examples of org.apache.hive.ptest.execution.ssh.SSHCommand

      try {
        for(final NodeMetadata node : hosts) {
          executorService.submit(new Runnable() {
            @Override
            public void run() {
              SSHCommand command = new SSHCommand(mSSHCommandExecutor, mPrivateKey, mUser, node.getHostname(), 0, "pkill -f java");
              mSSHCommandExecutor.execute(command);
              if(command.getExitCode() == Constants.EXIT_CODE_UNKNOWN ||
                  command.getException() != null) {
                LOG.error("Node " + node + " is bad on startup", command.getException());
                terminateInternal(node);
              } else {
                result.add(node);
              }
            }
View Full Code Here
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.