Package org.rhq.core.system

Examples of org.rhq.core.system.ProcessExecutionResults


        long timeout = 10000L;
        processExecution.setCaptureOutput(true);
        processExecution.setWaitForCompletion(timeout);
        processExecution.setKillOnTimeout(true);

        ProcessExecutionResults results = systemInfo.executeProcess(processExecution);
        String versionOutput = results.getCapturedOutput();

        String version = getVersionFromVersionScriptOutput(versionOutput);

        if (UNKNOWN_VERSION.equals(version)) {
            LOG.warn("Failed to determine Tomcat Server Version Given:\nVersionInfo:" + versionOutput
View Full Code Here


        BundleDeployResult result = new BundleDeployResult();

        ASConnection connection = new ASConnection(
            ASConnectionParams.createFrom(new ServerPluginConfiguration(request.getReferencedConfiguration())));

        ProcessExecutionResults results;
        BundleManagerProvider bmp = request.getBundleManagerProvider();
        BundleResourceDeployment rd = request.getResourceDeployment();

        Result<Boolean> stop = stopIfNeeded(connection, control,
            request.getResourceDeployment().getBundleDeployment().getConfiguration(), bmp, rd);
        if (stop.failed()) {
            result.setErrorMessage(stop.errorMessage);
            return result;
        }

        boolean startUp = stop.result;

        try {
            StringBuilder command = new StringBuilder("patch apply --path=").append(
                request.getPackageVersionFiles().values().iterator().next().getAbsolutePath());

            Configuration bundleConfig = request.getResourceDeployment().getBundleDeployment().getConfiguration();
            String override = bundleConfig.getSimpleValue("override");
            String overrideAll = bundleConfig.getSimpleValue("override-all");
            String preserve = bundleConfig.getSimpleValue("preserve");
            String overrideModules = bundleConfig.getSimpleValue("override-modules");

            if (override != null) {
                command.append(" --override=").append(override);
            }

            if (overrideAll != null) {
                command.append(" --override-all=").append(Boolean.valueOf(overrideAll));
            }

            if (preserve != null) {
                command.append(" --preserve=").append(preserve);
            }

            if (overrideModules != null) {
                command.append(" --override-modules=").append(overrideModules);
            }

            // as a last thing before the deployment, check the patch history
            Result<List<PatchDetails>> historyBeforeDeployment = getPatchHistory(control, "deploy");
            if (historyBeforeDeployment.failed()) {
                result.setErrorMessage(historyBeforeDeployment.errorMessage);
                return result;
            }

            results = control.cli().disconnected(true).executeCliCommand(command.toString());

            switch (handleExecutionResults(results, bmp, rd, true)) {
            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;
            }

            String errorMessage = storeState(control, request.getResourceDeployment(),
                request.getReferencedConfiguration(), historyBeforeDeployment.result);
View Full Code Here

        if (pids.isEmpty()) {
            return null;
        }

        ProcessExecutionResults results;
        ServerControl.Cli cli = control.cli().disconnected(true);

        Result<List<PatchDetails>> history = getPatchHistory(control, operation);
        if (history.failed()) {
            return history.errorMessage;
        }

        List<PatchDetails> installedPatches = history.result;

        List<String> pidsToRollback = new ArrayList<String>(pids);
        List<String> noLongerRemovablePids = new ArrayList<String>();
        Set<String> installedPids = new HashSet<String>();
        int lastPidToRollback = 0;
        int installedPidIdx = 0;
        for (; installedPidIdx < installedPatches.size() &&
            lastPidToRollback < pidsToRollback.size(); ++installedPidIdx) {

            PatchDetails installed = installedPatches.get(installedPidIdx);
            String pidToRollback = pidsToRollback.get(lastPidToRollback);

            String installedId = installed.getId();

            if (installedId.equals(pidToRollback)) {
                lastPidToRollback++;
            } else {
                while (!installedId.equals(pidToRollback) && lastPidToRollback < pidsToRollback.size()) {
                    pidToRollback = pidsToRollback.get(lastPidToRollback);
                    noLongerRemovablePids.add(pidsToRollback.remove(lastPidToRollback));
                }
                if (installedId.equals(pidToRollback)) {
                    lastPidToRollback++;
                }
            }

            installedPids.add(installedId);
        }

        for (; installedPidIdx < installedPatches.size(); ++installedPidIdx) {
            installedPids.add(installedPatches.get(installedPidIdx).getId());
        }

        // remove pids that we have not seen installed
        if (lastPidToRollback < pidsToRollback.size()) {
            List<String> uninstalledPids = pidsToRollback.subList(lastPidToRollback, pidsToRollback.size());
            noLongerRemovablePids.addAll(uninstalledPids);
            uninstalledPids.clear();
        }

        boolean inconsistent = false;
        for (String pid : noLongerRemovablePids) {
            if (installedPids.contains(pid)) {
                // the current patch state is inconsistent with what we're expecting, because
                // we see pids that are still installed but are no longer on rollback-able positions
                // even though they should.
                // If they're no longer installed then that's actually OK, we'd be rolling them back anyway.
                inconsistent = true;
                break;
            }
        }

        if (pidsToRollback.isEmpty()) {
            if (noLongerRemovablePids.isEmpty()) {
                audit(bmp, rd, "Rollback", "Nothing To Do", BundleResourceDeploymentHistory.Status.WARN,
                    "None of the patches " + pids + " is installed anymore.");

                return null;
            } else {
                String message =  "The following patches were not rolled back due to other patches having been applied in the meantime: " +
                        noLongerRemovablePids + ". No other patches can be rolled back.";

                if (inconsistent) {
                    return message;
                } else {
                    audit(bmp, rd, "Rollback", "Missing patches", BundleResourceDeploymentHistory.Status.WARN,
                        "The following patches were to be rolled back but they aren't installed anymore: " +
                            noLongerRemovablePids + ".");
                }
            }
        }

        Configuration deploymentConfiguration = rd.getBundleDeployment().getConfiguration();

        //if the server is online, let's bring it down for the duration of the rollback.
        Result<Boolean> stop = stopIfNeeded(connection, control, deploymentConfiguration, bmp, rd);
        if (stop.failed()) {
            return stop.errorMessage;
        }

        boolean serverWasUp = stop.result;

        List<String> patchCommands = new ArrayList<String>();
        for (String pid : pidsToRollback) {
            patchCommands.add(PATCH_ROLLBACK_COMMAND + pid);
        }

        String errorMessage = null;

        try {
            int i = 0;
            for (String command : patchCommands) {
                results = cli.executeCliCommand(command);
                switch (handleExecutionResults(results, bmp, rd, true)) {
                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");
                }

                ++i;
            }
View Full Code Here

        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);
        }
View Full Code Here

    }

    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 {
View Full Code Here

        if (supportsPatching.getBooleanValue() == null || !supportsPatching.getBooleanValue()) {
            return Result.error("The target resource does not support patching.");
        }

        ProcessExecutionResults results = serverControl.cli().disconnected(true).executeCliCommand("help --commands");
        switch (handleExecutionResults(results, bmp, resourceDeployment, false)) {
        case EXECUTION_ERROR:
            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.");
            }
            break;
        }
View Full Code Here

        return new Result<List<PatchDetails>>(installedPatches, null);
    }

    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);
    }
