@AfterMethod(groups = TEST_GROUP) public void resetConfigFiles() throws IOException { boolean deleteRoot = true; for (Resource res : getResources()) { resetConfigFiles(res.getPluginConfiguration(), deleteRoot); deleteRoot = false; } }
public PluginConfigurationUpdate getPluginConfigurationUpdate(Resource updateTarget) { Configuration oldResourcePluginConfiguration = updateTarget.getPluginConfiguration(); Configuration newResourcePluginConfiguration = getMergedConfiguration(oldResourcePluginConfiguration, this.configuration); PluginConfigurationUpdate update = new PluginConfigurationUpdate(updateTarget, newResourcePluginConfiguration, getSubjectName()); return update; }
private void showPluginConfig(String[] tokens) { if (resourceId == 0) { System.err.println("You must first set the resource to work with."); return; } Configuration config = pc.getInventoryManager().getResourceContainer(resourceId).getResource() .getPluginConfiguration(); showConfig(config, tokens); }
@Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public StorageNode createStorageNode(Resource resource, StorageClusterSettings clusterSettings) { Configuration pluginConfig = resource.getPluginConfiguration(); StorageNode storageNode = new StorageNode(); storageNode.setAddress(pluginConfig.getSimpleValue(RHQ_STORAGE_ADDRESS_PROPERTY)); storageNode.setCqlPort(clusterSettings.getCqlPort()); storageNode.setResource(resource); storageNode.setOperationMode(OperationMode.INSTALLED); storageNode.setVersion(this.getClass().getPackage().getImplementationVersion()); entityManager.persist(storageNode); return storageNode; }
discoveredResource.getPluginConfiguration());
ConnectionStringAvailableProperties(ResourceContainer container, MeasurementManager measurementManager, Configuration deploymentConfiguration) { this.resourceContainer = container; this.measurementManager = measurementManager; this.pluginConfiguration = new HashMap<String, Property>(); for (Property p : container.getResource().getPluginConfiguration().getProperties()) { pluginConfiguration.put("pluginConfiguration." + p.getName(), p); } this.resourceConfiguration = new HashMap<String, Property>(); for (Property p : InventoryManager.getResourceConfiguration(container.getResource()) .getProperties()) { resourceConfiguration.put("resourceConfiguration." + p.getName(), p); } this.traits = new HashMap<String, String>(); for (MeasurementScheduleRequest r : container.getMeasurementSchedule()) { if (r.getDataType() == DataType.TRAIT) { traits.put("measurementTrait." + r.getName(), r.getName()); } } this.deploymentConfiguration = new HashMap<String, Property>(); for (Property p : deploymentConfiguration.getProperties()) { this.deploymentConfiguration.put("deploymentConfiguration." + p.getName(), p); } }
@Override public Configuration persistUpdatedPluginConfiguration(int resourceId, Configuration pluginConfiguration) { ConfigurationManagerLocal configurationManager = LookupUtil.getConfigurationManager(); SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager(); Subject overlord = subjectManager.getOverlord(); PluginConfigurationUpdate update = configurationManager.upgradePluginConfiguration(overlord, resourceId, pluginConfiguration); return update.getResource().getPluginConfiguration(); } }
private Configuration mergeExistingResourcePluginConfiguration(Resource resource, Configuration pluginConfig) { // If there is no update necessary just return the current plugin config of the existing resource Configuration result = resource.getPluginConfiguration(); ConfigurationDefinition configDef = resource.getResourceType().getPluginConfigurationDefinition(); if (null == configDef) { return result; } Configuration existingPluginConfig = resource.getPluginConfiguration().deepCopy(false); Configuration defaultPluginConfig = ConfigurationUtility.createDefaultConfiguration(configDef); boolean configChanged = false; // for each property, update the existing plugin config if discovery has set a non-default value for (String propertyName : pluginConfig.getAllProperties().keySet()) { Property discoveredProp = pluginConfig.get(propertyName); Property defaultProp = defaultPluginConfig.get(propertyName); if (!discoveredProp.equals(defaultProp)) { if (log.isDebugEnabled()) { log.debug("Discovery reported a new version of " + resource + ". Updating value of config property" + " from [" + existingPluginConfig.get(propertyName) + "] to [" + discoveredProp + "]."); } existingPluginConfig.put(discoveredProp); configChanged = true; } } if (configChanged) { result = mergeExistingResourcePluginConfigurationOnServer(resource, existingPluginConfig); } return result; }
private void prefetchResource(Resource resource, boolean recursive) { if (resource == null) { return; // Nothing to do on invalid input } resource.getId(); resource.getPluginConfiguration().getNotes(); // Initialize the lazy plugin config // Init the lazy parent... // Don't fetch the parent's children, otherwise we'll end up in infinite recursion. prefetchResource(resource.getParentResource(), false); if (recursive) { // Recurse... for (Resource child : resource.getChildResources()) { prefetchResource(child, true); } } }
@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; }
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; }
private void cleanoutResource(Resource resource) { resource.setAncestry(null); resource.setAlertDefinitions(Collections.EMPTY_SET); resource.setLocation(null); resource.setDescription(null); resource.setAutoGroupBackingGroups(Collections.EMPTY_LIST); resource.setExplicitGroups(Collections.EMPTY_SET); resource.setCreateChildResourceRequests(Collections.EMPTY_LIST); resource.setDeleteResourceRequests(Collections.EMPTY_LIST); resource.setImplicitGroups(Collections.EMPTY_SET); resource.setInstalledPackageHistory(Collections.EMPTY_LIST); resource.setInstalledPackages(Collections.EMPTY_SET); resource.setPluginConfigurationUpdates(Collections.EMPTY_LIST); resource.setResourceConfigurationUpdates(Collections.EMPTY_LIST); if (resource.getPluginConfiguration()!=null) { resource.getPluginConfiguration().cleanoutRawConfiguration(); } }
public void fillInFromResource(Resource resource) { setNewDescription(resource.getDescription()); setNewName(resource.getName()); setNewResourceKey(resource.getResourceKey()); setNewPluginConfiguration(resource.getPluginConfiguration()); setNewVersion(resource.getVersion()); }
config = targetResource.getPluginConfiguration(); if (merge) {
Configuration existingPluginConfiguration = resource.getPluginConfiguration(); ConfigurationMaskingUtility.unmaskConfiguration(newPluginConfiguration, existingPluginConfiguration);
Configuration pluginConfiguration = resource.getPluginConfiguration(); int numberOfProperties = pluginConfiguration.getProperties().size(); pluginConfiguration.put(templateProperty.deepCopy(false)); Configuration pluginConfiguration = resource.getPluginConfiguration(); int numberOfProperties = pluginConfiguration.getProperties().size(); String propertyValue = pluginConfiguration.getSimpleValue(propertyDef.getName(), 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; }
Configuration pluginConfiguration = resource.getPluginConfiguration(); if (pluginConfiguration != null) { pluginConfiguration.cleanoutRawConfiguration();
Configuration pluginConfigClone = resource.getPluginConfiguration().deepCopy(false);
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; }