Package org.rhq.core.domain.configuration

Examples of org.rhq.core.domain.configuration.ResourceConfigurationUpdate


        configuration2.put(new PropertySimple("mysleep", "7000"));

        configurationManager.updateResourceConfiguration(overlord, resourceId, configuration1);
        Thread.sleep(2000); // wait for the test agent to complete the request

        ResourceConfigurationUpdate history1;
        history1 = configurationManager.getLatestResourceConfigurationUpdate(overlord, resourceId);
        assert history1 != null;
        PropertySimple myprop = history1.getConfiguration().getSimple("myboolean");
        assert myprop != null;
        assert "true".equals(myprop.getStringValue());

        // now update to that second config - the "agent" will sleep for a bit before it completes
        // so we will have an INPROGRESS configuration for a few seconds before it goes to SUCCESS
        ResourceConfigurationUpdate history2 = null;
        boolean inProgress = false;
        boolean inProgressTested = false;

        configurationManager.updateResourceConfiguration(overlord, resourceId, configuration2);

        do {
            history2 = configurationManager.getLatestResourceConfigurationUpdate(overlord, resourceId);
            inProgress = configurationManager.isResourceConfigurationUpdateInProgress(overlord, resourceId);

            if (inProgress) {
                // history2 should be history1 since the update is not complete
                assert history2 != null;
                assert history2.getId() == history1.getId();
                myprop = history2.getConfiguration().getSimple("myboolean");
                assert myprop != null;
                assert "true".equals(myprop.getStringValue());
                myprop = history2.getConfiguration().getSimple("mysleep"); // this wasn't in the first config
                assert myprop == null;
                // record that this test case ran, we expect it will if the agent delay is there
                inProgressTested = true;
            } else {
                // update is complete, history 2 should be different
                history2 = configurationManager.getLatestResourceConfigurationUpdate(overlord, resourceId);
                assert history2 != null;
                assert history2.getId() != history1.getId();
                myprop = history2.getConfiguration().getSimple("myboolean");
                assert myprop != null;
                assert "false".equals(myprop.getStringValue());
                myprop = history2.getConfiguration().getSimple("mysleep");
                assert myprop.getLongValue() != null;
                assert myprop.getLongValue().longValue() == 7000L;
            }
        } while (inProgress);
View Full Code Here


        // make config1 the current
        configurationManager.updateResourceConfiguration(overlord, resourceId, configuration1);
        Thread.sleep(2000); // wait for the test agent to complete the request

        ResourceConfigurationUpdate history1;
        history1 = configurationManager.getLatestResourceConfigurationUpdate(overlord, resourceId);
        assert history1 != null;
        PropertySimple myprop = history1.getConfiguration().getSimple("myboolean");
        assert myprop != null;
        assert "true".equals(myprop.getStringValue());

        // now update to config2 - the "agent" will sleep for a bit before it completes
        // so we will have an INPROGRESS configuration for a few seconds before it goes to SUCCESS
        configurationManager.updateResourceConfiguration(overlord, resourceId, configuration2);

        // now update to config3 - this should fail as you can't update while there is one in progress
        try {
            configurationManager.updateResourceConfiguration(overlord, resourceId, configuration3);
            assert false : "Should have thrown an in progress exception";

        } catch (ConfigurationUpdateStillInProgressException e) {
            System.out.println("======> " + e);

            // make sure everything works as expected (like the above test)

            boolean inProgress = false;
            boolean inProgressTested = false;

            do {
                ResourceConfigurationUpdate history2 = configurationManager.getLatestResourceConfigurationUpdate(
                    overlord, resourceId);
                inProgress = configurationManager.isResourceConfigurationUpdateInProgress(overlord, resourceId);

                if (inProgress) {
                    // history2 should be history1 since the update is not complete
                    assert history2 != null;
                    assert history2.getId() == history1.getId();
                    myprop = history2.getConfiguration().getSimple("myboolean");
                    assert myprop != null;
                    assert "true".equals(myprop.getStringValue());
                    myprop = history2.getConfiguration().getSimple("mysleep"); // this wasn't in the first config
                    assert myprop == null;
                    // record that this test case ran, we expect it will if the agent delay is there
                    inProgressTested = true;
                } else {
                    // update is complete, history 2 should be different
                    history2 = configurationManager.getLatestResourceConfigurationUpdate(overlord, resourceId);
                    assert history2 != null;
                    assert history2.getId() != history1.getId();
                    myprop = history2.getConfiguration().getSimple("myboolean");
                    assert myprop != null;
                    assert "false".equals(myprop.getStringValue());
                    myprop = history2.getConfiguration().getSimple("mysleep");
                    assert myprop.getLongValue() != null;
                    assert myprop.getLongValue().longValue() == 7000L;
                }
            } while (inProgress);
View Full Code Here

        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);
        }
