@Test public void acceptsNodeCountWithinLimits() { Set<HostGroup> request = Set.of( hostGroup("master", 2), hostGroup("worker", 4) ); Map<String, InstanceCount> requirements = Map.of( "master", InstanceCount.of(1, 2), "worker", InstanceCount.atLeast(3) ); validateHostGroupCardinality(request, requirements); }
public static void validateHostGroupCardinality(Set<HostGroup> hostGroups, Map<String, InstanceCount> blueprintHostGroupCardinality) { List<String> failures = new LinkedList<>(); for (HostGroup hostGroup : hostGroups) { InstanceCount requiredCount = blueprintHostGroupCardinality.get(hostGroup.getName()); int count = hostGroup.getInstanceGroup().getNodeCount(); if (!requiredCount.isAcceptable(count)) { failures.add(String.format("(group: '%s', required: %s, actual: %d)", hostGroup.getName(), requiredCount, count)); } } if (!failures.isEmpty()) { throw new BlueprintValidationException("Node count for the following host groups does not meet requirements: " + String.join(", ", failures)); } }
BlueprintValidatorUtil { public static void validateHostGroupCardinality(Set<HostGroup> hostGroups, Map<String, InstanceCount> blueprintHostGroupCardinality) { List<String> failures = new LinkedList<>(); for (HostGroup hostGroup : hostGroups) { InstanceCount requiredCount = blueprintHostGroupCardinality.get(hostGroup.getName()); int count = hostGroup.getInstanceGroup().getNodeCount(); if (!requiredCount.isAcceptable(count)) { failures.add(String.format("(group: '%s', required: %s, actual: %d)", hostGroup.getName(), requiredCount, count)); } } if (!failures.isEmpty()) { throw new BlueprintValidationException("Node count for the following host groups does not meet requirements: " + String.join(", ", failures)); } } }
BlueprintValidatorUtil { public static void validateHostGroupCardinality(Set<HostGroup> hostGroups, Map<String, InstanceCount> blueprintHostGroupCardinality) { List<String> failures = new LinkedList<>(); for (HostGroup hostGroup : hostGroups) { InstanceCount requiredCount = blueprintHostGroupCardinality.get(hostGroup.getName()); int count = hostGroup.getInstanceGroup().getNodeCount(); if (!requiredCount.isAcceptable(count)) { failures.add(String.format("(group: '%s', required: %s, actual: %d)", hostGroup.getName(), requiredCount, count)); } } if (!failures.isEmpty()) { throw new BlueprintValidationException("Node count for the following host groups does not meet requirements: " + String.join(", ", failures)); } } private  BlueprintValidatorUtil(); }
BlueprintValidatorUtil { public static void validateHostGroupCardinality(Set<HostGroup> hostGroups, Map<String, InstanceCount> blueprintHostGroupCardinality) { List<String> failures = new LinkedList<>(); for (HostGroup hostGroup : hostGroups) { InstanceCount requiredCount = blueprintHostGroupCardinality.get(hostGroup.getName()); int count = hostGroup.getInstanceGroup().getNodeCount(); if (!requiredCount.isAcceptable(count)) { failures.add(String.format("(group: '%s', required: %s, actual: %d)", hostGroup.getName(), requiredCount, count)); } } if (!failures.isEmpty()) { throw new BlueprintValidationException("Node count for the following host groups does not meet requirements: " + String.join(", ", failures)); } } private  BlueprintValidatorUtil(); static void validateHostGroupsMatch(Set<HostGroup> hostGroupsInRequest, Set<String> hostGroupsInBlueprint); static void validateInstanceGroups(Collection<HostGroup> hostGroups, Collection<InstanceGroup> instanceGroups); static Map<String, HostGroup> createHostGroupMap(Iterable<HostGroup> hostGroups); static void validateHostGroupCardinality(Set<HostGroup> hostGroups, Map<String, InstanceCount> blueprintHostGroupCardinality); }
BlueprintValidatorUtil { public static void validateHostGroupCardinality(Set<HostGroup> hostGroups, Map<String, InstanceCount> blueprintHostGroupCardinality) { List<String> failures = new LinkedList<>(); for (HostGroup hostGroup : hostGroups) { InstanceCount requiredCount = blueprintHostGroupCardinality.get(hostGroup.getName()); int count = hostGroup.getInstanceGroup().getNodeCount(); if (!requiredCount.isAcceptable(count)) { failures.add(String.format("(group: '%s', required: %s, actual: %d)", hostGroup.getName(), requiredCount, count)); } } if (!failures.isEmpty()) { throw new BlueprintValidationException("Node count for the following host groups does not meet requirements: " + String.join(", ", failures)); } } private  BlueprintValidatorUtil(); static void validateHostGroupsMatch(Set<HostGroup> hostGroupsInRequest, Set<String> hostGroupsInBlueprint); static void validateInstanceGroups(Collection<HostGroup> hostGroups, Collection<InstanceGroup> instanceGroups); static Map<String, HostGroup> createHostGroupMap(Iterable<HostGroup> hostGroups); static void validateHostGroupCardinality(Set<HostGroup> hostGroups, Map<String, InstanceCount> blueprintHostGroupCardinality);  }