private boolean isValidCluster(Map<String, Integer> serviceCounts) { for (Map.Entry<String, ServiceConstraint> entry : serviceConstraints.entrySet()) { String service = entry.getKey(); ServiceConstraint constraint = entry.getValue(); int serviceCount = serviceCounts.get(service); // TODO: ratio constraint if (serviceCount < constraint.getMinCount() || serviceCount > constraint.getMaxCount() || serviceCount > numMachines) { return false; } } return true; }
@Override public int compare(Map.Entry<String, ServiceConstraint> entry1, Map.Entry<String, ServiceConstraint> entry2) { ServiceConstraint constraint1 = entry1.getValue(); ServiceConstraint constraint2 = entry2.getValue(); if (constraint1 == null && constraint2 != null) { return 1; } else if (constraint1 != null && constraint2 == null) { return -1; } else if (constraint1 != null) { int compare = ((Integer) constraint1.getMaxCount()).compareTo(constraint2.getMaxCount()); if (compare != 0) { return compare; } compare = 0 - ((Integer) constraint1.getMinCount()).compareTo(constraint2.getMinCount()); if (compare != 0) { return compare; } } return entry1.getKey().compareTo(entry2.getKey()); } }
@Override public JsonElement serialize(ServiceConstraint serviceConstraint, Type type, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("hardwaretypes", context.serialize(serviceConstraint.getRequiredHardwareTypes())); jsonObj.add("imagetypes", context.serialize(serviceConstraint.getRequiredImageTypes())); JsonObject quantities = new JsonObject(); quantities.add("min", context.serialize(serviceConstraint.getMinCount())); quantities.add("max", context.serialize(serviceConstraint.getMaxCount())); jsonObj.add("quantities", quantities); return jsonObj; }
this.minNodesToAddTo = Math.max(serviceConstraint.getMinCount(), this.minNodesToAddTo);
private boolean satisfiesConstraints(Constraints constraints) { // check node layouts Set<String> clusterServices = serviceCounts.elementSet(); for (NodeLayout nodeLayout : layout.elementSet()) { if (!nodeLayout.satisfiesConstraints(constraints, clusterServices)) { return false; } } // check service counts Map<String, ServiceConstraint> serviceConstraints = constraints.getServiceConstraints(); for (Multiset.Entry<String> entry : serviceCounts.entrySet()) { ServiceConstraint constraint = serviceConstraints.get(entry.getElement()); if (constraint != null) { int serviceCount = entry.getCount(); // TODO: ratio constraint if (serviceCount < constraint.getMinCount() || serviceCount > constraint.getMaxCount() || serviceCount > layout.size()) { return false; } } } return true; }