[rhq] modules/enterprise
by Jay Shaughnessy
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java | 12 +++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
New commits:
commit bfc0a46761e3a13e17da91dd68be47c32952874e
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Jan 29 18:42:09 2013 -0500
Hopefully final tweeks to MergeInventoryReport
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
index cea1f6e..d5d7128 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
@@ -859,7 +859,6 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
log.debug("getExistingResource processing for [" + resource + "]");
}
- // We perform this query a lot during a large inventory merge, so minimize overhead by using it directly
Resource existingResource = null;
if (resource.getId() != 0) {
@@ -867,7 +866,8 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
log.debug("Agent claims resource is already in inventory. Id=" + resource.getId());
}
- existingResource = entityManager.getReference(Resource.class, resource.getId());
+ // This maybe could be more efficient using a named query that pulls some lazy data, but this should be fine
+ existingResource = entityManager.find(Resource.class, resource.getId());
if (isDebugEnabled) {
if (null != existingResource) {
log.debug("Found resource already in inventory. Id=" + resource.getId());
@@ -889,9 +889,10 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
+ ", key=" + resource.getResourceKey());
}
- // (jshaughn) I'm not 100% sure I understand the need for this while loop, but I believe it has to
- // do with handling the case in which a resource type has moved (see f74b22044) and trying to
- // relocate the parent. Anyway, I'm not going to touch it even though it slows things down.
+ // (jshaughn) I'm not 100% sure but I believe this loop has to do with either or both of:
+ // - protecting against the agent merging a resource it thinks is new but actually exists
+ // - handling the case in which a resource type has moved (see f74b22044) and trying to relocate the parent.
+ // Anyway, I'm not going to touch it even though it slows things down.
ResourceType resourceType = resource.getResourceType();
Resource parent = resource;
@@ -914,6 +915,7 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
}
if (null == existingParent) {
+ // I think getReference may be slightly faster here but it's likely negligible
existingParent = entityManager.getReference(Resource.class, parentId);
if (null != existingParent) {
if (null != parentMap) {
11 years, 3 months
[rhq] Branch 'feature/cassandra-backend' - modules/plugins
by John Sanda
modules/plugins/jmx/pom.xml | 7 +++++++
1 file changed, 7 insertions(+)
New commits:
commit ad0976da57e6b1b51299485b5be00b8a131c2329
Author: John Sanda <jsanda(a)redhat.com>
Date: Tue Jan 29 15:56:38 2013 -0500
completely disabling JMXPluginTest for now
Just disabling the test method where we hit the NPE causes the build to fail
since other test methods in the class depend on the disabled test method.
diff --git a/modules/plugins/jmx/pom.xml b/modules/plugins/jmx/pom.xml
index 16d4245..4936004 100644
--- a/modules/plugins/jmx/pom.xml
+++ b/modules/plugins/jmx/pom.xml
@@ -120,6 +120,13 @@
</goals>
<configuration>
<skip>${maven.test.skip}</skip>
+ <excludes>
+ <!--
+ Disabled to due a NPE that the test hits in vmUtility.attachToVirtualMachine on line 107 which
+ may be due to this Sigar bug, https://jira.hyperic.com/browse/SIGAR-231.
+ -->
+ <exclude>**/JMXPluginTest.java</exclude>
+ </excludes>
<excludedGroups>${rhq.testng.excludedGroups}</excludedGroups>
<useSystemClassLoader>true</useSystemClassLoader>
<argLine>${jacoco.integration-test.args} -Dorg.hyperic.sigar.path=${basedir}/target/itest/lib</argLine>
11 years, 3 months
[rhq] modules/enterprise
by Simeon Pinder
modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java | 2 +-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
New commits:
commit 9e70606deeb4654ae6117a8d36c322372ac63a27
Author: Simeon Pinder <spinder(a)fulliautomatix.conchfritter.com>
Date: Tue Jan 29 15:11:15 2013 -0500
[BZ 905632] fix MetadataManager query to use unlimited criteria queries.
diff --git a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
index 5beb643..dd5311b 100644
--- a/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
+++ b/modules/enterprise/server/itests-2/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
@@ -385,7 +385,7 @@ public class ResourceMetadataManagerBeanTest extends MetadataBeanTest {
resourcesServiceE1.get(0));
List<Resource> resourcesServiceE3 = createResources(2, "RemoveTypesPlugin", "ServiceE3",
resourcesServiceE2.get(0));
- List<Resource> resourcesServiceE4 = createResources(2, "RemoveTypesPlugin", "ServiceE4",
+ List<Resource> resourcesServiceE4 = createResources(205, "RemoveTypesPlugin", "ServiceE4",
resourcesServiceE3.get(0));
ResourceGroup rgRecursive = createResourceGroup("ServerE Group", "ServerE", "RemoveTypesPlugin", true);
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
index 2c8a925..9d844e4 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
@@ -56,6 +56,7 @@ import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceSubCategory;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.resource.group.ResourceGroup;
+import org.rhq.core.domain.util.PageControl;
import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.authz.RequiredPermission;
@@ -268,6 +269,7 @@ public class ResourceMetadataManagerBean implements ResourceMetadataManagerLocal
ResourceCriteria c = new ResourceCriteria();
c.addFilterResourceTypeId(existingType.getId());
c.addFilterInventoryStatus(null);
+ c.setPageControl(PageControl.getUnlimitedInstance());
List<Resource> resources = resourceManager.findResourcesByCriteria(subject, c);
if (resources != null) {
Iterator<Resource> resIter = resources.iterator();
11 years, 3 months
[rhq] Branch 'nightly/rhq4.6.0.jon' - 4 commits - modules/enterprise modules/helpers
by snegrea
modules/enterprise/server/jar/pom.xml | 107 +++++----
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java | 109 ++++++----
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertDefinitionHandlerBean.java | 62 ++++-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/RootHandlerBean.java | 6
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertConditionRest.java | 10
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertDefinitionRest.java | 7
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertNotificationRest.java | 4
modules/enterprise/server/jar/src/main/xsl/apiout2docbook.xsl | 22 +-
modules/helpers/rest-docs-generator/pom.xml | 9
modules/helpers/rest-docs-generator/src/main/java/org/rhq/helpers/rest_docs_generator/ClassLevelProcessor.java | 37 ++-
10 files changed, 246 insertions(+), 127 deletions(-)
New commits:
commit ffc824545987d3a3ec959b82208f79c933c2ae41
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Jan 29 14:23:16 2013 -0500
Even more MergeInventoryReport speed
- avoid slsb call overhead by performing relevant query locally
- remove unnecessary em.find
- convert some em.find calls to em.getReference
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
index 29ea65c..cea1f6e 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
@@ -37,6 +37,7 @@ import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.security.auth.login.LoginException;
@@ -866,7 +867,7 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
log.debug("Agent claims resource is already in inventory. Id=" + resource.getId());
}
- existingResource = entityManager.find(Resource.class, resource.getId());
+ existingResource = entityManager.getReference(Resource.class, resource.getId());
if (isDebugEnabled) {
if (null != existingResource) {
log.debug("Found resource already in inventory. Id=" + resource.getId());
@@ -893,7 +894,6 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
// relocate the parent. Anyway, I'm not going to touch it even though it slows things down.
ResourceType resourceType = resource.getResourceType();
Resource parent = resource;
- Subject overlord = subjectManager.getOverlord();
while (null != parent && null == existingResource) {
parent = parent.getParentResource();
@@ -914,7 +914,7 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
}
if (null == existingParent) {
- existingParent = entityManager.find(Resource.class, parentId);
+ existingParent = entityManager.getReference(Resource.class, parentId);
if (null != existingParent) {
if (null != parentMap) {
parentMap.put(parentId, existingParent);
@@ -928,8 +928,16 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
// We found the parent in inventory, so now see if we can find this resource in inventory by using
// the parent, the resource key (unique among siblings), the plugin and the type.
- existingResource = resourceManager.getResourceByParentAndKey(overlord, existingParent,
- resource.getResourceKey(), resourceType.getPlugin(), resourceType.getName());
+ Query query = entityManager.createNamedQuery(Resource.QUERY_FIND_BY_PARENT_AND_KEY);
+ query.setParameter("parent", existingParent);
+ query.setParameter("key", resource.getResourceKey());
+ query.setParameter("plugin", resourceType.getPlugin());
+ query.setParameter("typeName", resourceType.getName());
+ try {
+ existingResource = (Resource) query.getSingleResult();
+ } catch (NoResultException e) {
+ existingResource = null;
+ }
}
if (null != existingResource) {
@@ -957,6 +965,12 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
return existingResource;
}
+ /**
+ * <p>Requires A Transaction.</p>
+ * @param updatedResource pojo
+ * @param existingResource attached entity
+ * @throws InvalidInventoryReportException
+ */
private void updateExistingResource(Resource updatedResource, Resource existingResource)
throws InvalidInventoryReportException {
/*
@@ -974,9 +988,6 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
return;
}
- // get an attached entity to update
- existingResource = entityManager.find(Resource.class, existingResource.getId());
-
Resource existingParent = existingResource.getParentResource();
Resource updatedParent = updatedResource.getParentResource();
ResourceType existingResourceParentType = (existingParent != null) ? existingResource.getParentResource()
commit 16a2dc05205e491850e747368627ec54bdfdbedd
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Jan 29 11:36:46 2013 -0500
More mergeInventoryReport speed
- add map cache of attached parent entities to avoid redundant DB fetches
- replace named query fetch with simple em.find where possible
- trivial, rename some private methods that were named inappropriately
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
index 7a5d024..29ea65c 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
@@ -37,7 +37,6 @@ import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.security.auth.login.LoginException;
@@ -509,7 +508,7 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
+ resource.getResourceType());
}
- Resource existingResource = findExistingResource(resource);
+ Resource existingResource = findExistingResource(resource, null);
if (existingResource != null) {
mergeResourceResponse = new MergeResourceResponse(existingResource.getId(), true);
} else {
@@ -791,20 +790,22 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
long batchStart = System.currentTimeMillis();
boolean isDebugEnabled = log.isDebugEnabled();
+ // Cache parent resources we've already fetched from the DB, many resources will have the same parent
+ Map<Integer, Resource> parentMap = new HashMap<Integer, Resource>();
for (Resource resource : resourceBatch) {
Resource existingResource = null;
long start = System.currentTimeMillis();
- existingResource = findExistingResource(resource);
+ existingResource = findExistingResource(resource, parentMap);
// Does this resource already exist in inventory? If so, update, otherwise add
if (null != existingResource) {
- updateExistingResourceInNewTransaction(resource, existingResource);
+ updateExistingResource(resource, existingResource);
} else {
presetAgent(resource, agent);
- persistResourceInNewTransaction(resource);
+ persistResource(resource, parentMap);
}
if (isDebugEnabled) {
@@ -813,6 +814,9 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
}
}
+ // Help out the GC
+ parentMap.clear();
+
if (isDebugEnabled) {
long delta = (System.currentTimeMillis() - batchStart);
log.debug("Resource Batch merged: size/average/millis=" + resourceBatch.size() + "/" + delta
@@ -834,15 +838,19 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
}
/**
+ * <p>Requires A Transaction</p>
+ *
* Given a resource, will attempt to find it in the server's inventory (that is, finds it in the database). If the
* given resource's ID does not exist in the database, it will be looked up by its resource key. If the resource
* cannot be found either via ID or resource key then SIDE EFFECT: the given resource's ID will be reset to 0 and null
* will be returned.
*
- * @param resource Pojo containing resourceId, key, and parentResoure (if applicable)
+ * @param resource Pojo containing resourceId, key, and parentResoure (if applicable)
+ * @param parentMap, if supplied, holds previously fetched parent pojos. useful when the calling code does many
+ * finds for a few parents. If not found in the map the db will be searched, the map will be updated if possible.
* @return the Resource entity found in the database and matching the given resource.
*/
- private Resource findExistingResource(Resource resource) {
+ private Resource findExistingResource(Resource resource, Map<Integer, Resource> parentMap) {
boolean isDebugEnabled = log.isDebugEnabled();
@@ -850,27 +858,20 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
log.debug("getExistingResource processing for [" + resource + "]");
}
- // We perform this query a lot during a large inventory merge, so minimize overhead by using it directly
- Query query = entityManager.createNamedQuery(Resource.QUERY_FIND_BY_ID);
+ // We perform this query a lot during a large inventory merge, so minimize overhead by using it directly
Resource existingResource = null;
- Subject overlord = subjectManager.getOverlord();
if (resource.getId() != 0) {
if (isDebugEnabled) {
log.debug("Agent claims resource is already in inventory. Id=" + resource.getId());
}
- try {
- query.setParameter("resourceId", resource.getId());
- existingResource = (Resource) query.getSingleResult();
- if (isDebugEnabled) {
+ existingResource = entityManager.find(Resource.class, resource.getId());
+ if (isDebugEnabled) {
+ if (null != existingResource) {
log.debug("Found resource already in inventory. Id=" + resource.getId());
- }
- } catch (NoResultException e) {
- existingResource = null;
-
- // agent lied - agent's copy of JON server inventory must be stale.
- if (isDebugEnabled) {
+ } else {
+ // agent lied - agent's copy of JON server inventory must be stale.
log.debug("However, no resource exists with the specified id. Id=" + resource.getId());
}
}
@@ -892,6 +893,7 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
// relocate the parent. Anyway, I'm not going to touch it even though it slows things down.
ResourceType resourceType = resource.getResourceType();
Resource parent = resource;
+ Subject overlord = subjectManager.getOverlord();
while (null != parent && null == existingResource) {
parent = parent.getParentResource();
@@ -899,18 +901,28 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
// check if the parent is in inventory. This might not be the case during initial sync-up for resource upgrade.
Resource existingParent = null;
if (null != parent) {
- if (parent.getId() <= 0) {
+ int parentId = parent.getId();
+
+ if (parentId <= 0) {
log.warn("Expected potential parent resource to have a valid ID. Parent=" + parent + ", Child="
+ resource);
}
- try {
- query.setParameter("resourceId", parent.getId());
- existingParent = (Resource) query.getSingleResult();
+ // See if we already fetched this parent and it's in our cache map, if so, use it.
+ if (null != parentMap) {
+ existingParent = parentMap.get(parentId);
+ }
- } catch (NoResultException e) {
- // this parent is not known to the server, so there's no point in trying to find a child of it...
- continue;
+ if (null == existingParent) {
+ existingParent = entityManager.find(Resource.class, parentId);
+ if (null != existingParent) {
+ if (null != parentMap) {
+ parentMap.put(parentId, existingParent);
+ }
+ } else {
+ // this parent is not known to the server, so there's no point in trying to find a child of it...
+ continue;
+ }
}
}
@@ -945,7 +957,7 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
return existingResource;
}
- private void updateExistingResourceInNewTransaction(Resource updatedResource, Resource existingResource)
+ private void updateExistingResource(Resource updatedResource, Resource existingResource)
throws InvalidInventoryReportException {
/*
* there exists a small window of time after the synchronous part of the uninventory and before the async
@@ -1088,13 +1100,25 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
return true;
}
- private void persistResourceInNewTransaction(Resource resource) {
+ private void persistResource(Resource resource, Map<Integer, Resource> parentMap) {
- Resource parentResource = resource.getParentResource();
+ // Id of detached parent resource
+ Integer parentId = (null != resource.getParentResource()) ? resource.getParentResource().getId() : null;
- if (null != parentResource) {
- // Find the parent resource entity and create the parent-child relationship
- parentResource = findExistingResource(parentResource);
+ // attached parentResource
+ Resource parentResource = null;
+
+ if (null != parentId) {
+ // look in our map cache first
+ if (null != parentMap) {
+ parentResource = parentMap.get(parentId);
+ }
+ // if not in cache, try the DB
+ if (null == parentResource) {
+ // Find the parent resource entity
+ parentResource = entityManager.find(Resource.class, parentId);
+ }
+ // if the parent exists, create the parent-child relationship
if (null != parentResource) {
parentResource.addChildResource(resource);
}
commit 6c6b3984c01f54c98c2c19536410af8704063108
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Jan 29 17:16:41 2013 +0100
Improve representation of types.
diff --git a/modules/helpers/rest-docs-generator/src/main/java/org/rhq/helpers/rest_docs_generator/ClassLevelProcessor.java b/modules/helpers/rest-docs-generator/src/main/java/org/rhq/helpers/rest_docs_generator/ClassLevelProcessor.java
index cb1a56e..72be1ed 100644
--- a/modules/helpers/rest-docs-generator/src/main/java/org/rhq/helpers/rest_docs_generator/ClassLevelProcessor.java
+++ b/modules/helpers/rest-docs-generator/src/main/java/org/rhq/helpers/rest_docs_generator/ClassLevelProcessor.java
@@ -328,8 +328,11 @@ public class ClassLevelProcessor extends AbstractProcessor {
}
if (typeString.contains(modelPackage)) {
String mps = modelPackage.endsWith(".") ? modelPackage : modelPackage + ".";
+ // For a generic collection we need to find the "inner type" and link to it
+ int offset = typeString.contains("<") ? typeString.indexOf('<') +1 : 0;
+ String restType = typeString.substring(offset + modelPackage.length()+1);
typeString = typeString.replace(mps,"");
- typeId = "..." + typeString; // TODO in case of Collection<TypeString> only take the part from the modelPackage
+ typeId = "..." + restType;
}
element.setAttribute("type", typeString);
element.setAttribute("typeId", typeId);
@@ -380,7 +383,7 @@ public class ClassLevelProcessor extends AbstractProcessor {
Element elem = doc.createElement("data");
xmlRoot.appendChild(elem);
- elem.setAttribute("name",classElementIn.getSimpleName().toString());
+ elem.setAttribute("name", classElementIn.getSimpleName().toString());
elem.setAttribute("nameId","..." + classElementIn.getSimpleName().toString());
ApiClass api = classElementIn.getAnnotation(ApiClass.class);
if (api!=null) {
@@ -427,13 +430,15 @@ public class ClassLevelProcessor extends AbstractProcessor {
TypeMirror returnTypeMirror = m.getReturnType();
// for types in the modelPackage or java.lang, remove the fqdn
String typeName = returnTypeMirror.toString();
- if (typeName.startsWith(modelPackage)) {
- typeName = typeName.substring(modelPackage.length()+1);
+ if (typeName.contains(modelPackage)) {
+ typeName = typeName.replace(modelPackage+".","");
}
- else if (typeName.startsWith("java.lang")) {
- typeName = typeName.substring("java.lang".length()+1);
+ if (typeName.contains("java.lang.")) {
+ typeName = typeName.replaceAll("java\\.lang\\.", "");
+ }
+ if (typeName.contains("java.util.")) {
+ typeName = typeName.replaceAll("java\\.util\\.","");
}
- // TODO for collection<type> remove the collection expression and set some collection attribute
mElem.setAttribute("type", typeName);
}
}
commit 4fa01930008ddf35ff9956c7c8a0ad9fb9ef72d4
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Jan 29 11:19:31 2013 +0100
Improve documentation and get the processor to work again.
Generate links from parameters to domain classes, upgrade the docbook plugin.
diff --git a/modules/enterprise/server/jar/pom.xml b/modules/enterprise/server/jar/pom.xml
index 3b9f92d..7aef625 100644
--- a/modules/enterprise/server/jar/pom.xml
+++ b/modules/enterprise/server/jar/pom.xml
@@ -22,7 +22,7 @@
</properties>
<dependencies>
-
+
<!-- Internal Deps -->
<!-- rhq-enterprise-comm pulls in the old version of jboss remoting. The old version of remoting
@@ -35,7 +35,7 @@
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
- <version>3.1.0.GA</version>
+ <version>${jboss-logging.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -86,7 +86,7 @@
<artifactId>rhq-common-drift</artifactId>
<version>${project.version}</version>
</dependency>
-
+
<dependency>
<groupId>com.googlecode.java-diff-utils</groupId>
<artifactId>diffutils</artifactId>
@@ -115,7 +115,7 @@
<!-- Note, the test deps are intentionally placed above the other scoped deps because of classpath
reasons. Maven orders the [test] classpath in the order listed in the pom. -->
-
+
<dependency>
<groupId>org.jboss.spec</groupId>
@@ -124,7 +124,7 @@
<scope>provided</scope>
<type>pom</type>
</dependency>
-
+
<dependency>
<groupId>org.rhq</groupId>
<artifactId>test-utils</artifactId>
@@ -137,7 +137,7 @@
</exclusion>
</exclusions>
</dependency>
-
+
<dependency>
<groupId>org.rhq</groupId>
<artifactId>rhq-core-domain</artifactId>
@@ -145,15 +145,15 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
-
-
+
+
<!-- 3rd Party Deps -->
- <!-- do we really need this version, for now use the version provided by AS7, declare just below -->
+ <!-- do we really need this version, for now use the version provided by AS7, declare just below -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
- <version>3.2</version>
+ <version>3.2</version>
<exclusions>
<exclusion>
<groupId>antlr</groupId>
@@ -162,13 +162,13 @@
<exclusion>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
<groupId>antlr</groupId>
- <artifactId>antlr</artifactId>
+ <artifactId>antlr</artifactId>
<scope>provided</scope>
</dependency>
@@ -217,7 +217,7 @@
<groupId>gnu-getopt</groupId>
<artifactId>getopt</artifactId>
</dependency>
-
+
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
@@ -226,7 +226,7 @@
<dependency>
<groupId>jboss</groupId>
- <artifactId>jboss-cache</artifactId>
+ <artifactId>jboss-cache</artifactId>
<scope>compile</scope>
</dependency>
@@ -236,13 +236,13 @@
<scope>provided</scope>
</dependency>
- <!-- JBoss annotations like @TransactionTimeout -->
+ <!-- JBoss annotations like @TransactionTimeout -->
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-ext-api</artifactId>
<scope>provided</scope>
</dependency>
-
+
<!-- annotations like @ExcludeDefaultInterceptors -->
<dependency>
<groupId>org.jboss.spec.javax.interceptor</groupId>
@@ -268,7 +268,7 @@
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
-
+
<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_1.1_spec</artifactId>
@@ -402,7 +402,7 @@
<artifactId>snakeyaml</artifactId>
<version>1.8</version>
</dependency>
-
+
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
@@ -424,6 +424,13 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.rhq.helpers</groupId>
+ <artifactId>rest-docs-generator</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
<build>
@@ -836,26 +843,37 @@
<groupId>org.rhq.helpers</groupId>
<artifactId>rest-docs-generator</artifactId>
<version>${project.version}</version>
- <scope>provided</scope>
</dependency>
+
+ <!-- We need this, as otherwise processing fails completely with a class not found exception -->
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging</artifactId>
+ <version>${jboss-logging.version}</version>
+ </dependency>
+
</dependencies>
<build>
<!-- Document generation from the Annotations on the REST-API. -->
- <!-- TODO move to a better suited processing phase -->
<plugins>
-
<plugin>
- <groupId>org.bsc.maven</groupId>
- <artifactId>maven-processor-plugin</artifactId>
- <version>2.0.6-redhat</version>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.0</version>
<configuration>
- <processors>
+ <annotationProcessors>
<processor>org.rhq.helpers.rest_docs_generator.ClassLevelProcessor</processor>
- </processors>
- <compilerArguments>-AtargetDirectory=${project.build.directory}/docs/xml</compilerArguments>
- <!-- Comment the next line in to get more verbose output for debugging -->
- <!--<compilerArguments>-Averbose=true</compilerArguments> -->
+ </annotationProcessors>
+ <proc>only</proc>
+ <compilerArguments>
+ <AtargetDirectory>${project.build.directory}/docs/xml</AtargetDirectory>
+ <AmodelPkg>org.rhq.enterprise.server.rest.domain</AmodelPkg>
+ <!-- enable the next line to have the output of the processor shown on console -->
+ <!--<Averbose>true</Averbose>-->
+ </compilerArguments>
+ <!-- set the next to true to enable verbose output of the compiler plugin; default from the evn is true, but this is too noisy -->
+ <verbose>false</verbose>
</configuration>
<executions>
<execution>
@@ -863,20 +881,11 @@
<phase>process-classes</phase>
<goals>
<!-- We want to process the classes in src/ -->
- <goal>process</goal>
+ <goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
-
- <!-- Disable annotation processors during normal compilation -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <compilerArgument>-proc:none</compilerArgument>
- </configuration>
- </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
@@ -892,6 +901,7 @@
<configuration>
<transformationSets>
<transformationSet>
+ <!-- Generate a html rendering -->
<!-- org.rhq.helpers.rest_docs_generator.test plugin wrote to target/docs/xml (see -AtargetDirectory above) -->
<dir>target/docs/xml</dir>
<includes>
@@ -901,7 +911,7 @@
<parameters>
<parameter>
<name>basePath</name>
- <value>http://localhost:7080/rest/1</value>
+ <value>http://localhost:7080/rest</value>
</parameter>
</parameters>
<outputDir>${project.build.directory}/docs/html</outputDir>
@@ -912,6 +922,7 @@
</fileMappers>
</transformationSet>
<transformationSet>
+ <!-- Generate a docbook file as input to fop -->
<!-- org.rhq.helpers.rest_docs_generator.test plugin wrote to target/docs/xml (see -AtargetDirectory above) -->
<dir>target/docs/xml</dir>
<includes>
@@ -921,7 +932,7 @@
<parameters>
<parameter>
<name>basePath</name>
- <value>http://localhost:7080/rest/1</value>
+ <value>http://localhost:7080/rest</value>
</parameter>
</parameters>
<outputDir>${project.build.directory}/docs/xml</outputDir>
@@ -934,11 +945,11 @@
</transformationSets>
</configuration>
</plugin>
-
+
<plugin>
<groupId>com.agilejava.docbkx</groupId>
<artifactId>docbkx-maven-plugin</artifactId>
- <version>2.0.9</version>
+ <version>2.0.14</version>
<executions>
<execution>
<phase>process-classes</phase>
@@ -951,14 +962,14 @@
<configuration>
<sourceDirectory>target/docs/xml</sourceDirectory> <!-- from previous plugin, 2nd transformation set -->
<includes>rest-api-out.dbx.xml</includes>
- <hyphenate>false</hyphenate>
+ <hyphenate>true</hyphenate>
<generateToc>true</generateToc>
</configuration>
</plugin>
</plugins>
</build>
</profile>
-
+
<profile>
<id>cobertura</id>
<build>
@@ -1067,7 +1078,7 @@
</plugins>
</build>
</profile>
-
+
</profiles>
<reporting>
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertDefinitionHandlerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertDefinitionHandlerBean.java
index d0bb88e..97200cd 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertDefinitionHandlerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertDefinitionHandlerBean.java
@@ -126,6 +126,7 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
+ // Redirect from /definition to /definitions for GET requests
@GET
@Path("/definition")
public Response redirectDefinitionToDefinitions(@Context UriInfo uriInfo) {
@@ -178,11 +179,11 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@POST
@Path("/definitions")
- @ApiOperation("Create an AlertDefinition for the resource/group/resource type passed as query param. Only one of the three params may be given at any time.")
- public Response createAlertDefinition(@QueryParam("resourceId") Integer resourceId,
- @QueryParam("groupId") Integer groupId,
- @QueryParam("resourceTypeId") Integer resourceTypeId,
- AlertDefinitionRest adr,
+ @ApiOperation("Create an AlertDefinition for the resource/group/resource type passed as query param. One and only one of the three params must be given at any time.")
+ public Response createAlertDefinition(@ApiParam("The id of the resource to attach the definition to") @QueryParam("resourceId") Integer resourceId,
+ @ApiParam("The id of the group to attach the definition to") @QueryParam("groupId") Integer groupId,
+ @ApiParam("The id of the resource type to attach the definition to") @QueryParam("resourceTypeId") Integer resourceTypeId,
+ @ApiParam("The data for the new definition") AlertDefinitionRest adr,
@Context UriInfo uriInfo) {
int i = 0;
@@ -266,7 +267,7 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@ApiOperation(value = "Update the alert definition (priority, enablement, dampening, recovery)", notes = "Priority must be HIGH,LOW,MEDIUM")
public Response updateDefinition(
@ApiParam("Id of the alert definition to update") @PathParam("id") int definitionId,
- AlertDefinitionRest definitionRest) {
+ @ApiParam("Data for the update") AlertDefinitionRest definitionRest) {
AlertDefinition definition = alertDefinitionManager.getAlertDefinition(caller,definitionId);
if (definition==null)
@@ -303,14 +304,18 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@DELETE
@Path("definition/{id}")
@ApiOperation("Delete an alert definition")
- public Response deleteDefinition(@PathParam("id") int definitionId) {
+ public Response deleteDefinition(@ApiParam("Id of the definition to delete") @PathParam("id") int definitionId) {
- int count = alertDefinitionManager.removeAlertDefinitions(caller, new int[]{definitionId});
+ alertDefinitionManager.removeAlertDefinitions(caller, new int[]{definitionId});
return Response.noContent().build();
}
-
+ /**
+ * Create a dampening object for the passed definition from the alert definition rest that is passed in.
+ * @param alertDefinition The alert definition to modify
+ * @param adr The incoming AlertDefinitonRest object
+ */
private void setDampeningFromRest(AlertDefinition alertDefinition, AlertDefinitionRest adr) {
AlertDampening.Category dampeningCategory;
try {
@@ -373,7 +378,10 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@POST
@Path("definition/{id}/conditions")
- public Response addConditionToDefinition(@PathParam("id") int definitionId, AlertConditionRest conditionRest, @Context UriInfo uriInfo) {
+ @ApiOperation("Add a new alert condition to an existing alert definition")
+ public Response addConditionToDefinition(
+ @ApiParam("The id of the alert definition") @PathParam("id") int definitionId,
+ @ApiParam("The condition to add") AlertConditionRest conditionRest, @Context UriInfo uriInfo) {
AlertDefinition definition = alertDefinitionManager.getAlertDefinition(caller,definitionId);
if (definition==null)
@@ -392,7 +400,9 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@DELETE
@Path("condition/{cid}")
- public Response deleteCondition(@PathParam("cid") int conditionId) {
+ @ApiOperation("Remove an alert condition")
+ public Response deleteCondition(
+ @ApiParam("The id of the condition to remove")@PathParam("cid") int conditionId) {
Integer definitionId = findDefinitionIdForConditionId(conditionId);
AlertDefinition definition2 = entityManager.find(AlertDefinition.class,definitionId);
@@ -427,7 +437,10 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@PUT
@Path("condition/{cid}")
- public Response updateCondition(@PathParam("cid") int conditionId, AlertConditionRest conditionRest, @Context UriInfo uriInfo) {
+ @ApiOperation("Update an existing condition of an alert definition.Note that the update will change the id of the condition")
+ public Response updateCondition(
+ @ApiParam("The id of the condition to update") @PathParam("cid") int conditionId,
+ @ApiParam("The updated condition") AlertConditionRest conditionRest, @Context UriInfo uriInfo) {
Integer definitionId = findDefinitionIdForConditionId(conditionId);
@@ -465,7 +478,9 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@GET
@Path("condition/{cid}")
- public Response getCondition(@PathParam("cid") int conditionId) {
+ @ApiOperation("Retrieve a condition of an alert definition by its condition id")
+ public Response getCondition(
+ @ApiParam("The id of the condition to retrieve") @PathParam("cid") int conditionId) {
AlertCondition condition = conditionMgr.getAlertConditionById(conditionId);
AlertConditionRest acr = conditionToConditionRest(condition);
@@ -521,7 +536,9 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@GET
@Path("notification/{nid}")
- public Response getNotification(@PathParam("nid") int notificationId) {
+ @ApiOperation("Return a notification definition by its id")
+ public Response getNotification(
+ @ApiParam("The id of the notification definition to retrieve") @PathParam("nid") int notificationId) {
AlertNotification notification = notificationMgr.getAlertNotification(caller,notificationId);
AlertNotificationRest anr = notificationToNotificationRest(notification);
@@ -531,7 +548,9 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@DELETE
@Path("notification/{nid}")
- public Response deleteNotification(@PathParam("nid") int notificationId) {
+ @ApiOperation("Remove a notification definition")
+ public Response deleteNotification(
+ @ApiParam("The id of the notification definition to remove") @PathParam("nid") int notificationId) {
AlertNotification notification = notificationMgr.getAlertNotification(caller,notificationId);
AlertDefinition definition = alertDefinitionManager.getAlertDefinition(caller,notification.getAlertDefinition().getId());
@@ -548,7 +567,10 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@PUT
@Path("notification/{nid}")
- public Response updateNotification(@PathParam("nid") int notificationId, AlertNotificationRest notificationRest) {
+ @ApiOperation("Update a notification definition")
+ public Response updateNotification(
+ @ApiParam("The id of the notification definition to update") @PathParam("nid") int notificationId,
+ @ApiParam("The updated notification definition to use") AlertNotificationRest notificationRest) {
AlertNotification notification = notificationMgr.getAlertNotification(caller,notificationId);
AlertDefinition definition = alertDefinitionManager.getAlertDefinition(caller,notification.getAlertDefinition().getId());
@@ -578,7 +600,10 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@POST
@Path("definition/{id}/notifications")
- public Response addNotificationToDefinition(@PathParam("id") int definitionId, AlertNotificationRest notificationRest, @Context UriInfo uriInfo) {
+ @ApiOperation("Add a new notification definition to an alert definition")
+ public Response addNotificationToDefinition(
+ @ApiParam("Id of the alert definition that should get the notification definition") @PathParam("id") int definitionId,
+ @ApiParam("The notification definition to add") AlertNotificationRest notificationRest, @Context UriInfo uriInfo) {
AlertNotification notification = new AlertNotification(notificationRest.getSenderName());
@@ -670,7 +695,8 @@ public class AlertDefinitionHandlerBean extends AbstractRestBean {
@ApiOperation("Return an alert notification sender by name. This includes information about the configuration it expects")
@GET @GZIP
@Path("sender/{name}")
- public Response getAlertSenderByName(@PathParam("name")String senderName, @Context UriInfo uriInfo) {
+ public Response getAlertSenderByName(
+ @ApiParam("Name of the sender to retrieve") @PathParam("name")String senderName, @Context UriInfo uriInfo) {
AlertSenderInfo info = notificationMgr.getAlertInfoForSender(senderName);
if (info==null) {
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/RootHandlerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/RootHandlerBean.java
index 7998294..e2abffd 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/RootHandlerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/RootHandlerBean.java
@@ -35,6 +35,9 @@ import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
+
import org.rhq.enterprise.server.rest.domain.Link;
/**
@@ -42,6 +45,7 @@ import org.rhq.enterprise.server.rest.domain.Link;
*
* @author Heiko W. Rupp
*/
+@Api("Handle the root context to have an anchor for discoverability")
@Path("/")
@Interceptors(SetCallerInterceptor.class)
@Stateless
@@ -60,12 +64,14 @@ public class RootHandlerBean extends AbstractRestBean {
@GET
@Path("index")
+ @ApiOperation("Return links from the root /index of the REST-resource tree")
public Response index(@Context Request request, @Context HttpHeaders headers, @Context UriInfo uriInfo) {
return handleIndex(headers,uriInfo);
}
@GET
@Path("/")
+ @ApiOperation("Return links from the root / of the REST-resource tree")
public Response index2(@Context Request request, @Context HttpHeaders headers, @Context UriInfo uriInfo) {
return handleIndex(headers,uriInfo);
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertConditionRest.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertConditionRest.java
index 890a3fe..1ada16c 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertConditionRest.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertConditionRest.java
@@ -21,6 +21,9 @@ package org.rhq.enterprise.server.rest.domain;
import javax.xml.bind.annotation.XmlRootElement;
+import com.wordnik.swagger.annotations.ApiClass;
+import com.wordnik.swagger.annotations.ApiProperty;
+
import org.rhq.core.domain.alert.AlertConditionCategory;
import org.rhq.core.domain.alert.AlertConditionOperator;
@@ -29,6 +32,7 @@ import org.rhq.core.domain.alert.AlertConditionOperator;
* An alert definition can have any number of definitions
* @author Heiko W. Rupp
*/
+@ApiClass(value = "One condition for an alert definition")
@XmlRootElement(name = "condition")
public class AlertConditionRest {
@@ -44,6 +48,7 @@ public class AlertConditionRest {
public AlertConditionRest() {
}
+ @ApiProperty("Comparator to use with this definition")
public AlertConditionOperator getName() {
return name;
}
@@ -52,6 +57,7 @@ public class AlertConditionRest {
this.name = name;
}
+ @ApiProperty("The category")
public AlertConditionCategory getCategory() {
return category;
}
@@ -64,10 +70,12 @@ public class AlertConditionRest {
this.id = id;
}
+ @ApiProperty("Id of the condition.Note that this is not stable - when you update the condition, its id will change")
public int getId() {
return id;
}
+ @ApiProperty("THe threshold to compare against")
public Double getThreshold() {
return threshold;
}
@@ -76,6 +84,7 @@ public class AlertConditionRest {
this.threshold = threshold;
}
+ @ApiProperty("Options to this condition. Depends on the category used")
public String getOption() {
return option;
}
@@ -100,6 +109,7 @@ public class AlertConditionRest {
this.comparator = comparator;
}
+ @ApiProperty("The id of the measurement definition, this comparator should apply to. A metric schedule can be identified by a resource id and a definition id.")
public int getMeasurementDefinition() {
return measurementDefinition;
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertDefinitionRest.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertDefinitionRest.java
index 0e6b351..cecd946 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertDefinitionRest.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertDefinitionRest.java
@@ -26,8 +26,6 @@ import javax.xml.bind.annotation.XmlRootElement;
import com.wordnik.swagger.annotations.ApiClass;
import com.wordnik.swagger.annotations.ApiProperty;
-import org.rhq.core.domain.alert.AlertDampening;
-
/**
* Alert Definition
* @author Heiko W. Rupp
@@ -48,6 +46,7 @@ public class AlertDefinitionRest {
String dampeningCount;
String dampeningPeriod;
+ @SuppressWarnings("unused")
public AlertDefinitionRest() {
}
@@ -92,6 +91,7 @@ public class AlertDefinitionRest {
this.priority = priority;
}
+ @ApiProperty(value = "Id of an alert definition to recover")
public int getRecoveryId() {
return recoveryId;
}
@@ -128,6 +128,7 @@ public class AlertDefinitionRest {
this.notifications = notifications;
}
+ @ApiProperty(value = "Category for dampening. ONCE means 'disable definition after firing'", allowableValues = "NONE, CONSECUTIVE_COUNT, PARTIAL_COUNT, INVERSE_COUNT, DURATION_COUNT, NO_DUPLICATES, ONCE")
public String getDampeningCategory() {
return dampeningCategory;
}
@@ -136,6 +137,7 @@ public class AlertDefinitionRest {
this.dampeningCategory = dampeningCategory;
}
+ @ApiProperty(value = "Number of occurrences of an alert (in a given period)")
public String getDampeningCount() {
return dampeningCount;
}
@@ -144,6 +146,7 @@ public class AlertDefinitionRest {
this.dampeningCount = dampeningCount;
}
+ @ApiProperty( value = "Period to check events. Only applicable for PARTIAL_COUNT, DURATION_COUNT, INVERSE_COUNT")
public String getDampeningPeriod() {
return dampeningPeriod;
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertNotificationRest.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertNotificationRest.java
index 1b6a46b..c4cd0c5 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertNotificationRest.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/AlertNotificationRest.java
@@ -31,7 +31,7 @@ import com.wordnik.swagger.annotations.ApiProperty;
* Representation of notifications
* @author Heiko W. Rupp
*/
-@ApiClass("Represents an alert notification")
+@ApiClass("Represents an alert notification definition")
@XmlRootElement(name = "notification")
public class AlertNotificationRest {
@@ -42,6 +42,7 @@ public class AlertNotificationRest {
public AlertNotificationRest() {
}
+ @ApiProperty("Id of the definition. This will change if the notification is updated.")
public int getId() {
return id;
}
@@ -59,6 +60,7 @@ public class AlertNotificationRest {
this.senderName = senderName;
}
+ @ApiProperty("Configuration that needs to be passed to the definition.")
public Map<String, Object> getConfig() {
return config;
}
diff --git a/modules/enterprise/server/jar/src/main/xsl/apiout2docbook.xsl b/modules/enterprise/server/jar/src/main/xsl/apiout2docbook.xsl
index 97e0598..512a8d4 100644
--- a/modules/enterprise/server/jar/src/main/xsl/apiout2docbook.xsl
+++ b/modules/enterprise/server/jar/src/main/xsl/apiout2docbook.xsl
@@ -40,7 +40,7 @@
<xsl:element name="tocentry">
<link>
<xsl:attribute name="linkend">
- <xsl:value-of select="@path"/>
+ <xsl:value-of select="generate-id(@path)"/>
</xsl:attribute>
<xsl:if test="@basePath">
<xsl:value-of select="@basePath"/>
@@ -63,7 +63,7 @@
<xsl:template match="class">
<xsl:element name="section">
<xsl:attribute name="xml:id">
- <xsl:value-of select="@path"/>
+ <xsl:value-of select="generate-id(@path)"/>
</xsl:attribute>
<title>
<!--/<xsl:value-of select="@path"/>-->
@@ -167,7 +167,20 @@
<xsl:value-of select="@required"/>
</td>
<td>
- <xsl:value-of select="@type"/>
+ <xsl:choose>
+
+ <xsl:when test="starts-with(@typeId,'...')">
+ <link>
+ <xsl:attribute name="linkend">
+ <xsl:value-of select="@typeId"/>
+ </xsl:attribute>
+ <xsl:value-of select="@type"/>
+ </link>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="@type"/>
+ </xsl:otherwise>
+ </xsl:choose>
</td>
<td>
<xsl:choose>
@@ -233,6 +246,9 @@
<xsl:template match="data">
<xsl:element name="section">
+ <xsl:attribute name="xml:id">
+ <xsl:value-of select="@nameId"/>
+ </xsl:attribute>
<title>Data-Class: <xsl:value-of select="@name"/></title>
<xsl:if test="@abstract">
<subtitle><xsl:value-of select="@abstract"/></subtitle>
diff --git a/modules/helpers/rest-docs-generator/pom.xml b/modules/helpers/rest-docs-generator/pom.xml
index af3374f..f97d2de 100644
--- a/modules/helpers/rest-docs-generator/pom.xml
+++ b/modules/helpers/rest-docs-generator/pom.xml
@@ -48,15 +48,6 @@
</testResources>
<plugins>
-<!--
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>animal-sniffer-maven-plugin</artifactId>
- <configuration>
- <skip>true</skip>
- </configuration>
- </plugin>
--->
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
diff --git a/modules/helpers/rest-docs-generator/src/main/java/org/rhq/helpers/rest_docs_generator/ClassLevelProcessor.java b/modules/helpers/rest-docs-generator/src/main/java/org/rhq/helpers/rest_docs_generator/ClassLevelProcessor.java
index c10dd62..cb1a56e 100644
--- a/modules/helpers/rest-docs-generator/src/main/java/org/rhq/helpers/rest_docs_generator/ClassLevelProcessor.java
+++ b/modules/helpers/rest-docs-generator/src/main/java/org/rhq/helpers/rest_docs_generator/ClassLevelProcessor.java
@@ -58,7 +58,7 @@ import org.jboss.resteasy.annotations.GZIP;
*/
@SupportedOptions({ClassLevelProcessor.TARGET_DIRECTORY,ClassLevelProcessor.VERBOSE,ClassLevelProcessor.MODEL_PACKAGE_KEY})
-(a)SupportedSourceVersion(SourceVersion.RELEASE_6)
+(a)SupportedSourceVersion(SourceVersion.RELEASE_7)
@SupportedAnnotationTypes(value = {"com.wordnik.swagger.annotations.*","javax.ws.rs.*","javax.xml.bind.annotation.XmlRootElement"})
public class ClassLevelProcessor extends AbstractProcessor {
@@ -318,8 +318,21 @@ public class ClassLevelProcessor extends AbstractProcessor {
if (defaultValue!=null)
element.setAttribute("defaultValue",defaultValue);
-
- element.setAttribute("type", t.toString());
+ String typeString = t.toString();
+ String typeId = typeString;
+ if (typeString.contains("java.lang.")) {
+ typeString = typeString.replaceAll("java\\.lang\\.","");
+ }
+ else if (typeString.contains("java.util.")) {
+ typeString = typeString.replaceAll("java\\.util\\.","");
+ }
+ if (typeString.contains(modelPackage)) {
+ String mps = modelPackage.endsWith(".") ? modelPackage : modelPackage + ".";
+ typeString = typeString.replace(mps,"");
+ typeId = "..." + typeString; // TODO in case of Collection<TypeString> only take the part from the modelPackage
+ }
+ element.setAttribute("type", typeString);
+ element.setAttribute("typeId", typeId);
}
}
@@ -368,6 +381,7 @@ public class ClassLevelProcessor extends AbstractProcessor {
Element elem = doc.createElement("data");
xmlRoot.appendChild(elem);
elem.setAttribute("name",classElementIn.getSimpleName().toString());
+ elem.setAttribute("nameId","..." + classElementIn.getSimpleName().toString());
ApiClass api = classElementIn.getAnnotation(ApiClass.class);
if (api!=null) {
elem.setAttribute("abstract",api.value());
11 years, 3 months
[rhq] 2 commits - modules/enterprise modules/integration-tests
by Heiko W. Rupp
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/PluginFileUploadServlet.java | 15 -
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/ResourceHandlerBean.java | 81 +++++--
modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java | 110 +++++++++-
modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/d/Resource.java | 76 ++++++
4 files changed, 248 insertions(+), 34 deletions(-)
New commits:
commit 977ff337c997c2f5d63d19d46ada868eed4d9624
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Jan 29 21:30:06 2013 +0100
Use a real UUID for resource creation. Deprecate the endpoints for platform and resource creation.
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/ResourceHandlerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/ResourceHandlerBean.java
index be28d92..8142f17 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/ResourceHandlerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/ResourceHandlerBean.java
@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
+import java.util.UUID;
import javax.ejb.EJB;
import javax.ejb.Stateless;
@@ -529,15 +530,39 @@ public class ResourceHandlerBean extends AbstractRestBean {
@ApiOperation(value = "Create a new platform in the Server. If the platform already exists, this is a no-op." +
"The platform internally has a special name so that it will not clash with one that was generated" +
- "via a normal RHQ agent")
+ "via a normal RHQ agent. DEPRECATED Use POST /platforms instead")
@POST
@Path("platform/{name}")
- public Response createPlatform(
+ public Response createPlatformOLD(
@ApiParam(value = "Name of the platform") @PathParam("name") String name,
@ApiParam(value = "Type of the platform", allowableValues = "Linux,Windows,... TODO") StringValue typeValue,
@Context UriInfo uriInfo) {
+
String typeName = typeValue.getValue();
+ return createPlatformInternal(name, typeName, uriInfo);
+
+ }
+
+ @POST
+ @Path("platforms")
+ @ApiOperation(value = "Create a new platform in the Server. If the platform already exists, this is a no-op." +
+ "The platform internally has a special name so that it will not clash with one that was generated" +
+ "via a normal RHQ agent. Only resourceName and typeName need to be supplied in the passed object")
+ public Response createPlatform(
+ @ApiParam("The info about the platform. Only type name and resource name need to be supplied") ResourceWithType resource,
+ @Context UriInfo uriInfo)
+ {
+
+ String typeName = resource.getTypeName();
+ String resourceName = resource.getResourceName();
+
+ return createPlatformInternal(resourceName,typeName,uriInfo);
+ }
+
+
+ private Response createPlatformInternal(String name, String typeName, UriInfo uriInfo) {
+
ResourceType type = resourceTypeManager.getResourceTypeByNameAndPlugin(typeName,"Platforms");
if (type==null) {
throw new StuffNotFoundException("Platform with type [" + typeName + "]");
@@ -565,10 +590,8 @@ public class ResourceHandlerBean extends AbstractRestBean {
agent = new Agent("dummy-agent:name"+name,"-dummy-p:"+name,12345,"http://foo.com/p:name/"+name,"abc-"+name);
agentMgr.createAgent(agent);
-
-
Resource platform = new Resource(resourceKey,name,type);
- platform.setUuid(resourceKey);
+ platform.setUuid(UUID.randomUUID().toString());
platform.setAgent(agent);
platform.setInventoryStatus(InventoryStatus.COMMITTED);
platform.setModifiedBy(caller.getName());
@@ -595,40 +618,44 @@ public class ResourceHandlerBean extends AbstractRestBean {
} catch (Exception e) {
throw new RuntimeException(e);
}
-
}
- private void createSchedules(Resource resource) {
- ResourceType rt = resource.getResourceType();
- Set<MeasurementDefinition> definitions = rt.getMetricDefinitions ();
- for (MeasurementDefinition definition : definitions) {
- MeasurementSchedule schedule = new MeasurementSchedule(definition,resource);
- schedule.setEnabled(definition.isDefaultOn());
- schedule.setInterval(definition.getDefaultInterval());
- entityManager.persist(schedule);
- }
- }
- @ApiOperation(value = "Create a resource with a given type below a certain parent")
+ @ApiOperation(value = "Create a resource with a given type below a certain parent. DEPRECATED Use POST / instead")
@POST
@Path("{name}")
- public Response createResource(
+ public Response createResourceOLD(
@ApiParam("Name of the new resource") @PathParam("name") String name,
@ApiParam("Name of the Resource type") StringValue typeValue,
@ApiParam("Name of the plugin providing the type") @QueryParam("plugin") String plugin,
@ApiParam("Id of the future parent to attach this to") @QueryParam("parentId") int parentId,
@Context UriInfo uriInfo) {
+ String typeName = typeValue.getValue();
+
+ return createResourceInternal(name, plugin, parentId, typeName, uriInfo);
+ }
+
+ @POST
+ @Path("/")
+ @ApiOperation("Create a new resource as a child of an existing resource¡")
+ public Response createResource(
+ @ApiParam("THe info about the resource. You need to supply resource name, resource type name, plugin name, id of the parent") ResourceWithType resource,
+ @Context UriInfo uriInfo)
+ {
+ return createResourceInternal(resource.getResourceName(),resource.getPluginName(),resource.getParentId(),resource.getTypeName(),uriInfo);
+ }
+
+ private Response createResourceInternal(String name, String plugin, int parentId, String typeName,
+ UriInfo uriInfo) {
Resource parent = resMgr.getResourceById(caller,parentId);
- String typeName = typeValue.getValue();
ResourceType resType = resourceTypeManager.getResourceTypeByNameAndPlugin(typeName,plugin);
if (resType==null)
throw new StuffNotFoundException("ResourceType with name [" + typeName + "] and plugin [" + plugin + "]");
String resourceKey = "res:" + name + ":" + parentId;
-
Resource r = resMgr.getResourceByParentAndKey(caller,parent,resourceKey,plugin,typeName);
if (r!=null) {
// resource exists - return it
@@ -644,7 +671,7 @@ public class ResourceHandlerBean extends AbstractRestBean {
}
Resource res = new Resource(resourceKey,name,resType);
- res.setUuid(resourceKey);
+ res.setUuid(UUID.randomUUID().toString());
res.setAgent(parent.getAgent());
res.setParentResource(parent);
res.setInventoryStatus(InventoryStatus.COMMITTED);
@@ -683,4 +710,16 @@ public class ResourceHandlerBean extends AbstractRestBean {
return Response.status(Response.Status.NO_CONTENT).build();
}
+
+ private void createSchedules(Resource resource) {
+ ResourceType rt = resource.getResourceType();
+ Set<MeasurementDefinition> definitions = rt.getMetricDefinitions ();
+ for (MeasurementDefinition definition : definitions) {
+ MeasurementSchedule schedule = new MeasurementSchedule(definition,resource);
+ schedule.setEnabled(definition.isDefaultOn());
+ schedule.setInterval(definition.getDefaultInterval());
+ entityManager.persist(schedule);
+ }
+ }
+
}
diff --git a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
index e8066bc..6899995 100644
--- a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
+++ b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
@@ -25,12 +25,16 @@ package org.rhq.modules.integrationTests.restApi;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.path.json.JsonPath;
+import com.jayway.restassured.path.xml.XmlPath;
+import com.jayway.restassured.path.xml.element.Node;
import com.jayway.restassured.response.Response;
import org.apache.http.HttpStatus;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
+import org.rhq.modules.integrationTests.restApi.d.Resource;
+
import static com.jayway.restassured.RestAssured.expect;
import static com.jayway.restassured.RestAssured.get;
import static com.jayway.restassured.RestAssured.given;
@@ -129,7 +133,7 @@ public class ResourcesTest extends AbstractBase {
@Test
public void testGetPlatformXml() {
given()
- .header("Accept","application/xml")
+ .header("Accept", "application/xml")
.expect()
.statusCode(200)
.contentType(ContentType.XML)
@@ -140,7 +144,7 @@ public class ResourcesTest extends AbstractBase {
@Test
public void testGetPlatformSchedules() {
given()
- .header("Accept","application/json")
+ .header("Accept", "application/json")
.expect()
.statusCode(200)
.when()
@@ -158,18 +162,66 @@ public class ResourcesTest extends AbstractBase {
}
@Test
- public void testCreatePlatform() throws Exception {
+ public void testCreatePlatformOld() throws Exception {
given().body("{\"value\":\"Linux\"}")
- .header("Content-Type","application/json")
- .header("Accept","application/json")
+ .header("Content-Type", "application/json")
+ .header("Accept", "application/json")
.expect().statusCode(201)
.when().post("/resource/platform/api-test-dummy");
}
@Test
+ public void testCreatePlatform() throws Exception {
+
+ Resource resource = new Resource();
+ resource.setResourceName("dummy-test");
+ resource.setTypeName("Linux");
+
+ given()
+ .header(acceptXml)
+ .contentType(ContentType.JSON)
+ .body(resource)
+ .expect()
+ .statusCode(201)
+ .log().ifError()
+ .when()
+ .post("/resource/platforms");
+
+ }
+
+ @Test
public void testCreatePlatformAndRemove() throws Exception {
+ Resource resource = new Resource();
+ resource.setResourceName("dummy-test");
+ resource.setTypeName("Linux");
+
+ Response response =
+ given()
+ .header(acceptXml)
+ .contentType(ContentType.JSON)
+ .body(resource)
+ .expect()
+ .statusCode(201)
+ .log().ifError()
+ .when()
+ .post("/resource/platforms");
+
+ XmlPath xmlPath = response.xmlPath();
+ Node resource1 = xmlPath.get("resource");
+ Node platformIdNode = resource1.get("resourceId");
+ String platformId = platformIdNode.value();
+
+ given().pathParam("id", platformId)
+ .expect().statusCode(HttpStatus.SC_NO_CONTENT)
+ .when().delete("/resource/{id}");
+
+ }
+
+ @Test
+ public void testCreatePlatformOLDAndRemove() throws Exception {
+
Response response =
with().body("{\"value\":\"Linux\"}")
.header("Content-Type","application/json")
@@ -185,12 +237,12 @@ public class ResourcesTest extends AbstractBase {
}
@Test
- public void testCreatePlatformWithChildAndRemove() throws Exception {
+ public void testCreatePlatformOLDWithChildOLDAndRemove() throws Exception {
Response response =
with().body("{\"value\":\"Linux\"}")
.header("Content-Type","application/json")
- .header("Accept","application/json")
+ .header("Accept", "application/json")
.expect()
.statusCode(201)
.when()
@@ -219,6 +271,50 @@ public class ResourcesTest extends AbstractBase {
}
@Test
+ public void testCreatePlatformWithChildAndRemove() throws Exception {
+
+ Resource platform = new Resource();
+ platform.setResourceName("dummy-test");
+ platform.setTypeName("Linux");
+
+ Response response =
+ with().body(platform)
+ .header("Content-Type","application/json")
+ .header("Accept","application/json")
+ .expect()
+ .statusCode(201)
+ .log().ifError()
+ .when()
+ .post("/resource/platforms");
+
+ String platformId = response.jsonPath().getString("resourceId");
+
+ Resource child = new Resource();
+ child.setResourceName("test");
+ child.setTypeName("CPU");
+ child.setPluginName("Platforms");
+ child.setParentId(Integer.valueOf(platformId));
+
+ try {
+
+ with()
+ .body(child)
+ .header("Content-Type", "application/json")
+ .header("Accept", "application/json")
+ .expect()
+ .statusCode(201)
+ .log().ifError()
+ .when()
+ .post("/resource");
+ }
+ finally {
+ given().pathParam("id",platformId)
+ .expect().statusCode(HttpStatus.SC_NO_CONTENT)
+ .when().delete("/resource/{id}");
+ }
+ }
+
+ @Test
public void testDoubleChildCreate() throws Exception {
// a resource can be created again and again
diff --git a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/d/Resource.java b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/d/Resource.java
new file mode 100644
index 0000000..9c3c1a3
--- /dev/null
+++ b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/d/Resource.java
@@ -0,0 +1,76 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU 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.modules.integrationTests.restApi.d;
+
+/**
+ * A resource for testing purposes
+ * @author Heiko W. Rupp
+ */
+public class Resource {
+
+ String resourceName;
+ int resourceId;
+ String typeName;
+ String pluginName;
+ Integer parentId;
+
+ public Resource() {
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public void setResourceName(String resourceName) {
+ this.resourceName = resourceName;
+ }
+
+ public Integer getParentId() {
+ return parentId;
+ }
+
+ public void setParentId(Integer parentId) {
+ this.parentId = parentId;
+ }
+
+ public String getPluginName() {
+ return pluginName;
+ }
+
+ public void setPluginName(String pluginName) {
+ this.pluginName = pluginName;
+ }
+
+ public int getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(int resourceId) {
+ this.resourceId = resourceId;
+ }
+
+ public String getTypeName() {
+ return typeName;
+ }
+
+ public void setTypeName(String typeName) {
+ this.typeName = typeName;
+ }
+}
commit 75903fd6abdef24ac5bab17f35f3b83ba2b1033c
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Tue Jan 29 20:06:17 2013 +0100
Do not assume everything is a jar - we also support jar-less plugins.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/PluginFileUploadServlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/PluginFileUploadServlet.java
index adc870a..3263d19 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/PluginFileUploadServlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/PluginFileUploadServlet.java
@@ -66,13 +66,16 @@ public class PluginFileUploadServlet extends FileUploadServlet {
File file = files.values().iterator().next();
String newPluginFilename = fileNames.values().iterator().next();
- // make sure its a .jar file and strip off any temp file suffix (in case the browser set the name to something odd)
- int jarExtension = newPluginFilename.lastIndexOf(".jar");
- if (jarExtension < 0) {
- newPluginFilename = newPluginFilename + ".jar"; // make sure it ends with ".jar" in case it is some tmp filename
- jarExtension = newPluginFilename.lastIndexOf(".jar");
+ // see if it is a jar-less plugin descriptor and if not check for .jar
+ if (!newPluginFilename.endsWith("-rhq-plugin.xml")) {
+ // make sure its a .jar file and strip off any temp file suffix (in case the browser set the name to something odd)
+ int jarExtension = newPluginFilename.lastIndexOf(".jar");
+ if (jarExtension < 0) {
+ newPluginFilename = newPluginFilename + ".jar"; // make sure it ends with ".jar" in case it is some tmp filename
+ jarExtension = newPluginFilename.lastIndexOf(".jar");
+ }
+ newPluginFilename = newPluginFilename.substring(0, jarExtension + ".jar".length());
}
- newPluginFilename = newPluginFilename.substring(0, jarExtension + ".jar".length());
log.info("A new plugin [" + newPluginFilename + "] has been uploaded to [" + file + "]");
if (file == null || !file.exists()) {
11 years, 3 months
[rhq] Branch 'feature/cassandra-backend' - modules/plugins
by John Sanda
modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/JMXPluginTest.java | 21 +++++++---
1 file changed, 15 insertions(+), 6 deletions(-)
New commits:
commit 8506ca82f7f61050114090c8e9dc770f3c0f0b46
Author: John Sanda <jsanda(a)redhat.com>
Date: Tue Jan 29 15:05:17 2013 -0500
disable test until sigar issue is resolved
diff --git a/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/JMXPluginTest.java b/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/JMXPluginTest.java
index ee172ba..0434381 100644
--- a/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/JMXPluginTest.java
+++ b/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/JMXPluginTest.java
@@ -39,22 +39,20 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.resource.ResourceCategory;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.plugins.jmx.JMXDiscoveryComponent;
-import org.rhq.plugins.jmx.util.JvmResourceKey;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.rhq.core.clientapi.server.discovery.InventoryReport;
+import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.DataType;
import org.rhq.core.domain.measurement.MeasurementData;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.domain.resource.ResourceCategory;
+import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.inventory.InventoryManager;
@@ -65,6 +63,8 @@ import org.rhq.core.pc.util.InventoryPrinter;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
import org.rhq.core.pluginapi.operation.OperationFacet;
+import org.rhq.plugins.jmx.JMXDiscoveryComponent;
+import org.rhq.plugins.jmx.util.JvmResourceKey;
/**
* Integration test for the JMX plugin.
@@ -208,7 +208,16 @@ public class JMXPluginTest {
assert foundExplicitKey2Server : "JMX Remoting + explicit key server not found.";
}
- @Test(dependsOnMethods = "testServerDiscovery")
+ /**
+ * This test is currently disabled because we hit a NPE in
+ * JvmUtility.attachToVirtualMachine on line 107 where,
+ *
+ * process.getCredentialsName().getUser();
+ *
+ * is called. Looks like the NPE is coming from the call to getUser() at the end and
+ * it might be due to this Sigar bug, https://jira.hyperic.com/browse/SIGAR-231.
+ */
+ @Test(dependsOnMethods = "testServerDiscovery", enabled = false)
public void testServiceDiscovery() throws Exception {
InventoryReport report = PluginContainer.getInstance().getInventoryManager().executeServiceScanImmediately();
assert report != null;
11 years, 3 months
[rhq] Branch 'feature/cassandra-backend' - 2 commits - modules/plugins
by John Sanda
modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/util/JvmUtility.java | 3 --
modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/JMXPluginTest.java | 13 ++++------
2 files changed, 7 insertions(+), 9 deletions(-)
New commits:
commit 1242a7e054bf58f77abae4bae19936cade2775b0
Author: John Sanda <jsanda(a)redhat.com>
Date: Tue Jan 29 14:59:27 2013 -0500
Revert "make sure test uses same jvm as maven and the rest of the build"
This reverts commit 043b1fd0123de94c6abab841b4beebd772e5fcca.
diff --git a/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/JMXPluginTest.java b/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/JMXPluginTest.java
index 53825d2..ee172ba 100644
--- a/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/JMXPluginTest.java
+++ b/modules/plugins/jmx/src/test/java/org/rhq/plugins/jmx/test/JMXPluginTest.java
@@ -39,20 +39,22 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.resource.ResourceCategory;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.plugins.jmx.JMXDiscoveryComponent;
+import org.rhq.plugins.jmx.util.JvmResourceKey;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.rhq.core.clientapi.server.discovery.InventoryReport;
-import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.DataType;
import org.rhq.core.domain.measurement.MeasurementData;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
import org.rhq.core.domain.resource.Resource;
-import org.rhq.core.domain.resource.ResourceCategory;
-import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.inventory.InventoryManager;
@@ -63,8 +65,6 @@ import org.rhq.core.pc.util.InventoryPrinter;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
import org.rhq.core.pluginapi.operation.OperationFacet;
-import org.rhq.plugins.jmx.JMXDiscoveryComponent;
-import org.rhq.plugins.jmx.util.JvmResourceKey;
/**
* Integration test for the JMX plugin.
@@ -125,8 +125,7 @@ public class JMXPluginTest {
}
private Process startTestServerJvm(String... jvmArgs) throws IOException {
-// String javaHome = System.getProperty("java.home");
- String javaHome = System.getenv("JAVA_HOME");
+ String javaHome = System.getProperty("java.home");
String javaCmd = javaHome + "/bin/java";
List<String> args = new ArrayList<String>();
commit 476e22a6fbf8cb4dfcfc052ef6dec7f708196d57
Author: John Sanda <jsanda(a)redhat.com>
Date: Tue Jan 29 14:58:45 2013 -0500
Revert "trying to work around NPE occurring in test"
This reverts commit 5b883624d1d85cb414dac1e5f7eea8a04ecaacfd.
diff --git a/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/util/JvmUtility.java b/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/util/JvmUtility.java
index 99f573f..1e1182f 100644
--- a/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/util/JvmUtility.java
+++ b/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/util/JvmUtility.java
@@ -104,8 +104,7 @@ public class JvmUtility {
List<VirtualMachineDescriptor> vmDescriptors = VirtualMachine.list();
for (VirtualMachineDescriptor vmDescriptor : vmDescriptors) {
if (Long.valueOf(vmDescriptor.id()) == process.getPid()) {
-// String vmUserName = process.getCredentialsName().getUser();
- String vmUserName = process.freshSnapshot().getCredentialsName().getUser();
+ String vmUserName = process.getCredentialsName().getUser();
String agentUserName = System.getProperty("user.name");
if (vmUserName.equals(agentUserName)) {
LOG.debug("Attaching to JVM for java process with PID [" + process.getPid() + "]...");
11 years, 3 months
[rhq] Branch 'release/jon3.1.x' - modules/enterprise
by Jay Shaughnessy
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java | 27 +++++++---
1 file changed, 19 insertions(+), 8 deletions(-)
New commits:
commit a716736f228925bd46f95fd13342225d6e7a055f
Author: Jay Shaughnessy <jshaughn(a)jshaughn.csb>
Date: Tue Jan 29 14:27:02 2013 -0500
Even more MergeInventoryReport speed
- avoid slsb call overhead by performing relevant query locally
- remove unnecessary em.find
- convert some em.find calls to em.getReference
CP master : c26ee34703c608e21d361eb424d5ee39f0bca065
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
index ceff0ea..9eef962 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
@@ -37,6 +37,7 @@ import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.security.auth.login.LoginException;
@@ -856,7 +857,7 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
log.debug("Agent claims resource is already in inventory. Id=" + resource.getId());
}
- existingResource = entityManager.find(Resource.class, resource.getId());
+ existingResource = entityManager.getReference(Resource.class, resource.getId());
if (isDebugEnabled) {
if (null != existingResource) {
log.debug("Found resource already in inventory. Id=" + resource.getId());
@@ -883,7 +884,6 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
// relocate the parent. Anyway, I'm not going to touch it even though it slows things down.
ResourceType resourceType = resource.getResourceType();
Resource parent = resource;
- Subject overlord = subjectManager.getOverlord();
while (null != parent && null == existingResource) {
parent = parent.getParentResource();
@@ -904,7 +904,7 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
}
if (null == existingParent) {
- existingParent = entityManager.find(Resource.class, parentId);
+ existingParent = entityManager.getReference(Resource.class, parentId);
if (null != existingParent) {
if (null != parentMap) {
parentMap.put(parentId, existingParent);
@@ -918,8 +918,16 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
// We found the parent in inventory, so now see if we can find this resource in inventory by using
// the parent, the resource key (unique among siblings), the plugin and the type.
- existingResource = resourceManager.getResourceByParentAndKey(overlord, existingParent,
- resource.getResourceKey(), resourceType.getPlugin(), resourceType.getName());
+ Query query = entityManager.createNamedQuery(Resource.QUERY_FIND_BY_PARENT_AND_KEY);
+ query.setParameter("parent", existingParent);
+ query.setParameter("key", resource.getResourceKey());
+ query.setParameter("plugin", resourceType.getPlugin());
+ query.setParameter("typeName", resourceType.getName());
+ try {
+ existingResource = (Resource) query.getSingleResult();
+ } catch (NoResultException e) {
+ existingResource = null;
+ }
}
if (null != existingResource) {
@@ -947,6 +955,12 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
return existingResource;
}
+ /**
+ * <p>Requires A Transaction.</p>
+ * @param updatedResource pojo
+ * @param existingResource attached entity
+ * @throws InvalidInventoryReportException
+ */
private void updateExistingResource(Resource updatedResource, Resource existingResource)
throws InvalidInventoryReportException {
/*
@@ -964,9 +978,6 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
return;
}
- // get an attached entity to update
- existingResource = entityManager.find(Resource.class, existingResource.getId());
-
Resource existingParent = existingResource.getParentResource();
Resource updatedParent = updatedResource.getParentResource();
ResourceType existingResourceParentType = (existingParent != null) ? existingResource.getParentResource()
11 years, 3 months
[rhq] modules/enterprise
by Jay Shaughnessy
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java | 27 +++++++---
1 file changed, 19 insertions(+), 8 deletions(-)
New commits:
commit ffc824545987d3a3ec959b82208f79c933c2ae41
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Tue Jan 29 14:23:16 2013 -0500
Even more MergeInventoryReport speed
- avoid slsb call overhead by performing relevant query locally
- remove unnecessary em.find
- convert some em.find calls to em.getReference
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
index 29ea65c..cea1f6e 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/discovery/DiscoveryBossBean.java
@@ -37,6 +37,7 @@ import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.security.auth.login.LoginException;
@@ -866,7 +867,7 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
log.debug("Agent claims resource is already in inventory. Id=" + resource.getId());
}
- existingResource = entityManager.find(Resource.class, resource.getId());
+ existingResource = entityManager.getReference(Resource.class, resource.getId());
if (isDebugEnabled) {
if (null != existingResource) {
log.debug("Found resource already in inventory. Id=" + resource.getId());
@@ -893,7 +894,6 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
// relocate the parent. Anyway, I'm not going to touch it even though it slows things down.
ResourceType resourceType = resource.getResourceType();
Resource parent = resource;
- Subject overlord = subjectManager.getOverlord();
while (null != parent && null == existingResource) {
parent = parent.getParentResource();
@@ -914,7 +914,7 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
}
if (null == existingParent) {
- existingParent = entityManager.find(Resource.class, parentId);
+ existingParent = entityManager.getReference(Resource.class, parentId);
if (null != existingParent) {
if (null != parentMap) {
parentMap.put(parentId, existingParent);
@@ -928,8 +928,16 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
// We found the parent in inventory, so now see if we can find this resource in inventory by using
// the parent, the resource key (unique among siblings), the plugin and the type.
- existingResource = resourceManager.getResourceByParentAndKey(overlord, existingParent,
- resource.getResourceKey(), resourceType.getPlugin(), resourceType.getName());
+ Query query = entityManager.createNamedQuery(Resource.QUERY_FIND_BY_PARENT_AND_KEY);
+ query.setParameter("parent", existingParent);
+ query.setParameter("key", resource.getResourceKey());
+ query.setParameter("plugin", resourceType.getPlugin());
+ query.setParameter("typeName", resourceType.getName());
+ try {
+ existingResource = (Resource) query.getSingleResult();
+ } catch (NoResultException e) {
+ existingResource = null;
+ }
}
if (null != existingResource) {
@@ -957,6 +965,12 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
return existingResource;
}
+ /**
+ * <p>Requires A Transaction.</p>
+ * @param updatedResource pojo
+ * @param existingResource attached entity
+ * @throws InvalidInventoryReportException
+ */
private void updateExistingResource(Resource updatedResource, Resource existingResource)
throws InvalidInventoryReportException {
/*
@@ -974,9 +988,6 @@ public class DiscoveryBossBean implements DiscoveryBossLocal, DiscoveryBossRemot
return;
}
- // get an attached entity to update
- existingResource = entityManager.find(Resource.class, existingResource.getId());
-
Resource existingParent = existingResource.getParentResource();
Resource updatedParent = updatedResource.getParentResource();
ResourceType existingResourceParentType = (existingParent != null) ? existingResource.getParentResource()
11 years, 3 months
[rhq] Branch 'feature/cassandra-backend' - modules/plugins
by John Sanda
modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/util/JvmUtility.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
New commits:
commit 5b883624d1d85cb414dac1e5f7eea8a04ecaacfd
Author: John Sanda <jsanda(a)redhat.com>
Date: Tue Jan 29 12:53:30 2013 -0500
trying to work around NPE occurring in test
Might be caused by https://jira.hyperic.com/browse/SIGAR-231
diff --git a/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/util/JvmUtility.java b/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/util/JvmUtility.java
index 1e1182f..99f573f 100644
--- a/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/util/JvmUtility.java
+++ b/modules/plugins/jmx/src/main/java/org/rhq/plugins/jmx/util/JvmUtility.java
@@ -104,7 +104,8 @@ public class JvmUtility {
List<VirtualMachineDescriptor> vmDescriptors = VirtualMachine.list();
for (VirtualMachineDescriptor vmDescriptor : vmDescriptors) {
if (Long.valueOf(vmDescriptor.id()) == process.getPid()) {
- String vmUserName = process.getCredentialsName().getUser();
+// String vmUserName = process.getCredentialsName().getUser();
+ String vmUserName = process.freshSnapshot().getCredentialsName().getUser();
String agentUserName = System.getProperty("user.name");
if (vmUserName.equals(agentUserName)) {
LOG.debug("Attaching to JVM for java process with PID [" + process.getPid() + "]...");
11 years, 3 months