Package org.rhq.core.domain.configuration

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


    }

    @Override
    public void rollbackResourceConfiguration(Subject subject, int resourceId, int configHistoryId)
        throws ConfigurationUpdateException {
        ResourceConfigurationUpdate configurationUpdateHistory = entityManager.find(ResourceConfigurationUpdate.class,
            configHistoryId);
        Configuration configuration = configurationUpdateHistory.getConfiguration();
        if (configuration == null) {
            throw new ConfigurationUpdateException("No configuration history element exists with id = '"
                + configHistoryId + "'");
        }
View Full Code Here


    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public ResourceConfigurationUpdate persistResourceConfigurationUpdateInNewTransaction(Subject subject,
        int resourceId, Configuration newConfiguration, ConfigurationUpdateStatus newStatus, String newSubject,
        boolean isPartofGroupUpdate) throws ResourceNotFoundException, ConfigurationUpdateStillInProgressException {

        ResourceConfigurationUpdate current = null;
        String errorMessage = null;

        // for efficiency, in one query fetch IN_PROGRESS and/or the current update
        Query query = entityManager
            .createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_CURRENT_AND_IN_PROGRESS_CONFIGS);
        query.setParameter("resourceId", resourceId);
        List<?> updates = query.getResultList();
        for (Object result : updates) {
            current = (ResourceConfigurationUpdate) result;

            if (ConfigurationUpdateStatus.INPROGRESS == current.getStatus()) {
                // A previous update is still in progress for this Resource. If this update is part of a group
                // update, persist it with FAILURE status, so it is still listed as part of the group history.
                // Otherwise, throw an exception that can bubble up to the GUI.
                if (isPartofGroupUpdate) {
                    newStatus = ConfigurationUpdateStatus.FAILURE;
                    errorMessage = "Resource configuration Update was aborted because an update request for the Resource was already in progress.";

                } else {
                    // NOTE: If you change this to another exception, make sure you change getLatestResourceConfigurationUpdate().
                    throw new ConfigurationUpdateStillInProgressException(
                        "Resource ["
                            + resourceId
                            + "] has a resource configuration update request already in progress - please wait for it to finish: "
                            + current);
                }
            }
        }

        Resource resource = null;

        if (null != current) {
            // Always persist a group update because each member must have an update. Otherwise, only persist a
            // single resource update if it has changed.
            if (!isPartofGroupUpdate) {
                Configuration currentConfiguration = current.getConfiguration();
                Hibernate.initialize(currentConfiguration.getMap());
                if (currentConfiguration.equals(newConfiguration)) {
                    return null;
                }
            }

            resource = current.getResource();

        } else {
            // make sure the resource exists
            resource = resourceManager.getResourceById(subject, resourceId);
        }

        Configuration zeroedConfiguration = newConfiguration.deepCopyWithoutProxies();

        // create our new update request and assign it to our resource - its status will initially be INPROGRESS
        ResourceConfigurationUpdate newUpdateRequest = new ResourceConfigurationUpdate(resource, zeroedConfiguration,
            newSubject);
        newUpdateRequest.setStatus(newStatus);

        if (ConfigurationUpdateStatus.FAILURE == newStatus) {
            newUpdateRequest.setErrorMessage(errorMessage);
        }

        entityManager.persist(newUpdateRequest);

        // No need to alert on the first configuration update, only on subsequent change
View Full Code Here

        if (LOG.isDebugEnabled()) {
            LOG.debug("Received a configuration-update-completed message: " + response);
        }

        // find the current update request that is persisted - this is the one that is being reported as being complete
        ResourceConfigurationUpdate update = entityManager.find(ResourceConfigurationUpdate.class,
            response.getConfigurationUpdateId());
        if (update == null) {
            throw new IllegalStateException(
                "The completed request passed in does not match any request for any resource in inventory: " + response);
        }

        if (response.getStatus() == ConfigurationUpdateStatus.FAILURE) {
            // TODO [mazz]: what happens if the plugin dorked with the configuration ID? need to assert it hasn't changed
            if (response.getConfiguration() != null) {
                Configuration failedConfiguration = response.getConfiguration();
                failedConfiguration = entityManager.merge(failedConfiguration); // merge in any property error messages
                update.setConfiguration(failedConfiguration);
            }
        } else if (response.getStatus() == ConfigurationUpdateStatus.SUCCESS) {
            // link to the newer, persisted configuration object
            Resource resource = update.getResource();
            resource.setResourceConfiguration(update.getConfiguration().deepCopyWithoutProxies());
            notifyAlertConditionCacheManager("completeResourceConfigurationUpdate", update);
        }

        // Make sure we update the persisted request with the new status and any error message.
        update.setStatus(response.getStatus());
        update.setErrorMessage(response.getErrorMessage());

        /*
         * instead of checking for completed group resource configuration updates here, let our caller (the
         * ConfigurationServerService) do it so that this transaction completes before the check begins
         */
 
View Full Code Here

    }

    @Override
    @SuppressWarnings("unchecked")
    public void checkForCompletedGroupResourceConfigurationUpdate(int resourceConfigUpdateId) {
        ResourceConfigurationUpdate resourceConfigUpdate = entityManager.find(ResourceConfigurationUpdate.class,
            resourceConfigUpdateId);
        if (resourceConfigUpdate.getStatus() == ConfigurationUpdateStatus.INPROGRESS) {
            // If this update isn't done, then, by definition, the group update isn't done either.
            return;
        }

        GroupResourceConfigurationUpdate groupConfigUpdate = resourceConfigUpdate.getGroupConfigurationUpdate();
        if (groupConfigUpdate == null) {
            // The update isn't part of a group update - nothing we need to do.
            return;
        }
View Full Code Here

            // Make sure to unmask the configuration before persisting the update.
            Resource resource = resourceManager.getResource(subjectManager.getOverlord(), resourceId);
            Configuration existingResourceConfiguration = resource.getResourceConfiguration();
            ConfigurationMaskingUtility.unmaskConfiguration(memberResourceConfiguration, existingResourceConfiguration);
            Resource flyWeight = new Resource(resourceId);
            ResourceConfigurationUpdate memberUpdate = new ResourceConfigurationUpdate(flyWeight,
                memberResourceConfiguration, subject.getName());
            memberUpdate.setGroupConfigurationUpdate(groupUpdate);
            entityManager.persist(memberUpdate);
        }

        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.putAsString(AbstractGroupConfigurationUpdateJob.DATAMAP_INT_CONFIG_GROUP_UPDATE_ID, updateId);
