Exemplo n.º 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();
  }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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;
 }