@Override public int hashCode() { int uuidHashCode = parentResourceUuid == null ? 1 : parentResourceUuid.hashCode(); return 31 * uuidHashCode * resourceType.getId(); }
@Override @SuppressWarnings("unchecked") public List<ResourceType> getChildResourceTypes(Subject subject, ResourceType parent) { Query query = null; query = entityManager.createNamedQuery(ResourceType.QUERY_FIND_CHILDREN); query.setParameter("resourceTypeId", parent.getId()); List<ResourceType> results = query.getResultList(); return results; }
public EventDefinition(@NotNull ResourceType resourceType, @NotNull String name) { if (resourceType == null) throw new IllegalArgumentException("resourceType parameter must not be null."); if (name == null) throw new IllegalArgumentException("name parameter must not be null."); this.resourceType = resourceType; this.resourceTypeId = this.resourceType.getId(); this.name = name; }
@Override public String toString() { return "org.rhq.core.domain.alert.AlertDefinition" + "[ " + "id=" + id + ", " + "name=" + name + ", " + "conditionExpression=" + conditionExpression + ", " + "priority=" + priority + ", " + ((resource != null) ? ("resourceId=" + resource.getId()) : "") + ((resourceType != null) ? ("resourceTypeId=" + resourceType.getId()) : "") + " ]"; } }
protected Link getLinkToResourceType(ResourceType type, UriInfo uriInfo, String rel) { UriBuilder uriBuilder;URI uri; Link link; uriBuilder = uriInfo.getBaseUriBuilder(); uriBuilder.path("/resource/type/{id}"); uri = uriBuilder.build(type.getId()); link = new Link(rel, uri.toString()); return link; }
@Override @SuppressWarnings("unchecked") public List<PackageType> findPackageTypes(Subject subject, String resourceTypeName, String pluginName) throws ResourceTypeNotFoundException { ResourceType rt = resourceTypeManager.getResourceTypeByNameAndPlugin(subject, resourceTypeName, pluginName); if (null == rt) { throw new ResourceTypeNotFoundException(resourceTypeName); } Query query = entityManager.createNamedQuery(PackageType.QUERY_FIND_BY_RESOURCE_TYPE_ID); query.setParameter("typeId", rt.getId()); List<PackageType> result = query.getResultList(); return result; }
private void deleteResourcesForType(Subject subject, ResourceType type) throws Exception { List<Integer> typeIds = new ArrayList<Integer>(1); typeIds.add(type.getId()); List<Integer> resourceIds = resourceMgr.findIdsByTypeIds(typeIds); for (Integer resourceId : resourceIds) { resourceMgr.uninventoryResourceInNewTransaction(resourceId); } }
@Override public LinkedHashMap<Integer, String> getResourceTypeDescendantsWithOperations(Subject subject, int resourceTypeId) { List<ResourceType> types = getAllResourceTypeDescendants(subject, resourceTypeId); excludeThoseWithoutOperations(types); LinkedHashMap<Integer, String> results = new LinkedHashMap<Integer, String>(types.size()); for (ResourceType type : types) { results.put(type.getId(), type.getPlugin() + " -> " + type.getName()); } return results; }
private static String toConciseString(ResourceType type) { return (type != null) ? (type.getPlugin() + ":" + type.getName() + "(id=" + type.getId() + ")") : "null"; }
@Override public String toString() { return "ResourceTypeTemplateCountComposite[ " + "type[" + "id=" + getType().getId() + ", " + "name=" + getType().getName() + "], " + ", disabledMetricCount=" + disabledMetricCount + ", enabledAlertCount=" + enabledAlertCount + ", enabledMetricCount=" + enabledMetricCount + ", pluginDriftTemplates=" + pluginDriftTemplates + ", userDriftTemplates=" + userDriftTemplates + "]"; } }
private void initConfigDefs() { ConfigurationManagerRemote configurationManager = remoteClient.getProxy(ConfigurationManagerRemote.class); this.resourceConfigurationDefinition = configurationManager .getResourceConfigurationDefinitionWithTemplatesForResourceType(remoteClient.getSubject(), resource .getResourceType().getId()); this.pluginConfigurationDefinition = configurationManager.getPluginConfigurationDefinitionForResourceType( remoteClient.getSubject(), resource.getResourceType().getId()); }
@Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public Configuration getResourceConfiguration(int resourceId) { // Ensure that we return a non-proxied Configuration object that can survive after the // Hibernate session goes away. Query query = entityManager.createNamedQuery(Configuration.QUERY_GET_RESOURCE_CONFIG_BY_RESOURCE_ID); query.setParameter("resourceId", resourceId); Configuration resourceConfiguration = (Configuration) query.getSingleResult(); // Mask the configuration before returning it. Resource resource = resourceManager.getResourceById(subjectManager.getOverlord(), resourceId); ConfigurationDefinition resourceConfigurationDefinition = getResourceConfigurationDefinitionForResourceType( subjectManager.getOverlord(), resource.getResourceType().getId()); // We do not want the masked configurations persisted, so detach all entities before masking the configurations. resourceConfiguration.getMap().size(); entityManager.clear(); ConfigurationMaskingUtility.maskConfiguration(resourceConfiguration, resourceConfigurationDefinition); return resourceConfiguration; }
private void initMeasurements() { MeasurementDefinitionCriteria criteria = new MeasurementDefinitionCriteria(); criteria.addFilterResourceTypeId(resource.getResourceType().getId()); // criteria.addFilterResourceTypeName(resource.getResourceType().getName()); // criteria.setStrict(true); this.measurementDefinitions = remoteClient.getProxy(MeasurementDefinitionManagerRemote.class) .findMeasurementDefinitionsByCriteria(remoteClient.getSubject(), criteria); this.measurementMap = new HashMap<String, Measurement>(); for (MeasurementDefinition def : measurementDefinitions) { Measurement m = new Measurement(def); String name = def.getDisplayName().replaceAll("\\W", ""); name = decapitalize(name); this.measurementMap.put(name, m); this.allProperties.put(name, m); } }
public static EntityContext forGroup(ResourceGroup group) { EntityContext context = new EntityContext(null, group.getId(), null, null); context.isAutoCluster = group.getClusterResourceGroup() != null; context.isAutoGroup = group.getSubject() != null; if (context.isAutoGroup) { context.parentResourceId = group.getAutoGroupParentResource().getId(); context.resourceTypeId = group.getResourceType().getId(); } return context; }
/** * @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); }
private void abortResourceCreationIfExistingSingleton(Resource parentResource, ResourceType resourceType) { if (resourceType.isSingleton()) { ResourceCriteria resourceCriteria = new ResourceCriteria(); resourceCriteria.addFilterParentResourceId(parentResource.getId()); resourceCriteria.addFilterResourceTypeId(resourceType.getId()); resourceCriteria.clearPaging();//disable paging as the code assumes all the results will be returned. PageList<Resource> childResourcesOfType = resourceManager.findResourcesByCriteria( subjectManager.getOverlord(), resourceCriteria); if (childResourcesOfType.size() >= 1) { throw new RuntimeException("Cannot create " + resourceType + " child Resource under parent " + parentResource + ", since " + resourceType + " is a singleton type, and there is already a child Resource of that type. " + "If the existing child Resource corresponds to a managed Resource which no longer exists, " + "uninventory it and then try again."); } } }
private void abortResourceManualAddIfExistingSingleton(Resource parentResource, ResourceType resourceType) { if (resourceType.isSingleton()) { ResourceCriteria resourceCriteria = new ResourceCriteria(); resourceCriteria.addFilterParentResourceId(parentResource.getId()); resourceCriteria.addFilterResourceTypeId(resourceType.getId()); resourceCriteria.clearPaging();//Doc: disable paging as the code assumes all the results will be returned. PageList<Resource> childResourcesOfType = resourceManager.findResourcesByCriteria( subjectManager.getOverlord(), resourceCriteria); if (childResourcesOfType.size() >= 1) { throw new RuntimeException("Cannot manually add " + resourceType + " child Resource under parent " + parentResource + ", since " + resourceType + " is a singleton type, and there is already a child Resource of that type. " + "If the existing child Resource corresponds to a managed Resource which no longer exists, " + "uninventory it and then try again."); } } }
private ResourceTypeRest resourceTypeToResourceTypeRest(ResourceType type) { ResourceTypeRest rtr = new ResourceTypeRest(); rtr.setId(type.getId()); rtr.setName(type.getName()); rtr.setPluginName(type.getPlugin()); rtr.setCreatePolicy(type.getCreateDeletePolicy()); rtr.setDataType(type.getCreationDataType()); return rtr; }
private String getParentURL(AlertDefinition alertDef) { Integer templateId = alertDef.getParentId(); if (templateId != null && templateId > 0) { return getBaseURL() + "/#Administration/Configuration/AlertDefTemplates/" + alertDef.getResource().getResourceType().getId() + "/" + templateId; } else if (alertDef.getGroupAlertDefinition() != null) { return getBaseURL() + "/#ResourceGroup/" + alertDef.getGroupAlertDefinition().getGroup().getId() + "/Alerts/Definitions/" + alertDef.getGroupAlertDefinition().getId(); } else { return ""; } }
/** * @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); }