예제 #1
0
 private static double getDiskFrom(Protos.Offer offer) {
   for (Protos.Resource resource : offer.getResourcesList()) {
     if (resource.getName() == "disk") {
       return resource.getScalar().getValue();
     }
   }
   return -1;
 }
예제 #2
0
 private static double getDiskFrom(Protos.TaskInfo taskInfo) {
   for (Protos.Resource resource : taskInfo.getResourcesList()) {
     if (resource.getName() == "disk") {
       return resource.getScalar().getValue();
     }
   }
   return -1;
 }
예제 #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
  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();
  }
예제 #6
0
  protected Protos.Resource scalarResource(String name, double value) {
    // 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 && resource.getScalar().getValue() >= value) {
        role = resource.getRole();
        break;
      }
    }

    return Protos.Resource.newBuilder()
        .setName(name)
        .setType(Protos.Value.Type.SCALAR)
        .setScalar(Protos.Value.Scalar.newBuilder().setValue(value))
        .setRole(role)
        .build();
  }
예제 #7
0
 public static Protos.Resource disk(double disk) {
   return Protos.Resource.newBuilder()
       .setName("disk")
       .setType(Protos.Value.Type.SCALAR)
       .setScalar(Protos.Value.Scalar.newBuilder().setValue(disk).build())
       .build();
 }
예제 #8
0
 public static Protos.Resource mem(double mem) {
   return Protos.Resource.newBuilder()
       .setName("mem")
       .setType(Protos.Value.Type.SCALAR)
       .setScalar(Protos.Value.Scalar.newBuilder().setValue(mem).build())
       .build();
 }
예제 #9
0
 public static Protos.Resource cpus(double cpus) {
   return Protos.Resource.newBuilder()
       .setName("cpus")
       .setType(Protos.Value.Type.SCALAR)
       .setScalar(Protos.Value.Scalar.newBuilder().setValue(cpus).build())
       .build();
 }
예제 #10
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;
 }
예제 #11
0
 private List<Protos.Resource> getCoreRequiredResouces(long cpus, long mem) {
   // Build cpu/mem resource for task.
   List<Protos.Resource> resources = new ArrayList<Protos.Resource>();
   resources.add(
       Protos.Resource.newBuilder()
           .setName(Constants.MESOS_RESOURCE_CPUS)
           .setType(Protos.Value.Type.SCALAR)
           .setScalar(Protos.Value.Scalar.newBuilder().setValue(cpus))
           .build());
   resources.add(
       Protos.Resource.newBuilder()
           .setName(Constants.MESOS_RESOURCE_MEM)
           .setType(Protos.Value.Type.SCALAR)
           .setScalar(Protos.Value.Scalar.newBuilder().setValue(mem))
           .build());
   return resources;
 }
예제 #12
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();
 }
예제 #13
0
 private List<Protos.Resource> getExecutorResources() {
   // JIRA: https://issues.apache.org/jira/browse/MESOS-1807
   // From Mesos 0.22.0, executors must set CPU resources to at least 0.01 and
   // memory resources to at least 32MB.
   List<Protos.Resource> resources = new ArrayList<Protos.Resource>(2);
   // Both cpus/mem are "scalar" type, which means a double value should be used.
   // The resource name is "cpus", type is scalar and the value is 0.1 to tell Mesos
   // this executor would allocate 0.1 cpu for itself.
   resources.add(
       Protos.Resource.newBuilder()
           .setName(Constants.MESOS_RESOURCE_CPUS)
           .setType(Protos.Value.Type.SCALAR)
           .setScalar(Protos.Value.Scalar.newBuilder().setValue(0.1d))
           .build());
   // The resource name is "mem", type is scalar and the value is 32.0MB to tell Mesos
   // this executor would allocate 32.0MB mem for itself.
   resources.add(
       Protos.Resource.newBuilder()
           .setName(Constants.MESOS_RESOURCE_MEM)
           .setType(Protos.Value.Type.SCALAR)
           .setScalar(Protos.Value.Scalar.newBuilder().setValue(32.0d))
           .build());
   return resources;
 }
