[rhq] Branch 'pc' - .classpath
by mazz
.classpath | 1 -
1 file changed, 1 deletion(-)
New commits:
commit 17a352ec6f4a66174d489214e4b2f2b53f94cf8b
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Oct 31 14:25:51 2009 -0400
Squashed commit of the following:
commit c3d0353629ffcd41cf0404253b31f9c191be4b5f
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Oct 31 14:23:02 2009 -0400
no longer use redstone xmlrpc lib
diff --git a/.classpath b/.classpath
index 344d84a..7f1256c 100644
--- a/.classpath
+++ b/.classpath
@@ -189,7 +189,6 @@
<classpathentry exported="true" kind="var" path="M2_REPO/bouncycastle/bcprov-jdk15/140/bcprov-jdk15-140.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/org/apache/xmlrpc/xmlrpc-client/3.1.2/xmlrpc-client-3.1.2.jar" sourcepath="/M2_REPO/org/apache/xmlrpc/xmlrpc-client/3.1.2/xmlrpc-client-3.1.2-sources.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/org/apache/xmlrpc/xmlrpc-common/3.1.2/xmlrpc-common-3.1.2.jar"/>
- <classpathentry exported="true" kind="var" path="M2_REPO/net/sf/xmlrpc/xmlrpc/1.1.1/xmlrpc-1.1.1.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/org/apache/ws/commons/util/ws-commons-util/1.0.2/ws-commons-util-1.0.2.jar"/>
<classpathentry exported="true" kind="lib" path="modules/enterprise/remoting/webservices/target/rhq-remoting-webservices-1.4.0-SNAPSHOT/wsconsume-output"/>
<classpathentry kind="var" path="M2_REPO/org/antlr/antlr-runtime/3.2/antlr-runtime-3.2.jar"/>
14 years, 1 month
[rhq] .classpath
by mazz
.classpath | 1 -
1 file changed, 1 deletion(-)
New commits:
commit c3d0353629ffcd41cf0404253b31f9c191be4b5f
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Oct 31 14:23:02 2009 -0400
no longer use redstone xmlrpc lib
diff --git a/.classpath b/.classpath
index 344d84a..7f1256c 100644
--- a/.classpath
+++ b/.classpath
@@ -189,7 +189,6 @@
<classpathentry exported="true" kind="var" path="M2_REPO/bouncycastle/bcprov-jdk15/140/bcprov-jdk15-140.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/org/apache/xmlrpc/xmlrpc-client/3.1.2/xmlrpc-client-3.1.2.jar" sourcepath="/M2_REPO/org/apache/xmlrpc/xmlrpc-client/3.1.2/xmlrpc-client-3.1.2-sources.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/org/apache/xmlrpc/xmlrpc-common/3.1.2/xmlrpc-common-3.1.2.jar"/>
- <classpathentry exported="true" kind="var" path="M2_REPO/net/sf/xmlrpc/xmlrpc/1.1.1/xmlrpc-1.1.1.jar"/>
<classpathentry exported="true" kind="var" path="M2_REPO/org/apache/ws/commons/util/ws-commons-util/1.0.2/ws-commons-util-1.0.2.jar"/>
<classpathentry exported="true" kind="lib" path="modules/enterprise/remoting/webservices/target/rhq-remoting-webservices-1.4.0-SNAPSHOT/wsconsume-output"/>
<classpathentry kind="var" path="M2_REPO/org/antlr/antlr-runtime/3.2/antlr-runtime-3.2.jar"/>
14 years, 1 month
[rhq] Branch 'pc' - modules/helpers
by mazz
modules/helpers/rtfilter/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
New commits:
commit 6651c516b71893b310f5671f95c1677b59611d0a
Author: John Sanda <john(a)localhost.localdomain>
Date: Fri Oct 30 22:20:37 2009 -0400
Fixing group id of parent pom.
The group id of the parent pom was set to org.rhq but should be org.rhq.helpers.
diff --git a/modules/helpers/rtfilter/pom.xml b/modules/helpers/rtfilter/pom.xml
index b05625a..a3a0aea 100644
--- a/modules/helpers/rtfilter/pom.xml
+++ b/modules/helpers/rtfilter/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.rhq</groupId>
+ <groupId>org.rhq.helpers</groupId>
<artifactId>rhq-helpers</artifactId>
<version>1.4.0-SNAPSHOT</version>
</parent>
@@ -119,4 +119,4 @@
</profiles>
-</project>
\ No newline at end of file
+</project>
14 years, 1 month
[rhq] modules/helpers
by John Sanda
modules/helpers/rtfilter/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
New commits:
commit 6651c516b71893b310f5671f95c1677b59611d0a
Author: John Sanda <john(a)localhost.localdomain>
Date: Fri Oct 30 22:20:37 2009 -0400
Fixing group id of parent pom.
The group id of the parent pom was set to org.rhq but should be org.rhq.helpers.
diff --git a/modules/helpers/rtfilter/pom.xml b/modules/helpers/rtfilter/pom.xml
index b05625a..a3a0aea 100644
--- a/modules/helpers/rtfilter/pom.xml
+++ b/modules/helpers/rtfilter/pom.xml
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.rhq</groupId>
+ <groupId>org.rhq.helpers</groupId>
<artifactId>rhq-helpers</artifactId>
<version>1.4.0-SNAPSHOT</version>
</parent>
@@ -119,4 +119,4 @@
</profiles>
-</project>
\ No newline at end of file
+</project>
14 years, 1 month
[rhq] Branch 'linux-config' - modules/plugins
by Partha Aji
modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
New commits:
commit c2c76dd29e7592715432d0a563c87ac9878b3726
Author: Partha Aji <paji(a)redhat.com>
Date: Fri Oct 30 19:42:45 2009 -0400
Fixed a broken sudoers add configuration thanks to changes in Base component
diff --git a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java
index 2202a0f..401075a 100644
--- a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java
+++ b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java
@@ -525,7 +525,11 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
} else {
// The maps in the list are non-keyed, or there is no map in the list with the same key as the map
// being added, so create a new node for the map to add to the list.
- memberNodeToUpdate = getNewListMemberNode(listNode, listMemberPropDefMap, listIndex++);
+ AugeasNode basePathNode = getNewListMemberNode(listNode, listMemberPropDefMap, listIndex);
+ String var = "prop" + listIndex;
+ augeas.defineNode(var, basePathNode.getPath(), null);
+ memberNodeToUpdate = new AugeasNode("$" + var);
+ listIndex++;
}
// Update the node's children.
14 years, 1 month
[rhq] Branch 'linux-config' - modules/plugins
by Partha Aji
modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java | 23 +++++-----
1 file changed, 12 insertions(+), 11 deletions(-)
New commits:
commit d05920292d337406e77bff1caf17052f1d6b5ba3
Author: Partha Aji <paji(a)redhat.com>
Date: Fri Oct 30 19:06:54 2009 -0400
Fixed an accidental bug that occured because of choosing the wrong variable name...
diff --git a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java
index 8a66946..2202a0f 100644
--- a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java
+++ b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java
@@ -72,13 +72,13 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
public static final String INCLUDE_GLOBS_PROP = "configurationFilesInclusionPatterns";
public static final String EXCLUDE_GLOBS_PROP = "configurationFilesExclusionPatterns";
public static final String RESOURCE_CONFIGURATION_ROOT_NODE_PROP = "resourceConfigurationRootNode";
- public static final String AUGEAS_MODULE_NAME_PROP = "augeasModuleName";
+ public static final String AUGEAS_MODULE_NAME_PROP = "augeasModuleName";
private static final boolean IS_WINDOWS = (File.separatorChar == '\\');
private static final String AUGEAS_LOAD_PATH = "/usr/share/augeas/lenses";
private static final String AUGEAS_DEFAULT_ROOT_PATH = "/";
- private static final String AUGEAS_ROOT_PATH_VAR = "AUGEAS_ROOT";
+ public static final String AUGEAS_ROOT_PATH_VAR = "AUGEAS_ROOT";
private final Log log = LogFactory.getLog(this.getClass());
@@ -89,11 +89,11 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
private AugeasNode resourceConfigRootNode;
static String getAugeasRootPath() {
- String rootPath = System.getProperty("AUGEAS_ROOT");
+ String rootPath = System.getProperty(AUGEAS_ROOT_PATH_VAR);
if (rootPath != null && rootPath.trim().length() != 0) {
return rootPath;
}
- return AUGEAS_ROOT_PATH_VAR;
+ return AUGEAS_DEFAULT_ROOT_PATH;
}
public void start(ResourceContext<T> resourceContext) throws InvalidPluginConfigurationException, Exception {
@@ -340,7 +340,7 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
protected String getAugeasPathRelativeToParent(PropertyDefinition propDef, AugeasNode parentNode, Augeas augeas) {
return propDef.getName();
}
-
+
protected void loadProperty(PropertyDefinition propDef, AbstractPropertyMap parentPropMap, Augeas augeas,
AugeasNode parentNode) {
String propName = getAugeasPathRelativeToParent(propDef, parentNode, augeas);
@@ -540,10 +540,10 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
}
}
- protected AugeasNode getNewListMemberNode(AugeasNode listNode,
- PropertyDefinitionMap listMemberPropDefMap, int listIndex) {
+ protected AugeasNode getNewListMemberNode(AugeasNode listNode, PropertyDefinitionMap listMemberPropDefMap,
+ int listIndex) {
return new AugeasNode(listNode, getAugeasPathRelativeToParent(listMemberPropDefMap, listNode, getAugeas())
- + "[" + listIndex + "]");
+ + "[" + listIndex + "]");
}
private boolean isPropertyDefined(PropertyDefinition propDef, AbstractPropertyMap parentPropMap) {
@@ -607,10 +607,11 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
+ "' is a directory, not a regular file.");
}
}
+
protected String summarizeAugeasError() {
StringBuilder summary = new StringBuilder();
String metadataNodePrefix = "/augeas/files";
- for(String glob : includeGlobs) {
+ for (String glob : includeGlobs) {
if (glob.startsWith(AugeasNode.SEPARATOR)) {
glob = glob.substring(1);
}
@@ -619,8 +620,8 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
List<String> nodePaths = this.augeas.match(errorNode.getPath() + "/*");
for (String path : nodePaths) {
String error = this.augeas.get(path);
- summary.append("File \"").append(path.substring(metadataNodePrefix.length(), path.length()))
- .append("\":\n").append(error).append("\n");
+ summary.append("File \"").append(path.substring(metadataNodePrefix.length(), path.length())).append(
+ "\":\n").append(error).append("\n");
}
}
14 years, 1 month
[rhq] Branch 'linux-config' - modules/plugins
by Partha Aji
modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java | 17 +-
modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationDiscoveryComponent.java | 83 +++++-----
2 files changed, 59 insertions(+), 41 deletions(-)
New commits:
commit 8f574acd781af4b6c9a71a53a88249017a7abefb
Author: Partha Aji <paji(a)redhat.com>
Date: Fri Oct 30 18:32:17 2009 -0400
Added a way to specify custom augeas root directories by adding the 'AUGEAS_ROOT' property
diff --git a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java
index 8b27191..8a66946 100644
--- a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java
+++ b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationComponent.java
@@ -76,7 +76,9 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
private static final boolean IS_WINDOWS = (File.separatorChar == '\\');
private static final String AUGEAS_LOAD_PATH = "/usr/share/augeas/lenses";
- public static final String AUGEAS_ROOT_PATH = "/";
+ private static final String AUGEAS_DEFAULT_ROOT_PATH = "/";
+
+ private static final String AUGEAS_ROOT_PATH_VAR = "AUGEAS_ROOT";
private final Log log = LogFactory.getLog(this.getClass());
@@ -86,6 +88,14 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
private Augeas augeas;
private AugeasNode resourceConfigRootNode;
+ static String getAugeasRootPath() {
+ String rootPath = System.getProperty("AUGEAS_ROOT");
+ if (rootPath != null && rootPath.trim().length() != 0) {
+ return rootPath;
+ }
+ return AUGEAS_ROOT_PATH_VAR;
+ }
+
public void start(ResourceContext<T> resourceContext) throws InvalidPluginConfigurationException, Exception {
this.resourceContext = resourceContext;
Configuration pluginConfig = this.resourceContext.getPluginConfiguration();
@@ -270,7 +280,7 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
}
public List<File> getConfigurationFiles() {
- List<File> files = Glob.matchAll(new File(AUGEAS_ROOT_PATH), includeGlobs);
+ List<File> files = Glob.matchAll(new File(getAugeasRootPath()), includeGlobs);
Glob.excludeAll(files, excludeGlobs);
return files;
}
@@ -292,7 +302,7 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
Augeas augeas;
try {
- augeas = new Augeas(AUGEAS_ROOT_PATH, AUGEAS_LOAD_PATH, Augeas.NO_MODL_AUTOLOAD);
+ augeas = new Augeas(getAugeasRootPath(), AUGEAS_LOAD_PATH, Augeas.NO_MODL_AUTOLOAD);
augeas.set("/augeas/load/" + augeasModuleName + "/lens", augeasModuleName + ".lns");
int idx = 1;
@@ -303,6 +313,7 @@ public class AugeasConfigurationComponent<T extends ResourceComponent> implement
for (String excl : excludeGlobs) {
augeas.set("/augeas/load/" + augeasModuleName + "/excl[" + (idx++) + "]", excl);
}
+ augeas.load();
} catch (RuntimeException e) {
augeas = null;
log.warn("Failed to initialize Augeas Java API.", e);
diff --git a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationDiscoveryComponent.java b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationDiscoveryComponent.java
index 49e8331..83ba261 100644
--- a/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationDiscoveryComponent.java
+++ b/modules/plugins/augeas/src/main/java/org/rhq/plugins/augeas/AugeasConfigurationDiscoveryComponent.java
@@ -43,24 +43,25 @@ import org.rhq.plugins.augeas.helper.Glob;
* @author Ian Springer
* @author Lukas Krejci
*/
-public class AugeasConfigurationDiscoveryComponent<T extends ResourceComponent> implements ResourceDiscoveryComponent<T>, ManualAddFacet<T> {
+public class AugeasConfigurationDiscoveryComponent<T extends ResourceComponent> implements
+ ResourceDiscoveryComponent<T>, ManualAddFacet<T> {
private final Log log = LogFactory.getLog(this.getClass());
- public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<T> discoveryContext) throws InvalidPluginConfigurationException,
- Exception {
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<T> discoveryContext)
+ throws InvalidPluginConfigurationException, Exception {
Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>(1);
List<String> includes = determineIncludeGlobs(discoveryContext);
List<String> excludes = determineExcludeGlobs(discoveryContext);
-
+
Configuration pluginConfig = discoveryContext.getDefaultPluginConfiguration();
PropertySimple includeProps = getGlobList(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP, includes);
PropertySimple excludeProps = getGlobList(AugeasConfigurationComponent.EXCLUDE_GLOBS_PROP, excludes);
pluginConfig.put(includeProps);
pluginConfig.put(excludeProps);
-
+
checkFiles(pluginConfig);
-
+
DiscoveredResourceDetails resource = createResourceDetails(discoveryContext, pluginConfig);
discoveredResources.add(resource);
log.debug("Discovered " + discoveryContext.getResourceType().getName() + " Resource with key ["
@@ -71,7 +72,7 @@ public class AugeasConfigurationDiscoveryComponent<T extends ResourceComponent>
public DiscoveredResourceDetails discoverResource(Configuration pluginConfig,
ResourceDiscoveryContext<T> discoveryContext) throws InvalidPluginConfigurationException {
-
+
checkFiles(pluginConfig);
DiscoveredResourceDetails resource = createResourceDetails(discoveryContext, pluginConfig);
@@ -86,48 +87,52 @@ public class AugeasConfigurationDiscoveryComponent<T extends ResourceComponent>
.getName(), null, resourceType.getDescription(), pluginConfig, null);
return resource;
}
-
+
protected List<String> determineIncludeGlobs(ResourceDiscoveryContext<T> discoveryContext) {
Configuration pluginConfiguration = discoveryContext.getDefaultPluginConfiguration();
- PropertySimple includeGlobsProp = pluginConfiguration.getSimple(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP);
-
+ PropertySimple includeGlobsProp = pluginConfiguration
+ .getSimple(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP);
+
List<String> ret = getGlobList(includeGlobsProp);
if (ret == null || ret.size() == 0) {
- throw new IllegalStateException("Expecting at least once inclusion pattern for configuration files.");
+ throw new IllegalStateException("Expecting at least once inclusion pattern for configuration files.");
}
-
+
return ret;
}
-
+
protected List<String> determineExcludeGlobs(ResourceDiscoveryContext<T> discoveryContext) {
Configuration pluginConfiguration = discoveryContext.getDefaultPluginConfiguration();
- PropertySimple excludeGlobsProp = pluginConfiguration.getSimple(AugeasConfigurationComponent.EXCLUDE_GLOBS_PROP);
-
+ PropertySimple excludeGlobsProp = pluginConfiguration
+ .getSimple(AugeasConfigurationComponent.EXCLUDE_GLOBS_PROP);
+
List<String> ret = getGlobList(excludeGlobsProp);
-
+
return ret;
}
private void checkFiles(Configuration pluginConfiguration) {
- PropertySimple includeGlobsProp = pluginConfiguration.getSimple(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP);
- PropertySimple excludeGlobsProp = pluginConfiguration.getSimple(AugeasConfigurationComponent.EXCLUDE_GLOBS_PROP);
-
- File root = new File(AugeasConfigurationComponent.AUGEAS_ROOT_PATH);
-
+ PropertySimple includeGlobsProp = pluginConfiguration
+ .getSimple(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP);
+ PropertySimple excludeGlobsProp = pluginConfiguration
+ .getSimple(AugeasConfigurationComponent.EXCLUDE_GLOBS_PROP);
+
+ File root = new File(AugeasConfigurationComponent.getAugeasRootPath());
+
List<String> includeGlobs = getGlobList(includeGlobsProp);
-
+
if (includeGlobsProp == null) {
throw new IllegalStateException("Expecting at least once inclusion pattern for configuration files.");
}
-
+
List<File> files = Glob.matchAll(root, includeGlobs);
-
+
if (excludeGlobsProp != null) {
List<String> excludeGlobs = getGlobList(excludeGlobsProp);
Glob.excludeAll(files, excludeGlobs);
}
-
- for(File configFile : files) {
+
+ for (File configFile : files) {
if (!configFile.isAbsolute()) {
throw new IllegalStateException("Configuration files inclusion patterns contain a non-absolute file.");
}
@@ -139,29 +144,31 @@ public class AugeasConfigurationDiscoveryComponent<T extends ResourceComponent>
}
}
}
-
+
private String composeResourceKey(Configuration pluginConfiguration) {
- PropertySimple includeGlobsProp = pluginConfiguration.getSimple(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP);
- PropertySimple excludeGlobsProp = pluginConfiguration.getSimple(AugeasConfigurationComponent.EXCLUDE_GLOBS_PROP);
-
+ PropertySimple includeGlobsProp = pluginConfiguration
+ .getSimple(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP);
+ PropertySimple excludeGlobsProp = pluginConfiguration
+ .getSimple(AugeasConfigurationComponent.EXCLUDE_GLOBS_PROP);
+
StringBuilder bld = new StringBuilder();
-
+
bld.append(includeGlobsProp.getStringValue());
-
- if (excludeGlobsProp != null && excludeGlobsProp.getStringValue().length() > 0) {
+
+ if (excludeGlobsProp != null && excludeGlobsProp.getStringValue().length() > 0) {
bld.append("---");
bld.append(excludeGlobsProp.getStringValue());
}
-
+
bld.deleteCharAt(bld.length() - 1);
-
+
return bld.toString();
}
-
+
public static PropertySimple getGlobList(String name, List<String> simples) {
StringBuilder bld = new StringBuilder();
if (simples != null) {
- for(String s : simples) {
+ for (String s : simples) {
bld.append(s).append("|");
}
}
@@ -170,7 +177,7 @@ public class AugeasConfigurationDiscoveryComponent<T extends ResourceComponent>
}
return new PropertySimple(name, bld.toString());
}
-
+
public static List<String> getGlobList(PropertySimple list) {
if (list != null) {
return Arrays.asList(list.getStringValue().split("\\s*\\|\\s*"));
14 years, 1 month
[rhq] Branch 'raw-config' - 4 commits - modules/core modules/enterprise
by John Sanda
modules/core/client-api/src/main/java/org/rhq/core/clientapi/descriptor/PluginTransformException.java | 48 +
modules/core/client-api/src/main/java/org/rhq/core/clientapi/descriptor/PluginTransformer.java | 124 ++++
modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java | 303 ++++++++++
modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainerConfiguration.java | 16
modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginManager.java | 83 ++
modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java | 3
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml | 3
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ProductPluginDeployer.java | 16
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java | 46 -
9 files changed, 599 insertions(+), 43 deletions(-)
New commits:
commit 81923849f08cf1267a63938a3a11f89bace50061
Merge: 370de38... 58bea15...
Author: John Sanda <john(a)localhost.localdomain>
Date: Fri Oct 30 17:01:21 2009 -0400
Merge branch 'raw-config' of ssh://git.fedorahosted.org/git/rhq/rhq into raw-config
commit 370de388b6e3b3f0b88f7e2a2a5f7dfc325f7b41
Author: John Sanda <john(a)localhost.localdomain>
Date: Fri Oct 30 16:46:22 2009 -0400
[US 403] Adding ampsVersion to UI in plugin details page and updating logic for setting ampsVersion for exisitng plugins
For any pre-existing plugin whose ampsVersion is undefined or less than 2.1, the ampsVersion will be set to 2.0. This logic has been added to ProductPluginDeployer.
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
index 3c8a1f3..e1aef90 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
@@ -49,6 +49,9 @@
<h:outputLabel styleClass="BlockLabel" value="Version:"/>
<h:outputText styleClass="BlockContent" value="#{InstalledPluginUIBean.plugin.version}"/>
+ <h:outputLabel styleClass="BlockLabel" value="AMPS Version:"/>
+ <h:outputText styleClass="BlockContent" value="#{InstalledPluginUIBean.plugin.ampsVersion}"/>
+
<h:outputLabel styleClass="BlockLabel" value="Enabled:"/>
<h:outputText value="#{InstalledPluginUIBean.plugin.enabled}"/>
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ProductPluginDeployer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ProductPluginDeployer.java
index 6a73c7f..3c54d3c 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ProductPluginDeployer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ProductPluginDeployer.java
@@ -485,7 +485,7 @@ public class ProductPluginDeployer {
plugin.setDisplayName((displayName != null) ? displayName : pluginName);
plugin.setEnabled(true);
plugin.setDescription(pluginDescriptor.getDescription());
- plugin.setAmpsVersion(pluginDescriptor.getAmpsVersion());
+ plugin.setAmpsVersion(getAmpsVersion(pluginDescriptor));
// get the last modified of the "real" plugin jar since that's the one the user touches
long mtime = deploymentInfo.url.openConnection().getLastModified();
@@ -510,6 +510,21 @@ public class ProductPluginDeployer {
}
}
+ private String getAmpsVersion(PluginDescriptor pluginDescriptor) {
+ if (pluginDescriptor.getAmpsVersion() == null) {
+ return "2.0";
+ }
+
+ ComparableVersion version = new ComparableVersion(pluginDescriptor.getAmpsVersion());
+ ComparableVersion version2 = new ComparableVersion("2.0");
+
+ if (version.compareTo(version2) <= 0) {
+ return "2.0";
+ }
+
+ return pluginDescriptor.getAmpsVersion();
+ }
+
private void checkVersionCompatibility(String version) throws RuntimeException {
/*if (new OSGiVersionComparator().compare((String) version, (String) AMPS_VERSION) < 0)
* { throw new RuntimeException("Plugin AMPS requirement " + version + " not compatible with server's AMPS
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 7d2265a..bfc7d86 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
@@ -18,32 +18,8 @@
*/
package org.rhq.enterprise.server.resource.metadata;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.ejb.EJB;
-import javax.ejb.Stateless;
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-import javax.persistence.NonUniqueResultException;
-import javax.persistence.PersistenceContext;
-import javax.persistence.Query;
-import javax.sql.DataSource;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.rhq.core.clientapi.agent.metadata.PluginMetadataManager;
import org.rhq.core.clientapi.agent.metadata.SubCategoriesMetadataParser;
import org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil;
@@ -72,6 +48,28 @@ import org.rhq.enterprise.server.measurement.MeasurementDefinitionManagerLocal;
import org.rhq.enterprise.server.measurement.MeasurementScheduleManagerLocal;
import org.rhq.enterprise.server.resource.ResourceManagerLocal;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.NonUniqueResultException;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+import javax.sql.DataSource;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* This class manages the metadata for resources. Plugins are registered against this bean so that their metadata can be
* pulled out and stored as necessary.
commit 136646283cce6474558787bb266db9ce3cacecdb
Author: John Sanda <john(a)localhost.localdomain>
Date: Fri Oct 30 13:50:04 2009 -0400
[US 403] Modifying plugin container to load Plugin objects in their entirety.
Adding pluginsOnServer property to PluginContainerConfiguration. This set contains plugins sent
down from the server. It is only populated when the plugin container is running inside an agent.
Modyfing PluginUpdate to populate PluginContainerConfiguration.pluginsOnServer with the plugins
sent down from the server.
Updating PluginManager to store loaded plugin as Plugin objects. Previously, only the names
were stored. Now we can more easily retrive the ampsVersion of a plugin. Support has been added
to load plugins both in enterripse (i.e., running inside an agent) and in embedded mode.
Updating ProductPluginDeployer to set the ampsVersion of the Plugin object that is creates.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainerConfiguration.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainerConfiguration.java
index b76354b..563eb47 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainerConfiguration.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/PluginContainerConfiguration.java
@@ -26,10 +26,13 @@ import java.io.File;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
import org.rhq.core.pc.plugin.PluginFinder;
import org.rhq.core.pc.plugin.RootPluginClassLoader;
import org.rhq.core.pluginapi.inventory.PluginContainerDeployment;
+import org.rhq.core.domain.plugin.Plugin;
/**
* Configuration properties for the plugin container and all its internal managers.
@@ -124,6 +127,11 @@ public class PluginContainerConfiguration {
private ServerServices serverServices = null;
/**
+ * The plugins that reside on the server which are sent down to the agent.
+ */
+ private Set<Plugin> pluginsOnServer = new HashSet<Plugin>();
+
+ /**
* This is our hash map that contains the actual properties. We use a map (as opposed to individual data member
* variables) to support a future enhancement by which our plugins can squirrel away their own custom global
* properties here.
@@ -704,6 +712,14 @@ public class PluginContainerConfiguration {
this.serverServices = serverServices;
}
+ public Set<Plugin> getPluginsOnServer() {
+ return pluginsOnServer;
+ }
+
+ public void setPluginsOnServer(Set<Plugin> plugins) {
+ pluginsOnServer = plugins;
+ }
+
/**
* Returns whether or not the plugin container is running inside an agent, which means it is running external to any
* managed product.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginManager.java
index 1b9399a..4f71ab2 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/plugin/PluginManager.java
@@ -22,25 +22,16 @@
*/
package org.rhq.core.pc.plugin;
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.Nullable;
-
import org.rhq.core.clientapi.agent.PluginContainerException;
import org.rhq.core.clientapi.agent.metadata.PluginDependencyGraph;
import org.rhq.core.clientapi.agent.metadata.PluginMetadataManager;
import org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil;
+import org.rhq.core.clientapi.descriptor.PluginTransformer;
import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
+import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.pc.ContainerService;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pluginapi.plugin.PluginContext;
@@ -48,6 +39,18 @@ import org.rhq.core.pluginapi.plugin.PluginLifecycleListener;
import org.rhq.core.system.SystemInfo;
import org.rhq.core.system.SystemInfoFactory;
import org.rhq.core.util.exception.ThrowableUtil;
+import org.rhq.core.util.MessageDigestGenerator;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* This container service will load in all plugins that can be found and will maintain the complete set of
@@ -60,6 +63,16 @@ import org.rhq.core.util.exception.ThrowableUtil;
* @author John Mazzitelli
*/
public class PluginManager implements ContainerService {
+
+ /**
+ * A callback interface for updating the loadedPlugins list. When running inside of an agent, loadedPlugins gets
+ * updated with Plugin objects received from the RHQ server. When running in embedded mode, we have to create the
+ * Plugin objects ourselves.
+ */
+ private static interface UpdateLoadedPlugins {
+ void execute(PluginDescriptor pluginDescriptor, URL pluginURL);
+ }
+
private static final Log log = LogFactory.getLog(PluginManager.class);
/**
@@ -68,9 +81,9 @@ public class PluginManager implements ContainerService {
private Map<String, PluginEnvironment> loadedPluginEnvironments;
/**
- * A list of loaded plugin names in the order in which they were loaded.
+ * A list of loaded plugins in the order in which they were loaded.
*/
- private List<String> loadedPlugins;
+ private List<Plugin> loadedPlugins;
/**
* Cached instances of objects used to initialize and shutdown individual plugins.
@@ -81,6 +94,7 @@ public class PluginManager implements ContainerService {
private PluginMetadataManager metadataManager;
private ClassLoaderManager classLoaderManager;
private PluginContainerConfiguration configuration;
+ private UpdateLoadedPlugins updateLoadedPlugins;
/**
* Finds all plugins using the plugin finder defined in the
@@ -91,10 +105,12 @@ public class PluginManager implements ContainerService {
*/
public void initialize() {
loadedPluginEnvironments = new HashMap<String, PluginEnvironment>();
- loadedPlugins = new ArrayList<String>();
+ loadedPlugins = new ArrayList<Plugin>();
pluginLifecycleListenerCache = new HashMap<String, PluginLifecycleListener>();
metadataManager = new PluginMetadataManager();
+ initUpdateLoadedPluginsCallback();
+
PluginFinder finder = configuration.getPluginFinder();
File tmpDir = configuration.getTemporaryDirectory();
@@ -161,6 +177,35 @@ public class PluginManager implements ContainerService {
return;
}
+ private void initUpdateLoadedPluginsCallback() {
+ if (configuration.isInsideAgent()) {
+ updateLoadedPlugins = new UpdateLoadedPlugins() {
+ public void execute(PluginDescriptor pluginDescriptor, URL pluginURL) {
+ loadPluginIfFoundInListFromServer(pluginDescriptor);
+ }
+ };
+ }
+ else {
+ updateLoadedPlugins = new UpdateLoadedPlugins() {
+ PluginTransformer transformer = new PluginTransformer();
+
+ public void execute(PluginDescriptor pluginDescriptor, URL pluginURL) {
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, pluginURL);
+ loadedPlugins.add(plugin);
+ }
+ };
+ }
+ }
+
+ private void loadPluginIfFoundInListFromServer(PluginDescriptor pluginDescriptor) {
+ for (Plugin plugin : configuration.getPluginsOnServer()) {
+ if (pluginDescriptor.getName().equals(plugin.getName())) {
+ loadedPlugins.add(plugin);
+ return;
+ }
+ }
+ }
+
/**
* @see ContainerService#shutdown()
*/
@@ -168,20 +213,20 @@ public class PluginManager implements ContainerService {
// Inform the plugins we are shutting them down.
// We want to shut them down in the reverse order that we initialized them.
Collections.reverse(this.loadedPlugins);
- for (String pluginName : this.loadedPlugins) {
- PluginLifecycleListener listener = this.pluginLifecycleListenerCache.get(pluginName);
+ for (Plugin plugin : loadedPlugins) {
+ PluginLifecycleListener listener = this.pluginLifecycleListenerCache.get(plugin.getName());
if (listener != null) {
try {
ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(
- this.classLoaderManager.obtainPluginClassLoader(pluginName));
+ this.classLoaderManager.obtainPluginClassLoader(plugin.getName()));
try {
listener.shutdown();
} finally {
Thread.currentThread().setContextClassLoader(originalCL);
}
} catch (Throwable t) {
- log.warn("Failed to get lifecycle listener to shutdown [" + pluginName + "]. Cause: "
+ log.warn("Failed to get lifecycle listener to shutdown [" + plugin.getName() + "]. Cause: "
+ ThrowableUtil.getAllMessages(t));
}
}
@@ -298,7 +343,7 @@ public class PluginManager implements ContainerService {
// everything is loaded and initialized
this.loadedPluginEnvironments.put(pluginName, pluginEnvironment);
this.metadataManager.loadPlugin(pluginDescriptor);
- this.loadedPlugins.add(pluginName);
+ updateLoadedPlugins.execute(pluginDescriptor, pluginUrl);
return;
}
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java
index 605f91a..4e4a07b 100644
--- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java
+++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.HashSet;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.ReadWriteLock;
@@ -162,6 +163,8 @@ public class PluginUpdate {
// find out what the latest plugins are available to us
List<Plugin> latest_plugins = coreServerService.getLatestPlugins();
+ config.setPluginsOnServer(new HashSet(latest_plugins));
+
if (LOG.isDebugEnabled()) {
LOG.debug(AgentI18NResourceKeys.LATEST_PLUGINS_COUNT, latest_plugins.size());
for (Plugin latest_plugin : latest_plugins) {
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ProductPluginDeployer.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ProductPluginDeployer.java
index bec6ebb..6a73c7f 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ProductPluginDeployer.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ProductPluginDeployer.java
@@ -485,6 +485,7 @@ public class ProductPluginDeployer {
plugin.setDisplayName((displayName != null) ? displayName : pluginName);
plugin.setEnabled(true);
plugin.setDescription(pluginDescriptor.getDescription());
+ plugin.setAmpsVersion(pluginDescriptor.getAmpsVersion());
// get the last modified of the "real" plugin jar since that's the one the user touches
long mtime = deploymentInfo.url.openConnection().getLastModified();
commit a9e92b899c174c4fa7ffef154bb033469a3643e6
Author: John Sanda <john(a)localhost.localdomain>
Date: Fri Oct 30 11:33:42 2009 -0400
[US 403] Initial commit for PluginTransformer, PluginTransformerTest, and PluginTransformerException
PluginTransformer takes a PluginDescriptor and a URL for the plugin JAR file and converts them
into a Plugin object. This logic is needed by PluginManager when the plugin container is used in
embedded mode in order to build the list of loaded plugins. That list was previously a list of
just plugin names, but now it is a list of the Plugin domain objects. In enterprise mode, we get
those plugins from the server, but in embedded mode, we have to create the Plugin objects
ourselves since there is no server to talk to.
diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/descriptor/PluginTransformException.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/descriptor/PluginTransformException.java
new file mode 100644
index 0000000..6b31c63
--- /dev/null
+++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/descriptor/PluginTransformException.java
@@ -0,0 +1,48 @@
+/*
+ * 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.clientapi.descriptor;
+
+/**
+ * An exception that is throw when a plugin transformation fails for some reason.
+ *
+ * @see org.rhq.core.clientapi.descriptor.PluginTransformer
+ */
+public class PluginTransformException extends RuntimeException {
+
+ public PluginTransformException() {
+ super();
+ }
+
+ public PluginTransformException(String message) {
+ super(message);
+ }
+
+ public PluginTransformException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public PluginTransformException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/descriptor/PluginTransformer.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/descriptor/PluginTransformer.java
new file mode 100644
index 0000000..d1cb6ca
--- /dev/null
+++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/descriptor/PluginTransformer.java
@@ -0,0 +1,124 @@
+/*
+ * 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.clientapi.descriptor;
+
+import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
+import org.rhq.core.clientapi.descriptor.plugin.Help;
+import org.rhq.core.util.MessageDigestGenerator;
+
+import java.net.URL;
+import java.io.IOException;
+import java.io.File;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+import java.util.jar.Attributes;
+
+/**
+ * Transforms some input into a {@link org.rhq.core.domain.plugin.Plugin} object.
+ */
+public class PluginTransformer {
+
+ /**
+ * Takes the given plugin descriptor and plugin JAR file URL and converts them into a
+ * {@link org.rhq.core.domain.plugin.Plugin} object. This method does not set the <code>content</code> property
+ * of the plugin.
+ *
+ * @param pluginDescriptor The plugin descriptor from which to create the plugin
+ * @param pluginURL The URL of the plugin JAR file from which to create the plugin
+ * @return A new plugin object create from the descriptor and plugin URL
+ * @throws PluginTransformException if any IO errors occur trying to read the JAR file or if a version not in the
+ * plugin descriptor or in the plugin JAR manifest
+ */
+ public Plugin toPlugin(PluginDescriptor pluginDescriptor, URL pluginURL) {
+ try {
+ Plugin plugin = new Plugin();
+ plugin.setName(pluginDescriptor.getName());
+
+ if (pluginDescriptor.getDisplayName() == null) {
+ plugin.setDisplayName(pluginDescriptor.getName());
+ }
+ else {
+ plugin.setDisplayName(pluginDescriptor.getDisplayName());
+ }
+
+ plugin.setAmpsVersion(pluginDescriptor.getAmpsVersion());
+ plugin.setDescription(pluginDescriptor.getDescription());
+ plugin.setPath(pluginURL.getPath());
+ plugin.setMtime(pluginURL.openConnection().getLastModified());
+ plugin.setHelp(getHelp(pluginDescriptor));
+ plugin.setMd5(getMd5(pluginURL));
+ plugin.setVersion(getVersion(pluginDescriptor, pluginURL));
+
+ return plugin;
+ }
+ catch (IOException e) {
+ throw new PluginTransformException("Failed to create plugin.", e);
+ }
+ }
+
+ private String getHelp(PluginDescriptor pluginDescriptor) {
+ Help help = pluginDescriptor.getHelp();
+ if (help == null || help.getContent().isEmpty()) {
+ return null;
+ }
+ return help.getContent().get(0).toString();
+ }
+
+ private String getMd5(URL pluginURL) throws IOException {
+ File jarFile = toFile(pluginURL);
+ return MessageDigestGenerator.getDigestString(jarFile);
+ }
+
+ String getVersion(PluginDescriptor pluginDescriptor, URL pluginURL) throws IOException {
+ if (pluginDescriptor.getVersion() != null) {
+ return pluginDescriptor.getVersion();
+ }
+
+ File pluginJarFile = toFile(pluginURL);
+
+ String version = getVersionFromPluginJarManifest(pluginJarFile);
+
+ if (version == null) {
+ throw new PluginTransformException("No version is defined for plugin jar [" + pluginJarFile
+ + "]. A version must be defined either via the MANIFEST.MF [" + Attributes.Name.IMPLEMENTATION_VERSION
+ + "] attribute or via the plugin descriptor 'version' attribute.");
+ }
+
+ return version;
+ }
+
+ private String getVersionFromPluginJarManifest(File pluginJarFile) throws IOException {
+ JarFile jarFile = new JarFile(pluginJarFile);
+ Manifest manifest = jarFile.getManifest();
+ Attributes attributes = manifest.getMainAttributes();
+
+ return attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
+ }
+
+ private File toFile(URL url) {
+ return new File(url.getPath());
+ }
+
+}
diff --git a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java
new file mode 100644
index 0000000..f964178
--- /dev/null
+++ b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/descriptor/PluginTransformerTest.java
@@ -0,0 +1,303 @@
+/*
+ * 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.clientapi.descriptor;
+
+import static org.testng.Assert.*;
+
+import org.testng.annotations.Test;
+import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
+import org.rhq.core.clientapi.descriptor.plugin.Help;
+import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.util.MessageDigestGenerator;
+
+import java.net.URL;
+import java.util.jar.Manifest;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.JarFile;
+import java.io.FileOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+
+public class PluginTransformerTest {
+
+ @Test
+ public void pluginNameShouldBeSetToDescriptorName() throws Exception {
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setName("testPlugin");
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, getTestPluginURL());
+
+ assertEquals(
+ plugin.getName(),
+ pluginDescriptor.getName(),
+ "The plugin.name property should be set to the plugin descriptor name."
+ );
+ }
+
+ @Test
+ public void pluginDisplayNameShouldBeSetToDescriptorDisplayName() throws Exception {
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setName("testPlugin");
+ pluginDescriptor.setDisplayName("Test Plugin");
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, getTestPluginURL());
+
+ assertEquals(
+ plugin.getDisplayName(),
+ pluginDescriptor.getDisplayName(),
+ "The plugin.displayName property should be set to the plugin descriptor display name."
+ );
+ }
+
+ @Test
+ public void pluginDisplayNameShouldBeSetToDescriptorNameWhenItsDisplayNameIsNull() throws Exception {
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setName("testPlugin");
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, getTestPluginURL());
+
+ assertEquals(
+ plugin.getDisplayName(),
+ pluginDescriptor.getName(),
+ "The plugin.displayName property should be set to the plugin descriptor name when the descriptor display name is null."
+ );
+ }
+
+ @Test
+ public void pluginAmpsVersionShouldBeSetToDescriptorAmpsVersion() throws Exception {
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setAmpsVersion("2.1");
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, getTestPluginURL());
+
+ assertEquals(
+ plugin.getAmpsVersion(),
+ pluginDescriptor.getAmpsVersion(),
+ "The plugin.ampsVersion property should be set to the plugin descriptor ampsVersion."
+ );
+ }
+
+ @Test
+ public void pluginDescriptionShouldBeSetToDescriptorDescription() throws Exception {
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setDescription("description");
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, getTestPluginURL());
+
+ assertEquals(
+ plugin.getDescription(),
+ pluginDescriptor.getDescription(),
+ "The plugin.description property should be set to the plugin descriptor description."
+ );
+ }
+
+ @Test
+ public void pluginEnabledFlagShouldBeSetToTrue() throws Exception {
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, getTestPluginURL());
+
+ assertTrue(plugin.isEnabled(), "The plugin.enabled property should be set to true.");
+ }
+
+ @Test
+ public void pluginPathShouldBeSetToPathOfPluginURL() throws Exception {
+ File jarFile = createPluginJARFile();
+
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ URL pluginURL = toURL(jarFile);
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, pluginURL);
+
+ assertEquals(
+ plugin.getPath(),
+ pluginURL.getPath(),
+ "The plugin.path property should be set to the plugin url path."
+ );
+ }
+
+ @Test
+ public void pluginMtimeShouldBeSetToLastModificationTimeOfPluginJarFile() throws Exception {
+ File jarFile = createPluginJARFile();
+
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ URL pluginURL = toURL(jarFile);
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, pluginURL);
+
+ assertEquals(
+ plugin.getMtime(),
+ jarFile.lastModified(),
+ "The plugin.mtime property should be set to the last modification time of the plugin JAR file."
+ );
+ }
+
+ @Test
+ public void pluginHelpShouldBeSetToDescriptorHelp() throws Exception {
+ Help help = new Help();
+ help.getContent().add("help");
+
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setHelp(help);
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, getTestPluginURL());
+
+ assertEquals(
+ plugin.getHelp(),
+ pluginDescriptor.getHelp().getContent().get(0),
+ "The plugin.help property should be set to the plugin descriptor help."
+ );
+ }
+
+ @Test
+ public void pluginMd5ShouldBeSetToMd5OfPluginJarFile() throws Exception {
+ File jarFile = createPluginJARFile();
+
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ URL pluginURL = toURL(jarFile);
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, pluginURL);
+
+ assertEquals(
+ plugin.getMd5(),
+ MessageDigestGenerator.getDigestString(jarFile),
+ "The plugin.md5 property should be set to the MD5 sum of the plugin JAR file."
+ );
+ }
+
+ @Test
+ public void pluginVersionShouldBeSetToPluginDescriptorVersion() throws Exception {
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setVersion("2.1");
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(pluginDescriptor, getTestPluginURL());
+
+ assertEquals(
+ plugin.getVersion(),
+ pluginDescriptor.getVersion(),
+ "The plugin.version property should be set to the plugin descriptor version."
+ );
+ }
+
+ @Test
+ public void pluginVersionShouldBeSetToVersionInPluginJarManifestWhenDescriptorVersionIsNull() throws Exception {
+ File jarFile = createPluginJARFile();
+ URL pluginURL = toURL(jarFile);
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(new PluginDescriptor(), pluginURL);
+
+ assertEquals(
+ plugin.getVersion(),
+ getVersionFromPluginJarManifest(jarFile),
+ "The pliugin.version property should be set to the " + Attributes.Name.IMPLEMENTATION_VERSION +
+ " attribute in the plugin JAR manifest when the plugin descriptor version is null."
+ );
+ }
+
+ @Test(expectedExceptions = {PluginTransformException.class})
+ public void exceptionShouldBeThrownWhenVersionNotFoundInDescriptorOrPluginJarManifest() throws Exception {
+ File jarFile = createPluginJARFileWithoutVersionInManifest();
+ URL pluginURL = toURL(jarFile);
+
+ PluginTransformer transformer = new PluginTransformer();
+
+ Plugin plugin = transformer.toPlugin(new PluginDescriptor(), pluginURL);
+ }
+
+ URL getTestPluginURL() throws Exception {
+ File jarFile = createPluginJARFile();
+ return toURL(jarFile);
+ }
+
+ File createPluginJARFile() throws Exception {
+ URL url = getClass().getResource(".");
+
+ Manifest manifest = new Manifest();
+ Attributes attrs = manifest.getMainAttributes();
+ attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
+ attrs.putValue(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "2.1");
+
+ File jarFile = new File(url.getPath(), "test-plugin.jar");
+ JarOutputStream stream = new JarOutputStream(new FileOutputStream(jarFile), manifest);
+
+ stream.flush();
+ stream.close();
+
+ return jarFile;
+ }
+
+ File createPluginJARFileWithoutVersionInManifest() throws Exception {
+ URL url = getClass().getResource(".");
+
+ Manifest manifest = new Manifest();
+
+ File jarFile = new File(url.getPath(), "test-plugin.jar");
+ JarOutputStream stream = new JarOutputStream(new FileOutputStream(jarFile), manifest);
+
+ stream.flush();
+ stream.close();
+
+ return jarFile;
+ }
+
+ URL toURL(File file) throws Exception {
+ return file.toURI().toURL();
+ }
+
+ String getVersionFromPluginJarManifest(File pluginJarFile) throws Exception {
+ JarFile jarFile = new JarFile(pluginJarFile);
+ Manifest manifest = jarFile.getManifest();
+ Attributes attributes = manifest.getMainAttributes();
+
+ return attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
+ }
+
+}
14 years, 1 month
[rhq] modules/enterprise
by Mike McCune
modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivator.java | 82 ++--------
modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/ApacheXmlRpcExecutor.java | 7
modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/XmlRpcExecutor.java | 10 +
modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivatorTest.java | 73 +++-----
modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java | 12 -
5 files changed, 80 insertions(+), 104 deletions(-)
New commits:
commit 7f5db18b86fe6cb7503e359fd7c1fd94ade455b6
Author: Mike McCune <mmccune(a)gibson.pdx.redhat.com>
Date: Fri Oct 30 13:26:19 2009 -0700
400 - fixing rhnactivator test to not actually touch rhnhosted
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivator.java b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivator.java
index 60a9430..4c7ee1e 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivator.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivator.java
@@ -21,10 +21,8 @@ package org.rhq.enterprise.server.plugins.rhnhosted;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.PrintStream;
import java.net.URL;
import java.security.KeyException;
import java.util.ArrayList;
@@ -32,13 +30,10 @@ import java.util.ArrayList;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.rhq.enterprise.server.plugins.rhnhosted.certificate.PublicKeyRing;
-import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.RhnSSLTransportFactory;
-
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
-
+import org.rhq.enterprise.server.plugins.rhnhosted.certificate.PublicKeyRing;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.XmlRpcExecutor;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.XmlRpcExecutorFactory;
/**
* @author pkilambi
@@ -46,28 +41,25 @@ import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
*/
public class RHNActivator {
- private String certificateFileName;
private String certificateText;
private String systemid;
- private XmlRpcClient client;
+ private XmlRpcExecutor client;
private final Log log = LogFactory.getLog(RHNActivator.class);
/**
- * RHN Connector Constructor
- * @param systemidIn systemId file path
- * @param certificateIn certificate file path
+ * Constructor
+ * @param systemIdString xml systemid
+ * @param certificateTextIn certificate file path
* @param serverUrlIn hosted server url as a string
- *
+ * @throws Exception
*/
- public RHNActivator(String systemidIn, String certificateIn, String serverUrlIn)
- throws Exception {
-
- this.certificateFileName = certificateIn;
- this.certificateText = FileUtils.readFileToString(new File(this.certificateFileName));
+ public RHNActivator(String systemIdString, String certificateTextIn, String serverUrlIn) throws Exception {
+
+ this.certificateText = certificateTextIn;
+ this.systemid = systemIdString;
URL serverUrl = new URL(serverUrlIn);
client = newClient(serverUrl);
- File systemid_file = new File(systemidIn);
- this.systemid = FileUtils.readFileToString(systemid_file);
+
}
/**
@@ -79,24 +71,16 @@ public class RHNActivator {
public RHNActivator(String certificateTextIn, String serverUrlIn) throws Exception {
this.certificateText = certificateTextIn;
- // store the file to local server
- this.writeStringToFile();
URL serverUrl = new URL(serverUrlIn);
client = newClient(serverUrl);
File systemid_file = new File(RHNConstants.DEFAULT_SYSTEM_ID);
this.systemid = FileUtils.readFileToString(systemid_file);
}
- protected XmlRpcClient newClient(URL serverUrl) {
- XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
- config.setServerURL(serverUrl);
- client = new XmlRpcClient();
- client.setConfig(config);
- // Add support for SSL connections to RHN Hosted
- RhnSSLTransportFactory transportFactory = new RhnSSLTransportFactory(client);
- client.setTransportFactory(transportFactory);
- return client;
+ protected XmlRpcExecutor newClient(URL serverUrl) {
+ return XmlRpcExecutorFactory.getClient(serverUrl.toString());
}
+
/**
* Call that invokes the server object and passing in the xmlrpc
* exposed call to activate the rhq server.
@@ -127,32 +111,12 @@ public class RHNActivator {
// this.deleteCertTempFile(this.certificateFileName);
}
- public PublicKeyRing readDefaultKeyRing()
- throws ClassNotFoundException, KeyException, IOException {
+ public PublicKeyRing readDefaultKeyRing() throws ClassNotFoundException, KeyException, IOException {
InputStream keyringStream = new FileInputStream(RHNConstants.DEFAULT_WEBAPP_GPG_KEY_RING);
return new PublicKeyRing(keyringStream);
}
/**
- * Stores the certificate text string as a file on the filesystem
- *
- */
- protected void writeStringToFile() throws Exception {
- String tmpDir = System.getProperty("java.io.tmpdir");
-
- this.certificateFileName = tmpDir + "/rhn-entitlement-cert" + ".cert";
-
- FileOutputStream out = new FileOutputStream(this.certificateFileName);
- PrintStream printer = new PrintStream(out);
- try {
- printer.println(this.certificateText);
- }
- finally {
- printer.close();
- }
- }
-
- /**
* Delete the certificate file from the filesystem.
* @param fileName certificate filename
* @return boolean returns delete operation status
@@ -163,22 +127,22 @@ public class RHNActivator {
return f.delete();
}
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
// commandline test
if (args.length > 0) {
- String systemid = args[0];
- String cert = args[1];
+ String systemId = FileUtils.readFileToString(new File(args[0]));
+ String cert = FileUtils.readFileToString(new File(args[1]));
+
String serverUrl = "http://satellite.rhn.redhat.com/rpc/api";
try {
- RHNActivator rhqServer = new RHNActivator(systemid, cert, serverUrl);
+ RHNActivator rhqServer = new RHNActivator(systemId, cert, serverUrl);
rhqServer.processActivation();
System.out.println("Activation Complete");
rhqServer.processDeActivation();
System.out.println("De-Activation Complete");
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
}
}
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/ApacheXmlRpcExecutor.java b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/ApacheXmlRpcExecutor.java
index eee13b6..f3c75e2 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/ApacheXmlRpcExecutor.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/ApacheXmlRpcExecutor.java
@@ -19,6 +19,8 @@
package org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc;
+import java.util.List;
+
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
@@ -35,4 +37,9 @@ public class ApacheXmlRpcExecutor implements XmlRpcExecutor {
return client.execute(methodName, params);
}
+ @Override
+ public Object execute(String pMethodName, List pParams) throws XmlRpcException {
+ return client.execute(pMethodName, pParams);
+ }
+
}
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/XmlRpcExecutor.java b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/XmlRpcExecutor.java
index d84b402..721b350 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/XmlRpcExecutor.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/XmlRpcExecutor.java
@@ -19,6 +19,8 @@
package org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc;
+import java.util.List;
+
import org.apache.xmlrpc.XmlRpcException;
public interface XmlRpcExecutor {
@@ -31,4 +33,12 @@ public interface XmlRpcExecutor {
*/
public Object execute(String methodName, Object[] params) throws XmlRpcException;
+ /** Performs a request with the clients default configuration.
+ * @param pMethodName The method being performed.
+ * @param pParams The parameters.
+ * @return The result object.
+ * @throws XmlRpcException Performing the request failed.
+ */
+ public Object execute(String pMethodName, List pParams) throws XmlRpcException;
+
}
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivatorTest.java b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivatorTest.java
index aa62ca2..13c56cc 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivatorTest.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/RHNActivatorTest.java
@@ -21,39 +21,36 @@ package org.rhq.enterprise.server.plugins.rhnhosted;
import junit.framework.TestCase;
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringUtils;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.ApacheXmlRpcExecutor;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.MockRhnHttpURLConnection;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.MockRhnXmlRpcExecutor;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.RhnCommTest;
+import org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.RhnHttpURLConnectionFactory;
public class RHNActivatorTest extends TestCase {
- private static final String TEST_CERT_PATH = "./entitlement-cert.xml";
private static final String TEST_SERVER_URL = "http://satellite.rhn.redhat.com/rpc/api";
private static final String TEST_SYSTEM_ID = RHNConstants.DEFAULT_SYSTEM_ID;
private RHNActivator rhnObject;
public void setUp() throws Exception {
- rhnObject = new RHNActivator(TEST_SYSTEM_ID, TEST_CERT_PATH, TEST_SERVER_URL);
+ /* OVERRIDE THE XMLRPC CLIENT WITH A MOCK OBJECT */
+ System.setProperty(ApacheXmlRpcExecutor.class.getName(), MockRhnXmlRpcExecutor.class.getName());
+ System.setProperty(RhnHttpURLConnectionFactory.RHN_MOCK_HTTP_URL_CONNECTION, MockRhnHttpURLConnection.class
+ .getName());
+
+ rhnObject = new RHNActivator(RhnCommTest.SYSTEM_ID, ENT_CERT, TEST_SERVER_URL);
+
assertNotNull(rhnObject);
- }
+ }
public final void testActivate() throws Exception {
- String systemid = readSystemId();
- String cert = readCertificate();
- System.out.println("systemid and cert are:" + systemid + cert);
- if (StringUtils.isBlank(systemid) || StringUtils.isBlank(cert)) {
- System.out.println("Skipping test since systemid or cert is not readable");
- return;
- }
boolean success = true;
try {
rhnObject.processActivation();
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
success = false;
}
@@ -61,38 +58,32 @@ public class RHNActivatorTest extends TestCase {
}
public final void testDeActivate() throws Exception {
- String systemid = readSystemId();
- String cert = readCertificate();
- if (StringUtils.isBlank(systemid) || StringUtils.isBlank(cert)) {
- System.out.println("Skipping test since systemid or cert is not readable");
- return;
- }
+ String systemid = RhnCommTest.SYSTEM_ID;
boolean success = true;
try {
rhnObject.processDeActivation();
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
success = false;
}
assertEquals(true, success);
}
- protected String readSystemId() throws Exception {
- try {
- return FileUtils.readFileToString(new File(TEST_SYSTEM_ID));
- } catch (IOException e) {
- return "";
- }
- }
-
- protected String readCertificate() throws Exception {
- try {
- return FileUtils.readFileToString(new File(TEST_CERT_PATH));
- } catch (IOException e) {
- return "";
- }
-
- }
+ private static String ENT_CERT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<rhn-cert version=\"0.1\">"
+ + " <rhn-cert-field name=\"product\">RHN-SATELLITE-001</rhn-cert-field>"
+ + " <rhn-cert-field name=\"owner\">Test Lab - Base Organization</rhn-cert-field>"
+ + " <rhn-cert-field name=\"issued\">2009-08-17 00:00:00</rhn-cert-field>"
+ + " <rhn-cert-field name=\"expires\">2010-08-17 00:00:00</rhn-cert-field>"
+ + " <rhn-cert-field name=\"slots\">10</rhn-cert-field>"
+ + " <rhn-cert-field name=\"monitoring-slots\">10</rhn-cert-field>"
+ + " <rhn-cert-field name=\"provisioning-slots\">10</rhn-cert-field>"
+ + " <rhn-cert-field name=\"virtualization_host\">10</rhn-cert-field>"
+ + " <rhn-cert-field name=\"virtualization_host_platform\">10</rhn-cert-field>"
+ + " <rhn-cert-field name=\"channel-families\" quantity=\"10\" family=\"rhel-server\"/>"
+ + " <rhn-cert-field name=\"channel-families\" quantity=\"10\" family=\"rhel-server-vt\"/>"
+ + " <rhn-cert-field name=\"channel-families\" quantity=\"10\" family=\"rhn-tools\"/>"
+ + " <rhn-cert-field name=\"satellite-version\">5.3</rhn-cert-field>"
+ + " <rhn-cert-field name=\"generation\">2</rhn-cert-field>" + " <rhn-cert-signature>"
+ + "-----BEGIN PGP SIGNATURE-----" + "-----END PGP SIGNATURE-----" + "</rhn-cert-signature>" + "</rhn-cert>";
}
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
index 80bc290..5cc7d5e 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/xmlrpc/MockRhnXmlRpcExecutor.java
@@ -34,15 +34,14 @@ import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
-
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelFamiliesType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelFamilyType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnChannelsType;
-import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreeType;
-import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreesType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartFileType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartFilesType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreeType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnKickstartableTreesType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageShortType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackagesShortType;
@@ -129,7 +128,7 @@ public class MockRhnXmlRpcExecutor implements XmlRpcExecutor {
JAXBElement element = getRhnSatelliteType();
RhnSatelliteType retval = (RhnSatelliteType) element.getValue();
RhnKickstartableTreesType parentKSTree = new RhnKickstartableTreesType();
- List<RhnKickstartableTreeType> ksTreeList = parentKSTree.getRhnKickstartableTree();
+ List<RhnKickstartableTreeType> ksTreeList = parentKSTree.getRhnKickstartableTree();
List<String> kstids = (List<String>) params[1];
for (String kid : kstids) {
RhnKickstartableTreeType kstype = new RhnKickstartableTreeType();
@@ -242,4 +241,9 @@ public class MockRhnXmlRpcExecutor implements XmlRpcExecutor {
}
}
+
+ @Override
+ public Object execute(String pMethodName, List pParams) throws XmlRpcException {
+ return execute(pMethodName, pParams.toArray());
+ }
}
14 years, 1 month