Package org.rhq.core.domain.resource

Examples of org.rhq.core.domain.resource.Resource


        }
    }

    @Test(enabled = ENABLE_TESTS)
    public void testInvalidResourceConfigurationUpdate() throws Exception {
        Resource resource = newResource1;

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        Configuration configuration1 = new Configuration();
        configuration1.put(new PropertySimple("fakeReadOnly", "1"));
        configuration1.put(new PropertySimple("myboolean", "false"));

        Configuration configuration2 = new Configuration();
        configuration2.put(new PropertySimple("fakeReadOnly", "2"));
        configuration2.put(new PropertySimple("myboolean", "false"));

        Configuration current = configurationManager.getResourceConfiguration(overlord, resource.getId());
        assert current != null;
        assert current.getProperties().size() == 0 : current; // there is no res config settings yet

        ResourceConfigurationUpdate rcu = configurationManager.updateResourceConfiguration(overlord, resource.getId(),
            configuration1);
        for (int i = 0; configurationManager.isResourceConfigurationUpdateInProgress(overlord, newResource1.getId())
            && i < 5; ++i) {
            Thread.sleep(1000);
        }

        current = configurationManager.getResourceConfiguration(overlord, resource.getId());
        assert current != null;
        assert current.getProperties().size() == 2 : current;
        assert current.getSimple("fakeReadOnly").getIntegerValue() == 1 : current;

        try {
            configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration2);
            fail("Should have thrown BadArgumentException when trying to change readOnly property.");
        } catch (BadArgumentException e) {
            // expected
        }
    }
View Full Code Here


        }
    }

    @Test(enabled = ENABLE_TESTS)
    public void testPluginConfigurationUpdateCallbackSuccess() throws Exception {
        Resource resource = newResource1;

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        Configuration configuration1 = new Configuration();
        configuration1.put(new PropertySimple("foo", "1"));

        Configuration configuration2 = new Configuration();
        configuration2.put(new PropertySimple("bar", "2"));

        Configuration current;

        current = configurationManager.getPluginConfiguration(overlord, resource.getId());
        assert current != null;
        assert current.getProperties().size() == 0 : current; // there is no plugin config settings yet

        configurationManager.updatePluginConfiguration(overlord, resource.getId(), configuration1);
        current = configurationManager.getPluginConfiguration(overlord, resource.getId());
        assert current != null;
        assert current.getProperties().size() == 1 : current;
        assert current.getSimple("foo").getIntegerValue() == 1 : current;

        configurationManager.updatePluginConfiguration(overlord, resource.getId(), configuration2);
        current = configurationManager.getPluginConfiguration(overlord, resource.getId());
        assert current != null;
        assert current.getProperties().size() == 1 : current;
        assert current.getSimple("bar").getIntegerValue() == 2 : current;
        assert current.getSimple("foo") == null : current; // this is gone now, we overrode it

        assert current.remove("foo") == null : current; // secondary test - just exercise the remove method
        assert current.remove("bar") != null : current; // again just test the remove method
        current.put(new PropertySimple("hello", "3"));
        configurationManager.updatePluginConfiguration(overlord, resource.getId(), current);
        current = configurationManager.getPluginConfiguration(overlord, resource.getId());
        assert current != null;
        assert current.getProperties().size() == 1 : current;
        assert current.getSimple("hello").getIntegerValue() == 3 : current;
        assert current.getSimple("foo") == null : current; // this is gone now
        assert current.getSimple("bar") == null : current; // this is gone now
View Full Code Here

        assert current.getSimple("bar") == null : current; // this is gone now
    }

    @Test(enabled = ENABLE_TESTS)
    public void testPluginConfigurationUpdateCallbackFailure() throws Exception {
        Resource resource = newResource1;

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        Configuration configuration1 = new Configuration();
        configuration1.put(new PropertySimple("foo", "1"));
        configuration1.put(new PropertySimple("fail", "true"));

        Configuration current;

        current = configurationManager.getPluginConfiguration(overlord, resource.getId());
        assert current != null;
        assert current.getProperties().size() == 0 : current; // there is no plugin config settings yet

        PluginConfigurationUpdate update = configurationManager.updatePluginConfiguration(overlord, resource.getId(),
            configuration1);
        assert update.getErrorMessage() != null : "We should have simulated a failure, "
            + "but instead received no error.";

        // Even if a plugin container exception occurs, the plugin configuration should still be updated.
        current = configurationManager.getPluginConfiguration(overlord, resource.getId());
        assert current != null;
        assert current.getProperties().size() != 0 : current.toString();
    }