예제 #14
0
  @Override
  public void resourceOffers(SchedulerDriver schedulerDriver, List<Protos.Offer> list) {
    double CPUS_PER_TASK = 1;
    double MEM_PER_TASK = 128;

    for (Protos.Offer offer : list) {
      List<Protos.TaskInfo> taskInfoList = new ArrayList<Protos.TaskInfo>();
      double offerCpus = 0;
      double offerMem = 0;
      for (Protos.Resource resource : offer.getResourcesList()) {
        if (resource.getName().equals("cpus")) {
          offerCpus += resource.getScalar().getValue();
        } else if (resource.getName().equals("mem")) {
          offerMem += resource.getScalar().getValue();
        }
      }
      LOGGER.info(
          "Received Offer : "
              + offer.getId().getValue()
              + " with cpus = "
              + offerCpus
              + " and mem ="
              + offerMem);

      double remainingCpus = offerCpus;
      double remainingMem = offerMem;

      if (launchedTasks < totalTasks
          && remainingCpus >= CPUS_PER_TASK
          && remainingMem >= MEM_PER_TASK) {
        Protos.TaskID taskID =
            Protos.TaskID.newBuilder().setValue(Integer.toString(launchedTasks++)).build();
        LOGGER.info(
            "Launching task :"
                + taskID.getValue()
                + " using the offer : "
                + offer.getId().getValue());

        Protos.TaskInfo piTaskInfo =
            Protos.TaskInfo.newBuilder()
                .setName("task " + taskID.getValue())
                .setTaskId(taskID)
                .setSlaveId(offer.getSlaveId())
                .addResources(
                    Protos.Resource.newBuilder()
                        .setName("cpus")
                        .setType(Protos.Value.Type.SCALAR)
                        .setScalar(Protos.Value.Scalar.newBuilder().setValue(CPUS_PER_TASK)))
                .addResources(
                    Protos.Resource.newBuilder()
                        .setName("mem")
                        .setType(Protos.Value.Type.SCALAR)
                        .setScalar(Protos.Value.Scalar.newBuilder().setValue(MEM_PER_TASK)))
                .setExecutor(Protos.ExecutorInfo.newBuilder(piExecutor))
                .build();

        taskID = Protos.TaskID.newBuilder().setValue(Integer.toString(launchedTasks++)).build();
        LOGGER.info(
            "Launching task :"
                + taskID.getValue()
                + " using the offer : "
                + offer.getId().getValue());

        taskInfoList.add(piTaskInfo);
      }
      schedulerDriver.launchTasks(offer.getId(), taskInfoList);
    }
  }
