/** * The {@link Resource#getResourceKey() resource key} of the resource this context is associated with. This resource * key is unique across all of the resource's siblings. That is to say, this resource key is unique among all * children of the {@link #getParentResourceComponent() parent}. * * @return resource key of the associated resource */ public String getResourceKey() { return this.resource.getResourceKey(); }
@Override public boolean accept(Resource resource) { return (resource.getResourceType().equals(resourceType) && resource.getResourceKey().equals(resourceKey)); }
public static Resource getChildResource(Resource parent, ResourceType type, String key) { for (Resource resource : parent.getChildResources()) { if (resource.getResourceType().equals(type) && resource.getResourceKey().equals(key)) { return resource; } } return null; }
public CanonicalResourceKey(Resource resource, Resource parent) throws PluginContainerException { if (resource == null) { throw new PluginContainerException("resource must not be null"); } if (parent == null) { throw new PluginContainerException("parent must not be null"); } this.resourceKeyTypePlugin = new KeyTypePlugin(resource.getResourceKey(), resource.getResourceType()); this.ancestorKeyTypePlugins = new ArrayList<KeyTypePlugin>(5); while (parent != null) { KeyTypePlugin ktp = new KeyTypePlugin(parent.getResourceKey(), parent.getResourceType()); this.ancestorKeyTypePlugins.add(ktp); parent = parent.getParentResource(); } }
private boolean matches(Resource newResource, Resource existingResource) { try { return ((existingResource.getId() != 0) && (existingResource.getId() == newResource.getId())) || (existingResource.getUuid().equals(newResource.getUuid())) || (existingResource.getResourceType().equals(newResource.getResourceType()) && existingResource .getResourceKey().equals(newResource.getResourceKey())); } catch (RuntimeException e) { log.error("Runtime error while attempting to compare existing Resource " + existingResource + " to new Resource " + newResource); throw e; } }
processInfo = trackedProcesses.getProcessInfo(resource.getResourceKey()); processInfo = trackedProcesses.getProcessInfo(resource.getResourceKey()); } catch (Exception e) { LOG.warn("Cannot get native process for resource [" + this.resource.getResourceKey() + "] - discovery failed", e);
/** * Calculates a unique key based on parents' resource keys. * * @param prefixKey extra key to be appended at the beginning of the digest process * @return key */ private String getAncestryBasedResourceKey(String prefixKey) { MessageDigestGenerator messageDigest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256); if (prefixKey != null) { messageDigest.add(prefixKey.getBytes()); } messageDigest.add(this.resource.getResourceKey().getBytes()); ResourceContext<?> ancestor = this.parentResourceContext; while (ancestor != null) { messageDigest.add(ancestor.getResourceKey().getBytes()); ancestor = ancestor.getParentResourceContext(); } return messageDigest.getDigestString(); }
private Set<Resource> findDuplicitSiblingResources(Resource resource, ResourceUpgradeReport upgradeReport) { Resource parent = resource.getParentResource(); if (parent == null) { //there is only a single platform resource on an agent return Collections.emptySet(); } Set<Resource> ret = new HashSet<Resource>(); for (Resource sibling : parent.getChildResources()) { //we'd have a resource key conflict if there was a resource //of the same type under the same parent that would have the same //resource key. if (upgradeReport.getNewResourceKey() != null && sibling.getResourceType().equals(resource.getResourceType()) && !sibling.getUuid().equals(resource.getUuid())) { if (sibling.getResourceKey().equals(upgradeReport.getNewResourceKey())) { ret.add(sibling); } } } return ret; }
private Resource getDiscoveredResource() { ResourceContainer parentResourceContainer = inventoryManager.getResourceContainer(parentResourceId); Resource parentResource = parentResourceContainer.getResource(); for (Resource childResource : parentResource.getChildResources()) { if (childResource.getResourceType().equals(report.getResourceType()) && childResource.getResourceKey().equals(report.getResourceKey())) { return childResource; } } return null; }
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; }
if (getResourceByParentAndKey(user, parent, resource.getResourceKey(), resource.getResourceType() .getPlugin(), resource.getResourceType().getName()) != null) { throw new ResourceAlreadyExistsException("Resource with key '" + resource.getResourceKey() + "' already exists.");
public void fillInFromResource(Resource resource) { setNewDescription(resource.getDescription()); setNewName(resource.getName()); setNewResourceKey(resource.getResourceKey()); setNewPluginConfiguration(resource.getPluginConfiguration()); setNewVersion(resource.getVersion()); }
/** * @param resource This can be a detached object * @throws InvalidInventoryReportException */ private void validateResource(Resource resource) throws InvalidInventoryReportException { if (resource.getResourceType() == null) { throw new InvalidInventoryReportException("Reported resource [" + resource + "] has a null type."); } if (resource.getResourceKey() == null) { throw new InvalidInventoryReportException("Reported resource [" + resource + "] has a null key."); } if (resource.getInventoryStatus() == InventoryStatus.DELETED) { throw new InvalidInventoryReportException( "Reported resource [" + resource + "] has an illegal inventory status of 'DELETED' - agents are not allowed to delete platforms from inventory."); } // Recursively validate all the resource's descendants. for (Resource childResource : resource.getChildResources()) { validateResource(childResource); } }
resource.getResourceKey()); if (matchingHistory != null) { String userSuppliedResourceName = matchingHistory.getCreatedResourceName();
"] upgraded ["); if (needsUpgrade(resource.getResourceKey(), resourceKey)) { resource.setResourceKey(resourceKey); logMessage.append("resourceKey, "); ret.setUpgradedResourceKey(resource.getResourceKey());
/** * @see #constructResource(int, String, String, String, Integer, int, AvailabilityType) * * @param original the resource * @return the initialized resource flyweight */ public ResourceFlyweight constructResource(Resource original) { int id = original.getId(); String name = original.getName(); String uuid = original.getUuid(); String resourceKey = original.getResourceKey(); Resource parent = original.getParentResource(); ResourceType type = original.getResourceType(); ResourceAvailability avail = original.getCurrentAvailability(); return constructResource(id, name, uuid, resourceKey, parent != null ? parent.getId() : null, type.getId(), avail != null ? avail.getAvailabilityType() : AvailabilityType.UNKNOWN); }
Resource bareResource = new Resource(res.getResourceKey(), res.getName(), res.getResourceType()); bareResource.setId(res.getId()); bareResource.setUuid(res.getUuid());
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; }
DiscoveredResourceDetails details = new DiscoveredResourceDetails(resourceType, resource.getResourceKey(),
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; }