Pārlūkot izejas kodu

AMBARI-830. Various fixes and tests for controller implementation. (hitesh)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1395858 13f79535-47bb-0310-9956-ffa450edef68
Hitesh Shah 13 gadi atpakaļ
vecāks
revīzija
d18d9bacc8

+ 2 - 0
AMBARI-666-CHANGES.txt

@@ -213,6 +213,8 @@ AMBARI-666 branch (unreleased changes)
 
   BUG FIXES
 
+  AMBARI-830. Various fixes and tests for controller implementation. (hitesh)
+
   AMBARI-808. Handle appropriate start/stop/install/.. events at their respective
   failed states. (hitesh)
 

+ 2 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -845,6 +845,7 @@ public class AmbariManagementControllerImpl implements
         sch.setDesiredState(newState);
       }
     }
+    s.setDesiredState(newState);
 
     if (LOG.isDebugEnabled()) {
       LOG.debug("Triggering Action Manager"
@@ -991,6 +992,7 @@ public class AmbariManagementControllerImpl implements
     for (ServiceComponentHost sch : changedScHosts) {
       sch.setDesiredState(newState);
     }
+    sc.setDesiredState(newState);
 
     actionManager.sendActions(stages);
 

+ 2 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java

@@ -87,4 +87,6 @@ public interface Cluster {
 
   public ClusterResponse convertToResponse();
 
+  public void debugDump(StringBuilder sb);
+
 }

+ 2 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java

@@ -94,4 +94,6 @@ public interface Clusters {
   public void mapHostsToCluster(List<String> hostnames, String clusterName)
       throws AmbariException;
 
+  public void debugDump(StringBuilder sb);
+
 }

+ 2 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/Service.java

@@ -60,4 +60,6 @@ public interface Service {
 
   public ServiceResponse convertToResponse();
 
+  public void debugDump(StringBuilder sb);
+
 }

+ 2 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java

@@ -62,4 +62,6 @@ public interface ServiceComponent {
       throws AmbariException ;
 
   public ServiceComponentResponse convertToResponse();
+
+  public void debugDump(StringBuilder sb);
 }

+ 2 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java

@@ -97,4 +97,6 @@ public interface ServiceComponentHost {
 
   public ServiceComponentHostResponse convertToResponse();
 
+  public void debugDump(StringBuilder sb);
+
 }

+ 22 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java

@@ -209,4 +209,26 @@ public class ServiceComponentImpl implements ServiceComponent {
     return service.getCluster().getClusterName();
   }
 
+  @Override
+  public synchronized void debugDump(StringBuilder sb) {
+    sb.append("ServiceComponent={ serviceComponentName=" + componentName
+        + ", clusterName=" + service.getCluster().getClusterName()
+        + ", clusterId=" + service.getCluster().getClusterId()
+        + ", serviceName=" + service.getName()
+        + ", desiredStackVersion=" + desiredStackVersion
+        + ", desiredState=" + desiredState
+        + ", hostcomponents=[ ");
+    boolean first = true;
+    for(ServiceComponentHost sch : hostComponents.values()) {
+      if (!first) {
+        sb.append(" , ");
+        first = false;
+      }
+      sb.append("\n        ");
+      sch.debugDump(sb);
+      sb.append(" ");
+    }
+    sb.append(" ] }");
+  }
+
 }

+ 21 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java

@@ -193,4 +193,25 @@ public class ServiceImpl implements Service {
     return cluster;
   }
 
+  @Override
+  public synchronized void debugDump(StringBuilder sb) {
+    sb.append("Service={ serviceName=" + serviceName
+        + ", clusterName=" + cluster.getClusterName()
+        + ", clusterId=" + cluster.getClusterId()
+        + ", desiredStackVersion=" + desiredStackVersion.getStackVersion()
+        + ", desiredState=" + desiredState.toString()
+        + ", components=[ ");
+    boolean first = true;
+    for(ServiceComponent sc : components.values()) {
+      if (!first) {
+        sb.append(" , ");
+        first = false;
+      }
+      sb.append("\n      ");
+      sc.debugDump(sb);
+      sb.append(" ");
+    }
+    sb.append(" ] }");
+  }
+
 }

+ 4 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/StackVersion.java

@@ -58,4 +58,8 @@ public class StackVersion {
     return result;
   }
 
+  public String toString() {
+    return this.stackVersion;
+  }
+
 }

+ 20 - 2
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java

