incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r1182498 - in /incubator/ambari/trunk: ./ client/src/main/java/org/apache/ambari/common/rest/entities/ controller/src/main/java/org/apache/ambari/components/ controller/src/main/java/org/apache/ambari/components/impl/ controller/src/main/ja...
Date Wed, 12 Oct 2011 18:04:58 GMT
Author: omalley
Date: Wed Oct 12 18:04:58 2011
New Revision: 1182498

URL: http://svn.apache.org/viewvc?rev=1182498&view=rev
Log:
AMBARI-64. Define components in terms of XML. (omalley)

Added:
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/impl/XmlComponentDefinition.java
    incubator/ambari/trunk/controller/src/main/resources/org/
    incubator/ambari/trunk/controller/src/main/resources/org/apache/
    incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/
    incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/
    incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/hadoop-common-0.1.0.acd
    incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/hadoop-hdfs-0.1.0.acd
    incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/components/
    incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/components/impl/
    incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/components/impl/jaxb.index
Removed:
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/ClusterContext.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/Installer.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/impl/ClusterContextImpl.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/impl/HDFSPluginImpl.java
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ComponentDefinition.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/ComponentPlugin.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceImpl.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1182498&r1=1182497&r2=1182498&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Oct 12 18:04:58 2011
@@ -2,27 +2,33 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-64. Define components in terms of XML. (omalley)
+
   AMBARI-63. Implement cluster update, rename and delete CLI commands (vgogte)
 
   AMBARI-62. Adds the install/uninstall checks in the heartbeat handler (ddas)
 
-  AMBARI-60. Added permission check for RUN_ACTION, and WRITE_FILE_ACTION. (Eric Yang)
+  AMBARI-60. Added permission check for RUN_ACTION, and
+  WRITE_FILE_ACTION.  (Eric Yang)
 
   AMBARI-61. Rename cluster REST API. (vgogate)
 
   AMBARI-59. Refactor to use clusterRevision instead of bluePrintName and 
   bluePrintRevision. (Eric Yang)
 
-  AMBARI-57. Adds a state for monitoring safe-mode success/failure checks in the
-  ServiceFSM (ddas)
+  AMBARI-57. Adds a state for monitoring safe-mode success/failure
+  checks in the ServiceFSM (ddas)
 
-  AMBARI-56. Refactor write config file command to write config file action. (Eric Yang)
+  AMBARI-56. Refactor write config file command to write config file
+  action. (Eric Yang)
 
   AMBARI-54. Refactor agent implementation to match AMBARI-53. (Eric Yang)
 
-  AMBARI-51. Refactor transport data model for commands to become action. (Eric Yang)
+  AMBARI-51. Refactor transport data model for commands to become
+  action. (Eric Yang)
 
-  AMBARI-56. Surface the write config file command to write config file action. (Eric Yang)
+  AMBARI-56. Surface the write config file command to write config
+  file action. (Eric Yang)
 
   AMBARI-55. release cluster nodes function (vgogate)
 

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ComponentDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ComponentDefinition.java?rev=1182498&r1=1182497&r2=1182498&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ComponentDefinition.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ComponentDefinition.java
Wed Oct 12 18:04:58 2011
@@ -83,4 +83,14 @@ public class ComponentDefinition {
   public void setVersion(String version) {
     this.version = version;
   }
+  
+  public String toString() {
+    StringBuilder buffer = new StringBuilder();
+    buffer.append(group);
+    buffer.append('.');
+    buffer.append(definition);
+    buffer.append('@');
+    buffer.append(version);
+    return buffer.toString();
+  }
 }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/ComponentPlugin.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/ComponentPlugin.java?rev=1182498&r1=1182497&r2=1182498&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/ComponentPlugin.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/ComponentPlugin.java
Wed Oct 12 18:04:58 2011
@@ -18,24 +18,17 @@
 package org.apache.ambari.components;
 
 import java.io.IOException;
