modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java | 523 +++++----- modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java | 10 2 files changed, 274 insertions(+), 259 deletions(-)
New commits: commit e1c81ab6769109cce3d01ecec265df8508f438bb Author: Filip Drabek fdrabek@dhcp-lab-136.englab.brq.redhat.com Date: Thu Nov 18 09:12:06 2010 +0100
reverting of BZ-648790 - user needs only View Group permission to see Group Plugin Configuration Update
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java index 90f28d4..c49aa9d 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/configuration/ConfigurationManagerBean.java @@ -1,20 +1,14 @@ /* - * RHQ Management Platform - * Copyright (C) 2005-2010 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * RHQ Management Platform Copyright (C) 2005-2010 Red Hat, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.rhq.enterprise.server.configuration;
@@ -109,7 +103,7 @@ import org.rhq.enterprise.server.util.QuartzUtil;
/** * The manager responsible for working with resource and plugin configurations. - * + * * @author John Mazzitelli * @author Ian Springer */ @@ -150,7 +144,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
if (!authorizationManager.canViewResource(subject, resourceId)) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to view plugin configuration for [" + resource + "]"); + + "] does not have permission to view plugin configuration for [" + resource + "]"); }
Configuration pluginConfiguration = configurationManager.getPluginConfiguration(resourceId); @@ -159,7 +153,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
// Use new transaction because this only works if the resource in question has not - // yet been loaded by Hibernate. We want the query to return a non-proxied configuration, + // yet been loaded by Hibernate. We want the query to return a non-proxied configuration, // this is critical for remote API use. @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public Configuration getPluginConfiguration(int resourceId) { @@ -200,15 +194,16 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf entityManager.merge(update);
} else { - handlePluginConfiguratonUpdateRemoteException(resource, response.getStatus().toString(), - response.getErrorMessage()); + handlePluginConfiguratonUpdateRemoteException(resource, response.getStatus().toString(), response + .getErrorMessage());
update.setStatus(response.getStatus()); update.setErrorMessage(response.getErrorMessage()); } }
- // use requires new so that exceptions bubbling up from the agent.updatePluginConfiguration don't force callers to rollback as well + // use requires new so that exceptions bubbling up from the agent.updatePluginConfiguration don't force callers to + // rollback as well @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public ConfigurationUpdateResponse executePluginConfigurationUpdate(PluginConfigurationUpdate update) { Resource resource = update.getResource(); @@ -226,7 +221,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf agentClient.getDiscoveryAgentService().executeServiceScanDeferred(); } catch (Exception e) { log.warn("Failed to execute service scan - cannot detect children of the newly connected resource [" - + resource + "]", e); + + resource + "]", e); }
response = new ConfigurationUpdateResponse(update.getId(), null, ConfigurationUpdateStatus.SUCCESS, null); @@ -238,7 +233,8 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public PluginConfigurationUpdate updatePluginConfiguration(Subject subject, int resourceId, - @XmlJavaTypeAdapter(ConfigurationAdapter.class) Configuration configuration) throws ResourceNotFoundException { + @XmlJavaTypeAdapter(ConfigurationAdapter.class) Configuration configuration) + throws ResourceNotFoundException { Subject overlord = subjectManager.getOverlord(); Resource resource = resourceManager.getResourceById(overlord, resourceId);
@@ -274,7 +270,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
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 + "]"); + + "] does not have permission to view resource configuration for [" + resource + "]"); }
Configuration result = configurationManager.getResourceConfiguration(resourceId); @@ -283,7 +279,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
// Use new transaction because this only works if the resource in question has not - // yet been loaded by Hibernate. We want the query to return a non-proxied configuration, + // yet been loaded by Hibernate. We want the query to return a non-proxied configuration, // this is critical for remote API use. @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public Configuration getResourceConfiguration(int resourceId) { @@ -297,7 +293,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public ResourceConfigurationUpdate getLatestResourceConfigurationUpdate(Subject subject, int resourceId, - boolean fromStructured) { + boolean fromStructured) { log.debug("Getting current resource configuration for resource [" + resourceId + "]");
Resource resource; @@ -306,7 +302,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf // 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); + .createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_CURRENTLY_ACTIVE_CONFIG); query.setParameter("resourceId", resourceId); current = (ResourceConfigurationUpdate) query.getSingleResult(); resource = current.getResource(); @@ -317,13 +313,13 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf resource = entityManager.find(Resource.class, resourceId); if (resource == null) { throw new NoResultException("Cannot get latest resource configuration for unknown resource [" - + resourceId + "]"); + + resourceId + "]"); } }
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 + "]"); + + "] does not have permission to view resource configuration for [" + resource + "]"); }
// Check whether or not a resource configuration update is currently in progress. @@ -364,12 +360,12 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf // not effect our current transaction since the persist call was made with REQUIRES_NEW // and thus only that new tx was rolled back log.debug("Resource is currently in progress of changing its resource configuration - " - + "since it hasn't finished yet, will use the last successful resource configuration: " + e); + + "since it hasn't finished yet, will use the last successful resource configuration: " + e); } } } else { log.warn("Could not get live resource configuration for resource [" + resource - + "]; will assume latest resource configuration update is the current resource configuration."); + + "]; will assume latest resource configuration update is the current resource configuration."); }
return current; @@ -381,7 +377,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
private ResourceConfigurationUpdate persistNewAgentReportedResourceConfiguration(Resource resource, - Configuration liveConfig) throws ConfigurationUpdateStillInProgressException { + Configuration liveConfig) throws ConfigurationUpdateStillInProgressException {
if (liveConfig.getRawConfigurations() != null) { for (RawConfiguration raw : liveConfig.getRawConfigurations()) { @@ -392,16 +388,15 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
/* - * NOTE: We pass the overlord, since this is a system side-effect. here, the system - * 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. - */ + * NOTE: We pass the overlord, since this is a system side-effect. here, the system 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.persistNewResourceConfigurationUpdateHistory( - this.subjectManager.getOverlord(), resource.getId(), liveConfig, ConfigurationUpdateStatus.SUCCESS, null, - false); - //resource.setResourceConfiguration(liveConfig.deepCopy(false)); + this.subjectManager.getOverlord(), resource.getId(), liveConfig, ConfigurationUpdateStatus.SUCCESS, + null, false); + // resource.setResourceConfiguration(liveConfig.deepCopy(false)); resource.setResourceConfiguration(liveConfig.deepCopyWithoutProxies()); return update; } @@ -425,13 +420,13 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf resource = entityManager.find(Resource.class, resourceId); if (resource == null) { throw new NoResultException("Cannot get latest plugin configuration for unknown resource [" - + resourceId + "]"); + + resourceId + "]"); } }
if (!authorizationManager.canViewResource(subject, resource.getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to view plugin configuration for [" + resource + "]"); + + "] does not have permission to view plugin configuration for [" + resource + "]"); }
return current; @@ -444,10 +439,10 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf query.setParameter("resourceId", resourceId); ResourceConfigurationUpdate latestConfigUpdate = (ResourceConfigurationUpdate) query.getSingleResult(); if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_READ, latestConfigUpdate - .getResource().getId())) { + .getResource().getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to view Resource configuration for [" - + latestConfigUpdate.getResource() + "]"); + + "] does not have permission to view Resource configuration for [" + + latestConfigUpdate.getResource() + "]"); } updateInProgress = (latestConfigUpdate.getStatus() == ConfigurationUpdateStatus.INPROGRESS); } catch (NoResultException nre) { @@ -465,8 +460,8 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf PluginConfigurationUpdate latestConfigUpdate = (PluginConfigurationUpdate) query.getSingleResult(); if (!authorizationManager.canViewResource(subject, latestConfigUpdate.getResource().getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to view plugin configuration for [" - + latestConfigUpdate.getResource() + "]"); + + "] does not have permission to view plugin configuration for [" + + latestConfigUpdate.getResource() + "]"); } updateInProgress = (latestConfigUpdate.getStatus() == ConfigurationUpdateStatus.INPROGRESS); } catch (NoResultException nre) { @@ -480,14 +475,14 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf boolean updateInProgress; try { Query query = entityManager - .createNamedQuery(GroupResourceConfigurationUpdate.QUERY_FIND_LATEST_BY_GROUP_ID); + .createNamedQuery(GroupResourceConfigurationUpdate.QUERY_FIND_LATEST_BY_GROUP_ID); query.setParameter("groupId", groupId); GroupResourceConfigurationUpdate latestConfigGroupUpdate = (GroupResourceConfigurationUpdate) query - .getSingleResult(); + .getSingleResult(); if (!authorizationManager.canViewGroup(subject, latestConfigGroupUpdate.getGroup().getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to view group Resource configuration for [" - + latestConfigGroupUpdate.getGroup() + "]"); + + "] does not have permission to view group Resource configuration for [" + + latestConfigGroupUpdate.getGroup() + "]"); }
updateInProgress = (latestConfigGroupUpdate.getStatus() == ConfigurationUpdateStatus.INPROGRESS); @@ -505,11 +500,11 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf Query query = entityManager.createNamedQuery(GroupPluginConfigurationUpdate.QUERY_FIND_LATEST_BY_GROUP_ID); query.setParameter("groupId", groupId); GroupPluginConfigurationUpdate latestConfigGroupUpdate = (GroupPluginConfigurationUpdate) query - .getSingleResult(); + .getSingleResult(); if (!authorizationManager.canViewGroup(subject, latestConfigGroupUpdate.getGroup().getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to view group plugin configuration for [" - + latestConfigGroupUpdate.getGroup() + "]"); + + "] does not have permission to view group plugin configuration for [" + + latestConfigGroupUpdate.getGroup() + "]"); }
updateInProgress = (latestConfigGroupUpdate.getStatus() == ConfigurationUpdateStatus.INPROGRESS); @@ -522,11 +517,11 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public Map<Integer, Configuration> getResourceConfigurationsForCompatibleGroup(Subject subject, int groupId) - throws ConfigurationUpdateStillInProgressException, Exception { + throws ConfigurationUpdateStillInProgressException, Exception {
if (authorizationManager.hasGroupPermission(subject, Permission.CONFIGURE_READ, groupId) == false) { throw new PermissionException("User[name=" + subject.getName() - + "] does not have permission to view configuration for group[id=" + groupId + "]"); + + "] does not have permission to view configuration for group[id=" + groupId + "]"); }
// The below call will also handle the check to see if the subject has perms to view the group. @@ -538,10 +533,10 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
AvailabilityType availability = (groupComposite.getExplicitAvail() == 1) ? AvailabilityType.UP - : AvailabilityType.DOWN; + : AvailabilityType.DOWN; if (availability == AvailabilityType.DOWN) throw new Exception("Current group Resource configuration for " + groupId - + " cannot be calculated, because one or more of this group's member Resources are DOWN."); + + " cannot be calculated, because one or more of this group's member Resources are DOWN.");
// If we got this far, all member Resources are UP. Now check to make sure no config updates, group-level or // resource-level, are in progress. @@ -554,7 +549,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf int userPreferencesTimeout = new SubjectPreferences(subject).getGroupConfigurationTimeoutPeriod(); Set<Resource> groupMembers = group.getExplicitResources(); Map<Integer, Configuration> liveConfigs = LiveConfigurationLoader.getInstance().loadLiveResourceConfigurations( - groupMembers, userPreferencesTimeout); + groupMembers, userPreferencesTimeout);
// If we got this far, we were able to retrieve all of the live configs from the Agents. Now load the current // persisted configs from the DB and compare them to the corresponding live configs. For any that are not equal, @@ -567,22 +562,22 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf 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); + liveConfig); if (update != null) currentPersistedConfigs.put(memberResource.getId(), update.getConfiguration()); else log.error("Current Configuration for " + memberResource - + " does not match latest associated ResourceConfigurationUpdate with SUCCESS status."); + + " does not match latest associated ResourceConfigurationUpdate with SUCCESS status."); } } return currentPersistedConfigs; }
public Map<Integer, Configuration> getPluginConfigurationsForCompatibleGroup(Subject subject, int groupId) - throws ConfigurationUpdateStillInProgressException, Exception { + throws ConfigurationUpdateStillInProgressException, Exception { // The below call will also handle the check to see if the subject has perms to view the group. ResourceGroup group = this.resourceGroupManager - .getResourceGroupById(subject, groupId, GroupCategory.COMPATIBLE); + .getResourceGroupById(subject, groupId, GroupCategory.COMPATIBLE);
// Check to make sure no config updates, group-level or resource-level, are in progress. ensureNoPluginConfigurationUpdatesInProgress(group); @@ -595,16 +590,16 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
@SuppressWarnings("unchecked") private void ensureNoResourceConfigurationUpdatesInProgress(ResourceGroup compatibleGroup) - throws ConfigurationUpdateStillInProgressException { + throws ConfigurationUpdateStillInProgressException { if (isGroupResourceConfigurationUpdateInProgress(this.subjectManager.getOverlord(), compatibleGroup.getId())) { throw new ConfigurationUpdateStillInProgressException("Current group Resource configuration for " - + compatibleGroup - + " cannot be calculated, because a group Resource configuration update is currently in progress " - + " (please wait for this update to complete or delete it from the history)."); + + compatibleGroup + + " cannot be calculated, because a group Resource configuration update is currently in progress " + + " (please wait for this update to complete or delete it from the history)."); }
Query countQuery = PersistenceUtility.createCountQuery(entityManager, - ResourceConfigurationUpdate.QUERY_FIND_BY_GROUP_ID_AND_STATUS); + ResourceConfigurationUpdate.QUERY_FIND_BY_GROUP_ID_AND_STATUS); countQuery.setParameter("groupId", compatibleGroup.getId()); countQuery.setParameter("status", ConfigurationUpdateStatus.INPROGRESS); long count = (Long) countQuery.getSingleResult(); @@ -613,20 +608,21 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf query.setParameter("groupId", compatibleGroup.getId()); query.setParameter("status", ConfigurationUpdateStatus.INPROGRESS); List<Resource> resources = query.getResultList(); - throw new ConfigurationUpdateStillInProgressException("Current group Resource configuration for " - + compatibleGroup - + " cannot be calculated, because Resource configuration updates are currently in progress for the" - + " following Resources (please wait for these updates to complete or delete them from the history): " - + resources); + throw new ConfigurationUpdateStillInProgressException( + "Current group Resource configuration for " + + compatibleGroup + + " cannot be calculated, because Resource configuration updates are currently in progress for the" + + " following Resources (please wait for these updates to complete or delete them from the history): " + + resources); } }
private void ensureNoPluginConfigurationUpdatesInProgress(ResourceGroup compatibleGroup) - throws ConfigurationUpdateStillInProgressException { + throws ConfigurationUpdateStillInProgressException { if (isGroupPluginConfigurationUpdateInProgress(this.subjectManager.getOverlord(), compatibleGroup.getId())) { throw new ConfigurationUpdateStillInProgressException("Current group plugin configuration for " - + compatibleGroup - + " cannot be calculated, because a group plugin configuration update is currently in progress."); + + compatibleGroup + + " cannot be calculated, because a group plugin configuration update is currently in progress."); } List<Resource> resourcesWithPluginConfigUpdatesInProgress = new ArrayList<Resource>(); for (Resource memberResource : compatibleGroup.getExplicitResources()) { @@ -635,22 +631,22 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf } if (!resourcesWithPluginConfigUpdatesInProgress.isEmpty()) throw new ConfigurationUpdateStillInProgressException( - "Current group plugin configuration for " - + compatibleGroup - + " cannot be calculated, because plugin configuration updates are currently in progress for the following Resources: " - + resourcesWithPluginConfigUpdatesInProgress); + "Current group plugin configuration for " + + compatibleGroup + + " cannot be calculated, because plugin configuration updates are currently in progress for the following Resources: " + + resourcesWithPluginConfigUpdatesInProgress); }
@SuppressWarnings("unchecked") private Map<Integer, Configuration> getPersistedResourceConfigurationsForCompatibleGroup( - ResourceGroup compatibleGroup) { + ResourceGroup compatibleGroup) { Query countQuery = PersistenceUtility.createCountQuery(entityManager, - Configuration.QUERY_GET_RESOURCE_CONFIG_MAP_BY_GROUP_ID); + Configuration.QUERY_GET_RESOURCE_CONFIG_MAP_BY_GROUP_ID); countQuery.setParameter("resourceGroupId", compatibleGroup.getId()); long count = (Long) countQuery.getSingleResult(); if (count != compatibleGroup.getExplicitResources().size()) throw new IllegalStateException("Size of group changed from " - + compatibleGroup.getExplicitResources().size() + " to " + count + " - please retry the operation."); + + compatibleGroup.getExplicitResources().size() + " to " + count + " - please retry the operation.");
// Configurations are very expensive to load, so load 'em in chunks to ease the strain on the DB. PageControl pageControl = new PageControl(0, 10); @@ -681,12 +677,12 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf @SuppressWarnings("unchecked") private Map<Integer, Configuration> getPersistedPluginConfigurationsForCompatibleGroup(ResourceGroup compatibleGroup) { Query countQuery = PersistenceUtility.createCountQuery(entityManager, - Configuration.QUERY_GET_PLUGIN_CONFIG_MAP_BY_GROUP_ID); + Configuration.QUERY_GET_PLUGIN_CONFIG_MAP_BY_GROUP_ID); countQuery.setParameter("resourceGroupId", compatibleGroup.getId()); long count = (Long) countQuery.getSingleResult(); if (count != compatibleGroup.getExplicitResources().size()) throw new IllegalStateException("Size of group changed from " - + compatibleGroup.getExplicitResources().size() + " to " + count + " - please retry the operation."); + + compatibleGroup.getExplicitResources().size() + " to " + count + " - please retry the operation.");
// Configurations are very expensive to load, so load 'em in chunks to ease the strain on the DB. PageControl pageControl = new PageControl(0, 20); @@ -715,12 +711,12 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public Configuration getLiveResourceConfiguration(Subject subject, int resourceId, boolean pingAgentFirst) - throws Exception { + throws Exception { return getLiveResourceConfiguration(subject, resourceId, pingAgentFirst, true); }
public Configuration getLiveResourceConfiguration(Subject subject, int resourceId, boolean pingAgentFirst, - boolean fromStructured) throws Exception { + boolean fromStructured) throws Exception { Resource resource = entityManager.find(Resource.class, resourceId);
if (resource == null) { @@ -729,7 +725,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
if (!authorizationManager.canViewResource(subject, resource.getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to view resource configuration for [" + resource + "]"); + + "] does not have permission to view resource configuration for [" + resource + "]"); }
// ask the agent to get us the live, most up-to-date configuration for the resource @@ -749,7 +745,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf private void checkForTimedOutResourceConfigurationUpdateRequests() { try { // TODO (ips): Optimize this so the query actually does the timeout check too, - // i.e. "WHERE cu.createdtime > :maxCreatedTime". + // i.e. "WHERE cu.createdtime > :maxCreatedTime". Query query = entityManager.createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_ALL_IN_STATUS); query.setParameter("status", ConfigurationUpdateStatus.INPROGRESS); List<ResourceConfigurationUpdate> requests = query.getResultList(); @@ -760,9 +756,9 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf long duration = request.getDuration(); if (duration > timeout) { log.info("Resource configuration update request seems to have been orphaned - timing it out: " - + request); + + request); request.setErrorMessage("Timed out - did not complete after " + duration + " ms" - + " (the timeout period was " + timeout + " ms)"); + + " (the timeout period was " + timeout + " ms)"); request.setStatus(ConfigurationUpdateStatus.FAILURE); // If it's part of a group update, check if all member updates of the group update have completed, // and, if so, update the group update's status. @@ -778,22 +774,22 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf private void checkForTimedOutGroupResourceConfigurationUpdateRequests() { try { // TODO (ips): Optimize this so the query actually does the timeout check too, - // i.e. "WHERE cu.createdtime > :maxCreatedTime". + // i.e. "WHERE cu.createdtime > :maxCreatedTime". Query query = entityManager.createNamedQuery(GroupResourceConfigurationUpdate.QUERY_FIND_ALL_IN_STATUS); query.setParameter("status", ConfigurationUpdateStatus.INPROGRESS); List<GroupResourceConfigurationUpdate> requests = query.getResultList(); for (GroupResourceConfigurationUpdate request : requests) { // Note: Make this a little longer than the timeout used for individual Resource config updates - // (see checkForTimedOutResourceConfigurationUpdateRequests()), to ensure a group update never - // gets timed out before one or more of its member updates. + // (see checkForTimedOutResourceConfigurationUpdateRequests()), to ensure a group update never + // gets timed out before one or more of its member updates. long timeout = 1000L * 60 * 11; // 11 minutes
long duration = request.getDuration(); if (duration > timeout) { log.info("Group Resource configuration update request seems to have been orphaned - timing it out: " - + request); + + request); request.setErrorMessage("Timed out - did not complete after " + duration + " ms" - + " (the timeout period was " + timeout + " ms)"); + + " (the timeout period was " + timeout + " ms)"); request.setStatus(ConfigurationUpdateStatus.FAILURE); } } @@ -804,11 +800,11 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
@SuppressWarnings("unchecked") public PageList<PluginConfigurationUpdate> findPluginConfigurationUpdates(Subject subject, int resourceId, - Long beginDate, Long endDate, PageControl pc) { + Long beginDate, Long endDate, PageControl pc) {
Resource resource = entityManager.find(Resource.class, resourceId); if (resource.getResourceType().getPluginConfigurationDefinition() == null - || resource.getResourceType().getPluginConfigurationDefinition().getPropertyDefinitions().isEmpty()) { + || resource.getResourceType().getPluginConfigurationDefinition().getPropertyDefinitions().isEmpty()) { return new PageList<PluginConfigurationUpdate>(pc); }
@@ -841,7 +837,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf resource = updates.get(0).getResource(); if (!authorizationManager.canViewResource(subject, resource.getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to view resource [" + resource + "]"); + + "] does not have permission to view resource [" + resource + "]"); } }
@@ -850,16 +846,16 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
@SuppressWarnings("unchecked") public PageList<ResourceConfigurationUpdate> findResourceConfigurationUpdates(Subject subject, Integer resourceId, - Long beginDate, Long endDate, boolean suppressOldest, PageControl pc) { + Long beginDate, Long endDate, boolean suppressOldest, PageControl pc) {
if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_READ, resourceId)) { throw new PermissionException("User[" + subject.getName() - + "] does not have permission to view configuration history for resource[id=" + resourceId + "]"); + + "] does not have permission to view configuration history for resource[id=" + resourceId + "]"); }
// TODO (ips, 04/01/10): Our id's are not guaranteed to be sequential, because our sequences are configured to - // pre-create and cache blocks of 10 sequence id's, so it may be better to order by - // "cu.createdTime", rather than "cu.id". + // pre-create and cache blocks of 10 sequence id's, so it may be better to order by + // "cu.createdTime", rather than "cu.id". pc.initDefaultOrderingField("cu.id", PageOrdering.DESC);
String queryName = ResourceConfigurationUpdate.QUERY_FIND_ALL_BY_RESOURCE_ID; @@ -899,7 +895,8 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
if (!authorizationManager.canViewResource(subject, update.getResource().getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to view plugin configuration update for [" + update.getResource() + "]"); + + "] does not have permission to view plugin configuration update for [" + update.getResource() + + "]"); }
update.getConfiguration(); // this is EAGER loaded, so this really doesn't do anything @@ -909,11 +906,12 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
public ResourceConfigurationUpdate getResourceConfigurationUpdate(Subject subject, int configurationUpdateId) { ResourceConfigurationUpdate update = entityManager.find(ResourceConfigurationUpdate.class, - configurationUpdateId); + 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() + "]"); + + "] 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 @@ -923,7 +921,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
public void purgePluginConfigurationUpdate(Subject subject, int configurationUpdateId, boolean purgeInProgress) { PluginConfigurationUpdate doomedRequest = entityManager.find(PluginConfigurationUpdate.class, - configurationUpdateId); + configurationUpdateId);
if (doomedRequest == null) { log.debug("Asked to purge a non-existing config update request [" + configurationUpdateId + "]"); @@ -932,16 +930,16 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
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); + "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 plugin configuration update audit trail for resource [" - + resource + "]"); + + "] does not have permission to purge a plugin configuration update audit trail for resource [" + + resource + "]"); }
resource.getPluginConfigurationUpdates().remove(doomedRequest); @@ -953,7 +951,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
public void purgeResourceConfigurationUpdate(Subject subject, int configurationUpdateId, boolean purgeInProgress) { ResourceConfigurationUpdate doomedRequest = entityManager.find(ResourceConfigurationUpdate.class, - configurationUpdateId); + configurationUpdateId);
if (doomedRequest == null) { log.debug("Asked to purge a non-existing config update request [" + configurationUpdateId + "]"); @@ -962,16 +960,16 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
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); + "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.MODIFY_RESOURCE, resource.getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to purge a configuration update audit trail for resource [" + resource - + "]"); + + "] does not have permission to purge a configuration update audit trail for resource [" + + resource + "]"); }
resource.getResourceConfigurationUpdates().remove(doomedRequest); @@ -995,12 +993,12 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public ResourceConfigurationUpdate updateStructuredOrRawConfiguration(Subject subject, int resourceId, - Configuration newConfiguration, boolean fromStructured) throws ResourceNotFoundException, - ConfigurationUpdateStillInProgressException { + Configuration newConfiguration, boolean fromStructured) throws ResourceNotFoundException, + ConfigurationUpdateStillInProgressException {
if (authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_WRITE, resourceId) == false) { throw new PermissionException("User[name=" + subject.getName() - + "] does not have the permission to update configuration for resource[id=" + resourceId + "]"); + + "] does not have the permission to update configuration for resource[id=" + resourceId + "]"); }
Configuration configToUpdate = newConfiguration; @@ -1010,11 +1008,11 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf } try { Configuration invalidConfig = validateResourceConfiguration(subject, resourceId, newConfiguration, - fromStructured); + fromStructured); if (null != invalidConfig) { Resource resource = resourceManager.getResourceById(subject, resourceId); ResourceConfigurationUpdate resourceConfigurationUpdate = new ResourceConfigurationUpdate(resource, - invalidConfig, subject.getName()); + invalidConfig, subject.getName()); resourceConfigurationUpdate.setErrorMessage("resource.validation.failed"); resourceConfigurationUpdate.setStatus(ConfigurationUpdateStatus.FAILURE);
@@ -1023,27 +1021,27 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf } catch (PluginContainerException e) { Resource resource = resourceManager.getResourceById(subject, resourceId); ResourceConfigurationUpdate resourceConfigurationUpdate = new ResourceConfigurationUpdate(resource, - newConfiguration, subject.getName()); + newConfiguration, subject.getName()); resourceConfigurationUpdate.setErrorMessage(e.getMessage()); resourceConfigurationUpdate.setStatus(ConfigurationUpdateStatus.FAILURE); return resourceConfigurationUpdate; }
ResourceConfigurationUpdate newUpdate = configurationManager.persistNewResourceConfigurationUpdateHistory( - subject, resourceId, configToUpdate, ConfigurationUpdateStatus.INPROGRESS, subject.getName(), false); + subject, resourceId, configToUpdate, ConfigurationUpdateStatus.INPROGRESS, subject.getName(), false); executeResourceConfigurationUpdate(newUpdate, fromStructured); return newUpdate; }
private Configuration validateResourceConfiguration(Subject subject, int resourceId, Configuration configuration, - boolean isStructured) throws PluginContainerException { + boolean isStructured) throws PluginContainerException { Resource resource = entityManager.find(Resource.class, resourceId); if (resource == null) { throw new NoResultException("Cannot get live configuration for unknown resource [" + resourceId + "]"); } if (!authorizationManager.canViewResource(subject, resource.getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to view resource configuration for [" + resource + "]"); + + "] does not have permission to view resource configuration for [" + resource + "]"); } Agent agent = resource.getAgent(); AgentClient agentClient = this.agentManager.getAgentClient(agent); @@ -1056,7 +1054,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf ConfigurationDefinition configDef = resource.getResourceType().getResourceConfigurationDefinition();
return (ConfigurationFormat.STRUCTURED_AND_RAW == configDef.getConfigurationFormat() || (ConfigurationFormat.RAW == configDef - .getConfigurationFormat())); + .getConfigurationFormat())); }
private boolean isStructuredAndRawSupported(int resourceId) { @@ -1068,19 +1066,19 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
@Nullable public ResourceConfigurationUpdate updateResourceConfiguration(Subject subject, int resourceId, - @XmlJavaTypeAdapter(ConfigurationAdapter.class) Configuration newConfiguration) - throws ResourceNotFoundException { + @XmlJavaTypeAdapter(ConfigurationAdapter.class) Configuration newConfiguration) + throws ResourceNotFoundException {
if (isStructuredAndRawSupported(resourceId)) { throw new ConfigurationUpdateNotSupportedException("Cannot update a resource configuration that " - + "supports both structured and raw configuration using this method because there is insufficient " - + "information. You should instead call updateStructuredOrRawConfiguration() which requires you " - + "whether the structured or raw was updated."); + + "supports both structured and raw configuration using this method because there is insufficient " + + "information. You should instead call updateStructuredOrRawConfiguration() which requires you " + + "whether the structured or raw was updated."); }
if (authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_WRITE, resourceId) == false) { throw new PermissionException("User[name=" + subject.getName() - + "] does not have the permission to update configuration for resource[id=" + resourceId + "]"); + + "] does not have the permission to update configuration for resource[id=" + resourceId + "]"); }
// must do this in a separate transaction so it is committed prior to sending the agent request @@ -1090,7 +1088,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf // here we call ourself, but we do so via the EJB interface so we pick up the REQUIRES_NEW semantics // this can return null if newConfiguration is not actually different. newUpdate = configurationManager.persistNewResourceConfigurationUpdateHistory(subject, resourceId, - newConfiguration, ConfigurationUpdateStatus.INPROGRESS, subject.getName(), false); + newConfiguration, ConfigurationUpdateStatus.INPROGRESS, subject.getName(), false);
executeResourceConfigurationUpdate(newUpdate, true);
@@ -1111,11 +1109,12 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf private void executeResourceConfigurationUpdate(ResourceConfigurationUpdate update, boolean fromStructured) { try { AgentClient agentClient = agentManager.getAgentClient(update.getResource().getAgent()); - ConfigurationUpdateRequest request = new ConfigurationUpdateRequest(update.getId(), - update.getConfiguration(), update.getResource().getId()); + 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 + // 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); @@ -1128,13 +1127,13 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public void rollbackResourceConfiguration(Subject subject, int resourceId, int configHistoryId) - throws ConfigurationUpdateException { + throws ConfigurationUpdateException { ResourceConfigurationUpdate configurationUpdateHistory = entityManager.find(ResourceConfigurationUpdate.class, - configHistoryId); + configHistoryId); Configuration configuration = configurationUpdateHistory.getConfiguration(); if (configuration == null) { throw new ConfigurationUpdateException("No configuration history element exists with id = '" - + configHistoryId + "'"); + + configHistoryId + "'"); }
if (isStructuredAndRawSupported(resourceId)) { @@ -1146,15 +1145,15 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public ResourceConfigurationUpdate persistNewResourceConfigurationUpdateHistory(Subject subject, int resourceId, - Configuration newConfiguration, ConfigurationUpdateStatus newStatus, String newSubject, - boolean isPartofGroupUpdate) throws ResourceNotFoundException, ConfigurationUpdateStillInProgressException { + Configuration newConfiguration, ConfigurationUpdateStatus newStatus, String newSubject, + boolean isPartofGroupUpdate) throws ResourceNotFoundException, ConfigurationUpdateStillInProgressException { // get the resource that we will be updating Resource resource = resourceManager.getResourceById(subject, resourceId);
// make sure the user has the proper permissions to do this if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_WRITE, resource.getId())) { throw new PermissionException("User [" + subject.getName() - + "] does not have permission to modify configuration for resource [" + resource + "]"); + + "] does not have permission to modify configuration for resource [" + resource + "]"); }
// see if there was a previous update request and make sure it isn't still in progress @@ -1171,12 +1170,13 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf 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(). + // NOTE: If you change this to another exception, make sure you change + // getLatestResourceConfigurationUpdate(). throw new ConfigurationUpdateStillInProgressException( - "Resource [" - + resource - + "] has a resource configuration update request already in progress - please wait for it to finish: " - + previousRequest); + "Resource [" + + resource + + "] has a resource configuration update request already in progress - please wait for it to finish: " + + previousRequest); } } } @@ -1187,7 +1187,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf // 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); + .createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_CURRENTLY_ACTIVE_CONFIG); query.setParameter("resourceId", resourceId); current = (ResourceConfigurationUpdate) query.getSingleResult(); resource = current.getResource(); @@ -1202,12 +1202,12 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf return null; }
- //Configuration zeroedConfiguration = newConfiguration.deepCopy(false); + // Configuration zeroedConfiguration = newConfiguration.deepCopy(false); Configuration zeroedConfiguration = newConfiguration.deepCopyWithoutProxies();
// create our new update request and assign it to our resource - its status will initially be "in progress" ResourceConfigurationUpdate newUpdateRequest = new ResourceConfigurationUpdate(resource, zeroedConfiguration, - newSubject); + newSubject);
newUpdateRequest.setStatus(newStatus); if (newStatus == ConfigurationUpdateStatus.FAILURE) { @@ -1245,15 +1245,17 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf 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()); + 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); + "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 + // 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 @@ -1280,7 +1282,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf @SuppressWarnings("unchecked") public void checkForCompletedGroupResourceConfigurationUpdate(int resourceConfigUpdateId) { ResourceConfigurationUpdate resourceConfigUpdate = entityManager.find(ResourceConfigurationUpdate.class, - resourceConfigUpdateId); + resourceConfigUpdateId); if (resourceConfigUpdate.getStatus() == ConfigurationUpdateStatus.INPROGRESS) // If this update isn't done, then, by definition, the group update isn't done either. return; @@ -1291,14 +1293,14 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf return;
Query inProgressResourcesCountQuery = PersistenceUtility.createCountQuery(this.entityManager, - ResourceConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID_AND_STATUS); + ResourceConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID_AND_STATUS); inProgressResourcesCountQuery.setParameter("parentUpdateId", groupConfigUpdate.getId()); inProgressResourcesCountQuery.setParameter("status", ConfigurationUpdateStatus.INPROGRESS); long inProgressResourcesCount = (Long) inProgressResourcesCountQuery.getSingleResult(); if (inProgressResourcesCount == 0) { // No more member updates in progress - the group update is complete. Query failedResourcesQuery = this.entityManager - .createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID_AND_STATUS); + .createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID_AND_STATUS); failedResourcesQuery.setParameter("parentUpdateId", groupConfigUpdate.getId()); failedResourcesQuery.setParameter("status", ConfigurationUpdateStatus.FAILURE); List<Resource> failedResources = failedResourcesQuery.getResultList(); @@ -1308,17 +1310,17 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf } else { groupStatus = ConfigurationUpdateStatus.FAILURE; groupConfigUpdate.setErrorMessage("The following Resources failed to update their Configurations: " - + failedResources); + + failedResources); } groupConfigUpdate.setStatus(groupStatus); log.info("Group Resource configuration update [" + groupConfigUpdate.getId() + "] for " - + groupConfigUpdate.getGroup() + " has completed with status [" + groupStatus + "]."); + + groupConfigUpdate.getGroup() + " has completed with status [" + groupStatus + "]."); // TODO: Add support for alerting on completion of group resource config updates. - //notifyAlertConditionCacheManager("checkForCompletedGroupResourceConfigurationUpdate", groupUpdate); + // notifyAlertConditionCacheManager("checkForCompletedGroupResourceConfigurationUpdate", groupUpdate); } else { log.debug("Group Resource configuration update [" + groupConfigUpdate.getId() + "] for " - + groupConfigUpdate.getGroup() + " has " + inProgressResourcesCount - + " member updates still in progress."); + + groupConfigUpdate.getGroup() + " has " + inProgressResourcesCount + + " member updates still in progress."); } return; } @@ -1358,7 +1360,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
@Nullable public ConfigurationDefinition getResourceConfigurationDefinitionWithTemplatesForResourceType(Subject subject, - int resourceTypeId) { + int resourceTypeId) { Query query = entityManager.createNamedQuery(ConfigurationDefinition.QUERY_FIND_RESOURCE_BY_RESOURCE_TYPE_ID); query.setParameter("resourceTypeId", resourceTypeId); ConfigurationDefinition configurationDefinition = null; @@ -1381,7 +1383,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
public boolean hasPluginConfiguration(int resourceTypeId) { Query countQuery = PersistenceUtility.createCountQuery(entityManager, - ConfigurationDefinition.QUERY_FIND_PLUGIN_BY_RESOURCE_TYPE_ID); + ConfigurationDefinition.QUERY_FIND_PLUGIN_BY_RESOURCE_TYPE_ID);
countQuery.setParameter("resourceTypeId", resourceTypeId); long count = (Long) countQuery.getSingleResult(); @@ -1415,14 +1417,17 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf * Given an actual resource, this asks the agent to return that resource's live configuration. Note that this does * not perform any authorization checks - it is assumed the caller has permissions to view the configuration. This * also assumes <code>resource</code> is a non-<code>null</code> and existing resource. - * - * <p>If failed to contact the agent or any other communications problem occurred, <code>null</code> will be - * returned.</p> - * - * @param resource an existing resource whose live configuration is to be retrieved - * @param pingAgentFirst true if the underlying Agent should be pinged successfully before attempting to retrieve - * the configuration, or false otherwise - * + * + * <p> + * If failed to contact the agent or any other communications problem occurred, <code>null</code> will be returned. + * </p> + * + * @param resource + * an existing resource whose live configuration is to be retrieved + * @param pingAgentFirst + * true if the underlying Agent should be pinged successfully before attempting to retrieve the configuration, or + * false otherwise + * * @return the resource's live configuration or <code>null</code> if it could not be retrieved from the agent */ private Configuration getLiveResourceConfiguration(Resource resource, boolean pingAgentFirst, boolean fromStructured) { @@ -1434,7 +1439,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
boolean agentPingedSuccessfully = false; // Getting live configuration is mostly for the UI's benefit - as such, do not hang - // for a long time in the event the agent is down or can't be reached. Let's make the UI + // for a long time in the event the agent is down or can't be reached. Let's make the UI // responsive even in the case of an agent down by pinging it quickly to verify the agent is up. if (pingAgentFirst) agentPingedSuccessfully = agentClient.ping(5000L); @@ -1442,17 +1447,18 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf if (!pingAgentFirst || agentPingedSuccessfully) { liveConfig = agentClient.getConfigurationAgentService().loadResourceConfiguration(resource.getId()); if (liveConfig == null) { - // This should really never occur - the PC should never return a null, always at least an empty config. + // This should really never occur - the PC should never return a null, always at least an empty + // config. log.debug("ConfigurationAgentService.loadResourceConfiguration() returned a null Configuration."); liveConfig = new Configuration(); } } else { log.warn("Agent is unreachable [" + agent + "] - cannot get live configuration for resource [" - + resource + "]"); + + resource + "]"); } } catch (Exception e) { log.warn("Could not get live configuration for resource [" + resource + "]" - + ThrowableUtil.getAllMessages(e, true)); + + ThrowableUtil.getAllMessages(e, true)); }
return liveConfig; @@ -1460,7 +1466,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public AbstractResourceConfigurationUpdate mergeConfigurationUpdate( - AbstractResourceConfigurationUpdate configurationUpdate) { + AbstractResourceConfigurationUpdate configurationUpdate) { return this.entityManager.merge(configurationUpdate); }
@@ -1473,15 +1479,16 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public Configuration getConfigurationFromDefaultTemplate(ConfigurationDefinition definition) { - ConfigurationDefinition managedDefinition = entityManager.find(ConfigurationDefinition.class, - definition.getId()); + ConfigurationDefinition managedDefinition = entityManager.find(ConfigurationDefinition.class, definition + .getId()); return managedDefinition.getDefaultTemplate().getConfiguration(); }
private void handlePluginConfiguratonUpdateRemoteException(Resource resource, String summary, String detail) { resource.setConnected(false); ResourceError invalidPluginConfigError = new ResourceError(resource, - ResourceErrorType.INVALID_PLUGIN_CONFIGURATION, summary, detail, Calendar.getInstance().getTimeInMillis()); + ResourceErrorType.INVALID_PLUGIN_CONFIGURATION, summary, detail, Calendar.getInstance() + .getTimeInMillis()); this.resourceManager.addResourceError(invalidPluginConfigError); }
@@ -1498,11 +1505,11 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public int scheduleGroupPluginConfigurationUpdate(Subject subject, int compatibleGroupId, - Map<Integer, Configuration> memberPluginConfigurations) throws SchedulerException { + Map<Integer, Configuration> memberPluginConfigurations) throws SchedulerException {
if (memberPluginConfigurations == null) { throw new IllegalArgumentException( - "GroupPluginConfigurationUpdate must have non-null member configurations."); + "GroupPluginConfigurationUpdate must have non-null member configurations."); }
ResourceGroup group = getCompatibleGroupIfAuthorized(subject, compatibleGroupId); @@ -1510,11 +1517,10 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf ensureModifyResourcePermission(subject, group);
/* - * we need to create and persist the group in a new/separate transaction before the rest of the - * processing of this method; if we try to create and attach the PluginConfigurationUpdate children - * to the parent group before the group update is actually persisted, we'll get StaleStateExceptions - * from Hibernate because of our use of flush/clear (we're trying to update it before it actually - * actually exists) + * we need to create and persist the group in a new/separate transaction before the rest of the processing of + * this method; if we try to create and attach the PluginConfigurationUpdate children to the parent group before + * the group update is actually persisted, we'll get StaleStateExceptions from Hibernate because of our use of + * flush/clear (we're trying to update it before it actually actually exists) */ GroupPluginConfigurationUpdate groupUpdate = new GroupPluginConfigurationUpdate(group, subject.getName()); int updateId = configurationManager.createGroupConfigurationUpdate(groupUpdate); @@ -1524,7 +1530,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf Configuration memberResourceConfiguration = memberPluginConfigurations.get(resourceId); Resource flyWeight = new Resource(resourceId); PluginConfigurationUpdate memberUpdate = new PluginConfigurationUpdate(flyWeight, - memberResourceConfiguration, subject.getName()); + memberResourceConfiguration, subject.getName()); memberUpdate.setGroupConfigurationUpdate(groupUpdate); entityManager.persist(memberUpdate); } @@ -1534,8 +1540,8 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf jobDataMap.putAsString(AbstractGroupConfigurationUpdateJob.DATAMAP_INT_SUBJECT_ID, subject.getId());
/* - * acquire quartz objects and schedule the group update, but deferred the execution for 10 seconds - * because we need this transaction to complete so that the data is available when the quartz job triggers + * acquire quartz objects and schedule the group update, but deferred the execution for 10 seconds because we + * need this transaction to complete so that the data is available when the quartz job triggers */ JobDetail jobDetail = GroupPluginConfigurationUpdateJob.getJobDetail(group, subject, jobDataMap); Trigger trigger = QuartzUtil.getFireOnceOffsetTrigger(jobDetail, 10000); @@ -1547,28 +1553,28 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public int scheduleGroupResourceConfigurationUpdate(Subject subject, int compatibleGroupId,// - @WebParam(targetNamespace = ServerVersion.namespace)// - @XmlJavaTypeAdapter(WebServiceTypeAdapter.class)// - Map<Integer, Configuration> newResourceConfigurationMap) { + @WebParam(targetNamespace = ServerVersion.namespace)// + @XmlJavaTypeAdapter(WebServiceTypeAdapter.class)// + Map<Integer, Configuration> newResourceConfigurationMap) { if (newResourceConfigurationMap == null) { throw new IllegalArgumentException( - "GroupResourceConfigurationUpdate must have non-null member configurations."); + "GroupResourceConfigurationUpdate must have non-null member configurations."); }
ResourceGroup group = getCompatibleGroupIfAuthorized(subject, compatibleGroupId);
if (!authorizationManager.hasGroupPermission(subject, Permission.CONFIGURE_WRITE, group.getId())) { throw new PermissionException("User [" + subject.getName() + "] does not have permission " - + "to modify Resource configurations for members of group [" + group + "]."); + + "to modify Resource configurations for members of group [" + group + "]."); }
ensureNoResourceConfigurationUpdatesInProgress(group);
/* * we need to create and persist the group update in a new/separate transaction before the rest of the - * processing of this method; if we try to create and attach the PluginConfigurationUpdate children - * to the parent group before the group update is actually persisted, we'll get StaleStateExceptions - * from Hibernate because of our use of flush/clear (we're trying to update it before it actually exists) + * processing of this method; if we try to create and attach the PluginConfigurationUpdate children to the + * parent group before the group update is actually persisted, we'll get StaleStateExceptions from Hibernate + * because of our use of flush/clear (we're trying to update it before it actually exists) */ GroupResourceConfigurationUpdate groupUpdate = new GroupResourceConfigurationUpdate(group, subject.getName()); int updateId = -1; @@ -1585,7 +1591,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf Configuration memberResourceConfiguration = newResourceConfigurationMap.get(resourceId); Resource flyWeight = new Resource(resourceId); ResourceConfigurationUpdate memberUpdate = new ResourceConfigurationUpdate(flyWeight, - memberResourceConfiguration, subject.getName()); + memberResourceConfiguration, subject.getName()); memberUpdate.setGroupConfigurationUpdate(groupUpdate); entityManager.persist(memberUpdate); } @@ -1595,8 +1601,8 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf jobDataMap.putAsString(AbstractGroupConfigurationUpdateJob.DATAMAP_INT_SUBJECT_ID, subject.getId());
/* - * Acquire Quartz objects and schedule the group update, but defer the execution for 10 seconds, - * because we need this transaction to complete so that the data is available when the Quartz job triggers. + * Acquire Quartz objects and schedule the group update, but defer the execution for 10 seconds, because we need + * this transaction to complete so that the data is available when the Quartz job triggers. */ JobDetail jobDetail = GroupResourceConfigurationUpdateJob.getJobDetail(group, subject, jobDataMap); Trigger trigger = QuartzUtil.getFireOnceOffsetTrigger(jobDetail, 10000); @@ -1609,7 +1615,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
log.debug("Scheduled Resource configuration update against compatible ResourceGroup[id=" + compatibleGroupId - + "]."); + + "].");
return updateId; } @@ -1622,7 +1628,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf group = resourceGroupManager.getResourceGroupById(subject, compatibleGroupId, GroupCategory.COMPATIBLE); } catch (ResourceGroupNotFoundException e) { throw new RuntimeException("Cannot get support operations for unknown group [" + compatibleGroupId + "]: " - + e, e); + + e, e); }
return group; @@ -1631,36 +1637,36 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf private void ensureModifyPermission(Subject subject, Resource resource) throws PermissionException { if (!authorizationManager.hasResourcePermission(subject, Permission.MODIFY_RESOURCE, resource.getId())) { throw new PermissionException("User [" + subject.getName() + "] does not have permission " - + "to modify plugin configuration for resource [" + resource + "]"); + + "to modify plugin configuration for resource [" + resource + "]"); } }
private void ensureModifyResourcePermission(Subject subject, ResourceGroup group) throws PermissionException { if (!authorizationManager.hasGroupPermission(subject, Permission.MODIFY_RESOURCE, group.getId())) { throw new PermissionException("User [" + subject.getName() + "] does not have permission " - + "to modify plugin configuration for members of group [" + group + "]"); + + "to modify plugin configuration for members of group [" + group + "]"); } }
public GroupPluginConfigurationUpdate getGroupPluginConfigurationById(int configurationUpdateId) { GroupPluginConfigurationUpdate update = entityManager.find(GroupPluginConfigurationUpdate.class, - configurationUpdateId); + configurationUpdateId); return update; }
public GroupResourceConfigurationUpdate getGroupResourceConfigurationById(int configurationUpdateId) { GroupResourceConfigurationUpdate update = entityManager.find(GroupResourceConfigurationUpdate.class, - configurationUpdateId); + configurationUpdateId); return update; }
@SuppressWarnings("unchecked") public PageList<ConfigurationUpdateComposite> findPluginConfigurationUpdateCompositesByParentId( - int configurationUpdateId, PageControl pageControl) { + int configurationUpdateId, PageControl pageControl) { pageControl.initDefaultOrderingField("cu.modifiedTime");
Query query = PersistenceUtility.createQueryWithOrderBy(entityManager, - PluginConfigurationUpdate.QUERY_FIND_COMPOSITE_BY_PARENT_UPDATE_ID, pageControl); + PluginConfigurationUpdate.QUERY_FIND_COMPOSITE_BY_PARENT_UPDATE_ID, pageControl); query.setParameter("groupConfigurationUpdateId", configurationUpdateId);
long count = getPluginConfigurationUpdateCountByParentId(configurationUpdateId); @@ -1672,14 +1678,14 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
@SuppressWarnings("unchecked") public PageList<ConfigurationUpdateComposite> findResourceConfigurationUpdateCompositesByParentId(Subject subject, - int configurationUpdateId, PageControl pageControl) { - // will perform CONFIGURE_READ security check for us, no need to save the + int configurationUpdateId, PageControl pageControl) { + // will perform CONFIGURE_READ security check for us, no need to save the getGroupResourceConfigurationUpdate(subject, configurationUpdateId);
pageControl.initDefaultOrderingField("cu.modifiedTime");
Query query = PersistenceUtility.createQueryWithOrderBy(entityManager, - ResourceConfigurationUpdate.QUERY_FIND_COMPOSITE_BY_PARENT_UPDATE_ID, pageControl); + ResourceConfigurationUpdate.QUERY_FIND_COMPOSITE_BY_PARENT_UPDATE_ID, pageControl); query.setParameter("groupConfigurationUpdateId", configurationUpdateId);
long count = getResourceConfigurationUpdateCountByParentId(configurationUpdateId); @@ -1694,7 +1700,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf pageControl.initDefaultOrderingField("cu.modifiedTime");
Query query = PersistenceUtility.createQueryWithOrderBy(entityManager, - PluginConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID, pageControl); + PluginConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID, pageControl); query.setParameter("groupConfigurationUpdateId", configurationUpdateId);
long count = getPluginConfigurationUpdateCountByParentId(configurationUpdateId); @@ -1706,18 +1712,18 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
public long getPluginConfigurationUpdateCountByParentId(int configurationUpdateId) { Query countQuery = PersistenceUtility.createCountQuery(entityManager, - PluginConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID); + PluginConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID); countQuery.setParameter("groupConfigurationUpdateId", configurationUpdateId); return (Long) countQuery.getSingleResult(); }
@SuppressWarnings("unchecked") public PageList<Integer> findResourceConfigurationUpdatesByParentId(int groupConfigurationUpdateId, - PageControl pageControl) { + PageControl pageControl) { pageControl.initDefaultOrderingField("cu.modifiedTime");
Query query = PersistenceUtility.createQueryWithOrderBy(entityManager, - ResourceConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID, pageControl); + ResourceConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID, pageControl); query.setParameter("groupConfigurationUpdateId", groupConfigurationUpdateId);
long count = getResourceConfigurationUpdateCountByParentId(groupConfigurationUpdateId); @@ -1729,41 +1735,41 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
public long getResourceConfigurationUpdateCountByParentId(int groupConfigurationUpdateId) { Query countQuery = PersistenceUtility.createCountQuery(entityManager, - ResourceConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID); + ResourceConfigurationUpdate.QUERY_FIND_BY_PARENT_UPDATE_ID); countQuery.setParameter("groupConfigurationUpdateId", groupConfigurationUpdateId); return (Long) countQuery.getSingleResult(); }
@SuppressWarnings("unchecked") public Map<Integer, Configuration> getResourceConfigurationMapForGroupUpdate(Subject subject, - Integer groupResourceConfigurationUpdateId) { + Integer groupResourceConfigurationUpdateId) { // this method will perform the CONFIGURE_READ security check for us, no need to keep reference to result getGroupResourceConfigurationUpdate(subject, groupResourceConfigurationUpdateId);
Tuple<String, Object> groupIdParameter = new Tuple<String, Object>("groupConfigurationUpdateId", - groupResourceConfigurationUpdateId); + groupResourceConfigurationUpdateId); return executeGetConfigurationMapQuery(Configuration.QUERY_GET_RESOURCE_CONFIG_MAP_BY_GROUP_UPDATE_ID, 100, - groupIdParameter); + groupIdParameter); }
@SuppressWarnings("unchecked") public Map<Integer, Configuration> getPluginConfigurationMapForGroupUpdate(Integer groupPluginConfigurationUpdateId) { Tuple<String, Object> groupIdParameter = new Tuple<String, Object>("groupConfigurationUpdateId", - groupPluginConfigurationUpdateId); + groupPluginConfigurationUpdateId); return executeGetConfigurationMapQuery(Configuration.QUERY_GET_PLUGIN_CONFIG_MAP_BY_GROUP_UPDATE_ID, 100, - groupIdParameter); + groupIdParameter); }
@SuppressWarnings("unchecked") public Map<Integer, Configuration> getResourceConfigurationMapForCompatibleGroup(ResourceGroup compatibleGroup) { Tuple<String, Object> groupIdParameter = new Tuple<String, Object>("resourceGroupId", compatibleGroup.getId()); return executeGetConfigurationMapQuery(Configuration.QUERY_GET_RESOURCE_CONFIG_MAP_BY_GROUP_ID, 100, - groupIdParameter); + groupIdParameter); }
@SuppressWarnings("unchecked") private Map<Integer, Configuration> executeGetConfigurationMapQuery(String memberQueryName, int maxSize, - Tuple<String, Object>... parameters) { + Tuple<String, Object>... parameters) { Query countQuery = PersistenceUtility.createCountQuery(entityManager, memberQueryName); Query query = entityManager.createNamedQuery(memberQueryName);
@@ -1778,7 +1784,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf int resultsSize; if (count > maxSize) { log.error("Configuration set contains more than " + maxSize + " members - " + "returning only " + maxSize - + " Configurations (the maximum allowed)."); + + " Configurations (the maximum allowed)."); resultsSize = maxSize; } else { resultsSize = (int) count; @@ -1798,9 +1804,9 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf pc.initDefaultOrderingField("modifiedTime", PageOrdering.DESC);
Query query = PersistenceUtility.createQueryWithOrderBy(entityManager, - GroupPluginConfigurationUpdate.QUERY_FIND_BY_GROUP_ID, pc); + GroupPluginConfigurationUpdate.QUERY_FIND_BY_GROUP_ID, pc); Query countQuery = PersistenceUtility.createCountQuery(entityManager, - GroupPluginConfigurationUpdate.QUERY_FIND_BY_GROUP_ID); + GroupPluginConfigurationUpdate.QUERY_FIND_BY_GROUP_ID); query.setParameter("groupId", groupId); countQuery.setParameter("groupId", groupId);
@@ -1814,18 +1820,18 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
@SuppressWarnings("unchecked") public PageList<GroupResourceConfigurationUpdate> findGroupResourceConfigurationUpdates(Subject subject, - int groupId, PageControl pc) { + int groupId, PageControl pc) { if (authorizationManager.hasGroupPermission(subject, Permission.CONFIGURE_READ, groupId) == false) { throw new PermissionException("User[name=" + subject.getName() - + "] does not have permission to view configuration for group[id=" + groupId + "]"); + + "] does not have permission to view configuration for group[id=" + groupId + "]"); }
pc.initDefaultOrderingField("modifiedTime", PageOrdering.DESC);
Query query = PersistenceUtility.createQueryWithOrderBy(entityManager, - GroupResourceConfigurationUpdate.QUERY_FIND_BY_GROUP_ID, pc); + GroupResourceConfigurationUpdate.QUERY_FIND_BY_GROUP_ID, pc); Query countQuery = PersistenceUtility.createCountQuery(entityManager, - GroupResourceConfigurationUpdate.QUERY_FIND_BY_GROUP_ID); + GroupResourceConfigurationUpdate.QUERY_FIND_BY_GROUP_ID); query.setParameter("groupId", groupId); countQuery.setParameter("groupId", groupId);
@@ -1839,10 +1845,10 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
@SuppressWarnings("unchecked") public ConfigurationUpdateStatus updateGroupPluginConfigurationUpdateStatus(int groupConfigurationUpdateId, - String errorMessages) { + String errorMessages) {
GroupPluginConfigurationUpdate groupUpdate = configurationManager - .getGroupPluginConfigurationById(groupConfigurationUpdateId); + .getGroupPluginConfigurationById(groupConfigurationUpdateId);
Query query = entityManager.createNamedQuery(PluginConfigurationUpdate.QUERY_FIND_STATUS_BY_PARENT_UPDATE_ID); query.setParameter("groupConfigurationUpdateId", groupConfigurationUpdateId); @@ -1864,21 +1870,21 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public int deleteGroupPluginConfigurationUpdates(Subject subject, Integer resourceGroupId, - Integer[] groupPluginConfigurationUpdateIds) { - //TODO: use subject and resourceGroupId to perform security check + Integer[] groupPluginConfigurationUpdateIds) { + // TODO: use subject and resourceGroupId to perform security check
if (authorizationManager.hasGroupPermission(subject, Permission.MODIFY_RESOURCE, resourceGroupId) == false) { log.error(subject + " attempted to delete " + groupPluginConfigurationUpdateIds.length - + " group resource configuration updates for ResourceGroup[id" + resourceGroupId - + "], but did not have the " + Permission.MODIFY_RESOURCE.name() + " permission for this group"); + + " group resource configuration updates for ResourceGroup[id" + resourceGroupId + + "], but did not have the " + Permission.MODIFY_RESOURCE.name() + " permission for this group"); return 0; }
int removed = 0; for (Integer apcuId : groupPluginConfigurationUpdateIds) { /* - * use this strategy instead of GroupPluginConfigurationUpdate.QUERY_DELETE_BY_ID because removing via - * the entityManager will respect cascading rules, using a JPQL DELETE statement will not + * use this strategy instead of GroupPluginConfigurationUpdate.QUERY_DELETE_BY_ID because removing via the + * entityManager will respect cascading rules, using a JPQL DELETE statement will not */ try { // break the plugin configuration update links in order to preserve individual change history @@ -1898,20 +1904,20 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf }
public int deleteGroupResourceConfigurationUpdates(Subject subject, Integer resourceGroupId, - Integer[] groupResourceConfigurationUpdateIds) { + Integer[] groupResourceConfigurationUpdateIds) {
if (authorizationManager.hasGroupPermission(subject, Permission.MODIFY_RESOURCE, resourceGroupId) == false) { log.error(subject + " attempted to delete " + groupResourceConfigurationUpdateIds.length - + " group resource configuration updates for ResourceGroup[id" + resourceGroupId - + "], but did not have the " + Permission.MODIFY_RESOURCE.name() + " permission for this group"); + + " group resource configuration updates for ResourceGroup[id" + resourceGroupId + + "], but did not have the " + Permission.MODIFY_RESOURCE.name() + " permission for this group"); return 0; }
int removed = 0; for (Integer arcuId : groupResourceConfigurationUpdateIds) { /* - * use this strategy instead of GroupResourceConfigurationUpdate.QUERY_DELETE_BY_ID because removing via - * the entityManager will respect cascading rules, using a JPQL DELETE statement will not + * use this strategy instead of GroupResourceConfigurationUpdate.QUERY_DELETE_BY_ID because removing via the + * entityManager will respect cascading rules, using a JPQL DELETE statement will not */ try { // break the resource configuration update links in order to preserve individual change history @@ -1943,15 +1949,15 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf boolean supportsCascade = DatabaseTypeFactory.getDefaultDatabaseType().supportsSelfReferringCascade(); if (supportsCascade == false) { Query breakPropertyRecursionQuery = entityManager - .createNamedQuery(Configuration.QUERY_BREAK_PROPERTY_RECURSION_BY_CONFIGURATION_IDS); + .createNamedQuery(Configuration.QUERY_BREAK_PROPERTY_RECURSION_BY_CONFIGURATION_IDS); breakPropertyRecursionQuery.setParameter("configurationIds", configurationIds); breakPropertyRecursionQuery.executeUpdate(); }
Query rawConfigurationsQuery = entityManager - .createNamedQuery(Configuration.QUERY_DELETE_RAW_CONFIGURATIONS_CONFIGURATION_IDS); + .createNamedQuery(Configuration.QUERY_DELETE_RAW_CONFIGURATIONS_CONFIGURATION_IDS); Query configurationsQuery = entityManager - .createNamedQuery(Configuration.QUERY_DELETE_CONFIGURATIONS_BY_CONFIGURATION_IDs); + .createNamedQuery(Configuration.QUERY_DELETE_CONFIGURATIONS_BY_CONFIGURATION_IDs);
rawConfigurationsQuery.setParameter("configurationIds", configurationIds); configurationsQuery.setParameter("configurationIds", configurationIds); @@ -1974,33 +1980,34 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf GroupPluginConfigurationUpdate update = getGroupPluginConfigurationById(configurationUpdateId);
int groupId = update.getGroup().getId(); - if (authorizationManager.hasGroupPermission(subject, Permission.MODIFY_RESOURCE, groupId) == false) { - throw new PermissionException("User[" + subject.getName() - + "] does not have permission to view group resourceConfiguration[id=" + configurationUpdateId + "]"); + if (!authorizationManager.canViewGroup(subject, groupId)) { + throw new PermissionException("User [" + subject.getName() + + "] does not have permission to view group Resource configuration for [" + update.getGroup() + "]"); }
return update; }
public GroupResourceConfigurationUpdate getGroupResourceConfigurationUpdate(Subject subject, - int configurationUpdateId) { + int configurationUpdateId) { GroupResourceConfigurationUpdate update = getGroupResourceConfigurationById(configurationUpdateId);
int groupId = update.getGroup().getId(); if (authorizationManager.hasGroupPermission(subject, Permission.CONFIGURE_READ, groupId) == false) { throw new PermissionException("User[" + subject.getName() - + "] does not have permission to view group resourceConfiguration[id=" + configurationUpdateId + "]"); + + "] does not have permission to view group resourceConfiguration[id=" + configurationUpdateId + + "]"); }
return update; }
public Configuration translateResourceConfiguration(Subject subject, int resourceId, Configuration configuration, - boolean fromStructured) { + boolean fromStructured) {
if (!isStructuredAndRawSupported(resourceId)) { throw new TranslationNotSupportedException("The translation operation is only supported for " - + "configurations that support both structured and raw."); + + "configurations that support both structured and raw."); }
Resource resource = entityManager.find(Resource.class, resourceId); @@ -2011,7 +2018,7 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf
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 + "]"); + + "] does not have permission to view resource configuration for [" + resource + "]"); }
try { @@ -2032,4 +2039,4 @@ public class ConfigurationManagerBean implements ConfigurationManagerLocal, Conf return out; }
-} +} \ No newline at end of file
commit 3b7d1a901f61e5bd87a7cbe9d9d0d1c9cd5e5222 Author: Filip Drabek fdrabek@dhcp-lab-136.englab.brq.redhat.com Date: Tue Nov 16 23:36:03 2010 +0100
BZ-550046 (httpd) new virtual host creation fails if Resource Name is string. - Resource name format for created virtual hosts is Address:Port. - updated error messages
diff --git a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java index 719d9cb..95b8a54 100644 --- a/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java +++ b/modules/plugins/apache/src/main/java/org/rhq/plugins/apache/ApacheServerComponent.java @@ -25,6 +25,7 @@ import java.net.URL; import java.util.Date; import java.util.List; import java.util.Set; +import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException;
@@ -35,6 +36,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; + import org.rhq.augeas.AugeasProxy; import org.rhq.augeas.config.AugeasModuleConfig; import org.rhq.augeas.node.AugeasNode; @@ -400,6 +402,12 @@ public class ApacheServerComponent implements AugeasRHQComponent<PlatformCompone ApacheParser parser = new ApacheParserImpl(parserTree,getServerRoot().getAbsolutePath());
ApacheConfigReader.buildTree(getHttpdConfFile().getAbsolutePath(), parser); + + Pattern virtualHostPattern = Pattern.compile(".+:([\d]+|\*)"); + Matcher matcher = virtualHostPattern.matcher(vhostDefs[0]); + if (!matcher.matches()) + throw new Exception("Wrong format of virtual host resource name. The right format is Address:Port."); + addr = getAddressUtility().getVirtualHostSampleAddress(parserTree, vhostDefs[0], serverName, false); } catch (Exception e) { report.setStatus(CreateResourceStatus.FAILURE); @@ -905,4 +913,4 @@ public class ApacheServerComponent implements AugeasRHQComponent<PlatformCompone return false; } } -} +} \ No newline at end of file
rhq-commits@lists.fedorahosted.org