You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dd...@apache.org on 2011/12/02 01:46:22 UTC

svn commit: r1209323 - in /incubator/ambari/trunk: ./ client/src/main/java/org/apache/ambari/client/ client/src/main/java/org/apache/ambari/common/rest/entities/ controller/ controller/src/main/java/org/apache/ambari/controller/ controller/src/main/jav...

Author: ddas
Date: Fri Dec  2 00:46:19 2011
New Revision: 1209323

URL: http://svn.apache.org/viewvc?rev=1209323&view=rev
Log:
AMBARI-145. FSMs are created for only those components that have active roles. Contributed by Thejas M Nair.

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterGet.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterList.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterUpdate.java
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.java
    incubator/ambari/trunk/controller/pom.xml
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/config/Examples.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterStateFSM.java
    incubator/ambari/trunk/pom.xml

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Fri Dec  2 00:46:19 2011
@@ -2,6 +2,9 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-145. FSMs are created for only those components that have 
+  active roles (Thejas M Nair via ddas)
+
   AMBARI-146. Fix test case failures in agent's FileUtil. (omalley)
 
   AMBARI-144. Implement getInstallAndConfigureScript for a given

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterCreate.java Fri Dec  2 00:46:19 2011
@@ -234,7 +234,7 @@ public class ClusterCreate extends Comma
             revision = stack.getRevision();
         }
         clsDef.setStackRevision(revision);
