|
@@ -75,24 +75,24 @@ public class TestAllocationTagsManager {
|
|
|
|
|
|
// 3 Containers from app1
|
|
|
atm.addContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 1),
|
|
|
+ TestUtils.getMockContainerId(1, 1),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 2),
|
|
|
+ TestUtils.getMockContainerId(1, 2),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 3),
|
|
|
+ TestUtils.getMockContainerId(1, 3),
|
|
|
ImmutableSet.of("service"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 4),
|
|
|
+ TestUtils.getMockContainerId(1, 4),
|
|
|
ImmutableSet.of("reducer"));
|
|
|
|
|
|
// 1 Container from app2
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(2), TestUtils.getMockContainerId(2, 3),
|
|
|
+ TestUtils.getMockContainerId(2, 3),
|
|
|
ImmutableSet.of("service"));
|
|
|
|
|
|
// Get Node Cardinality of app1 on node1, with tag "mapper"
|
|
@@ -170,24 +170,21 @@ public class TestAllocationTagsManager {
|
|
|
|
|
|
// Finish all containers:
|
|
|
atm.removeContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 1),
|
|
|
+ TestUtils.getMockContainerId(1, 1),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.removeContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 2),
|
|
|
+ TestUtils.getMockContainerId(1, 2),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.removeContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 3),
|
|
|
- ImmutableSet.of("service"));
|
|
|
+ TestUtils.getMockContainerId(1, 3), ImmutableSet.of("service"));
|
|
|
|
|
|
atm.removeContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 4),
|
|
|
- ImmutableSet.of("reducer"));
|
|
|
+ TestUtils.getMockContainerId(1, 4), ImmutableSet.of("reducer"));
|
|
|
|
|
|
atm.removeContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(2), TestUtils.getMockContainerId(2, 3),
|
|
|
- ImmutableSet.of("service"));
|
|
|
+ TestUtils.getMockContainerId(2, 3), ImmutableSet.of("service"));
|
|
|
|
|
|
// Expect all cardinality to be 0
|
|
|
// Get Cardinality of app1 on node1, with tag "mapper"
|
|
@@ -270,25 +267,22 @@ public class TestAllocationTagsManager {
|
|
|
|
|
|
// 3 Containers from app1
|
|
|
atm.addContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 1),
|
|
|
+ TestUtils.getMockContainerId(1, 1),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(2), TestUtils.getMockContainerId(2, 2),
|
|
|
+ TestUtils.getMockContainerId(2, 2),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(2), TestUtils.getMockContainerId(2, 4),
|
|
|
- ImmutableSet.of("reducer"));
|
|
|
+ TestUtils.getMockContainerId(2, 4), ImmutableSet.of("reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 3),
|
|
|
- ImmutableSet.of("service"));
|
|
|
+ TestUtils.getMockContainerId(1, 3), ImmutableSet.of("service"));
|
|
|
|
|
|
// 1 Container from app2
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(2), TestUtils.getMockContainerId(2, 3),
|
|
|
- ImmutableSet.of("service"));
|
|
|
+ TestUtils.getMockContainerId(2, 3), ImmutableSet.of("service"));
|
|
|
|
|
|
// Get Rack Cardinality of app1 on rack0, with tag "mapper"
|
|
|
Assert.assertEquals(1, atm.getRackCardinality("rack0",
|
|
@@ -325,45 +319,39 @@ public class TestAllocationTagsManager {
|
|
|
|
|
|
// Add a bunch of containers
|
|
|
atm.addContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 1),
|
|
|
+ TestUtils.getMockContainerId(1, 1),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 2),
|
|
|
+ TestUtils.getMockContainerId(1, 2),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 3),
|
|
|
- ImmutableSet.of("service"));
|
|
|
+ TestUtils.getMockContainerId(1, 3), ImmutableSet.of("service"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 4),
|
|
|
- ImmutableSet.of("reducer"));
|
|
|
+ TestUtils.getMockContainerId(1, 4), ImmutableSet.of("reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(2), TestUtils.getMockContainerId(2, 3),
|
|
|
- ImmutableSet.of("service"));
|
|
|
+ TestUtils.getMockContainerId(2, 3), ImmutableSet.of("service"));
|
|
|
|
|
|
// Remove all these containers
|
|
|
atm.removeContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 1),
|
|
|
+ TestUtils.getMockContainerId(1, 1),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.removeContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 2),
|
|
|
+ TestUtils.getMockContainerId(1, 2),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.removeContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 3),
|
|
|
- ImmutableSet.of("service"));
|
|
|
+ TestUtils.getMockContainerId(1, 3), ImmutableSet.of("service"));
|
|
|
|
|
|
atm.removeContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 4),
|
|
|
- ImmutableSet.of("reducer"));
|
|
|
+ TestUtils.getMockContainerId(1, 4), ImmutableSet.of("reducer"));
|
|
|
|
|
|
atm.removeContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(2), TestUtils.getMockContainerId(2, 3),
|
|
|
- ImmutableSet.of("service"));
|
|
|
+ TestUtils.getMockContainerId(2, 3), ImmutableSet.of("service"));
|
|
|
|
|
|
// Check internal data structure
|
|
|
Assert.assertEquals(0,
|
|
@@ -374,6 +362,87 @@ public class TestAllocationTagsManager {
|
|
|
Assert.assertEquals(0, atm.getPerAppRackMappings().size());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testTempContainerAllocations()
|
|
|
+ throws InvalidAllocationTagsQueryException {
|
|
|
+ /**
|
|
|
+ * Construct both TEMP and normal containers: Node1: TEMP container_1_1
|
|
|
+ * (mapper/reducer/app_1) container_1_2 (service/app_1)
|
|
|
+ *
|
|
|
+ * Node2: container_1_3 (reducer/app_1) TEMP container_2_1 (service/app_2)
|
|
|
+ */
|
|
|
+
|
|
|
+ AllocationTagsManager atm = new AllocationTagsManager(rmContext);
|
|
|
+
|
|
|
+ // 3 Containers from app1
|
|
|
+ atm.addTempContainer(NodeId.fromString("host1:123"),
|
|
|
+ TestUtils.getMockApplicationId(1),
|
|
|
+ ImmutableSet.of("mapper", "reducer"));
|
|
|
+
|
|
|
+ atm.addContainer(NodeId.fromString("host1:123"),
|
|
|
+ TestUtils.getMockContainerId(1, 2), ImmutableSet.of("service"));
|
|
|
+
|
|
|
+ atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
+ TestUtils.getMockContainerId(1, 3), ImmutableSet.of("reducer"));
|
|
|
+
|
|
|
+ // 1 Container from app2
|
|
|
+ atm.addTempContainer(NodeId.fromString("host2:123"),
|
|
|
+ TestUtils.getMockApplicationId(2), ImmutableSet.of("service"));
|
|
|
+
|
|
|
+ // Expect tag mappings to be present including temp Tags
|
|
|
+ Assert.assertEquals(1,
|
|
|
+ atm.getNodeCardinalityByOp(NodeId.fromString("host1:123"),
|
|
|
+ TestUtils.getMockApplicationId(1), ImmutableSet.of("mapper"),
|
|
|
+ Long::sum));
|
|
|
+
|
|
|
+ Assert.assertEquals(1,
|
|
|
+ atm.getNodeCardinalityByOp(NodeId.fromString("host1:123"),
|
|
|
+ TestUtils.getMockApplicationId(1), ImmutableSet.of("service"),
|
|
|
+ Long::sum));
|
|
|
+
|
|
|
+ Assert.assertEquals(1,
|
|
|
+ atm.getNodeCardinalityByOp(NodeId.fromString("host2:123"),
|
|
|
+ TestUtils.getMockApplicationId(2), ImmutableSet.of("service"),
|
|
|
+ Long::sum));
|
|
|
+
|
|
|
+ // Do a temp Tag cleanup on app2
|
|
|
+ atm.cleanTempContainers(TestUtils.getMockApplicationId(2));
|
|
|
+ Assert.assertEquals(0,
|
|
|
+ atm.getNodeCardinalityByOp(NodeId.fromString("host2:123"),
|
|
|
+ TestUtils.getMockApplicationId(2), ImmutableSet.of("service"),
|
|
|
+ Long::sum));
|
|
|
+ // Expect app1 to be unaffected
|
|
|
+ Assert.assertEquals(1,
|
|
|
+ atm.getNodeCardinalityByOp(NodeId.fromString("host1:123"),
|
|
|
+ TestUtils.getMockApplicationId(1), ImmutableSet.of("mapper"),
|
|
|
+ Long::sum));
|
|
|
+ // Do a cleanup on app1 as well
|
|
|
+ atm.cleanTempContainers(TestUtils.getMockApplicationId(1));
|
|
|
+ Assert.assertEquals(0,
|
|
|
+ atm.getNodeCardinalityByOp(NodeId.fromString("host1:123"),
|
|
|
+ TestUtils.getMockApplicationId(1), ImmutableSet.of("mapper"),
|
|
|
+ Long::sum));
|
|
|
+
|
|
|
+ // Non temp-tags should be unaffected
|
|
|
+ Assert.assertEquals(1,
|
|
|
+ atm.getNodeCardinalityByOp(NodeId.fromString("host1:123"),
|
|
|
+ TestUtils.getMockApplicationId(1), ImmutableSet.of("service"),
|
|
|
+ Long::sum));
|
|
|
+
|
|
|
+ Assert.assertEquals(0,
|
|
|
+ atm.getNodeCardinalityByOp(NodeId.fromString("host2:123"),
|
|
|
+ TestUtils.getMockApplicationId(2), ImmutableSet.of("service"),
|
|
|
+ Long::sum));
|
|
|
+
|
|
|
+ // Expect app2 with no containers, and app1 with 2 containers across 2 nodes
|
|
|
+ Assert.assertEquals(2,
|
|
|
+ atm.getPerAppNodeMappings().get(TestUtils.getMockApplicationId(1))
|
|
|
+ .getTypeToTagsWithCount().size());
|
|
|
+
|
|
|
+ Assert.assertNull(
|
|
|
+ atm.getPerAppNodeMappings().get(TestUtils.getMockApplicationId(2)));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testQueryCardinalityWithIllegalParameters()
|
|
|
throws InvalidAllocationTagsQueryException {
|
|
@@ -385,24 +454,21 @@ public class TestAllocationTagsManager {
|
|
|
|
|
|
// Add a bunch of containers
|
|
|
atm.addContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 1),
|
|
|
+ TestUtils.getMockContainerId(1, 1),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 2),
|
|
|
+ TestUtils.getMockContainerId(1, 2),
|
|
|
ImmutableSet.of("mapper", "reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host1:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 3),
|
|
|
- ImmutableSet.of("service"));
|
|
|
+ TestUtils.getMockContainerId(1, 3), ImmutableSet.of("service"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(1), TestUtils.getMockContainerId(1, 4),
|
|
|
- ImmutableSet.of("reducer"));
|
|
|
+ TestUtils.getMockContainerId(1, 4), ImmutableSet.of("reducer"));
|
|
|
|
|
|
atm.addContainer(NodeId.fromString("host2:123"),
|
|
|
- TestUtils.getMockApplicationId(2), TestUtils.getMockContainerId(2, 3),
|
|
|
- ImmutableSet.of("service"));
|
|
|
+ TestUtils.getMockContainerId(2, 3), ImmutableSet.of("service"));
|
|
|
|
|
|
// No node-id
|
|
|
boolean caughtException = false;
|