public static Resource getPortsResource(int numPorts, Offer offer) {
return getPortsResource(numPorts, offer.getResourcesList());
}
public static Resource getPortsResource(int numPorts, List<Resource> resources) {
Ranges ranges = getRanges(resources, PORTS);
Preconditions.checkState(ranges != null, "Ports %s should have existed in resources %s", PORTS, resources);
Ranges.Builder rangesBldr = Ranges.newBuilder();
int portsSoFar = 0;
List<Range> offerRangeList = Lists.newArrayList(ranges.getRangeList());
Random random = new Random();
Collections.shuffle(offerRangeList, random);
for (Range range : offerRangeList) {