View Full Code Here

    }

    private void testGroupPluginConfigurationUpdateWorkflowHelper(boolean failOnChildUpdates) throws Exception {
        getTransactionManager().begin();

        Resource resource1 = newResource1;
        Resource resource2 = newResource2;

        try {
            Subject overlord = LookupUtil.getSubjectManager().getOverlord();

            Configuration configuration1 = new Configuration();
            configuration1.put(new PropertySimple("foo", "1"));
            configuration1.put(new PropertySimple("fail", "false"));

            Configuration configuration2 = new Configuration();
            configuration2.put(new PropertySimple("foo", "2"));
            configuration2.put(new PropertySimple("fail", "false"));

            /* begin simple checks */
            PluginConfigurationUpdate update1 = configurationManager.updatePluginConfiguration(overlord,
                resource1.getId(), configuration1);
            assert update1.getErrorMessage() == null : "We weren't expecting a failure here";

            PluginConfigurationUpdate update2 = configurationManager.updatePluginConfiguration(overlord,
                resource2.getId(), configuration2);
            assert update2.getErrorMessage() == null : "We weren't expecting a failure here";

            Configuration updatedConfiguration1 = configurationManager.getPluginConfiguration(overlord,
                resource1.getId());
            Configuration updatedConfiguration2 = configurationManager.getPluginConfiguration(overlord,
                resource2.getId());

            assert updatedConfiguration1.equals(configuration1) : "configuration1 was: " + updatedConfiguration1 + ", "
                + "expected was: " + configuration1;

            assert updatedConfiguration2.equals(configuration2) : "configuration2 was: " + updatedConfiguration2 + ", "
                + "expected was: " + configuration2;
            /*  end simple checks */

            /* begin group configuration creation checks */
            Configuration expectedGroupConfiguration = new Configuration();
            expectedGroupConfiguration
                .put(new PropertySimple("foo", GroupPluginConfigurationUpdate.MIXED_VALUES_MARKER));
            expectedGroupConfiguration.put(new PropertySimple("fail", "false"));

            List<Configuration> updatedConfigurations = Arrays.asList(new Configuration[] { updatedConfiguration1,
                updatedConfiguration2 });

            Configuration groupConfiguration = null;
            /*
            Configuration groupConfiguration = GroupPluginConfigurationUpdate
                .getGroupConfiguration(updatedConfigurations);
             */

            assert groupConfiguration.equals(expectedGroupConfiguration) : "group configuration was: "
                + groupConfiguration + ", " + "expected was: " + expectedGroupConfiguration;
            /*  end group configuration creation checks */

            /* begin group modification */
            Configuration groupConfigurationOverride = new Configuration();
            PropertySimple propertySimple1 = new PropertySimple("foo", "3");
            PropertySimple propertySimple2 = new PropertySimple("fail", "true");
            groupConfigurationOverride.put(propertySimple1);
            groupConfigurationOverride.put(propertySimple2);

            // regardless of failures, semantics dictate that the new configuration should be persisted to the resource
            Configuration expectedGroupConfigurationResults = new Configuration();
            expectedGroupConfigurationResults.put(new PropertySimple("foo", "3")); // from groupConfigurationOverride
            propertySimple1.setOverride(Boolean.TRUE);

            if (failOnChildUpdates) {
                expectedGroupConfigurationResults.put(new PropertySimple("fail", "true")); // from groupConfigurationOverride
                propertySimple2.setOverride(Boolean.TRUE); // will make TestServices fail
            } else {
                expectedGroupConfigurationResults.put(new PropertySimple("fail", "false")); // from both resource's current configuration
                propertySimple2.setOverride(Boolean.FALSE); // false is default, but setting explicitly for test clarity
            }

            Map<Integer, Configuration> memberConfigs = new HashMap<Integer, Configuration>();
            memberConfigs.put(resource1.getId(), configuration1);
            memberConfigs.put(resource2.getId(), configuration2);
            int groupUpdateId = configurationManager.scheduleGroupPluginConfigurationUpdate(overlord,
                compatibleGroup.getId(), memberConfigs);

            // instead of sleeping, let's directly execute what would normally be scheduled
            //configurationManager.completeGroupPluginConfigurationUpdate(groupUpdateId);

            GroupPluginConfigurationUpdate update = configurationManager.getGroupPluginConfigurationById(groupUpdateId);

            assert update != null : "Group plugin configuration update should not have been null";

            int i = 0;
            for (PluginConfigurationUpdate childUpdate : update.getConfigurationUpdates()) {
                Configuration childUpdateConfiguration = childUpdate.getConfiguration();
                assert childUpdateConfiguration.equals(expectedGroupConfigurationResults) : "new updateChildConfig["
                    + i + "] was: " + childUpdateConfiguration + ", " + "expected was: "
                    + expectedGroupConfigurationResults;
                i++;
            }

            Configuration configurationAfterGroupUpdate1 = configurationManager.getPluginConfiguration(overlord,
                resource1.getId());
            Configuration configurationAfterGroupUpdate2 = configurationManager.getPluginConfiguration(overlord,
                resource2.getId());

            ConfigurationUpdateStatus expectedResultStatus = null;

            if (failOnChildUpdates) {
                expectedResultStatus = ConfigurationUpdateStatus.FAILURE;
View Full Code Here

        }
    }

    @Test(enabled = ENABLE_TESTS)
    public void testResourceConfigurationUpdateCallbackFailure() throws Exception {
        Resource resource = newResource1;

        try {
            Subject overlord = LookupUtil.getSubjectManager().getOverlord();

            // this is simulating what the UI would be doing, build the config and call the server-side API
            // we'll pretend the user is the overlord - another test will check a real user to see permission errors
            Configuration configuration = new Configuration();
            configuration.put(new PropertySimple("myboolean", "invalid-bool"));

            ResourceConfigurationUpdate history = new ResourceConfigurationUpdate(resource, configuration, "dummyuser");

            assert history.getStatus().equals(ConfigurationUpdateStatus.INPROGRESS);

            configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration);

            Thread.sleep(2000); // wait for the test agent to complete the request

            // our test service pretends the agent got an error - it will set some errors and the call to
            // completedConfigurationUpdate is made inline (in the real code, this would be asynchronous)
            // at this point in time, the round trip messaging is done and we have the agent response
            getTransactionManager().begin();

            try {
                resource = em.find(Resource.class, resource.getId());

                history = resource.getResourceConfigurationUpdates().get(0);

                assert history.getStatus().equals(ConfigurationUpdateStatus.FAILURE) : "Status was "
                    + history.getStatus();
                assert history.getErrorMessage() != null;
                assert history.getErrorMessage().indexOf("This simulates a failed update") > 0;
                assert history.getConfiguration() != null;
                PropertySimple mybool = history.getConfiguration().getSimple("myboolean");
                assert mybool != null;
                assert mybool.getStringValue().equals("invalid-bool");
                assert mybool.getErrorMessage().indexOf("Not a valid boolean") > 0;
            } finally {
                getTransactionManager().rollback();
            }

            assert configurationManager.getLatestResourceConfigurationUpdate(overlord, resource.getId()) != null : "Resource wasn't configured yet - but we should have populated it with live values";

            // purging a non-existing request is a no-op
            configurationManager.purgeResourceConfigurationUpdate(overlord, Integer.MIN_VALUE, false);

            // delete the request now
            configurationManager.purgeResourceConfigurationUpdate(overlord, history.getId(), false);

            getTransactionManager().begin();

            try {
                resource = em.find(Resource.class, resource.getId());
                assert resource.getResourceConfigurationUpdates().size() == 1; // the initial built for us for free with the live config
            } finally {
                getTransactionManager().rollback();
            }
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

        }
    }

    @Test(enabled = ENABLE_TESTS)
    public void testResourceConfigurationUpdateCallbackSuccess() throws Exception {
        Resource resource = newResource1;
        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        // this is simulating what the UI would be doing, build the config and call the server-side API
        // we'll pretend the user is the overlord - another test will check a real user to see permission errors
        Configuration configuration = new Configuration();
        configuration.put(new PropertySimple("myboolean", "true"));

        ResourceConfigurationUpdate request = new ResourceConfigurationUpdate(resource, configuration, "dummyuser");

        assert request.getStatus().equals(ConfigurationUpdateStatus.INPROGRESS);

        configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration);

        Thread.sleep(2000); // wait for the test agent to complete the request

        // at this point in time, the round trip messaging is done and we have the agent response
        ResourceConfigurationUpdateCriteria criteria = new ResourceConfigurationUpdateCriteria();
        criteria.addFilterResourceIds(resource.getId());
        criteria.fetchConfiguration(true);
        criteria.addSortCreatedTime(PageOrdering.ASC);

        List<ResourceConfigurationUpdate> requests;

        requests = configurationManager.findResourceConfigurationUpdatesByCriteria(overlord, criteria);

        assert requests.size() == 1;
        assert requests.get(0) != null;

        request = requests.get(0);

        assert request.getStatus().equals(ConfigurationUpdateStatus.SUCCESS);
        assert request.getErrorMessage() == null;
        assert request.getConfiguration() != null;
        PropertySimple mybool = request.getConfiguration().getSimple("myboolean");
        assert mybool != null;
        assert mybool.getStringValue().equals("true");
        assert mybool.getErrorMessage() == null;

        ResourceConfigurationUpdate current;
        current = configurationManager.getLatestResourceConfigurationUpdate(overlord, resource.getId());

        assert current != null;
        assert current.getId() == request.getId();
        assert current.getResource().equals(resource);
        assert current.getStatus().equals(request.getStatus());
        assert current.getSubjectName().equals(request.getSubjectName());
        assert current.getCreatedTime() == request.getCreatedTime();
        assert current.getModifiedTime() == request.getModifiedTime();
        assert current.getConfiguration().getId() == request.getConfiguration().getId();

        Configuration live = configurationManager.getLiveResourceConfiguration(overlord, resource.getId(), false);
        assert live != null;
        mybool = live.getSimple("myboolean");
        assert mybool != null;
        assert "true".equals(mybool.getStringValue());
        assert mybool.getErrorMessage() == null;

        // purging a non-existing request is a no-op
        configurationManager.purgeResourceConfigurationUpdate(overlord, Integer.MIN_VALUE, false);

        // delete the request now
        System.out.println("REQUEST WAS: " + request.toString());
        configurationManager.purgeResourceConfigurationUpdate(overlord, request.getId(), false);

        requests = configurationManager.findResourceConfigurationUpdates(overlord, resource.getId(), null, null, false,
            configUpdatesPageControl);

        assert requests.size() == 1; // it will create one for us from the "live" configuration
    }
