This post shows how you can easily achieve the very same in your plugin.
Basically you need to do four things:
- Have your plugin use the jmx-plugin:
 <plugin name="hadoop"
 displayName="hadoopPlugin"
 <depends plugin="JMX" useClasses="true"/>
- In the Discovery Class (could also be done in ResourceComponent.start()at the very beginning), you put some additional plugin properties:
 public Set<DiscoveredResourceDetails> discoverResources(
 ResourceDiscoveryContext context)
 throws Exception
 {
 Configuration pluginConfiguration = context.getDefaultPluginConfiguration();
 pluginConfiguration.put(new PropertySimple(
 JMXDiscoveryComponent.COMMAND_LINE_CONFIG_PROPERTY,
 javaClazz));
 pluginConfiguration.put(new PropertySimple(
 JMXDiscoveryComponent.CONNECTION_TYPE,
 LocalVMTypeDescriptor.class.getName()));
 ...
 The javaClazz is the fully qualified name of the main class as it would
 appear withjps -l:
 $ jps -l
 3299 org.apache.hadoop.mapred.TaskTracker
 12311
 3177 org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode
 3037 org.apache.hadoop.hdfs.server.namenode.NameNode
 (the output is vmid and class, where the vmid is usually the process id)
- Have your component class extend JMXComponentpublic class HadoopServiceComponent extends JMXServerComponent, ...
 In component.start() call the JMXServerComponent
 public void start(ResourceContext context) throws Exception
 {
 super.start(context);
 ...
 }
From there on, you can get the JMX connection by a simple
EmsConnection conn = getEmsConnection();
and so on ...
 
No comments:
Post a Comment