Package org.rhq.core.pluginapi.operation

Examples of org.rhq.core.pluginapi.operation.OperationResult


    }

    private OperationResult invokeSimpleOperation(String action) {
        Operation op = new Operation(action, getAddress());
        Result res = getASConnection().execute(op);
        OperationResult result = new OperationResult();
        if (res.isSuccess()) {
            result.setSimpleResult("Success");
            if ("enable".equals(action)) {
                context.getAvailabilityContext().enable();
            }
            if ("disable".equals(action)) {
                context.getAvailabilityContext().disable();
            }
        } else {
            result.setErrorMessage(res.getFailureDescription());
        }

        return result;
    }
View Full Code Here


     * @throws RuntimeException
     *             if any errors occur while trying to perform the operation
     */
    public OperationResult invoke(ApplicationServerSupportedOperations operation, Configuration parameters)
        throws InterruptedException {
        OperationResult result = null;

        switch (operation) {
        case START: {
            result = start();
            break;
View Full Code Here

     *             executing
     */
    private OperationResult start() throws InterruptedException {
        AvailabilityType avail = this.serverComponent.getAvailability();
        if (avail == AvailabilityType.UP) {
            OperationResult result = new OperationResult();
            result.setErrorMessage("The server is already started.");
            return result;
        }
        Configuration pluginConfig = serverComponent.getResourceContext().getPluginConfiguration();
        StartScriptConfiguration startScriptConfig = new StartScriptConfiguration(pluginConfig);
        File startScriptFile = getStartScriptPath(startScriptConfig);
        validateScriptFile(startScriptFile, ApplicationServerPluginConfigurationProperties.START_SCRIPT_CONFIG_PROP);

        // The optional command prefix (e.g. sudo or nohup).
        String prefix = pluginConfig
            .getSimpleValue(ApplicationServerPluginConfigurationProperties.SCRIPT_PREFIX_CONFIG_PROP, null);
        if ((prefix != null) && prefix.replaceAll("\\s", "").equals("")) {
            // all whitespace - normalize to null
            prefix = null;
        }

        ProcessExecution processExecution = ProcessExecutionUtility.createProcessExecution(prefix, startScriptFile);
        addProcessExecutionArguments(processExecution, startScriptFile, startScriptConfig, false);

        // processExecution is initialized to the current process' env.  This isn't really right, it's the
        // rhq agent env.  Override this if the startScriptEnv property has been set.
        Map<String, String> startScriptEnv = startScriptConfig.getStartScriptEnv();
        if (!startScriptEnv.isEmpty()) {
            for (String envVarName : startScriptEnv.keySet()) {
                String envVarValue = startScriptEnv.get(envVarName);
                // TODO: If we migrate the AS7 util to a general util then hook it up
                // envVarValue = replacePropertyPatterns(envVarValue);
                startScriptEnv.put(envVarName, envVarValue);
            }
            processExecution.setEnvironmentVariables(startScriptEnv);
        } else {
            // set JAVA_HOME to the value of the deprecated 'javaHome' plugin config prop.
            setJavaHomeEnvironmentVariable(processExecution);
        }

        // perform any init common for start and shutdown scripts
        initProcessExecution(processExecution, startScriptFile);

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

        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.
        OperationResult result;
        if (avail == AvailabilityType.DOWN) {
            result = new OperationResult();
            result.setErrorMessage("The server failed to start: " + results.getCapturedOutput());
        } else {
            result = new OperationResult("The server has been started.");
        }
        return result;
    }
View Full Code Here

        } catch (ExecutionFailedException e) {
            errorMessage = e.getMessage();
        }

        AvailabilityType avail = waitForServerToShutdown();
        OperationResult result;
        if (avail == AvailabilityType.UP) {
            result = new OperationResult();
            result.setErrorMessage("The server failed to shut down.");
        } else {
            result = new OperationResult();
            result.setSimpleResult(resultMessage);
            result.setErrorMessage(errorMessage);
        }

        return result;
    }
View Full Code Here

     *
     * @return A success message on success
     */
    private OperationResult restart() {
        try {
            OperationResult result = shutDown();
            if (result.getErrorMessage() != null) {
                return result;
            }
        } catch (Exception e) {
            throw new RuntimeException("Shutdown may have failed: " + e);
        }

        try {
            OperationResult result = start();
            if (result.getErrorMessage() != null) {
                return result;
            }
        } catch (Exception e) {
            throw new RuntimeException("Start following shutdown may have failed: " + e);
        }

        return new OperationResult("Server has been restarted.");
    }
View Full Code Here

    static String DYNAMIC_PROVIDER = ",dynamic-load-provider=configuration";

    @Override
    public OperationResult invokeOperation(String name, Configuration parameters) throws Exception {
        Operation op = new Operation(name, getAddress());
        OperationResult operationResult = new OperationResult();
        Result result = null;

        String modClusterKeyMesg = "Modcluster resource keys are not in correct format.";
        modClusterKeyMesg += " Should be {modcluster address}:{jvmRoute}:{virtual-host}:{context} but instead ";
        modClusterKeyMesg += " was '" + key + "'";

        if ("list-proxies".equals(name)) {
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                ArrayList container = (ArrayList) result.getResult();
                if ((container != null) && !container.isEmpty()) {
                    Object type = container.get(0);
                    String values = "";
                    if (type instanceof String) {
                        for (int i = 0; i < container.size(); i++) {
                            values += container.get(i) + ",";
                        }
                        values = values.substring(0, values.length() - 1);
                    } else {
                        values = container.toString();
                    }
                    operationResult.getComplexResults().put(new PropertySimple("proxy-list", values));

                } else {//return empty value.
                    operationResult.getComplexResults().put(new PropertySimple("proxy-list", ""));
                }
            }
        } else if ("add-proxy".equals(name)) {
            addAdditionalToOp(op, parameters, "host", false);
            addAdditionalToOp(op, parameters, "port", false);
            result = getASConnection().execute(op);
            if (result != null && result.isSuccess()) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("remove-proxy".equals(name)) {
            addAdditionalToOp(op, parameters, "host", false);
            addAdditionalToOp(op, parameters, "port", false);
            result = getASConnection().execute(op);
            if (result != null && result.isSuccess()) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("disable-context".equals(name)) {//disable handled by base case
            //update the operation components with details from the resource being operated on.
            //Ex. {modcluster address}:{jvmRoute}:{virtual-host}:{context}
            String[] keyComponents = key.split(":");
            if (keyComponents.length == 4) {
                op.addAdditionalProperty("virtualhost", keyComponents[2]);
                op.addAdditionalProperty("context", keyComponents[3]);
                result = getASConnection().execute(op);
                if ((result != null) && (result.isSuccess())) {
                    operationResult.setSimpleResult("Success");
                }
            } else {
                operationResult.setErrorMessage(modClusterKeyMesg);
                return operationResult;
            }
        } else if ("enable-context".equals(name)) {//enable handled by base case
            String currentAddress = getAddress().getPath();
            //update the operation components with details from the resource being operated on.
            //Ex. {modcluster address}:{jvmRoute}:{virtual-host}:{context}
            String[] keyComponents = key.split(":");
            if (keyComponents.length == 4) {
                op.addAdditionalProperty("virtualhost", keyComponents[2]);
                op.addAdditionalProperty("context", keyComponents[3]);
                result = getASConnection().execute(op);
                if ((result != null) && (result.isSuccess())) {
                    operationResult.setSimpleResult("Success");
                }
            } else {
                operationResult.setErrorMessage(modClusterKeyMesg);
                return operationResult;
            }
        } else if ("stop-context".equals(name)) {
            String currentAddress = getAddress().getPath();
            //Ex. {modcluster address}:{jvmRoute}:{virtual-host}:{context}
            String[] keyComponents = key.split(":");
            if (keyComponents.length == 4) {
                op.addAdditionalProperty("virtualhost", keyComponents[2]);
                op.addAdditionalProperty("context", keyComponents[3]);
                addAdditionalToOp(op, parameters, "waittime", true);
                result = getASConnection().execute(op);
                if ((result != null) && (result.isSuccess())) {
                    operationResult.setSimpleResult("Success");
                }
            } else {
                operationResult.setErrorMessage(modClusterKeyMesg);
                return operationResult;
            }
        } else if ("add-custom-metric".equals(name)) {
            //update the address and operation name. Use class name as identifier.
            String newOperationDestination = getAddress().getPath() + DYNAMIC_PROVIDER
                + ",custom-load-metric,custom-load-metric=" + retrieveNewIdentifier(parameters, "class");
            op = new Operation("add", new Address(newOperationDestination));
            addAdditionalToOp(op, parameters, "class", false);
            addAdditionalToOp(op, parameters, "weight", false);
            addAdditionalToOp(op, parameters, "capacity", true);
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("remove-custom-metric".equals(name)) {
            //update the address and operation name. Use class name as identifier.
            String newOperationDestination = getAddress().getPath() + DYNAMIC_PROVIDER
                + ",custom-load-metric,custom-load-metric=" + retrieveNewIdentifier(parameters, "class");
            op = new Operation("remove", new Address(newOperationDestination));
            addAdditionalToOp(op, parameters, "class", false);
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("add-metric".equals(name)) {
            //update the address and operation name. Use class name as identifier.
            String newOperationDestination = getAddress().getPath() + DYNAMIC_PROVIDER
                + ",custom-load-metric,load-metric=" + retrieveNewIdentifier(parameters, "type");
            op = new Operation("add", new Address(newOperationDestination));
            addAdditionalToOp(op, parameters, "weight", false);
            addAdditionalToOp(op, parameters, "capacity", true);
            addAdditionalToOp(op, parameters, "type", false);
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("remove-metric".equals(name)) {
            //update the address and operation name. Use class name as identifier.
            String newOperationDestination = getAddress().getPath() + DYNAMIC_PROVIDER
                + ",custom-load-metric,load-metric=" + retrieveNewIdentifier(parameters, "type");
            op = new Operation("remove", new Address(newOperationDestination));
            addAdditionalToOp(op, parameters, "type", false);
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("read-proxies-configuration".equals(name)) {
            //spinder 3/25/12: Can we do better than displaying all content as massive string?
            //                 Content is unstructured/variable from httpd server.
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                ArrayList container = (ArrayList) result.getResult();
                if ((container != null) && !container.isEmpty()) {
                    Object type = container.get(0);
                    String values = "";
                    if (type instanceof String) {
                        for (int i = 0; i < container.size(); i++) {
                            values += container.get(i) + ",";
                        }
                        values = values.substring(0, values.length() - 1);
                    } else {
                        values = container.toString();
                    }
                    operationResult.getComplexResults().put(new PropertySimple("current-proxy-config", values));

                } else {//return empty value.
                    operationResult.getComplexResults().put(new PropertySimple("current-proxy-config", ""));
                }
            }
        } else if ("read-proxies-info".equals(name)) {
            //spinder 3/25/12: Can we do better than displaying all content as massive string?
            //                 Content is unstructured/variable from httpd server.
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                ArrayList container = (ArrayList) result.getResult();
                if ((container != null) && !container.isEmpty()) {
                    Object type = container.get(0);
                    String values = "";
                    if (type instanceof String) {
                        for (int i = 0; i < container.size(); i++) {
                            values += container.get(i) + ",";
                        }
                        values = values.substring(0, values.length() - 1);
                    } else {
                        values = container.toString();
                    }
                    operationResult.getComplexResults().put(new PropertySimple("current-proxy-info", values));

                } else {//return empty value.
                    operationResult.getComplexResults().put(new PropertySimple("current-proxy-info", ""));
                }
            }
        } else {
            /*
             * This is a catch all for operations that are not explicitly treated above.
             */
            result = getASConnection().execute(op);
            if (result.isSuccess()) {
                operationResult.setSimpleResult("Success");
            }
        }

        if (!result.isSuccess()) {
            operationResult.setErrorMessage(result.getFailureDescription());
        }

        return operationResult;
    }
View Full Code Here

    @Override
    public OperationResult invokeOperation(String name,
                                           Configuration parameters) throws InterruptedException, Exception {

        OperationResult result = new OperationResult();

        Operation operation;
        if (name.equals("jndi-view")) {
            Address address = new Address(path);
            operation = new Operation("jndi-view",address);
            Result res = getASConnection().execute(operation);

            if (!res.isSuccess()) {
                result.setErrorMessage(res.getFailureDescription());
                return result;
            }

            Configuration config = result.getComplexResults();

            Map<String,Map> contexts = (Map<String, Map>) res.getResult();

            String entryName = "java: contexts";
            Map<String,Map> javaContexts = contexts.get(entryName);
View Full Code Here

            String dataFilesChangedString = config.getSimpleValue("dataDirectoriesChanged");
            boolean dataFilesChanged = dataFilesChangedString != null && Boolean.parseBoolean(dataFilesChangedString);

            if(dataFilesChanged && invoker != null) {
                try {
                    OperationResult moveDataFilesResult = invoker.invokeOperation("moveDataFiles", config);
                    if(moveDataFilesResult.getErrorMessage() != null) {
                        configurationUpdateReport.setErrorMessage(moveDataFilesResult.getErrorMessage());
                    }
                    restartIfNecessary = false; // We have already restarted the storage node, don't do it twice
                } catch (Exception e) {
                    configurationUpdateReport.setErrorMessage(e.getMessage());
                }
View Full Code Here

                restartIsRequired = true;
            }
        }
        if (restartIsRequired && invoker != null) {
            try {
                OperationResult restartResult = invoker.invokeOperation("restart", null);
                if (restartResult.getErrorMessage() != null) {
                    configurationUpdateReport.setErrorMessage(restartResult.getErrorMessage());
                }
            } catch (Exception e) {
                configurationUpdateReport.setErrorMessage(e.getMessage());
            }
        }
View Full Code Here

        // Convert parameters into MetaValue array.
        MetaValue[] parameterMetaValues = ConversionUtils.convertOperationsParametersToMetaValues(managedOperation,
            parameters, operationDefinition);
        // invoke() takes a varargs, so we need to pass an empty array, rather than null.
        MetaValue resultMetaValue = managedOperation.invoke(parameterMetaValues);
        OperationResult result = new OperationResult();
        // Convert result MetaValue to corresponding Property type.
        ConversionUtils.convertManagedOperationResults(managedOperation, resultMetaValue, result.getComplexResults(),
            operationDefinition);
        // If this is a lifecycle operation ask for an avail check
        boolean availCheck = name.toLowerCase().equals("stop") || name.toLowerCase().contains("start");
        if (availCheck) {
            getResourceContext().getAvailabilityContext().requestAvailabilityCheck();
View Full Code Here

TOP

Related Classes of org.rhq.core.pluginapi.operation.OperationResult

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.