if (!authorizationManager.hasResourcePermission(subject, Permission.CONFIGURE_READ, resource.getId())) {
throw new PermissionException("User [" + subject.getName()
+ "] does not have permission to view Resource configuration for [" + resource + "].");
}
ResourceConfigurationUpdate current;
// Get the latest configuration as known to the server (i.e. persisted in the DB).
try {
Query query = entityManager
.createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_CURRENTLY_ACTIVE_CONFIG);
query.setParameter("resourceId", resourceId);
current = (ResourceConfigurationUpdate) query.getSingleResult();
resource = current.getResource();
} catch (NoResultException nre) {
// The Resource hasn't been successfully configured yet - return null.
current = null;
}
// Check whether or not a resource configuration update is currently in progress.
ResourceConfigurationUpdate latest;
try {
Query query = entityManager.createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_LATEST_BY_RESOURCE_ID);
query.setParameter("resourceId", resourceId);
latest = (ResourceConfigurationUpdate) query.getSingleResult();
if (latest.getStatus() == ConfigurationUpdateStatus.INPROGRESS) {
// The agent is in the process of a config update, so we do not want to ask it for the live config.
// Instead, simply return the most recent persisted config w/ a SUCCESS status (possibly null).
if (current != null) {
// Fetch and mask the configuration before returning the update.
Configuration configuration = current.getConfiguration();