Examples of OperationResult


Examples of org.jboss.as.controller.OperationResult

            final CountDownLatch completeLatch = new CountDownLatch(1);
            final IOExceptionHolder exceptionHolder = new IOExceptionHolder();
            final FailureHolder failureHolder = new FailureHolder();
            final AtomicInteger status = new AtomicInteger(0);

            OperationResult result = modelController.execute(builder.build(), new ResultHandler() {
                @Override
                public void handleResultFragment(String[] location, ModelNode fragment) {
                    try {
                        synchronized (outputStream) {
                            outputStream.write(ModelControllerClientProtocol.PARAM_HANDLE_RESULT_FRAGMENT);
                            outputStream.write(ModelControllerClientProtocol.PARAM_LOCATION);
                            StreamUtils.writeInt(outputStream, location.length);
                            for (String loc : location) {
                                StreamUtils.writeUTFZBytes(outputStream, loc);
                            }
                            outputStream.write(ModelControllerClientProtocol.PARAM_OPERATION);
                            fragment.writeExternal(outputStream);
                            outputStream.flush();
                        }
                    } catch (IOException e) {
                        clearAsynchronousOperation(asynchronousRequestId);
                        exceptionHolder.setException(e);
                        completeLatch.countDown();
                    }
                }

                @Override
                public void handleResultComplete() {
                    clearAsynchronousOperation(asynchronousRequestId);
                    if(!status.compareAndSet(0, 1)) {
                        throw new RuntimeException("Result already set");
                    }
                    completeLatch.countDown();
                }

                @Override
                public void handleFailed(final ModelNode failureDescription) {
                    clearAsynchronousOperation(asynchronousRequestId);
                    if(!status.compareAndSet(0, 2)) {
                        throw new RuntimeException("Result already set");
                    }
                    failureHolder.setFailure(failureDescription);
                    completeLatch.countDown();
                }

                @Override
                public void handleCancellation() {
                    clearAsynchronousOperation(asynchronousRequestId);
                    if(!status.compareAndSet(0, 3)) {
                        throw new RuntimeException("Result already set");
                    }
                    completeLatch.countDown();
                }
            });

            //Do this blocking operation outside the synch block or our result handler will deadlock
            ModelNode compensating = result.getCompensatingOperation() != null ? result.getCompensatingOperation() : new ModelNode();

            synchronized (outputStream) {
                outputStream.write(ModelControllerClientProtocol.PARAM_OPERATION);
                compensating.writeExternal(outputStream);
                outputStream.flush();
            }

            if (completeLatch.getCount() == 0) {
                //It was handled synchronously or has completed by now
            } else {
                //It was handled asynchronously
                addAsynchronousOperation(asynchronousRequestId, result.getCancellable());
                synchronized (outputStream) {
                    outputStream.write(ModelControllerClientProtocol.PARAM_REQUEST_ID);
                    StreamUtils.writeInt(outputStream, asynchronousRequestId);
                    outputStream.flush();
                }
View Full Code Here

Examples of org.jboss.as.controller.client.OperationResult

        }
        DeploymentPlanImpl planImpl = DeploymentPlanImpl.class.cast(plan);
        Map<UUID, String> actionsById = new HashMap<UUID, String>();
        Operation operation = getDeploymentPlanOperation(planImpl, actionsById);
        Handler handler = new Handler(operation);
        OperationResult c = client.execute(operation, handler.resultHandler);
        handler.setCancellable(c.getCancellable());
        return new DomainDeploymentPlanResultFuture(planImpl, handler, actionsById);
    }
View Full Code Here

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

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

        }
    }

    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

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

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

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

        }
    }

    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

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

                    } 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

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

            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

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

            + ((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

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



    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
TOP
Copyright © 2018 www.massapi.com. 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.