modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java | 3
modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java | 9
modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java.orig | 863 ++++++++++
modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java | 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/inventory/InventoryManagerBean.java | 4
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java | 14
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerLocal.java | 4
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java | 10
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerLocal.java | 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginManagerBean.java | 19
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginManagerLocal.java | 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginStats.java | 29
12 files changed, 953 insertions(+), 8 deletions(-)
New commits:
commit b13dc3b20d1c2629f9bc688c2afdea40ff2aac28
Author: John Sanda <jsanda(a)redhat.com>
Date: Mon Dec 13 10:04:57 2010 -0500
Fixing typo in log message
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java
index 9338ea5..538b6c2 100644
--- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java
+++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java
@@ -1713,7 +1713,7 @@ public class AgentMain {
start();
} catch (Throwable t1) {
LOG.error(t1, "Restarting the agent has failed. Please check the logs for errors and " +
- "and manually restart the agent as soon as possible");
+ "manually restart the agent as soon as possible.");
return;
}
}
commit 3ae3e8871c7ab719680175bf54843f454e849e43
Author: John Sanda <jsanda(a)redhat.com>
Date: Fri Dec 10 09:44:46 2010 -0500
Adding queries to generate plugin stats
The stats include the number of resource types and resources of those
types in a given plugin. The idea is that these stats can be displayed
to the user immediately prior to deleting a plugin so that he is aware
of what is going to happen. These stats might otherwise be useful in
other areas of the app like a portlet that displays summary info on the
system.
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
index 33188c5..dff6d58 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
@@ -351,6 +351,8 @@ import org.rhq.core.domain.util.Summary;
"SELECT r.id "
+ "FROM Resource r "
+ "WHERE r.resourceType.id IN (:resourceTypeIds)"),
+ @NamedQuery(name = Resource.QUERY_FIND_COUNT_BY_TYPES, query =
+ "SELECT COUNT(r) FROM Resource r WHERE r.resourceType.id IN (:resourceTypeIds)"),
@NamedQuery(name = Resource.QUERY_FIND_BY_TYPE_AND_IDS_ADMIN, query = "" //
+ "SELECT res " //
+ " FROM Resource res " //
@@ -792,6 +794,7 @@ public class Resource implements Comparable<Resource>, Serializable {
public static final String QUERY_FIND_BY_TYPE_ADMIN = "Resource.findByType_admin";
public static final String QUERY_FIND_IDS_BY_TYPE_IDS = "Resource.findIDsByType";
+ public static final String QUERY_FIND_COUNT_BY_TYPES = "Resource.findCountByTypes";
public static final String QUERY_FIND_BY_TYPE_AND_IDS = "Resource.findByTypeAndIds";
public static final String QUERY_FIND_BY_TYPE_AND_IDS_ADMIN = "Resource.findByTypeAndIds_admin";
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
index 78b3be6..947bf62 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
@@ -191,7 +191,11 @@ import org.rhq.core.domain.util.Summary;
@NamedQuery(name = ResourceType.QUERY_DYNAMIC_CONFIG_WITH_PLUGIN, query = "" //
+ "SELECT rt.plugin || ' - ' || rt.name, rt.plugin || '-' || rt.name FROM ResourceType rt WHERE rt.deleted = false"), //
@NamedQuery(name = ResourceType.QUERY_MARK_TYPES_DELETED, query =
- "UPDATE ResourceType t SET t.deleted = true WHERE t.id IN (:resourceTypeIds)")
+ "UPDATE ResourceType t SET t.deleted = true WHERE t.id IN (:resourceTypeIds)"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_IDS_BY_PLUGIN, query =
+ "SELECT t.id FROM ResourceType t WHERE t.plugin = :plugin AND t.deleted = false"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_COUNT_BY_PLUGIN, query =
+ "SELECT COUNT(t) FROM ResourceType t WHERE t.plugin = :plugin AND t.deleted = false")
})
@NamedNativeQueries( {
// TODO: Add authz conditions to the below query.
@@ -285,6 +289,9 @@ public class ResourceType implements Serializable, Comparable<ResourceType> {
public static final String QUERY_MARK_TYPES_DELETED = "ResourceType.markTypesDeleted";
+ public static final String QUERY_FIND_IDS_BY_PLUGIN = "ResourceType.findIdsByPlugin";
+ public static final String QUERY_FIND_COUNT_BY_PLUGIN = "ResourceType.findCountByPlugin";
+
@Id
@Column(name = "ID", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java.orig b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java.orig
new file mode 100644
index 0000000..2a55b7b
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java.orig
@@ -0,0 +1,863 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.core.domain.resource;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EntityResult;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedNativeQueries;
+import javax.persistence.NamedNativeQuery;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.OrderBy;
+import javax.persistence.PrePersist;
+import javax.persistence.PreUpdate;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.SqlResultSetMapping;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.rhq.core.domain.bundle.BundleType;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.content.PackageType;
+import org.rhq.core.domain.event.EventDefinition;
+import org.rhq.core.domain.measurement.MeasurementDefinition;
+import org.rhq.core.domain.operation.OperationDefinition;
+import org.rhq.core.domain.resource.group.ResourceGroup;
+import org.rhq.core.domain.util.Summary;
+
+/**
+ * Defines a type of {@link Resource} (e.g. a Linux platform, a JBossAS server, or a Datasource service).
+ * Unique business key (and therefore equals/hashCode basis) is the (String name, String plugin) combination.
+ * This will keep plugin writers from stepping on each other's toes.
+ *
+ * @author Greg Hinkle
+ * @author Ian Springer
+ */
+@Entity
+@Table(name = ResourceType.TABLE_NAME)
+@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_RESOURCE_TYPE_ID_SEQ")
+@NamedQueries( {
+ @NamedQuery(name = ResourceType.QUERY_FIND_BY_PLUGIN, query = "SELECT rt FROM ResourceType AS rt " +
+ "WHERE rt.plugin = :plugin AND rt.deleted = false"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_BY_NAME_AND_PLUGIN, // TODO: QUERY: names are case-sensitive
+ query = "SELECT rt FROM ResourceType AS rt WHERE LOWER(rt.name) = LOWER(:name) AND rt.plugin = :plugin " +
+ "AND rt.deleted = false"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_ALL, query = "SELECT rt FROM ResourceType AS rt where rt.deleted = false"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_BY_PARENT_AND_NAME, // TODO: QUERY: Not looking up by the full key, get rid of this query
+ query = "SELECT rt FROM ResourceType AS rt WHERE :parent MEMBER OF rt.parentResourceTypes AND rt.name = :name " +
+ "AND rt.deleted = false"),
+
+ /* authz'ed queries for ResourceTypeManagerBean */
+ @NamedQuery(name = ResourceType.QUERY_FIND_CHILDREN, query = "SELECT c "
+ + "FROM ResourceType rt JOIN rt.childResourceTypes c WHERE rt.id = :resourceTypeId AND rt.deleted = false "
+ + "AND c.deleted = false"),
+ @NamedQuery(name = ResourceType.FIND_CHILDREN_BY_PARENT, query = "SELECT DISTINCT rt FROM ResourceType AS rt "
+ + "JOIN FETCH rt.parentResourceTypes AS pa " + // also fetch parents, as we need them later
+ "WHERE rt.deleted = false and pa IN (:resourceType)"),
+ // template count composites need the parent types fetched; however, because of a quirk in hibernate,
+ // we can't use the template component constructor in the select, we'll build the composites in our code
+ @NamedQuery(name = ResourceType.FIND_ALL_TEMPLATE_COUNT_COMPOSITES, query = "" //
+ + "SELECT new org.rhq.core.domain.resource.composite.ResourceTypeTemplateCountComposite" //
+ + "(" //
+ + " rt," //
+ + " (SELECT COUNT(md) FROM MeasurementDefinition AS md WHERE md.resourceType = rt AND md.defaultOn = TRUE), "//
+ + " (SELECT COUNT(md) FROM MeasurementDefinition AS md WHERE md.resourceType = rt AND md.defaultOn = FALSE), "//
+ + " (SELECT COUNT(ad) FROM AlertDefinition AS ad WHERE ad.resourceType = rt AND ad.deleted = FALSE AND ad.enabled = TRUE), "//
+ + " (SELECT COUNT(ad) FROM AlertDefinition AS ad WHERE ad.resourceType = rt AND ad.deleted = FALSE AND ad.enabled = FALSE) "//
+ + ")" //
+ + "FROM ResourceType AS rt WHERE rt.deleted = false"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_BY_CATEGORY, query = "SELECT rt FROM ResourceType AS rt "
+ + "WHERE rt.category = :category and rt.deleted = false"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_UTILIZED_BY_CATEGORY, query = "SELECT DISTINCT res.resourceType "
+ + "FROM Resource res, IN (res.implicitGroups) g, IN (g.roles) r, IN (r.subjects) s " //
+ + "WHERE s = :subject " //
+ + "AND res.resourceType.category = :category "
+ + "AND res.resourceType.deleted = false "
+ + "AND (UPPER(res.name) LIKE :nameFilter ESCAPE :escapeChar OR :nameFilter is null) "
+ + "AND (res.resourceType.plugin = :pluginName OR :pluginName is null) "
+ + "AND (:inventoryStatus = res.inventoryStatus OR :inventoryStatus is null) "
+ + "ORDER BY res.resourceType.name "),
+ @NamedQuery(name = ResourceType.QUERY_FIND_UTILIZED_BY_CATEGORY_admin, query = "SELECT DISTINCT res.resourceType "
+ + "FROM Resource res " //
+ + "WHERE res.resourceType.category = :category "
+ + "AND (UPPER(res.name) LIKE :nameFilter ESCAPE :escapeChar OR :nameFilter is null) "
+ + "AND res.resourceType.deleted = false "
+ + "AND (res.resourceType.plugin = :pluginName OR :pluginName is null) "
+ + "AND (:inventoryStatus = res.inventoryStatus OR :inventoryStatus is null) "
+ + "ORDER BY res.resourceType.name "),
+ @NamedQuery(name = ResourceType.QUERY_FIND_UTILIZED_CHILDREN_BY_CATEGORY, query = "SELECT DISTINCT res.resourceType "
+ + "FROM Resource res, IN (res.implicitGroups) g, IN (g.roles) r, IN (r.subjects) s "
+ + "WHERE s = :subject "
+ + "AND res.parentResource = :parentResource "
+ + "AND res.resourceType.category = :category "
+ + "AND res.resourceType.deleted = false "
+ + "AND (:inventoryStatus = res.inventoryStatus OR :inventoryStatus is null) "),
+ @NamedQuery(name = ResourceType.QUERY_FIND_UTILIZED_CHILDREN_BY_CATEGORY_admin, query = "SELECT DISTINCT res.resourceType "
+ + "FROM Resource res "
+ + "WHERE res.parentResource = :parentResource "
+ + "AND res.resourceType.deleted = false "
+ + "AND res.resourceType.category = :category "
+ + "AND (:inventoryStatus = res.inventoryStatus OR :inventoryStatus is null) "),
+ @NamedQuery(name = ResourceType.QUERY_FIND_BY_RESOURCE_GROUP, query = "" //
+ + "SELECT DISTINCT rt " //
+ + " FROM ResourceGroup rg " //
+ + " JOIN rg.resourceType rt" //
+ + " JOIN rg.roles r JOIN r.subjects s " //
+ + " WHERE s = :subject " //
+ + " AND rt.deleted = false "
+ + " AND ( rt.plugin = :pluginName OR :pluginName is null ) "),
+ @NamedQuery(name = ResourceType.QUERY_FIND_BY_RESOURCE_GROUP_admin, query = "" //
+ + "SELECT DISTINCT rt " //
+ + " FROM ResourceGroup rg " //
+ + " JOIN rg.resourceType rt" //
+ + " WHERE rt.deleted = false AND ( rt.plugin = :pluginName OR :pluginName is null ) "),
+ @NamedQuery(name = ResourceType.QUERY_GET_EXPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP, query = "SELECT type.id, type.name, COUNT(type.id) "
+ + "FROM ResourceGroup rg JOIN rg.explicitResources res JOIN res.resourceType type "
+ + "WHERE rg.id = :groupId AND res.resourceType.deleted = false "
+ + "GROUP BY type.id, type.name "),
+ @NamedQuery(name = ResourceType.QUERY_GET_IMPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP, query = "SELECT type.id, type.name, COUNT(type.id) "
+ + "FROM ResourceGroup rg JOIN rg.implicitResources res JOIN res.resourceType type "
+ + "WHERE rg.id = :groupId AND res.resourceType.deleted = false "
+ + "GROUP BY type.id, type.name "),
+ @NamedQuery(name = ResourceType.QUERY_FIND_BY_SUBCATEGORY, query = "SELECT rt " + "FROM ResourceType rt "
+ + "WHERE rt.subCategory = :subCategory AND rt.deleted = false"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_BY_ID_WITH_ALL_OPERATIONS, query = "SELECT DISTINCT rt "
+ + "FROM ResourceType rt " + "LEFT JOIN FETCH rt.operationDefinitions def "
+ + "LEFT JOIN FETCH def.parametersConfigurationDefinition "
+ + "LEFT JOIN FETCH def.resultsConfigurationDefinition " + "WHERE rt.id = :id AND rt.deleted = false"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_RESOURCE_FACETS, query = "" //
+ + "SELECT new org.rhq.core.domain.resource.composite.ResourceFacets " //
+ + " ( " //
+ + " rt.id," // the resourceTypeId
+ + " (SELECT COUNT(metricDef) FROM rt.metricDefinitions metricDef)," // measurement
+ + " (SELECT COUNT(eventDef) FROM rt.eventDefinitions eventDef)," // event
+ + " (SELECT COUNT(pluginConfig) FROM rt.pluginConfigurationDefinition pluginConfig)," // pluginConfiguration
+ + " (SELECT COUNT(resConfig) FROM rt.resourceConfigurationDefinition resConfig)," // configuration
+ + " (SELECT COUNT(operationDef) FROM rt.operationDefinitions operationDef)," // operation
+ + " (SELECT COUNT(packageType) FROM rt.packageTypes packageType)," // content
+ + " (SELECT COUNT(metricDef) FROM rt.metricDefinitions metricDef WHERE metricDef.dataType = 3)," // calltime
+ + " (SELECT COUNT(propDef) FROM rt.pluginConfigurationDefinition pluginConfig JOIN pluginConfig.propertyDefinitions propDef WHERE propDef.name = 'snapshotLogEnabled')" // support
+ + " ) " //
+ + " FROM ResourceType rt " //
+ + " WHERE rt.deleted = false AND ( rt.id = :resourceTypeId OR :resourceTypeId IS NULL )"),
+ @NamedQuery(name = ResourceType.QUERY_FIND_DUPLICATE_TYPE_NAMES, query = "" //
+ + " SELECT rt.name " //
+ + " FROM ResourceType rt " //
+ + " WHERE rt.deleted = false "
+ + " GROUP BY rt.name " //
+ + " HAVING COUNT(rt.name) > 1"), //
+ @NamedQuery(name = ResourceType.QUERY_DYNAMIC_CONFIG_WITH_PLUGIN, query = "" //
+ + "SELECT rt.plugin || ' - ' || rt.name, rt.plugin || '-' || rt.name FROM ResourceType rt WHERE rt.deleted = false"), //
+ @NamedQuery(name = ResourceType.QUERY_MARK_TYPES_DELETED, query =
+ "UPDATE ResourceType t SET t.deleted = true WHERE t.id IN (:resourceTypeIds)")
+})
+@NamedNativeQueries( {
+ // TODO: Add authz conditions to the below query.
+ @NamedNativeQuery(name = ResourceType.QUERY_FIND_CHILDREN_BY_CATEGORY, query = "" //
+<<<<<<< HEAD
+ + "(SELECT crt.id, crt.name, crt.category, crt.creation_data_type, crt.create_delete_policy, crt.singleton, "
+ + "crt.supports_manual_add, crt.description, crt.plugin, crt.ctime, crt.mtime, crt.subcategory_id, "
+ + "crt.plugin_config_def_id, crt.res_config_def_id, crt.deleted "
+=======
+ + "(SELECT crt.id, crt.name, crt.category, crt.creation_data_type, crt.create_delete_policy, crt.singleton, crt.supports_manual_add, crt.description, crt.plugin, crt.ctime, crt.mtime, crt.deleted, crt.subcategory_id, crt.plugin_config_def_id, crt.res_config_def_id "
+>>>>>>> master
+ + "FROM RHQ_resource_type crt, RHQ_resource res, RHQ_resource_type rt, RHQ_resource_type_parents rtp "
+ + "WHERE res.id = ? "
+ + "AND crt.deleted = false "
+ + "AND res.resource_type_id = rt.id "
+ + "AND rt.id = rtp.parent_resource_type_id "
+ + "AND rtp.resource_type_id = crt.id "
+ + "AND crt.category = ? "
+ +
+ // "ORDER BY crt.name " +
+ "UNION "
+<<<<<<< HEAD
+ + "SELECT DISTINCT crt2.id, crt2.name, crt2.category, crt2.creation_data_type, crt2.create_delete_policy, "
+ + "crt2.singleton, crt2.supports_manual_add, crt2.description, crt2.plugin, crt2.ctime, "
+ + "crt2.mtime, crt2.subcategory_id, crt2.plugin_config_def_id, crt2.res_config_def_id, crt2.deleted "
+ + "FROM RHQ_resource_type crt2 " + "WHERE crt2.deleted = false AND 1 = "
+=======
+ + "SELECT DISTINCT crt2.id, crt2.name, crt2.category, crt2.creation_data_type, crt2.create_delete_policy, crt2.singleton, crt2.supports_manual_add, crt2.description, crt2.plugin, crt2.ctime, crt2.mtime, crt2.deleted, crt2.subcategory_id, crt2.plugin_config_def_id, crt2.res_config_def_id "
+ + "FROM RHQ_resource_type crt2 " + "WHERE 1 = "
+>>>>>>> master
+ + "(SELECT COUNT(res2.id) "
+ + "FROM RHQ_resource res2, RHQ_resource_type rt2 "
+ + "WHERE res2.id = ? "
+ + "AND res2.resource_type_id = rt2.id " + "AND rt2.category = 'PLATFORM') "
+ + "AND 0 = "
+ + "(SELECT COUNT(rtp2.resource_type_id) "
+ + "FROM RHQ_resource_type_parents rtp2 "
+ + "WHERE rtp2.resource_type_id = crt2.id) "
+ + "AND crt2.deleted = false "
+ + "AND crt2.category = ? " + " ) ORDER BY name", resultSetMapping = ResourceType.MAPPING_FIND_CHILDREN_BY_CATEGORY),
+ @NamedNativeQuery(name = ResourceType.QUERY_FIND_CHILDREN_BY_CATEGORY_admin, query = "" //
+<<<<<<< HEAD
+ + "(SELECT crt.id, crt.name, crt.category, crt.creation_data_type, crt.create_delete_policy, crt.singleton, "
+ + "crt.supports_manual_add, crt.description, crt.plugin, crt.ctime, crt.mtime, crt.subcategory_id, "
+ + "crt.plugin_config_def_id, crt.res_config_def_id, crt.deleted "
+=======
+ + "(SELECT crt.id, crt.name, crt.category, crt.creation_data_type, crt.create_delete_policy, crt.singleton, crt.supports_manual_add, crt.description, crt.plugin, crt.ctime, crt.mtime, crt.deleted, crt.subcategory_id, crt.plugin_config_def_id, crt.res_config_def_id "
+>>>>>>> master
+ + "FROM RHQ_resource_type crt, RHQ_resource res, RHQ_resource_type rt, RHQ_resource_type_parents rtp "
+ + "WHERE res.id = ? "
+ + "AND crt.deleted = false "
+ + "AND res.resource_type_id = rt.id "
+ + "AND rt.id = rtp.parent_resource_type_id "
+ + "AND rtp.resource_type_id = crt.id "
+ + "AND crt.category = ? "
+ +
+ // "ORDER BY crt.name " +
+ "UNION "
+<<<<<<< HEAD
+ + "(SELECT DISTINCT crt2.id, crt2.name, crt2.category, crt2.creation_data_type, crt2.create_delete_policy, "
+ + "crt2.singleton, crt2.supports_manual_add, crt2.description, crt2.plugin, crt2.ctime, "
+ + "crt2.mtime, crt2.subcategory_id, crt2.plugin_config_def_id, crt2.res_config_def_id, "
+ + "crt2.deleted "
+ + "FROM RHQ_resource_type crt2 " + "WHERE crt2.deleted = false AND 1 = "
+=======
+ + "(SELECT DISTINCT crt2.id, crt2.name, crt2.category, crt2.creation_data_type, crt2.create_delete_policy, crt2.singleton, crt2.supports_manual_add, crt2.description, crt2.plugin, crt2.ctime, crt2.mtime, crt2.deleted, crt2.subcategory_id, crt2.plugin_config_def_id, crt2.res_config_def_id "
+ + "FROM RHQ_resource_type crt2 " + "WHERE 1 = "
+>>>>>>> master
+ + "(SELECT COUNT(res2.id) "
+ + "FROM RHQ_resource res2, RHQ_resource_type rt2 "
+ + "WHERE res2.id = ? "
+ + "AND res2.resource_type_id = rt2.id " + "AND rt2.category = 'PLATFORM') "
+ + "AND 0 = "
+ + "(SELECT COUNT(rtp2.resource_type_id) "
+ + "FROM RHQ_resource_type_parents rtp2 "
+ + "WHERE rtp2.resource_type_id = crt2.id) " + "AND crt2.category = ?" +
+ // "ORDER BY crt2.name" +
+ ")) ORDER BY name", resultSetMapping = ResourceType.MAPPING_FIND_CHILDREN_BY_CATEGORY) //
+})
+@SqlResultSetMapping(name = ResourceType.MAPPING_FIND_CHILDREN_BY_CATEGORY, entities = { @EntityResult(entityClass = ResourceType.class) })
+// @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
+public class ResourceType implements Serializable, Comparable<ResourceType> {
+ private static final long serialVersionUID = 2L;
+
+ public static final String TABLE_NAME = "RHQ_RESOURCE_TYPE";
+
+ public static final ResourceType ANY_PLATFORM_TYPE = null;
+
+ public static final String QUERY_GET_EXPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP = "ResourceType.getExplicitResourceTypeCountsByGroup";
+ public static final String QUERY_GET_IMPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP = "ResourceType.getImplicitResourceTypeCountsByGroup";
+ public static final String QUERY_FIND_BY_NAME_AND_PLUGIN = "ResourceType.findByNameAndPlugin";
+ public static final String QUERY_FIND_BY_PLUGIN = "ResourceType.findByPlugin";
+ public static final String QUERY_FIND_BY_PARENT_AND_NAME = "ResourceType.findByParentAndName";
+ public static final String QUERY_FIND_ALL = "ResourceType.findAll";
+ public static final String QUERY_FIND_BY_ID_WITH_ALL_OPERATIONS = "ResourceType.findByIdWithAllOperations";
+ public static final String QUERY_FIND_BY_CATEGORY = "ResourceType.findByCategory";
+ public static final String QUERY_FIND_CHILDREN = "ResourceType.findChildren";
+ /** find child resource types for resource :parentResource and category :category */
+ public static final String QUERY_FIND_CHILDREN_BY_CATEGORY = "ResourceType.findChildrenByCategory";
+ public static final String QUERY_FIND_CHILDREN_BY_CATEGORY_admin = "ResourceType.findChildrenByCategory_admin";
+ /** find utilized (i.e. represented in inventory) child resource types for resource :parentResource and category :category */
+ public static final String QUERY_FIND_UTILIZED_CHILDREN_BY_CATEGORY = "ResourceType.findUtilizedChildrenByCategory";
+ public static final String QUERY_FIND_UTILIZED_CHILDREN_BY_CATEGORY_admin = "ResourceType.findUtilizedChildrenByCategory_admin";
+ /** find child resource types for the resource type passed in :resourceType */
+ public static final String FIND_CHILDREN_BY_PARENT = "ResourceType.findChildrenByParent";
+ public static final String FIND_ALL_TEMPLATE_COUNT_COMPOSITES = "ResourceType.findAllTemplateCountComposites";
+ public static final String QUERY_FIND_BY_SUBCATEGORY = "ResourceType.findBySubCategory";
+ public static final String QUERY_FIND_UTILIZED_BY_CATEGORY = "ResourceType.findUtilizedByCategory";
+ public static final String QUERY_FIND_UTILIZED_BY_CATEGORY_admin = "ResourceType.findUtilizedByCategory_admin";
+ public static final String QUERY_FIND_BY_RESOURCE_GROUP = "ResourceType.findByResourceGroup";
+ public static final String QUERY_FIND_BY_RESOURCE_GROUP_admin = "ResourceType.findByResourceGroup_admin";
+
+ public static final String MAPPING_FIND_CHILDREN_BY_CATEGORY = "ResourceType.findChildrenByCategoryMapping";
+ public static final String QUERY_FIND_RESOURCE_FACETS = "ResourceType.findResourceFacets";
+ public static final String QUERY_FIND_DUPLICATE_TYPE_NAMES = "ResourceType.findDuplicateTypeNames";
+
+ public static final String QUERY_DYNAMIC_CONFIG_WITH_PLUGIN = "ResourceType.dynamicConfigWithPlugin";
+
+ public static final String QUERY_MARK_TYPES_DELETED = "ResourceType.markTypesDeleted";
+
+ @Id
+ @Column(name = "ID", nullable = false)
+ @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
+ @Summary(index = 0)
+ private int id;
+
+ @Column(name = "NAME", nullable = false)
+ @Summary(index = 1)
+ private String name;
+
+ @Column(name = "DESCRIPTION")
+ private String description;
+
+ @Column(name = "CATEGORY", nullable = false)
+ @Enumerated(EnumType.STRING)
+ @Summary(index = 2)
+ private ResourceCategory category;
+
+ @Column(name = "CREATION_DATA_TYPE", nullable = false)
+ @Enumerated(EnumType.STRING)
+ private ResourceCreationDataType creationDataType = ResourceCreationDataType.CONFIGURATION;
+
+ @Column(name = "CREATE_DELETE_POLICY", nullable = false)
+ @Enumerated(EnumType.STRING)
+ private CreateDeletePolicy createDeletePolicy = CreateDeletePolicy.BOTH;
+
+ @Column(name = "SUPPORTS_MANUAL_ADD", nullable = false)
+ private boolean supportsManualAdd;
+
+ @Column(name = "SINGLETON", nullable = false)
+ private boolean singleton;
+
+ @Column(name = "PLUGIN", nullable = false)
+ @Summary(index = 3)
+ private String plugin;
+
+ @Column(name = "CTIME")
+ private Long ctime;
+
+ @Column(name = "MTIME")
+ private Long mtime;
+
+ @Column(name = "DELETED")
+ private boolean deleted;
+
+ @ManyToMany(mappedBy = "parentResourceTypes", cascade = { CascadeType.REFRESH })
+ @OrderBy
+ //@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
+ private Set<ResourceType> childResourceTypes;
+
+ @ManyToMany(cascade = CascadeType.PERSIST)
+ // persist so self-injecting plugins work
+ @JoinTable(name = "RHQ_RESOURCE_TYPE_PARENTS", joinColumns = { @JoinColumn(name = "RESOURCE_TYPE_ID") }, inverseJoinColumns = { @JoinColumn(name = "PARENT_RESOURCE_TYPE_ID") })
+ @OrderBy
+ //@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
+ private Set<ResourceType> parentResourceTypes;
+
+ @JoinColumn(name = "PLUGIN_CONFIG_DEF_ID")
+ @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ //@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
+ private ConfigurationDefinition pluginConfigurationDefinition;
+
+ @JoinColumn(name = "RES_CONFIG_DEF_ID")
+ @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ //@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
+ private ConfigurationDefinition resourceConfigurationDefinition;
+
+ @JoinColumn(name = "SUBCATEGORY_ID")
+ @ManyToOne(fetch = FetchType.LAZY)
+ private ResourceSubCategory subCategory;
+
+ @OneToMany(mappedBy = "resourceType", cascade = CascadeType.ALL)
+ @OrderBy
+ // primary key
+ //@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
+ private Set<MeasurementDefinition> metricDefinitions = new LinkedHashSet<MeasurementDefinition>();
+
+ @OneToMany(mappedBy = "resourceType", cascade = CascadeType.ALL)
+ @OrderBy
+ // primary key
+ //@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
+ private Set<EventDefinition> eventDefinitions;
+
+ @OneToMany(mappedBy = "resourceType", cascade = CascadeType.ALL)
+ @OrderBy
+ // primary key
+ private Set<OperationDefinition> operationDefinitions = new HashSet<OperationDefinition>();
+
+ @JoinColumn(name = "RESOURCE_TYPE_ID")
+ @OneToMany(cascade = CascadeType.ALL)
+ private Set<ProcessScan> processScans;
+
+ @OneToMany(mappedBy = "resourceType", cascade = CascadeType.ALL)
+ private Set<PackageType> packageTypes = new HashSet<PackageType>();
+
+ @OneToMany(mappedBy = "resourceType", cascade = CascadeType.ALL)
+ private List<ResourceSubCategory> subCategories;
+
+ @OneToMany(mappedBy = "resourceType", cascade = CascadeType.REMOVE)
+ private List<Resource> resources;
+
+ @OneToMany(mappedBy = "resourceType", cascade = CascadeType.REMOVE)
+ private List<ResourceGroup> resourceGroups;
+
+ @OneToMany(mappedBy = "resourceType", cascade = CascadeType.ALL)
+ private Set<ProductVersion> productVersions;
+
+ @OneToOne(mappedBy = "resourceType", fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = true)
+ private BundleType bundleType;
+
+ @Transient
+ private transient String helpText;
+
+ @Transient
+ private transient ClassLoaderType classLoaderType;
+
+ /* no-arg constructor required by EJB spec and Externalizable (Externalizable also requires it to be public) */
+ public ResourceType() {
+ // Intentionally left blank
+ }
+
+ public ResourceType(String name, String plugin, ResourceCategory category, ResourceType parentResourceType) {
+ if (name == null) {
+ throw new IllegalArgumentException("name==null");
+ }
+ if (plugin == null) {
+ throw new IllegalArgumentException("plugin==null");
+ }
+
+ // Initialize empty ordered lists...
+ this.childResourceTypes = new LinkedHashSet<ResourceType>();
+ this.parentResourceTypes = new LinkedHashSet<ResourceType>();
+ this.metricDefinitions = new LinkedHashSet<MeasurementDefinition>();
+ this.eventDefinitions = new LinkedHashSet<EventDefinition>();
+ this.operationDefinitions = new LinkedHashSet<OperationDefinition>();
+ this.processScans = new HashSet<ProcessScan>();
+ this.packageTypes = new HashSet<PackageType>();
+ this.subCategories = new ArrayList<ResourceSubCategory>();
+ this.productVersions = new HashSet<ProductVersion>();
+
+ this.name = name;
+ this.category = category;
+ this.plugin = plugin;
+ this.mtime = this.ctime = System.currentTimeMillis();
+
+ if (parentResourceType != null) {
+ parentResourceType.addChildResourceType(this);
+ }
+ }
+
+ public int getId() {
+ return this.id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public ResourceCategory getCategory() {
+ return this.category;
+ }
+
+ public void setCategory(ResourceCategory category) {
+ this.category = category;
+ }
+
+ public ResourceCreationDataType getCreationDataType() {
+ return creationDataType;
+ }
+
+ public void setCreationDataType(ResourceCreationDataType creationDataType) {
+ if (creationDataType == null)
+ throw new IllegalArgumentException("creationDataType cannot be null");
+
+ this.creationDataType = creationDataType;
+ }
+
+ public CreateDeletePolicy getCreateDeletePolicy() {
+ return createDeletePolicy;
+ }
+
+ public void setCreateDeletePolicy(CreateDeletePolicy createDeletePolicy) {
+ if (createDeletePolicy == null)
+ throw new IllegalArgumentException("createDeletePolicy cannot be null");
+
+ this.createDeletePolicy = createDeletePolicy;
+ }
+
+ public boolean isCreatable() {
+ return (createDeletePolicy == CreateDeletePolicy.BOTH || createDeletePolicy == CreateDeletePolicy.CREATE_ONLY);
+ }
+
+ public boolean isDeletable() {
+ return (createDeletePolicy == CreateDeletePolicy.BOTH || createDeletePolicy == CreateDeletePolicy.DELETE_ONLY);
+ }
+
+ /**
+ * Returns the ResourceSubCategory, if any, which this ResourceType
+ * has been tagged with. If the ResourceType has not been tagged with
+ * a subcategory, <code>null</code> is returned.
+ */
+ public ResourceSubCategory getSubCategory() {
+ return this.subCategory;
+ }
+
+ /**
+ * Tags this ResourceType as being part of the specified ResourceSubCategory
+ */
+ public void setSubCategory(ResourceSubCategory subcategory) {
+ this.subCategory = subcategory;
+ }
+
+ /**
+ * If true, this resource may only ever have one discovered instance per parent resource.
+ * @return true if this is a singleton resource
+ */
+ public boolean isSingleton() {
+ return singleton;
+ }
+
+ /**
+ * @param singleton true if there is only ever one discovered instance per parent resource
+ */
+ public void setSingleton(boolean singleton) {
+ this.singleton = singleton;
+ }
+
+ public boolean isSupportsManualAdd() {
+ return supportsManualAdd;
+ }
+
+ public void setSupportsManualAdd(boolean supportsManualAdd) {
+ this.supportsManualAdd = supportsManualAdd;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getPlugin() {
+ return this.plugin;
+ }
+
+ public void setPlugin(String plugin) {
+ this.plugin = plugin;
+ }
+
+ public long getCtime() {
+ return this.ctime;
+ }
+
+ @PrePersist
+ void onPersist() {
+ this.mtime = this.ctime = System.currentTimeMillis();
+ }
+
+ public long getMtime() {
+ return this.mtime;
+ }
+
+ public boolean isDeleted() {
+ return deleted;
+ }
+
+ public void setDeleted(boolean deleted) {
+ this.deleted = deleted;
+ }
+
+ @PreUpdate
+ void onUpdate() {
+ this.mtime = System.currentTimeMillis();
+ }
+
+ public List<Resource> getResources() {
+ return resources;
+ }
+
+ public void setResources(List<Resource> resources) {
+ this.resources = resources;
+ }
+
+ public List<ResourceGroup> getResourceGroups() {
+ return resourceGroups;
+ }
+
+ public void setResourceGroups(List<ResourceGroup> resourceGroups) {
+ this.resourceGroups = resourceGroups;
+ }
+
+ public Set<ResourceType> getParentResourceTypes() {
+ return this.parentResourceTypes;
+ }
+
+ public void setParentResourceTypes(Set<ResourceType> parentResourceTypes) {
+ this.parentResourceTypes = parentResourceTypes;
+ }
+
+ /**
+ * Makes this resource type a child of the given parent resource type.
+ * @param parentResourceType
+ */
+ public void addParentResourceType(ResourceType parentResourceType) {
+ parentResourceType.childResourceTypes.add(this);
+ this.parentResourceTypes.add(parentResourceType);
+ }
+
+ /**
+ * Removes the given resource type as a parent of this resource type.
+ * @param oldParentResourceType
+ */
+ public void removeParentResourceType(ResourceType oldParentResourceType) {
+ oldParentResourceType.childResourceTypes.remove(this);
+ this.parentResourceTypes.remove(oldParentResourceType);
+ }
+
+ public Set<ResourceType> getChildResourceTypes() {
+ return this.childResourceTypes;
+ }
+
+ /**
+ * Makes this resource type a parent of the given child resource type.
+ * @param childResourceType
+ */
+ public void addChildResourceType(ResourceType childResourceType) {
+ childResourceType.parentResourceTypes.add(this);
+ this.childResourceTypes.add(childResourceType);
+ }
+
+ /**
+ * Removes the given resource type as a child of this resource type.
+ * @param oldChildResourceType
+ */
+ public void removeChildResourceType(ResourceType oldChildResourceType) {
+ oldChildResourceType.parentResourceTypes.remove(this);
+ this.childResourceTypes.remove(oldChildResourceType);
+ }
+
+ public void setChildResourceTypes(Set<ResourceType> childResourceTypes) {
+ this.childResourceTypes = childResourceTypes;
+ }
+
+ public ConfigurationDefinition getPluginConfigurationDefinition() {
+ return pluginConfigurationDefinition;
+ }
+
+ public void setPluginConfigurationDefinition(ConfigurationDefinition pluginConfigurationDefinition) {
+ this.pluginConfigurationDefinition = pluginConfigurationDefinition;
+ }
+
+ public ConfigurationDefinition getResourceConfigurationDefinition() {
+ return resourceConfigurationDefinition;
+ }
+
+ public void setResourceConfigurationDefinition(ConfigurationDefinition resourceConfigurationDefinition) {
+ this.resourceConfigurationDefinition = resourceConfigurationDefinition;
+ }
+
+ @XmlTransient
+ public Set<MeasurementDefinition> getMetricDefinitions() {
+ return metricDefinitions;
+ }
+
+ public void setMetricDefinitions(Set<MeasurementDefinition> metricDefinitions) {
+ this.metricDefinitions = metricDefinitions;
+ }
+
+ public boolean addMetricDefinition(MeasurementDefinition metricDef) {
+ metricDef.setResourceType(this);
+ return this.metricDefinitions.add(metricDef);
+ }
+
+ @XmlTransient
+ public Set<EventDefinition> getEventDefinitions() {
+ return eventDefinitions;
+ }
+
+ public void setEventDefinitions(Set<EventDefinition> eventDefinitions) {
+ this.eventDefinitions = eventDefinitions;
+ }
+
+ public void addEventDefinition(EventDefinition eventDefinition) {
+ this.eventDefinitions.add(eventDefinition);
+ }
+
+ public Set<OperationDefinition> getOperationDefinitions() {
+ return operationDefinitions;
+ }
+
+ public void setOperationDefinitions(Set<OperationDefinition> operationDefinitions) {
+ this.operationDefinitions = operationDefinitions;
+ }
+
+ public boolean addOperationDefinition(OperationDefinition operationDefinition) {
+ operationDefinition.setResourceType(this);
+ return this.operationDefinitions.add(operationDefinition);
+ }
+
+ public Set<ProcessScan> getProcessScans() {
+ return this.processScans;
+ }
+
+ public void setProcessScans(Set<ProcessScan> processScans) {
+ this.processScans = processScans;
+ }
+
+ public boolean addProcessScan(ProcessScan processMatch) {
+ // this is unidirection - no need to set this resource this on process match
+
+ if (this.processScans == null) {
+ this.processScans = new HashSet<ProcessScan>();
+ }
+ return this.processScans.add(processMatch);
+ }
+
+ public Set<PackageType> getPackageTypes() {
+ return packageTypes;
+ }
+
+ public void setPackageTypes(Set<PackageType> packageTypes) {
+ this.packageTypes = packageTypes;
+ }
+
+ public void addPackageType(PackageType packageType) {
+ packageType.setResourceType(this);
+ packageTypes.add(packageType);
+ }
+
+ public void removePackageType(PackageType packageType) {
+ packageTypes.remove(packageType);
+ packageType.setResourceType(null);
+ }
+
+ /**
+ * Returns the List of child ResourceSubCategorys which have been defined
+ * on this ResourceType. These ResourceSubCategory's are available to
+ * tag any child ResourceTypes of this ResourceType.
+ *
+ * @return the list of ResourceSubCategory's which have been defined
+ * on this ResourceType
+ */
+ public List<ResourceSubCategory> getChildSubCategories() {
+ return this.subCategories;
+ }
+
+ /**
+ * Sets the List of child ResourceSubCategorys for this ResourceType.
+ *
+ * @param subCategories the List of ResourceSubCategory's for this ResourceType
+ */
+ public void setChildSubCategories(List<ResourceSubCategory> subCategories) {
+ this.subCategories = subCategories;
+ }
+
+ /**
+ * Adds a child ResourceSubCategory to the List which has been defined
+ * on this ResourceType.
+ */
+ public void addChildSubCategory(ResourceSubCategory subCategory) {
+ if (this.subCategories == null) {
+ this.subCategories = new ArrayList<ResourceSubCategory>();
+ }
+ subCategory.setResourceType(this);
+ this.subCategories.add(subCategory);
+ }
+
+ public Set<ProductVersion> getProductVersions() {
+ return productVersions;
+ }
+
+ public void setProductVersions(Set<ProductVersion> productVersions) {
+ this.productVersions = productVersions;
+ }
+
+ public int compareTo(ResourceType that) {
+ return this.name.compareTo(that.getName());
+ }
+
+ public String getHelpText() {
+ return helpText;
+ }
+
+ public void setHelpText(String helpText) {
+ this.helpText = helpText;
+ }
+
+ public ClassLoaderType getClassLoaderType() {
+ return classLoaderType;
+ }
+
+ public void setClassLoaderType(ClassLoaderType classLoaderType) {
+ this.classLoaderType = classLoaderType;
+ }
+
+ public BundleType getBundleType() {
+ return this.bundleType;
+ }
+
+ public void setBundleType(BundleType bundleType) {
+ this.bundleType = bundleType;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null || !(obj instanceof ResourceType))
+ return false;
+ ResourceType that = (ResourceType) obj;
+ if (this.name != null ? !this.name.equals(that.name) : that.name != null)
+ return false;
+ if (this.plugin != null ? !this.plugin.equals(that.plugin) : that.plugin != null)
+ return false;
+ //only compare id's if they've both been set
+ if (this.id != 0 && that.id != 0 && this.id != that.id)
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result;
+ if (name != null && this.plugin != null) {
+ result = (this.name != null ? this.name.hashCode() : 0);
+ result = 31 * result + (this.plugin != null ? plugin.hashCode() : 0);
+ } else {
+ result = 31 * id;
+ }
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "ResourceType[id=" + this.id + ", category=" + this.category + ", name=" + this.name + ", plugin="
+ + this.plugin + "]";
+ }
+
+}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/inventory/InventoryManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/inventory/InventoryManagerBean.java
index 420533c..c159275 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/inventory/InventoryManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/inventory/InventoryManagerBean.java
@@ -55,9 +55,7 @@ public class InventoryManagerBean implements InventoryManagerLocal {
int typesDeleted = 0;
BatchIterator<Integer> batchIterator = new BatchIterator<Integer>(resourceTypeIds);
for (List<Integer> typeIdsBatch : batchIterator) {
- List<Integer> resourceIds = entityMgr.createNamedQuery(Resource.QUERY_FIND_IDS_BY_TYPE_IDS)
- .setParameter("resourceTypeIds", typeIdsBatch)
- .getResultList();
+ List<Integer> resourceIds = resourceMgr.findIdsByTypeIds(typeIdsBatch);
resourceMgr.uninventoryResources(subjectMgr.getOverlord(), toIntArray(resourceIds));
Query query = entityMgr.createNamedQuery(ResourceType.QUERY_MARK_TYPES_DELETED);
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
index e61fc0c..7acac6b 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
@@ -2327,4 +2327,18 @@ public class ResourceManagerBean implements ResourceManagerLocal, ResourceManage
return Disambiguator.disambiguate(results, updateStrategy, extractor, entityManager, typeManager
.getDuplicateTypeNames());
}
+
+ @SuppressWarnings("unchecked")
+ public List<Integer> findIdsByTypeIds(List<Integer> resourceTypeIds) {
+ return entityManager.createNamedQuery(Resource.QUERY_FIND_IDS_BY_TYPE_IDS)
+ .setParameter("resourceTypeIds", resourceTypeIds)
+ .getResultList();
+ }
+
+ @Override
+ public Integer getResourceCount(List<Integer> resourceTypeIds) {
+ return (Integer) entityManager.createNamedQuery(Resource.QUERY_FIND_COUNT_BY_TYPES)
+ .setParameter("resourceTypeIds", resourceTypeIds)
+ .getSingleResult();
+ }
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerLocal.java
index 0dccf06..38d68b6 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerLocal.java
@@ -470,4 +470,8 @@ public interface ResourceManagerLocal {
*/
<T> List<DisambiguationReport<T>> disambiguate(List<T> results, IntExtractor<? super T> resourceIdExtractor,
DisambiguationUpdateStrategy updateStrategy);
+
+ List<Integer> findIdsByTypeIds(List<Integer> resourceTypeIds);
+
+ Integer getResourceCount(List<Integer> resourceTypeIds);
}
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java
index 28386e7..b4086b9 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerBean.java
@@ -449,12 +449,18 @@ public class ResourceTypeManagerBean implements ResourceTypeManagerLocal, Resour
@SuppressWarnings("unchecked")
public List<Integer> getResourceTypeIdsByPlugin(String plugin) {
- return entityManager.createQuery(
- "select t.id from ResourceType t where t.plugin = :plugin and t.deleted = false")
+ return entityManager.createNamedQuery(ResourceType.QUERY_FIND_IDS_BY_PLUGIN)
.setParameter("plugin", plugin)
.getResultList();
}
+ @Override
+ public Integer getResourceTypeCountByPlugin(String plugin) {
+ return (Integer) entityManager.createNamedQuery(ResourceType.QUERY_FIND_COUNT_BY_PLUGIN)
+ .setParameter("plugin", plugin)
+ .getSingleResult();
+ }
+
@SuppressWarnings("unchecked")
public PageList<ResourceType> findResourceTypesByCriteria(Subject subject, ResourceTypeCriteria criteria) {
CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria);
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerLocal.java
index bc691e5..2a5d4d6 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceTypeManagerLocal.java
@@ -130,6 +130,8 @@ public interface ResourceTypeManagerLocal {
List<Integer> getResourceTypeIdsByPlugin(String plugin);
+ Integer getResourceTypeCountByPlugin(String plugin);
+
PageList<ResourceType> findResourceTypesByCriteria(Subject subject, ResourceTypeCriteria criteria);
List<String> getDuplicateTypeNames();
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginManagerBean.java
index 39563fb..15193c6 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginManagerBean.java
@@ -39,6 +39,7 @@ import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.authz.RequiredPermission;
import org.rhq.enterprise.server.inventory.InventoryManagerLocal;
+import org.rhq.enterprise.server.resource.ResourceManagerLocal;
import org.rhq.enterprise.server.resource.ResourceTypeManagerLocal;
@Stateless
@@ -66,6 +67,9 @@ public class PluginManagerBean implements PluginManagerLocal {
@EJB
private ResourceTypeManagerLocal resourceTypeMgr;
+ @EJB
+ private ResourceManagerLocal resourceMgr;
+
/**
* Returns the information on the given plugin as found in the database.
* @param name the name of a plugin
@@ -241,7 +245,6 @@ public class PluginManagerBean implements PluginManagerLocal {
for (Plugin plugin : plugins) {
if (plugin.getStatus().equals(PluginStatusType.INSTALLED)) {
long startTime = System.currentTimeMillis();
-// List<ResourceType> resourceTypes = resourceTypeMgr.getResourceTypesByPlugin(plugin.getName());
List<Integer> resourceTypeIds = resourceTypeMgr.getResourceTypeIdsByPlugin(plugin.getName());
Plugin managedPlugin = entityManager.merge(plugin);
inventoryMgr.markTypesDeleted(resourceTypeIds);
@@ -254,6 +257,20 @@ public class PluginManagerBean implements PluginManagerLocal {
}
}
+ @Override
+ public List<PluginStats> getPluginStats(List<Integer> pluginIds) {
+ List<PluginStats> stats = new ArrayList<PluginStats>();
+ List<Plugin> plugins = getAllPluginsById(pluginIds);
+
+ for (Plugin plugin : plugins) {
+ List<Integer> resourceTypeIds = resourceTypeMgr.getResourceTypeIdsByPlugin(plugin.getName());
+ Integer resourceCount = resourceMgr.getResourceCount(resourceTypeIds);
+ stats.add(new PluginStats(plugin, resourceTypeIds.size(), resourceCount));
+ }
+
+ return stats;
+ }
+
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void setPluginEnabledFlag(Subject subject, int pluginId, boolean enabled) throws Exception {
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginManagerLocal.java
index f46cf98..0a1ad1b 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginManagerLocal.java
@@ -49,6 +49,8 @@ public interface PluginManagerLocal {
List<Plugin> getPluginsByResourceTypeAndCategory(String resourceTypeName, ResourceCategory resourceCategory);
+ List<PluginStats> getPluginStats(List<Integer> pluginIds);
+
void enablePlugins(Subject subject, List<Integer> pluginIds) throws Exception;
void disablePlugins(Subject subject, List<Integer> pluginIds) throws Exception;
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginStats.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginStats.java
new file mode 100644
index 0000000..66c4759
--- /dev/null
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/PluginStats.java
@@ -0,0 +1,29 @@
+package org.rhq.enterprise.server.resource.metadata;
+
+import org.rhq.core.domain.plugin.Plugin;
+
+public class PluginStats {
+ private Plugin plugin;
+
+ private Integer resourceTypeCount;
+
+ private Integer resourceCount;
+
+ public PluginStats(Plugin plugin, Integer resourceTypeCount, Integer resourceCount) {
+ this.plugin = plugin;
+ this.resourceTypeCount = resourceTypeCount;
+ this.resourceCount = resourceCount;
+ }
+
+ public Plugin getPlugin() {
+ return plugin;
+ }
+
+ public Integer getResourceTypeCount() {
+ return resourceTypeCount;
+ }
+
+ public Integer getResourceCount() {
+ return resourceCount;
+ }
+}