Package org.rhq.core.system

Examples of org.rhq.core.system.ProcessExecutionResults


    }

    public OperationResult invoke(@NotNull
    HadoopSupportedOperations operation, Configuration parameters, String serverType) throws InterruptedException {

        ProcessExecutionResults results = null;
        switch (operation) {
        case FORMAT:
            throw new UnsupportedOperationException("This operation requires user interaction.");
            //            results = format(operation);
            //            break;
        case FSCK:
            results = fsck(operation);
            break;
        case LS:
            results = ls(operation);
            break;
        case START:
            results = start(operation, serverType);
            break;
        case STOP:
            results = stop(operation, serverType);
            break;
        case QUEUE_LIST:
            results = queueList(operation);
            break;
        case JOB_LIST_RUNNING:
            results = invokeGeneralOperation(operation);
            break;
        case JOB_LIST_ALL:
            results = invokeGeneralOperation(operation);
            break;
        case REBALANCE_DFS:
            results = invokeGeneralOperation(operation);
            break;
        case KILL:
            results = invokeGeneralOperation(operation, parameters, null);
            break;
        case JAR:
            results = invokeGeneralOperation(operation, parameters, null);
            break;
        default:
            throw new UnsupportedOperationException(operation.toString());
        }

        String message = truncateString(results.getCapturedOutput());
        if (LOG.isDebugEnabled()) {
            LOG.debug("CLI results: exitcode=[" + results.getExitCode() + "]; error=[" + results.getError()
                + "]; output=" + message);
        }

        OperationResult result = new OperationResult(message);
        return result;
View Full Code Here


        }
        processExecution.setWaitForCompletion(wait);
        processExecution.setCaptureOutput(captureOutput);
        processExecution.setKillOnTimeout(killOnTimeout);

        ProcessExecutionResults results = sysInfo.executeProcess(processExecution);

        return results;
    }
View Full Code Here

            for (String paramName : operation.getParamsNames()) {
                args += " " + parameters.getSimpleValue(paramName);
            }
        }

        ProcessExecutionResults results = executeExecutable(resourceContext.getSystemInformation(), executable, args,
            MAX_WAIT, true, operation.isKillOnTimeout());
        return results;
    }