-        clsDef.setActiveServices(splitServices(line.getOptionValue("services")));
+        clsDef.setEnabledServices(splitServices(line.getOptionValue("services")));
         clsDef.setDescription(line.getOptionValue("desc"));
         clsDef.setRoleToNodesMap(getRoleToNodesList(line.getOptionProperties("role")));
         

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterGet.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterGet.java?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterGet.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterGet.java Fri Dec  2 00:46:19 2011
@@ -145,7 +145,7 @@ public class ClusterGet extends Command 
             System.out.println("["+clsInfo.getDefinition().getName()+"]\t"+
                                "["+clsInfo.getState().getState()+"]\t"+
                                "["+clsInfo.getState().getCreationTime()+"]\t"+
-                               "["+clsInfo.getDefinition().getActiveServices()+"]\n");
+                               "["+clsInfo.getDefinition().getEnabledServices()+"]\n");
         } else {
             System.out.println("Cluster Information document:\n");
             printClusterInformation(clsInfo);

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterList.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterList.java?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterList.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterList.java Fri Dec  2 00:46:19 2011
@@ -153,7 +153,7 @@ public class ClusterList extends Command
                 System.out.println("["+clsInfo.getDefinition().getName()+"]\t"+
                                    "["+clsInfo.getState().getState()+"]\t"+
                                    "["+clsInfo.getState().getCreationTime()+"]\t"+
-                                   "["+clsInfo.getDefinition().getActiveServices()+"]\n");
+                                   "["+clsInfo.getDefinition().getEnabledServices()+"]\n");
             }
         } else {
             System.out.println("Cluster Information documents:\n");

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterUpdate.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterUpdate.java?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterUpdate.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/client/ClusterUpdate.java Fri Dec  2 00:46:19 2011
@@ -218,7 +218,7 @@ public class ClusterUpdate extends Comma
         
         clsDef.setGoalState(line.getOptionValue("goalstate"));
         clsDef.setStackRevision(line.getOptionValue("revision"));
-        clsDef.setActiveServices(splitServices(line.getOptionValue("services")));
+        clsDef.setEnabledServices(splitServices(line.getOptionValue("services")));
         clsDef.setDescription(line.getOptionValue("desc"));
         clsDef.setRoleToNodesMap(getRoleToNodesList(line.getOptionProperties("role")));
         

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.java?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/ClusterDefinition.java Fri Dec  2 00:46:19 2011
@@ -34,7 +34,7 @@ import javax.xml.bind.annotation.XmlType
  */
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlType(name = "ClusterDefinition", propOrder = {
-    "activeServices",
+    "enabledServices",
     "roleToNodesMap"
 })
 @XmlRootElement(name = "cluster")
@@ -92,7 +92,7 @@ public class ClusterDefinition {
      * The list of components that should be running if the cluster is ACTIVE.
      */
     @XmlElement
-    protected List<String> activeServices = null;
+    protected List<String> enabledServices = null;
     
     /**
      * A node expression giving the entire set of nodes for this cluster.
@@ -192,17 +192,17 @@ public class ClusterDefinition {
     }
 
     /**
-     * @return the activeServices
+     * @return the enabledServices
      */
-    public List<String> getActiveServices() {
-            return activeServices;
+    public List<String> getEnabledServices() {
+            return enabledServices;
     }
 
     /**
-     * @param activeServices the active3Services to set
+     * @param enabledServices the enabledServices to set
      */
-    public void setActiveServices(List<String> activeServices) {
-            this.activeServices = activeServices;
+    public void setEnabledServices(List<String> enabledServices) {
+            this.enabledServices = enabledServices;
     }
 
     /**

Modified: incubator/ambari/trunk/controller/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/pom.xml?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/pom.xml (original)
+++ incubator/ambari/trunk/controller/pom.xml Fri Dec  2 00:46:19 2011
@@ -311,6 +311,12 @@
         <version>1.8</version>
         <scope>test</scope>
       </dependency>
+      <dependency>
+        <groupId>org.mockito</groupId>
+        <artifactId>mockito-all</artifactId>
+        <version>1.8.5</version>
+        <scope>test</scope>
+      </dependency>
     </dependencies>
 
   <distributionManagement>

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=1209323&r1=1209322&r2=1209323&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 Fri Dec  2 00:46:19 2011
@@ -27,16 +27,16 @@ import java.util.concurrent.ConcurrentHa
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 
-import org.apache.ambari.common.rest.entities.Component;
-import org.apache.ambari.common.rest.entities.ConfigurationCategory;
-import org.apache.ambari.common.rest.entities.Property;
-import org.apache.ambari.common.rest.entities.Role;
-import org.apache.ambari.common.rest.entities.Stack;
 import org.apache.ambari.common.rest.entities.ClusterDefinition;
 import org.apache.ambari.common.rest.entities.ClusterInformation;
 import org.apache.ambari.common.rest.entities.ClusterState;
+import org.apache.ambari.common.rest.entities.Component;
+import org.apache.ambari.common.rest.entities.ConfigurationCategory;
 import org.apache.ambari.common.rest.entities.Node;
+import org.apache.ambari.common.rest.entities.Property;
+import org.apache.ambari.common.rest.entities.Role;
 import org.apache.ambari.common.rest.entities.RoleToNodes;
+import org.apache.ambari.common.rest.entities.Stack;
 import org.apache.ambari.datastore.DataStoreFactory;
 import org.apache.ambari.datastore.PersistentDataStore;
 import org.apache.ambari.resource.statemachine.ClusterFSM;
@@ -222,11 +222,11 @@ public class Clusters {
         } else {
             newcd.setGoalState(cls.getClusterDefinition(-1).getGoalState());
         }
-        if (c.getActiveServices() != null && !c.getActiveServices().equals(cls.getClusterDefinition(-1).getActiveServices())) {
-            newcd.setActiveServices(c.getActiveServices());
+        if (c.getEnabledServices() != null && !c.getEnabledServices().equals(cls.getClusterDefinition(-1).getEnabledServices())) {
+            newcd.setEnabledServices(c.getEnabledServices());
             clsDefChanged = true;
         } else {
-            newcd.setActiveServices(cls.getClusterDefinition(-1).getActiveServices());
+            newcd.setEnabledServices(cls.getClusterDefinition(-1).getEnabledServices());
         }
         
         /*
@@ -435,10 +435,10 @@ public class Clusters {
         cdef.setRevision(null);
         
         // TODO: Add the list of active services by querying pluging component.
-        if (cdef.getActiveServices() == null) {
+        if (cdef.getEnabledServices() == null) {
             List<String> services = new ArrayList<String>();
             services.add("ALL");
-            cdef.setActiveServices(services);
+            cdef.setEnabledServices(services);
         }    
     }
     

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/config/Examples.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/config/Examples.java?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/config/Examples.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/rest/config/Examples.java Fri Dec  2 00:46:19 2011
@@ -52,7 +52,7 @@ public class Examples {
         CLUSTER_DEFINITION.setGoalState(ClusterState.CLUSTER_STATE_ATTIC);
         activeServices.add("hdfs");
         activeServices.add("mapred");
-        CLUSTER_DEFINITION.setActiveServices(activeServices);
+        CLUSTER_DEFINITION.setEnabledServices(activeServices);
         
         String nodes = "jt-nodex,nn-nodex,hostname-1x,hostname-2x,hostname-3x,"+
                        "hostname-4x,node-2x,node-3x,node-4x";  

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterImpl.java Fri Dec  2 00:46:19 2011
@@ -28,7 +28,6 @@ import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
-import org.apache.ambari.common.rest.entities.ClusterDefinition;
 import org.apache.ambari.common.rest.entities.ClusterState;
 import org.apache.ambari.common.state.MultipleArcTransition;
 import org.apache.ambari.common.state.SingleArcTransition;
@@ -36,8 +35,6 @@ import org.apache.ambari.common.state.St
 import org.apache.ambari.common.state.StateMachineFactory;
 import org.apache.ambari.components.ComponentPlugin;
 import org.apache.ambari.controller.Cluster;
-import org.apache.ambari.controller.Clusters;
-import org.apache.ambari.controller.HeartbeatHandler;
 import org.apache.ambari.event.EventHandler;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -83,10 +80,10 @@ public class ClusterImpl implements Clus
   .addTransition(ClusterStateFSM.FAIL, ClusterStateFSM.STOPPING, 
       ClusterEventType.STOP)
       
-  .addTransition(ClusterStateFSM.STOPPING, ClusterStateFSM.STOPPED, 
+  .addTransition(ClusterStateFSM.STOPPING, ClusterStateFSM.INACTIVE, 
       ClusterEventType.STOP_SUCCESS)
       
-  .addTransition(ClusterStateFSM.STOPPED, ClusterStateFSM.STOPPED, 
+  .addTransition(ClusterStateFSM.INACTIVE, ClusterStateFSM.INACTIVE, 
       ClusterEventType.STOP_SUCCESS)
       
   .addTransition(ClusterStateFSM.STOPPING, ClusterStateFSM.UNCLEAN_STOP, 
@@ -117,14 +114,23 @@ public class ClusterImpl implements Clus
     this.stateMachine = stateMachineFactory.make(this);
     List<ServiceFSM> serviceImpls = new ArrayList<ServiceFSM>();
     for (String service : 
-      cluster.getClusterDefinition(revision).getActiveServices()) {
-      ServiceImpl serviceImpl = new ServiceImpl(cluster, this, service);
-      serviceImpls.add(serviceImpl);
+      cluster.getClusterDefinition(revision).getEnabledServices()) {
+      if(hasActiveRoles(cluster, service)){
+        ServiceImpl serviceImpl = new ServiceImpl(cluster, this, service);
+        serviceImpls.add(serviceImpl);
+      }
     }
     this.services = serviceImpls;
     this.clusterState = clusterState;
   }
-  
+
+  private boolean hasActiveRoles(Cluster cluster, String serviceName)
+      throws IOException {
+    ComponentPlugin plugin = cluster.getComponentDefinition(serviceName);
+    String[] roles = plugin.getActiveRoles();
+    return roles.length > 0;
+  }
+
   public ClusterStateFSM getState() {
     return stateMachine.getCurrentState();
   }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterStateFSM.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterStateFSM.java?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterStateFSM.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/ClusterStateFSM.java Fri Dec  2 00:46:19 2011
@@ -18,5 +18,5 @@
 package org.apache.ambari.resource.statemachine;
 
 public enum ClusterStateFSM {
-  INACTIVE, STARTING, ACTIVE, FAIL, ATTIC, STOPPING, UNCLEAN_STOP, STOPPED
+  INACTIVE, STARTING, ACTIVE, FAIL, ATTIC, STOPPING, UNCLEAN_STOP
 }
\ No newline at end of file

Modified: incubator/ambari/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/pom.xml?rev=1209323&r1=1209322&r2=1209323&view=diff
==============================================================================
--- incubator/ambari/trunk/pom.xml (original)
+++ incubator/ambari/trunk/pom.xml Fri Dec  2 00:46:19 2011
@@ -295,7 +295,7 @@
               <phase>test</phase>
               <argLine>-Xmx1024m</argLine>
               <includes>
-                <include>**/Test*.java</include>
+                <include>**/*Test.java</include>
               </includes>
               <excludes>
                 <exclude>**/IntegrationTest*.java</exclude>