Package org.rhq.core.domain.configuration

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


        if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_READ, resource.getId())) {
            throw new PermissionException("User [" + subject.getName()
                + "] does not have permission to view Resource configuration for [" + resource + "].");
        }

        ResourceConfigurationUpdate current;
        // Get the latest configuration as known to the server (i.e. persisted in the DB).
        try {
            Query query = entityManager
                .createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_CURRENTLY_ACTIVE_CONFIG);
            query.setParameter("resourceId", resourceId);
            current = (ResourceConfigurationUpdate) query.getSingleResult();
            resource = current.getResource();
        } catch (NoResultException nre) {
            // The Resource hasn't been successfully configured yet - return null.
            current = null;
        }

        // Check whether or not a resource configuration update is currently in progress.
        ResourceConfigurationUpdate latest;
        try {
            Query query = entityManager.createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_LATEST_BY_RESOURCE_ID);
            query.setParameter("resourceId", resourceId);
            latest = (ResourceConfigurationUpdate) query.getSingleResult();
            if (latest.getStatus() == ConfigurationUpdateStatus.INPROGRESS) {
                // The agent is in the process of a config update, so we do not want to ask it for the live config.
                // Instead, simply return the most recent persisted config w/ a SUCCESS status (possibly null).
                if (current != null) {
                    // Fetch and mask the configuration before returning the update.
                    Configuration configuration = current.getConfiguration();
View Full Code Here


        * and *not* the user, is choosing to persist the most recent configuration because it was different
        * from the last known value.  again, the user isn't attempting to change the value; instead, *JON*
        * is triggering save based on the semantics that we want to provide for configuration updates.
        * For the same reason, we pass null as the subject.
        */
        ResourceConfigurationUpdate update = this.configurationManager
            .persistResourceConfigurationUpdateInNewTransaction(this.subjectManager.getOverlord(), resource.getId(),
                liveConfig, ConfigurationUpdateStatus.SUCCESS, null, false);

        // resource.setResourceConfiguration(liveConfig.deepCopy(false));
        resource.setResourceConfiguration(liveConfig.deepCopyWithoutProxies());
View Full Code Here

    public boolean isResourceConfigurationUpdateInProgress(Subject subject, int resourceId) {
        boolean updateInProgress;
        try {
            Query query = entityManager.createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_LATEST_BY_RESOURCE_ID);
            query.setParameter("resourceId", resourceId);
            ResourceConfigurationUpdate latestConfigUpdate = (ResourceConfigurationUpdate) query.getSingleResult();
            if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_READ, latestConfigUpdate
                .getResource().getId())) {
                throw new PermissionException("User [" + subject.getName()
                    + "] does not have permission to view Resource configuration for ["
                    + latestConfigUpdate.getResource() + "]");
            }
            updateInProgress = (latestConfigUpdate.getStatus() == ConfigurationUpdateStatus.INPROGRESS);
        } catch (NoResultException nre) {
            // The resource config history is empty, so there's obviously no update in progress.
            updateInProgress = false;
        }
        return updateInProgress;
