Package org.rhq.core.pluginapi.operation

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


    public void testOperation2() throws Exception {
        for (Resource jmxServer : jmxServers) {
            Set<Resource> childResources = getChildResourcesOfType(jmxServer, TEST_SERVICE_RESOURCE_TYPE);
            assertEquals(childResources.size(), 1, String.valueOf(childResources));

            OperationResult operationResult = invokeOperation(childResources.iterator().next(), "doSomething",
                new Configuration());
            assertNull(operationResult); // Operation did not define a "<results>" block.
        }
    }
View Full Code Here


    public void testOperation3() throws Exception {
        for (Resource jmxServer : jmxServers) {
            Set<Resource> childResources = getChildResourcesOfType(jmxServer, TEST_SERVICE_RESOURCE_TYPE);
            assertEquals(childResources.size(), 1, String.valueOf(childResources));

            OperationResult operationResult = invokeOperation(childResources.iterator().next(), "hello",
                new Configuration());
            assertNotNull(operationResult);
            assertEquals(operationResult.getSimpleResult(), "Hello World");
        }
    }
View Full Code Here

            Set<Resource> childResources = getChildResourcesOfType(jmxServer, TEST_SERVICE_RESOURCE_TYPE);
            assertEquals(childResources.size(), 1, String.valueOf(childResources));

            Configuration parameters = new Configuration();
            parameters.put(new PropertySimple("p1", "Hello Test"));
            OperationResult operationResult = invokeOperation(childResources.iterator().next(), "echo", parameters);
            assertNotNull(operationResult);
            assertEquals(operationResult.getSimpleResult(), "Hello Test");
        }
    }
View Full Code Here

            jdbcConnection = getPooledConnectionProvider().getPooledConnection();
            statement = jdbcConnection.createStatement();
            resultSet = statement.executeQuery("select * from pg_stat_reset()");
            return null; // does not return results
        } catch (SQLException e) {
            OperationResult result = new OperationResult("Failed to reset statistics");
            result.setErrorMessage(e.getMessage());
            return result;
        } finally {
            DatabasePluginUtil.safeClose(jdbcConnection, statement, resultSet);
        }
    }
View Full Code Here

            assertEquals(childResources.size(), 1, String.valueOf(childResources));

            Configuration parameters = new Configuration();
            parameters.put(new PropertySimple("p1", "Hello"));
            parameters.put(new PropertySimple("p2", "Test"));
            OperationResult operationResult = invokeOperation(childResources.iterator().next(), "concat", parameters);
            assertNotNull(operationResult);
            assertEquals(operationResult.getSimpleResult(), "HelloTest");
        }
    }
View Full Code Here

        try {
            jdbcConnection = getPooledConnectionProvider().getPooledConnection();
            statement = jdbcConnection.createStatement();
            String sql = parameters.getSimple("sql").getStringValue();

            OperationResult result = new OperationResult();
            if ("update".equals(parameters.getSimpleValue("type"))) {
                int updateCount = statement.executeUpdate(sql);
                result.getComplexResults().put(new PropertySimple("result", "Query updated " + updateCount + " rows"));
                return result;
            }

            resultSet = statement.executeQuery(sql);

            ResultSetMetaData resultSetMetaData = resultSet.getMetaData();

            InvokeSqlResult invokeSqlResult = new InvokeSqlResult(resultSetMetaData.getColumnCount());

            for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
                invokeSqlResult.setColumnHeader(i - 1,
                    resultSetMetaData.getColumnName(i) + " (" + resultSetMetaData.getColumnTypeName(i) + ")");
            }

            while (resultSet.next()) {
                String[] row = invokeSqlResult.createRow();
                for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
                    row[i - 1] = resultSet.getString(i);
                }
                invokeSqlResult.addRow(row);
            }

            InvokeSqlResultExporter exporter;
            if ("formattedText".equals(parameters.getSimpleValue("outputFormat"))) {
                exporter = new InvokeSqlResultFormattedTextExporter();
            } else {
                exporter = new InvokeSqlResultHtmlExporter();
            }

            result.getComplexResults().put(
                new PropertySimple("result", "Query returned " + invokeSqlResult.getRows().size() + " row(s)"));
            result.getComplexResults().put(new PropertySimple("contents", exporter.export(invokeSqlResult)));

            return result;

        } catch (SQLException e) {
            OperationResult result = new OperationResult("Failed to invoke SQL");
            result.setErrorMessage(e.getMessage());
            return result;
        } finally {
            DatabasePluginUtil.safeClose(jdbcConnection, statement, resultSet);
        }
    }
