incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r1179004 - in /incubator/ambari/trunk: ./ controller/src/main/java/org/apache/ambari/resource/statemachine/
Date Tue, 04 Oct 2011 23:06:10 GMT
Author: ddas
Date: Tue Oct  4 23:06:10 2011
New Revision: 1179004

URL: http://svn.apache.org/viewvc?rev=1179004&view=rev
Log:
AMBARI-37. Tidies up a bit the statemachine API and related classes. Contributed by Devaraj
Das.

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Cluster.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/StateMachineInvoker.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1179004&r1=1179003&r2=1179004&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Tue Oct  4 23:06:10 2011
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-37. Tidies up a bit the statemachine API and related classes (ddas)
+
   AMBARI-35. Replaces the counters for keeping track of service/role start/stop
   with iterators. (ddas)
 

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Cluster.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Cluster.java?rev=1179004&r1=1179003&r2=1179004&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Cluster.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/Cluster.java
Tue Oct  4 23:06:10 2011
@@ -25,6 +25,5 @@ public interface Cluster extends LifeCyc
   public ClusterState getState();
   public Map<String, String> getServiceStates();
   public String getClusterName();
-  public void addServices(List<Service> services);
   public void terminate();
 }

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=1179004&r1=1179003&r2=1179004&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
Tue Oct  4 23:06:10 2011
@@ -17,6 +17,7 @@
 */
 package org.apache.ambari.resource.statemachine;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.HashMap;
@@ -51,33 +52,44 @@ public class ClusterImpl implements Clus
    */
 
   private static final StateMachineFactory
-  <ClusterImpl,ClusterState,ClusterEventType,ClusterEvent>
-  stateMachineFactory = 
-  new StateMachineFactory
-  <ClusterImpl,ClusterState,ClusterEventType,ClusterEvent>(ClusterState.INACTIVE)
+  <ClusterImpl,ClusterState,ClusterEventType,ClusterEvent> stateMachineFactory 
+          = new StateMachineFactory<ClusterImpl,ClusterState,ClusterEventType,
+          ClusterEvent>(ClusterState.INACTIVE)
+  
   .addTransition(ClusterState.INACTIVE, ClusterState.STARTING, 
       ClusterEventType.START, new StartClusterTransition())
+      
   .addTransition(ClusterState.STARTING, EnumSet.of(ClusterState.ACTIVE, 
       ClusterState.STARTING), ClusterEventType.START_SUCCESS, 
       new ServiceStartedTransition())
+      
   .addTransition(ClusterState.STARTING, ClusterState.FAIL, 
       ClusterEventType.START_FAILURE)
+      
   .addTransition(ClusterState.ACTIVE, ClusterState.STOPPING, 
       ClusterEventType.STOP)
+      
   .addTransition(ClusterState.STOPPING, ClusterState.INACTIVE, 
       ClusterEventType.STOP_SUCCESS)
+      
   .addTransition(ClusterState.STOPPING, ClusterState.UNCLEAN_STOP, 
       ClusterEventType.STOP_FAILURE)
+      
   .addTransition(ClusterState.FAIL, ClusterState.STOPPING, 
       ClusterEventType.STOP)
+      
   .addTransition(ClusterState.STOPPING, ClusterState.INACTIVE, 
       ClusterEventType.STOP_SUCCESS)
+      
   .addTransition(ClusterState.STOPPING, ClusterState.UNCLEAN_STOP, 
       ClusterEventType.STOP_FAILURE)
+      
   .addTransition(ClusterState.INACTIVE, ClusterState.ATTIC, 
       ClusterEventType.RELEASE_NODES)
+      
   .addTransition(ClusterState.ATTIC, ClusterState.INACTIVE, 
       ClusterEventType.ADD_NODES)
+      
   .installTopology();
   
   private List<Service> services;
@@ -89,19 +101,20 @@ public class ClusterImpl implements Clus
   private String clusterName;
   private Iterator<Service> iterator;
     
-  public ClusterImpl(String name, List<Service> services) {
+  public ClusterImpl(String name, List<String> services) throws IOException {
     this.clusterName = name;
     ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
     this.readLock = readWriteLock.readLock();
     this.writeLock = readWriteLock.writeLock();
     this.stateMachine = stateMachineFactory.make(this);
-    this.services = services;
+    List<Service> serviceImpls = new ArrayList<Service>();
+    for (String service : services) {
+      ServiceImpl serviceImpl = new ServiceImpl(this, service);
+      serviceImpls.add(serviceImpl);
+    }
+    this.services = serviceImpls;
   }
   
-  public ClusterImpl(String name) {
-    this(name, new ArrayList<Service>());
-  }
-
   @Override
   public ClusterState getState() {
     return stateMachine.getCurrentState();
@@ -121,12 +134,6 @@ public class ClusterImpl implements Clus
     return stateMachine;
   }
   
-  @Override  
-  public void addServices(List<Service> services) {
-    //The services start in the order they appear in the list
-    this.services.addAll(services);
-  }
-  
   private Service getFirstService() {
     //this call should reset the iterator
     iterator = services.iterator();

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/StateMachineInvoker.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/StateMachineInvoker.java?rev=1179004&r1=1179003&r2=1179004&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/StateMachineInvoker.java
(original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/resource/statemachine/StateMachineInvoker.java
Tue Oct  4 23:06:10 2011
@@ -18,7 +18,6 @@
 package org.apache.ambari.resource.statemachine;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -73,27 +72,14 @@ public class StateMachineInvoker {
   private static ConcurrentMap<String, Cluster> clusters = 
       new ConcurrentHashMap<String, Cluster>();
   
-  public static Cluster createCluster(String clusterId) {
-    ClusterImpl cluster = new ClusterImpl(clusterId);
+  public static Cluster createCluster(String clusterId, 
+      List<String> services) throws IOException {
+    ClusterImpl cluster = new ClusterImpl(clusterId, services);
     clusters.put(clusterId, cluster);
     return cluster;
   }
   
   public static Cluster getStateMachineClusterInstance(String clusterId) {
     return clusters.get(clusterId);
-  }
-  
-  public static Service addServiceInCluster(Cluster cluster, String serviceName) 
-      throws IOException {
-    Service service = new ServiceImpl(cluster, serviceName);
-    return addServiceInCluster(cluster, service);
-  }
-  
-  public static Service addServiceInCluster(Cluster cluster, Service service) {
-    List<Service> serviceList = new ArrayList<Service>();
-    serviceList.add(service);
-    cluster.addServices(serviceList);
-    return service;
-  }
-    
+  }    
 }



Mime
View raw message