/** * At the time of writing (4.10) platform top level services don't have children so this will be quick, but * write it to handle any future children. In general this will still be a relatively small number of resources. * * @param topLevelServices * @return The top level service hierarchy sync info */ private Set<ResourceSyncInfo> getToplevelServiceSyncInfo(Set<Resource> topLevelServices) { Set<ResourceSyncInfo> result = new HashSet<ResourceSyncInfo>(topLevelServices.size()); Set<Integer> topLevelServiceIds = new HashSet<Integer>(); for (Resource topLevelService : topLevelServices) { result.add(ResourceSyncInfo.buildResourceSyncInfo(topLevelService)); topLevelServiceIds.add(topLevelService.getId()); } getToplevelServiceSyncInfoHierarchy(topLevelServiceIds, result); return result; }
private void getToplevelServiceSyncInfoHierarchy(Set<Integer> parentIds, Set<ResourceSyncInfo> result) { if (parentIds.isEmpty()) { return; } Query q = entityManager.createNamedQuery(ResourceSyncInfo.QUERY_SERVICE_CHILDREN); q.setParameter("parentIds", parentIds); List<ResourceSyncInfo> childSyncInfos = q.getResultList(); if (!childSyncInfos.isEmpty()) { result.addAll(childSyncInfos); Set<Integer> childIds = new HashSet<Integer>(childSyncInfos.size()); for (ResourceSyncInfo childSyncInfo : childSyncInfos) { childIds.add(childSyncInfo.getId()); } getToplevelServiceSyncInfoHierarchy(childIds, result); } }
private void addAllUuids(Collection<ResourceSyncInfo> syncInfos, Set<String> allServerSideUuids) { for (ResourceSyncInfo syncInfo : syncInfos) { allServerSideUuids.add(syncInfo.getUuid()); } }
if (InventoryStatus.DELETED == syncInfo.getInventoryStatus()) { deletedResourceIds.add(syncInfo.getId()); } else { ResourceContainer container = getResourceContainer(syncInfo.getUuid()); if (container == null) { if (InventoryStatus.IGNORED != syncInfo.getInventoryStatus()) { unknownResourceSyncInfos.add(syncInfo); } else { log.info("Got an unknown but ignored resource - ignoring it: " + syncInfo.getId()); + resource.getInventoryStatus() + ", mtime=" + resource.getMtime()); log.debug("Sync Resource: " + syncInfo.getId() + ", status=" + syncInfo.getInventoryStatus() + ", mtime=" + syncInfo.getMtime()); final boolean ignoreResource = (InventoryStatus.IGNORED == syncInfo.getInventoryStatus()); final boolean ignoreResourceType = this.pluginManager.getMetadataManager() .isDisabledOrIgnoredResourceType(resource.getResourceType()); } else { if (resource.getInventoryStatus() != InventoryStatus.COMMITTED && syncInfo.getInventoryStatus() == InventoryStatus.COMMITTED) { newlyCommittedResources.add(resource); resource.setId(syncInfo.getId()); resource.setMtime(syncInfo.getMtime()); resource.setInventoryStatus(syncInfo.getInventoryStatus()); refreshResourceComponentState(container, true);
allServerSideUuids.add(platformResourceSyncInfo.getUuid()); syncInfos.add(platformResourceSyncInfo); log.info("Sync Starting: Platform [" + platformSyncInfo.getPlatform().getId() + "]"); log.info("Sync Starting: Platform Top level services [" + platformSyncInfo.getPlatform().getId() + "]"); boolean hadSyncedResources = syncResources(platformResourceSyncInfo.getId(), syncInfos); log.info("Sync Complete: Platform Top level services [" + platformSyncInfo.getPlatform().getId() + "] Local inventory changed: [" + hadSyncedResources + "]"); log.info("Sync Complete: Platform [" + platformSyncInfo.getPlatform().getId() + "]."); + platformSyncInfo.getPlatform().getId() + "]");
long mtime = dbType.getLong(row[2]); InventoryStatus status = InventoryStatus.valueOf((String) row[3]); result.add(new ResourceSyncInfo(id, uuid, mtime, status));
static public ResourceSyncInfo buildResourceSyncInfo(Resource res) { return new ResourceSyncInfo(res.getId(), res.getUuid(), res.getMtime(), res.getInventoryStatus()); } }
@Override public void synchronizePlatform(PlatformSyncInfo syncInfo) { syncPlatform(syncInfo); performServiceScan(syncInfo.getPlatform().getId()); // NOTE: This will block (the initial scan blocks). // TODO: (jshaughn) should we also request a full avail scan? }
public static PlatformSyncInfo buildPlatformSyncInfo(Resource platform) { Set<Integer> toplevelServerIds = new HashSet<Integer>(); for (Resource r : platform.getChildResources()) { if (r.getResourceType().getCategory().equals(ResourceCategory.SERVER)) { toplevelServerIds.add(r.getId()); } } ResourceSyncInfo resSyncInfo = ResourceSyncInfo.buildResourceSyncInfo(platform); PlatformSyncInfo syncInfo = new PlatformSyncInfo(resSyncInfo, new HashSet<ResourceSyncInfo>(1), toplevelServerIds); return syncInfo; } }
resourceIdList.add(syncInfo.getId());
@Override public PlatformSyncInfo getPlatformSyncInfo(Agent knownAgent) { Resource platform = resourceManager.getPlatform(knownAgent); if (null == platform) { return null; } Set<Resource> toplevelServices = new HashSet<Resource>(); Set<Integer> topLevelServerIds = new HashSet<Integer>(); for (Resource platformChild : platform.getChildResources()) { switch (platformChild.getResourceType().getCategory()) { case SERVER: topLevelServerIds.add(platformChild.getId()); break; case SERVICE: toplevelServices.add(platformChild); break; default: break; } } ResourceSyncInfo platformSyncInfo = ResourceSyncInfo.buildResourceSyncInfo(platform); Set<ResourceSyncInfo> topLevelServiceSyncInfo = getToplevelServiceSyncInfo(toplevelServices); PlatformSyncInfo result = new PlatformSyncInfo(platformSyncInfo, topLevelServiceSyncInfo, topLevelServerIds); return result; }