Search in sources :

Example 1 with Range

use of org.apache.mesos.Protos.Value.Range in project storm-mesos by nathanmarz.

the class MesosNimbus method getResources.

private OfferResources getResources(Offer offer, int cpu, int mem) {
    OfferResources resources = new OfferResources();
    for (Resource r : offer.getResourcesList()) {
        if (r.getName().equals("cpus")) {
            resources.cpuSlots = (int) Math.floor(r.getScalar().getValue() / cpu);
        } else if (r.getName().equals("mem")) {
            resources.memSlots = (int) Math.floor(r.getScalar().getValue() / mem);
        }
    }
    int maxPorts = Math.min(resources.cpuSlots, resources.memSlots);
    for (Resource r : offer.getResourcesList()) {
        if (r.getName().equals("ports")) {
            for (Range range : r.getRanges().getRangeList()) {
                if (resources.ports.size() >= maxPorts) {
                    break;
                } else {
                    int start = (int) range.getBegin();
                    int end = (int) range.getEnd();
                    for (int p = start; p <= end; p++) {
                        resources.ports.add(p);
                        if (resources.ports.size() >= maxPorts) {
                            break;
                        }
                    }
                }
            }
        }
    }
    LOG.debug("Offer: " + offer.toString());
    LOG.debug("Extracted resources: " + resources.toString());
    return resources;
}
Also used : Resource(org.apache.mesos.Protos.Resource) Range(org.apache.mesos.Protos.Value.Range)

Aggregations

Resource (org.apache.mesos.Protos.Resource)1 Range (org.apache.mesos.Protos.Value.Range)1