existingResource.setPluginConfiguration(mergedPluginConfiguration); log.info("Version of [" + existingResource + "] changed from [" + existingVersion + "] to [" + discoveredVersion + "]");
existingResource.setPluginConfiguration(pluginConfig); logMessage.append("pluginConfiguration, ");
@Override public PluginConfigurationUpdate upgradePluginConfiguration(Subject subject, int resourceId, Configuration newPluginConfiguration) throws ResourceNotFoundException { Subject overlord = subjectManager.getOverlord(); Resource resource = resourceManager.getResourceById(overlord, resourceId); // make sure the user has the proper permissions to do this ensureModifyPermission(subject, resource); // Make sure to unmask the configuration before persisting the update. Configuration existingPluginConfiguration = resource.getPluginConfiguration(); ConfigurationMaskingUtility.unmaskConfiguration(newPluginConfiguration, existingPluginConfiguration); // create our new update request and assign it to our resource - its status will initially be "in progress" PluginConfigurationUpdate update = new PluginConfigurationUpdate(resource, newPluginConfiguration, subject.getName()); update.setStatus(ConfigurationUpdateStatus.SUCCESS); entityManager.persist(update); resource.addPluginConfigurationUpdates(update); resource.setPluginConfiguration(update.getConfiguration()); entityManager.merge(update); return update; }
static Resource createNewResource(DiscoveredResourceDetails details) { // Use a CopyOnWriteArraySet for childResources to allow the field to be concurrently accessed safely // (i.e. to avoid ConcurrentModificationExceptions). Set<Resource> childResources = new CopyOnWriteArraySet<Resource>(); Resource resource = new Resource(childResources); resource.setUuid(UUID.randomUUID().toString()); resource.setResourceKey(details.getResourceKey()); resource.setName(details.getResourceName()); resource.setVersion(details.getResourceVersion()); resource.setDescription(details.getResourceDescription()); resource.setResourceType(details.getResourceType()); Configuration pluginConfiguration = details.getPluginConfiguration(); ConfigurationUtility.normalizeConfiguration(details.getPluginConfiguration(), details.getResourceType() .getPluginConfigurationDefinition(), false, false); resource.setPluginConfiguration(pluginConfiguration); return resource; }
resource = existingResource; if (resource.getInventoryStatus() != InventoryStatus.COMMITTED) { resource.setPluginConfiguration(pluginConfiguration);
@Override public void completePluginConfigurationUpdate(PluginConfigurationUpdate update) { // use EJB3 reference to ourself so that transaction semantics are correct ConfigurationUpdateResponse response = configurationManager.executePluginConfigurationUpdate(update); Resource resource = update.getResource(); // link to the newer, persisted configuration object -- regardless of errors resource.setAgentSynchronizationNeeded(); resource.setPluginConfiguration(update.getConfiguration()); if (response.getStatus() == ConfigurationUpdateStatus.SUCCESS) { update.setStatus(ConfigurationUpdateStatus.SUCCESS); resource.setConnected(true); removeAnyExistingInvalidPluginConfigurationErrors(resource); // Flush before merging to ensure the update has been persisted and avoid StaleStateExceptions. entityManager.flush(); entityManager.merge(update); } else { handlePluginConfiguratonUpdateRemoteException(resource, response.getStatus().toString(), response.getErrorMessage()); update.setStatus(response.getStatus()); update.setErrorMessage(response.getErrorMessage()); } }
targetResource.setPluginConfiguration(newConfig); } else { config = pc.getConfigurationManager().loadResourceConfiguration(resourceId);
existingResource.setPluginConfiguration(updatedResource.getPluginConfiguration()); existingResource.setAgentSynchronizationNeeded();
@Override public void updatePluginConfiguration(int resourceId, Configuration newPluginConfiguration) throws InvalidPluginConfigurationClientException, PluginContainerException { ResourceContainer container = getResourceContainer(resourceId); if (container == null) { throw new PluginContainerException("Cannot update plugin configuration for unknown Resource with id [" + resourceId + "]"); } Resource resource = container.getResource(); // First stop the resource component. deactivateResource(resource); // Then update the resource's plugin config. resource.setPluginConfiguration(newPluginConfiguration); // And finally restart the resource component. try { activateResource(resource, container, true); // TODO: What about re-activating the Resource's descendants? } catch (InvalidPluginConfigurationException e) { String errorMessage = "Unable to connect to managed resource of type [" + resource.getResourceType().getName() + "] using the specified connection properties."; log.info(errorMessage, e); errorMessage += ((e.getLocalizedMessage() != null) ? (" " + e.getLocalizedMessage()) : ""); // In the exception we throw over to the server, strip the InvalidPluginConfigurationException out of the // stack trace, but append the message from that exception to the message of the exception we throw. This // will make for a nicer error message for the server to display in the UI. throw new InvalidPluginConfigurationClientException(errorMessage, (e.getCause() != null) ? new WrappedRemotingException(e.getCause()) : null); } }
private Resource cloneResourceWithoutChildren(Resource resourceFromServer) { // Use a CopyOnWriteArraySet for childResources to allow the field to be concurrently accessed safely // (i.e. to avoid ConcurrentModificationExceptions). Set<Resource> childResources = new CopyOnWriteArraySet<Resource>(); Resource resource = new Resource(childResources); resource.setId(resourceFromServer.getId()); resource.setUuid(resourceFromServer.getUuid()); resource.setResourceKey(resourceFromServer.getResourceKey()); resource.setResourceType(resourceFromServer.getResourceType()); resource.setMtime(resourceFromServer.getMtime()); resource.setInventoryStatus(resourceFromServer.getInventoryStatus()); resource.setPluginConfiguration(resourceFromServer.getPluginConfiguration()); resource.setVersion(resourceFromServer.getVersion()); resource.setName(resourceFromServer.getName()); compactResource(resource); return resource; }
private boolean mergeResource(Resource sourceResource, Resource targetResource) { if (targetResource.getId() != 0 && targetResource.getId() != sourceResource.getId()) { log.warn("Id for " + targetResource + " changed from [" + targetResource.getId() + "] to [" + sourceResource.getId() + "]."); } targetResource.setId(sourceResource.getId()); targetResource.setUuid(sourceResource.getUuid()); if (!targetResource.getResourceKey().equals(sourceResource.getResourceKey())) { log.warn("Resource key for " + targetResource + " changed from [" + targetResource.getResourceKey() + "] to [" + sourceResource.getResourceKey() + "]."); } targetResource.setResourceKey(sourceResource.getResourceKey()); targetResource.setResourceType(sourceResource.getResourceType()); targetResource.setMtime(sourceResource.getMtime()); targetResource.setInventoryStatus(sourceResource.getInventoryStatus()); // (jshaughn) noticed we don't set the version here, should we? boolean pluginConfigUpdated = (!targetResource.getPluginConfiguration().equals( sourceResource.getPluginConfiguration())); targetResource.setPluginConfiguration(sourceResource.getPluginConfiguration()); targetResource.setName(sourceResource.getName()); compactResource(targetResource); return pluginConfigUpdated; }
public void updateResource(Resource resource) { if (getNewResourceKey() != null) { resource.setResourceKey(getNewResourceKey()); } if (getNewName() != null) { resource.setName(getNewName()); } if (getNewDescription() != null) { resource.setDescription(getNewDescription()); } if (getNewPluginConfiguration() != null) { resource.setPluginConfiguration(getNewPluginConfiguration()); } if (getNewVersion() != null) { resource.setVersion(getNewVersion()); } }
private static Resource convertToPojoResource(Resource resource, boolean includeDescendants) { Resource pojoResource = new Resource(resource.getId()); pojoResource.setUuid(resource.getUuid()); pojoResource.setResourceKey(resource.getResourceKey()); pojoResource.setResourceType(resource.getResourceType()); pojoResource.setMtime(resource.getMtime()); pojoResource.setInventoryStatus(resource.getInventoryStatus()); Configuration pcCopy = resource.getPluginConfiguration(); if (pcCopy != null) { pcCopy = pcCopy.deepCopy(); } pojoResource.setPluginConfiguration(pcCopy); pojoResource.setName(resource.getName()); pojoResource.setDescription(resource.getDescription()); pojoResource.setLocation(resource.getLocation()); pojoResource.setVersion(resource.getVersion()); if (resource.getParentResource() != null) { pojoResource.setParentResource(convertToPojoResource(resource.getParentResource(), false)); } if (includeDescendants) { for (Resource childResource : resource.getChildResources()) { if (isVisibleInInventory(childResource)) { pojoResource.addChildResource(convertToPojoResource(childResource, true)); } } } return pojoResource; }