You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by tb...@apache.org on 2015/04/05 01:38:10 UTC

ambari git commit: AMBARI-10359 - Ambari : generate topology script on service start (tbeerbower)

Repository: ambari
Updated Branches:
  refs/heads/trunk fc18e469b -> f4a44bdb5


AMBARI-10359 - Ambari : generate topology script on service start (tbeerbower)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f4a44bdb
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f4a44bdb
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f4a44bdb

Branch: refs/heads/trunk
Commit: f4a44bdb53e9d985787abbcb88a0c810361257ec
Parents: fc18e46
Author: tbeerbower <tb...@hortonworks.com>
Authored: Sat Apr 4 19:38:01 2015 -0400
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Sat Apr 4 19:38:01 2015 -0400

----------------------------------------------------------------------
 .../AmbariCustomCommandExecutionHelper.java     | 15 ++++++++---
 .../AmbariManagementControllerImpl.java         | 12 ++++++---
 .../AmbariCustomCommandExecutionHelperTest.java | 27 ++++++++++++++------
 3 files changed, 40 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f4a44bdb/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index cfc1d4e..2680851 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
@@ -148,6 +148,7 @@ public class AmbariCustomCommandExecutionHelper {
   private OsFamily os_family;
 
   protected static final String SERVICE_CHECK_COMMAND_NAME = "SERVICE_CHECK";
+  protected static final String START_COMMAND_NAME = "START";
   protected static final String RESTART_COMMAND_NAME = "RESTART";
   protected static final String INSTALL_COMMAND_NAME = "INSTALL";
   public static final String DECOMMISSION_COMMAND_NAME = "DECOMMISSION";
@@ -1089,10 +1090,18 @@ public class AmbariCustomCommandExecutionHelper {
     return hostLevelParams;
   }
 
-  // determine whether or not the action should trigger a topology refresh
-  private boolean isTopologyRefreshRequired(String actionName, String clusterName, String serviceName)
+  /**
+   * Determine whether or not the action should trigger a topology refresh.
+   *
+   * @param actionName   the action name (i.e. START, RESTART)
+   * @param clusterName  the cluster name
+   * @param serviceName  the service name
+   *
+   * @return true if a topology refresh is required for the action
+   */
+  public boolean isTopologyRefreshRequired(String actionName, String clusterName, String serviceName)
       throws AmbariException {
-    if (actionName.contains(RESTART_COMMAND_NAME)) {
+    if (actionName.equals(START_COMMAND_NAME) || actionName.equals(RESTART_COMMAND_NAME)) {
       Cluster cluster = clusters.getCluster(clusterName);
       StackId stackId = cluster.getDesiredStackVersion();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f4a44bdb/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index a3ede22..f323920 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -1666,11 +1666,12 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
                                 )
                                 throws AmbariException {
 
+    String serviceName = scHost.getServiceName();
+
     stage.addHostRoleExecutionCommand(scHost.getHostName(), Role.valueOf(scHost
       .getServiceComponentName()), roleCommand,
       event, scHost.getClusterName(),
-      scHost.getServiceName(), false);
-    String serviceName = scHost.getServiceName();
+        serviceName, false);
     String componentName = event.getServiceComponentName();
     String hostname = scHost.getHostName();
     String osFamily = clusters.getHost(hostname).getOsFamily();
@@ -1743,13 +1744,18 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
       serviceInfo.getServicePackageFolder());
     commandParams.put(HOOKS_FOLDER, stackInfo.getStackHooksFolder());
 
+    String clusterName = cluster.getClusterName();
+    if (customCommandExecutionHelper.isTopologyRefreshRequired(roleCommand.name(), clusterName, serviceName)) {
+      commandParams.put(ExecutionCommand.KeyNames.REFRESH_TOPOLOGY, "True");
+    }
+
     execCmd.setCommandParams(commandParams);
 
     String repoInfo = customCommandExecutionHelper.getRepoInfo(cluster, host);
     if (LOG.isDebugEnabled()) {
       LOG.debug("Sending repo information to agent"
         + ", hostname=" + scHost.getHostName()
-        + ", clusterName=" + cluster.getClusterName()
+        + ", clusterName=" + clusterName
         + ", stackInfo=" + stackId.getStackId()
         + ", repoInfo=" + repoInfo);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f4a44bdb/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index ee56ea7..947a76f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
@@ -106,7 +106,7 @@ public class
   @Test
   public void testRefreshQueueCustomCommand() {
     try {
-      createClusterFixture();
+      createClusterFixture("HDP-2.0.6");
       
       Map<String, String> requestProperties = new HashMap<String, String>() {
         {
@@ -151,7 +151,7 @@ public class
 
   @Test
   public void testHostsFilterHealthy() throws Exception {
-    createClusterFixture();
+    createClusterFixture("HDP-2.0.6");
 
     Map<String, String> requestProperties = new HashMap<String, String>() {
       {
@@ -192,7 +192,7 @@ public class
   @Test
   public void testHostsFilterUnhealthyHost(){
     try {
-      createClusterFixture();
+      createClusterFixture("HDP-2.0.6");
 
       // Set custom status to host
       clusters.getHost("c6402").setState(HostState.HEARTBEAT_LOST);
@@ -236,7 +236,7 @@ public class
   @Test
   public void testHostsFilterUnhealthyComponent(){
     try {
-      createClusterFixture();
+      createClusterFixture("HDP-2.0.6");
 
       // Set custom status to host
       clusters.getCluster("c1").getService("GANGLIA").getServiceComponent("GANGLIA_MONITOR").getServiceComponentHost("c6402")
@@ -278,8 +278,19 @@ public class
     }
   }
 
-  private void createClusterFixture() throws AmbariException {
-    createCluster("c1");
+  @Test
+  public void testIsTopologyRefreshRequired() throws Exception {
+    AmbariCustomCommandExecutionHelper helper = injector.getInstance(AmbariCustomCommandExecutionHelper.class);
+
+    createClusterFixture("HDP-2.1.1");
+
+    Assert.assertTrue(helper.isTopologyRefreshRequired("START", "c1", "HDFS"));
+    Assert.assertTrue(helper.isTopologyRefreshRequired("RESTART", "c1", "HDFS"));
+    Assert.assertFalse(helper.isTopologyRefreshRequired("STOP", "c1", "HDFS"));
+  }
+
+  private void createClusterFixture(String stackVersion) throws AmbariException {
+    createCluster("c1", stackVersion);
     addHost("c6401","c1");
     addHost("c6402","c1");
     
@@ -318,9 +329,9 @@ public class
     host.setHostAttributes(hostAttributes);
   }
 
-  private void createCluster(String clusterName) throws AmbariException {
+  private void createCluster(String clusterName, String stackVersion) throws AmbariException {
     ClusterRequest r = new ClusterRequest(null, clusterName, State.INSTALLED.name(),
-        SecurityType.NONE, "HDP-2.0.6", null);
+        SecurityType.NONE, stackVersion, null);
     controller.createCluster(r);
   }