private boolean isResourceUncommitted(Resource resource) { return resource == null || resource.getInventoryStatus() != InventoryStatus.COMMITTED; }
private static boolean isVisibleInInventory(Resource resource) { return resource.getInventoryStatus() != InventoryStatus.DELETED && resource.getInventoryStatus() != InventoryStatus.UNINVENTORIED; }
@Override public void resourceActivated(Resource resource) { // Schedule content discovery if resource is synchronized and COMMITED if (resource.getId() != 0 && resource.getInventoryStatus() == COMMITTED) { ContentManager.this.scheduleDiscoveries(resource); } }
@Override public Map<Integer, InventoryStatus> getResourceStatuses(int rootResourceId, boolean descendents) { Resource root = entityManager.find(Resource.class, rootResourceId); Map<Integer, InventoryStatus> statuses = new LinkedHashMap<Integer, InventoryStatus>(); statuses.put(root.getId(), root.getInventoryStatus()); getResourceStatuses(rootResourceId, descendents, statuses); return statuses; }
private void syncDriftDefinitions(Set<Resource> resources) { if (log.isDebugEnabled()) { log.debug("Syncing drift definitions for " + resources); } if (resources.isEmpty()) { return; } Set<Integer> committedResourceIds = new HashSet<Integer>(); for (Resource resource : resources) { if (resource.getInventoryStatus() == InventoryStatus.COMMITTED) { committedResourceIds.add(resource.getId()); } } DriftSyncManager driftSyncMgr = createDriftSyncManager(); driftSyncMgr.syncWithServer(committedResourceIds); }
private void syncDriftDefinitionsRecursively(Resource resource) { if (resource.getInventoryStatus() != InventoryStatus.COMMITTED) { return; } Deque<Resource> resources = new LinkedList<Resource>(); resources.push(resource); Set<Integer> resourceIds = new HashSet<Integer>(); while (!resources.isEmpty()) { Resource r = resources.pop(); if (supportsDriftManagement(r)) { resourceIds.add(r.getId()); } Set<Resource> children = getContainerChildren(r); for (Resource child : children) { resources.push(child); } } DriftSyncManager driftSyncMgr = createDriftSyncManager(); driftSyncMgr.syncWithServer(resourceIds); }
private void syncSchedules(Set<Resource> resources) { if (log.isDebugEnabled()) { log.debug("syncSchedules(Set<Resource>) for resources: " + resources); } if (resources.isEmpty()) { return; } Set<Integer> committedResourceIds = new HashSet<Integer>(); for (Resource resource : resources) { if (resource.getInventoryStatus() == InventoryStatus.COMMITTED) { committedResourceIds.add(resource.getId()); } } Set<ResourceMeasurementScheduleRequest> scheduleRequests = configuration.getServerServices() .getMeasurementServerService().getLatestSchedulesForResourceIds(committedResourceIds, false); installSchedules(scheduleRequests); }
private void postProcessNewlyCommittedResources(Set<Resource> resources) { if (log.isDebugEnabled()) { log.debug("Post-processing newly committed resources: " + resources); } if (resources.isEmpty()) { return; } Set<Integer> newlyCommittedResourceIds = new HashSet<Integer>(); for (Resource resource : resources) { if (resource.getInventoryStatus() == InventoryStatus.COMMITTED) { newlyCommittedResourceIds.add(resource.getId()); } } Set<ResourceMeasurementScheduleRequest> schedules = configuration.getServerServices() .getDiscoveryServerService().postProcessNewlyCommittedResources(newlyCommittedResourceIds); installSchedules(schedules); }
static public ResourceSyncInfo buildResourceSyncInfo(Resource res) { return new ResourceSyncInfo(res.getId(), res.getUuid(), res.getMtime(), res.getInventoryStatus()); } }
boolean versionUpdated = existingResource.getInventoryStatus() != InventoryStatus.COMMITTED || mergeExistingResourceVersionOnServer(existingResource, discoveredVersion);
private void refreshResourceComponentState(ResourceContainer container, boolean pluginConfigUpdated) { if (isResourceUpgradeActive()) { //don't do anything during upgrade. The resources are only started during the upgrade process. return; } Resource resource = container.getResource(); switch (resource.getInventoryStatus()) { case COMMITTED: { try { if (pluginConfigUpdated) { deactivateResource(resource); } activateResource(resource, container, pluginConfigUpdated); } catch (InvalidPluginConfigurationException ipce) { handleInvalidPluginConfigurationResourceError(resource, ipce); log.warn("Cannot start component for " + resource + " from synchronized merge due to invalid plugin config: " + ipce.getLocalizedMessage()); } catch (Exception e) { log.error("Failed to start component for " + resource + " from synchronized merge.", e); } break; } default: // nothing to do for other states break; } container.setSynchronizationState(ResourceContainer.SynchronizationState.SYNCHRONIZED); }
if (inventoryManager.getPlatform().getInventoryStatus() != InventoryStatus.COMMITTED) { return null;
if (res.getInventoryStatus()==InventoryStatus.NEW && res.getResourceType().getCategory()!=ResourceCategory.SERVICE && resourceWithType.getStatus().equalsIgnoreCase("COMMITTED")) { if (res.getInventoryStatus()!=InventoryStatus.COMMITTED) { throw new BadArgumentException("Can only update resources in committed state");
&& (resource.getParentResource().getInventoryStatus() != InventoryStatus.COMMITTED)) { throw new IllegalStateException("Cannot commit resource [" + resource + "] to inventory, because its parent resource [" + resource.getParentResource()
/** * @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); } }
private void setInventoryStatus(Resource parentResource, Resource resource, Map<Resource, Set<PostMergeAction>> postMergeActions) { // never autocommit a platform if (null == parentResource) { resource.setInventoryStatus(InventoryStatus.NEW); return; } ResourceType resourceType = resource.getResourceType(); boolean isParentCommitted = InventoryStatus.COMMITTED == parentResource.getInventoryStatus(); boolean isService = ResourceCategory.SERVICE == resourceType.getCategory(); boolean isParentServer = ResourceCategory.SERVER == parentResource.getResourceType().getCategory(); // always autocommit non-top-level-server children of committed parents if (isParentCommitted && (isService || isParentServer)) { resource.setInventoryStatus(InventoryStatus.COMMITTED); return; } // always autocommit top-level-server if it's an RHQ Storage Node (and the platform, if necessary) boolean isStorageNodePlugin = "RHQStorage".equals(resourceType.getPlugin()); boolean isStorageNode = (isStorageNodePlugin && "RHQ Storage Node".equals(resourceType.getName())); if (isStorageNode) { resource.setInventoryStatus(InventoryStatus.COMMITTED); if (!isParentCommitted) { parentResource.setInventoryStatus(InventoryStatus.COMMITTED); } addPostMergeAction(postMergeActions, resource, PostMergeAction.LINK_STORAGE_NODE); return; } // otherwise, set NEW resource.setInventoryStatus(InventoryStatus.NEW); }
/** * This method is called for a resource tree that exists in the server inventory but * not in the agent's inventory. * * @param resource */ private void syncSchedulesRecursively(Resource resource) { if (resource.getInventoryStatus() == InventoryStatus.COMMITTED) { if (resource.getResourceType().getCategory() == ResourceCategory.PLATFORM) { // Get and schedule the latest measurement schedules rooted at the given id. // This should include disabled schedules to make sure that previously enabled schedules are shut off. Set<ResourceMeasurementScheduleRequest> scheduleRequests = configuration.getServerServices() .getMeasurementServerService().getLatestSchedulesForResourceId(resource.getId(), false); installSchedules(scheduleRequests); // performing syncing of the children schedules in one fell swoop Set<Integer> childrenIds = new HashSet<Integer>(); for (Resource child : getContainerChildren(resource)) { childrenIds.add(child.getId()); } scheduleRequests = configuration.getServerServices().getMeasurementServerService() .getLatestSchedulesForResourceIds(childrenIds, true); installSchedules(scheduleRequests); } else { Set<ResourceMeasurementScheduleRequest> scheduleRequests = configuration.getServerServices() .getMeasurementServerService().getLatestSchedulesForResourceId(resource.getId(), true); installSchedules(scheduleRequests); } } }
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; }