incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject svn commit: r1181301 - in /incubator/ambari/trunk: client/src/main/java/org/apache/ambari/common/rest/entities/agent/ controller/src/main/java/org/apache/ambari/controller/ controller/src/main/java/org/apache/ambari/controller/rest/agent/
Date Mon, 10 Oct 2011 23:59:14 GMT
Author: eyang
Date: Mon Oct 10 23:59:13 2011
New Revision: 1181301

URL: http://svn.apache.org/viewvc?rev=1181301&view=rev
Log:
AMBARI-54. Fixed refactoring code from AMBARI-53. (Eric Yang)

Removed:
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ServerStatus.java
Modified:
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Action.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/AgentRoleState.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Command.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/HeartBeat.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/AgentJAXBContextResolver.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/ControllerResource.java

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Action.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Action.java?rev=1181301&r1=1181300&r2=1181301&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Action.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Action.java
Mon Oct 10 23:59:13 2011
@@ -18,8 +18,6 @@
 
 package org.apache.ambari.common.rest.entities.agent;
 
-import java.util.List;
-
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
@@ -46,9 +44,9 @@ public class Action {
   @XmlElement
   public Signal signal;
   @XmlElement
-  public List<Command> commands;
+  public Command command;
   @XmlElement
-  public List<Command> cleanUpCommands;
+  public Command cleanUpCommand;
   @XmlElement
   public String bluePrintName;
   @XmlElement
@@ -110,20 +108,20 @@ public class Action {
     this.signal = signal;
   }
   
-  public List<Command> getCommands() {
-    return commands;
+  public Command getCommand() {
+    return command;
   }
   
-  public void setCommands(List<Command> commands) {
-    this.commands = commands;
+  public void setCommand(Command command) {
+    this.command = command;
   }
   
-  public List<Command> getCleanUpCommands() {
-    return cleanUpCommands;
+  public Command getCleanUpCommand() {
+    return cleanUpCommand;
   }
   
-  public void setCleanUpCommands(List<Command> cleanUpCommands) {
-    this.cleanUpCommands = cleanUpCommands;  
+  public void setCleanUpCommand(Command cleanUpCommand) {
+    this.cleanUpCommand = cleanUpCommand;  
   }
   
   public String getBluePrintName() {
@@ -143,7 +141,8 @@ public class Action {
   }
   
   public static enum Kind {
-    RUN_ACTION, START_ACTION, STOP_ACTION, STATUS_ACTION;
+    RUN_ACTION, START_ACTION, STOP_ACTION, STATUS_ACTION, 
+    CREATE_STRUCTURE_ACTION, DELETE_STRUCTURE_ACTION;
     public static class KindAdaptor extends XmlAdapter<String, Kind> {
       @Override
       public String marshal(Kind obj) throws Exception {

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/AgentRoleState.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/AgentRoleState.java?rev=1181301&r1=1181300&r2=1181301&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/AgentRoleState.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/AgentRoleState.java
Mon Oct 10 23:59:13 2011
@@ -18,20 +18,18 @@
 
 package org.apache.ambari.common.rest.entities.agent;
 
-import java.util.List;
-
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-
+import javax.xml.bind.annotation.adapters.XmlAdapter;
 
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "", propOrder = {"clusterId", "bluePrintName", 
     "bluePrintRevision", "componentName", "roleName",
-    "serversStatus"})
+    "serverStatus"})
 public class AgentRoleState {
   @XmlElement
   private String bluePrintName;
@@ -44,7 +42,7 @@ public class AgentRoleState {
   @XmlElement
   private String roleName;
   @XmlElement
-  private ServerStatus serverStatus;
+  private State serverStatus;
   
   public String getClusterId() {
     return clusterId;
@@ -66,7 +64,7 @@ public class AgentRoleState {
     return roleName;
   }
   
-  public ServerStatus getServerStatus() {
+  public State getServerStatus() {
     return serverStatus;
   }
   
@@ -90,7 +88,29 @@ public class AgentRoleState {
     this.roleName = roleName;
   }
   
-  public void setServerStatus(ServerStatus serverStatus) {
+  public void setServerStatus(State serverStatus) {
     this.serverStatus = serverStatus;
   }
+  
+  public static enum State {
+    START, STARTING, STARTED, STOP, STOPPING, STOPPED;
+    public static class ServerStateAdaptor extends XmlAdapter<String, State> {
+      @Override
+      public String marshal(State obj) throws Exception {
+        return obj.toString();
+      }
+
+      @Override
+      public State unmarshal(String str) throws Exception {
+        for (State j : State.class.getEnumConstants()) {
+          if (j.toString().equals(str)) {
+            return j;
+          }
+        }
+        throw new Exception("Can't convert " + str + " to "
+          + State.class.getName());
+      }
+
+    }
+  }
 }

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Command.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Command.java?rev=1181301&r1=1181300&r2=1181301&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Command.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Command.java
Mon Oct 10 23:59:13 2011
@@ -36,18 +36,22 @@ public class Command {
   public Command() {
   }
   
-  public Command(String user, String[] cmd) {
+  public Command(String user, String cmd, String[] param) {
     this.cmd = cmd;
     this.user = user;
+    this.param = param;
   }
   
   @XmlElement
-  private String[] cmd;
+  private String cmd;
 
   @XmlElement
+  private String[] param;
+  
+  @XmlElement
   private String user;
 
-  public String[] getCmd() {
+  public String getCmd() {
     return cmd;
   }
   
@@ -55,11 +59,19 @@ public class Command {
     return user;
   }
   
-  public void setCmd(String[] cmd) {
+  public void setCmd(String cmd) {
     this.cmd = cmd;
   }
   
   public void setUser(String user) {
     this.user = user;
   }
+  
+  public String[] getParam() {
+    return this.param;
+  }
+  
+  public void setParam(String[] param) {
+    this.param = param;
+  }
 }

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/HeartBeat.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/HeartBeat.java?rev=1181301&r1=1181300&r2=1181301&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/HeartBeat.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/HeartBeat.java
Mon Oct 10 23:59:13 2011
@@ -34,9 +34,9 @@ import javax.xml.bind.annotation.XmlType
  */
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "", propOrder = {"responseId","timestamp", "clusterId", 
-    "hostname", "bluePrintName", "bluePrintRevision", "hardwareProfile", 
-    "actionResults", "serversStatus", "idle"})
+@XmlType(name = "", propOrder = {"responseId","timestamp", 
+    "hostname", "hardwareProfile", "installedRoleStates",
+    "actionResults", "idle"})
 public class HeartBeat {
   @XmlElement
   private String responseId;

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java?rev=1181301&r1=1181300&r2=1181301&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
Mon Oct 10 23:59:13 2011
@@ -32,6 +32,7 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.common.rest.entities.Node;
 import org.apache.ambari.common.rest.entities.RoleToNodes;
 import org.apache.ambari.common.util.ExceptionUtil;
+import org.apache.ambari.resource.statemachine.ClusterFSM;
 import org.apache.ambari.resource.statemachine.StateMachineInvoker;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -488,14 +489,26 @@ public class Clusters {
             /*
              * TODO: Persist the latest cluster definition under new revision
              */
-            
+            ClusterFSM clusterFSM = StateMachineInvoker.
+                getStateMachineClusterInstance(cls.getID(), 
+                    c.getBlueprintName(), c.getBlueprintRevision());
+            if(c.getGoalState().equals(ClusterState.CLUSTER_STATE_ACTIVE)) {
+              clusterFSM.activate();
+            } else if(c.getGoalState().
+                equals(ClusterState.CLUSTER_STATE_INACTIVE)) {
+              clusterFSM.deactivate();
+            } else if(c.getGoalState().
+                equals(ClusterState.CLUSTER_STATE_ATTIC)) {
+              clusterFSM.deactivate();
+              clusterFSM.terminate();
+            }
         }
         return cls.getLatestClusterDefinition();
     }
     
     /*
      * Delete Cluster 
-     * Delete operation will bring the clsuter to ATTIC state and then remove the
+     * Delete operation will bring the cluster to ATTIC state and then remove the
      * cluster definition from the controller 
      * When cluster state transitions to ATTIC, it should check if the cluster definition
is 
      * part of tobe_deleted_clusters map and then delete the definition.

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=1181301&r1=1181300&r2=1181301&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
Mon Oct 10 23:59:13 2011
@@ -40,7 +40,6 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.common.rest.entities.agent.AgentRoleState;
 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.ServerStatus;
 import org.apache.ambari.common.rest.entities.agent.Action.Signal;
 import org.apache.ambari.components.ClusterContext;
 import org.apache.ambari.components.impl.ClusterContextImpl;
@@ -264,7 +263,7 @@ public class HeartbeatHandler {
         }
       }
       if (stopRole && 
-        agentRoleState.getServerStatus().state == ServerStatus.State.STARTED) {
+        agentRoleState.getServerStatus() == AgentRoleState.State.STARTED) {
         //TODO: not sure whether this requires to be done...
         Action action = new Action();
         action.setClusterId(agentRoleState.getClusterId());

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/AgentJAXBContextResolver.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/AgentJAXBContextResolver.java?rev=1181301&r1=1181300&r2=1181301&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/AgentJAXBContextResolver.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/AgentJAXBContextResolver.java
Mon Oct 10 23:59:13 2011
@@ -53,6 +53,7 @@ public class AgentJAXBContextResolver im
       add("cmd");
       add("commands");
       add("cleanUpCommands");
+      add("installedRoleStates");
     }
   };
   

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/ControllerResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/ControllerResource.java?rev=1181301&r1=1181300&r2=1181301&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/ControllerResource.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/agent/ControllerResource.java
Mon Oct 10 23:59:13 2011
@@ -43,7 +43,6 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.common.rest.entities.agent.ControllerResponse;
 import org.apache.ambari.common.rest.entities.agent.HardwareProfile;
 import org.apache.ambari.common.rest.entities.agent.HeartBeat;
-import org.apache.ambari.common.rest.entities.agent.ServerStatus;
 
 /** 
  * Controller Resource represents Ambari controller.
@@ -60,6 +59,7 @@ public class ControllerResource {
    * @response.representation.200.doc This API is invoked by Ambari agent running
    *  on a cluster to update the state of various services running on the node.
    * @response.representation.200.mediaType application/json
+   * @response.representation.200.example { "a" : "b" }
    * @response.representation.500.doc Error in accepting heartbeat message
    * @param message Heartbeat message
    */
@@ -70,16 +70,11 @@ public class ControllerResource {
   public ControllerResponse heartbeat(HeartBeat message) {
     ControllerResponse controllerResponse = new ControllerResponse();
     controllerResponse.setResponseId("id-00002");    
-    List<Command> commands = new ArrayList<Command>();
-    String[] cmd = { "ls", "-l" };
-    commands.add(new Command("root", cmd));
-    commands.add(new Command("root", cmd));
-    commands.add(new Command("root", cmd));
-
-    List<Command> cleanUps = new ArrayList<Command>();
-    String[] cleanUpCmd = { "ls", "-t" };
-    cleanUps.add(new Command("hdfs", cleanUpCmd));
-    cleanUps.add(new Command("hdfs", cleanUpCmd));
+    String cmd = "import os\nos._exit(0)";
+    String[] param = { "cluster", "role" };
+    Command command = new Command("root", cmd, param);
+
+    Command cleanUp = new Command("root", cmd, param);
     
     Action action = new Action();
     action.setUser("hdfs");
@@ -97,8 +92,8 @@ public class ControllerResource {
     action2.setKind(Kind.START_ACTION);
     action2.setId("action-002");
     action2.setClusterId("cluster-002");
-    action2.setCommands(commands);
-    action2.setCleanUpCommands(cleanUps);
+    action2.setCommand(command);
+    action2.setCleanUpCommand(cleanUp);
     action2.setComponent("hdfs");
     action2.setBluePrintName("blueprint");
     action2.setBluePrintRevision("0.2");
@@ -111,8 +106,8 @@ public class ControllerResource {
     action3.setBluePrintName("blueprint");
     action3.setBluePrintRevision("0.2");
     action3.setClusterId("cluster-003");
-    action3.setCommands(commands);
-    action3.setCleanUpCommands(cleanUps);
+    action3.setCommand(command);
+    action3.setCleanUpCommand(cleanUp);
 
     List<Action> actions = new ArrayList<Action>();
     actions.add(action);
@@ -178,8 +173,8 @@ public class ControllerResource {
       agentRole1.setClusterId("cluster-003");
       agentRole1.setComponentName("hdfs");
       agentRole1.setRoleName("datanode");
-      ServerStatus serverStatus = new ServerStatus(ServerStatus.State.STARTED);
-      agentRole1.setServerStatus(serverStatus);
+      agentRole1.setServerStatus(AgentRoleState.State.STARTED);
+      agentRoles.add(agentRole1);
       
       HeartBeat hb = new HeartBeat();
       hb.setResponseId("unknown");
@@ -209,25 +204,28 @@ public class ControllerResource {
   public ControllerResponse getControllerResponse() {
     ControllerResponse controllerResponse = new ControllerResponse();
     controllerResponse.setResponseId("id-00002");    
-    List<Command> commands = new ArrayList<Command>();
-    String[] cmd = { "top" };
-    commands.add(new Command("root", cmd));
-
-    List<Command> cleanUps = new ArrayList<Command>();
-    String[] cleanUpCmd = { "ls", "-t" };
-    cleanUps.add(new Command("hdfs", cleanUpCmd));
-    cleanUps.add(new Command("hdfs", cleanUpCmd));
+    
+    String cmd = "import os\nos._exit(0)";
+    String[] param = { "cluster", "role" };
+
+    Command command = new Command("root", cmd, param);
+    Command cleanUp = new Command("root", cmd, param);
     
     Action action = new Action();
-    action.setBluePrintName("blueprint");
-    action.setBluePrintRevision("0.1");
-    action.setUser("hdfs");
+    action.setKind(Kind.CREATE_STRUCTURE_ACTION);
     action.setComponent("hdfs");
     action.setRole("datanode");
-    action.setKind(Kind.STOP_ACTION);
-    action.setSignal(Signal.KILL);
-    action.setClusterId("cluster-001");
-    action.setId("action-001");
+    
+    Action action1 = new Action();
+    action1.setBluePrintName("blueprint");
+    action1.setBluePrintRevision("0.1");
+    action1.setUser("hdfs");
+    action1.setComponent("hdfs");
+    action1.setRole("datanode");
+    action1.setKind(Kind.STOP_ACTION);
+    action1.setSignal(Signal.KILL);
+    action1.setClusterId("cluster-001");
+    action1.setId("action-001");
 
     Action action2 = new Action();
     action2.setBluePrintName("blueprint");
@@ -236,8 +234,8 @@ public class ControllerResource {
     action2.setKind(Kind.START_ACTION);
     action2.setId("action-002");
     action2.setClusterId("cluster-002");
-    action2.setCommands(commands);
-    action2.setCleanUpCommands(cleanUps);
+    action2.setCommand(command);
+    action2.setCleanUpCommand(cleanUp);
     action2.setComponent("hdfs");
     action2.setRole("datanode");
     
@@ -248,21 +246,20 @@ public class ControllerResource {
     action3.setKind(Kind.RUN_ACTION);
     action3.setId("action-003");
     action3.setClusterId("cluster-002");
-    List<Command> configFiles = new ArrayList<Command>();
-    String[] writeFile = { 
-        "ambari-write-file",
-        "hdfs",
-        "hadoop",
-        "0700",
-        "/tmp/test",
-        "content of file"
-        };
-    configFiles.add(new Command("hdfs", writeFile));
-    action3.setCommands(configFiles);
+    action3.setCommand(command);
+    action3.setCleanUpCommand(cleanUp);
+    
+    Action action4 = new Action();
+    action4.setKind(Kind.DELETE_STRUCTURE_ACTION);
+    action4.setComponent("hdfs");
+    action4.setRole("datanode");
+    
     List<Action> actions = new ArrayList<Action>();
     actions.add(action);
+    actions.add(action1);
     actions.add(action2);
     actions.add(action3);
+    actions.add(action4);
     controllerResponse.setActions(actions);
     return controllerResponse;
   }



Mime
View raw message