private ExecutionResult handleExecutionResults(ProcessExecutionResults results, BundleManagerProvider bmp, BundleResourceDeployment resourceDeployment, boolean doAudit) { ExecutionResult ret = ExecutionResult.OK; if (results.getError() != null) { ret = ExecutionResult.EXECUTION_ERROR; } else if (results.getExitCode() == null) { ret = ExecutionResult.TIMEOUT; } else if (results.getExitCode() != 0) { ret = ExecutionResult.ERROR; } if (doAudit) { audit(bmp, resourceDeployment, "Output", ret == ExecutionResult.OK ? "Standard" : "Error", ret.status(), results.getCapturedOutput()); } return ret; }
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"); }
/** * Logs the result of a process execution. * * @param results the result of a process execution */ public static void logExecutionResults(ProcessExecutionResults results) { // Always log the output at info level. On Unix we could switch depending on a exitCode being !=0, but ... LOG.info("Exit code from process execution: " + results.getExitCode()); LOG.info("Output from process execution: " + SEPARATOR + results.getCapturedOutput() + SEPARATOR); } }
Throwable error = results.getError(); Integer exitCode = results.getExitCode();
/** * Spawns a new process using the Java Runtime API. * * @see SystemInfo#executeProcess(ProcessExecution) */ public ProcessExecutionResults executeProcess(ProcessExecution processExecution) { ProcessToStart process = new ProcessToStart(); ProcessExecutionResults executionResults = new ProcessExecutionResults(); process.setProgramExecutable(processExecution.getExecutable()); process.setCheckExecutableExists(processExecution.isCheckExecutableExists()); process.setArguments(processExecution.getArgumentsAsArray()); process.setEnvironment(processExecution.getEnvironmentVariablesAsArray()); process.setWorkingDirectory(processExecution.getWorkingDirectory()); process.setWaitForExit(Long.valueOf(processExecution.getWaitForCompletion())); process.setCaptureOutput(Boolean.valueOf(processExecution.isCaptureOutput())); process.setKillOnTimeout(Boolean.valueOf(processExecution.isKillOnTimeout())); if (processExecution.isCaptureOutput()) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); process.setOutputStream(outputStream); executionResults.setCapturedOutputStream(outputStream); } ProcessExecutorResults javaExecResults = javaExec.execute(process); executionResults.setExitCode(javaExecResults.getExitCode()); executionResults.setError(javaExecResults.getError()); executionResults.setProcess(javaExecResults.getProcess()); return executionResults; }
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; }
String versionOutput = results.getCapturedOutput();
Throwable error = results.getError(); if (error != null) { return BundleHandoverResponse.failure(EXECUTION, error.getMessage(), error); Integer exitCode = results.getExitCode(); if (exitCode == null) { return BundleHandoverResponse.failure(EXECUTION, "Timeout waiting for completion of the CLI process");
private void logExecutionResults(ProcessExecutionResults results) { if (log.isDebugEnabled()) { log.debug("Exit code from process execution: " + results.getExitCode()); log.debug("Output from process execution: " + SEPARATOR + results.getCapturedOutput() + SEPARATOR); } }
/** * Spawns a new process using the Java Runtime API. * * @see SystemInfo#executeProcess(ProcessExecution) */ public ProcessExecutionResults executeProcess(ProcessExecution processExecution) { ProcessToStart process = new ProcessToStart(); ProcessExecutionResults executionResults = new ProcessExecutionResults(); process.setProgramExecutable(processExecution.getExecutable()); process.setCheckExecutableExists(processExecution.isCheckExecutableExists()); process.setArguments(processExecution.getArgumentsAsArray()); process.setEnvironment(processExecution.getEnvironmentVariablesAsArray()); process.setWorkingDirectory(processExecution.getWorkingDirectory()); process.setWaitForExit(Long.valueOf(processExecution.getWaitForCompletion())); process.setCaptureOutput(Boolean.valueOf(processExecution.getCaptureMode().isCapture())); process.setKillOnTimeout(Boolean.valueOf(processExecution.isKillOnTimeout())); ProcessExecutionOutputStream outputStream = processExecution.getCaptureMode().createOutputStream(); process.setOutputStream(outputStream); executionResults.setCapturedOutputStream(outputStream); ProcessExecutorResults javaExecResults = javaExec.execute(process); executionResults.setExitCode(javaExecResults.getExitCode()); executionResults.setError(javaExecResults.getError()); executionResults.setProcess(javaExecResults.getProcess()); return executionResults; }
private Result<String> getPatchHistoryJSON(ServerControl control, String operation) { ProcessExecutionResults results = control.cli().disconnected(true).executeCliCommand("patch history"); switch (handleExecutionResults(results, null, null, false)) { case EXECUTION_ERROR: return new Result<String>(null, "Failed to determine the patch history while doing a " + operation + ": " + results.getError().getMessage()); case TIMEOUT: return new Result<String>(null, "Timed out while determining patch history for a " + operation + ". Output was: " + results.getCapturedOutput()); case ERROR: return new Result<String>(null, "Failed to determine the patch history for a " + operation + ". Returned error code was: " + results.getExitCode() + "\nOutput was: " + results.getCapturedOutput()); } return new Result<String>(results.getCapturedOutput(), null); }
private String startServer(ASConnection connection, ServerControl control, BundleManagerProvider bmp, BundleResourceDeployment resourceDeployment) { audit(bmp, resourceDeployment, "Start", "Start", null, "Starting the server back up."); ProcessExecutionResults results = control.lifecycle().startServer(); switch (handleExecutionResults(results, bmp, resourceDeployment, false)) { case EXECUTION_ERROR: return "Error trying to start the server. " + results.getError().getMessage(); case ERROR: return "Starting the server failed with error code " + results.getExitCode() + " and output: " + results.getCapturedOutput(); // ignore timeout, because starting the server actually would always be detected as doing it, because the start // script never stops... } try { waitForServerToStart(connection); } catch (InterruptedException e) { String message = "Interrupted while waiting for the server to start up after applying the patch"; Thread.currentThread().interrupt(); return message; } return null; }
private Result<Boolean> stopIfNeeded(ASConnection connection, ServerControl control, Configuration bundleDeploymentConfiguration, BundleManagerProvider bmp, BundleResourceDeployment resourceDeployment) { boolean doRestart = Boolean.valueOf(bundleDeploymentConfiguration.getSimpleValue("restart", "true")); if (doRestart && isServerUp(connection)) { audit(bmp, resourceDeployment, "Stop", "Stop", null, "The server is running. Stopping it before any operation on patches."); ProcessExecutionResults results = control.lifecycle().shutdownServer(); switch (handleExecutionResults(results, bmp, resourceDeployment, true)) { case EXECUTION_ERROR: return new Result<Boolean>(false, "Error trying to shutdown the server: " + results.getError().getMessage()); case TIMEOUT: return new Result<Boolean>(false, "Stopping the server timed out. Captured output: " + results.getCapturedOutput()); case ERROR: return new Result<Boolean>(false, "Stopping the server failed with error code " + results.getExitCode() + " and output: " + results.getCapturedOutput()); } return new Result<Boolean>(true, null); } return new Result<Boolean>(false, null); }
.cli().disconnected(true).executeCliCommand("patch info"); if (results.getError() != null) { LOG.info("Failed to determine the list of installed patches on " + context.getResourceDetails() + ". The execution of JBoss CLI failed.", results.getError()); } else if (results.getExitCode() == null) { LOG.info("Failed to determine the list of installed patches on " + context.getResourceDetails() + ". The execution of JBoss CLI timed out."); } else if (results.getExitCode() != 0) { LOG.info("Failed to determine the list of installed patches on " + context.getResourceDetails() + ". The execution of JBoss CLI exited with code " + results.getExitCode() + "."); String json = results.getCapturedOutput();
Throwable error = results.getError(); Integer exitCode = results.getExitCode(); AvailabilityType avail; String output = results.getCapturedOutput(); String message = "Script returned error or non-zero exit code while starting the Tomcat instance - exitCode=[" + ((exitCode != null) ? exitCode : "UNKNOWN") + "], output=[" + output + "]."; throw new RuntimeException("Server failed to start: " + results.getCapturedOutput()); } else { return "Server has been started.";
logExecutionResults(results); if (results.getError() != null) { operationResult.setErrorMessage(results.getError().getMessage()); } else if (results.getExitCode() != null && results.getExitCode() != 0) { operationResult.setErrorMessage("Start failed with error code " + results.getExitCode() + ":\n" + results.getCapturedOutput()); } else {
case EXECUTION_ERROR: return fullErrorMessage("Error trying to run patch rollback: " + results.getError().getMessage(), pids, i - 1, "rolled back"); case TIMEOUT: return fullErrorMessage("Patch rollback timed out. Captured output: " + results.getCapturedOutput(), pids, i - 1, "rolled back"); case ERROR: return fullErrorMessage("Patch rollback failed with error code " + results.getExitCode() + ".", pids, i - 1, "rolled back");
result.setSimpleResult(results.getCapturedOutput()); if (results.getError() != null) { result.setErrorMessage(results.getError().getMessage()); return result; if (results.getExitCode() == null) { result.setErrorMessage("jboss-cli execution timed out"); return result; if (results.getExitCode() != 0) { result.setErrorMessage("jboss-cli execution failed with error code " + results.getExitCode()); return result;
return Result.error("Failed to check availability of patch command using the 'help --commands' command. The error was: " + results.getError().getMessage()); case ERROR: return Result.error("Failed to check availability of patch command using the 'help --commands' command. The execution failed with an exit code " + results.getExitCode()); case TIMEOUT: return Result.error("Failed to check availability of patch command using the 'help --commands' command. The execution timed out with the output: " + results.getCapturedOutput()); case OK: if (results.getCapturedOutput() == null || !(results.getCapturedOutput().contains(" patch ") || results.getCapturedOutput().contains("\npatch"))) { return Result.error("The underlying server does not support the patch command. Cannot perform the patch operation.");
case EXECUTION_ERROR: result .setErrorMessage("Error while trying to execute patch command: " + results.getError().getMessage()); return result; case TIMEOUT: result.setErrorMessage("Patch application timed out. Output was: " + results.getCapturedOutput()); return result; case ERROR: result.setErrorMessage("Patch application failed with error code " + results.getExitCode() + "."); return result;