-import java.util.List;
 
 import org.apache.ambari.common.rest.entities.agent.Action;
 
 /**
- * A plug in that defines how to manage each component.
- * 
- * All commands must be idempotent, so that if they are replayed, they
- * work without failure.
+ * An interface for pluggable component definitions.
  */
 public abstract class ComponentPlugin {
   
-  /**
-   * Get the inactive roles for this component.
-   * @return the list of roles that need to be installed, but don't have servers.
-   * @throws IOException
-   */
-  public abstract String[] getInactiveRoles() throws IOException;
+  public abstract String getProvides();
+  
+  public abstract String getPackage();
   
   /**
    * Get the active roles (ie. with servers) for this component.
@@ -52,58 +45,58 @@ public abstract class ComponentPlugin {
   public abstract String[] getRequiredComponents() throws IOException;
   
   /**
-   * Is this component a service (ie. runs servers)?
-   * @return true if it has running servers
-   * @throws IOException
-   */
-  public abstract boolean isService() throws IOException;
-  
-  /**
    * Get the commands to write the configuration for this component.
    * @param cluster the cluster that is being configured
-   * @return the list of commands to run on each node
+   * @return the commands to run on each node
    * @throws IOException
    */
-  public abstract List<Action> writeConfiguration(ClusterContext cluster
-                                                  ) throws IOException;
+  public abstract Action configure(String cluster,
+                                   String role) throws IOException;
   
   /**
    * Get the commands to finalize the installation on the machine.
    * @param cluster the cluster that is being installed
-   * @return the list of commands to execute
+   * @return the commands to execute
    * @throws IOException
    */
-  public abstract List<Action> install(ClusterContext cluster
-                                       ) throws IOException;
+  public abstract Action install(String cluster,
+                                 String role) throws IOException;
   
   /**
    * Get the commands to start a role's server.
    * @param cluster the cluster that is being installed
    * @param role the role that needs to start running its server
-   * @return the list of commands to execute
+   * @return the commands to execute
    * @throws IOException
    */
-  public abstract List<Action> startRoleServer(ClusterContext cluster,
-                                               String role
-                                               ) throws IOException;
-
+  public abstract Action startServer(String cluster,
+                                     String role
+                                     ) throws IOException;
+  
   /**
-   * Get the commands to stop a role's server.
-   * @param cluster the cluster that is being installed
-   * @param role the role that needs to stop running its server
-   * @return the list of commands to execute
+   * Get the role that should run the check command.
+   * @return the role name
+   * @throws IOException
+   */
+  public abstract String runCheckRole() throws IOException;
+  
+  /**
+   * Get the commands to check whether the service is up
+   * @param clusterv the name of the cluster
+   * @param role the role that is being checked
+   * @return the commands to run on the agent
    * @throws IOException
    */
-  public abstract List<Action> stopRoleServer(ClusterContext cluster,
-                                              String role
-                                              ) throws IOException;
+  public abstract Action checkService(String cluster, 
+                                      String role) throws IOException;
 
   /**
    * Get the commands to run before the software is uninstalled.
    * @param cluster the cluster that is being uninstalled
-   * @return the list of commands to execute
+   * @return the commands to execute
    * @throws IOException
    */
-  public abstract List<Action> uninstall(ClusterContext cluster
-                                         ) throws IOException;
+  public abstract Action uninstall(String cluster,
+                                   String role
+                                   ) throws IOException;
 }

