public synchronized void scpThirdParty(String remoteFileSource, String remoteFileTarget) throws SSHApiException { try { if(!session.isConnected()){ session.connect(); } log.info("Transfering from:" + remoteFileSource + " To: " + remoteFileTarget); SSHUtils.scpThirdParty(remoteFileSource, remoteFileTarget, session); } catch (IOException e) { throw new SSHApiException("Failed during scping file:" + remoteFileSource + " to remote file " +remoteFileTarget , e); } catch (JSchException e) { throw new SSHApiException("Failed during scping file:" + remoteFileSource + " to remote file " +remoteFileTarget, e); } }
/** * This method will read standard output and if there's any it will be parsed * * @param jobIDReaderCommandOutput * @param errorMsg * @return * @throws SSHApiException */ private String getOutputifAvailable(StandardOutReader jobIDReaderCommandOutput, String errorMsg, String command) throws SSHApiException { String stdOutputString = jobIDReaderCommandOutput.getStdOutputString(); String stdErrorString = jobIDReaderCommandOutput.getStdErrorString(); log.info("StandardOutput Returned:" + stdOutputString); log.info("StandardError Returned:" +stdErrorString); String[] list = command.split(File.separator); command = list[list.length - 1]; // We are checking for stderr containing the command issued. Thus ignores the verbose logs in stderr. if (stdErrorString != null && stdErrorString.contains(command.trim()) && !stdErrorString.contains("Warning")) { log.error("Standard Error output : " + stdErrorString); throw new SSHApiException(errorMsg + "\n\r StandardOutput: "+ stdOutputString + "\n\r StandardError: "+ stdErrorString); }else if(stdOutputString.contains("error")){ throw new SSHApiException(errorMsg + "\n\r StandardOutput: "+ stdOutputString + "\n\r StandardError: "+ stdErrorString); } return stdOutputString; }
/** * This method will read standard output and if there's any it will be parsed * * @param jobIDReaderCommandOutput * @param errorMsg * @return * @throws SSHApiException */ private String getOutputifAvailable(StandardOutReader jobIDReaderCommandOutput, String errorMsg) throws SSHApiException { String stdOutputString = jobIDReaderCommandOutput.getStdOutputString(); String stdErrorString = jobIDReaderCommandOutput.getStdErrorString(); if (stdOutputString == null || stdOutputString.isEmpty() || (stdErrorString != null && !stdErrorString.isEmpty())) { log.error("Standard Error output : " + stdErrorString); throw new SSHApiException(errorMsg + stdErrorString); } return stdOutputString; }
String error = "System configuration file '" + jobManagerConfiguration.getJobDescriptionTemplateName() + "' not found in the classpath"; throw new SSHApiException(error); FileUtils.writeStringToFile(tempPBSFile, scriptContent); } catch (TransformerConfigurationException e) { throw new SSHApiException("Error parsing PBS transformation", e); } catch (TransformerException e) { throw new SSHApiException("Error generating PBS script", e); } catch (IOException e) { throw new SSHApiException("An exception occurred while connecting to server." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " connecting user name - "
String error = "System configuration file '" + jobManagerTemplate + "' not found in the classpath"; throw new SSHApiException(error);
throw new SSHApiException("Failed during listing directory:" + directoryPath + " to remote file ", e); reconnect(serverInfo, authenticationInfo); if (retry == 0) { throw new SSHApiException("Failed during listing directory :" + directoryPath + " to remote file ", e); throw new SSHApiException("Failed during listing directory :" + directoryPath + " to remote file " + serverInfo.getHost() + ":rFile", e);
retry = 0; } catch (IOException e) { throw new SSHApiException("Failed during creating directory:" + directoryPath + " to remote file " + serverInfo.getHost() + ":rFile", e); } catch (JSchException e) { throw new SSHApiException("Failed during creating directory :" + directoryPath + " to remote file " + serverInfo.getHost() + ":rFile", e); throw new SSHApiException("Failed during creating directory :" + directoryPath + " to remote file " + serverInfo.getHost() + ":rFile", e);
reconnect(serverInfo, authenticationInfo); if (retry == 0) { throw new SSHApiException("Failed during scping local file:" + localFile + " to remote file " + serverInfo.getHost() + ":rFile : " + remoteFile, e); throw new SSHApiException("Failed during scping local file:" + localFile + " to remote file " + serverInfo.getHost() + ":rFile : " + remoteFile, e);
throw new SSHApiException("Failed during listing directory:" + directoryPath + " to remote file ", e); reconnect(serverInfo, authenticationInfo); if (retry == 0) { throw new SSHApiException("Failed during listing directory :" + directoryPath + " to remote file ", e); throw new SSHApiException("Failed during listing directory :" + directoryPath + " to remote file " + serverInfo.getHost() + ":rFile", e);
String error = "System configuration file '" + jobManagerConfiguration.getJobDescriptionTemplateName() + "' not found in the classpath"; throw new SSHApiException(error); throw new SSHApiException("Error parsing PBS transformation", e); } catch (TransformerException e) { throw new SSHApiException("Error generating PBS script", e); } catch (IOException e) { throw new SSHApiException("An exception occurred while connecting to server." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " connecting user name - "
throw new SSHApiException("Failed during scping local file:" + localFile + " to remote file " + serverInfo.getHost() + ":rFile", e); }else{ throw new SSHApiException("Failed during scping local file:" + localFile + " to remote file " + serverInfo.getHost() + ":rFile", e); }else{
String error = "Error Reading input Stream"; log.error(error); throw new SSHApiException(error); String error = "Error Reading input Stream"; log.error(error); throw new SSHApiException(error); String error = "Error Reading input Stream"; log.error(error); throw new SSHApiException(error); String error = "Error Reading input Stream"; log.error(error); throw new SSHApiException(error); throw new SSHApiException(stdOutReader.getStdErrorString());
String error = "Error transfering the file content"; log.error(error); throw new SSHApiException(error); throw new SSHApiException(stdOutReader.getStdErrorString());
session = jsch.getSession(serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort()); } catch (JSchException e) { throw new SSHApiException("An exception occurred while creating SSH session." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " connecting user name - " session.connect(); } catch (JSchException e) { throw new SSHApiException("An exception occurred while connecting to server." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " connecting user name - " String error = "Error Reading input Stream"; log.error(error); throw new SSHApiException(error); String error = "Error Reading input Stream"; log.error(error); throw new SSHApiException(error); String error = "Error Reading input Stream"; log.error(error); throw new SSHApiException(error); String error = "Error Reading input Stream"; log.error(error); throw new SSHApiException(error); throw new SSHApiException(stdOutReader.getStdErrorString());
@Deprecated public synchronized void getJobStatuses(String userName, Map<String,JobStatus> jobIDs)throws SSHApiException { int retry = 3; RawCommandInfo rawCommandInfo = jobManagerConfiguration.getUserBasedMonitorCommand(userName); StandardOutReader stdOutReader = new StandardOutReader(); while (retry > 0){ try { log.info("Executing RawCommand : " + rawCommandInfo.getCommand()); CommandExecutor.executeCommand(rawCommandInfo, this.getSession(), stdOutReader); retry=0; } catch (SSHApiException e) { retry--; try { Thread.sleep(5000); } catch (InterruptedException e1) { log.error(e1.getMessage(), e1); } reconnect(serverInfo, authenticationInfo); if (retry == 0) { throw new SSHApiException("Failed Getting statuses to remote file", e); } } } String result = getOutputifAvailable(stdOutReader, "Error getting job information from the resource !", jobManagerConfiguration.getBaseMonitorCommand()); jobManagerConfiguration.getParser().parseJobStatuses(userName, jobIDs, result); }
throw new SSHApiException("Unable to execute command - ", e); throw new SSHApiException("Unable to retrieve command output. Command - " + command, e);
throw new SSHApiException("Unable to retrieve command output. Command - " + command + " on server - " + session.getHost() + ":" + session.getPort() + " connecting user name - " stdOutReader.getStdOutputString(); if (stdOutReader.getStdErrorString().contains("ls:")) { throw new SSHApiException(stdOutReader.getStdErrorString());
throw new SSHApiException("Unable to retrieve command output. Command - " + command + " on server - " + session.getHost() + ":" + session.getPort() + " connecting user name - " throw new SSHApiException(stdOutReader.getStdErrorString());
this.configReader = new ConfigReader(); } catch (IOException e) { throw new SSHApiException("Unable to load system configurations.", e); throw new SSHApiException("An exception occurred while creating SSH session." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " connecting user name - " identityFile = GSISSHIdentityFile.newInstance(privateKeyFile, null, defaultJSch); } catch (JSchException e) { throw new SSHApiException("An exception occurred while initializing keys using files. " + "(private key and public key)." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + sshPublicKeyAuthentication.getPublicKey(serverInfo.getUserName(), serverInfo.getHost()), defaultJSch); } catch (JSchException e) { throw new SSHApiException("An exception occurred while initializing keys using byte arrays. " + "(private key and public key)." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + session.connect(Integer.parseInt(configReader.getConfiguration(SSH_SESSION_TIMEOUT))); } catch (Exception e) { throw new SSHApiException("An exception occurred while connecting to server." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " connecting user name - "
session = jsch.getSession(serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort()); } catch (JSchException e) { throw new SSHApiException("An exception occurred while creating SSH session." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " connecting user name - " identityFile = GSISSHIdentityFile.newInstance(privateKeyFile, null, jsch); } catch (JSchException e) { throw new SSHApiException("An exception occurred while initializing keys using files. " + "(private key and public key)." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + sshPublicKeyAuthentication.getPublicKey(serverInfo.getUserName(), serverInfo.getHost()), jsch); } catch (JSchException e) { throw new SSHApiException("An exception occurred while initializing keys using byte arrays. " + "(private key and public key)." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + session.connect(); } catch (JSchException e) { throw new SSHApiException("An exception occurred while connecting to server." + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " connecting user name - " throw new SSHApiException("Unable to execute command - " + command + " on server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " connecting user name - " throw new SSHApiException("Unable to retrieve command output. Command - " + command +