@Before public void before() { this.pcm = createPCM(); // Build appIDs, constraints, source tags, and constraint map. long ts = System.currentTimeMillis(); appId1 = BuilderUtils.newApplicationId(ts, 123); appId2 = BuilderUtils.newApplicationId(ts, 234); c1 = PlacementConstraints.build(targetIn(NODE, allocationTag("hbase-m"))); c2 = PlacementConstraints.build(targetIn(RACK, allocationTag("hbase-rs"))); c3 = PlacementConstraints .build(targetNotIn(NODE, nodeAttribute("java", "1.8"))); c4 = PlacementConstraints .build(targetCardinality(RACK, 2, 10, allocationTag("zk"))); sourceTag1 = new HashSet<>(Arrays.asList("spark")); sourceTag2 = new HashSet<>(Arrays.asList("zk")); sourceTag3 = new HashSet<>(Arrays.asList("storm")); sourceTag4 = new HashSet<>(Arrays.asList("hbase-m", "hbase-sec")); constraintMap1 = Stream .of(new SimpleEntry<>(sourceTag1, c1), new SimpleEntry<>(sourceTag2, c2)) .collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)); constraintMap2 = Stream.of(new SimpleEntry<>(sourceTag3, c4)) .collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)); }
@Test public void testAndConstraint() { AbstractConstraint constraintExpr = and(targetIn(RACK, allocationTag("spark")), maxCardinality(NODE, 3, "spark"), targetCardinality(RACK, 2, 10, allocationTag("zk"))); And andExpr = (And) constraintExpr; Assert.assertEquals(3, andExpr.getChildren().size()); SingleConstraint sConstr = (SingleConstraint) andExpr.getChildren().get(0); TargetExpression tExpr = sConstr.getTargetExpressions().iterator().next(); Assert.assertEquals("spark", tExpr.getTargetValues().iterator().next()); sConstr = (SingleConstraint) andExpr.getChildren().get(1); Assert.assertEquals(0, sConstr.getMinCardinality()); Assert.assertEquals(3, sConstr.getMaxCardinality()); sConstr = (SingleConstraint) andExpr.getChildren().get(2); Assert.assertEquals(2, sConstr.getMinCardinality()); Assert.assertEquals(10, sConstr.getMaxCardinality()); } }
.build(targetCardinality(NODE, 0, 1, allocationTag("foo")))); MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm2, constraintMap); am1.addSchedulingRequest(
@Test public void testTargetCardinalityConstraint() { AbstractConstraint constraintExpr = targetCardinality(RACK, 3, 10, allocationTag("zk")); Assert.assertTrue(constraintExpr instanceof SingleConstraint); PlacementConstraint constraint = PlacementConstraints.build(constraintExpr); // Apply transformation. Should be a no-op. SpecializedConstraintTransformer specTransformer = new SpecializedConstraintTransformer(constraint); PlacementConstraint newConstraint = specTransformer.transform(); // The constraint expression should be the same. Assert.assertEquals(constraintExpr, newConstraint.getConstraintExpr()); }
Collections.singletonMap(Collections.singleton("foo"), PlacementConstraints.build(PlacementConstraints .targetCardinality(NODE, 0, 3, allocationTag("foo"))))); am1.addSchedulingRequest( Arrays.asList(schedulingRequest(1, 1, 1, 512, "foo"),
AbstractConstraint constraintExpr = or(targetIn(RACK, allocationTag("spark")), maxCardinality(NODE, 3), targetCardinality(RACK, 2, 10, allocationTag("zk"))); Assert.assertTrue(constraintExpr instanceof Or); PlacementConstraint constraint = PlacementConstraints.build(constraintExpr);
AbstractConstraint constraintExpr = or(targetIn(RACK, allocationTag("spark")), maxCardinality(NODE, 3), targetCardinality(RACK, 2, 10, allocationTag("zk"))); Assert.assertTrue(constraintExpr instanceof Or); PlacementConstraint constraint = PlacementConstraints.build(constraintExpr);
.allocationRequestId(10L).priority(Priority.newInstance(1)) .placementConstraintExpression(PlacementConstraints .targetCardinality(PlacementConstraints.NODE, 0, 1, PlacementConstraints.PlacementTargets .allocationTag("mapper"),