/** * Executes a sequence of commands on the remote host and block until execution completed. * * @param commands the commands to execute * @return the output to stdout by the commands * @throws IOException if failed to execute command or command exit with non-zero values. */ default String executeAndWait(String... commands) throws IOException { return executeAndWait(Arrays.asList(commands)); }
@Override public String executeAndWait(List<String> commands) throws IOException { return getDelegate().executeAndWait(commands); }
@Override public String executeAndWait(List<String> commands) throws IOException { return getDelegate().executeAndWait(commands); }
@Override public void initializeCluster(ProvisionerContext context, Cluster cluster) throws Exception { // Start the ZK server try (SSHSession session = createSSHSession(context, getMasterExternalIp(cluster))) { LOG.debug("Starting zookeeper server."); String output = session.executeAndWait("sudo zookeeper-server start"); LOG.debug("Zookeeper server started: {}", output); } }
@Override public void initializeCluster(ProvisionerContext context, Cluster cluster) throws Exception { // Start the ZK server try (SSHSession session = createSSHSession(context, getMasterExternalIp(cluster))) { LOG.debug("Starting zookeeper server."); String output = session.executeAndWait("sudo zookeeper-server start"); LOG.debug("Zookeeper server started: {}", output); } }
@Override public void initializeCluster(ProvisionerContext context, Cluster cluster) throws Exception { RemoteHadoopConf conf = RemoteHadoopConf.fromProperties(context.getProperties()); String initializationAction = conf.getInitializationAction(); if (initializationAction != null && !initializationAction.isEmpty()) { try (SSHSession session = createSSHSession(context, getMasterExternalIp(cluster))) { LOG.debug("Initializing action: {}", initializationAction); String output = session.executeAndWait(initializationAction); LOG.debug("Initialization action completed: {}", output); } } }
session.executeAndWait("mkdir -p " + localizedDir); LOG.debug("Expanding archive {} on host {} to {}", localizedFile, session.getAddress().getHostName(), expandedDir); session.executeAndWait( "mkdir -p " + expandedDir, "cd " + expandedDir, LOG.debug("Create hardlink {} on host {} to {}/{}", localizedFile, session.getAddress().getHostName(), targetPath, localFile.getName()); session.executeAndWait(String.format("ln %s %s/%s", localizedFile, targetPath, localFile.getName()));
session.executeAndWait("mkdir -p " + localizedDir); LOG.debug("Expanding archive {} on host {} to {}", localizedFile, session.getAddress().getHostName(), expandedDir); session.executeAndWait( "mkdir -p " + expandedDir, "cd " + expandedDir, LOG.debug("Create hardlink {} on host {} to {}/{}", localizedFile, session.getAddress().getHostName(), targetPath, localFile.getName()); session.executeAndWait(String.format("ln %s %s/%s", localizedFile, targetPath, localFile.getName()));
RetryStrategies.fixDelay(200, TimeUnit.MILLISECONDS)); int port = Retries.callWithRetries(() -> { String json = session.executeAndWait("cat " + programRunId.getRun() + "/" + cConf.get(Constants.RuntimeMonitor.SERVER_INFO_FILE)); RuntimeMonitorServerInfo info = GSON.fromJson(json, RuntimeMonitorServerInfo.class);
RetryStrategies.fixDelay(200, TimeUnit.MILLISECONDS)); int port = Retries.callWithRetries(() -> { String json = session.executeAndWait("cat " + programRunId.getRun() + "/" + cConf.get(Constants.RuntimeMonitor.SERVER_INFO_FILE)); RuntimeMonitorServerInfo info = GSON.fromJson(json, RuntimeMonitorServerInfo.class);
String targetPath = session.executeAndWait("mkdir -p ./" + programRunId.getRun(), "echo `pwd`/" + programRunId.getRun()).trim(); session.executeAndWait(String.format("bash %s/%s/%s %s/%s/%s > %s/%s", targetPath, Constants.Files.RUNTIME_CONFIG_JAR, SETUP_SPARK_SH, targetPath, Constants.Files.RUNTIME_CONFIG_JAR, SETUP_SPARK_PY, session.executeAndWait(targetPath + "/launcher.sh");
String targetPath = session.executeAndWait("mkdir -p ./" + programRunId.getRun(), "echo `pwd`/" + programRunId.getRun()).trim(); session.executeAndWait(String.format("bash %s/%s/%s %s/%s/%s > %s/%s", targetPath, Constants.Files.RUNTIME_CONFIG_JAR, SETUP_SPARK_SH, targetPath, Constants.Files.RUNTIME_CONFIG_JAR, SETUP_SPARK_PY, session.executeAndWait(targetPath + "/launcher.sh");
@Test public void testSsh() throws Exception { SSHConfig config = getSSHConfig(); try (SSHSession session = new DefaultSSHSession(config)) { for (int i = 0; i < 10; i++) { String msg = "Sending some message " + i; String result = session.executeAndWait(msg); Assert.assertEquals(msg, result); } } // Test the error exit try (SSHSession session = new DefaultSSHSession(config)) { try { session.executeAndWait("failure"); Assert.fail("Expected failure from ssh command"); } catch (Exception e) { // Expected } } }