/** * If for some reason the platform plugin is not available, this method can be called to add a "dummy" platform * resource. This is normally only used during tests. * @return A dummy platform for testing purposes only. */ private Resource getTestPlatform() { ResourceType type = this.pluginManager.getMetadataManager().addTestPlatformType(); if (this.platform != null && this.platform.getResourceType() == type) { return this.platform; } Set<Resource> childResources = new CopyOnWriteArraySet<Resource>( Collections.newSetFromMap(new ConcurrentHashMap<Resource, Boolean>())); Resource platform = new Resource(childResources); platform.setResourceKey("testkey" + configuration.getContainerName()); platform.setName("testplatform"); platform.setResourceType(type); platform.setUuid(UUID.randomUUID().toString()); platform.setAgent(this.agent); return platform; }
/** * Starts a new availability interval for a given resource. If the new interval is of the same type as the previous, * then the previous will be extended. Otherwise the previous will be terminated and a new one will be started. The * Availability objects in the given record will be modified; make sure they are managed by an entity manager if you * want the changes to be persisted. * * @param record identifies the resource and its current availability * @param startDate Start date of the new interval (which must be after the current availability interval) * @param aType the new type of availability (UP, DOWN) that the resource will now have * * @return the new availability interval for a given resource, or null if there is already an existing availability */ private Availability getNewInterval(ResourceIdWithAvailabilityComposite record, Date startDate, AvailabilityType aType) { // if there is already an existing availability, update it Availability old = record.getAvailability(); if (old != null) { if (old.getAvailabilityType() == aType) { // existing availability is the same type, just extend it without creating a new entity old.setEndTime(null); // don't really need to do this; just enforces the fact that we extend the last interval return null; } old.setEndTime(startDate.getTime()); } Resource resource = new Resource(); resource.setId(record.getResourceId()); Availability newAvail = new Availability(resource, startDate.getTime(), aType); entityManager.persist(newAvail); return newAvail; }
Resource res = new Resource(resourceKey,name,resType); res.setUuid(UUID.randomUUID().toString()); res.setAgent(parent.getAgent());
boolean sendResourceErrorToServer(ResourceError resourceError) { Resource resource = resourceError.getResource(); if (resource.getId() == 0) { if (log.isDebugEnabled()) { log.debug("Resource ID is 0!" + " Will not send resource error until the resource is synced with server. " + resource.toString()); } return false; } boolean errorSent = false; DiscoveryServerService serverService = null; ServerServices serverServices = this.configuration.getServerServices(); if (serverServices != null) { serverService = serverServices.getDiscoveryServerService(); } if (serverService != null) { try { // use light-weight proxy to Resource, so that the entire hierarchy doesn't get serialized resourceError.setResource(new Resource(resource.getId())); serverService.setResourceError(resourceError); errorSent = true; } catch (RuntimeException e) { log.warn("Cannot inform the Server about a Resource error [" + resourceError + "]. Cause: " + e); } } return errorSent; }
writeResourceType.setId(7); Resource writeParentResource = new Resource(); writeParentResource.setId(11); writeParentResource.setName("reflectiveParentResource"); writeParentResource.setResourceKey("reflectiveParentKey"); Resource writeResource = new Resource(); writeResource.setId(42); writeResource.setName("reflectiveResource"); Resource readResource = new Resource(); FileInputStream fis = new FileInputStream(tempFile); try {
agentMgr.createAgent(agent); Resource platform = new Resource(resourceKey,name,type); platform.setUuid(UUID.randomUUID().toString()); platform.setAgent(agent);
Resource res = new Resource(resourceKey,name,resType); res.setUuid(UUID.randomUUID().toString()); res.setAgent(parent.getAgent());
availabilities.add(new Availability(new Resource(datum.getResourceId()), datum.getStartTime(), datum .getAvailabilityType()));
Resource.class, context.resourceId) : new Resource(-1); Availability surrogateAvailability = new SurrogateAvailability(surrogateResource, fullRangeBeginDate.getTime());
Resource in = new Resource(res.getId()); in.setName(resourceWithType.getResourceName()); in.setDescription(resourceWithType.getDescription());
static Resource createNewResource(DiscoveredResourceDetails details) { // 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.setUuid(UUID.randomUUID().toString()); resource.setResourceKey(details.getResourceKey()); resource.setName(details.getResourceName()); resource.setVersion(details.getResourceVersion()); resource.setDescription(details.getResourceDescription()); resource.setResourceType(details.getResourceType()); Configuration pluginConfiguration = details.getPluginConfiguration(); ConfigurationUtility.normalizeConfiguration(details.getPluginConfiguration(), details.getResourceType() .getPluginConfigurationDefinition(), false, false); resource.setPluginConfiguration(pluginConfiguration); return resource; }
Configuration existingPluginConfiguration = resource.getPluginConfiguration(); ConfigurationMaskingUtility.unmaskConfiguration(memberPluginConfiguration, existingPluginConfiguration); Resource flyWeight = new Resource(resourceId); PluginConfigurationUpdate memberUpdate = new PluginConfigurationUpdate(flyWeight, memberPluginConfiguration, subject.getName());
Resource bareResource = new Resource(res.getResourceKey(), res.getName(), res.getResourceType()); bareResource.setId(res.getId()); bareResource.setUuid(res.getUuid());
Configuration existingResourceConfiguration = resource.getResourceConfiguration(); ConfigurationMaskingUtility.unmaskConfiguration(memberResourceConfiguration, existingResourceConfiguration); Resource flyWeight = new Resource(resourceId); ResourceConfigurationUpdate memberUpdate = new ResourceConfigurationUpdate(flyWeight, memberResourceConfiguration, subject.getName());
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; }
alertDefinition.setResource(new Resource(resourceId));
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; }