@Override public boolean equals(Object o) { if (this == o) { return true; } if ((o == null) || !(o instanceof Resource)) { return false; } final Resource resource = (Resource) o; if ((getUuid() != null) ? (!getUuid().equals(resource.getUuid())) : (resource.getUuid() != null)) { return false; } return true; }
@Nullable public ResourceContainer getResourceContainer(Resource resource) { String uuid = resource.getUuid(); if (uuid == null) return null; return this.resourceContainersByUUID.get(uuid); }
/** * Create inventory context for a resource. * * @param resource the resource * @return the inventory context */ private InventoryContext getInventoryContext(Resource resource) { if (null == resource.getUuid() || resource.getUuid().isEmpty()) { log.error("RESOURCE UUID IS NOT SET! Inventory features may not work!"); } return new InventoryContextImpl(resource, this); }
private AvailabilityContext getAvailabilityContext(Resource resource) { if (null == resource.getUuid() || resource.getUuid().isEmpty()) { log.error("RESOURCE UUID IS NOT SET! Availability features may not work!"); } AvailabilityContext availabilityContext = new AvailabilityContextImpl(resource, this); return availabilityContext; }
@Nullable public ResourceComponent<?> getResourceComponent(Resource resource) { ResourceContainer resourceContainer = this.resourceContainersByUUID.get(resource.getUuid()); if (resourceContainer == null) { return null; } return resourceContainer.getResourceComponent(); }
/** * Inject a new availability * * @param resource * @param availabilityType * * @return */ public Availability updateAvailability(Resource resource, AvailabilityType availabilityType) { ResourceContainer resourceContainer = resourceContainersByUUID.get(resource.getUuid()); return resourceContainer.updateAvailability(availabilityType); }
/** * The data directory of the resource this context is associated with. * * @return resource data directory */ public File getResourceDataDirectory() { File resourceDataDirectory = new File(baseDataDirectory, this.getAncestryBasedResourceKey()); try { File oldResourceDataDirectory = new File(baseDataDirectory, this.resource.getUuid()); if (oldResourceDataDirectory.exists()) { oldResourceDataDirectory.renameTo(resourceDataDirectory); } } catch (Exception e) { //Just prevent an exception related to renaming of the old //data resource directory from causing this method fail. //This method should continue and create the new folder //as if the old folder never existed. } if (!resourceDataDirectory.exists()) { resourceDataDirectory.mkdirs(); } return resourceDataDirectory; }
private void addAllUUIDsToList(Resource resource, Set<String> list) { list.add(resource.getUuid()); Set<Resource> children = inventoryManager.getContainerChildren(resource); for (Resource child : children) { addAllUUIDsToList(child, list); } return; }
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; } }
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 void removeStaleResources(Resource parent, ResourceType childResourceType, Map<String, Resource> mergedResources) { Set<Resource> existingChildResources = parent.getChildResources(); for (Resource existingChildResource : existingChildResources) { // NOTE: If inside Agent, only remove Resources w/ id == 0. Other Resources may still exist in the // the Server's inventory. if (existingChildResource.getResourceType().equals(childResourceType) && !mergedResources.containsKey(existingChildResource.getUuid()) && (existingChildResource.getId() == 0 || !this.pluginContainerConfiguration.isInsideAgent())) { log.info("Removing stale resource [" + existingChildResource + "]"); this.inventoryManager.removeResourceAndIndicateIfScanIsNeeded(existingChildResource, true); } } } }
static public ResourceSyncInfo buildResourceSyncInfo(Resource res) { return new ResourceSyncInfo(res.getId(), res.getUuid(), res.getMtime(), res.getInventoryStatus()); } }
nameId[0] = container.getResource().getName(); nameId[1] = Integer.toString(container.getResource().getId()); nameId[2] = container.getResource().getUuid(); } else { nameId[0] = "<unknown>";
private ResourceContainer initResourceContainer(Resource resource) { ResourceContainer resourceContainer = getResourceContainer(resource); if (resourceContainer == null) { ClassLoader classLoader = getResourceClassLoader(resource); resourceContainer = new ResourceContainer(resource, classLoader); if (!this.configuration.isInsideAgent()) { // Auto-sync if the PC is running within the embedded JBossAS console. resourceContainer.setSynchronizationState(ResourceContainer.SynchronizationState.SYNCHRONIZED); } this.resourceContainersByUUID.put(resource.getUuid().intern(), resourceContainer); this.resourceContainerByResourceId.put(resource.getId(), resourceContainer); } else { // container already exists, but make sure the classloader exists too if (resourceContainer.getResourceClassLoader() == null) { ClassLoader classLoader = getResourceClassLoader(resource); resourceContainer.setResourceClassLoader(classLoader); } } return resourceContainer; }
parentResourceUuid = resource.getParentResource().getUuid();
/** * @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); }
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; }
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; }