Added: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/impl/XmlComponentDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/impl/XmlComponentDefinition.java?rev=1182498&view=auto
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/impl/XmlComponentDefinition.java
(added)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/components/impl/XmlComponentDefinition.java
Wed Oct 12 18:04:58 2011
@@ -0,0 +1,294 @@
+package org.apache.ambari.components.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+
+import org.apache.ambari.common.rest.entities.ComponentDefinition;
+import org.apache.ambari.common.rest.entities.agent.Action;
+import org.apache.ambari.common.rest.entities.agent.Command;
+import org.apache.ambari.components.ComponentPlugin;
+
+public class XmlComponentDefinition extends ComponentPlugin {
+
+  @XmlAccessorType(XmlAccessType.FIELD)
+  @XmlType(name = "component", propOrder = {
+      "requires",
+      "roles",
+      "install",
+      "configure",
+      "start",
+      "check",
+      "uninstall"
+  })
+  @XmlRootElement
+  public static class Component {
+    @XmlAttribute String provides;
+    @XmlAttribute(name="package") String pkg;
+    @XmlAttribute String user;
+    @XmlElement List<Requires> requires;
+    @XmlElement List<Role> roles;
+    @XmlElement Install install;
+    @XmlElement Configure configure;
+    @XmlElement Start start;
+    @XmlElement Check check;
+    @XmlElement Uninstall uninstall;
+  }
+  
+  @XmlAccessorType
+  @XmlType(name = "role")
+  public static class Role {
+    @XmlAttribute String name;
+  }
+
+  @XmlAccessorType(XmlAccessType.FIELD)
+  @XmlType(name = "requires")
+  public static class Requires {
+    @XmlAttribute String name;
+  }
+
+  public static class ScriptCommand {
+    @XmlAttribute String user;
+    @XmlValue String script;
+  }
+
+  @XmlAccessorType(XmlAccessType.FIELD)
+  @XmlType(name = "install")
+  public static class Install extends ScriptCommand {
+  }
+
+  @XmlAccessorType(XmlAccessType.FIELD)
+  @XmlType(name = "configure")
+  public static class Configure extends ScriptCommand {
+  }
+
+  @XmlAccessorType(XmlAccessType.FIELD)
+  @XmlType(name = "start")
+  public static class Start extends ScriptCommand {
+  }
+
+  @XmlAccessorType(XmlAccessType.FIELD)
+  @XmlType(name = "check")
+  public static class Check extends ScriptCommand {
+    @XmlAttribute String runOn;
+  }
+
+  @XmlAccessorType(XmlAccessType.FIELD)
+  @XmlType(name = "uninstall")
+  public static class Uninstall extends ScriptCommand {
+  }
+
+  private static final JAXBContext jaxbContext;
+  static {
+    try {
+      jaxbContext = JAXBContext.newInstance("org.apache.ambari.components.impl");
+    } catch (JAXBException e) {
+      throw new RuntimeException("Can't create jaxb context", e);
+    }
+  }
+
+  private final String provides;
+  private final String pkg;
+  private final String[] roles;
+  private final String[] dependencies;
+  private final String configureCommand;
+  private final String configureUser;
+  private final String installCommand;
+  private final String installUser;
+  private final String startCommand;
+  private final String startUser;
+  private final String uninstallCommand;
+  private final String uninstallUser;
+  private final String checkRole;
+  private final String checkCommand;
+  private final String checkUser;
+  
+  @Override
+  public String getProvides() {
+    return provides;
+  }
+  
+  @Override
+  public String getPackage() {
+    return pkg;
+  }
+
+  @Override
+  public String[] getActiveRoles() throws IOException {
+    return roles;
+  }
+
+  @Override
+  public String[] getRequiredComponents() throws IOException {
+    return dependencies;
+  }
+
+  @Override
+  public Action configure(String cluster, String role) throws IOException {
+    if (configureCommand == null) {
+      return null;
+    }
+    Action result = new Action();
+    result.kind = Action.Kind.RUN_ACTION;
+    result.command = new Command(configureUser, configureCommand, 
+                                 new String[]{cluster, role});
+    return result;
+  }
+
+  @Override
+  public Action install(String cluster, String role) throws IOException {
+    if (installCommand == null) {
+      return null;
+    }
+    Action result = new Action();
+    result.kind = Action.Kind.RUN_ACTION;
+    result.command = new Command(installUser, installCommand, 
+                                 new String[]{cluster, role});
+    return result;
+  }
+
+  @Override
+  public Action startServer(String cluster, String role) throws IOException {
+    if (startCommand == null) {
+      return null;
+    }
+    Action result = new Action();
+    result.kind = Action.Kind.START_ACTION;
+    result.command = new Command(startUser, startCommand, 
+                                 new String[]{cluster, role});
+    return result;
+  }
+
+  @Override
+  public String runCheckRole() throws IOException {
+    return checkRole;
+  }
+
+  @Override
+  public Action checkService(String cluster, String role) throws IOException {
+    if (checkCommand == null) {
+      return null;
+    }
+    Action result = new Action();
+    result.kind = Action.Kind.RUN_ACTION;
+    result.command = new Command(checkUser, checkCommand, 
+                                 new String[]{cluster, role});
+    return result;
+  }
+
+  @Override
+  public Action uninstall(String cluster, String role) throws IOException {
+    if (uninstallCommand == null) {
+      return null;
+    }
+    Action result = new Action();
+    result.kind = Action.Kind.RUN_ACTION;
+    result.command = new Command(uninstallUser, uninstallCommand, 
+                                 new String[]{cluster, role});
+    return result;
+  }
+
+  private static String getCommand(ScriptCommand cmd) {
+    if (cmd == null) {
+      return null;
+    } else {
+      return cmd.script;
+    }
+  }
+
+  private static String getUser(ScriptCommand cmd, String user) {
+    if (cmd == null || cmd.user == null) {
+      return user;
+    } else {
+      return cmd.user;
+    }
+  }
+
+  XmlComponentDefinition(InputStream in) throws IOException {
+    Unmarshaller um;
+    try {
+      um = jaxbContext.createUnmarshaller();
+      Component component = (Component) um.unmarshal(in);
+      provides = component.provides;
+      pkg = component.pkg;
+      int i = 0;
+      if (component.requires == null) {
+        dependencies = new String[0];
+      } else {
+        dependencies = new String[component.requires.size()];
+        for(Requires r: component.requires) {
+          dependencies[i] = r.name;
+        }
+      }
+      i = 0;
+      if (component.roles == null) {
+        roles = new String[0];
+      } else {
+        roles = new String[component.roles.size()];
+        for(Role r: component.roles) {
+          roles[i] = r.name;
+        }      
+      }
+      installCommand = getCommand(component.install);
+      installUser = getUser(component.install, component.user);
+      configureCommand = getCommand(component.configure);
+      configureUser = getUser(component.configure, component.user);
+      startCommand = getCommand(component.start);
+      startUser = getUser(component.start, component.user);
+      checkCommand = getCommand(component.check);
+      checkUser = getUser(component.check, component.user);
+      if (component.check != null) {
+        checkRole = component.check.runOn;
+      } else {
+        checkRole = null;
+      }
+      uninstallCommand = getCommand(component.uninstall);
+      uninstallUser = getUser(component.uninstall, component.user);
+    } catch (JAXBException e) {
+      throw new IOException("Problem parsing component defintion", e);
+    }
+  }
+
+  private static InputStream getInputStream(ComponentDefinition defn) {
+    String name = defn.getGroup().replace('.', '/') + "/acd/" +
+                  defn.getDefinition() + '-' +
+                  defn.getVersion() + ".acd";
+    InputStream result = ClassLoader.getSystemResourceAsStream(name);
+    if (result == null) {
+      throw new IllegalArgumentException("Can't find resource for " + defn);
+    }
+    return result;
+  }
+
+  /**
+   * Get a component definition based on the name.
+   * @param defn the name of the definition
+   * @throws IOException
+   */
+  public XmlComponentDefinition(ComponentDefinition defn) throws IOException {
+    this(getInputStream(defn));
+  }
+  
+  public static void main(String[] args) throws Exception {
+    ComponentDefinition defn = new ComponentDefinition();
+    defn.setDefinition("hadoop-hdfs");
+    defn.setGroup("org.apache.ambari");
+    defn.setVersion("0.1.0");
+    XmlComponentDefinition comp = new XmlComponentDefinition(defn);
+    System.out.println(comp.provides);
+    defn.setDefinition("hadoop-common");
+    comp = new XmlComponentDefinition(defn);
+    System.out.println(comp.provides);
+  }
+}

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java?rev=1182498&r1=1182497&r2=1182498&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Blueprints.java
Wed Oct 12 18:04:58 2011
@@ -134,7 +134,7 @@ public class Blueprints {
     /*
      * Get blueprint. If revision = -1 then return latest revision
      */
-    public Blueprint getBlueprint(String blueprintName, int revision) throws Exception {
+    public Blueprint getBlueprint(String blueprintName, int revision) {
         /*
          * If revision is -1, then return the latest revision
          */  

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java?rev=1182498&r1=1182497&r2=1182498&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Cluster.java
Wed Oct 12 18:04:58 2011
@@ -18,9 +18,17 @@
 package org.apache.ambari.controller;
 
 
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.ambari.common.rest.entities.Blueprint;
 import org.apache.ambari.common.rest.entities.ClusterDefinition;
 import org.apache.ambari.common.rest.entities.ClusterState;
+import org.apache.ambari.common.rest.entities.Component;
+import org.apache.ambari.components.ComponentPlugin;
+import org.apache.ambari.components.impl.XmlComponentDefinition;
 
 
 public class Cluster {
@@ -29,7 +37,7 @@ public class Cluster {
     /*
      * Latest revision of cluster definition
      */
-    protected long latestRevision;
+    private long latestRevision = 0;
     
     /**
      * @return the latestRevision
@@ -41,9 +49,12 @@ public class Cluster {
     /*
      * Map of cluster revision to cluster definition
      */
-    protected ConcurrentHashMap<Long, ClusterDefinition> clusterDefinitionRevisionsList
= null;
-    protected ClusterState clusterState;
-    
+    private final Map<Long, ClusterDefinition> clusterDefinitionRevisionsList = 
+        new ConcurrentHashMap<Long, ClusterDefinition>();
+    private ClusterState clusterState;
+    private ClusterDefinition definition;
+    private final Map<String, ComponentPlugin> plugins =
+        new HashMap<String, ComponentPlugin>();
     
     /**
      * @return the iD
@@ -62,35 +73,46 @@ public class Cluster {
     /**
      * @return the clusterDefinition
      */
-    public ClusterDefinition getClusterDefinition(long revision) {
+    public synchronized ClusterDefinition getClusterDefinition(long revision) {
         return clusterDefinitionRevisionsList.get(revision);
     }
     
     /**
      * @return the latest clusterDefinition
      */
-    public ClusterDefinition getLatestClusterDefinition() {
-        return clusterDefinitionRevisionsList.get(this.latestRevision);
+    public synchronized ClusterDefinition getLatestClusterDefinition() {
+        return definition;
     }
     
     /**
      * @return Add Cluster definition
      */
-    public void addClusterDefinition(ClusterDefinition c) {
-        if (clusterDefinitionRevisionsList == null) {
-            clusterDefinitionRevisionsList = new ConcurrentHashMap<Long, ClusterDefinition>();
-            clusterDefinitionRevisionsList.put((long)0, c);
-            this.latestRevision = 0;
-        } else {
-            this.latestRevision++;
-            clusterDefinitionRevisionsList.put((long)this.latestRevision, c);
+    public synchronized 
+    void addClusterDefinition(ClusterDefinition c) throws IOException {
+      this.latestRevision++;
+      clusterDefinitionRevisionsList.put((long)this.latestRevision, c);
+      definition = c;
+      // find the plugins for the current definition of the cluster
+      Blueprints context = Blueprints.getInstance();
+      Blueprint bp = context.getBlueprint(c.getBlueprintName(),
+                                   Integer.parseInt(c.getBlueprintRevision()));
+      while (bp != null) {
+        for(Component comp: bp.getComponents()) {
+          String name = comp.getName();
+          if (!plugins.containsKey(name) && comp.getDefinition() != null) {
+            plugins.put(name, new XmlComponentDefinition(comp.getDefinition()));
+          }
         }
+        // go up to the parent
+        bp = context.getBlueprint(bp.getParentName(), 
+                                  Integer.parseInt(bp.getParentRevision()));
+      }
     }
     
     /**
      * @return the clusterDefinitionList
      */
-    public ConcurrentHashMap<Long, ClusterDefinition> getClusterDefinitionRevisionsList()
{
+    public Map<Long, ClusterDefinition> getClusterDefinitionRevisionsList() {
         return clusterDefinitionRevisionsList;
     }
 
@@ -107,5 +129,17 @@ public class Cluster {
     public void setClusterState(ClusterState clusterState) {
             this.clusterState = clusterState;
     }
-        
+    
+    public synchronized String getName() {
+      return definition.getName();
+    }
+
+    public synchronized Iterable<String> getComponents() {
+      return plugins.keySet();
+    }
+    
+    public synchronized 
+    ComponentPlugin getComponentDefinition(String component) {
+      return plugins.get(component);
+    }
 }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java?rev=1182498&r1=1182497&r2=1182498&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
Wed Oct 12 18:04:58 2011
@@ -41,9 +41,7 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.common.rest.entities.agent.ControllerResponse;
 import org.apache.ambari.common.rest.entities.agent.HeartBeat;
 import org.apache.ambari.common.rest.entities.agent.Action.Signal;
-import org.apache.ambari.components.ClusterContext;
-import org.apache.ambari.components.impl.ClusterContextImpl;
-import org.apache.ambari.components.impl.HDFSPluginImpl;
+import org.apache.ambari.components.ComponentPlugin;
 import org.apache.ambari.resource.statemachine.ClusterFSM;
 import org.apache.ambari.resource.statemachine.RoleFSM;
 import org.apache.ambari.resource.statemachine.RoleEvent;
@@ -85,7 +83,6 @@ public class HeartbeatHandler {
     
     Cluster cluster = 
         Clusters.getInstance().getClusterByID(state.getClusterID());
-    ClusterContext clusterContext = new ClusterContextImpl(cluster, node);
     
     List<Action> allActions = new ArrayList<Action>();
     
@@ -105,8 +102,7 @@ public class HeartbeatHandler {
       //get the list of uninstall actions
       //create a map from component/role to 'started' for easy lookup later
       allActions = 
-          inspectAgentState(heartbeat, clusterContext, 
-              componentServers, clusterFsm);
+          inspectAgentState(heartbeat, cluster, componentServers, clusterFsm);
 
       checkActionResults(cluster, clusterFsm, heartbeat, allActions);
       //the state machine reference to the services
@@ -125,18 +121,21 @@ public class HeartbeatHandler {
               role.getAssociatedService().getServiceName(),
               role.getRoleName());
           //TODO: get reference to the plugin impl for this service/component
-          HDFSPluginImpl plugin = new HDFSPluginImpl();
+          ComponentPlugin plugin = cluster.getComponentDefinition(service.getServiceName());
           //check whether the agent should start any server
           if (role.shouldStart()) {
             if (!roleInstalled) {
-              allActions.addAll(plugin.install(clusterContext));
+              Action action = plugin.install(cluster.getName(), 
+                                             role.getRoleName());
               continue;
             }
             if (!roleServerRunning) {
               //TODO: keep track of retries (via checkActionResults)
-              List<Action> actions = 
-                  plugin.startRoleServer(clusterContext, role.getRoleName());
-              allActions.addAll(actions);
+              Action actions = 
+		plugin.startServer(cluster.getName(), role.getRoleName());
+              if (actions != null) {
+                allActions.add(actions);
+	      }
             }
             //raise an event to the state machine for a successful role-start
             if (roleServerRunning) {
@@ -148,19 +147,21 @@ public class HeartbeatHandler {
           if (role.shouldStop()) {
             if (roleServerRunning) {
               //TODO: keep track of retries (via checkActionResults)
-              List<Action> actions = 
-                  plugin.stopRoleServer(clusterContext, role.getRoleName());
-              allActions.addAll(actions);
+              //TODO: addin stop server actions
             }
             //raise an event to the state machine for a successful role-stop
             if (!roleServerRunning) {
               StateMachineInvoker.getAMBARIEventHandler()
-              .handle(new RoleEvent(RoleEventType.STOP_SUCCESS, role));
+                .handle(new RoleEvent(RoleEventType.STOP_SUCCESS, role));
             }
             if (roleInstalled && 
                 clusterFsm.getClusterState()
                   .equals(ClusterState.CLUSTER_STATE_ATTIC)) {
-              allActions.addAll(plugin.uninstall(clusterContext));
+              Action action = plugin.uninstall(cluster.getName(), 
+                                               role.getRoleName());
+              if (action != null) {
+                allActions.add(action);
+              }
             }
           }
         }
@@ -262,7 +263,7 @@ public class HeartbeatHandler {
   }
   
   private static List<Action> inspectAgentState(
-      HeartBeat heartbeat, ClusterContext context, 
+      HeartBeat heartbeat, Cluster cluster, 
       InstalledOrStartedComponents componentServers, ClusterFSM desiredCluster)
           throws IOException {
     List<AgentRoleState> agentRoleStates = 
@@ -310,9 +311,11 @@ public class HeartbeatHandler {
       }
       if (uninstall) {
         //TODO: get reference to the plugin impl for this service/component
-        HDFSPluginImpl plugin = new HDFSPluginImpl();
-        List<Action> uninstallAction = plugin.uninstall(context);
-        killAndUninstallCmds.addAll(uninstallAction);
+        ComponentPlugin plugin = 
+            cluster.getComponentDefinition(agentRoleState.getComponentName());
+        Action uninstallAction = 
+            plugin.uninstall(cluster.getName(), agentRoleState.getRoleName());
+        killAndUninstallCmds.add(uninstallAction);
       }
       if (!stopRole && !uninstall) {
         //this must be one of the roles we care about

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceImpl.java?rev=1182498&r1=1182497&r2=1182498&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceImpl.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ServiceImpl.java
Wed Oct 12 18:04:58 2011
@@ -28,14 +28,16 @@ import org.apache.ambari.common.state.Si
 import org.apache.ambari.common.state.StateMachine;
 import org.apache.ambari.common.state.StateMachineFactory;
 import org.apache.ambari.components.ComponentPlugin;
-import org.apache.ambari.components.impl.HDFSPluginImpl;
+import org.apache.ambari.controller.Cluster;
+import org.apache.ambari.controller.Clusters;
 import org.apache.ambari.event.EventHandler;
 
 public class ServiceImpl implements ServiceFSM, EventHandler<ServiceEvent> {
 
   private ServiceState myState;
-  private ClusterFSM cluster;
+  private ClusterFSM clusterFsm;
   private ComponentPlugin plugin;
+  private Cluster cluster;
   
   /* The state machine for the service looks like:
    * INACTIVE --S_START--> STARTING --S_START_SUCCESS--> STARTED
@@ -107,11 +109,13 @@ public class ServiceImpl implements Serv
   private final String serviceName;
   
   public ServiceImpl(ClusterFSM cluster, String serviceName) throws IOException {
-    this.cluster = cluster;
+    this.clusterFsm = cluster;
     this.serviceName = serviceName;
     this.myState = ServiceState.INACTIVE;
     //load plugin and get the roles and create them
-    this.plugin = new HDFSPluginImpl();
+    this.cluster = 
+        Clusters.getInstance().getClusterByID(cluster.getClusterID());
+    this.plugin = this.cluster.getComponentDefinition(serviceName);
     String[] roles = this.plugin.getActiveRoles();
     for (String role : roles) {
       RoleImpl roleImpl = new RoleImpl(this, role);
@@ -137,7 +141,7 @@ public class ServiceImpl implements Serv
 
   @Override
   public ClusterFSM getAssociatedCluster() {
-    return cluster;
+    return clusterFsm;
   }
   
   @Override

Added: incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/hadoop-common-0.1.0.acd
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/hadoop-common-0.1.0.acd?rev=1182498&view=auto
==============================================================================
--- incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/hadoop-common-0.1.0.acd
(added)
+++ incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/hadoop-common-0.1.0.acd
Wed Oct 12 18:04:58 2011
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<component provides="hadoop-common" package="hadoop-${version}.tar.gz"
+           user="root">
+  <configure>
+<![CDATA[
+import ambari_component
+
+for file in ['log4j', 'commons-logging', 'hadoop-metrics2']:
+  ambari_component.copyProperties('hadoop/' + file, {})
+
+ambari_component.copySh('hadoop/hadoop-env', {})
+
+ambari_component.copyXml('hadoop/core-site', {})
+]]>
+  </configure>
+  <install>
+<![CDATA[
+import ambari_component
+import os
+
+if not os.path.isdir("stack"):
+  os.mkdir("stack")
+
+ambari_component.installTar("hadoop")
+]]>
+  </install>
+  <uninstall>
+<![CDATA[
+import ambari_component
+import shutil
+
+shutil.rmtree("stack")
+]]>
+  </uninstall>
+</component>

Added: incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/hadoop-hdfs-0.1.0.acd
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/hadoop-hdfs-0.1.0.acd?rev=1182498&view=auto
==============================================================================
--- incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/hadoop-hdfs-0.1.0.acd
(added)
+++ incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/acd/hadoop-hdfs-0.1.0.acd
Wed Oct 12 18:04:58 2011
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<component provides="hdfs" user="root">
+  <requires name="hadoop-common"/>
+  <roles name="namenode"/>
+  <roles name="secondarynamenode"/>
+  <roles name="datanode"/>
+  <configure>
+<![CDATA[
+import ambari_component
+import sys
+
+[pgm, cluster, role] = sys.argv
+
+opts = {}
+if role == "datanode":
+  opts['dfs.data.dir'] = ambari_component.getDataDirs()
+
+ambari_component.copyXml('hadoop/hdfs-site', opts)
+]]>
+  </configure>
+  <start>
+<![CDATA[
+import os
+import sys
+
+[pgm, cluster, role] = sys.argv
+
+os.execl("stack/bin/hadoop", "stack/bin/hadoop", role)
+]]>
+  </start>
+  <check run_on="namenode" user="${hdfs.user}">
+<![CDATA[
+import os
+
+os.exec('stack/bin/hadoop', 'stack/bin/hadoop', 'dfsadmin', '-get')
+]]>
+  </check>
+</component>

Added: incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/components/impl/jaxb.index
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/components/impl/jaxb.index?rev=1182498&view=auto
==============================================================================
--- incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/components/impl/jaxb.index
(added)
+++ incubator/ambari/trunk/controller/src/main/resources/org/apache/ambari/components/impl/jaxb.index
Wed Oct 12 18:04:58 2011
@@ -0,0 +1 @@
+XmlComponentDefinition$Component
\ No newline at end of file



Mime
View raw message