Package org.rhq.core.pluginapi.operation

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


    private class MockOperationFacet implements OperationFacet {
        public OperationResult invokeOperation(String name, Configuration parameters) throws Exception {
            if (name.equals("opFailure")) {
                throw new IllegalStateException("Simulates an operation failure");
            } else if (name.equals("opSuccess")) {
                OperationResult config = new OperationResult();
                config.getComplexResults().put(new PropertySimple("successName", "successValue"));
                return config;
            } else if (name.equals("opTimeout")) {
                try {
                    long sleepTime;
View Full Code Here


        }
    }

    private class MockOperationFacet implements OperationFacet {
        public OperationResult invokeOperation(String name, Configuration parameters) throws Exception {
            OperationResult opConfig = new OperationResult();
            if (name.equals("initialOp")) {
                manager.invokeOperation(JOB_2_ID, RESOURCE_2_ID, "secondOp", new Configuration()); // call back into OperationManager on different resource
                // The above call to secondOp should be asynchronous and be able to run concurrently with us (because
                // we are invoking it on resource 2, and we are running on resource 1).
                // If it cannot complete within a few seconds, we have deadlocked.
                // That would mean resource 1 is delaying a resource 2 op - which would be a bug.
                // Different resources should not delay operations on other resources.
                waitForAgentResponse(OPERATION_TIMEOUT_MILLIS, JOB_2_ID);
                Object results = opResults.get(JOB_2_ID);
                assert results != null : "our called job 2 did not finish";
                assert results instanceof Configuration : "our called job 2 did not finish as expected: " + opResults;
                assert ((Configuration) results).getSimple("secondOpResults").getStringValue()
                    .equals("secondOpSuccess") : "our called job 2 did not finish as expected: " + opResults;

                opConfig.getComplexResults().put(new PropertySimple("initialOpResults", "initialOpSuccess"));
            } else if (name.equals("secondOp")) {
                opConfig.getComplexResults().put(new PropertySimple("secondOpResults", "secondOpSuccess"));
            } else if (name.equals("initialOpSameResource")) {
                manager.invokeOperation(JOB_2_ID, RESOURCE_1_ID, "secondOpSameResource", new Configuration()); // call back into OperationManager on same resource #1
                // The above call to secondOp should not be able to run concurrently with us (because
                // we are invoking it on resource 1, which is the same resource we are running on).
                // This should deadlock - job 2 should never finish because it should never start (at least
                // until we finish first).
                // Therefore, we are going to wait for an agent response to job 2 that will never come.
                // This will in turn cause our job to timeout.
                waitForAgentResponse(OPERATION_TIMEOUT_MILLIS + 1000L, JOB_2_ID); // wait longer than the operation timeout
            } else if (name.equals("secondOpSameResource")) {
                opConfig.getComplexResults().put(
                    new PropertySimple("secondOpSameResourceResults", "secondOpSameResourceSuccess"));
            } else {
                throw new IllegalStateException("BAD TEST - unknown operation: " + name);
            }
View Full Code Here

            // the plugin writer of the operation facet to handle the interrupt exception, if applicable.

            if (canContinue) {
                // call the plugin component's operation facet to actually execute the operation
                Configuration parameters = (parameterConfig != null) ? parameterConfig : new Configuration();
                OperationResult opResult = operationComponent.invokeOperation(operationName, parameters);

                // allow a plugin to return a null (aka void) result set
                result = (opResult != null) ? opResult.getComplexResults() : null;
                if (result != null) {
                    if (this.operationDefinition != null) {
                        if (this.operationDefinition.getResultsConfigurationDefinition() != null) {
                            // Normalize the result Configuration.
                            ConfigurationUtility.normalizeConfiguration(result, operationDefinition
                                .getResultsConfigurationDefinition());
                            // TODO: Validate the result Configuration?
                        } else if (!result.getProperties().isEmpty()) {
                            log.error("Plugin error: Operation [" + this.operationDefinition.getName()
                                + "] is defined as returning no results, but it returned non-null results: "
                                + result.toString(true));
                            result = null; // Don't return results that the GUI won't be able to display anyway.
                        }
                    }
                    errorMessage = opResult.getErrorMessage();
                }
            } else {
                failure = new InterruptedException("Operation was aborted before it started.");
            }
        } catch (Throwable t) {
View Full Code Here

        }
    }

    public OperationResult retrieveAllPluginInfo() {
        List<File> plugins;
        OperationResult info = new OperationResult();
        ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
            PluginUpdate updater = getPluginUpdateObject();
            plugins = updater.getCurrentPluginFiles();
            PluginContainerConfiguration pcConfig = m_agent.getConfiguration().getPluginContainerConfiguration();
            List<String> enabledPlugins = pcConfig.getEnabledPlugins();
            List<String> disabledPlugins = pcConfig.getDisabledPlugins();

            PropertyList list = new PropertyList("plugins".intern());
            info.getComplexResults().put(list);

            if (plugins.size() > 0) {
                for (File plugin : plugins) {
                    String pluginName;
                    String pluginDisplayName;
View Full Code Here

                    } catch (Exception t) {
                        continue;
                    }

                    if (pluginNameToReturn.toLowerCase().equals(pluginName.toLowerCase())) {
                        OperationResult opResults = new OperationResult();
                        Configuration info = opResults.getComplexResults();
                        info.put(new PropertySimple(PLUGIN_INFO_NAME, pluginNameToReturn));
                        info.put(new PropertySimple(PLUGIN_INFO_DISPLAY_NAME, pluginDisplayName));
                        info.put(new PropertySimple(PLUGIN_INFO_PATH, plugin.getAbsoluteFile()));
                        info.put(new PropertySimple(PLUGIN_INFO_TIMESTAMP, new Date(plugin.lastModified())));
                        info.put(new PropertySimple(PLUGIN_INFO_SIZE, plugin.length()));
View Full Code Here

            report = inventoryManager.executeAvailabilityScanImmediately(changes);
        } finally {
            Thread.currentThread().setContextClassLoader(originalCL);
        }

        OperationResult opResult = new OperationResult();
        Configuration complexResults = opResult.getComplexResults();

        PropertyList list = new PropertyList("resourceAvailabilities");
        complexResults.put(list);

        String agentName;
View Full Code Here

            + ((params != null) ? params.toString(true) : params) + "] on " + resource + "...");
        ResourceContainer resourceContainer = this.pluginContainer.getInventoryManager().getResourceContainer(resource);
        long timeoutMillis = timeout * 1000;
        OperationFacet operationFacet = resourceContainer.createResourceComponentProxy(OperationFacet.class,
            FacetLockType.WRITE, timeoutMillis, false, false, false);
        OperationResult operationResult;
        try {
            operationResult = operationFacet.invokeOperation(operationName, params);
        } catch (Exception e) {
            String paramsString = (params != null) ? params.toString(true) : String.valueOf(params);
            System.out.println("====== Error occurred during invocation of operation [" + operationName
View Full Code Here



    protected OperationResult invokeOperationAndAssertSuccess(Resource resource, String operationName, @Nullable
    Configuration params) throws PluginContainerException {
        OperationResult result = invokeOperation(resource, operationName, params);
        assertOperationSucceeded(operationName, params, result);
        return result;
    }
View Full Code Here

    public void testUninterruptedComponentInvocationContext() throws Exception {
        ResourceContainer resourceContainer = getResourceContainer();
        OperationFacet proxy = resourceContainer.createResourceComponentProxy(OperationFacet.class,
            FacetLockType.WRITE, SECONDS.toMillis(10L), true, false, true);
        try {
            OperationResult op = proxy.invokeOperation("op", new Configuration());
            assertTrue(op.getSimpleResult().equals(MockResourceComponent.OPERATION_RESULT));
        } catch (Exception e) {
            fail("Caught unexpected Exception: " + e.getClass().getName());
            assertFalse(((MockResourceComponent) resourceContainer.getResourceComponent())
                    .caughtInterruptedComponentInvocation());
        }
View Full Code Here

            sleep(SECONDS.toMillis(5));
            if (resourceContext.getComponentInvocationContext().isInterrupted()) {
                caughtInterruptedComponentInvocation = true;
                throw new InterruptedException();
            }
            return new OperationResult(OPERATION_RESULT);
        }
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.