summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJirka Kremser <jkremser@redhat.com>2014-02-25 17:39:38 (GMT)
committerJirka Kremser <jkremser@redhat.com>2014-02-25 17:39:49 (GMT)
commit57fdc211b633b7cea15485cc11cbd79b7a207cf6 (patch)
tree6d291c2cf57a2a04b36df3ef856dca78cd6b9703
parent0afa8ff370f19421e1ee04bf867a779e823d46b8 (diff)
downloadrhq-57fdc211b.zip
rhq-57fdc211b.tar.gz
rhq-57fdc211b.tar.xz
[BZ 536287] - (RHQ-653) Agent "Get Info On All Plugins" operation does not return the short name of a plugin (and is inconsistent with the agent prompt) - Returning also the display name and the short name of plugin for both the retrieveAllPluginInfo and the retrievePluginInfo agent operations. Now it is more consistent with the prompt command for agent (plugins info) and the short plugin name can be used elsewhere.
-rw-r--r--modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentManagement.java103
-rw-r--r--modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentManagementMBean.java5
-rw-r--r--modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml8
3 files changed, 74 insertions, 42 deletions
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentManagement.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentManagement.java
index 249cb51..11eb3e3 100644
--- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentManagement.java
+++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentManagement.java
@@ -22,6 +22,7 @@ import java.io.CharArrayWriter;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
+import java.net.URL;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
@@ -36,6 +37,9 @@ import javax.management.MBeanServer;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
+import org.rhq.core.clientapi.agent.metadata.PluginMetadataManager;
+import org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil;
+import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
import org.rhq.core.clientapi.server.core.CoreServerService;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertyList;
@@ -158,38 +162,49 @@ public class AgentManagement implements AgentManagementMBean, MBeanRegistration
public OperationResult retrieveAllPluginInfo() {
List<File> plugins;
-
+ OperationResult info = new OperationResult();
ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
PluginUpdate updater = getPluginUpdateObject();
plugins = updater.getCurrentPluginFiles();
- } finally {
- Thread.currentThread().setContextClassLoader(originalCL);
- }
- OperationResult info = new OperationResult();
- PropertyList list = new PropertyList("plugins");
- info.getComplexResults().put(list);
+ PropertyList list = new PropertyList("plugins".intern());
+ info.getComplexResults().put(list);
+
+ if (plugins.size() > 0) {
+ for (File plugin : plugins) {
+ String pluginName;
+ String pluginDisplayName;
+ try {
+ URL url = plugin.toURI().toURL();
+ PluginDescriptor descriptor = AgentPluginDescriptorUtil.loadPluginDescriptorFromUrl(url);
+ pluginName = descriptor.getName();
+ pluginDisplayName = descriptor.getDisplayName();
+ } catch (Exception t) {
+ pluginName = "?cannot-parse-descriptor?".intern();
+ pluginDisplayName = "?cannot-parse-descriptor?".intern();
+ }
- if (plugins.size() > 0) {
- for (File plugin : plugins) {
- PropertyMap map = new PropertyMap("plugin");
- map.put(new PropertySimple(PLUGIN_INFO_NAME, plugin.getName()));
- map.put(new PropertySimple(PLUGIN_INFO_PATH, plugin.getAbsoluteFile()));
- map.put(new PropertySimple(PLUGIN_INFO_TIMESTAMP, new Date(plugin.lastModified())));
- map.put(new PropertySimple(PLUGIN_INFO_SIZE, plugin.length()));
+ PropertyMap map = new PropertyMap("plugin".intern());
+ map.put(new PropertySimple(PLUGIN_INFO_NAME, pluginName));
+ map.put(new PropertySimple(PLUGIN_INFO_DISPLAY_NAME, pluginDisplayName));
+ map.put(new PropertySimple(PLUGIN_INFO_PATH, plugin.getAbsoluteFile()));
+ map.put(new PropertySimple(PLUGIN_INFO_TIMESTAMP, new Date(plugin.lastModified())));
+ map.put(new PropertySimple(PLUGIN_INFO_SIZE, plugin.length()));
- try {
- map.put(new PropertySimple(PLUGIN_INFO_MD5, MessageDigestGenerator.getDigestString(plugin)));
- } catch (IOException e) {
- map.put(new PropertySimple(PLUGIN_INFO_MD5, e.toString()));
- }
+ try {
+ map.put(new PropertySimple(PLUGIN_INFO_MD5, MessageDigestGenerator.getDigestString(plugin)));
+ } catch (IOException e) {
+ map.put(new PropertySimple(PLUGIN_INFO_MD5, e.toString()));
+ }
- list.add(map);
+ list.add(map);
+ }
}
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalCL);
}
-
return info;
}
@@ -201,31 +216,41 @@ public class AgentManagement implements AgentManagementMBean, MBeanRegistration
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
PluginUpdate updater = getPluginUpdateObject();
plugins = updater.getCurrentPluginFiles();
- } finally {
- Thread.currentThread().setContextClassLoader(originalCL);
- }
-
- if (plugins.size() > 0) {
- for (File plugin : plugins) {
- if (plugin.getName().equals(pluginName)) {
- OperationResult opResults = new OperationResult();
- Configuration info = opResults.getComplexResults();
- info.put(new PropertySimple(PLUGIN_INFO_NAME, plugin.getName()));
- info.put(new PropertySimple(PLUGIN_INFO_PATH, plugin.getAbsoluteFile()));
- info.put(new PropertySimple(PLUGIN_INFO_TIMESTAMP, new Date(plugin.lastModified())));
- info.put(new PropertySimple(PLUGIN_INFO_SIZE, plugin.length()));
+ if (plugins.size() > 0) {
+ for (File plugin : plugins) {
+ String pluginDisplayName;
+ String pluginNameToReturn;
try {
- info.put(new PropertySimple(PLUGIN_INFO_MD5, MessageDigestGenerator.getDigestString(plugin)));
- } catch (IOException e) {
- info.put(new PropertySimple(PLUGIN_INFO_MD5, e.toString()));
+ URL url = plugin.toURI().toURL();
+ PluginDescriptor pluginDescriptor = AgentPluginDescriptorUtil.loadPluginDescriptorFromUrl(url);
+ pluginDisplayName = pluginDescriptor.getDisplayName();
+ pluginNameToReturn = pluginDescriptor.getName();
+ } catch (Exception t) {
+ continue;
}
- return opResults;
+ if (pluginNameToReturn.toLowerCase().equals(pluginName.toLowerCase())) {
+ OperationResult opResults = new OperationResult();
+ Configuration info = opResults.getComplexResults();
+ info.put(new PropertySimple(PLUGIN_INFO_NAME, pluginNameToReturn));
+ info.put(new PropertySimple(PLUGIN_INFO_DISPLAY_NAME, pluginDisplayName));
+ info.put(new PropertySimple(PLUGIN_INFO_PATH, plugin.getAbsoluteFile()));
+ info.put(new PropertySimple(PLUGIN_INFO_TIMESTAMP, new Date(plugin.lastModified())));
+ info.put(new PropertySimple(PLUGIN_INFO_SIZE, plugin.length()));
+ try {
+ info.put(new PropertySimple(PLUGIN_INFO_MD5, MessageDigestGenerator.getDigestString(plugin)));
+ } catch (IOException e) {
+ info.put(new PropertySimple(PLUGIN_INFO_MD5, e.toString()));
+ }
+
+ return opResults;
+ }
}
}
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalCL);
}
-
throw new IllegalArgumentException("There is no plugin named [" + pluginName + "]");
}
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentManagementMBean.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentManagementMBean.java
index 1be62dc..9ba53b4 100644
--- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentManagementMBean.java
+++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentManagementMBean.java
@@ -61,6 +61,11 @@ public interface AgentManagementMBean {
* Identifies the name of a plugin.
*/
String PLUGIN_INFO_NAME = "name";
+
+ /**
+ * Identifies the display name of a plugin.
+ */
+ String PLUGIN_INFO_DISPLAY_NAME = "displayName";
/**
* Identifies the full path to a plugin.
diff --git a/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml
index c9820cf..b8ca439 100644
--- a/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml
@@ -93,7 +93,8 @@
<results>
<c:list-property name="plugins">
<c:map-property name="plugin">
- <c:simple-property name="name" description="Name of the plugin" />
+ <c:simple-property name="name" description="Short name of the plugin" />
+ <c:simple-property name="displayName" description="Full name of the plugin" />
<c:simple-property name="path" description="Full path to the plugin as seen by the agent" />
<c:simple-property name="timestamp" description="Last time the plugin was updated" />
<c:simple-property name="size" description="Size of the plugin file" />
@@ -110,7 +111,8 @@
<c:simple-property name="pluginName" description="The name of the plugin whose info is to be retrieved"/>
</parameters>
<results>
- <c:simple-property name="name" description="Name of the plugin" />
+ <c:simple-property name="name" description="Short name of the plugin" />
+ <c:simple-property name="displayName" description="Full name of the plugin" />
<c:simple-property name="path" description="Full path to the plugin as seen by the agent" />
<c:simple-property name="timestamp" description="Last time the plugin was updated" />
<c:simple-property name="size" description="Size of the plugin file" />
@@ -836,4 +838,4 @@
</service>
</server>
-</plugin> \ No newline at end of file
+</plugin>