@Override public String toString() { return this.getClass().getName().substring(this.getClass().getName().lastIndexOf(".") + 1) + "[" + "id=" + this.id + ", " + "eventDefinition.name=" + ((this.eventDefinition != null) ? this.eventDefinition.getName() : "null") + ", " + "resource.name=" + ((this.resource != null) ? this.resource.getName() : "null") + ", " + "location=" + this.location + "]"; } }
@Override public String toString() { return "InstalledPackage[resource=" + resource.getName() + ",packageVersion=" + packageVersion.getDisplayName() + "]"; }
@Summary(index = 1) public String getName() { return resource.getName(); }
private void practiceSafeSets(final Resource resource) { Set<Resource> children = resource.getChildResources(); if (null == children) { resource.setChildResources(new CopyOnWriteArraySet<Resource>()); } else if (!(children instanceof CopyOnWriteArraySet)) { if (log.isDebugEnabled()) { log.debug("Converting persisted childResources to CopyOnWriteArraySet from [" + children.getClass().getSimpleName() + "] for [" + resource.getName() + "]"); } resource.setChildResources(new CopyOnWriteArraySet<Resource>(children)); } }
@Override public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append("Resource").append("["); buffer.append("id=").append(this.id); buffer.append(", uuid=").append(this.uuid); String typeName = (this.resourceType != null) ? '{' + this.resourceType.getPlugin() + '}' + this.resourceType.getName() : "<null>"; buffer.append(", type=").append(typeName); buffer.append(", key=").append(this.resourceKey); buffer.append(", name=").append(this.name); String parentName; try { parentName = (this.parentResource != null) ? this.parentResource.getName() : "<null>"; } catch (RuntimeException e) { // It may not be possible to get the parent name if this is a detached Entity on the Server side, since // this.parentResource is lazily fetched. NOTE: We can't specifically catch LazyInitializationException // here, since Hibernate classes do not exist on the Agent side. parentName = null; } if (parentName != null) buffer.append(", parent=").append(parentName); if (this.version != null && !this.version.equals("")) buffer.append(", version=").append(this.version); buffer.append("]"); return buffer.toString(); }
@Override public void _finalizePurge(Subject subject, BundleDeployment bundleDeployment, Map<BundleResourceDeployment, String> failedToPurge) throws Exception { bundleDeployment = entityManager.find(BundleDeployment.class, bundleDeployment.getId()); if (failedToPurge.isEmpty()) { bundleDeployment.setLive(false); // all deployments are purged, no where is this live anymore bundleDeployment.setErrorMessage(null); bundleDeployment.setStatus(BundleDeploymentStatus.SUCCESS); } else { bundleDeployment.setLive(true); // not all deployments are purged - error indicates it is still live somewhere StringBuilder errorStr = new StringBuilder(); int totalDeployments = bundleDeployment.getResourceDeployments().size(); int failedPurges = failedToPurge.size(); if (failedPurges < totalDeployments) { bundleDeployment.setStatus(BundleDeploymentStatus.MIXED); // some deployments were purged, so show MIXED status errorStr.append("Failed to purge [").append(failedPurges).append("] of [").append(totalDeployments) .append("] remote resource deployments"); } else { bundleDeployment.setStatus(BundleDeploymentStatus.FAILURE); // all deployments failed to be purged errorStr.append("Failed to purge all [").append(failedPurges).append("] remote resource deployments"); } // key is the resource deployment that failed to be purged; value is the error message for (Map.Entry<BundleResourceDeployment, String> entry : failedToPurge.entrySet()) { errorStr.append("\n\n"); errorStr.append(entry.getKey().getResource().getName()).append(": ").append(entry.getValue()); } bundleDeployment.setErrorMessage(errorStr.toString()); } }
private void processPropertyOptionsSource(Resource resource, Resource baseResource, PropertyDefinitionSimple pds, PropertyOptionsSource.TargetType tt, String expression, Pattern filterPattern, Resource foundResource) { if (tt == PropertyOptionsSource.TargetType.RESOURCE) { String name = foundResource.getName(); // filter if the user provided a filter if (filterPattern != null) { Matcher m = filterPattern.matcher(name); if (m.matches()) { PropertyDefinitionEnumeration pde = new PropertyDefinitionEnumeration(name, "" + name); pds.getEnumeratedValues().add(pde); } } else { // Filter is null -> none provided -> do not filter PropertyDefinitionEnumeration pde = new PropertyDefinitionEnumeration(name, "" + name); pds.getEnumeratedValues().add(pde); } } else if (tt == PropertyOptionsSource.TargetType.CONFIGURATION) { // for configuration we need to drill down into the resource configuration if (!handleConfigurationTarget(resource, baseResource, pds, expression, foundResource)) return; } }
@SuppressWarnings("unchecked") private void ensureNoResourceConfigurationUpdatesInProgress(ResourceGroup compatibleGroup) throws ConfigurationUpdateStillInProgressException { if (isGroupResourceConfigurationUpdateInProgress(this.subjectManager.getOverlord(), compatibleGroup.getId())) { throw new ConfigurationUpdateStillInProgressException("Current group Resource configuration for " + compatibleGroup + " cannot be calculated, because a group Resource configuration update is currently in progress " + " (please wait for this update to complete or delete it from the history)."); } Query countQuery = PersistenceUtility.createCountQuery(entityManager, ResourceConfigurationUpdate.QUERY_FIND_BY_GROUP_ID_AND_STATUS); countQuery.setParameter("groupId", compatibleGroup.getId()); countQuery.setParameter("status", ConfigurationUpdateStatus.INPROGRESS); long count = (Long) countQuery.getSingleResult(); if (count != 0) { Query query = entityManager.createNamedQuery(ResourceConfigurationUpdate.QUERY_FIND_BY_GROUP_ID_AND_STATUS); query.setParameter("groupId", compatibleGroup.getId()); query.setParameter("status", ConfigurationUpdateStatus.INPROGRESS); List<Resource> resources = query.getResultList(); List<String> names = new ArrayList<String>(); for (Resource resource : resources) { names.add(resource.getName()); } throw new ConfigurationUpdateStillInProgressException("Current group Resource configuration for " + compatibleGroup + " cannot be calculated, because Resource configuration updates are currently in progress for the" + " following Resources (please wait for these updates to complete or delete them from the history): " + names); } }
private ResourceWithChildren getHierarchy(Resource baseResource) { ResourceWithChildren rwc = new ResourceWithChildren("" + baseResource.getId(), baseResource.getName()); PageControl pc = new PageControl(); List<Resource> ret = resMgr.findResourceByParentAndInventoryStatus(caller, baseResource, InventoryStatus.COMMITTED, pc); if (!ret.isEmpty()) { List<ResourceWithChildren> resList = new ArrayList<ResourceWithChildren>(ret.size()); for (Resource res : ret) { ResourceWithChildren child = getHierarchy(res); resList.add(child); putToCache(res.getId(), Resource.class, res); } if (!resList.isEmpty()) rwc.setChildren(resList); } return rwc; }
@Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void deleteResourceError(Subject user, int resourceErrorId) { ResourceError error = entityManager.find(ResourceError.class, resourceErrorId); if (error != null) { if (!authorizationManager.hasResourcePermission(user, Permission.MODIFY_RESOURCE, error.getResource() .getId())) { throw new PermissionException("Cannot delete Resource error [" + resourceErrorId + "]. User [" + user + "] does not have permission to modify Resource [" + error.getResource().getName() + "]."); } entityManager.remove(error); } }
/** * @see ResourceContext#ResourceContext(org.rhq.core.domain.resource.Resource, org.rhq.core.pluginapi.inventory.ResourceComponent, org.rhq.core.pluginapi.inventory.ResourceContext, org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent, org.rhq.core.system.SystemInfo, java.io.File, java.io.File, String, org.rhq.core.pluginapi.event.EventContext, org.rhq.core.pluginapi.operation.OperationContext, org.rhq.core.pluginapi.content.ContentContext, org.rhq.core.pluginapi.availability.AvailabilityContext, org.rhq.core.pluginapi.inventory.InventoryContext, org.rhq.core.pluginapi.inventory.PluginContainerDeployment) * * @since 4.0 */ public ResourceUpgradeContext(Resource resource, ResourceContext<?> parentResourceContext, T parentResourceComponent, ResourceDiscoveryComponent<T> resourceDiscoveryComponent, SystemInfo systemInfo, File temporaryDirectory, File baseDataDirectory, String pluginContainerName, EventContext eventContext, OperationContext operationContext, ContentContext contentContext, AvailabilityContext availabilityContext, InventoryContext inventoryContext, PluginContainerDeployment pluginContainerDeployment) { super(resource, parentResourceComponent, parentResourceContext, resourceDiscoveryComponent, systemInfo, temporaryDirectory, baseDataDirectory, pluginContainerName, eventContext, operationContext, contentContext, availabilityContext, inventoryContext, pluginContainerDeployment); this.resourceConfiguration = resource.getResourceConfiguration(); this.name = resource.getName(); this.description = resource.getDescription(); this.version = resource.getVersion(); }
public String toString() { return "[" + resourceId + "] " + resource.getName() + " (" + resource.getResourceType().getName() + "::" + resource.getResourceType().getPlugin() + ")"; }
@Override public Resource updateResource(Subject user, Resource resource) { Resource persistedResource = entityManager.find(Resource.class, resource.getId()); if (persistedResource == null) { throw new ResourceNotFoundException(resource.getId()); } if (!authorizationManager.hasResourcePermission(user, Permission.MODIFY_RESOURCE, resource.getId())) { throw new PermissionException("You do not have permission to modify Resource with id " + resource.getId() + "."); } /*if (getResourceByParentAndKey(user, resource.getParentResource(), resource.getResourceKey()) != null) * { throw new ResourceAlreadyExistsException("Resource with key '" + resource.getName() + "' already * exists");}*/ // On name change make sure we update the ancestry as the name is part of the ancestry string if (!persistedResource.getName().equals(resource.getName())) { persistedResource.setName(resource.getName()); updateAncestry(persistedResource); } persistedResource.setLocation(resource.getLocation()); persistedResource.setDescription(resource.getDescription()); persistedResource.setAgentSynchronizationNeeded(); persistedResource.setModifiedBy(user.getName()); return entityManager.merge(persistedResource); }
/** * Shows the list of availabilities known so far * for resources that have been discovered * @param tokens tokenized command line tokens[0] is the command itself */ private void avail(String[] tokens) { Set<Resource> resources = getResources(); int id = getResourceIdFromTokens(tokens, 0); for (Resource res : resources) { if (id == 0 || (res.getId() == id)) { AvailabilityReport availabilityReport = inventoryManager.getCurrentAvailability(res, false); for(AvailabilityReport.Datum datum : availabilityReport.getResourceAvailability()) { if (datum.getResourceId() == res.getId()) { System.out.println(res.getName() + "( " + res.getId() + " ):" + datum.getAvailabilityType()); break; } } } } }
public void fillInFromResource(Resource resource) { setNewDescription(resource.getDescription()); setNewName(resource.getName()); setNewResourceKey(resource.getResourceKey()); setNewPluginConfiguration(resource.getPluginConfiguration()); setNewVersion(resource.getVersion()); }
@Override public PageList<MeasurementDataTrait> findTraitsByCriteria(Subject subject, MeasurementDataTraitCriteria criteria) { CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria); Map<String, Object> filterFields = generator.getFilterFields(criteria); if (!this.authorizationManager.isInventoryManager(subject)) { generator.setAuthorizationResourceFragment(CriteriaQueryGenerator.AuthorizationTokenType.RESOURCE, "schedule.resource", subject.getId()); } CriteriaQueryRunner<MeasurementDataTrait> queryRunner = new CriteriaQueryRunner(criteria, generator, this.entityManager); PageList<MeasurementDataTrait> results = queryRunner.execute(); // Fetch the metric definition for each schedule, so the results include the trait names. for (MeasurementDataTrait result : results) { result.getSchedule().getDefinition().getName(); } // If the query is filtered by group id, also fetch the Resource for each schedule, so the results include the // Resource names. if (filterFields.get(MeasurementDataTraitCriteria.FILTER_FIELD_GROUP_ID) != null) { for (MeasurementDataTrait result : results) { result.getSchedule().getResource().getName(); } } return results; }
/** * @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 String toCSV(ResourceConfigurationUpdate configurationUpdate) { return configurationUpdate.getId() + "," + formatDateTime(configurationUpdate.getCreatedTime())+"," + formatDateTime(configurationUpdate.getModifiedTime())+"," + configurationUpdate.getStatus()+"," + cleanForCSV(configurationUpdate.getResource().getName())+ "," + cleanForCSV(ReportFormatHelper.parseAncestry(configurationUpdate.getResource().getAncestry())) + "," + getDetailsURL(configurationUpdate); //@todo: check dates, user, update-type }
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; }