/** * Returns whether or not the given resource type requires a server scan to pick up potential changes. * * @param resourceType type of resource that packages were deployed against * @return <code>true</code> if the resource type refers to a resource that is updated in a server scan; * <code>false</code> otherwise */ private boolean executeServerScan(ResourceType resourceType) { boolean execute = resourceType.getCategory() == ResourceCategory.PLATFORM || (resourceType.getCategory() == ResourceCategory.SERVER && resourceType.getParentResourceTypes().isEmpty()); return execute; } }
private void addType(ResourceType type) { ResourceCategory category = type.getCategory(); synchronized (typesLock) { if (!typesByCategory.containsKey(category)) { typesByCategory.put(category, new LinkedHashSet<ResourceType>()); } typesByCategory.get(category).add(type); types.add(type); } }
public static boolean isService(Resource resource) { return resource.getResourceType().getCategory() == ResourceCategory.SERVICE; } }
public static boolean isServer(Resource resource) { return resource.getResourceType().getCategory() == ResourceCategory.SERVER; }
public static boolean isPlatform(Resource resource) { return resource.getResourceType().getCategory() == ResourceCategory.PLATFORM; }
/** * Returns the base server or service of the specified <code>resource</code>. * * @param resource * @return the base server or service of the specified <code>resource</code>. * @throws IllegalArgumentException if <code>resource</code> is null */ public static Resource getBaseServerOrService(Resource resource) { if (resource == null) { throw new IllegalArgumentException("resource is null"); } Resource current, parent = resource; do { current = parent; parent = current.getParentResource(); } while (parent != null && parent.getResourceType().getCategory() != PLATFORM); return current; }
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; } }
public void tallyResource(Resource resource) { if (resource == null) { return; } totalCount++; if (resource.getResourceType() == null) { return; } ResourceCategory category = resource.getResourceType().getCategory(); switch (category) { case PLATFORM: platformCount++; break; case SERVER: serverCount++; break; case SERVICE: serviceCount++; break; } }
toProcess.addAll(parentTypes); } else { if (next.getCategory() == ResourceCategory.SERVER) { sawTopLevelServer = true;
private Set<Resource> getResourcesWithType(ResourceType type, Set<Resource> resources) { Set<Resource> result = new HashSet<Resource>(); if (resources == null) { return result; } for (Resource resource : resources) { // If we're looking for SERVERs and we've hit a SERVICE, skip it as it doesn't match and // we won't find SERVERs below a SERVICE if (ResourceCategory.SERVER == type.getCategory() && ResourceCategory.SERVICE == resource.getResourceType().getCategory()) { continue; } Set<Resource> children = getContainerChildren(resource); result.addAll(getResourcesWithType(type, children)); if (type.equals(resource.getResourceType())) { ResourceContainer container = getResourceContainer(resource); result.add((container == null) ? resource : container.getResource()); } } return result; }
public MeasurementScheduleRequest getAvailabilitySchedule() { // platforms don't have a schedule but other types should. If one has not yet been set (this can // happen in various upgrade scenarios) set one, using a default interval. synchronized (this) { if (null == availabilitySchedule) { switch (this.resource.getResourceType().getCategory()) { case PLATFORM: break; case SERVER: availabilitySchedule = new MeasurementScheduleRequest(-1, MeasurementDefinition.AVAILABILITY_NAME, MeasurementDefinition.AVAILABILITY_DEFAULT_PERIOD_SERVER, true, DataType.AVAILABILITY); break; case SERVICE: availabilitySchedule = new MeasurementScheduleRequest(-1, MeasurementDefinition.AVAILABILITY_NAME, MeasurementDefinition.AVAILABILITY_DEFAULT_PERIOD_SERVICE, true, DataType.AVAILABILITY); break; } } } return availabilitySchedule; }
report.getAddedRoots().iterator().next().getResourceType().getCategory() == ResourceCategory.PLATFORM) { Resource platform = report.getAddedRoots().iterator().next(); log.info("Discovered new platform with " + platform.getChildResources().size() + " child server(s).");
@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; }
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); }
/** * @see #constructResourceType(int, String, String, boolean, ResourceCategory, Integer) * * @param original the original resource type * @return a fully initialized resource type flyweight */ public ResourceTypeFlyweight constructResourceType(ResourceType original) { int id = original.getId(); String name = original.getName(); String plugin = original.getPlugin(); boolean singleton = original.isSingleton(); ResourceCategory category = original.getCategory(); String subCategory = original.getSubCategory(); return constructResourceType(id, name, plugin, singleton, category, subCategory); }
@PUT @Path("/{id}/availability") @ApiOperation("Set the current availability of the passed resource") @TransactionAttribute(TransactionAttributeType.NEVER) public void reportAvailability(@ApiParam("Id of the resource to update") @PathParam("id") int resourceId, @ApiParam(value= "New Availability setting", required = true) AvailabilityRest avail) { if (avail.getResourceId() != resourceId) throw new IllegalArgumentException("Resource Ids do not match"); Resource resource = fetchResource(resourceId); AvailabilityType at; at = AvailabilityType.valueOf(avail.getType()); // According to jshaughn, plaforms must not be set to DISABLED, so catch this case here. if (resource.getResourceType().getCategory()==ResourceCategory.PLATFORM && at==AvailabilityType.DISABLED) { throw new BadArgumentException("Availability","Platforms must not be set to DISABLED"); } Agent agent = agentMgr.getAgentByResourceId(caller,resourceId); AvailabilityReport report = new AvailabilityReport(true, agent.getName()); Availability availability = new Availability(resource, avail.getSince(), at); report.addAvailability(availability); availMgr.mergeAvailabilityReport(report); }
if (res.getInventoryStatus()==InventoryStatus.NEW && res.getResourceType().getCategory()!=ResourceCategory.SERVICE && resourceWithType.getStatus().equalsIgnoreCase("COMMITTED")) {
if (resourceContainer.getResourceContext().getResourceType().getCategory() != ResourceCategory.PLATFORM) { resourceContainer.setAvailabilityScheduleTime(System.currentTimeMillis() - 10);
@Override public Resource getPlaformOfResource(Subject subject, int resourceId) { Resource resource; Resource parent = null; do { resource = parent; if (resource != null) { resourceId = parent.getId(); } parent = getParentResource(resourceId); if (parent != null && parent.getResourceType().getCategory().equals(ResourceCategory.PLATFORM)) { resource = parent; parent = null; } } while (parent != null); if (resource != null) { if (!authorizationManager.canViewResource(subject, resource.getId())) { throw new PermissionException("User [" + subject + "] does not have permission to view resource [" + resource.getId() + "]"); } } return resource; }
/** * 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); } } }