View Full Code Here

            // 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());
View Full Code Here

        // 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;
View Full Code Here

        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());
        assert current.getCreatedTime() == newConfigUpdate.getCreatedTime();
        assert current.getModifiedTime() == newConfigUpdate.getModifiedTime();
        assert current.getConfiguration().getId() == newConfigUpdate.getConfiguration().getId();
    }
View Full Code Here

        configuration1.put(new PropertySimple("myboolean", "true"));

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

        ResourceConfigurationUpdate up;
        up = configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration1);
        Thread.sleep(2000); // wait for the test agent to complete the request
        assert configuration1.equals(configurationManager.getResourceConfiguration(resource.getId()));
        up = configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration2);
        Thread.sleep(2000); // wait for the test agent to complete the request
        assert configuration2.equals(configurationManager.getResourceConfiguration(resource.getId()));

        // at this point in time, the round trip messaging is done and we have the agent response
        List<ResourceConfigurationUpdate> requests;

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

        assert requests != null;
        assert requests.size() == 2 : "Got " + requests.size() + " config update requests - expected 2.";

        // delete the first one
        ResourceConfigurationUpdate doomedRequest = requests.get(0);
        ResourceConfigurationUpdate savedRequest = requests.get(1);

        configurationManager.purgeResourceConfigurationUpdates(overlord, new int[] { doomedRequest.getId() }, false);

        // now get the current configs/requests and
        // make sure we deleted just the one configuration, leaving one left
        requests = configurationManager.findResourceConfigurationUpdates(overlord, resource.getId(), null, null, false,
            configUpdatesPageControl);

        assert requests.size() == 1;
        assert requests.get(0).getId() == savedRequest.getId();
    }
View Full Code Here

        assert requests.get(0).getStatus() == ConfigurationUpdateStatus.FAILURE : "actual: "
            + requests.get(0).getStatus();
        assert requests.get(1).getStatus() == ConfigurationUpdateStatus.SUCCESS : "actual: "
            + requests.get(1).getStatus();

        ResourceConfigurationUpdate savedRequest = requests.get(0); // this is the one that failed
        ResourceConfigurationUpdate doomedRequest = requests.get(1); // this is the one that succeeded

        configurationManager.purgeResourceConfigurationUpdate(overlord, doomedRequest.getId(), false);

        // now get the current configs/requests and
        // make sure we deleted the only one configuration that succeeded, leaving one update record
        ResourceConfigurationUpdateCriteria criteria = new ResourceConfigurationUpdateCriteria();
        criteria.addFilterResourceIds(resource.getId());
        criteria.fetchConfiguration(true);
        criteria.addSortCreatedTime(PageOrdering.ASC);

        requests = configurationManager.findResourceConfigurationUpdatesByCriteria(overlord, criteria);

        assert requests.size() == 1;

        ResourceConfigurationUpdate request = requests.get(0);
        assert request.getId() == savedRequest.getId();
        assert request.getStatus().equals(ConfigurationUpdateStatus.FAILURE);
        assert request.getErrorMessage() != null;
        assert request.getErrorMessage().indexOf("This simulates a failed update") > 0;
        assert request.getConfiguration() != null;
        PropertySimple mybool = request.getConfiguration().getSimple("myboolean");
        assert mybool != null;
        assert mybool.getStringValue().equals("invalid-boolean");
        assert mybool.getErrorMessage().indexOf("Not a valid boolean") > 0;
    }
View Full Code Here

    }

    @Override
    public ResourceConfigurationUpdate getLatestResourceConfigurationUpdate(int resourceId) throws RuntimeException {
        try {
            ResourceConfigurationUpdate update = configurationManager.getLatestResourceConfigurationUpdate(
                getSessionSubject(), resourceId);
            return SerialUtility.prepare(update, "ConfigurationService.getLatestResourceConfigurationUpdate");
        } catch (Throwable t) {
            throw getExceptionToThrowToClient(t);
        }
View Full Code Here

    @Override
    public ResourceConfigurationUpdate updateResourceConfiguration(int resourceId, Configuration configuration)
        throws RuntimeException {
        try {
            ResourceConfigurationUpdate update = configurationManager.updateResourceConfiguration(getSessionSubject(),
                resourceId, configuration);
            return SerialUtility.prepare(update, "ConfigurationService.updateResourceConfiguration");
        } catch (Throwable t) {
            throw getExceptionToThrowToClient(t);
        }
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.configuration.ResourceConfigurationUpdate

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.