Package org.rhq.core.pluginapi.operation

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


            // create our timer task that will force the operation invocation to time out if it takes too long to complete
            final long operationTimeout = getOperationTimeout(operationDefinition, parameterConfig);

            // ensure the facet method timeout is comfortably longer than the operation timeout
            long facetMethodTimeout = operationTimeout + (10 * 1000L);
            final OperationFacet operationComponent = getOperationFacet(resourceId, facetMethodTimeout);
            final TimerTask timerTask = new TimerTask() {
                // TIMER TASK THREAD - waits until the timeout time expires - if this is not canceled before the timeout hits,
                // the operation invocation thread is interrupted and the server will be told the operation has timed out.
                @Override
                public void run() {
View Full Code Here


        long timeout = getDefaultTimeout(resource.getResourceType(), operationName);
        System.out.println("=== Invoking operation [" + operationName + "] with parameters ["
            + ((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
                + "] with parameters [" + paramsString + "] on " + resource + ": " + e);
            e.printStackTrace(System.out);
View Full Code Here

        // TODO: Test proxy locking.
    }

    public void testInterruptedComponentInvocationContext() throws Exception {
        ResourceContainer resourceContainer = getResourceContainer();
        OperationFacet proxy = resourceContainer.createResourceComponentProxy(OperationFacet.class,
            FacetLockType.WRITE, SECONDS.toMillis(1L), true, false, true);
        try {
            proxy.invokeOperation("op", new Configuration());
            fail("Expected invokeOperation to throw a TimeoutException");
        } catch (TimeoutException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Caught expected TimeoutException: " + e.getMessage());
            }
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

        // First disable datasource (allow service restart)
        OperationDefinition disableOperation = getOperationDefinition("disable");
        Configuration disableOperationParams = disableOperation.getParametersConfigurationDefinition()
            .getDefaultTemplate().createConfiguration();
        disableOperationParams.setSimpleValue("allow-resource-service-restart", TRUE.toString());
        OperationFacet operationFacet = getOperationFacet(datasourceTestResource);
        OperationResult operationResult = operationFacet.invokeOperation(disableOperation.getName(),
            disableOperationParams);
        assertNull(operationResult.getErrorMessage(),
            "Disable operation failed with error: " + operationResult.getErrorMessage());

        // Then update properties which can only be changed when datasource is in disabled state
        Configuration configuration = pluginContainer.getConfigurationManager().loadResourceConfiguration(
            datasourceTestResource.getId());
        assertFalse(Boolean.parseBoolean(configuration.getSimpleValue("enabled")), "");
        // Make a working copy
        configuration = configuration.deepCopy(false);
        // Change values
        PropertySimple propertySimple = configuration.getSimple("prepared-statements-cache-size");
        Long currentCacheSize = propertySimple.getLongValue();
        long newCacheSize = currentCacheSize == null ? 40 : currentCacheSize + 1;
        propertySimple.setStringValue(String.valueOf(newCacheSize));
        PropertyList connectionPropertiesListWrapper = configuration.getList("*1");
        assertNotNull(connectionPropertiesListWrapper, "Connection properties list wrapper is null");
        List<Property> connectionPropertiesList = connectionPropertiesListWrapper.getList();
        connectionPropertiesList.add(new PropertyMap("*:pname", new PropertySimple("pname", "pipo"),
            new PropertySimple("value", "molo")));
        ConfigurationUpdateRequest configurationUpdateRequest = new ConfigurationUpdateRequest(-1, configuration,
            datasourceTestResource.getId());
        ConfigurationUpdateResponse configurationUpdateResponse = pluginContainer.getConfigurationManager()
            .executeUpdateResourceConfigurationImmediately(configurationUpdateRequest);
        assertSame(configurationUpdateResponse.getStatus(), ConfigurationUpdateStatus.SUCCESS);
        configuration = pluginContainer.getConfigurationManager().loadResourceConfiguration(
            datasourceTestResource.getId());
        assertFalse(Boolean.parseBoolean(configuration.getSimpleValue("enabled")), "");
        assertEquals(configuration.getSimple("prepared-statements-cache-size").getLongValue(),
            Long.valueOf(newCacheSize));
        connectionPropertiesListWrapper = configuration.getList("*1");
        assertNotNull(connectionPropertiesListWrapper, "Connection properties list wrapper is null");
        connectionPropertiesList = connectionPropertiesListWrapper.getList();
        String connectionPropertyValue = null;
        for (Property property : connectionPropertiesList) {
            assertTrue(property instanceof PropertyMap, "Connection properties should be a list of maps");
            PropertyMap propertyMap = (PropertyMap) property;
            String pname = propertyMap.getSimpleValue("pname", null);
            assertNotNull(pname, "Connection property key is null");
            String value = propertyMap.getSimpleValue("value", null);
            assertNotNull(value, "Connection property value is null");
            if ("pipo".equals(pname)) {
                connectionPropertyValue = value;
                break;
            }
        }
        assertEquals(connectionPropertyValue, "molo");
        assertFalse(
            configuration.getNames().contains("__OOB"),
            "The configuration object should not contain out of band messages: "
                + configuration.getSimpleValue("__OOB"));

        // Now re-enable datasource
        OperationDefinition enableOperation = getOperationDefinition("enable");
        Configuration enableOperationParams = enableOperation.getParametersConfigurationDefinition()
            .getDefaultTemplate().createConfiguration();
        operationResult = operationFacet.invokeOperation(enableOperation.getName(), enableOperationParams);
        assertNull(operationResult.getErrorMessage(),
            "Enable operation failed with error: " + operationResult.getErrorMessage());

        // Check server state
        configuration = pluginContainer.getConfigurationManager().loadResourceConfiguration(
View Full Code Here

    @Test(priority = 13)
    public void testHibernatePersistenceUnitViewQueriesOperation() throws Exception {
        Set<Resource> resources = getChildResourcesOfType(getDeploymentResource(),
            RuntimeServiceType.HIBERNATE_PERSISTENCE_UNIT.getServiceTypeName());
        for (Resource resource : resources) {
            OperationFacet operationFacet = getOperationFacet(resource);
            Configuration parameters = new Configuration();
            parameters.setSimpleValue("batchSize", "50");
            parameters.setSimpleValue("managementQueryTimeout", "180");
            OperationResult operationResult = operationFacet.invokeOperation("viewQueries", parameters);
            String errorMessage = operationResult.getErrorMessage();
            assertNull(errorMessage, errorMessage);
            Configuration complexResults = operationResult.getComplexResults();
            assertNotNull(complexResults, "ComplexResults is null");
            PropertyList queriesPropList = complexResults.getList("queries");
View Full Code Here

    }

    public static OperationResult invokeOperation(Resource resource, String operationName, Configuration parameters)
        throws Exception {

        OperationFacet operationFacet = getResourceComponentFacet(resource, OperationFacet.class);
        OperationResult operationResult = operationFacet.invokeOperation(operationName, parameters);

        if (operationResult != null && operationResult.getErrorMessage() != null) {
            fail("Operation (" + operationName + ") failed : " + operationResult.getErrorMessage());
        }
        return operationResult;
View Full Code Here

                //       For example, execute 'restart' first, followed by 'stop', followed by 'start'.
                for (String name : operationNames) {
                    //we must get a new operation facet for each operation so that each operation gets
                    //the 3 seconds to finish. Otherwise all the operations would have to finish in 3 secs
                    //which can be a bit harsh limit.
                    OperationFacet operationFacet = ComponentUtil.getComponent(resource.getId(), OperationFacet.class,
                        FacetLockType.WRITE, OPERATION_FACET_METHOD_TIMEOUT, true, true, true);
                    //String name = operationDefinition.getName();
                    OperationResult result = operationFacet.invokeOperation(name, getTestOperationParameters(name));
                    System.out.println("Validating operation '" + name + "' result (" + result + ")...");
                    validateOperationResult(name, result, resource);
                }
            }
        }
View Full Code Here

        Set<Resource> resources = getResources();
        Boolean foundDestination = false;
        for (Resource resource : resources) {
            if (resource.getName().equals(getDestinationName())) {
                foundDestination = true;
                OperationFacet operationFacet = ComponentUtil.getComponent(resource.getId(), OperationFacet.class,
                    FacetLockType.WRITE, 3000, true, true, true);
                String name = "removeAllMessages";
                operationFacet.invokeOperation(name, getTestOperationParameters(name));
            }
        }
        if (!foundDestination)
            throw new Exception("cannot find " + getDestinationName());
        Thread.sleep(4000);
View Full Code Here

      Set<Resource> resources = TestHelper.getResources(resourceType);

      for (Resource resource : resources) {
        log.info("Validating operations for " + resource + "...");
        OperationFacet operationFacet = ComponentUtil.getComponent(
            resource.getId(), OperationFacet.class,
            FacetLockType.WRITE,
            CacheComponentTest.OPERATION_FACET_METHOD_TIMEOUT,
            true, true, true);

        for (OperationDefinition operationDefinition : operationDefinitions) {
          String name = operationDefinition.getName();

          OperationResult result = operationFacet.invokeOperation(
              name, new Configuration());

          log.info("Validating operation '" + name + "' result ("
              + result + ")...");
View Full Code Here

TOP

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

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.