@Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("or("); Iterator<AbstractConstraint> it = getChildren().iterator(); while (it.hasNext()) { AbstractConstraint child = it.next(); sb.append(child.toString()); if (it.hasNext()) { sb.append(":"); } } sb.append(")"); return sb.toString(); } }
private AbstractConstraint convert(CompositePlacementConstraintProto proto) { switch (proto.getCompositeType()) { case AND: case OR: List<AbstractConstraint> children = new ArrayList<>(); for (PlacementConstraintProto cp : proto.getChildConstraintsList()) { children.add(convert(cp)); } return (proto.getCompositeType() == AND) ? new And(children) : new Or(children); case DELAYED_OR: List<TimedPlacementConstraint> tChildren = new ArrayList<>(); for (TimedPlacementConstraintProto cp : proto .getTimedChildConstraintsList()) { tChildren.add(convert(cp)); } return new DelayedOr(tChildren); default: throw new YarnRuntimeException( "Encountered unexpected type of composite constraint."); } }
PlacementConstraints.PlacementTargets .nodeAttribute("java", "1.8"))) .build()).resourceSizing( ResourceSizing.newInstance(1, Resource.newInstance(1024, 1))) .build();
Assert.assertEquals(3, cProto.getChildConstraintsCount()); Assert.assertEquals(0, cProto.getTimedChildConstraintsCount()); Iterator<AbstractConstraint> orChildren = orExpr.getChildren().iterator(); Iterator<PlacementConstraintProto> orProtoChildren = cProto.getChildConstraintsList().iterator(); Assert.assertTrue(newConstraintExpr instanceof Or); Or newOrExpr = (Or) newConstraintExpr; Assert.assertEquals(3, newOrExpr.getChildren().size()); orChildren = orExpr.getChildren().iterator(); Iterator<AbstractConstraint> newOrChildren = newOrExpr.getChildren().iterator(); while (orChildren.hasNext() && newOrChildren.hasNext()) { AbstractConstraint orChild = orChildren.next();
Assert.assertTrue(constraint instanceof Or); or = (Or) constraint; Assert.assertEquals(2, or.getChildren().size()); verifyConstraintToString(expressionExpr, constraint); constraint = parser.parse(); Assert.assertTrue(constraint instanceof Or); Assert.assertEquals(2, or.getChildren().size()); verifyConstraintToString(expressionExpr, constraint); Assert.assertTrue(constraint instanceof Or); or = (Or) constraint; Assert.assertTrue(or.getChildren().get(0) instanceof SingleConstraint); Assert.assertTrue(or.getChildren().get(1) instanceof Or); or = (Or) or.getChildren().get(1); Assert.assertEquals(2, or.getChildren().size()); verifyConstraintToString(expressionExpr, constraint);
PlacementConstraint constraint = PlacementConstraints.build(constraintExpr); Or orExpr = (Or) constraintExpr; for (AbstractConstraint child : orExpr.getChildren()) { Assert.assertTrue(child instanceof SingleConstraint); List<AbstractConstraint> specChildren = specOrExpr.getChildren(); Assert.assertEquals(3, specChildren.size()); Assert.assertTrue(specChildren.get(0) instanceof TargetConstraint); Assert.assertTrue(simConstraint.getConstraintExpr() instanceof Or); Or simOrExpr = (Or) specConstraint.getConstraintExpr(); for (AbstractConstraint child : simOrExpr.getChildren()) { Assert.assertTrue(child instanceof SingleConstraint);
/** * Returns true as long as any of child constraint is satisfied. * @param appId application id * @param constraint Or constraint * @param node node * @param atm allocation tags manager * @return true if any child constraint is satisfied, false otherwise * @throws InvalidAllocationTagsQueryException */ private static boolean canSatisfyOrConstraint(ApplicationId appId, Or constraint, SchedulerNode node, AllocationTagsManager atm) throws InvalidAllocationTagsQueryException { for (AbstractConstraint child : constraint.getChildren()) { if (canSatisfyConstraints(appId, child.build(), node, atm)) { return true; } } return false; }
/** * A disjunction of constraints. * * @param children the children constraints, one of which should be satisfied * @return the resulting placement constraint */ public static Or or(AbstractConstraint... children) { return new Or(children); }