View Full Code Here

    @Override
    @RequiredPermission(Permission.MANAGE_SETTINGS)
    public StorageNodeConfigurationComposite retrieveConfiguration(Subject subject, StorageNode storageNode) {
        if (storageNode != null && storageNode.getResource() != null) {
            Resource storageNodeResource = storageNode.getResource();
            ResourceConfigurationUpdate configurationUpdate = configurationManager
                .getLatestResourceConfigurationUpdate(subject, storageNodeResource.getId());
            Configuration storageNodeConfiguration = configurationUpdate.getConfiguration();

            Configuration storageNodePluginConfiguration = configurationManager.getPluginConfiguration(subject,
                storageNodeResource.getId());

            if (configurationUpdate != null) {
View Full Code Here

            if(!existingStorageNodeConfigurationComposite.isDirectoriesEqual(newStorageNodeConfigurationComposite)) {
                storageNodeResourceConfig.setSimpleValue(StorageNodeConfigurationUtil.RHQ_STORAGE_NOTIFY_DIR_CHANGE_PROPERTY, Boolean.TRUE.toString());
            }

            ResourceConfigurationUpdate resourceUpdate = configurationManager.updateResourceConfiguration(subject, storageNodeResource.getId(),
                storageNodeResourceConfig);

            // initial waiting before the first check
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                // nothing
            }
            // wait for the resource config update
            ResourceConfigurationUpdateCriteria criteria = new ResourceConfigurationUpdateCriteria();
            criteria.addFilterId(resourceUpdate.getId());
            criteria.addFilterStartTime(System.currentTimeMillis() - (5 * 60 * 1000));
            boolean updateSuccess = waitForConfigurationUpdateToFinish(subject, criteria, 10);

            // restart the storage node and wait for it
            boolean restartSuccess = runOperationAndWaitForResult(subject, storageNodeResource, RESTART_OPERATION,
View Full Code Here

         */
        ConfigurationManagerLocal configurationManager = LookupUtil.getConfigurationManager();
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();

        int configUpdateId = response.getConfigurationUpdateId();
        ResourceConfigurationUpdate configUpdate = configurationManager.getResourceConfigurationUpdate(
            subjectManager.getOverlord(), configUpdateId);

        if (configUpdate != null) {
            Resource resource = configUpdate.getResource();
            if (resource != null)
                LOG.debug("Resource configuration update [" + configUpdate.getId() + "] for " + resource
                    + " completed with status [" + response.getStatus() + "].");
        }

        /*
         * perform the check for completed group updates AFTER completing the individual resource configuration update;
View Full Code Here

    public void persistUpdatedResourceConfiguration(int resourceId, Configuration resourceConfiguration) {
        ConfigurationManagerLocal configurationManager = LookupUtil.getConfigurationManager();
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();

        Subject overlord = subjectManager.getOverlord();
        ResourceConfigurationUpdate update = configurationManager.persistResourceConfigurationUpdateInNewTransaction(
            overlord, resourceId, resourceConfiguration, ConfigurationUpdateStatus.SUCCESS, null, false);

        if (update == null) {
            LOG.debug("Not persisting Configuration " + resourceConfiguration
                + ", since it is identical to the current revision.");
            return;
        }

        Configuration configuration = update.getConfiguration().deepCopy(false); // clone the config, zeroing out ids
        configurationManager.setResourceConfiguration(resourceId, configuration); // now set it as the current config on the Resource
    }
View Full Code Here

    @Test
    public void updateStructuredResourceConfigShouldUpdateAuditTrailAndSendUpdateToAgent() throws Exception {
        final ResourceConfigUpdateFixture fixture = newStructuredResourceConfigUpdateFixture();

        final ResourceConfigurationUpdate expectedUpdate = new ResourceConfigurationUpdate(fixture.resource,
            fixture.configuration, fixture.subject.getName());

        final AgentClient agentClient = context.mock(AgentClient.class);
        final ConfigurationAgentService configAgentService = context.mock(ConfigurationAgentService.class);

        final ConfigurationUpdateRequest expectedUpdateRequest = new ConfigurationUpdateRequest(expectedUpdate.getId(),
            expectedUpdate.getConfiguration(), expectedUpdate.getResource().getId());

        final Query query = context.mock(Query.class);

        context.checking(new Expectations() {
            {
                allowing(subjectMgr).getOverlord();
                will(returnValue(OVERLORD));

                allowing(resourceMgr).getResource(OVERLORD, fixture.resourceId);
                will(returnValue(fixture.resource));

                oneOf(authorizationMgr).hasResourcePermission(fixture.subject, CONFIGURE_WRITE, fixture.resourceId);
                will(returnValue(true));

                allowing(entityMgr).find(Resource.class, fixture.resourceId);
                will(returnValue(fixture.resource));

                oneOf(configurationMgrLocal).persistResourceConfigurationUpdateInNewTransaction(fixture.subject,
                    fixture.resourceId, fixture.configuration, INPROGRESS, fixture.subject.getName(),
                    fixture.isPartOfGroupUpdate);
                will(returnValue(expectedUpdate));

                allowing(agentMgr).getAgentClient(expectedUpdate.getResource().getAgent());
                will(returnValue(agentClient));

                allowing(agentClient).getConfigurationAgentService();
                will(returnValue(configAgentService));

                oneOf(configAgentService).updateResourceConfiguration(
                    with(matchingUpdateRequest(expectedUpdateRequest)));

                allowing(entityMgr).createNamedQuery("ConfigurationDefinition.findResourceByResourceTypeId");
                will(returnValue(query));
                allowing(query).setParameter("resourceTypeId", fixture.resourceTypeId);
                allowing(query).getSingleResult();
                will(returnValue(fixture.configurationDefinition));

                oneOf(configurationMgrLocal).getResourceConfigurationDefinitionForResourceType(fixture.subject,
                    fixture.resourceTypeId);
                will(returnValue(fixture.configurationDefinition));
            }
        });

        ResourceConfigurationUpdate actualUpdate = configurationMgr.updateResourceConfiguration(fixture.subject,
            fixture.resourceId, fixture.configuration);

        assertSame(actualUpdate, expectedUpdate, "Expected to get back the persisted configuration update");
    }
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.