public LoginCredentials build() { if (identity == null && password == null && privateKey == null && !authenticateSudo) return null; return new LoginCredentials(identity, password, privateKey, authenticateSudo); } }
public LoginCredentials build() { if (identity == null && password == null && privateKey == null && !authenticateSudo) return null; return new LoginCredentials(identity, password, privateKey, authenticateSudo); } }
public LoginCredentials build() { if (identity == null && password == null && privateKey == null && !authenticateSudo) return null; return new LoginCredentials(identity, password, privateKey, authenticateSudo); } }
public LoginCredentials build() { if (identity == null && !password.isPresent() && !privateKey.isPresent() && !authenticateSudo) return null; return new LoginCredentials(identity, password, privateKey, authenticateSudo); } }
public LoginCredentials build() { if (identity == null && !password.isPresent() && !privateKey.isPresent() && !authenticateSudo) return null; return new LoginCredentials(identity, password, privateKey, authenticateSudo); } }
public LoginCredentials build() { if (identity == null && !password.isPresent() && !privateKey.isPresent() && !authenticateSudo) return null; return new LoginCredentials(identity, password, privateKey, authenticateSudo); } }
/** * Execute a command on a group of nodes * @param group name of the group * @param command the command to be executed * @param login username * @param key sshkey * @throws RunScriptOnNodesException */ public void execCommandInGroup(String group, String command, String login, String key) throws RunScriptOnNodesException{ journal.log(Level.INFO, ">> executing command..."); journal.log(Level.INFO, ">> "+ command); try { String contentKey=FileUtils.readFileToString(new File(key)); Map<? extends NodeMetadata, ExecResponse> responses = compute.runScriptOnNodesMatching( runningInGroup(group), exec(command), overrideLoginCredentials(new LoginCredentials(login, null, contentKey, false)) .runAsRoot(false) .wrapInInitScript(false));// run command directly for(Entry<? extends NodeMetadata, ExecResponse> r : responses.entrySet()) journal.log(Level.INFO, ">> "+r.getValue()); } catch (IOException e) { journal.log(Level.SEVERE, ">> Unable to find key file - check your path!"); } }
/** * Execute a command on a specified node * @param id id of the node * @param command the command to be executed * @param login username * @param keyPath sshkey for connection */ public void execCommand(String id, String command, String login, String key){ journal.log(Level.INFO, ">> executing command..."); journal.log(Level.INFO, ">> "+ command); try { String contentKey=FileUtils.readFileToString(new File(key)); ExecResponse response = compute.runScriptOnNode( id, exec(command), overrideLoginCredentials(new LoginCredentials(login, null, contentKey, false)) .runAsRoot(false) .wrapInInitScript(false));// run command directly journal.log(Level.INFO, ">> "+response.getOutput()); } catch (IOException e) { journal.log(Level.SEVERE, ">> Unable to find key file - check your path!"); } }
/** * Upload a file on a selected node * @param sourcePath path to the file to be uploaded * @param destinationPath path to the file to be created * @param nodeId Id of a node * @param login user login * @param key key to connect */ public void uploadFile(String sourcePath, String destinationPath, String nodeId, String login, String key){ try { String contentKey=FileUtils.readFileToString(new File(key)); SshClient ssh = compute.getContext().getUtils().sshForNode().apply(NodeMetadataBuilder.fromNodeMetadata(getNodeById(nodeId)).credentials(new LoginCredentials(login, null, contentKey, true)).build()); try { ssh.connect(); ssh.put(destinationPath, Payloads.newPayload(new File(sourcePath))); } finally { if (ssh != null) ssh.disconnect(); journal.log(Level.INFO, ">> File uploaded!"); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }