Package org.rhq.core.system

Examples of org.rhq.core.system.ProcessExecutionResults


        // Make sure rpm is actually on the system
        ProcessExecution processExecution = new ProcessExecution("/usr/bin/which");
        processExecution.setArguments(new String[] { "rpm" });
        processExecution.setCaptureOutput(true);

        ProcessExecutionResults executionResults = systemInfo.executeProcess(processExecution);
        String capturedOutput = executionResults.getCapturedOutput();

        rpmExecutable = (((capturedOutput == null) || "".equals(capturedOutput)) ? null : capturedOutput.trim());
    }
View Full Code Here


         */
        ProcessExecution listRpmsProcess = new ProcessExecution(rpmExecutable);
        listRpmsProcess.setArguments(new String[] { "-qa" });
        listRpmsProcess.setCaptureOutput(true);

        ProcessExecutionResults executionResults = systemInfo.executeProcess(listRpmsProcess);
        String capturedOutput = executionResults.getCapturedOutput();

        // Process the resulting output
        if (capturedOutput == null) {
            return packages;
        }

        BufferedReader rpmNameReader = new BufferedReader(new StringReader(capturedOutput));

        String rpmName;

        while ((rpmName = rpmNameReader.readLine()) != null) {
            String name = null;
            String version = null;
            String architectureName = null;

            try {

                // Execute RPM query for each RPM
                ProcessExecution rpmQuery = new ProcessExecution(rpmExecutable);
                rpmQuery
                    .setArguments(new String[] {
                        "-q",
                        "--qf",
                        "%{NAME}\\n%{VERSION}.%{RELEASE}\\n%{ARCH}\\n%{INSTALLTIME}\\n%{FILEMD5S}\\n%{GROUP}\\n%{FILENAMES}\\n%{SIZE}\\n%{LICENSE}\\n%{DESCRIPTION}",
                        rpmName });
                rpmQuery.setCaptureOutput(true);

                ProcessExecutionResults rpmDataResults = systemInfo.executeProcess(rpmQuery);
                String rpmData = rpmDataResults.getCapturedOutput();

                BufferedReader rpmDataReader = new BufferedReader(new StringReader(rpmData));

                name = rpmDataReader.readLine();
                version = rpmDataReader.readLine();
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

        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 + "]";
View Full Code Here

        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);
        }

View Full Code Here

        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);
        }

View Full Code Here

        long start = System.currentTimeMillis();
        if (log.isDebugEnabled()) {
            log.debug("About to execute the following process: [" + processExecution + "]");
        }
        ProcessExecutionResults results = this.systemInfo.executeProcess(processExecution);
        logExecutionResults(results);

        AvailabilityType avail;
        if (results.getError() == null) {
            avail = waitForServerToStart(start);
        } else {
            log.error("Error from process execution while starting the AS instance. Exit code ["
                + results.getExitCode() + "]", results.getError());
            avail = this.serverComponent.getAvailability();
        }

        // If, after the loop, the Server is still down, consider the start to be a failure.
        if (avail == AvailabilityType.DOWN) {
            throw new RuntimeException("Server failed to start: " + results.getCapturedOutput());
        } else {
            return "Server has been started.";
        }
    }
View Full Code Here

        processExecution.getEnvironmentVariables().put("NOPAUSE", "1");

        if (log.isDebugEnabled()) {
            log.debug("About to execute the following process: [" + processExecution + "]");
        }
        ProcessExecutionResults results = this.systemInfo.executeProcess(processExecution);
        logExecutionResults(results);

        if (results.getError() != null) {
            throw new RuntimeException("Error executing shutdown script while stopping AS instance. Exit code ["
                + results.getExitCode() + "]", results.getError());
        }

        return "Server has been shut down.";
    }
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.