예제 #15
0
  @Override
  public void resourceOffers(SchedulerDriver driver, List<Protos.Offer> offers) {
    long masterCpu = Configuration.getInt(PropertyKey.INTEGRATION_MASTER_RESOURCE_CPU);
    long masterMem =
        Configuration.getBytes(PropertyKey.INTEGRATION_MASTER_RESOURCE_MEM) / Constants.MB;
    long workerCpu = Configuration.getInt(PropertyKey.INTEGRATION_WORKER_RESOURCE_CPU);
    long workerMem =
        Configuration.getBytes(PropertyKey.INTEGRATION_WORKER_RESOURCE_MEM) / Constants.MB;

    LOG.info(
        "Master launched {}, master count {}, "
            + "requested master cpu {} mem {} MB and required master hostname {}",
        mMasterLaunched,
        mMasterCount,
        masterCpu,
        masterMem,
        mRequiredMasterHostname);

    for (Protos.Offer offer : offers) {
      Protos.Offer.Operation.Launch.Builder launch = Protos.Offer.Operation.Launch.newBuilder();
      double offerCpu = 0;
      double offerMem = 0;
      for (Protos.Resource resource : offer.getResourcesList()) {
        if (resource.getName().equals(Constants.MESOS_RESOURCE_CPUS)) {
          offerCpu += resource.getScalar().getValue();
        } else if (resource.getName().equals(Constants.MESOS_RESOURCE_MEM)) {
          offerMem += resource.getScalar().getValue();
        } else {
          // Other resources are currently ignored.
        }
      }

      LOG.info(
          "Received offer {} on host {} with cpus {} and mem {} MB and hasMasterPorts {}",
          offer.getId().getValue(),
          offer.getHostname(),
          offerCpu,
          offerMem,
          OfferUtils.hasAvailableMasterPorts(offer));

      Protos.ExecutorInfo.Builder executorBuilder = Protos.ExecutorInfo.newBuilder();
      List<Protos.Resource> resources;
      if (!mMasterLaunched
          && offerCpu >= masterCpu
          && offerMem >= masterMem
          && mMasterCount
              < Configuration.getInt(PropertyKey.INTEGRATION_MESOS_ALLUXIO_MASTER_NODE_COUNT)
          && OfferUtils.hasAvailableMasterPorts(offer)
          && (mRequiredMasterHostname == null
              || mRequiredMasterHostname.equals(offer.getHostname()))) {
        LOG.debug("Creating Alluxio Master executor");
        executorBuilder
            .setName("Alluxio Master Executor")
            .setSource("master")
            .setExecutorId(Protos.ExecutorID.newBuilder().setValue("master"))
            .addAllResources(getExecutorResources())
            .setCommand(
                Protos.CommandInfo.newBuilder()
                    .setValue(createStartAlluxioCommand("alluxio-master-mesos.sh"))
                    .addAllUris(getExecutorDependencyURIList())
                    .setEnvironment(
                        Protos.Environment.newBuilder()
                            .addVariables(
                                Protos.Environment.Variable.newBuilder()
                                    .setName("ALLUXIO_UNDERFS_ADDRESS")
                                    .setValue(Configuration.get(PropertyKey.UNDERFS_ADDRESS))
                                    .build())
                            .build()));
        // pre-build resource list here, then use it to build Protos.Task later.
        resources = getMasterRequiredResources(masterCpu, masterMem);
        mMasterHostname = offer.getHostname();
        mTaskName = Configuration.get(PropertyKey.INTEGRATION_MESOS_ALLUXIO_MASTER_NAME);
        mMasterCount++;
        mMasterTaskId = mLaunchedTasks;
      } else if (mMasterLaunched
          && !mWorkers.contains(offer.getHostname())
          && offerCpu >= workerCpu
          && offerMem >= workerMem
          && OfferUtils.hasAvailableWorkerPorts(offer)) {
        LOG.debug("Creating Alluxio Worker executor");
        final String memSize = FormatUtils.getSizeFromBytes((long) workerMem * Constants.MB);
        executorBuilder
            .setName("Alluxio Worker Executor")
            .setSource("worker")
            .setExecutorId(Protos.ExecutorID.newBuilder().setValue("worker"))
            .addAllResources(getExecutorResources())
            .setCommand(
                Protos.CommandInfo.newBuilder()
                    .setValue(createStartAlluxioCommand("alluxio-worker-mesos.sh"))
                    .addAllUris(getExecutorDependencyURIList())
                    .setEnvironment(
                        Protos.Environment.newBuilder()
                            .addVariables(
                                Protos.Environment.Variable.newBuilder()
                                    .setName("ALLUXIO_MASTER_HOSTNAME")
                                    .setValue(mMasterHostname)
                                    .build())
                            .addVariables(
                                Protos.Environment.Variable.newBuilder()
                                    .setName("ALLUXIO_WORKER_MEMORY_SIZE")
                                    .setValue(memSize)
                                    .build())
                            .addVariables(
                                Protos.Environment.Variable.newBuilder()
                                    .setName("ALLUXIO_UNDERFS_ADDRESS")
                                    .setValue(Configuration.get(PropertyKey.UNDERFS_ADDRESS))
                                    .build())
                            .build()));
        // pre-build resource list here, then use it to build Protos.Task later.
        resources = getWorkerRequiredResources(workerCpu, workerMem);
        mWorkers.add(offer.getHostname());
        mTaskName = Configuration.get(PropertyKey.INTEGRATION_MESOS_ALLUXIO_WORKER_NAME);
      } else {
        // The resource offer cannot be used to start either master or a worker.
        LOG.info("Declining offer {}", offer.getId().getValue());
        driver.declineOffer(offer.getId());
        continue;
      }

      Protos.TaskID taskId =
          Protos.TaskID.newBuilder().setValue(String.valueOf(mLaunchedTasks)).build();

      LOG.info("Launching task {} using offer {}", taskId.getValue(), offer.getId().getValue());

      Protos.TaskInfo task =
          Protos.TaskInfo.newBuilder()
              .setName(mTaskName)
              .setTaskId(taskId)
              .setSlaveId(offer.getSlaveId())
              .addAllResources(resources)
              .setExecutor(executorBuilder)
              .build();

      launch.addTaskInfos(Protos.TaskInfo.newBuilder(task));
      mLaunchedTasks++;

      // NOTE: We use the new API `acceptOffers` here to launch tasks.
      // The 'launchTasks' API will be deprecated.
      List<Protos.OfferID> offerIds = new ArrayList<Protos.OfferID>();
      offerIds.add(offer.getId());
      List<Protos.Offer.Operation> operations = new ArrayList<Protos.Offer.Operation>();
      Protos.Offer.Operation operation =
          Protos.Offer.Operation.newBuilder()
              .setType(Protos.Offer.Operation.Type.LAUNCH)
              .setLaunch(launch)
              .build();
      operations.add(operation);
      Protos.Filters filters = Protos.Filters.newBuilder().setRefuseSeconds(1).build();
      driver.acceptOffers(offerIds, operations, filters);
    }
  }