예제 #1
0
  protected Protos.Resource rangeResource(String name, long begin, long end) {
    // For a given named resource and value,
    // find and return the role that matches the name and exceeds the value.
    // Give preference to reserved offers first (those whose roles do not match "*")
    List<Protos.Resource> reservedResources = new LinkedList<>();
    for (Protos.Resource resource : offer.getResourcesList()) {
      if (resource.hasRole() && !resource.getRole().equals("*")) {
        reservedResources.add(resource);
      }
    }

    String role = "*";
    for (Protos.Resource resource : reservedResources) {
      if (resource.getName() == name) {
        Protos.Value.Ranges ranges = resource.getRanges();
        for (Protos.Value.Range range : ranges.getRangeList()) {
          if (range.getBegin() <= begin && range.getEnd() >= end) {
            role = resource.getRole();
            break;
          }
        }
      }
    }

    return Protos.Resource.newBuilder()
        .setType(Protos.Value.Type.RANGES)
        .setName(name)
        .setRanges(
            Protos.Value.Ranges.newBuilder()
                .addRange(Protos.Value.Range.newBuilder().setBegin(begin).setEnd(end))
                .build())
        .setRole(role)
        .build();
  }
예제 #2
0
 private List<Protos.Resource> getWorkerRequiredResources(long workerCpus, long workerMem) {
   List<Protos.Resource> resources = getCoreRequiredResouces(workerCpus, workerMem);
   // Set worker rcp port, web ui port, data port as range resources for this task.
   // By default, it would require 29998, 29999, 30000 ports for worker process.
   resources.add(
       Protos.Resource.newBuilder()
           .setName(Constants.MESOS_RESOURCE_PORTS)
           .setType(Protos.Value.Type.RANGES)
           .setRanges(
               Protos.Value.Ranges.newBuilder()
                   .addRange(
                       Protos.Value.Range.newBuilder()
                           .setBegin(Configuration.getLong(PropertyKey.WORKER_RPC_PORT))
                           .setEnd(Configuration.getLong(PropertyKey.WORKER_RPC_PORT)))
                   .addRange(
                       Protos.Value.Range.newBuilder()
                           .setBegin(Configuration.getLong(PropertyKey.WORKER_DATA_PORT))
                           .setEnd(Configuration.getLong(PropertyKey.WORKER_DATA_PORT)))
                   .addRange(
                       (Protos.Value.Range.newBuilder()
                           .setBegin(Configuration.getLong(PropertyKey.WORKER_WEB_PORT))
                           .setEnd(Configuration.getLong(PropertyKey.WORKER_WEB_PORT)))))
           .build());
   return resources;
 }
예제 #3
0
 private static int getPortsFrom(Protos.TaskInfo taskInfo) {
   double portCount = 0;
   for (Protos.Resource resource : taskInfo.getResourcesList()) {
     if (resource.getName() == "ports") {
       for (Protos.Value.Range range : resource.getRanges().getRangeList()) {
         portCount = 1 + range.getEnd() - range.getBegin();
       }
     }
   }
   return (int) portCount;
 }
예제 #4
0
 private static List<VirtualMachineLease.Range> getPortsFrom(Protos.Offer offer) {
   List<VirtualMachineLease.Range> ranges = new ArrayList<>();
   for (Protos.Resource resource : offer.getResourcesList()) {
     if (resource.getName() == "ports") {
       for (Protos.Value.Range range : resource.getRanges().getRangeList()) {
         int beg = (int) range.getBegin();
         int end = (int) range.getEnd();
         VirtualMachineLease.Range vmRange = new VirtualMachineLease.Range(beg, end);
         ranges.add(vmRange);
       }
     }
   }
   return ranges;
 }
예제 #5
0
 public static Protos.Resource portRange(long beginPort, long endPort) {
   Protos.Value.Range singlePortRange =
       Protos.Value.Range.newBuilder().setBegin(beginPort).setEnd(endPort).build();
   return Protos.Resource.newBuilder()
       .setName("ports")
       .setType(Protos.Value.Type.RANGES)
       .setRanges(Protos.Value.Ranges.newBuilder().addRange(singlePortRange))
       .build();
 }