@Override public void addScript(String exe, List<String> exeArgs) { super.addScript(exe, exeArgs); File scriptFile = new File(this.baseWorkingDirectory, exe); ensureExecutable(scriptFile); ProcessExecution pe = new ProcessExecution(scriptFile.getAbsolutePath()); pe.setArguments(exeArgs); pe.setWaitForCompletion(30 * 60 * 1000L); pe.setWorkingDirectory(scriptFile.getParent()); String msg; ProcessExecutionResults results = this.systemInfo.executeProcess(pe); if (results.getError() != null) { msg = "Could not execute script [" + pe + "]: " + results; audit("script", BundleResourceDeploymentHistory.Status.FAILURE, msg); throw new RuntimeException(msg, results.getError()); } else { msg = "Executed script [" + pe + "]"; audit("script", BundleResourceDeploymentHistory.Status.SUCCESS, msg); } return; }
private ProcessExecutionResults startNode(File basedir) { if (log.isDebugEnabled()) { log.debug("Starting node at " + basedir); } File binDir = new File(basedir, "bin"); File startScript; SystemInfo systemInfo = SystemInfoFactory.createSystemInfo(); ProcessExecution startScriptExe; if (systemInfo.getOperatingSystemType() == OperatingSystemType.WINDOWS) { startScript = new File(binDir, "cassandra.bat"); startScriptExe = createProcessExecution(null, startScript); } else { startScript = new File(binDir, "cassandra"); startScriptExe = createProcessExecution(null, startScript); startScriptExe.addArguments(Arrays.asList("-p", "cassandra.pid")); } startScriptExe.setWaitForCompletion(0); ProcessExecutionResults results = systemInfo.executeProcess(startScriptExe); if (log.isDebugEnabled()) { log.debug(startScript + " returned with exit code [" + results.getExitCode() + "]"); } return results; }
public OperationResult invokeOperation(String name, Configuration params) throws Exception { if (name.equals(EXECUTE_OPERATION)) { OperationResult operationResult = new OperationResult(); File scriptFile = getScriptFile(); SystemInfo systemInfo = this.resourceContext.getSystemInformation(); ProcessExecution processExecution = ProcessExecutionUtility.createProcessExecution(scriptFile); processExecution.setWaitForCompletion(1000L * 60 * 60); // 1 hour processExecution.setCaptureOutput(true); // TODO: Make the script's cwd configurable, but default it to the // directory containing the script. processExecution.setWorkingDirectory(scriptFile.getParent()); setEnvironmentVariables(processExecution); setCommandLineArguments(params, processExecution); if (log.isDebugEnabled()) { log.debug(processExecution); } ProcessExecutionResults processExecutionResults = systemInfo.executeProcess(processExecution); if (processExecutionResults.getError() != null) { throw new Exception(processExecutionResults.getError()); } Integer exitCode = processExecutionResults.getExitCode(); String output = processExecutionResults.getCapturedOutput(); // NOTE: // this // is // stdout // + // stderr Configuration complexResults = operationResult.getComplexResults(); complexResults.put(new PropertySimple(EXIT_CODE_RESULT_PROP, exitCode)); complexResults.put(new PropertySimple(OUTPUT_RESULT_PROP, output)); if (exitCode != null && exitCode != 0) { operationResult.setErrorMessage( "Exit code was '" + exitCode + "', see operation results for details"); } return operationResult; } else { throw new IllegalArgumentException("Unsupported operation: " + name); } }
public void startCluster(List<Integer> nodeIds) { if (log.isDebugEnabled()) { log.debug("Starting embedded cluster for nodes " + collectionToString(nodeIds)); } else { log.info("Starting embedded cluster"); } long start = System.currentTimeMillis(); File basedir = new File(deploymentOptions.getClusterDir()); for (Integer nodeId : nodeIds) { File nodeDir = new File(basedir, "node" + nodeId); ProcessExecutionResults results = startNode(nodeDir); if (results.getError() != null) { log.warn( "An unexpected error occurred while starting the node at " + nodeDir, results.getError()); } else { nodeProcessMap.put(nodeId, results.getProcess()); } } long end = System.currentTimeMillis(); log.info("Started embedded cluster in " + (end - start) + " ms"); }
@Override public void addCommand(String exe, List<String> exeArgs) { super.addCommand(exe, exeArgs); ProcessExecution pe = new ProcessExecution(exe); pe.setArguments(exeArgs); pe.setWaitForCompletion(30 * 60 * 1000L); pe.setCheckExecutableExists(false); pe.setWorkingDirectory(this.baseWorkingDirectory); String msg; ProcessExecutionResults results = this.systemInfo.executeProcess(pe); if (results.getError() != null) { msg = "Could not execute command [" + pe + "]: " + results; audit("command", BundleResourceDeploymentHistory.Status.FAILURE, msg); throw new RuntimeException(msg, results.getError()); } else { msg = "Executed command [" + pe + "]"; audit("command", BundleResourceDeploymentHistory.Status.SUCCESS, msg); } return; }
@Override public void addDeployFile(String filename, String directory) { super.addDeployFile(filename, directory); String msg; File existingFile = new File(this.baseWorkingDirectory, filename); ProcessExecution pe = getUnzipExecution(existingFile, directory); if (pe != null) { ProcessExecutionResults results = this.systemInfo.executeProcess(pe); if (results.getError() != null) { msg = "Could not unbundle file [" + pe + "]: " + results; audit("deploy", BundleResourceDeploymentHistory.Status.FAILURE, msg); throw new RuntimeException(msg, results.getError()); } else if (results.getExitCode() == null || results.getExitCode().intValue() > 0) { msg = "Failed to unbundle file [" + pe + "]: " + results; audit("deploy", BundleResourceDeploymentHistory.Status.FAILURE, msg); throw new RuntimeException(msg); } else { msg = "extracted files from [" + existingFile + "] to [" + directory + "]"; } // existingFile.delete(); WOULD WE WANT TO REMOVE THE COMPRESSED FILE? audit("deploy", BundleResourceDeploymentHistory.Status.SUCCESS, msg); } else { // not a zipped format - just move the file to the directory as-is File newFile = new File(directory, filename); if (!existingFile.renameTo(newFile)) { msg = "Failed to move [" + existingFile + "] to [" + newFile + "]"; audit("deploy", BundleResourceDeploymentHistory.Status.FAILURE, msg); throw new RuntimeException(msg); } audit( "deploy", BundleResourceDeploymentHistory.Status.SUCCESS, "renamed [" + existingFile + "] to [" + newFile + "]"); } }