modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopComponent.java |
45 ---
modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopDiscovery.java |
64 -----
modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceComponent.java |
124 +++-------
modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceDiscovery.java |
2
4 files changed, 50 insertions(+), 185 deletions(-)
New commits:
commit 89da8bf8ba91b32db9701cb0a6d7831d58d31516
Merge: 1733c4d 527bc2a
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Jul 31 15:38:07 2012 +0200
more formatting and code cleanup before we do anything serious.
diff --cc
modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopComponent.java
index 848d560,848d560..0000000
deleted file mode 100644,100644
--- a/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopComponent.java
+++ /dev/null
diff --cc
modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopDiscovery.java
index de8613a,de8613a..0000000
deleted file mode 100644,100644
--- a/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopDiscovery.java
+++ /dev/null
commit 527bc2ae7a0a42af1a0ca2819b570c4333b5cabf
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Tue Jul 31 15:32:21 2012 +0200
formatting and general cleanup before we start doing anything serious.
diff --git
a/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceComponent.java
b/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceComponent.java
index c0f060f..5cb3806 100644
---
a/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceComponent.java
+++
b/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceComponent.java
@@ -1,3 +1,21 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
package org.rhq.plugins.hadoop;
@@ -10,68 +28,37 @@ import org.mc4j.ems.connection.bean.EmsBean;
import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.MeasurementDataNumeric;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
-import org.rhq.core.pluginapi.inventory.ResourceContext;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
-import org.rhq.core.pluginapi.operation.OperationContext;
import org.rhq.core.pluginapi.operation.OperationFacet;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.plugins.jmx.JMXComponent;
import org.rhq.plugins.jmx.JMXServerComponent;
-public class HadoopServiceComponent extends JMXServerComponent implements JMXComponent,
ResourceComponent
-, MeasurementFacet
-, OperationFacet
-{
- private final Log log = LogFactory.getLog(this.getClass());
-
- private ResourceContext context;
-
-
-
+public class HadoopServiceComponent extends
JMXServerComponent<ResourceComponent<?>> implements
+ JMXComponent<ResourceComponent<?>>, MeasurementFacet, OperationFacet {
+
+ private static final Log LOG = LogFactory.getLog(HadoopServiceComponent.class);
/**
* Return availability of this resource
* @see org.rhq.core.pluginapi.inventory.ResourceComponent#getAvailability()
*/
+ @Override
public AvailabilityType getAvailability() {
- return AvailabilityType.UP; // Return UP until we know why context has no process
info TODO
- //return context.getNativeProcess().isRunning() ? AvailabilityType.UP:
AvailabilityType.DOWN;
- }
-
-
- /**
- * Start the resource connection
- * @see
org.rhq.core.pluginapi.inventory.ResourceComponent#start(org.rhq.core.pluginapi.inventory.ResourceContext)
- */
- public void start(ResourceContext context) throws
InvalidPluginConfigurationException, Exception {
-
- Configuration conf = context.getPluginConfiguration();
- this.context = context;
- super.start(context);
- log.info("Started " + context.getResourceKey());
-
- }
-
-
- /**
- * Tear down the resource connection
- * @see org.rhq.core.pluginapi.inventory.ResourceComponent#stop()
- */
- public void stop() {
- super.stop();
-
+ return getResourceContext().getNativeProcess().isRunning() ? AvailabilityType.UP:
AvailabilityType.DOWN;
}
@Override
public EmsConnection getEmsConnection() {
- EmsConnection conn = super.getEmsConnection(); // TODO: Customise this
generated block
- log.info("EmsConnection is " + conn.toString());
+ EmsConnection conn = super.getEmsConnection(); // TODO: Customise this generated
block
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("EmsConnection is " + conn.toString());
+ }
return conn;
}
@@ -80,38 +67,29 @@ public class HadoopServiceComponent extends JMXServerComponent
implements JMXCom
* Gather measurement data
* @see
org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport,
java.util.Set)
*/
- public void getValues(MeasurementReport report,
Set<MeasurementScheduleRequest> metrics) throws Exception {
-
- for (MeasurementScheduleRequest req : metrics) {
- String property=req.getName();
- String props[] = property.split("\\|");
-
- EmsConnection conn = getEmsConnection();
- EmsBean bean = conn.getBean(props[0]);
- if (bean != null) {
- bean.refreshAttributes();
- EmsAttribute att = bean.getAttribute(props[1]);
- if (att!=null) {
- Long val = (Long) att.getValue(); // TODO check for real type
-
- MeasurementDataNumeric res = new MeasurementDataNumeric(req,
Double.valueOf(val));
- report.addData(res);
- }
- else
- log.warn("Attribute " + props[1] + " not
found");
- }
- else
- log.warn("MBean " + props[0] +" not found");
- }
- }
-
-
-
- public void startOperationFacet(OperationContext context) {
-
+ public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest>
metrics) throws Exception {
+
+ for (MeasurementScheduleRequest req : metrics) {
+ String property = req.getName();
+ String props[] = property.split("\\|");
+
+ EmsConnection conn = getEmsConnection();
+ EmsBean bean = conn.getBean(props[0]);
+ if (bean != null) {
+ bean.refreshAttributes();
+ EmsAttribute att = bean.getAttribute(props[1]);
+ if (att != null) {
+ Long val = (Long) att.getValue(); // TODO check for real type
+
+ MeasurementDataNumeric res = new MeasurementDataNumeric(req,
Double.valueOf(val));
+ report.addData(res);
+ } else
+ LOG.warn("Attribute " + props[1] + " not
found");
+ } else
+ LOG.warn("MBean " + props[0] + " not found");
+ }
}
-
/**
* Invokes the passed operation on the managed resource
* @param name Name of the operation
@@ -129,8 +107,4 @@ public class HadoopServiceComponent extends JMXServerComponent
implements JMXCom
return res;
}
-
-
-
-
}
diff --git
a/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceDiscovery.java
b/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceDiscovery.java
index 41db515..f010976 100644
---
a/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceDiscovery.java
+++
b/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceDiscovery.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
+ * Copyright (C) 2005-2012 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -44,6 +44,7 @@ import org.rhq.plugins.jmx.JMXDiscoveryComponent;
/**
* Discover individual hadoop processes
* @author Heiko W. Rupp
+ * @author Lukas Krejci
*/
public class HadoopServiceDiscovery implements
ResourceDiscoveryComponent<ResourceComponent<?>> {
@@ -51,36 +52,33 @@ public class HadoopServiceDiscovery implements
ResourceDiscoveryComponent<Resour
private static final String HADOOP_VERSION_MATCH =
"hadoop-core-([0-9\\.]+)\\.jar";
private static final Pattern HADOOP_VERSION_PATTERN =
Pattern.compile(HADOOP_VERSION_MATCH);
private static final String MAIN_CLASS_PROPERTY = "_mainClass";
-
+
public Set<DiscoveredResourceDetails> discoverResources(
- ResourceDiscoveryContext<ResourceComponent<?>>
resourceDiscoveryContext) throws InvalidPluginConfigurationException, Exception {
+ ResourceDiscoveryContext<ResourceComponent<?>>
resourceDiscoveryContext)
+ throws InvalidPluginConfigurationException, Exception {
Set<DiscoveredResourceDetails> details = new
HashSet<DiscoveredResourceDetails>();
- List<ProcessScanResult> parentProcessScans =
resourceDiscoveryContext.getAutoDiscoveredProcesses();
+ List<ProcessScanResult> processScans =
resourceDiscoveryContext.getAutoDiscoveredProcesses();
ResourceType resourceType = resourceDiscoveryContext.getResourceType();
String rtName = resourceType.getName();
- for (ProcessScanResult psr : parentProcessScans) {
-
+ for (ProcessScanResult psr : processScans) {
if (psr.getProcessScan().getName().equals(rtName)) {
String cwd = psr.getProcessInfo().getCurrentWorkingDirectory();
-
+
String version = getVersion(cwd);
Configuration pluginConfiguration =
resourceDiscoveryContext.getDefaultPluginConfiguration();
- DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
- resourceType, // ResourceType
- rtName+":"+cwd, // ResourceKey
- rtName, // resource name
- version, // Version
- "Hadoop " + rtName + " ( "+ cwd +"
)", // description
- pluginConfiguration,
- psr.getProcessInfo() // process info
- );
-
+ DiscoveredResourceDetails detail = new
DiscoveredResourceDetails(resourceType, // ResourceType
+ rtName + ":" + cwd, // ResourceKey
+ rtName, // resource name
+ version, // Version
+ "Hadoop " + rtName + " ( " + cwd + "
)", // description
+ pluginConfiguration, psr.getProcessInfo() // process info
+ );
/*
* We'll connect to the discovered VM on the local host, so set the
jmx connection
@@ -88,12 +86,12 @@ public class HadoopServiceDiscovery implements
ResourceDiscoveryComponent<Resour
* anyway.
*/
pluginConfiguration.put(new
PropertySimple(JMXDiscoveryComponent.COMMAND_LINE_CONFIG_PROPERTY,
- pluginConfiguration.getSimpleValue(MAIN_CLASS_PROPERTY, null)));
+ pluginConfiguration.getSimpleValue(MAIN_CLASS_PROPERTY, null)));
pluginConfiguration.put(new
PropertySimple(JMXDiscoveryComponent.CONNECTION_TYPE,
LocalVMTypeDescriptor.class.getName()));
log.debug("Discovered " + detail);
-
+
details.add(detail);
}
}
@@ -109,9 +107,9 @@ public class HadoopServiceDiscovery implements
ResourceDiscoveryComponent<Resour
*/
private String getVersion(String hadoopHomeDir) {
- File homeDir =new File(hadoopHomeDir);
+ File homeDir = new File(hadoopHomeDir);
if (homeDir.isDirectory() && homeDir.canRead()) {
- String[] foundCoreJars = homeDir.list(new FilenameFilter() {
+ String[] foundCoreJars = homeDir.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return HADOOP_VERSION_PATTERN.matcher(name).matches();
}
@@ -120,7 +118,7 @@ public class HadoopServiceDiscovery implements
ResourceDiscoveryComponent<Resour
if (foundCoreJars == null || foundCoreJars.length == 0) {
return null;
}
-
+
Matcher matcher = HADOOP_VERSION_PATTERN.matcher(foundCoreJars[0]);
if (matcher.matches()) {
return matcher.group(1);
@@ -132,5 +130,4 @@ public class HadoopServiceDiscovery implements
ResourceDiscoveryComponent<Resour
}
}
-
}