You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2016/10/20 16:09:46 UTC
[1/2] ambari git commit: AMBARI-18553. Provision actions to happen
based only on specified dependencies (magyari_sandor)
Repository: ambari
Updated Branches:
refs/heads/trunk d9bc653a0 -> 5fdc9f97e
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/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 a03f05b..a2a098f 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
@@ -18,18 +18,8 @@
package org.apache.ambari.server.metadata;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertTrue;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-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;
@@ -38,12 +28,9 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
-import junit.framework.Assert;
-
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.RoleCommand;
-import org.apache.ambari.server.metadata.RoleCommandOrder.RoleCommandPair;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.state.Service;
@@ -65,9 +52,20 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
+import junit.framework.Assert;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
public class RoleCommandOrderTest {
private Injector injector;
+ private RoleCommandOrderProvider roleCommandOrderProvider;
private final static String TEST_RCO_DATA_FILE = "test_rco_data.json";
@@ -75,6 +73,7 @@ public class RoleCommandOrderTest {
public void setup() throws Exception {
injector = Guice.createInjector(new InMemoryDefaultTestModule());
injector.getInstance(GuiceJpaInitializer.class);
+ roleCommandOrderProvider = injector.getInstance(RoleCommandOrderProvider.class);
}
@After
@@ -90,18 +89,19 @@ public class RoleCommandOrderTest {
@Test
public void testInitializeAtGLUSTERFSCluster() throws AmbariException {
- RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
+
ClusterImpl cluster = createMock(ClusterImpl.class);
Service service = createMock(Service.class);
+ expect(cluster.getClusterId()).andReturn(1L);
expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
expect(cluster.getService("GLUSTERFS")).andReturn(service);
expect(cluster.getService("HDFS")).andReturn(null);
expect(cluster.getService("YARN")).andReturn(null);
replay(cluster);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
+
Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies();
- assertTrue("Dependencies are empty before initialization", deps.size() == 0);
- rco.initialize(cluster);
assertTrue("Dependencies are loaded after initialization", deps.size() > 0);
verify(cluster);
// Check that HDFS components are not present in dependencies
@@ -133,10 +133,9 @@ public class RoleCommandOrderTest {
@Test
public void testInitializeAtHDFSCluster() throws AmbariException {
- RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
ClusterImpl cluster = createMock(ClusterImpl.class);
expect(cluster.getService("GLUSTERFS")).andReturn(null);
-
+ expect(cluster.getClusterId()).andReturn(1L);
Service hdfsService = createMock(Service.class);
expect(cluster.getService("HDFS")).andReturn(hdfsService).atLeastOnce();
@@ -147,9 +146,8 @@ public class RoleCommandOrderTest {
replay(cluster);
replay(hdfsService);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies();
- assertTrue("Dependencies are empty before initialization", deps.size() == 0);
- rco.initialize(cluster);
assertTrue("Dependencies are loaded after initialization", deps.size() > 0);
verify(cluster);
verify(hdfsService);
@@ -177,10 +175,10 @@ public class RoleCommandOrderTest {
*/
@Test
public void testInitializeAtHaHDFSCluster() throws AmbariException {
- RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
+
ClusterImpl cluster = createMock(ClusterImpl.class);
expect(cluster.getService("GLUSTERFS")).andReturn(null);
-
+ expect(cluster.getClusterId()).andReturn(1L);
Service hdfsService = createMock(Service.class);
ServiceComponent journalnodeSC = createMock(ServiceComponent.class);
@@ -192,9 +190,8 @@ public class RoleCommandOrderTest {
replay(cluster);
replay(hdfsService);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies();
- assertTrue("Dependencies are empty before initialization", deps.size() == 0);
- rco.initialize(cluster);
assertTrue("Dependencies are loaded after initialization", deps.size() > 0);
verify(cluster);
verify(hdfsService);
@@ -217,12 +214,12 @@ public class RoleCommandOrderTest {
@Test
public void testInitializeAtHaRMCluster() throws AmbariException {
- 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);
-
+ expect(cluster.getClusterId()).andReturn(1L);
Map<String, ServiceComponentHost> hostComponents = new HashMap<String, ServiceComponentHost>();
hostComponents.put("1",sch1);
@@ -239,9 +236,8 @@ public class RoleCommandOrderTest {
replay(cluster, yarnService, sch1, sch2, resourcemanagerSC);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies();
- assertTrue("Dependencies are empty before initialization", deps.size() == 0);
- rco.initialize(cluster);
assertTrue("Dependencies are loaded after initialization", deps.size() > 0);
verify(cluster, yarnService);
// Check that GLUSTERFS components are not present in dependencies
@@ -262,7 +258,7 @@ public class RoleCommandOrderTest {
assertNotNull(rmRoleCommandPairs);
boolean isZookeeperStartPresent = false;
for (RoleCommandPair pair : rmRoleCommandPairs) {
- if (pair.cmd == RoleCommand.START && pair.getRole() == Role.ZOOKEEPER_SERVER) {
+ if (pair.getCmd() == RoleCommand.START && pair.getRole() == Role.ZOOKEEPER_SERVER) {
isZookeeperStartPresent = true;
}
}
@@ -271,12 +267,11 @@ public class RoleCommandOrderTest {
@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);
-
+ expect(cluster.getClusterId()).andReturn(1L);
Map<String, ServiceComponentHost> hostComponents = new HashMap<>();
hostComponents.put("1", sch1);
@@ -293,7 +288,7 @@ public class RoleCommandOrderTest {
replay(cluster, yarnService, sch1, sch2, resourcemanagerSC);
- rco.initialize(cluster);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
verify(cluster, yarnService);
@@ -372,10 +367,10 @@ public class RoleCommandOrderTest {
@Test
public void testInitializeDefault() throws IOException {
- RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
+
ClusterImpl cluster = createMock(ClusterImpl.class);
expect(cluster.getService("GLUSTERFS")).andReturn(null);
-
+ expect(cluster.getClusterId()).andReturn(1L);
Service hdfsService = createMock(Service.class);
expect(cluster.getService("HDFS")).andReturn(hdfsService).atLeastOnce();
@@ -387,7 +382,7 @@ public class RoleCommandOrderTest {
replay(cluster);
replay(hdfsService);
- rco.initialize(cluster);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
verify(cluster);
verify(hdfsService);
@@ -395,7 +390,6 @@ public class RoleCommandOrderTest {
@Test
public void testTransitiveServices() throws AmbariException {
- RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
ClusterImpl cluster = createMock(ClusterImpl.class);
Service hdfsService = createMock(Service.class);
@@ -408,6 +402,7 @@ public class RoleCommandOrderTest {
Service hbaseService = createMock(Service.class);
expect(cluster.getService("HBASE")).andReturn(hbaseService).atLeastOnce();
+ expect(cluster.getClusterId()).andReturn(1L);
expect(hbaseService.getCluster()).andReturn(cluster).anyTimes();
ServiceComponent hbaseMaster = createMock(ServiceComponent.class);
@@ -432,7 +427,7 @@ public class RoleCommandOrderTest {
//replay
replay(cluster, hdfsService, hbaseService, hbaseMaster, namenode);
- rco.initialize(cluster);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
Set<Service> transitiveServices = rco.getTransitiveServices(
cluster.getService("HBASE"), RoleCommand.START);
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleGraphTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleGraphTest.java b/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleGraphTest.java
index 8bead43..28aef22 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleGraphTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleGraphTest.java
@@ -19,10 +19,6 @@
package org.apache.ambari.server.metadata;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import junit.framework.Assert;
-
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.RoleCommand;
@@ -41,15 +37,20 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
-public class RoleGraphTest {
+import junit.framework.Assert;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+public class RoleGraphTest {
private Injector injector;
+ private RoleCommandOrderProvider roleCommandOrderProvider;
@Before
public void setup() throws Exception {
injector = Guice.createInjector(new InMemoryDefaultTestModule());
injector.getInstance(GuiceJpaInitializer.class);
+ roleCommandOrderProvider = injector.getInstance(RoleCommandOrderProvider.class);
}
@After
@@ -59,12 +60,11 @@ public class RoleGraphTest {
@Test
public void testValidateOrder() throws AmbariException {
- RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
ClusterImpl cluster = mock(ClusterImpl.class);
-
when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
+ when(cluster.getClusterId()).thenReturn(1L);
- rco.initialize(cluster);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
RoleGraphNode datanode_upgrade = new RoleGraphNode(Role.DATANODE, RoleCommand.UPGRADE);
RoleGraphNode hdfs_client_upgrade = new RoleGraphNode(Role.HDFS_CLIENT, RoleCommand.UPGRADE);
@@ -133,7 +133,7 @@ public class RoleGraphTest {
when(cluster.getService("HDFS")).thenReturn(hdfsServiceMock);
when(hdfsServiceMock.getServiceComponent("JOURNALNODE")).thenReturn(jnComponentMock);
- rco.initialize(cluster);
+ rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
Assert.assertEquals(1, rco.order(nn_start, jn_start));
Assert.assertEquals(1, rco.order(nn_start, zk_server_start));
Assert.assertEquals(1, rco.order(zkfc_start, nn_start));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/test/java/org/apache/ambari/server/stageplanner/TestStagePlanner.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/stageplanner/TestStagePlanner.java b/ambari-server/src/test/java/org/apache/ambari/server/stageplanner/TestStagePlanner.java
index d26816c..7a37224 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/stageplanner/TestStagePlanner.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/stageplanner/TestStagePlanner.java
@@ -26,9 +26,11 @@ import java.util.List;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.RoleCommand;
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
import org.apache.ambari.server.actionmanager.Stage;
import org.apache.ambari.server.actionmanager.StageFactory;
import org.apache.ambari.server.metadata.RoleCommandOrder;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.state.StackId;
@@ -48,20 +50,21 @@ import com.google.inject.persist.PersistService;
public class TestStagePlanner {
private Injector injector;
- private static StageFactory stageFactory;
@Inject
- StageUtils stageUtils;
-
+ private StageFactory stageFactory;
+ @Inject
+ private RoleCommandOrderProvider roleCommandOrderProvider;
@Inject
- RoleGraphFactory roleGraphFactory;
+ private StageUtils stageUtils;
+ @Inject
+ private RoleGraphFactory roleGraphFactory;
@Before
public void setup() throws Exception {
injector = Guice.createInjector(new InMemoryDefaultTestModule());
injector.getInstance(GuiceJpaInitializer.class);
injector.injectMembers(this);
- stageFactory = injector.getInstance(StageFactory.class);
}
@After
@@ -71,11 +74,10 @@ public class TestStagePlanner {
@Test
public void testSingleStagePlan() throws AmbariException {
- RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
ClusterImpl cluster = mock(ClusterImpl.class);
when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
- rco.initialize(cluster);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
RoleGraph rg = roleGraphFactory.createNew(rco);
String hostname = "dummy";
@@ -87,15 +89,14 @@ public class TestStagePlanner {
}
assertEquals(1, outStages.size());
assertEquals(stage.getExecutionCommands(hostname), outStages.get(0)
- .getExecutionCommands(hostname));
+ .getExecutionCommands(hostname));
}
@Test
public void testMultiStagePlan() {
- RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
ClusterImpl cluster = mock(ClusterImpl.class);
when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
- rco.initialize(cluster);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
RoleGraph rg = roleGraphFactory.createNew(rco);
long now = System.currentTimeMillis();
Stage stage = StageUtils.getATestStage(1, 1, "host1", "", "");
@@ -118,23 +119,22 @@ public class TestStagePlanner {
@Test
public void testRestartStagePlan() {
- RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
ClusterImpl cluster = mock(ClusterImpl.class);
when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
- rco.initialize(cluster);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
RoleGraph rg = roleGraphFactory.createNew(rco);
long now = System.currentTimeMillis();
- Stage stage = stageFactory.createNew(1, "/tmp", "cluster1", 1L, "execution command wrapper test",
- "clusterHostInfo", "commandParamsStage", "hostParamsStage");
+ Stage stage = stageFactory.createNew(1, "/tmp", "cluster1", 1L, "execution command wrapper test",
+ "clusterHostInfo", "commandParamsStage", "hostParamsStage");
stage.setStageId(1);
stage.addServerActionCommand("RESTART", null, Role.HIVE_METASTORE,
- RoleCommand.CUSTOM_COMMAND, "cluster1",
- new ServiceComponentHostServerActionEvent("host2", System.currentTimeMillis()),
- null, "command detail", null, null, false, false);
+ RoleCommand.CUSTOM_COMMAND, "cluster1",
+ new ServiceComponentHostServerActionEvent("host2", System.currentTimeMillis()),
+ null, "command detail", null, null, false, false);
stage.addServerActionCommand("RESTART", null, Role.MYSQL_SERVER,
- RoleCommand.CUSTOM_COMMAND, "cluster1",
- new ServiceComponentHostServerActionEvent("host2", System.currentTimeMillis()),
- null, "command detail", null, null, false, false);
+ RoleCommand.CUSTOM_COMMAND, "cluster1",
+ new ServiceComponentHostServerActionEvent("host2", System.currentTimeMillis()),
+ null, "command detail", null, null, false, false);
System.out.println(stage.toString());
rg.build(stage);
@@ -148,10 +148,9 @@ public class TestStagePlanner {
@Test
public void testManyStages() {
- RoleCommandOrder rco = injector.getInstance(RoleCommandOrder.class);
ClusterImpl cluster = mock(ClusterImpl.class);
when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
- rco.initialize(cluster);
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
RoleGraph rg = roleGraphFactory.createNew(rco);
long now = System.currentTimeMillis();
Stage stage = StageUtils.getATestStage(1, 1, "host1", "", "");
@@ -180,14 +179,14 @@ public class TestStagePlanner {
RoleCommand.START, new ServiceComponentHostStartEvent("OOZIE_SERVER",
"host6", now), "cluster1", "OOZIE", false, false);
stage.addHostRoleExecutionCommand("host7", Role.WEBHCAT_SERVER,
- RoleCommand.START, new ServiceComponentHostStartEvent("WEBHCAT_SERVER",
- "host7", now), "cluster1", "WEBHCAT", false, false);
+ RoleCommand.START, new ServiceComponentHostStartEvent("WEBHCAT_SERVER",
+ "host7", now), "cluster1", "WEBHCAT", false, false);
stage.addHostRoleExecutionCommand("host4", Role.GANGLIA_MONITOR,
- RoleCommand.START, new ServiceComponentHostStartEvent("GANGLIA_MONITOR",
- "host4", now), "cluster1", "GANGLIA", false, false);
+ RoleCommand.START, new ServiceComponentHostStartEvent("GANGLIA_MONITOR",
+ "host4", now), "cluster1", "GANGLIA", false, false);
stage.addHostRoleExecutionCommand("host9", Role.GANGLIA_SERVER,
- RoleCommand.START, new ServiceComponentHostStartEvent("GANGLIA_SERVER",
- "host9", now), "cluster1", "GANGLIA", false, false);
+ RoleCommand.START, new ServiceComponentHostStartEvent("GANGLIA_SERVER",
+ "host9", now), "cluster1", "GANGLIA", false, false);
System.out.println(stage.toString());
rg.build(stage);
System.out.println(rg.stringifyGraph());
@@ -197,4 +196,56 @@ public class TestStagePlanner {
}
assertEquals(4, outStages.size());
}
+
+ @Test
+ public void testDependencyOrderedStageCreate() {
+ ClusterImpl cluster = mock(ClusterImpl.class);
+ when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
+ RoleGraph rg = roleGraphFactory.createNew(rco);
+ rg.setCommandExecutionType(CommandExecutionType.DEPENDENCY_ORDERED);
+ long now = System.currentTimeMillis();
+ Stage stage = StageUtils.getATestStage(1, 1, "host1", "", "");
+ stage.addHostRoleExecutionCommand("host11", Role.SECONDARY_NAMENODE,
+ RoleCommand.START, new ServiceComponentHostStartEvent("SECONDARY_NAMENODE",
+ "host11", now), "cluster1", "HDFS", false, false);
+ stage.addHostRoleExecutionCommand("host2", Role.HBASE_MASTER,
+ RoleCommand.START, new ServiceComponentHostStartEvent("HBASE_MASTER",
+ "host2", now), "cluster1", "HBASE", false, false);
+ stage.addHostRoleExecutionCommand("host3", Role.ZOOKEEPER_SERVER,
+ RoleCommand.START, new ServiceComponentHostStartEvent("ZOOKEEPER_SERVER",
+ "host3", now), "cluster1", "ZOOKEEPER", false, false);
+ stage.addHostRoleExecutionCommand("host4", Role.DATANODE,
+ RoleCommand.START, new ServiceComponentHostStartEvent("DATANODE",
+ "host4", now), "cluster1", "HDFS", false, false);
+ stage.addHostRoleExecutionCommand("host4", Role.HBASE_REGIONSERVER,
+ RoleCommand.START, new ServiceComponentHostStartEvent("HBASE_REGIONSERVER",
+ "host4", now), "cluster1", "HBASE", false, false);
+ stage.addHostRoleExecutionCommand("host4", Role.TASKTRACKER,
+ RoleCommand.START, new ServiceComponentHostStartEvent("TASKTRACKER",
+ "host4", now), "cluster1", "MAPREDUCE", false, false);
+ stage.addHostRoleExecutionCommand("host5", Role.JOBTRACKER,
+ RoleCommand.START, new ServiceComponentHostStartEvent("JOBTRACKER",
+ "host5", now), "cluster1", "MAPREDUCE", false, false);
+ stage.addHostRoleExecutionCommand("host6", Role.OOZIE_SERVER,
+ RoleCommand.START, new ServiceComponentHostStartEvent("OOZIE_SERVER",
+ "host6", now), "cluster1", "OOZIE", false, false);
+ stage.addHostRoleExecutionCommand("host7", Role.WEBHCAT_SERVER,
+ RoleCommand.START, new ServiceComponentHostStartEvent("WEBHCAT_SERVER",
+ "host7", now), "cluster1", "WEBHCAT", false, false);
+ stage.addHostRoleExecutionCommand("host4", Role.GANGLIA_MONITOR,
+ RoleCommand.START, new ServiceComponentHostStartEvent("GANGLIA_MONITOR",
+ "host4", now), "cluster1", "GANGLIA", false, false);
+ stage.addHostRoleExecutionCommand("host9", Role.GANGLIA_SERVER,
+ RoleCommand.START, new ServiceComponentHostStartEvent("GANGLIA_SERVER",
+ "host9", now), "cluster1", "GANGLIA", false, false);
+ System.out.println(stage.toString());
+ rg.build(stage);
+ System.out.println(rg.stringifyGraph());
+ List<Stage> outStages = rg.getStages();
+ for (Stage s : outStages) {
+ System.out.println(s.toString());
+ }
+ assertEquals(1, outStages.size());
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java
index f40e0a1..99bd312 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java
@@ -48,7 +48,6 @@ import org.apache.ambari.server.scheduler.ExecutionScheduler;
import org.apache.ambari.server.security.authorization.Users;
import org.apache.ambari.server.stack.StackManagerFactory;
import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.ConfigFactory;
@@ -260,7 +259,7 @@ public class ClusterEffectiveVersionTest extends EasyMockSupport {
binder.bind(ExecutionScheduler.class).toInstance(EasyMock.createNiceMock(ExecutionScheduler.class));
binder.bind(RequestFactory.class).toInstance(EasyMock.createNiceMock(RequestFactory.class));
binder.bind(StageFactory.class).toInstance(EasyMock.createNiceMock(StageFactory.class));
- binder.bind(RoleGraphFactory.class).toInstance(EasyMock.createNiceMock(RoleGraphFactoryImpl.class));
+ binder.bind(RoleGraphFactory.class).toInstance(EasyMock.createNiceMock(RoleGraphFactory.class));
binder.bind(AbstractRootServiceResponseFactory.class).toInstance(EasyMock.createNiceMock(AbstractRootServiceResponseFactory.class));
binder.bind(ConfigFactory.class).toInstance(EasyMock.createNiceMock(ConfigFactory.class));
binder.bind(ConfigGroupFactory.class).toInstance(EasyMock.createNiceMock(ConfigGroupFactory.class));
[2/2] ambari git commit: AMBARI-18553. Provision actions to happen
based only on specified dependencies (magyari_sandor)
Posted by ma...@apache.org.
AMBARI-18553. Provision actions to happen based only on specified dependencies (magyari_sandor)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5fdc9f97
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5fdc9f97
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5fdc9f97
Branch: refs/heads/trunk
Commit: 5fdc9f97e3ef98a88a56753708310384bfc6a1b5
Parents: d9bc653
Author: Sandor Magyari <sm...@hortonworks.com>
Authored: Tue Oct 4 19:23:19 2016 +0200
Committer: Sandor Magyari <sm...@hortonworks.com>
Committed: Thu Oct 20 18:06:13 2016 +0200
----------------------------------------------------------------------
.../server/actionmanager/ActionScheduler.java | 117 ++++++++++++------
.../actionmanager/CommandExecutionType.java | 35 ++++++
.../ambari/server/actionmanager/Stage.java | 34 ++++-
.../server/configuration/Configuration.java | 14 +++
.../AmbariManagementControllerImpl.java | 17 ++-
.../server/controller/ControllerModule.java | 20 +--
.../CachedRoleCommandOrderProvider.java | 112 +++++++++++++++++
.../server/metadata/RoleCommandOrder.java | 123 ++++++-------------
.../metadata/RoleCommandOrderProvider.java | 30 +++++
.../ambari/server/metadata/RoleCommandPair.java | 68 ++++++++++
.../ambari/server/orm/entities/StageEntity.java | 17 +++
.../ambari/server/stageplanner/RoleGraph.java | 65 ++++++----
.../server/stageplanner/RoleGraphFactory.java | 4 +-
.../stageplanner/RoleGraphFactoryImpl.java | 54 --------
.../server/upgrade/UpgradeCatalog250.java | 7 ++
.../main/resources/Ambari-DDL-Derby-CREATE.sql | 1 +
.../main/resources/Ambari-DDL-MySQL-CREATE.sql | 1 +
.../main/resources/Ambari-DDL-Oracle-CREATE.sql | 1 +
.../resources/Ambari-DDL-Postgres-CREATE.sql | 1 +
.../resources/Ambari-DDL-SQLAnywhere-CREATE.sql | 1 +
.../resources/Ambari-DDL-SQLServer-CREATE.sql | 1 +
.../server/controller/KerberosHelperTest.java | 40 +++---
.../ActiveWidgetLayoutResourceProviderTest.java | 8 +-
.../StackUpgradeConfigurationMergeTest.java | 4 +-
.../UserAuthorizationResourceProviderTest.java | 32 +++--
.../internal/UserResourceProviderTest.java | 8 +-
.../internal/ViewURLResourceProviderTest.java | 65 +++-------
.../server/metadata/RoleCommandOrderTest.java | 69 +++++------
.../ambari/server/metadata/RoleGraphTest.java | 18 +--
.../server/stageplanner/TestStagePlanner.java | 107 +++++++++++-----
.../cluster/ClusterEffectiveVersionTest.java | 3 +-
31 files changed, 700 insertions(+), 377 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
index 8cbfb1e..7a84536 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
@@ -50,6 +50,9 @@ import org.apache.ambari.server.events.ActionFinalReportReceivedEvent;
import org.apache.ambari.server.events.jpa.EntityManagerCacheInvalidationEvent;
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.events.publishers.JPAEventPublisher;
+import org.apache.ambari.server.metadata.RoleCommandOrder;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
+import org.apache.ambari.server.metadata.RoleCommandPair;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
import org.apache.ambari.server.orm.entities.RequestEntity;
@@ -66,6 +69,7 @@ import org.apache.ambari.server.state.ServiceComponentHostEvent;
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpFailedEvent;
import org.apache.ambari.server.utils.StageUtils;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -94,7 +98,10 @@ class ActionScheduler implements Runnable {
private static Logger LOG = LoggerFactory.getLogger(ActionScheduler.class);
public static final String FAILED_TASK_ABORT_REASONING =
- "Server considered task failed and automatically aborted it";
+ "Server considered task failed and automatically aborted it";
+
+ @Inject
+ private RoleCommandOrderProvider roleCommandOrderProvider;
@Inject
private UnitOfWork unitOfWork;
@@ -154,7 +161,7 @@ class ActionScheduler implements Runnable {
* but are not cancelled yet
*/
private final Set<Long> requestsToBeCancelled =
- Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());
+ Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());
/**
* Maps request IDs to reasoning for cancelling request.
@@ -162,7 +169,7 @@ class ActionScheduler implements Runnable {
* requestsToBeCancelled object
*/
private final Map<Long, String> requestCancelReasons =
- new HashMap<Long, String>();
+ new HashMap<Long, String>();
/**
* true if scheduler should run ASAP.
@@ -185,8 +192,8 @@ class ActionScheduler implements Runnable {
*/
@Inject
public ActionScheduler(@Named("schedulerSleeptime") long sleepTime,
- @Named("actionTimeout") long actionTimeout, ActionDBAccessor db,
- JPAEventPublisher jpaPublisher) {
+ @Named("actionTimeout") long actionTimeout, ActionDBAccessor db,
+ JPAEventPublisher jpaPublisher) {
this.sleepTime = sleepTime;
this.actionTimeout = actionTimeout;
@@ -217,10 +224,10 @@ class ActionScheduler implements Runnable {
* @param hostRoleCommandFactory
*/
protected ActionScheduler(long sleepTimeMilliSec, long actionTimeoutMilliSec, ActionDBAccessor db,
- ActionQueue actionQueue, Clusters fsmObject, int maxAttempts, HostsMap hostsMap,
- UnitOfWork unitOfWork, AmbariEventPublisher ambariEventPublisher,
- Configuration configuration, Provider<EntityManager> entityManagerProvider,
- HostRoleCommandDAO hostRoleCommandDAO, HostRoleCommandFactory hostRoleCommandFactory) {
+ ActionQueue actionQueue, Clusters fsmObject, int maxAttempts, HostsMap hostsMap,
+ UnitOfWork unitOfWork, AmbariEventPublisher ambariEventPublisher,
+ Configuration configuration, Provider<EntityManager> entityManagerProvider,
+ HostRoleCommandDAO hostRoleCommandDAO, HostRoleCommandFactory hostRoleCommandFactory) {
sleepTime = sleepTimeMilliSec;
actionTimeout = actionTimeoutMilliSec;
@@ -244,10 +251,10 @@ class ActionScheduler implements Runnable {
/**
* Initializes the caches.
*/
- private void initializeCaches(){
+ private void initializeCaches() {
clusterHostInfoCache = CacheBuilder.newBuilder().
- expireAfterAccess(5, TimeUnit.MINUTES).
- build();
+ expireAfterAccess(5, TimeUnit.MINUTES).
+ build();
commandParamsStageCache = CacheBuilder.newBuilder().
expireAfterAccess(5, TimeUnit.MINUTES).
@@ -294,7 +301,7 @@ class ActionScheduler implements Runnable {
try {
synchronized (wakeupSyncObject) {
if (!activeAwakeRequest) {
- wakeupSyncObject.wait(sleepTime);
+ wakeupSyncObject.wait(sleepTime);
}
activeAwakeRequest = false;
}
@@ -367,14 +374,14 @@ class ActionScheduler implements Runnable {
// a list does not change between invocations
for (Stage stage : stages) {
// Check if we can process this stage in parallel with another stages
- i_stage ++;
+ i_stage++;
long requestId = stage.getRequestId();
LOG.debug("==> STAGE_i = " + i_stage + "(requestId=" + requestId + ",StageId=" + stage.getStageId() + ")");
RequestEntity request = db.getRequestEntity(requestId);
if (request.isExclusive()) {
- if (runningRequestIds.size() > 0 ) {
+ if (runningRequestIds.size() > 0) {
// As a result, we will wait until any previous stages are finished
LOG.debug("Stage requires exclusive execution, but other requests are already executing. Stopping for now");
break;
@@ -395,7 +402,8 @@ class ActionScheduler implements Runnable {
}
// Commands that will be scheduled in current scheduler wakeup
- List<ExecutionCommand> commandsToSchedule = new ArrayList<ExecutionCommand>();
+ List<ExecutionCommand> commandsToSchedule = new ArrayList<>();
+
Map<String, RoleStats> roleStats = processInProgressStage(stage, commandsToSchedule);
// Check if stage is failed
@@ -500,7 +508,7 @@ class ActionScheduler implements Runnable {
}
LOG.debug("==> Finished.");
- if (! configuration.getParallelStageExecution()) { // If disabled
+ if (!configuration.getParallelStageExecution()) { // If disabled
return;
}
@@ -519,11 +527,11 @@ class ActionScheduler implements Runnable {
}
}
+
/**
* Returns the list of hosts that have a task assigned
*
* @param stages
- *
* @return
*/
private HashSet<String> getListOfHostsWithPendingTask(List<Stage> stages) {
@@ -653,7 +661,7 @@ class ActionScheduler implements Runnable {
return false;
}
- Map<Role, Integer> hostCountsForRoles = new HashMap<Role, Integer>();
+ Map<Role, Integer> hostCountsForRoles = new HashMap<Role, Integer>();
Map<Role, Integer> failedHostCountsForRoles = new HashMap<Role, Integer>();
for (String host : prevStage.getHostRoleCommands().keySet()) {
@@ -687,16 +695,15 @@ class ActionScheduler implements Runnable {
/**
* This method processes command timeouts and retry attempts, and
* adds new (pending) execution commands to commandsToSchedule list.
- *
* @return the stats for the roles in the stage which are used to determine
* whether stage has succeeded or failed
*/
- protected Map<String, RoleStats> processInProgressStage(Stage s,
- List<ExecutionCommand> commandsToSchedule) throws AmbariException {
+ protected Map<String, RoleStats> processInProgressStage(Stage s, List<ExecutionCommand> commandsToSchedule) throws AmbariException {
LOG.debug("==> Collecting commands to schedule...");
// Map to track role status
Map<String, RoleStats> roleStats = initRoleStats(s);
long now = System.currentTimeMillis();
+ Set<RoleCommandPair> rolesCommandsInProgress = s.getHostRolesInProgress();
Cluster cluster = null;
if (null != s.getClusterName()) {
@@ -716,14 +723,14 @@ class ActionScheduler implements Runnable {
int i_my = 0;
LOG.trace("===>host=" + host);
- for(ExecutionCommandWrapper wrapper : commandWrappers) {
+ for (ExecutionCommandWrapper wrapper : commandWrappers) {
ExecutionCommand c = wrapper.getExecutionCommand();
String roleStr = c.getRole();
HostRoleStatus status = s.getHostRoleStatus(host, roleStr);
- i_my ++;
+ i_my++;
if (LOG.isTraceEnabled()) {
LOG.trace("Host task " + i_my + ") id = " + c.getTaskId() + " status = " + status.toString() +
- " (role=" + roleStr + "), roleCommand = "+ c.getRoleCommand());
+ " (role=" + roleStr + "), roleCommand = " + c.getRoleCommand());
}
boolean hostDeleted = false;
if (null != cluster) {
@@ -741,8 +748,8 @@ class ActionScheduler implements Runnable {
}
} catch (ServiceComponentNotFoundException scnex) {
String msg = String.format(
- "%s is not not a service component, assuming its an action",
- roleStr);
+ "%s is not not a service component, assuming its an action",
+ roleStr);
LOG.debug(msg);
}
@@ -750,7 +757,7 @@ class ActionScheduler implements Runnable {
if (hostDeleted) {
String message = String.format(
"Host component information has not been found. Details:" +
- "cluster=%s; host=%s; service=%s; component=%s; ",
+ "cluster=%s; host=%s; service=%s; component=%s; ",
c.getClusterName(), host,
svcComp == null ? "null" : svcComp.getServiceName(),
svcComp == null ? "null" : svcComp.getName());
@@ -768,7 +775,7 @@ class ActionScheduler implements Runnable {
commandTimeout += Long.parseLong(timeoutStr) * 1000; // Converting to milliseconds
} else {
LOG.error("Execution command has no timeout parameter" +
- c.toString());
+ c.toString());
}
}
@@ -777,10 +784,10 @@ class ActionScheduler implements Runnable {
String message = String.format(
"Host not found when trying to schedule an execution command. " +
- "The most probable reason for that is that host or host component " +
- "has been deleted recently. The command has been aborted and dequeued." +
- "Execution command details: " +
- "cmdId: %s; taskId: %s; roleCommand: %s",
+ "The most probable reason for that is that host or host component " +
+ "has been deleted recently. The command has been aborted and dequeued." +
+ "Execution command details: " +
+ "cmdId: %s; taskId: %s; roleCommand: %s",
c.getCommandId(), c.getTaskId(), c.getRoleCommand());
LOG.warn("Host {} has been detected as non-available. {}", host, message);
// Abort the command itself
@@ -794,7 +801,7 @@ class ActionScheduler implements Runnable {
// Process command timeouts
if (s.getAttemptCount(host, roleStr) >= maxAttempts) {
LOG.warn("Host: {}, role: {}, actionId: {} expired and will be failed", host, roleStr,
- s.getActionId());
+ s.getActionId());
// determine if the task should be auto skipped
boolean isSkipSupported = s.isAutoSkipOnFailureSupported();
@@ -826,19 +833,28 @@ class ActionScheduler implements Runnable {
cancelCommandOnTimeout(Collections.singletonList(s.getHostRoleCommand(host, roleStr)));
LOG.info("Host: {}, role: {}, actionId: {} timed out and will be rescheduled", host,
- roleStr, s.getActionId());
+ roleStr, s.getActionId());
// reschedule command
commandsToSchedule.add(c);
LOG.trace("===> commandsToSchedule(reschedule)=" + commandsToSchedule.size());
}
} else if (status.equals(HostRoleStatus.PENDING)) {
- //Need to schedule first time
- commandsToSchedule.add(c);
- LOG.trace("===>commandsToSchedule(first_time)=" + commandsToSchedule.size());
+ // in case of DEPENDENCY_ORDERED stage command can be scheduled only if all of it's dependencies are
+ // already finished
+ if (CommandExecutionType.STAGE == s.getCommandExecutionType() ||
+ (CommandExecutionType.DEPENDENCY_ORDERED == s.getCommandExecutionType() &&
+ CommandExecutionType.DEPENDENCY_ORDERED == configuration.getStageExecutionType() &&
+ areCommandDependenciesFinished(c, s, rolesCommandsInProgress))) {
+
+ //Need to schedule first time
+ commandsToSchedule.add(c);
+ LOG.trace("===>commandsToSchedule(first_time)=" + commandsToSchedule.size());
+ }
}
updateRoleStats(status, roleStats.get(roleStr));
+
}
}
LOG.debug("Collected {} commands to schedule in this wakeup.", commandsToSchedule.size());
@@ -846,6 +862,31 @@ class ActionScheduler implements Runnable {
}
/**
+ * Returns true if all command dependencies are already finished (not IN_PROGRESS states).
+ * @param command
+ * @param stage
+ * @param rolesCommandsInProgress
+ * @return
+ */
+ private boolean areCommandDependenciesFinished(ExecutionCommand command, Stage stage, Set<RoleCommandPair>
+ rolesCommandsInProgress) {
+ boolean areCommandDependenciesFinished = true;
+ RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(stage.getClusterId());
+ if (rco != null) {
+ Set<RoleCommandPair> roleCommandDependencies = rco.getDependencies().get(new
+ RoleCommandPair(Role.valueOf(command.getRole()), command.getRoleCommand()));
+
+ // check if there are any dependencies IN_PROGRESS
+ if (roleCommandDependencies != null && CollectionUtils.containsAny(rolesCommandsInProgress, roleCommandDependencies)) {
+ areCommandDependenciesFinished = false;
+ }
+ }
+
+ return areCommandDependenciesFinished;
+
+ }
+
+ /**
* Generate a OPFailed event before aborting all operations in the stage
* @param stage
*/
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CommandExecutionType.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CommandExecutionType.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CommandExecutionType.java
new file mode 100644
index 0000000..08fb21a
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CommandExecutionType.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.actionmanager;
+/**
+ * Enum which indicates the execution type of commands for a stage.
+ */
+public enum CommandExecutionType {
+
+ /**
+ * One or more stages are created depending on dependencies. This is the default.
+ */
+ STAGE,
+
+ /**
+ * Create only one stage for each request and instead of handling dependencies with multiple stage, verify that
+ * dependencies are satisfied before scheduling a new command.
+ */
+ DEPENDENCY_ORDERED
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
index f03d8ea..319d72d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
@@ -19,7 +19,9 @@ package org.apache.ambari.server.actionmanager;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.EnumSet;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -32,6 +34,8 @@ import org.apache.ambari.server.Role;
import org.apache.ambari.server.RoleCommand;
import org.apache.ambari.server.agent.AgentCommand.AgentCommandType;
import org.apache.ambari.server.agent.ExecutionCommand;
+import org.apache.ambari.server.metadata.RoleCommandOrder;
+import org.apache.ambari.server.metadata.RoleCommandPair;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
import org.apache.ambari.server.orm.entities.RoleSuccessCriteriaEntity;
@@ -76,6 +80,8 @@ public class Stage {
private String commandParamsStage;
private String hostParamsStage;
+ private CommandExecutionType commandExecutionType = CommandExecutionType.STAGE;
+
private boolean skippable;
private boolean supportsAutoSkipOnFailure;
@@ -138,7 +144,7 @@ public class Stage {
supportsAutoSkipOnFailure = stageEntity.isAutoSkipOnFailureSupported();
logDir = stageEntity.getLogInfo();
- long clusterId = stageEntity.getClusterId().longValue();
+ clusterId = stageEntity.getClusterId().longValue();
if (-1L != clusterId) {
try {
clusterName = clusters.getClusterById(clusterId).getClusterName();
@@ -152,6 +158,7 @@ public class Stage {
clusterHostInfo = stageEntity.getClusterHostInfo();
commandParamsStage = stageEntity.getCommandParamsStage();
hostParamsStage = stageEntity.getHostParamsStage();
+ commandExecutionType = stageEntity.getCommandExecutionType();
List<Long> taskIds = hostRoleCommandDAO.findTaskIdsByStage(requestId, stageId);
Collection<HostRoleCommand> commands = dbAccessor.getTasks(taskIds);
@@ -191,6 +198,7 @@ public class Stage {
stageEntity.setClusterHostInfo(clusterHostInfo);
stageEntity.setCommandParamsStage(commandParamsStage);
stageEntity.setHostParamsStage(hostParamsStage);
+ stageEntity.setCommandExecutionType(commandExecutionType);
for (Role role : successFactors.keySet()) {
RoleSuccessCriteriaEntity roleSuccessCriteriaEntity = new RoleSuccessCriteriaEntity();
@@ -235,6 +243,23 @@ public class Stage {
return commands;
}
+ /**
+ * Returns <Role, RoleCommand> pairs which are in progress.
+ * @return
+ */
+ public Set<RoleCommandPair> getHostRolesInProgress() {
+ Set<RoleCommandPair> commandsToScheduleSet = new HashSet<>();
+ for (Map.Entry<String, Map<String, HostRoleCommand>> hostRoleCommandEntry : hostRoleCommands.entrySet()) {
+ for (Map.Entry<String, HostRoleCommand> roleCommandEntry : hostRoleCommandEntry.getValue().entrySet()) {
+ if (HostRoleStatus.IN_PROGRESS_STATUSES.contains(roleCommandEntry.getValue().getStatus())) {
+ commandsToScheduleSet.add(
+ new RoleCommandPair(roleCommandEntry.getValue().getRole(), roleCommandEntry.getValue().getRoleCommand()));
+ }
+ }
+ }
+ return commandsToScheduleSet;
+ }
+
public String getClusterHostInfo() {
return clusterHostInfo;
}
@@ -259,6 +284,13 @@ public class Stage {
this.hostParamsStage = hostParamsStage;
}
+ public CommandExecutionType getCommandExecutionType() {
+ return commandExecutionType;
+ }
+
+ public void setCommandExecutionType(CommandExecutionType commandExecutionType) {
+ this.commandExecutionType = commandExecutionType;
+ }
public synchronized void setStageId(long stageId) {
if (this.stageId != -1) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 378db18..1759dc4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -51,6 +51,7 @@ import org.apache.ambari.annotations.Markdown;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
import org.apache.ambari.server.controller.spi.PropertyProvider;
import org.apache.ambari.server.events.listeners.alerts.AlertReceivedListener;
import org.apache.ambari.server.orm.JPATableGenerationStrategy;
@@ -1821,6 +1822,15 @@ public class Configuration {
"server.stages.parallel", Boolean.TRUE);
/**
+ * In case this is set to DEPENDENCY_ORDERED one stage is created for each request and command dependencies are
+ * handled directly by ActionScheduler. In case of STAGE (which is the default) one or more stages are
+ * created depending on dependencies.
+ */
+ @Markdown(description = "How to execute commands in one stage")
+ public static final ConfigurationProperty<String> COMMAND_EXECUTION_TYPE = new ConfigurationProperty<>(
+ "server.stage.command.execution_type", CommandExecutionType.STAGE.toString());
+
+ /**
* The time, in {@link TimeUnit#SECONDS}, before agent commands are killed.
* This does not include package installation commands.
*/
@@ -3061,6 +3071,10 @@ public class Configuration {
return getProperty(SYS_PREPPED_HOSTS);
}
+ public CommandExecutionType getStageExecutionType(){
+ return CommandExecutionType.valueOf(getProperty(COMMAND_EXECUTION_TYPE));
+ }
+
public String getStackAdvisorScript() {
return getProperty(STACK_ADVISOR_SCRIPT);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/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 25806e2..09e49ef 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
@@ -82,6 +82,7 @@ import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.RequestFactory;
import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
import org.apache.ambari.server.actionmanager.StageFactory;
import org.apache.ambari.server.agent.ExecutionCommand;
import org.apache.ambari.server.agent.ExecutionCommand.KeyNames;
@@ -104,6 +105,7 @@ import org.apache.ambari.server.customactions.ActionDefinition;
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.metadata.ActionMetadata;
import org.apache.ambari.server.metadata.RoleCommandOrder;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
import org.apache.ambari.server.orm.dao.ClusterDAO;
import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
import org.apache.ambari.server.orm.dao.ExtensionDAO;
@@ -239,6 +241,10 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
private final Gson gson;
+
+ @Inject
+ private RoleCommandOrderProvider roleCommandOrderProvider;
+
@Inject
private ServiceFactory serviceFactory;
@Inject
@@ -402,10 +408,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
@Override
public RoleCommandOrder getRoleCommandOrder(Cluster cluster) {
- RoleCommandOrder rco;
- rco = injector.getInstance(RoleCommandOrder.class);
- rco.initialize(cluster);
- return rco;
+ return roleCommandOrderProvider.getRoleCommandOrder(cluster);
}
@Override
@@ -2841,6 +2844,12 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
RoleCommandOrder rco = getRoleCommandOrder(cluster);
RoleGraph rg = roleGraphFactory.createNew(rco);
+
+ if (CommandExecutionType.DEPENDENCY_ORDERED == configs.getStageExecutionType() && "INITIAL_START".equals
+ (requestProperties.get("phase"))) {
+ LOG.info("Set DEPENDENCY_ORDERED CommandExecutionType on stage: {}", stage.getRequestContext());
+ rg.setCommandExecutionType(CommandExecutionType.DEPENDENCY_ORDERED);
+ }
rg.build(stage);
requestStages.addStages(rg.getStages());
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index 5afaba8..e32e653 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -77,6 +77,8 @@ import org.apache.ambari.server.controller.metrics.timeline.cache.TimelineMetric
import org.apache.ambari.server.controller.metrics.timeline.cache.TimelineMetricCacheProvider;
import org.apache.ambari.server.controller.spi.ResourceProvider;
import org.apache.ambari.server.controller.utilities.KerberosChecker;
+import org.apache.ambari.server.metadata.CachedRoleCommandOrderProvider;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
import org.apache.ambari.server.metrics.system.MetricsService;
import org.apache.ambari.server.metrics.system.impl.MetricsServiceImpl;
import org.apache.ambari.server.notifications.DispatchFactory;
@@ -95,8 +97,8 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService;
import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl;
import org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandlerFactory;
import org.apache.ambari.server.stack.StackManagerFactory;
+import org.apache.ambari.server.stageplanner.RoleGraph;
import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Config;
@@ -352,9 +354,6 @@ public class ControllerModule extends AbstractModule {
bindConstant().annotatedWith(Names.named(HostRoleCommandDAO.HRC_STATUS_SUMMARY_CACHE_EXPIRY_DURATION_MINUTES)).
to(configuration.getHostRoleCommandStatusSummaryCacheExpiryDuration());
-
-
-
bind(AmbariManagementController.class).to(
AmbariManagementControllerImpl.class);
bind(AbstractRootServiceResponseFactory.class).to(RootServiceResponseFactory.class);
@@ -428,7 +427,7 @@ public class ControllerModule extends AbstractModule {
install(new FactoryModuleBuilder().implement(
Host.class, HostImpl.class).build(HostFactory.class));
install(new FactoryModuleBuilder().implement(
- Service.class, ServiceImpl.class).build(ServiceFactory.class));
+ Service.class, ServiceImpl.class).build(ServiceFactory.class));
install(new FactoryModuleBuilder()
.implement(ResourceProvider.class, Names.named("host"), HostResourceProvider.class)
@@ -444,8 +443,8 @@ public class ControllerModule extends AbstractModule {
.build(ResourceProviderFactory.class));
install(new FactoryModuleBuilder().implement(
- ServiceComponent.class, ServiceComponentImpl.class).build(
- ServiceComponentFactory.class));
+ ServiceComponent.class, ServiceComponentImpl.class).build(
+ ServiceComponentFactory.class));
install(new FactoryModuleBuilder().implement(
ServiceComponentHost.class, ServiceComponentHostImpl.class).build(
ServiceComponentHostFactory.class));
@@ -454,10 +453,13 @@ public class ControllerModule extends AbstractModule {
install(new FactoryModuleBuilder().implement(
ConfigGroup.class, ConfigGroupImpl.class).build(ConfigGroupFactory.class));
install(new FactoryModuleBuilder().implement(RequestExecution.class,
- RequestExecutionImpl.class).build(RequestExecutionFactory.class));
+ RequestExecutionImpl.class).build(RequestExecutionFactory.class));
bind(StageFactory.class).to(StageFactoryImpl.class);
- bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class);
+ bind(RoleCommandOrderProvider.class).to(CachedRoleCommandOrderProvider.class);
+
+ install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
+
install(new FactoryModuleBuilder().build(RequestFactory.class));
install(new FactoryModuleBuilder().build(StackManagerFactory.class));
install(new FactoryModuleBuilder().build(ExecutionCommandWrapperFactory.class));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/metadata/CachedRoleCommandOrderProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/metadata/CachedRoleCommandOrderProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/metadata/CachedRoleCommandOrderProvider.java
new file mode 100644
index 0000000..e2b44ca
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/metadata/CachedRoleCommandOrderProvider.java
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.metadata;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+/**
+ * RoleCommandOrderProvider which caches RoleCommandOrder objects for a cluster to avoid the cost of construction of
+ * RoleCommandOrder objects each time.
+ */
+public class CachedRoleCommandOrderProvider implements RoleCommandOrderProvider {
+
+ private static Logger LOG = LoggerFactory.getLogger(CachedRoleCommandOrderProvider.class);
+
+ @Inject
+ private Injector injector;
+
+ @Inject
+ private Clusters clusters;
+
+ private Map<Integer, RoleCommandOrder> rcoMap = new HashMap<>();
+
+ @Inject
+ public CachedRoleCommandOrderProvider() {
+ }
+
+ @Override
+ public RoleCommandOrder getRoleCommandOrder(Long clusterId) {
+ Cluster cluster = null;
+ try {
+ cluster = clusters.getCluster(clusterId);
+ return getRoleCommandOrder(cluster);
+ } catch (AmbariException e) {
+ return null;
+ }
+
+ }
+
+ @Override
+ public RoleCommandOrder getRoleCommandOrder(Cluster cluster) {
+ boolean hasGLUSTERFS = false;
+ boolean isNameNodeHAEnabled = false;
+ boolean isResourceManagerHAEnabled = false;
+
+ try {
+ if (cluster != null && cluster.getService("GLUSTERFS") != null) {
+ hasGLUSTERFS = true;
+ }
+ } catch (AmbariException e) {
+ }
+
+ try {
+ if (cluster != null &&
+ cluster.getService("HDFS") != null &&
+ cluster.getService("HDFS").getServiceComponent("JOURNALNODE") != null) {
+ isNameNodeHAEnabled = true;
+ }
+ } catch (AmbariException e) {
+ }
+
+ try {
+ if (cluster != null &&
+ cluster.getService("YARN") != null &&
+ cluster.getService("YARN").getServiceComponent("RESOURCEMANAGER").getServiceComponentHosts().size() > 1) {
+ isResourceManagerHAEnabled = true;
+ }
+ } catch (AmbariException e) {
+ }
+
+ int clusterCacheId = new HashCodeBuilder().append(cluster.getClusterId()).append(hasGLUSTERFS).append(isNameNodeHAEnabled).append
+ (isResourceManagerHAEnabled).toHashCode();
+
+ RoleCommandOrder rco = rcoMap.get(clusterCacheId);
+ if (rco == null) {
+ rco = injector.getInstance(RoleCommandOrder.class);
+ rco.setHasGLUSTERFS(hasGLUSTERFS);
+ rco.setIsNameNodeHAEnabled(isNameNodeHAEnabled);
+ rco.setIsResourceManagerHAEnabled(isResourceManagerHAEnabled);
+ rco.initialize(cluster);
+ rcoMap.put(clusterCacheId, rco);
+ }
+ return rco;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/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 bbdb808..58675ae 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
@@ -17,25 +17,26 @@
*/
package org.apache.ambari.server.metadata;
-import java.io.*;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
-import com.google.inject.Inject;
+import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.RoleCommand;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.stageplanner.RoleGraphNode;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Service;
import org.apache.ambari.server.state.ServiceComponent;
import org.apache.ambari.server.state.StackId;
import org.apache.ambari.server.state.StackInfo;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.type.TypeReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.ambari.server.AmbariException;
+
+import com.google.inject.Inject;
/**
* This class is used to establish the order between two roles. This class
@@ -43,9 +44,12 @@ import org.apache.ambari.server.AmbariException;
*/
public class RoleCommandOrder {
- @Inject Configuration configs;
@Inject AmbariMetaInfo ambariMetaInfo;
+ private boolean hasGLUSTERFS;
+ private boolean isNameNodeHAEnabled;
+ private boolean isResourceManagerHAEnabled;
+
private final static Logger LOG =
LoggerFactory.getLogger(RoleCommandOrder.class);
@@ -66,50 +70,6 @@ public class RoleCommandOrder {
add(RoleCommand.SERVICE_CHECK);
}};
- static class RoleCommandPair {
- Role role;
- RoleCommand cmd;
-
- public RoleCommandPair(Role _role, RoleCommand _cmd) {
- if (_role == null || _cmd == null) {
- throw new IllegalArgumentException("role = "+_role+", cmd = "+_cmd);
- }
- this.role = _role;
- this.cmd = _cmd;
- }
-
- @Override
- public int hashCode() {
- return (role.toString() + cmd.toString()).hashCode();
- }
-
- @Override
- public boolean equals(Object other) {
- if (other != null && (other instanceof RoleCommandPair)
- && ((RoleCommandPair) other).role.equals(role)
- && ((RoleCommandPair) other).cmd.equals(cmd)) {
- return true;
- }
- return false;
- }
-
- Role getRole() {
- return role;
- }
-
- RoleCommand getCmd() {
- return cmd;
- }
-
- @Override
- public String toString() {
- return "RoleCommandPair{" +
- "role=" + role +
- ", cmd=" + cmd +
- '}';
- }
- }
-
/**
* key -> blocked role command value -> set of blocker role commands.
*/
@@ -160,40 +120,12 @@ public class RoleCommandOrder {
}
public void initialize(Cluster cluster) {
- Boolean hasGLUSTERFS = false;
- Boolean isNameNodeHAEnabled = false;
- Boolean isResourceManagerHAEnabled = false;
-
- try {
- if (cluster != null && cluster.getService("GLUSTERFS") != null) {
- hasGLUSTERFS = true;
- }
- } catch (AmbariException e) {
- }
-
- try {
- if (cluster != null &&
- cluster.getService("HDFS") != null &&
- cluster.getService("HDFS").getServiceComponent("JOURNALNODE") != null) {
- isNameNodeHAEnabled = true;
- }
- } catch (AmbariException e) {
- }
-
- try {
- if (cluster != null &&
- cluster.getService("YARN") != null &&
- cluster.getService("YARN").getServiceComponent("RESOURCEMANAGER").getServiceComponentHosts().size() > 1) {
- isResourceManagerHAEnabled = true;
- }
- } catch (AmbariException e) {
- }
StackId stackId = cluster.getCurrentStackVersion();
StackInfo stack = null;
try {
stack = ambariMetaInfo.getStack(stackId.getStackName(),
- stackId.getStackVersion());
+ stackId.getStackVersion());
} catch (AmbariException e) {
}
@@ -399,8 +331,8 @@ public class RoleCommandOrder {
v2 = rco.dependencies.get(roleCommandPairSetEntry.getKey());
if (!v1.equals(v2)) {
LOG.debug("different entry found for key ("
- + roleCommandPairSetEntry.getKey().role.toString() + ", "
- + roleCommandPairSetEntry.getKey().cmd.toString() + ")" );
+ + roleCommandPairSetEntry.getKey().getRole().toString() + ", "
+ + roleCommandPairSetEntry.getKey().getCmd().toString() + ")" );
return 1;
}
}
@@ -408,11 +340,34 @@ public class RoleCommandOrder {
return 0;
}
+ public boolean isHasGLUSTERFS() {
+ return hasGLUSTERFS;
+ }
+
+ public void setHasGLUSTERFS(boolean hasGLUSTERFS) {
+ this.hasGLUSTERFS = hasGLUSTERFS;
+ }
+
+ public boolean isNameNodeHAEnabled() {
+ return isNameNodeHAEnabled;
+ }
+
+ public void setIsNameNodeHAEnabled(boolean isNameNodeHAEnabled) {
+ this.isNameNodeHAEnabled = isNameNodeHAEnabled;
+ }
+
+ public boolean isResourceManagerHAEnabled() {
+ return isResourceManagerHAEnabled;
+ }
+
+ public void setIsResourceManagerHAEnabled(boolean isResourceManagerHAEnabled) {
+ this.isResourceManagerHAEnabled = isResourceManagerHAEnabled;
+ }
/**
* For test purposes
*/
- Map<RoleCommandPair, Set<RoleCommandPair>> getDependencies() {
+ public Map<RoleCommandPair, Set<RoleCommandPair>> getDependencies() {
return dependencies;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrderProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrderProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrderProvider.java
new file mode 100644
index 0000000..20c7d77
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandOrderProvider.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.metadata;
+
+import org.apache.ambari.server.state.Cluster;
+
+/**
+ * Provider to retrieve RoleCommandOrder objects for a cluster.
+ */
+public interface RoleCommandOrderProvider {
+
+ RoleCommandOrder getRoleCommandOrder(Cluster cluster);
+ RoleCommandOrder getRoleCommandOrder(Long clusterId);
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandPair.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandPair.java b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandPair.java
new file mode 100644
index 0000000..9b44ae5
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/metadata/RoleCommandPair.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.metadata;
+
+import java.util.Objects;
+
+import org.apache.ambari.server.Role;
+import org.apache.ambari.server.RoleCommand;
+
+/**
+ * Tuple object containing a Role and RoleCommand.
+ */
+public class RoleCommandPair {
+
+ private final Role role;
+ private final RoleCommand cmd;
+
+ public RoleCommandPair(Role _role, RoleCommand _cmd) {
+ if (_role == null || _cmd == null) {
+ throw new IllegalArgumentException("role = "+_role+", cmd = "+_cmd);
+ }
+ this.role = _role;
+ this.cmd = _cmd;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(role, cmd);
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other != null && (other instanceof RoleCommandPair)
+ && ((RoleCommandPair) other).role.equals(role)
+ && ((RoleCommandPair) other).cmd.equals(cmd)) {
+ return true;
+ }
+ return false;
+ }
+
+ Role getRole() {
+ return role;
+ }
+
+ RoleCommand getCmd() {
+ return cmd;
+ }
+
+ @Override
+ public String toString() {
+ return "RoleCommandPair{" + "role=" + role + ", cmd=" + cmd + '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
index eaea913..f9c8810 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
@@ -26,6 +26,8 @@ import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
@@ -36,6 +38,8 @@ import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
+
@Entity
@Table(name = "stage")
@IdClass(org.apache.ambari.server.orm.entities.StageEntityPK.class)
@@ -77,6 +81,11 @@ public class StageEntity {
@Basic
private String requestContext = "";
+ @Basic
+ @Enumerated(value = EnumType.STRING)
+ @Column(name = "command_execution_type", nullable = false)
+ private CommandExecutionType commandExecutionType = CommandExecutionType.STAGE;
+
/**
* On large clusters, this value can be in the 10,000's of kilobytes. During
* an upgrade, all stages are loaded in memory for every request, which can
@@ -178,6 +187,14 @@ public class StageEntity {
}
}
+ public CommandExecutionType getCommandExecutionType() {
+ return commandExecutionType;
+ }
+
+ public void setCommandExecutionType(CommandExecutionType commandExecutionType) {
+ this.commandExecutionType = commandExecutionType;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java b/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java
index c9ab6f9..c8a18b6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java
@@ -18,13 +18,18 @@
package org.apache.ambari.server.stageplanner;
import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+import com.google.inject.assistedinject.AssistedInject;
+
import org.apache.ambari.server.RoleCommand;
import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
import org.apache.ambari.server.actionmanager.StageFactory;
import org.apache.ambari.server.metadata.RoleCommandOrder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
@@ -33,28 +38,34 @@ import java.util.TreeMap;
public class RoleGraph {
- private static Log LOG = LogFactory.getLog(RoleGraph.class);
+ private static Logger LOG = LoggerFactory.getLogger(RoleGraph.class);
-
Map<String, RoleGraphNode> graph = null;
private RoleCommandOrder roleDependencies;
private Stage initialStage = null;
private boolean sameHostOptimization = true;
+ private CommandExecutionType commandExecutionType = CommandExecutionType.STAGE;
@Inject
private StageFactory stageFactory;
- @Inject
- public RoleGraph(StageFactory stageFactory) {
- this.stageFactory = stageFactory;
+ @AssistedInject
+ public RoleGraph() {
}
- @Inject
- public RoleGraph(RoleCommandOrder rd, StageFactory stageFactory) {
- this(stageFactory);
+ @AssistedInject
+ public RoleGraph(@Assisted RoleCommandOrder rd) {
this.roleDependencies = rd;
}
+ public CommandExecutionType getCommandExecutionType() {
+ return commandExecutionType;
+ }
+
+ public void setCommandExecutionType(CommandExecutionType commandExecutionType) {
+ this.commandExecutionType = commandExecutionType;
+ }
+
/**
* Given a stage builds a DAG of all execution commands within the stage.
*/
@@ -80,22 +91,28 @@ public class RoleGraph {
}
}
- if (null != roleDependencies) {
- //Add edges
- for (String roleI : graph.keySet()) {
- for (String roleJ : graph.keySet()) {
- if (!roleI.equals(roleJ)) {
- RoleGraphNode rgnI = graph.get(roleI);
- RoleGraphNode rgnJ = graph.get(roleJ);
- int order = roleDependencies.order(rgnI, rgnJ);
- if (order == -1) {
- rgnI.addEdge(rgnJ);
- } else if (order == 1) {
- rgnJ.addEdge(rgnI);
+ // In case commandExecutionType == DEPENDENCY_ORDERED there will be only one stage, thus no need to add edges to
+ // the graph
+ if (commandExecutionType == CommandExecutionType.STAGE) {
+ if (null != roleDependencies) {
+ //Add edges
+ for (String roleI : graph.keySet()) {
+ for (String roleJ : graph.keySet()) {
+ if (!roleI.equals(roleJ)) {
+ RoleGraphNode rgnI = graph.get(roleI);
+ RoleGraphNode rgnJ = graph.get(roleJ);
+ int order = roleDependencies.order(rgnI, rgnJ);
+ if (order == -1) {
+ rgnI.addEdge(rgnJ);
+ } else if (order == 1) {
+ rgnJ.addEdge(rgnI);
+ }
}
}
}
}
+ } else {
+ LOG.info("Build stage with DEPENDENCY_ORDERED commandExecutionType: {} ", stage.getRequestContext());
}
}
/**
@@ -166,6 +183,10 @@ public class RoleGraph {
newStage.setSuccessFactors(origStage.getSuccessFactors());
newStage.setSkippable(origStage.isSkippable());
newStage.setAutoSkipFailureSupported(origStage.isAutoSkipOnFailureSupported());
+ if (commandExecutionType != null) {
+ newStage.setCommandExecutionType(commandExecutionType);
+ }
+
for (RoleGraphNode rgn : stageGraphNodes) {
for (String host : rgn.getHosts()) {
newStage.addExecutionCommandWrapper(origStage, host, rgn.getRole());
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactory.java
index 625b168..1ece2c7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactory.java
@@ -24,12 +24,12 @@ public interface RoleGraphFactory {
*
* @return
*/
- public RoleGraph createNew();
+ RoleGraph createNew();
/**
*
* @param rd
* @return
*/
- public RoleGraph createNew(RoleCommandOrder rd);
+ RoleGraph createNew(RoleCommandOrder rd);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactoryImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactoryImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactoryImpl.java
deleted file mode 100644
index 5ca4d88..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraphFactoryImpl.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.server.stageplanner;
-
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.Singleton;
-import org.apache.ambari.server.actionmanager.StageFactory;
-import org.apache.ambari.server.metadata.RoleCommandOrder;
-
-
-@Singleton
-public class RoleGraphFactoryImpl implements RoleGraphFactory {
- private Injector injector;
-
- @Inject
- public RoleGraphFactoryImpl(Injector injector) {
- this.injector = injector;
- }
-
- /**
- *
- * @return
- */
- @Override
- public RoleGraph createNew() {
- return new RoleGraph(this.injector.getInstance(StageFactory.class));
- }
-
- /**
- *
- * @param rd
- * @return
- */
- @Override
- public RoleGraph createNew(RoleCommandOrder rd) {
- return new RoleGraph(rd, this.injector.getInstance(StageFactory.class));
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
index 34331ee..44784ed 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
@@ -26,8 +26,11 @@ import java.util.List;
import java.util.Map;
import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.actionmanager.CommandExecutionType;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
+import org.apache.ambari.server.orm.DBAccessor;
+
import org.apache.ambari.server.orm.dao.DaoUtils;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
@@ -104,6 +107,10 @@ public class UpgradeCatalog250 extends AbstractUpgradeCatalog {
protected void executeDDLUpdates() throws AmbariException, SQLException {
updateHostVersionTable();
createComponentVersionTable();
+ dbAccessor.addColumn("stage",
+ new DBAccessor.DBColumnInfo("command_execution_type", String.class, 32, CommandExecutionType.STAGE.toString(),
+ false));
+
}
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
index 4b64955..ed94c40 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
@@ -356,6 +356,7 @@ CREATE TABLE stage (
cluster_host_info BLOB NOT NULL,
command_params BLOB,
host_params BLOB,
+ command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE',
CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 15a84cd..c8fbaa7 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -356,6 +356,7 @@ CREATE TABLE stage (
cluster_host_info LONGBLOB,
command_params LONGBLOB,
host_params LONGBLOB,
+ command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE',
CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 6c3c036..04473d6 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -347,6 +347,7 @@ CREATE TABLE stage (
cluster_host_info BLOB NOT NULL,
command_params BLOB,
host_params BLOB,
+ command_execution_type VARCHAR2(32) DEFAULT 'STAGE' NOT NULL,
CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 570b684..09ae3b0 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -356,6 +356,7 @@ CREATE TABLE stage (
cluster_host_info BYTEA NOT NULL,
command_params BYTEA,
host_params BYTEA,
+ command_execution_type VARCHAR(32) DEFAULT 'STAGE' NOT NULL,
CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index 170e430..3dbd3fc 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -345,6 +345,7 @@ CREATE TABLE stage (
cluster_host_info IMAGE,
command_params IMAGE,
host_params IMAGE,
+ command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE',
CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index 1501143..9def741 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -360,6 +360,7 @@ CREATE TABLE stage (
cluster_host_info VARBINARY(MAX) NOT NULL,
command_params VARBINARY(MAX),
host_params VARBINARY(MAX),
+ command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE',
CONSTRAINT PK_stage PRIMARY KEY CLUSTERED (stage_id, request_id),
CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
index c7e0a9c..7dc6425 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
@@ -18,24 +18,6 @@
package org.apache.ambari.server.controller;
-import static org.easymock.EasyMock.anyLong;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.anyString;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.getCurrentArguments;
-import static org.easymock.EasyMock.isNull;
-import static org.easymock.EasyMock.newCapture;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reset;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.lang.reflect.Method;
import java.net.InetAddress;
@@ -93,7 +75,6 @@ import org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandler;
import org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandlerFactory;
import org.apache.ambari.server.stack.StackManagerFactory;
import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Config;
@@ -136,6 +117,25 @@ import org.junit.rules.TemporaryFolder;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.newCapture;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
@SuppressWarnings("unchecked")
@@ -228,8 +228,8 @@ public class KerberosHelperTest extends EasyMockSupport {
bind(ActionManager.class).toInstance(createNiceMock(ActionManager.class));
bind(RequestFactory.class).toInstance(createNiceMock(RequestFactory.class));
bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class));
- bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class);
bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
+ install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
bind(ConfigHelper.class).toInstance(createNiceMock(ConfigHelper.class));
bind(KerberosOperationHandlerFactory.class).toInstance(kerberosOperationHandlerFactory);
bind(ClusterController.class).toInstance(clusterController);
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActiveWidgetLayoutResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActiveWidgetLayoutResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActiveWidgetLayoutResourceProviderTest.java
index 6b371d8..c592a20 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActiveWidgetLayoutResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActiveWidgetLayoutResourceProviderTest.java
@@ -21,6 +21,8 @@ import com.google.gson.Gson;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+
import org.apache.ambari.server.actionmanager.ActionDBAccessor;
import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.actionmanager.StageFactory;
@@ -36,6 +38,8 @@ import org.apache.ambari.server.controller.spi.ResourceProvider;
import org.apache.ambari.server.controller.spi.SystemException;
import org.apache.ambari.server.controller.utilities.PredicateBuilder;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.metadata.CachedRoleCommandOrderProvider;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
import org.apache.ambari.server.orm.DBAccessor;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.dao.UserDAO;
@@ -53,7 +57,6 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService;
import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl;
import org.apache.ambari.server.stack.StackManagerFactory;
import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.ConfigFactory;
@@ -379,7 +382,7 @@ public class ActiveWidgetLayoutResourceProviderTest extends EasyMockSupport {
bind(org.apache.ambari.server.actionmanager.RequestFactory.class).toInstance(createNiceMock(org.apache.ambari.server.actionmanager.RequestFactory.class));
bind(RequestExecutionFactory.class).toInstance(createNiceMock(RequestExecutionFactory.class));
bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class));
- bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class);
+ install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
bind(AbstractRootServiceResponseFactory.class).toInstance(createNiceMock(AbstractRootServiceResponseFactory.class));
bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class));
@@ -392,6 +395,7 @@ public class ActiveWidgetLayoutResourceProviderTest extends EasyMockSupport {
bind(KerberosHelper.class).toInstance(createNiceMock(KerberosHelper.class));
bind(Users.class).toInstance(createMock(Users.class));
bind(AmbariManagementController.class).to(AmbariManagementControllerImpl.class);
+ bind(RoleCommandOrderProvider.class).to(CachedRoleCommandOrderProvider.class);
bind(CredentialStoreService.class).to(CredentialStoreServiceImpl.class);
bind(UserDAO.class).toInstance(createMock(UserDAO.class));
bind(WidgetLayoutDAO.class).toInstance(createMock(WidgetLayoutDAO.class));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
index a49fc09..0c54593 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackUpgradeConfigurationMergeTest.java
@@ -40,7 +40,6 @@ import org.apache.ambari.server.scheduler.ExecutionScheduler;
import org.apache.ambari.server.security.authorization.Users;
import org.apache.ambari.server.stack.StackManagerFactory;
import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Config;
@@ -71,6 +70,7 @@ import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
import junit.framework.Assert;
@@ -279,7 +279,7 @@ public class StackUpgradeConfigurationMergeTest extends EasyMockSupport {
binder.bind(ExecutionScheduler.class).toInstance(createNiceMock(ExecutionScheduler.class));
binder.bind(RequestFactory.class).toInstance(createNiceMock(RequestFactory.class));
binder.bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class));
- binder.bind(RoleGraphFactory.class).toInstance(createNiceMock(RoleGraphFactoryImpl.class));
+ binder.install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
binder.bind(AbstractRootServiceResponseFactory.class).toInstance(createNiceMock(AbstractRootServiceResponseFactory.class));
binder.bind(ConfigFactory.class).toInstance(createNiceMock(ConfigFactory.class));
binder.bind(ConfigGroupFactory.class).toInstance(createNiceMock(ConfigGroupFactory.class));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserAuthorizationResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserAuthorizationResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserAuthorizationResourceProviderTest.java
index 3705af1..013d42d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserAuthorizationResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserAuthorizationResourceProviderTest.java
@@ -18,9 +18,15 @@
package org.apache.ambari.server.controller.internal;
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+
import org.apache.ambari.server.actionmanager.ActionDBAccessor;
import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.actionmanager.StageFactory;
@@ -37,6 +43,8 @@ import org.apache.ambari.server.controller.spi.ResourceProvider;
import org.apache.ambari.server.controller.spi.SystemException;
import org.apache.ambari.server.controller.utilities.PredicateBuilder;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.metadata.CachedRoleCommandOrderProvider;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
import org.apache.ambari.server.orm.DBAccessor;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.dao.PermissionDAO;
@@ -53,7 +61,6 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService;
import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl;
import org.apache.ambari.server.stack.StackManagerFactory;
import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.ConfigFactory;
import org.apache.ambari.server.state.ServiceComponentFactory;
@@ -71,15 +78,13 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
-import javax.persistence.EntityManager;
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Set;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
-import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.expect;
/**
@@ -389,7 +394,7 @@ public class UserAuthorizationResourceProviderTest extends EasyMockSupport {
bind(org.apache.ambari.server.actionmanager.RequestFactory.class).toInstance(createNiceMock(org.apache.ambari.server.actionmanager.RequestFactory.class));
bind(RequestExecutionFactory.class).toInstance(createNiceMock(RequestExecutionFactory.class));
bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class));
- bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class);
+ install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
bind(AbstractRootServiceResponseFactory.class).toInstance(createNiceMock(AbstractRootServiceResponseFactory.class));
bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class));
@@ -402,6 +407,7 @@ public class UserAuthorizationResourceProviderTest extends EasyMockSupport {
bind(KerberosHelper.class).toInstance(createNiceMock(KerberosHelper.class));
bind(Users.class).toInstance(createMock(Users.class));
bind(AmbariManagementController.class).to(AmbariManagementControllerImpl.class);
+ bind(RoleCommandOrderProvider.class).to(CachedRoleCommandOrderProvider.class);
bind(CredentialStoreService.class).to(CredentialStoreServiceImpl.class);
bind(UserDAO.class).toInstance(createMock(UserDAO.class));
bind(ResourceTypeDAO.class).toInstance(createMock(ResourceTypeDAO.class));
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java
index 8984342..bed5be3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java
@@ -21,6 +21,8 @@ package org.apache.ambari.server.controller.internal;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+
import org.apache.ambari.server.actionmanager.ActionDBAccessor;
import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.actionmanager.RequestFactory;
@@ -36,6 +38,8 @@ import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.ResourceProvider;
import org.apache.ambari.server.controller.utilities.PredicateBuilder;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.metadata.CachedRoleCommandOrderProvider;
+import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
import org.apache.ambari.server.orm.DBAccessor;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.scheduler.ExecutionScheduler;
@@ -48,7 +52,6 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService;
import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl;
import org.apache.ambari.server.stack.StackManagerFactory;
import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.ConfigFactory;
import org.apache.ambari.server.state.ServiceComponentFactory;
@@ -227,7 +230,7 @@ public class UserResourceProviderTest extends EasyMockSupport {
bind(RequestFactory.class).toInstance(createNiceMock(RequestFactory.class));
bind(RequestExecutionFactory.class).toInstance(createNiceMock(RequestExecutionFactory.class));
bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class));
- bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class);
+ install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
bind(AbstractRootServiceResponseFactory.class).toInstance(createNiceMock(AbstractRootServiceResponseFactory.class));
bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class));
@@ -240,6 +243,7 @@ public class UserResourceProviderTest extends EasyMockSupport {
bind(KerberosHelper.class).toInstance(createNiceMock(KerberosHelper.class));
bind(Users.class).toInstance(createMock(Users.class));
bind(AmbariManagementController.class).to(AmbariManagementControllerImpl.class);
+ bind(RoleCommandOrderProvider.class).to(CachedRoleCommandOrderProvider.class);
bind(CredentialStoreService.class).to(CredentialStoreServiceImpl.class);
bind(HostRoleCommandDAO.class).toInstance(createMock(HostRoleCommandDAO.class));
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/5fdc9f97/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewURLResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewURLResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewURLResourceProviderTest.java
index e223d0f..e155b20 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewURLResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ViewURLResourceProviderTest.java
@@ -18,73 +18,42 @@
package org.apache.ambari.server.controller.internal;
-import com.google.common.base.Optional;
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.actionmanager.ActionDBAccessor;
-import org.apache.ambari.server.actionmanager.ActionManager;
-import org.apache.ambari.server.actionmanager.StageFactory;
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.controller.AbstractRootServiceResponseFactory;
-import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
-import org.apache.ambari.server.controller.KerberosHelper;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.ambari.server.controller.predicate.EqualsPredicate;
import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
import org.apache.ambari.server.controller.utilities.PredicateBuilder;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import org.apache.ambari.server.orm.DBAccessor;
-import org.apache.ambari.server.orm.dao.UserDAO;
import org.apache.ambari.server.orm.dao.ViewURLDAO;
-import org.apache.ambari.server.orm.dao.WidgetLayoutDAO;
import org.apache.ambari.server.orm.entities.ViewEntity;
-import org.apache.ambari.server.orm.entities.ViewInstanceDataEntity;
import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
import org.apache.ambari.server.orm.entities.ViewURLEntity;
-import org.apache.ambari.server.scheduler.ExecutionScheduler;
import org.apache.ambari.server.security.TestAuthenticationFactory;
-import org.apache.ambari.server.security.authorization.AuthorizationException;
-import org.apache.ambari.server.security.authorization.Users;
-import org.apache.ambari.server.security.encryption.CredentialStoreService;
-import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl;
-import org.apache.ambari.server.stack.StackManagerFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl;
-import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.ConfigFactory;
-import org.apache.ambari.server.state.ServiceComponentFactory;
-import org.apache.ambari.server.state.ServiceComponentHostFactory;
-import org.apache.ambari.server.state.ServiceFactory;
-import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
-import org.apache.ambari.server.state.scheduler.RequestExecutionFactory;
-import org.apache.ambari.server.state.stack.OsFamily;
import org.apache.ambari.server.view.ViewRegistry;
-import org.apache.ambari.server.view.configuration.ViewConfig;
-import org.apache.ambari.view.ViewDefinition;
import org.easymock.Capture;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.crypto.password.PasswordEncoder;
-import javax.persistence.EntityManager;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import com.google.common.base.Optional;
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.newCapture;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
public class ViewURLResourceProviderTest {