.append(getNodeAttributeOpCode()).append(",") .append(targetExpr) .toString());
private static boolean canSatisfyNodeConstraintExpression( SingleConstraint sc, TargetExpression targetExpression, SchedulerNode schedulerNode) { Set<String> values = targetExpression.getTargetValues(); if (targetExpression.getTargetKey().equals(NODE_PARTITION)) { if (values == null || values.isEmpty()) { return schedulerNode.getPartition() .equals(RMNodeLabelsManager.NO_LABEL); } else { String nodePartition = values.iterator().next(); if (!nodePartition.equals(schedulerNode.getPartition())) { return false; } } } else { NodeAttributeOpCode opCode = sc.getNodeAttributeOpCode(); // compare attributes. String inputAttribute = values.iterator().next(); NodeAttribute requestAttribute = getNodeConstraintFromRequest( targetExpression.getTargetKey(), inputAttribute); if (requestAttribute == null) { return true; } return getNodeConstraintEvaluatedResult(schedulerNode, opCode, requestAttribute); } return true; }
@Override public int hashCode() { int result = getScope().hashCode(); result = 31 * result + getMinCardinality(); result = 31 * result + getMaxCardinality(); result = 31 * result + getNodeAttributeOpCode().hashCode(); result = 31 * result + getTargetExpressions().hashCode(); return result; }
@Override public GeneratedMessage visit(SingleConstraint constraint) { SimplePlacementConstraintProto.Builder sb = SimplePlacementConstraintProto.newBuilder(); if (constraint.getScope() != null) { sb.setScope(constraint.getScope()); } sb.setMinCardinality(constraint.getMinCardinality()); sb.setMaxCardinality(constraint.getMaxCardinality()); if (constraint.getNodeAttributeOpCode() != null) { sb.setAttributeOpCode( convertToProtoFormat(constraint.getNodeAttributeOpCode())); } if (constraint.getTargetExpressions() != null) { for (TargetExpression target : constraint.getTargetExpressions()) { sb.addTargetExpressions( (PlacementConstraintTargetProto) target.accept(this)); } } SimplePlacementConstraintProto sProto = sb.build(); // Wrap around PlacementConstraintProto object. PlacementConstraintProto.Builder pb = PlacementConstraintProto.newBuilder(); pb.setSimpleConstraint(sProto); return pb.build(); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof SingleConstraint)) { return false; } SingleConstraint that = (SingleConstraint) o; if (getMinCardinality() != that.getMinCardinality()) { return false; } if (getMaxCardinality() != that.getMaxCardinality()) { return false; } if (!getScope().equals(that.getScope())) { return false; } if (getNodeAttributeOpCode() != null && !getNodeAttributeOpCode() .equals(that.getNodeAttributeOpCode())) { return false; } return getTargetExpressions().equals(that.getTargetExpressions()); }