[rhq] Branch 'feature/hadoop-plugin' - modules/plugins

Jiri Kremser jkremser at fedoraproject.org
Wed Aug 1 10:20:24 UTC 2012


 modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopOperationsDelegate.java  |   64 ++++++++++
 modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopServiceComponent.java    |   19 +-
 modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopSupportedOperations.java |   29 ++++
 modules/plugins/hadoop/src/main/resources/META-INF/rhq-plugin.xml                          |    2 
 4 files changed, 107 insertions(+), 7 deletions(-)

New commits:
commit 0c3a66c7315e101ea2f423160173bf0166dc5372
Author: Jirka Kremser <jkremser at redhat.com>
Date:   Wed Aug 1 12:19:42 2012 +0200

    Adding the class infrastructure for performing the operations

diff --git a/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopOperationsDelegate.java b/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopOperationsDelegate.java
new file mode 100644
index 0000000..4d97eeb
--- /dev/null
+++ b/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopOperationsDelegate.java
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.rhq.core.pluginapi.operation.OperationResult;
+
+/**
+ * Handles performing operations on Hadoop node instance.
+ * 
+ * @author Jirka Kremser
+ */
+public class HadoopOperationsDelegate {
+
+    private ResourceContext<HadoopServiceComponent> resourceContext;
+
+    public HadoopOperationsDelegate(ResourceContext<HadoopServiceComponent> resourceContext) {
+        this.resourceContext = resourceContext;
+    }
+
+    public OperationResult invoke(HadoopSupportedOperations operation, Configuration parameters)
+        throws InterruptedException {
+
+        String message = null;
+        switch (operation) {
+        case FORMAT:
+            message = format();
+            break;
+        default:
+            throw new UnsupportedOperationException(operation.toString());
+        }
+        OperationResult result = new OperationResult(message);
+        return result;
+    }
+
+    /**
+     * Format a new distributed filesystem
+     * by running $bin/hadoop namenode -format
+     * 
+     * @return message
+     */
+    private String format() {
+        String hadoopHome = resourceContext.getPluginConfiguration()
+            .getSimple(HadoopServiceDiscovery.HOME_DIR_PROPERTY).getStringValue();
+        return null;
+    }
+}
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 02f7a22..1bf2e1c 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
@@ -50,6 +50,7 @@ import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
 import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
 import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
 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.OperationFacet;
 import org.rhq.core.pluginapi.operation.OperationResult;
@@ -66,6 +67,8 @@ public class HadoopServiceComponent extends JMXServerComponent<ResourceComponent
     private static final String PROPERTY_TAG_NAME = "property";
     private static final String NAME_TAG_NAME = "name";
     private static final String VALUE_TAG_NAME = "value";
+    
+    private HadoopOperationsDelegate operationsDelegate;
 
     /**
      * Return availability of this resource
@@ -86,6 +89,13 @@ public class HadoopServiceComponent extends JMXServerComponent<ResourceComponent
 
     }
 
+    @Override
+    public void start(ResourceContext context) throws Exception {
+        super.start(context);
+        this.operationsDelegate = new HadoopOperationsDelegate(context);
+    }
+    
+    
     /**
      * Gather measurement data
      *  @see org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport, java.util.Set)
@@ -163,13 +173,8 @@ public class HadoopServiceComponent extends JMXServerComponent<ResourceComponent
      * @see org.rhq.core.pluginapi.operation.OperationFacet
      */
     public OperationResult invokeOperation(String name, Configuration params) throws Exception {
-
-        OperationResult res = new OperationResult();
-        if ("dummyOperation".equals(name)) {
-            // TODO implement me
-
-        }
-        return res;
+        HadoopSupportedOperations operation = HadoopSupportedOperations.valueOf(name); 
+        return operationsDelegate.invoke(operation, params);
     }
 
     public static void fillResourceConfiguration(File homeDir, Configuration config, ConfigurationDefinition definition)
diff --git a/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopSupportedOperations.java b/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopSupportedOperations.java
new file mode 100644
index 0000000..90572d8
--- /dev/null
+++ b/modules/plugins/hadoop/src/main/java/org/rhq/plugins/hadoop/HadoopSupportedOperations.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+/**
+ * Supported operations for Hadoop plugin
+ * 
+ * @author Jirka Kremser
+ */
+public enum HadoopSupportedOperations {
+    FORMAT
+
+}
diff --git a/modules/plugins/hadoop/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/hadoop/src/main/resources/META-INF/rhq-plugin.xml
index 91f829a..2f07b20 100644
--- a/modules/plugins/hadoop/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/hadoop/src/main/resources/META-INF/rhq-plugin.xml
@@ -13,6 +13,8 @@
     </plugin-configuration>
 
     <process-scan name="NameNode" query="process|basename|match=^java.*,arg|-Dproc_namenode|match=.*"/>
+    
+    <operation name="format" displayName="Format dfs" description="Format a new distributed-filesystem."/>
 
     <metric property="Hadoop:service=NameNode,name=NameNodeInfo:NameDirStatuses" displayName="NameNode Storage"
       dataType="trait" displayType="summary"/>




More information about the rhq-commits mailing list