@@ -219,8 +219,8 @@ public class ClusterImpl implements Cluster {
       LOG.debug("Changing DesiredStackVersion of Cluster"
         + ", clusterName=" + clusterName
         + ", clusterId=" + clusterId
-        + ", currentStackVersion=" + this.desiredStackVersion
-        + ", newStackVersion=" + stackVersion);
+        + ", currentDesiredStackVersion=" + this.desiredStackVersion
+        + ", newDesiredStackVersion=" + stackVersion);
     }
     this.desiredStackVersion = stackVersion;
   }
@@ -264,4 +264,22 @@ public class ClusterImpl implements Cluster {
     return r;
   }
 
+  public void debugDump(StringBuilder sb) {
+    sb.append("Cluster={ clusterName=" + clusterName
+        + ", clusterId=" + clusterId
+        + ", desiredStackVersion=" + desiredStackVersion.getStackVersion()
+        + ", services=[ ");
+    boolean first = true;
+    for(Service s : services.values()) {
+      if (!first) {
+        sb.append(" , ");
+        first = false;
+      }
+      sb.append("\n    ");
+      s.debugDump(sb);
+      sb.append(" ");
+    }
+    sb.append(" ] }");
+  }
+
 }

+ 16 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java

@@ -156,4 +156,20 @@ public class ClustersImpl implements Clusters {
       }
     }
   }
+
+  public void debugDump(StringBuilder sb) {
+    sb.append("Clusters=[ ");
+    boolean first = true;
+    for(Cluster c : clusters.values()) {
+      if (!first) {
+        sb.append(" , ");
+        first = false;
+      }
+      sb.append("\n  ");
+      c.debugDump(sb);
+      sb.append(" ");
+    }
+    sb.append(" ]");
+  }
+
 }

+ 19 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java

@@ -745,4 +745,23 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
     return serviceComponent.getClusterName();
   }
 
+  @Override
+  public void debugDump(StringBuilder sb) {
+    try {
+      readLock.lock();
+      sb.append("ServiceComponentHost={ hostname=" + hostName
+          + ", serviceComponentName=" + serviceComponent.getName()
+          + ", clusterName=" + serviceComponent.getClusterName()
+          + ", serviceName=" + serviceComponent.getServiceName()
+          + ", desiredStackVersion=" + desiredStackVersion
+          + ", desiredState=" + desiredState
+          + ", stackVersion=" + stackVersion
+          + ", state=" + getState()
+          + " }");
+    }
+    finally {
+      readLock.unlock();
+    }
+  }
+
 }

+ 28 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

@@ -32,6 +32,8 @@ import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.Stage;
 import org.apache.ambari.server.agent.ActionQueue;
 import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.ServiceComponent;
+import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.cluster.ClustersImpl;
 import org.apache.ambari.server.utils.StageUtils;
@@ -338,6 +340,17 @@ public class AmbariManagementControllerTest {
         State.INSTALLED.toString());
 
     controller.updateService(r1);
+    Assert.assertEquals(State.INSTALLED,
+        clusters.getCluster(clusterName).getService(serviceName)
+        .getDesiredState());
+    for (ServiceComponent sc :
+      clusters.getCluster(clusterName).getService(serviceName)
+      .getServiceComponents().values()) {
+      Assert.assertEquals(State.INSTALLED, sc.getDesiredState());
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        Assert.assertEquals(State.INSTALLED, sch.getDesiredState());
+      }
+    }
 
     // TODO validate stages?
     List<Stage> stages = db.getAllStages(1);
@@ -361,6 +374,17 @@ public class AmbariManagementControllerTest {
         State.STARTED.toString());
 
     controller.updateService(r2);
+    Assert.assertEquals(State.STARTED,
+        clusters.getCluster(clusterName).getService(serviceName)
+        .getDesiredState());
+    for (ServiceComponent sc :
+      clusters.getCluster(clusterName).getService(serviceName)
+      .getServiceComponents().values()) {
+      Assert.assertEquals(State.STARTED, sc.getDesiredState());
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        Assert.assertEquals(State.STARTED, sch.getDesiredState());
+      }
+    }
 
     // TODO validate stages?
     stages = db.getAllStages(2);
@@ -380,6 +404,10 @@ public class AmbariManagementControllerTest {
       }
     }
 
+    StringBuilder sb = new StringBuilder();
+    clusters.debugDump(sb);
+    LOG.info("Cluster Dump: " + sb.toString());
+
   }
 
 

+ 0 - 1
ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImplTest.java

@@ -302,7 +302,6 @@ public class ServiceComponentHostImplTest {
         State.WIPING_OUT,
         State.WIPEOUT_FAILED,
         State.INIT);
-
   }
 
 }