private String getDetailsURL(ResourceConfigurationUpdate configUpdate) { String protocol; if (request.isSecure()) { protocol = "https"; } else { protocol = "http"; } return protocol + "://" + request.getServerName() + ":" + request.getServerPort() + "/coregui/#Resource/" + configUpdate.getResource().getId() + "/Configuration/History/" + configUpdate.getId(); } };
/** * @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; }
@Override 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; }
@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 + "]"); } resource.getResourceConfigurationUpdates().remove(doomedRequest); entityManager.remove(doomedRequest); entityManager.flush(); return; }
private String toCSV(ResourceConfigurationUpdate configurationUpdate) { return configurationUpdate.getId() + "," + formatDateTime(configurationUpdate.getCreatedTime())+"," + formatDateTime(configurationUpdate.getModifiedTime())+"," + configurationUpdate.getStatus()+"," + cleanForCSV(configurationUpdate.getResource().getName())+ "," + cleanForCSV(ReportFormatHelper.parseAncestry(configurationUpdate.getResource().getAncestry())) + "," + getDetailsURL(configurationUpdate); //@todo: check dates, user, update-type }
public AlertConditionCacheStats checkConditions(ResourceConfigurationUpdate update) { if (update == null) { return new AlertConditionCacheStats(); } AlertConditionCacheStats stats = new AlertConditionCacheStats(); try { Resource resource = update.getResource(); List<ResourceConfigurationCacheElement> cacheElements = lookupResourceConfigurationCacheElements(resource .getId()); processCacheElements(cacheElements, update.getConfiguration(), update.getCreatedTime(), stats); AlertConditionCacheMonitor.getMBean().incrementResourceConfigurationCacheElementMatches(stats.matched); AlertConditionCacheMonitor.getMBean().incrementResourceConfigurationProcessingTime(stats.getAge()); if (log.isDebugEnabled()) log.debug("Check " + update + " - " + stats); } catch (Throwable t) { // don't let any exceptions bubble up to the calling SLSB layer log.error("Error during global cache processing: ", t); } return stats; }
Resource resource = update.getResource(); resource.setResourceConfiguration(update.getConfiguration().deepCopyWithoutProxies()); notifyAlertConditionCacheManager("completeResourceConfigurationUpdate", update);
query.setParameter("resourceId", resourceId); current = (ResourceConfigurationUpdate) query.getSingleResult(); resource = current.getResource(); } catch (NoResultException nre) {
@Override public PageList<ResourceConfigurationUpdate> findResourceConfigurationUpdatesByCriteria(Subject subject, ResourceConfigurationUpdateCriteria criteria) { CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria); if (!authorizationManager.isInventoryManager(subject)) { generator.setAuthorizationResourceFragment(CriteriaQueryGenerator.AuthorizationTokenType.RESOURCE, "resource", subject.getId()); } CriteriaQueryRunner<ResourceConfigurationUpdate> queryRunner = new CriteriaQueryRunner<ResourceConfigurationUpdate>( criteria, generator, entityManager); PageList<ResourceConfigurationUpdate> updates = queryRunner.execute(); // If configurations were fetched, mask them before returning the updates. // We do not want the masked configurations persisted, so detach all entities before masking the configurations. Set<String> fetchFields = new HashSet<String>(generator.getFetchFields(criteria)); if (fetchFields.contains(AbstractConfigurationUpdateCriteria.FETCH_FIELD_CONFIGURATION)) { for (ResourceConfigurationUpdate update : updates) { Configuration configuration = update.getConfiguration(); configuration.getMap().size(); } entityManager.clear(); for (ResourceConfigurationUpdate update : updates) { Configuration configuration = update.getConfiguration(); ConfigurationDefinition configurationDefinition = getResourceConfigurationDefinitionForResourceType( subjectManager.getOverlord(), update.getResource().getResourceType().getId()); ConfigurationMaskingUtility.maskConfiguration(configuration, configurationDefinition); } } return updates; }
/** * Tells the Agent to asynchronously update a managed resource's configuration as per the specified * <code>ResourceConfigurationUpdate</code>. */ private void executeResourceConfigurationUpdate(ResourceConfigurationUpdate update) { try { AgentClient agentClient = agentManager.getAgentClient(update.getResource().getAgent()); ConfigurationUpdateRequest request = new ConfigurationUpdateRequest(update.getId(), update.getConfiguration(), update.getResource().getId()); agentClient.getConfigurationAgentService().updateResourceConfiguration(request); } catch (RuntimeException e) { // Any exception means the remote call itself failed - make sure to change the status on the update to FAILURE // and set its error message field. if (null != update) { update.setStatus(ConfigurationUpdateStatus.FAILURE); update.setErrorMessage(ThrowableUtil.getStackAsString(e)); // Here we call ourselves, but we do so via the EJB interface so we pick up the REQUIRES_NEW semantics. this.configurationManager.mergeConfigurationUpdate(update); checkForCompletedGroupResourceConfigurationUpdate(update.getId()); } } }
@Override public void completeConfigurationUpdate(ConfigurationUpdateResponse response) { /* * Would be nice to get the resource name, but it is not in the response, so we could bring back the log message * that used to be 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; * this will perform the work in two separate transactions, thus ensuring that multiple updates from the same * group update see each others' results (RHQ-1810) */ configurationManager.completeResourceConfigurationUpdate(response); configurationManager.checkForCompletedGroupResourceConfigurationUpdate(configUpdateId); }
resource = current.getResource();