View Full Code Here

    public void testUpdateResourceTags() {
        executeInTransaction(new TransactionCallback() {
            @Override
            public void execute() throws Exception {
                Resource resource = SessionTestHelper.createNewResource(em, getRandomString());
                resource.setTags(emptyTagSet());
                Set<Tag> tags = generateTagSet(7);
                tagManager.updateResourceTags(overlord, resource.getId(), tags);
                assertEquals(tags, resource.getTags());
            }
        });
    }
View Full Code Here

    @Test(enabled = ENABLE_TESTS)
    public void testResourceConfigurationDefinitionsOptions() throws Exception {
        ConfigurationManagerLocal configurationManager = LookupUtil.getConfigurationManager();

        getTransactionManager().begin();
        Resource resource = em.find(Resource.class, newResource1.getId());
        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        try {
            // this is simulating what the UI would be doing, build the config and call the server-side API
            // we'll pretend the user is the overlord - another test will check a real user to see permission errors
            ResourceType newResource1Type = resource.getResourceType();
            ConfigurationDefinition initialDefinition = newResource1Type.getResourceConfigurationDefinition();
            int loadCount = 300;
            HashSet<String> parsedNames = new HashSet<String>();
            for (int i = 0; i < loadCount; i++) {
                String name = "fakeProperty_" + i;
View Full Code Here

        resourceTypeBundleConfiguration.addBundleDestinationBaseDirectory(getRandomString(),
            ResourceTypeBundleConfiguration.BundleDestinationBaseDirectory.Context.pluginConfiguration.name(),
            getRandomString(), getRandomString());
        resourceType.setResourceTypeBundleConfiguration(resourceTypeBundleConfiguration);

        Resource resource = SessionTestHelper.createNewResource(em, getRandomString(), resourceType);

        ResourceGroup resourceGroup = createResourceGroup();
        resourceGroup.addExplicitResource(resource);
        resourceGroup.setResourceType(resourceType);
View Full Code Here

        }
    }

    @Test(enabled = ENABLE_TESTS)
    public void testConfigurationRollback() throws Exception {
        Resource resource = newResource1;

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        // create a few configs in history
        Configuration configuration1 = new Configuration();
        configuration1.put(new PropertySimple("myboolean", "true"));
        configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration1);
        Thread.sleep(3000); // wait for the test agent to complete the request

        Configuration configuration2 = new Configuration();
        configuration2.put(new PropertySimple("myboolean", "false"));
        configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration2);
        Thread.sleep(3000); // wait for the test agent to complete the request

        Configuration configuration3 = new Configuration();
        configuration3.put(new PropertySimple("myboolean", "TRUE"));
        configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration3);
        Thread.sleep(3000); // wait for the test agent to complete the request

        ResourceConfigurationUpdateCriteria criteria = new ResourceConfigurationUpdateCriteria();
        criteria.addFilterResourceIds(resource.getId());
        criteria.fetchConfiguration(true);
        criteria.addSortCreatedTime(PageOrdering.ASC);
        List<ResourceConfigurationUpdate> history = configurationManager.findResourceConfigurationUpdatesByCriteria(
            overlord, criteria);
        assert history != null;
        assert history.size() == 3;

        Configuration currentConfiguration = history.get(2).getConfiguration();
        PropertySimple mybool = currentConfiguration.getSimple("myboolean");
        assert mybool != null;
        assertEquals("TRUE", mybool.getStringValue());

        // now grab one of the earlier configurations and rollback to it
        Configuration rollbackToHere = history.get(1).getConfiguration(); // the "false" one
        mybool = rollbackToHere.getSimple("myboolean");
        assert mybool != null;
        assertEquals("false", mybool.getStringValue());

        configurationManager.updateResourceConfiguration(overlord, resource.getId(), rollbackToHere);
        Thread.sleep(3000); // wait for the test agent to complete the request

        criteria = new ResourceConfigurationUpdateCriteria();
        criteria.addFilterResourceIds(resource.getId());
        criteria.fetchConfiguration(true);
        criteria.addSortCreatedTime(PageOrdering.ASC);

        history = configurationManager.findResourceConfigurationUpdatesByCriteria(overlord, criteria);
        assert history != null;
        assert history.size() == 4;
        ResourceConfigurationUpdate newConfigUpdate = history.get(3); // the last one is the new one
        Configuration newConfiguration = newConfigUpdate.getConfiguration();
        assert newConfiguration.getId() != rollbackToHere.getId();
        mybool = newConfiguration.getSimple("myboolean");
        assert mybool != null;
        assertEquals("false", mybool.getStringValue());
        assert mybool.getErrorMessage() == null;

        ResourceConfigurationUpdate current = configurationManager.getLatestResourceConfigurationUpdate(overlord,
            resource.getId());
        assert current != null;
        assert current.getId() == newConfigUpdate.getId();
        assert current.getResource().equals(resource);
        assert current.getStatus().equals(newConfigUpdate.getStatus());
        assert current.getSubjectName().equals(newConfigUpdate.getSubjectName());
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.resource.Resource

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.