throw new Exception("Current group Resource configuration for " + groupId
+ " 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.
ResourceGroup group = groupComposite.getResourceGroup();
ensureNoResourceConfigurationUpdatesInProgress(group);
// If we got this far, no updates are in progress. Now try to obtain the live configs from the Agents.
// If any of the requests for live configs fail (e.g. because an Agent is down) or if all of the live
// configs can't be obtained within the specified timeout, this call will throw an exception.
int userPreferencesTimeout = new SubjectPreferences(subject).getGroupConfigurationTimeoutPeriod();
Set<Resource> groupMembers = group.getExplicitResources();
Map<Integer, Configuration> liveConfigs = LiveConfigurationLoader.getInstance().loadLiveResourceConfigurations(
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,
// persist the live config to the DB as the new current config.
Map<Integer, Configuration> currentPersistedConfigs = getPersistedResourceConfigurationsForCompatibleGroup(group);
for (Resource memberResource : groupMembers) {
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);
}
}
}
// Mask the configurations before returning them.
for (Configuration resourceConfiguration : currentPersistedConfigs.values()) {
resourceConfiguration.getMap().size();
}
ConfigurationDefinition resourceConfigurationDefinition = getResourceConfigurationDefinitionForResourceType(
subjectManager.getOverlord(), group.getResourceType().getId());
// We do not want the masked configurations persisted, so detach all entities before masking the configurations.
entityManager.clear();
for (Configuration resourceConfiguration : currentPersistedConfigs.values()) {
ConfigurationMaskingUtility.maskConfiguration(resourceConfiguration, resourceConfigurationDefinition);
}