/** * 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); } }
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); } }
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); }
String versionOutput = results.getCapturedOutput();
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; }
String json = results.getCapturedOutput();
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()
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; }
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); }
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.";
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.");
result.setSimpleResult(results.getCapturedOutput());
return result; case TIMEOUT: result.setErrorMessage("Patch application timed out. Output was: " + results.getCapturedOutput()); return result; case ERROR:
} else if (results.getExitCode() != null && results.getExitCode() != 0) { operationResult.setErrorMessage("Start failed with error code " + results.getExitCode() + ":\n" + results.getCapturedOutput()); } else {