ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject ambari git commit: AMBARI-18191. Restart all required services operation failed at Metrics Collector since HDFS was not yet up. (swagle)
Date Wed, 07 Sep 2016 20:03:48 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 535039422 -> b4c8c0da3


AMBARI-18191. Restart all required services operation failed at Metrics Collector since HDFS
was not yet up. (swagle)


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

Branch: refs/heads/branch-2.4
Commit: b4c8c0da3e81800647eca3a434145dc3e167273b
Parents: 5350394
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Wed Sep 7 11:04:17 2016 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Wed Sep 7 11:04:17 2016 -0700

----------------------------------------------------------------------
 .../server/metadata/RoleCommandOrder.java       | 40 +++++++++++--
 .../server/metadata/RoleCommandOrderTest.java   | 59 ++++++++++++++++++++
 2 files changed, 95 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b4c8c0da/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java
b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java
index f3356da..bbdb808 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrder.java
@@ -113,10 +113,7 @@ public class RoleCommandOrder {
   /**
    * key -> blocked role command value -> set of blocker role commands.
    */
-  private Map<RoleCommandPair, Set<RoleCommandPair>> dependencies =
-          new HashMap<RoleCommandPair, Set<RoleCommandPair>>();
-
-
+  private Map<RoleCommandPair, Set<RoleCommandPair>> dependencies = new HashMap<>();
 
   /**
    * Add a pair of tuples where the tuple defined by the first two parameters are blocked
on
@@ -224,6 +221,7 @@ public class RoleCommandOrder {
       addDependencies(ResourceManagerHASection);
     }
     extendTransitiveDependency();
+    addMissingRestartDependencies();
   }
 
   /**
@@ -314,6 +312,40 @@ public class RoleCommandOrder {
     }
   }
 
+  /**
+   * RoleCommand.RESTART dependencies that are missing from role_command_order.json
+   * will be added to the RCO graph to make sure RESTART ALL type of
+   * operations respect the RCO. Only those @{@link RoleCommandPair} will be
+   * added which do not have any RESTART definition in the role_command_order.json
+   * by copying dependencies from the START operation.
+   */
+  private void addMissingRestartDependencies() {
+    Map<RoleCommandPair, Set<RoleCommandPair>> missingDependencies = new HashMap<>();
+    for (Map.Entry<RoleCommandPair, Set<RoleCommandPair>> roleCommandPairSetEntry
: this.dependencies.entrySet()) {
+      RoleCommandPair roleCommandPair = roleCommandPairSetEntry.getKey();
+      if (roleCommandPair.getCmd().equals(RoleCommand.START)) {
+        RoleCommandPair restartPair = new RoleCommandPair(roleCommandPair.getRole(), RoleCommand.RESTART);
+        if (!this.dependencies.containsKey(restartPair)) {
+          // Assumption that if defined the RESTART deps are complete
+          Set<RoleCommandPair> roleCommandDeps = new HashSet<>();
+          for (RoleCommandPair rco : roleCommandPairSetEntry.getValue()) {
+            // Change dependency Role to match source
+            roleCommandDeps.add(new RoleCommandPair(rco.getRole(), RoleCommand.RESTART));
+          }
+
+          if (LOG.isDebugEnabled()) {
+            LOG.debug("Adding dependency for " + restartPair + ", " +
+              "dependencies => " + roleCommandDeps);
+          }
+          missingDependencies.put(restartPair, roleCommandDeps);
+        }
+      }
+    }
+    if (!missingDependencies.isEmpty()) {
+      this.dependencies.putAll(missingDependencies);
+    }
+  }
+
   private int compareCommands(RoleGraphNode rgn1, RoleGraphNode rgn2) {
     // TODO: add proper order comparison support for RoleCommand.ACTIONEXECUTE
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b4c8c0da/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java
index 7f852f0..a03f05b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java
@@ -29,6 +29,7 @@ import static org.easymock.EasyMock.verify;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -268,6 +269,64 @@ public class RoleCommandOrderTest {
     assertTrue(isZookeeperStartPresent);
   }
 
+  @Test
+  public void testMissingRestartDependenciesAdded() throws Exception {
+    RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
+    ClusterImpl cluster = createMock(ClusterImpl.class);
+    ServiceComponentHost sch1 = createMock(ServiceComponentHostImpl.class);
+    ServiceComponentHost sch2 = createMock(ServiceComponentHostImpl.class);
+    expect(cluster.getService("GLUSTERFS")).andReturn(null);
+
+
+    Map<String, ServiceComponentHost> hostComponents = new HashMap<>();
+    hostComponents.put("1", sch1);
+    hostComponents.put("2", sch2);
+
+    Service yarnService = createMock(Service.class);
+    ServiceComponent resourcemanagerSC = createMock(ServiceComponent.class);
+
+    expect(cluster.getService("YARN")).andReturn(yarnService).atLeastOnce();
+    expect(cluster.getService("HDFS")).andReturn(null);
+    expect(yarnService.getServiceComponent("RESOURCEMANAGER")).andReturn(resourcemanagerSC).anyTimes();
+    expect(resourcemanagerSC.getServiceComponentHosts()).andReturn(hostComponents).anyTimes();
+    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
+
+    replay(cluster, yarnService, sch1, sch2, resourcemanagerSC);
+
+    rco.initialize(cluster);
+
+    verify(cluster, yarnService);
+
+    Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies();
+    assertNotNull(deps);
+    Map<RoleCommandPair, Set<RoleCommandPair>> startRCOs = new HashMap<>();
+    Map<RoleCommandPair, Set<RoleCommandPair>> restartRCOs = new HashMap<>();
+
+    for (Map.Entry<RoleCommandPair, Set<RoleCommandPair>> dep : deps.entrySet())
{
+      if (dep.getKey().getCmd().equals(RoleCommand.START)) {
+        startRCOs.put(dep.getKey(), dep.getValue());
+      }
+      if (dep.getKey().getCmd().equals(RoleCommand.RESTART)) {
+        restartRCOs.put(dep.getKey(), dep.getValue());
+      }
+    }
+
+    assertFalse(startRCOs.isEmpty());
+    assertFalse(restartRCOs.isEmpty());
+    assertEquals(startRCOs.size(), restartRCOs.size());
+    // Verify one
+    Map.Entry<RoleCommandPair, Set<RoleCommandPair>> entry = restartRCOs.entrySet().iterator().next();
+    assertEquals(RoleCommand.RESTART, entry.getKey().getCmd());
+    for (RoleCommandPair pair : entry.getValue()) {
+      assertEquals(RoleCommand.RESTART, pair.getCmd());
+    }
+    // Verify all
+    for (Map.Entry<RoleCommandPair, Set<RoleCommandPair>> startEntry : startRCOs.entrySet())
{
+      assertTrue(restartRCOs.containsKey(
+        new RoleCommandPair(startEntry.getKey().getRole(), RoleCommand.RESTART)));
+    }
+  }
+
 
   @Test
   public void testAddDependencies() throws IOException {


Mime
View raw message