/** * Similar to {@link #cardinality(String, int, int, String...)}, but * determines only the maximum cardinality (the minimum cardinality is 0). * * @param scope the scope of the constraint * @param maxCardinality determines the maximum number of allocations within * the scope * @param allocationTags the constraint targets allocations with these tags * @return the resulting placement constraint */ public static AbstractConstraint maxCardinality(String scope, int maxCardinality, String... allocationTags) { return cardinality(scope, 0, maxCardinality, allocationTags); }
/** * Similar to {@link #cardinality(String, int, int, String...)}, but * determines only the minimum cardinality (the maximum cardinality is * unbound). * * @param scope the scope of the constraint * @param minCardinality determines the minimum number of allocations within * the scope * @param allocationTags the constraint targets allocations with these tags * @return the resulting placement constraint */ public static AbstractConstraint minCardinality(String scope, int minCardinality, String... allocationTags) { return cardinality(scope, minCardinality, Integer.MAX_VALUE, allocationTags); }
/** * Similar to {@link #minCardinality(String, int, String...)}, but let you * attach a namespace to the allocation tags. * * @param scope the scope of the constraint * @param namespace the namespace of these tags * @param minCardinality determines the minimum number of allocations within * the scope * @param allocationTags the constraint targets allocations with these tags * @return the resulting placement constraint */ public static AbstractConstraint minCardinality(String scope, String namespace, int minCardinality, String... allocationTags) { return cardinality(scope, namespace, minCardinality, Integer.MAX_VALUE, allocationTags); }
/** * Similar to {@link #maxCardinality(String, int, String...)}, but let you * specify a namespace for the tags, see supported namespaces in * {@link AllocationTagNamespaceType}. * * @param scope the scope of the constraint * @param tagNamespace the namespace of these tags * @param maxCardinality determines the maximum number of allocations within * the scope * @param allocationTags allocation tags * @return the resulting placement constraint */ public static AbstractConstraint maxCardinality(String scope, String tagNamespace, int maxCardinality, String... allocationTags) { return cardinality(scope, tagNamespace, 0, maxCardinality, allocationTags); }
return PlacementConstraints.cardinality(scope, min, max, targetTags.toArray(new String[targetTags.size()]));
Assert.assertEquals("foo", tag1.getTag()); Assert.assertEquals(10, tag1.getNumOfAllocations()); expectedPc1 = cardinality("node", 0, 100, "foo", "bar").build(); Assert.assertEquals(expectedPc1, result.values().iterator().next());
@Test public void testCardinalityConstraintProtoConverter() { AbstractConstraint sConstraintExpr = cardinality(RACK, 3, 10); Assert.assertTrue(sConstraintExpr instanceof SingleConstraint); SingleConstraint single = (SingleConstraint) sConstraintExpr; PlacementConstraint sConstraint = PlacementConstraints.build(sConstraintExpr); // Convert to proto. PlacementConstraintToProtoConverter toProtoConverter = new PlacementConstraintToProtoConverter(sConstraint); PlacementConstraintProto protoConstraint = toProtoConverter.convert(); compareSimpleConstraintToProto(single, protoConstraint); // Convert from proto. PlacementConstraintFromProtoConverter fromProtoConverter = new PlacementConstraintFromProtoConverter(protoConstraint); PlacementConstraint newConstraint = fromProtoConverter.convert(); AbstractConstraint newConstraintExpr = newConstraint.getConstraintExpr(); Assert.assertTrue(newConstraintExpr instanceof SingleConstraint); SingleConstraint newSingle = (SingleConstraint) newConstraintExpr; compareSimpleConstraints(single, newSingle); }
am3.registerAppAttempt(); pc = cardinality("node", new TargetApplicationsNamespace.NotSelf().toString(), 1, 1, "foo").build();
new TargetApplicationsNamespace.AppTag("web-server").toString(), "ws-inst")), cardinality("node", 0, 2, "ws-servant")).build(); am3.addSchedulingRequest( ImmutableList.of(