protected void waitForOpenSlot(int maxProcessesOnNode, Reporter reporter) throws IOException, InterruptedException { while (true) { // sleep for a random length of time between 0 and 60 seconds long sleepTime = (long) (Math.random() * 1000 * 60); logger.info("sleeping for " + sleepTime); Thread.sleep(sleepTime); int numRunningMappers = getNumRunningMappers(); logger.info("num running mappers: " + numRunningMappers); if (numRunningMappers < maxProcessesOnNode) return; reporter.progress(); } }
public void addHostKey(byte[] key) throws JSchException { HostKeyRepository hkr = this.jsch.getHostKeyRepository(); HostKey hk = new HostKey(this.host, key); UserInfo userInfo = new MyUserInfo(); hkr.add(hk, userInfo); log.info("hostkey added"); }
protected void setValidationErrorMessage( List<org.kuali.coeus.s2sgen.api.core.AuditError> errors) { if (errors != null) { LOG.info("Error list size:" + errors.size() + errors.toString()); List<org.kuali.rice.krad.util.AuditError> auditErrors = new ArrayList<>(); for (org.kuali.coeus.s2sgen.api.core.AuditError error : errors) { auditErrors.add( new org.kuali.rice.krad.util.AuditError( error.getErrorKey(), Constants.GRANTS_GOV_GENERIC_ERROR_KEY, error.getLink(), new String[] {error.getMessageKey()})); } if (!auditErrors.isEmpty()) { getGlobalVariableService() .getAuditErrorMap() .put( "grantsGovAuditErrors", new AuditCluster( Constants.GRANTS_GOV_OPPORTUNITY_PANEL, auditErrors, Constants.GRANTSGOV_ERRORS)); } } }
public Session getSession(String host, Integer port, String user, Boolean hostKeyChecking) throws JSchException { if (this.session != null) return this.session; this.setHost(host); this.setUser(user); this.session = jsch.getSession(user, host, port); java.util.Properties config = new java.util.Properties(); if (hostKeyChecking) { log.info("strict host key checking enabled"); config.put("StrictHostKeyChecking", "yes"); } else { log.info("strict host key checking disabled"); config.put("StrictHostKeyChecking", "no"); } session.setConfig(config); return session; }
@Override public Result execute() { Folder cur; try { cur = currentResource(); } catch (NotAuthorizedException | BadRequestException ex) { return result("can't lookup current resource", ex); } if (cur == null) { return result("current dir not found: " + currentDir); } String deployUrl = ""; if (cur instanceof Folder) { Folder col = cur; try { if (args.size() == 1) { deployUrl = args.get(0); return deploySimple(deployUrl, col); } else if (args.size() >= 3) { String s = args.get(0); boolean isUnderlay = false; if (s.equals("-underlay")) { isUnderlay = true; args.remove(0); } if (mavenRoot == null || mavenRoot.length() == 0) { return result("Cant deploy maven spec, no maven root has been configred"); } String group = args.get(0); String artifact = args.get(1); String version = args.get(2); deployUrl = mavenRoot + "/" + group.replace(".", "/") + "/" + artifact + "/" + version + "/" + artifact + "-" + version + ".war"; log.info("Built maven URL: " + deployUrl); if (isUnderlay) { UnderlayVector v = new UnderlayVector(); v.setArtifcatId(artifact); v.setGroupId(group); v.setVersion(version); return deployUnderlay(deployUrl, v); } else { return deploySimple(deployUrl, col); } } else { return result( "Invalid number of arguments. Either give single URL or 3 arguments for a maven vector group artifact id"); } } catch (MalformedURLException ex) { return result("Bad url: " + deployUrl); } catch (Exception ex) { return result("Exception deploying: " + deployUrl, ex); } } else { return result("not a collection: " + cur.getHref()); } }
public void createSession(String host, Integer port, String user, Boolean hostKeyChecking) throws JSchException { log.info("creating session"); this.session = this.getSession(host, port, user, hostKeyChecking); }
@Override public Integer call() { int exitstatus = Integer.MAX_VALUE; Boolean useIdentityFile = null; String credentials = null; String userName = nodeCredentials.getUsername(); if (nodeCredentials instanceof LoginCredentialsPassword) { useIdentityFile = false; credentials = ((LoginCredentialsPassword) nodeCredentials).getPassword(); } else if (nodeCredentials instanceof LoginCredentialsPrivateKey) { useIdentityFile = true; credentials = ((LoginCredentialsPrivateKey) nodeCredentials).getKey().getKeyPath(); } ChannelExec c = null; SshClient ssh = null; try { ssh = new SshClient(); ssh.createSession(nodeAddress, userName, false); log.info("connecting with username: "******"connecting using identity file: " + credentials); } else { log.info("connecting using password: "******"executing command: " + command); c.connect(); new Thread( new Runnable() { public void run() { String line; BufferedReader bufferedInputReader = new BufferedReader(new InputStreamReader(is)); try { while ((line = bufferedInputReader.readLine()) != null) { output.append(line); synchronized (timeStamp) { timeStamp = System.currentTimeMillis(); } } } catch (IOException e) { e.printStackTrace(); } } }) .start(); new Thread( new Runnable() { public void run() { String line; BufferedReader bufferedErrorReader = new BufferedReader(new InputStreamReader(err)); try { while ((line = bufferedErrorReader.readLine()) != null) { error.append(line); synchronized (timeStamp) { timeStamp = System.currentTimeMillis(); } } } catch (IOException e) { e.printStackTrace(); } } }) .start(); while (!c.isClosed()) { synchronized (this.timeStamp) { if (System.currentTimeMillis() - this.timeStamp > MAXIMUM_WAITING_TIME_INACTIVITY) { log.warn("command execution seems inactive, canceling!"); break; } } log.info("waiting for command to finish."); try { Thread.sleep(SshClient.DEFAULT_WAITING_TIME_PER_CYCLE); } catch (InterruptedException e) { e.printStackTrace(); } } exitstatus = c.getExitStatus(); } catch (JSchException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (c != null) { c.disconnect(); } if (ssh != null) { try { ssh.disconnectSession(); } catch (JSchException e) { e.printStackTrace(); } } } return exitstatus; }
public ChannelSftp getSftpChannel() throws JSchException { Channel channel = session.openChannel("sftp"); log.info("opening sftp channel"); return (ChannelSftp) channel; }
public ChannelShell getShellChannel() throws JSchException { Channel channel = session.openChannel("shell"); log.info("opening shell channel"); return (ChannelShell) channel; }
public ChannelExec getExecutionChannel() throws JSchException { Channel channel = session.openChannel("exec"); log.info("opening execution channel"); return (ChannelExec) channel; }
public void disconnectSession() throws JSchException { log.info("disconnecting session"); this.session.disconnect(); }
public void setSessionPassword(String pw) { log.info("password set"); this.session.setPassword(pw); }