// Instead, simply return the most recent persisted config w/ a SUCCESS status (possibly null).
if (current != null) {
// Fetch and mask the configuration before returning the update.
Configuration configuration = current.getConfiguration();
configuration.getMap().size();
ConfigurationDefinition configurationDefinition = getResourceConfigurationDefinitionForResourceType(
subjectManager.getOverlord(), resource.getResourceType().getId());
// We do not want the masked configuration persisted, so detach all entities before masking the configuration.
entityManager.clear();
ConfigurationMaskingUtility.maskConfiguration(configuration, configurationDefinition);
}
return current;
}
} catch (NoResultException nre) {
// The resource hasn't been successfully configured yet - not a problem, we'll ask the agent for the live
// config...
}
// ask the agent to get us the live, most up-to-date configuration for the resource,
// then compare it to make sure what we think is the latest configuration is really the latest
Configuration liveConfig = getLiveResourceConfiguration(resource, true, fromStructured);
if (liveConfig != null) {
Configuration currentConfig = (current != null) ? current.getConfiguration() : null;
// Compare the live values and, if there is a difference with the current, store the live config as a new
// update. Note that, if there is no current configuration stored, the live config is stored as the first
// update.
boolean theSame = (currentConfig != null && currentConfig.equals(liveConfig));
// Someone dorked with the configuration on the agent side - save the live config as a new update.
if (!theSame) {
try {
current = persistNewAgentReportedResourceConfiguration(resource, liveConfig);
} catch (ConfigurationUpdateStillInProgressException e) {
// This means a config update is INPROGRESS.
// Return the current in this case since it is our latest committed active config.
// Note that even though this application exception specifies "rollback=true", it will
// not effect our current transaction since the persist call was made with REQUIRES_NEW
// and thus only that new tx was rolled back
if (LOG.isDebugEnabled()) {
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);
}
}
}
} else {
LOG.warn("Could not get live resource configuration for resource [" + resource
+ "]; will assume latest resource configuration update is the current resource configuration.");
}
if (current != null) {
// Mask the configuration before returning the update.
Configuration configuration = current.getConfiguration();
configuration.getMap().size();
ConfigurationDefinition configurationDefinition = getResourceConfigurationDefinitionForResourceType(
subjectManager.getOverlord(), resource.getResourceType().getId());
// We do not want the masked configuration persisted, so detach all entities before masking the configuration.
// But before we detach the entities, let's flush the entity manager to persist any pending changes.
// This will ensure that:
// 1) All changes in the entity manager are persisted