incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r1181258 - 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 21:51:03 GMT
Author: ddas
Date: Mon Oct 10 21:51:03 2011
New Revision: 1181258

URL: http://svn.apache.org/viewvc?rev=1181258&view=rev
Log:
AMBARI-53. Refactor the HeartBeat to have Agents' states separated by component/role. Contributed
by Devaraj Das.

Added:
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/AgentRoleState.java
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/HeartBeat.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ServerStatus.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/ControllerResource.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1181258&r1=1181257&r2=1181258&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Mon Oct 10 21:51:03 2011
@@ -2,6 +2,9 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-53. Refactor the HeartBeat to have Agents' states separated by 
+  component/role (ddas)
+
   AMBARI-50. Refactor the REST apis. (omalley)
 
   AMBARI-48. Move Cluster object from rest entities to controller(vgogate)

Added: 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=1181258&view=auto
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/AgentRoleState.java
(added)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/AgentRoleState.java
Mon Oct 10 21:51:03 2011
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {"clusterId", "bluePrintName", 
+    "bluePrintRevision", "componentName", "roleName",
+    "serversStatus"})
+public class AgentRoleState {
+  @XmlElement
+  private String bluePrintName;
+  @XmlElement
+  private String bluePrintRevision;
+  @XmlElement
+  private String clusterId;
+  @XmlElement
+  private String componentName;
+  @XmlElement
+  private String roleName;
+  @XmlElement
+  private ServerStatus serverStatus;
+  
+  public String getClusterId() {
+    return clusterId;
+  }
+  
+  public String getBluePrintName() {
+    return bluePrintName;
+  }
+  
+  public String getBluePrintRevision() {
+    return bluePrintRevision;
+  }
+  
+  public String getComponentName() {
+    return componentName;
+  }
+  
+  public String getRoleName() {
+    return roleName;
+  }
+  
+  public ServerStatus getServerStatus() {
+    return serverStatus;
+  }
+  
+  public void setClusterId(String clusterId) {
+    this.clusterId = clusterId;
+  }
+  
+  public void setBluePrintName(String bluePrintName) {
+    this.bluePrintName = bluePrintName;
+  }
+  
+  public void setBluePrintRevision(String bluePrintRevision) {
+    this.bluePrintRevision = bluePrintRevision;    
+  }
+  
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+  
+  public void setRoleName(String roleName) {
+    this.roleName = roleName;
+  }
+  
+  public void setServerStatus(ServerStatus serverStatus) {
+    this.serverStatus = serverStatus;
+  }
+}

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=1181258&r1=1181257&r2=1181258&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 21:51:03 2011
@@ -41,21 +41,15 @@ public class HeartBeat {
   @XmlElement
   private String responseId;
   @XmlElement
-  private String clusterId;
-  @XmlElement
   private long timestamp;
   @XmlElement
   private String hostname;
   @XmlElement
-  private String bluePrintName;
-  @XmlElement
-  private String bluePrintRevision;
-  @XmlElement
   private HardwareProfile hardwareProfile;
   @XmlElement
-  private List<ActionResult> actionResults;
+  private List<AgentRoleState> installedRoleStates;
   @XmlElement
-  private List<ServerStatus> serversStatus;
+  private List<ActionResult> actionResults;
   @XmlElement
   private boolean idle;
   
@@ -67,10 +61,6 @@ public class HeartBeat {
     this.responseId=responseId;
   }
   
-  public String getClusterId() {
-    return clusterId;
-  }
-  
   public long getTimestamp() {
     return timestamp;
   }
@@ -79,14 +69,6 @@ public class HeartBeat {
     return hostname;
   }
   
-  public String getBluePrintName() {
-    return bluePrintName;
-  }
-  
-  public String getBluePrintRevision() {
-    return bluePrintRevision;
-  }
-    
   public boolean getIdle() {
     return idle;
   }
@@ -99,14 +81,10 @@ public class HeartBeat {
     return actionResults;
   }
   
-  public List<ServerStatus> getServersStatus() {
-    return serversStatus;
+  public List<AgentRoleState> getInstalledRoleStates() {
+    return installedRoleStates;
   }
   
-  public void setClusterId(String clusterId) {
-    this.clusterId = clusterId;
-  }
-
   public void setTimestamp(long timestamp) {
     this.timestamp = timestamp;
   }
@@ -114,15 +92,7 @@ public class HeartBeat {
   public void setHostname(String hostname) {
     this.hostname = hostname;
   }
-  
-  public void setBluePrintName(String bluePrintName) {
-    this.bluePrintName = bluePrintName;
-  }
-  
-  public void setBluePrintRevision(String bluePrintRevision) {
-    this.bluePrintRevision = bluePrintRevision;    
-  }
-  
+    
   public void setActionResults(List<ActionResult> actionResults) {
     this.actionResults = actionResults;
   }
@@ -131,8 +101,8 @@ public class HeartBeat {
     this.hardwareProfile = hardwareProfile;    
   }
   
-  public void setServersStatus(List<ServerStatus> serversStatus) {
-    this.serversStatus = serversStatus;
+  public void setInstalledRoleStates(List<AgentRoleState> installedRoleStates) {
+    this.installedRoleStates = installedRoleStates;
   }
   
   public void setIdle(boolean idle) {

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ServerStatus.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ServerStatus.java?rev=1181258&r1=1181257&r2=1181258&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ServerStatus.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ServerStatus.java
Mon Oct 10 21:51:03 2011
@@ -28,34 +28,14 @@ import javax.xml.bind.annotation.adapter
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "", propOrder = {})
 public class ServerStatus {
-  public String component;
-  public String role;
   public State state;
   
   public ServerStatus() {  
   }
   
-  public ServerStatus(String component, String role, State state) {
-    this.component = component;
-    this.role = role;
+  public ServerStatus(State state) {
     this.state = state;
   }
-
-  public String getComponent() {
-    return this.component;
-  }
-
-  public void setComponent(String component) {
-    this.component = component;  
-  }
-  
-  public String getRole() {
-    return role;
-  }
-  
-  public void setServerName(String role) {
-    this.role = role;
-  }
   
   public State getState() {
     return state;

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=1181258&r1=1181257&r2=1181258&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 21:51:03 2011
@@ -29,14 +29,19 @@ import java.util.Map;
 import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.DatatypeFactory;
 
+import org.apache.ambari.common.rest.entities.ClusterState;
 import org.apache.ambari.common.rest.entities.Node;
 import org.apache.ambari.common.rest.entities.NodeState;
 import org.apache.ambari.controller.Clusters;
 import org.apache.ambari.controller.Nodes;
 import org.apache.ambari.common.rest.entities.agent.Action;
+import org.apache.ambari.common.rest.entities.agent.Action.Kind;
+import org.apache.ambari.common.rest.entities.agent.ActionResults;
+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;
 import org.apache.ambari.components.impl.HDFSPluginImpl;
@@ -46,6 +51,7 @@ import org.apache.ambari.resource.statem
 import org.apache.ambari.resource.statemachine.RoleEventType;
 import org.apache.ambari.resource.statemachine.ServiceFSM;
 import org.apache.ambari.resource.statemachine.StateMachineInvoker;
+import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
 
 public class HeartbeatHandler {
   
@@ -90,24 +96,28 @@ public class HeartbeatHandler {
       //command more than once. In the future this could be improved
       //to reflect the command execution state more accurately.
       
-      //get what is currently running on the node
-      List<ServerStatus> roleStatuses = heartbeat.getServersStatus();
+      String desiredBlueprint = 
+          cluster.getLatestClusterDefinition().getBlueprintName();
+      String desiredBlueprintRev = 
+          cluster.getLatestClusterDefinition().getBlueprintRevision();
+      String desiredClusterId = cluster.getID();
+      ClusterFSM desiredClusterFSM = StateMachineInvoker
+          .getStateMachineClusterInstance(desiredClusterId, desiredBlueprint,
+              desiredBlueprintRev);
       
-      //what servers are running currently
-      //ADD LOGIC FOR CAPTURING THE CLUSTER-ID THE SERVERS BELONG TO
-      //IF THEY BELONG TO THE CLUSTER-ID THIS NODE IS PART OF, WELL AND GOOD
-      //IF NOT, THEN SEND COMMANDS TO STOP THE SERVERS
       StartedComponentServers componentServers = new StartedComponentServers();
-      for (ServerStatus status : roleStatuses) {
-        componentServers.roleServerStarted(status.getComponent(), 
-            status.getRole());
-      }
+      //check if the node is in the expected cluster (with the appropriate 
+      //revision of the blueprint)      
+      //get the list of install/uninstall actions
+      //create a map from component/role to 'started' for easy lookup later
+      List<Action> installAndUninstallActions = 
+          getInstallAndUninstallActions(heartbeat, desiredClusterFSM, 
+              clusterContext, componentServers);
 
       //get the state machine reference to the cluster
       ClusterFSM clusterSMobject = StateMachineInvoker
-          .getStateMachineClusterInstance(cluster.getID(), 
-              cluster.getLatestClusterDefinition().getBlueprintName(), 
-              cluster.getLatestClusterDefinition().getBlueprintRevision());
+          .getStateMachineClusterInstance(desiredClusterId, desiredBlueprint, 
+              desiredBlueprintRev);
       //the state machine reference to the services
       List<ServiceFSM> clusterServices = clusterSMobject.getServices();
       //go through all the services, and check which role should be started
@@ -176,11 +186,6 @@ public class HeartbeatHandler {
     return r;
   }
   
-  private static class InstalledComponents {
-    private Map<String, Boolean> installedComponentMap =
-        new HashMap<String, Boolean>();
-    
-  }
   private static class StartedComponentServers {
     private Map<String, Map<String, Boolean>> startedComponentServerMap =
         new HashMap<String, Map<String, Boolean>>();
@@ -221,4 +226,67 @@ public class HeartbeatHandler {
       countMap.remove(hostname);
     }
   }
+  
+  private static List<Action> getInstallAndUninstallActions(
+      HeartBeat heartbeat, ClusterFSM desiredClusterFSM, 
+      ClusterContext context, StartedComponentServers componentServers)
+          throws IOException {
+    List<AgentRoleState> agentRoleStates = 
+        heartbeat.getInstalledRoleStates();
+    List<Action> killAndUninstallCmds = new ArrayList<Action>();
+    //Go over all the reported role states, and stop/uninstall the
+    //unnecessary ones
+    for (AgentRoleState agentRoleState : agentRoleStates) {
+      boolean stopRole = false;
+      boolean uninstall = false;
+      
+      ClusterFSM clusterFSM = StateMachineInvoker
+          .getStateMachineClusterInstance(agentRoleState.getClusterId(), 
+              agentRoleState.getBluePrintName(), 
+              agentRoleState.getBluePrintRevision());
+      if (clusterFSM == null) {
+        //ask the agent to stop everything belonging to this role
+        //since the controller can't be in a state where the clusterFSM
+        //is null and the cluster is not in ATTIC or deleted state
+        stopRole = true;
+        uninstall = true;
+      }
+      if (clusterFSM != null) {
+        if (clusterFSM.getClusterState().getState()
+            .equals(ClusterState.CLUSTER_STATE_INACTIVE)) {
+          stopRole = true;
+          uninstall = false;
+        }
+        else if (clusterFSM.getClusterState().getState()
+            .equals(ClusterState.CLUSTER_STATE_ATTIC)) {
+          stopRole = true;
+          uninstall = true;
+        }
+      }
+      if (stopRole && 
+        agentRoleState.getServerStatus().state == ServerStatus.State.STARTED) {
+        //TODO: not sure whether this requires to be done...
+        Action action = new Action();
+        action.setClusterId(agentRoleState.getClusterId());
+        action.setBluePrintName(agentRoleState.getBluePrintName());
+        action.setBluePrintRevision(agentRoleState.getBluePrintRevision());
+        action.setRole(agentRoleState.getRoleName());
+        action.setComponent(agentRoleState.getComponentName());
+        action.setKind(Kind.STOP_ACTION);
+        action.setSignal(Signal.KILL);
+        killAndUninstallCmds.add(action);
+      }
+      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);
+      }
+      if (!stopRole && !uninstall) {
+        componentServers.roleServerStarted(agentRoleState.getComponentName(), 
+              agentRoleState.getRoleName());
+      }
+    }
+    return killAndUninstallCmds;
+  }
 }

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=1181258&r1=1181257&r2=1181258&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 21:51:03 2011
@@ -37,6 +37,7 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.common.rest.entities.agent.Action.Kind;
 import org.apache.ambari.common.rest.entities.agent.Action.Signal;
 import org.apache.ambari.common.rest.entities.agent.ActionResult;
+import org.apache.ambari.common.rest.entities.agent.AgentRoleState;
 import org.apache.ambari.common.rest.entities.agent.Command;
 import org.apache.ambari.common.rest.entities.agent.CommandResult;
 import org.apache.ambari.common.rest.entities.agent.ControllerResponse;
@@ -156,7 +157,7 @@ public class ControllerResource {
       actionResult2.setCommandResults(commandResults);
       actionResult2.setCleanUpResults(cleanUpResults);
       actionResult2.setKind(Kind.START_ACTION);
-      actionResult2.setComponent("hadoop");
+      actionResult2.setComponent("hdfs");
       actionResult2.setRole("datanode");
 
       actionResults.add(actionResult);
@@ -170,21 +171,23 @@ public class ControllerResource {
       hp.setNetSpeed(1000);
       hp.setRamSize(16442752);
       
+      List<AgentRoleState> agentRoles = new ArrayList<AgentRoleState>(2);
+      AgentRoleState agentRole1 = new AgentRoleState();
+      agentRole1.setBluePrintName("blueprint");
+      agentRole1.setBluePrintRevision("0.2");
+      agentRole1.setClusterId("cluster-003");
+      agentRole1.setComponentName("hdfs");
+      agentRole1.setRoleName("datanode");
+      ServerStatus serverStatus = new ServerStatus(ServerStatus.State.STARTED);
+      agentRole1.setServerStatus(serverStatus);
+      
       HeartBeat hb = new HeartBeat();
       hb.setResponseId("unknown");
-      hb.setClusterId("cluster-123");
       hb.setTimestamp(System.currentTimeMillis());
       hb.setHostname(addr.getHostName());
-      hb.setBluePrintName("blueprint");
-      hb.setBluePrintRevision("0.1");
       hb.setActionResults(actionResults);
       hb.setHardwareProfile(hp);
-      List<ServerStatus> serversStatus = new ArrayList<ServerStatus>();
-      serversStatus.add(new ServerStatus("hdfs","datanode", 
-          ServerStatus.State.STARTED));
-      serversStatus.add(new ServerStatus("hdfs","tasktracker", 
-          ServerStatus.State.STARTED));
-      hb.setServersStatus(serversStatus);
+      hb.setInstalledRoleStates(agentRoles);
       hb.setIdle(false);
       return hb;
     } catch (UnknownHostException e) {



Mime
View raw message