View Full Code Here

        exe.setArguments(new String[] { arg });
        exe.setWorkingDirectory(this.launcherScript.getParent());
        exe.setCaptureOutput(true);
        exe.setWaitForCompletion(30000L);
        exe.setEnvironmentVariables(envvars);
        ProcessExecutionResults results = this.resourceContext.getSystemInformation().executeProcess(exe);
        Throwable error = results.getError();
        if (error != null) {
            throw new Exception("Failed to invoke [" + this.launcherScript + ' ' + arg + "]", error);
        }

        HashMap<Integer, String> map = new HashMap<Integer, String>();
        Integer exitCode = results.getExitCode();
        String output = results.getCapturedOutput();
        map.put((exitCode != null) ? exitCode : Integer.valueOf(-1), (output != null) ? output : "");
        return map;
    }
View Full Code Here

                try {
                    Thread.sleep(10000L); // this should be enough to return our operation results back
                    ProcessExecution exe = new ProcessExecution(script.getAbsolutePath());
                    exe.setArguments(new String[] { arg });
                    exe.setWorkingDirectory(script.getParent());
                    ProcessExecutionResults results = sysInfo.executeProcess(exe);
                    if (results != null && results.getError() != null) {
                        throw results.getError();
                    }
                } catch (Throwable t) {
                    log.error("Failed to invoke [" + script + ' ' + arg + "] in a thread", t);
                }
            }
View Full Code Here

        File binDir = new File(deploymentOptions.getBasedir(), "bin");
        SystemInfo systemInfo = SystemInfoFactory.createSystemInfo();

        ProcessExecution processExecution = getProcessExecution(binDir);
        ProcessExecutionResults results = systemInfo.executeProcess(processExecution);

        assertEquals(results.getExitCode(), (Integer) 0, "Cassandra failed to start: " + results.getCapturedOutput());
    }
View Full Code Here

TOP

Related Classes of org.rhq.core.system.ProcessExecutionResults

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.