View Full Code Here

                if (executable != null) {
                    String postgresExe = executable.getName();
                    ProcessExecution execution = new ProcessExecution(postgresExe);
                    execution.setArguments(new String[] { "--version" });
                    execution.setCaptureOutput(true);
                    ProcessExecutionResults results = systemInfo.executeProcess(execution);
                    String versionInfo = results.getCapturedOutput();
                    Matcher m = VERSION_FROM_COMMANDLINE.matcher(versionInfo);
                    if (m.find()) {
                        version = versionInfo.substring(m.start(), m.end());
                    } else {
                        LOG.debug("Can't get the process executable - does the agent have the right permissions?");
View Full Code Here

                String arguments = argsRegex.get(METRIC_PROPERTY_ARGUMENTS);
                String regex = argsRegex.get(METRIC_PROPERTY_REGEX);
                boolean valueIsExitCode = METRIC_PROPERTY_EXITCODE.equals(regex);

                // if we already executed it with the same arguments, don't bother doing it again
                ProcessExecutionResults exeResults = exeResultsCache.get((arguments == null) ? "" : arguments);
                if (exeResults == null) {
                    boolean captureOutput = !valueIsExitCode; // don't need output if we need to just check exit code
                    exeResults = executeExecutable(arguments, DEFAULT_MAX_WAIT_TIME, captureOutput);
                    exeResultsCache.put((arguments == null) ? "" : arguments, exeResults);
                }

                // don't report a metric value if the CLI failed to execute
                if (exeResults.getError() != null) {
                    LOG.error("Cannot collect CLI metric [" + metricPropertyName + "]. Cause: "
                        + ThrowableUtil.getAllMessages(exeResults.getError()));
                    continue;
                }

                // set dataValue to the appropriate value based on how the metric property defined it
                if (valueIsExitCode) {
                    dataValue = exeResults.getExitCode();
                    if (dataValue == null) {
                        LOG.error("Could not determine exit code for metric property [" + metricPropertyName
                            + "] - metric will not be collected");
                        continue;
                    }
                } else if (regex != null) {
                    String output = exeResults.getCapturedOutput();
                    if (output == null) {
                        LOG.error("Could not get output for metric property [" + metricPropertyName
                            + "] -- metric will not be collected");
                        continue;
                    } else {
                        output = output.trim();
                    }

                    Pattern pattern = Pattern.compile(regex);
                    Matcher match = pattern.matcher(output);
                    if (match.find()) {
                        if (match.groupCount() > 0) {
                            dataValue = match.group(1);
                        } else {
                            dataValue = output;
                        }
                    } else {
                        LOG.error("Output did not match metric property [" + metricPropertyName
                            + "] - metric will not be collected: " + truncateString(output));
                        continue;
                    }
                } else {
                    dataValue = exeResults.getCapturedOutput();
                    if (dataValue == null) {
                        LOG.error("Could not get output for metric property [" + metricPropertyName
                            + "] - metric will not be collected");
                        continue;
                    }
View Full Code Here

        }

        captureOutput = captureOutputStr == null || Boolean.parseBoolean(captureOutputStr);
        killOnTimeout = killOnTimeoutStr == null || Boolean.parseBoolean(killOnTimeoutStr);

        ProcessExecutionResults exeResults = executeExecutable(arguments, waitTime, captureOutput, killOnTimeout);
        Integer exitcode = exeResults.getExitCode();
        String output = exeResults.getCapturedOutput();
        Throwable error = exeResults.getError();

        if (error != null) {
            result.setErrorMessage(ThrowableUtil.getAllMessages(error));
        }
View Full Code Here

    protected ProcessExecutionResults executeExecutable(String args, long wait, boolean captureOutput,
        boolean killOnTimeout) throws InvalidPluginConfigurationException {

        SystemInfo sysInfo = this.resourceContext.getSystemInformation();
        Configuration pluginConfig = this.resourceContext.getPluginConfiguration();
        ProcessExecutionResults results = executeExecutable(sysInfo, pluginConfig, args, wait, captureOutput,
            killOnTimeout, escapeChar);

        if (LOG.isDebugEnabled()) {
            logDebug("CLI results: exitcode=[" + results.getExitCode() + "]; error=[" + results.getError()
                + "]; output=" + truncateString(results.getCapturedOutput()));
        }

        return results;
    }
View Full Code Here

        }
        processExecution.setCaptureOutput(captureOutput);
        processExecution.setWaitForCompletion(wait);
        processExecution.setKillOnTimeout(killOnTimeout);

        ProcessExecutionResults results = sysInfo.executeProcess(processExecution);

        return results;
    }
View Full Code Here

            return false;
        }

        // if we need to check the exit code or output, execute the CLI now
        if (availExecuteCheck || availExitCodeRegex != null || availOutputRegex != null) {
            ProcessExecutionResults results = executeExecutable(availArgs, 3000L, (availOutputRegex != null));

            // if we get some error while trying to run the executable, immediately consider the resource down
            if (results.getError() != null) {
                if (LOG.isDebugEnabled()) {
                    logDebug("CLI execution encountered an error, resource is considered DOWN: "
                        + ThrowableUtil.getAllMessages(results.getError()));
                }
                return false;
            }

            // if the exit code is used to determine availability, check it now
            if (availExitCodeRegex != null) {
                if (results.getExitCode() == null) {
                    if (LOG.isDebugEnabled()) {
                        logDebug("Cannot get exit code, resource is considered DOWN");
                    }
                    return false;
                }

                boolean exitcodeMatches = results.getExitCode().toString().matches(availExitCodeRegex);
                if (!exitcodeMatches) {
                    if (LOG.isDebugEnabled()) {
                        logDebug("CLI exit code=[" + results.getExitCode() + "] != [" + availExitCodeRegex + "]. DOWN");
                    }
                    return false;
                }
            }

            // if the output is used to determine availability, check it now
            if (availOutputRegex != null) {
                String output = results.getCapturedOutput();
                if (output == null) {
                    output = "";
                } else {
                    output = output.trim();
                }
View Full Code Here

            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
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.