View Full Code Here

        }
        return super.invokeOperation(name, parameters);
    }

    private OperationResult invokeViewQueriesOperation(Configuration parameters) throws InterruptedException {
        OperationResult operationResult = new OperationResult();

        int batchSize;
        PropertySimple batchSizeProp = parameters.getSimple("batchSize");
        if (batchSizeProp == null || batchSizeProp.getStringValue() == null) {
            batchSize = BATCH_SIZE;
        } else {
            try {
                batchSize = Integer.parseInt(batchSizeProp.getStringValue());
                if (batchSize < 1) {
                    operationResult.setErrorMessage("batchSize property is less than 1");
                    return operationResult;
                }
            } catch (NumberFormatException e) {
                operationResult.setErrorMessage("batchSize property is not an integer");
                return operationResult;
            }
        }

        int timeoutSec;
        PropertySimple managementQueryTimeoutProp = parameters.getSimple("managementQueryTimeout");
        if (managementQueryTimeoutProp == null || managementQueryTimeoutProp.getStringValue() == null) {
            timeoutSec = MANAGEMENT_QUERY_TIMEOUT;
        } else {
            try {
                timeoutSec = Integer.parseInt(managementQueryTimeoutProp.getStringValue());
                if (timeoutSec < 1) {
                    operationResult.setErrorMessage("managementQueryTimeout property is less than 1");
                    return operationResult;
                }
            } catch (NumberFormatException e) {
                operationResult.setErrorMessage("managementQueryTimeout property is not an integer");
                return operationResult;
            }
        }

        PropertyList queriesPropertyList = new PropertyList("queries");
        operationResult.getComplexResults().put(queriesPropertyList);

        ReadChildrenNames readQueryCacheChildrenNames = new ReadChildrenNames(getAddress(), "query-cache");
        Result readQueryCacheChildrenNamesResult = getASConnection().execute(readQueryCacheChildrenNames, timeoutSec);
        if (!readQueryCacheChildrenNamesResult.isSuccess()) {
            operationResult.setErrorMessage("Could not read query-cache children names: "
                + readQueryCacheChildrenNamesResult.getFailureDescription());
            return operationResult;
        }
        @SuppressWarnings("unchecked")
        List<String> childrenNames = (List<String>) readQueryCacheChildrenNamesResult.getResult();

        // Process children in batches to avoid sending too many queries if the PU has many query-cache nodes
        while (!childrenNames.isEmpty()) {
            if (context.getComponentInvocationContext().isInterrupted()) {
                // Operation canceled or timed out
                throw new InterruptedException();
            }

            List<String> childrenNamesSubList = childrenNames.subList(0, Math.min(batchSize, childrenNames.size()));

            // Create batch operation to read N query-cache nodes
            CompositeOperation batchOperation = new CompositeOperation();
            for (String childrenName : childrenNamesSubList) {
                Address address = new Address(getAddress());
                address.add("query-cache", childrenName);
                ReadResource readQueryCacheResource = new ReadResource(address);
                readQueryCacheResource.includeRuntime(true);
                batchOperation.addStep(readQueryCacheResource);
            }

            // Execute batch
            Result batchResult = getASConnection().execute(batchOperation, timeoutSec);
            if (!batchResult.isSuccess()) {
                operationResult.setErrorMessage("Could not read query-cache attributes: "
                    + batchResult.getFailureDescription());
                return operationResult;
            }

            // Iterate over batch results
View Full Code Here

        Configuration params = new Configuration();
        params.setSimpleValue("user", MANAGEMENT_USERNAME);
        params.setSimpleValue("password", MANAGEMENT_PASSWORD);

        String operationName = "installRhqUser";
        OperationResult result = invokeOperation(resource, operationName, params);
        System.out.println("Installed management user [" + MANAGEMENT_USERNAME + "] for " + resource + ".");
        assertOperationSucceeded(operationName, params, result);

        // Update the username and password in the *Server-side* plugin config. This simulates the end user updating the
        // plugin config via the GUI.
View Full Code Here

        return (scriptFile.exists()) ? AvailabilityType.UP : AvailabilityType.DOWN;
    }

    public OperationResult invokeOperation(String name, Configuration params) throws Exception {
        if (name.equals(EXECUTE_OPERATION)) {
            OperationResult operationResult = new OperationResult();

            File scriptFile = getScriptFile();
            SystemInfo systemInfo = this.resourceContext.getSystemInformation();
            ProcessExecution processExecution = ProcessExecutionUtility.createProcessExecution(scriptFile);

            processExecution.setWaitForCompletion(1000L * 60 * 60); // 1 hour
            processExecution.setCaptureOutput(true);

            // TODO: Make the script's cwd configurable, but default it to the
            // directory containing the script.
            processExecution.setWorkingDirectory(scriptFile.getParent());

            setEnvironmentVariables(processExecution);
            setCommandLineArguments(params, processExecution);

            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

            Configuration complexResults = operationResult.getComplexResults();
            complexResults.put(new PropertySimple(EXIT_CODE_RESULT_PROP, exitCode));
            complexResults.put(new PropertySimple(OUTPUT_RESULT_PROP, output));
            if (exitCode != null && exitCode != 0) {
                operationResult.setErrorMessage("Exit code was '" + exitCode + "', see operation results for details");
            }

            return operationResult;
        } else {
            throw new IllegalArgumentException("Unsupported operation: " + name);
View Full Code Here

        return (scriptFile.exists()) ? AvailabilityType.UP : AvailabilityType.DOWN;
    }

    public OperationResult invokeOperation(String name, Configuration params) throws Exception {
        if (name.equals(EXECUTE_OPERATION)) {
            OperationResult operationResult = new OperationResult();

            File scriptFile = getScriptFile();
            SystemInfo systemInfo = this.resourceContext.getSystemInformation();
            ProcessExecution processExecution = ProcessExecutionUtility.createProcessExecution(scriptFile);

            processExecution.setWaitForCompletion(1000L * 60 * 60); // 1 hour
            processExecution.setCaptureOutput(true);

            // TODO: Make the script's cwd configurable, but default it to the directory containing the script.
            processExecution.setWorkingDirectory(scriptFile.getParent());

            setEnvironmentVariables(processExecution);
            setCommandLineArguments(params, processExecution);

            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

            Configuration complexResults = operationResult.getComplexResults();
            complexResults.put(new PropertySimple(EXIT_CODE_RESULT_PROP, exitCode));
            complexResults.put(new PropertySimple(OUTPUT_RESULT_PROP, output));
            if (exitCode != null && exitCode != 0) {
                operationResult.setErrorMessage("Exit code was '" + exitCode + "', see operation results for details");
            }

            return operationResult;
        } else {
            throw new IllegalArgumentException("Unsupported operation: " + name);
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.