View Full Code Here

            Configuration liveConfig = liveConfigs.get(memberResource.getId());
            // NOTE: The persisted config may be null if no config has been persisted yet.
            Configuration currentPersistedConfig = currentPersistedConfigs.get(memberResource.getId());
            if (!liveConfig.equals(currentPersistedConfig)) {
                // If the live config is different than the persisted config, persist it as the new current config.
                ResourceConfigurationUpdate update = persistNewAgentReportedResourceConfiguration(memberResource,
                    liveConfig);
                if (update != null) {
                    currentPersistedConfigs.put(memberResource.getId(), update.getConfiguration());
                    LOG.info("Live configuration for [" + memberResource
                        + "] did not match latest associated ResourceConfigurationUpdate with SUCCESS status.");
                } else {
                    // this means the live config is identical to the persisted config
                    currentPersistedConfigs.put(memberResource.getId(), liveConfig);
View Full Code Here

        List<ResourceConfigurationUpdate> updates = query.getResultList();

        if (suppressOldest == false && updates.size() == 0) {
            // there is no configuration yet - get the latest from the agent, if possible
            updates = new ArrayList<ResourceConfigurationUpdate>();
            ResourceConfigurationUpdate latest = getLatestResourceConfigurationUpdate(subject, resourceId);
            if (latest != null) {
                updates.add(latest);
            }
        }
View Full Code Here

     * @deprecated use criteria-based API
     */
    @Deprecated
    @Override
    public ResourceConfigurationUpdate getResourceConfigurationUpdate(Subject subject, int configurationUpdateId) {
        ResourceConfigurationUpdate update = entityManager.find(ResourceConfigurationUpdate.class,
            configurationUpdateId);

        if (!authorizationManager.canViewResource(subject, update.getResource().getId())) {
            throw new PermissionException("User [" + subject.getName()
                + "] does not have permission to view resource configuration update for [" + update.getResource() + "]");
        }

        update.getConfiguration(); // this is EAGER loaded, so this really doesn't do anything

        return update;
    }
View Full Code Here

        return;
    }

    @Override
    public void purgeResourceConfigurationUpdate(Subject subject, int configurationUpdateId, boolean purgeInProgress) {
        ResourceConfigurationUpdate doomedRequest = entityManager.find(ResourceConfigurationUpdate.class,
            configurationUpdateId);

        if (doomedRequest == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Asked to purge a non-existing config update request [" + configurationUpdateId + "]");
            }
            return;
        }

        if ((doomedRequest.getStatus() == ConfigurationUpdateStatus.INPROGRESS) && !purgeInProgress) {
            throw new IllegalStateException(
                "The update request is still in the in-progress state. Please wait for it to complete: "
                    + doomedRequest);
        }

        // make sure the user has the proper permissions to do this
        Resource resource = doomedRequest.getResource();
        if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_WRITE, resource.getId())) {
            throw new PermissionException("User [" + subject.getName()
                + "] does not have permission to purge a configuration update audit trail for resource [" + resource
                + "]");
        }
View Full Code Here

        try {
            Configuration invalidConfig = validateResourceConfiguration(subject, resourceId, newConfiguration,
                fromStructured);
            if (null != invalidConfig) {
                Resource resource = resourceManager.getResourceById(subject, resourceId);
                ResourceConfigurationUpdate resourceConfigurationUpdate = new ResourceConfigurationUpdate(resource,
                    invalidConfig, subject.getName());
                resourceConfigurationUpdate.setErrorMessage("resource.validation.failed");
                resourceConfigurationUpdate.setStatus(ConfigurationUpdateStatus.FAILURE);

                return resourceConfigurationUpdate;
            }
        } catch (PluginContainerException e) {
            Resource resource = resourceManager.getResourceById(subject, resourceId);
            ResourceConfigurationUpdate resourceConfigurationUpdate = new ResourceConfigurationUpdate(resource,
                newConfiguration, subject.getName());
            resourceConfigurationUpdate.setErrorMessage(e.getMessage());
            resourceConfigurationUpdate.setStatus(ConfigurationUpdateStatus.FAILURE);
            return resourceConfigurationUpdate;
        }

        ResourceConfigurationUpdate newUpdate = configurationManager
            .persistResourceConfigurationUpdateInNewTransaction(subject, resourceId, configToUpdate,
                ConfigurationUpdateStatus.INPROGRESS, subject.getName(), false);
        executeResourceConfigurationUpdate(newUpdate);
        return newUpdate;
    }
View Full Code Here

        // the update in a separate transaction; this way, the update is committed prior to sending the agent request
        // Note, the persist method will return null if newConfiguration is no different than the current Resource
        // configuration.
        // TODO: Consider synchronizing to avoid the condition where someone calls this method twice quickly in two
        // different tx's, which would put two updates in INPROGRESS and cause havoc.
        ResourceConfigurationUpdate newUpdate = configurationManager
            .persistResourceConfigurationUpdateInNewTransaction(subject, resourceId, newResourceConfiguration,
                ConfigurationUpdateStatus.INPROGRESS, subject.getName(), false);

        executeResourceConfigurationUpdate(newUpdate);
View Full Code Here

        return newUpdate;
    }

    @Override
    public void executeResourceConfigurationUpdate(int updateId) {
        ResourceConfigurationUpdate update = getResourceConfigurationUpdate(subjectManager.getOverlord(), updateId);
        Configuration originalConfig = update.getConfiguration();
        update.setConfiguration(originalConfig.deepCopy(false));
        executeResourceConfigurationUpdate(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.