当前位置: 首页>>代码示例>>Java>>正文


Java SchedulerDriver.launchTasks方法代码示例

本文整理汇总了Java中org.apache.mesos.SchedulerDriver.launchTasks方法的典型用法代码示例。如果您正苦于以下问题:Java SchedulerDriver.launchTasks方法的具体用法?Java SchedulerDriver.launchTasks怎么用?Java SchedulerDriver.launchTasks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mesos.SchedulerDriver的用法示例。


在下文中一共展示了SchedulerDriver.launchTasks方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: launchTasks

import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
public void launchTasks(SchedulerDriver driver) {
  final List<TaskInfo> toLaunch = Lists.newArrayListWithCapacity(acceptedTasks.size());
  final List<SingularityTaskId> taskIds = Lists.newArrayListWithCapacity(acceptedTasks.size());

  for (SingularityTask task : acceptedTasks) {
    taskIds.add(task.getTaskId());
    toLaunch.add(task.getMesosTask());
    LOG.trace("Launching {} mesos task: {}", task.getTaskId(), task.getMesosTask());
  }

  Status initialStatus = driver.launchTasks(ImmutableList.of(offer.getId()), toLaunch);

  LOG.info("{} tasks ({}) launched with status {}", taskIds.size(), taskIds, initialStatus);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:15,代码来源:SingularityOfferHolder.java

示例2: resourceOffers

import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:53,代码来源:PiScheduler.java

示例3: resourceOffers

import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
@Override
public void resourceOffers(SchedulerDriver schedulerDriver, List<Protos.Offer> offers) {

    loggerWrapper.debug("Resource offers with " + offers.size() + " offers" );

    for (Protos.Offer offer : offers) {
        if (!constraints.constraintsAllow(offer) ||
                runningInstances.size() + pendingInstances.size() >= desiredInstances) {
            schedulerDriver.declineOffer(offer.getId());
            schedulerDriver.suppressOffers();
            continue;
        }

        Double offerCpus = 0d;
        Double offerMem = 0d;
        for (Resource resource : offer.getResourcesList()) {
          if (resource.getName().equals("cpus")) {
            offerCpus += resource.getScalar().getValue();
          } else if (resource.getName().equals("mem")) {
            offerMem += resource.getScalar().getValue();
          }
        }
        if (offerCpus < cpu || offerMem < memory) {
            schedulerDriver.declineOffer(offer.getId());
            continue;
        }

        List<Protos.TaskInfo> tasks = new ArrayList<>();
        // generate a unique task ID
        Protos.TaskID taskId = Protos.TaskID.newBuilder()
                .setValue(TaskIdGeneratorHelper.getTaskId(context)).build();

        loggerWrapper.debug("Launching task " + taskId.getValue());
        pendingInstances.add(taskId.getValue());

        // docker image info
        Protos.ContainerInfo.DockerInfo.Builder dockerInfoBuilder = Protos.ContainerInfo.DockerInfo.newBuilder();
        dockerInfoBuilder.setImage(imageName);
        dockerInfoBuilder.setNetwork(Protos.ContainerInfo.DockerInfo.Network.BRIDGE);
        dockerInfoBuilder.setForcePullImage(forcePullImage);
        if (!parameters.isEmpty()) {
            dockerInfoBuilder.addAllParameters(parameters);
        }

        // container info
        Protos.ContainerInfo.Builder containerInfoBuilder = Protos.ContainerInfo.newBuilder();
        containerInfoBuilder.setType(Protos.ContainerInfo.Type.DOCKER);
        containerInfoBuilder.setDocker(dockerInfoBuilder.build());
        if (!volumes.isEmpty()) {
            containerInfoBuilder.addAllVolumes(volumes);
        }

        // create task to run
        Protos.TaskInfo task = 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(cpu)))
                .addResources(Protos.Resource.newBuilder()
                        .setName("mem")
                        .setType(Protos.Value.Type.SCALAR)
                        .setScalar(Protos.Value.Scalar.newBuilder().setValue(memory)))
                .setContainer(containerInfoBuilder)
                .setCommand(commandInfoBuilder)
                .build();

        tasks.add(task);

        loggerWrapper.task = task;
        loggerWrapper.stoptMesosTailWait();

        // Only accept offer when tasks size greater than 0.
        Protos.Filters filters = Protos.Filters.newBuilder().setRefuseSeconds(1).build();
        schedulerDriver.launchTasks(offer.getId(), tasks, filters);
    }
}
 
开发者ID:farmapromlab,项目名称:rundeck-mesos-plugin,代码行数:80,代码来源:DockerScheduler.java

示例4: resourceOffers

import org.apache.mesos.SchedulerDriver; //导入方法依赖的package包/类
@Override
public void resourceOffers(SchedulerDriver schedulerDriver, List<Protos.Offer> list) {
    for (Protos.Offer offer : list) {
        Protos.SlaveID slaveId = offer.getSlaveId();
        if (needMoreNodes() && !slaveContainsHazelcastNode(slaveId)) {
            System.out.println("Launching Hazelcast on slaveId = " + slaveId.getValue());
            Protos.TaskID.Builder taskId = Protos.TaskID.newBuilder().setValue("node-" + slaveId.getValue());

            HazelcastMessages.HazelcastServerProcessTask processTask = HazelcastMessages.HazelcastServerProcessTask
                    .newBuilder()
                    .setVersion(getHazelcastVersion())
                    .addCommand("java")
                    .addCommand("-server")
                    .addCommand("-Xms" + getMinHeap())
                    .addCommand("-Xmx" + getMaxHeap())
                    .addCommand("-Djava.net.preferIPv4Stack=true")
                    .addCommand("-cp")
                    .addCommand("hazelcast-" + getHazelcastVersion() + ".jar:hazelcast-zookeeper.jar")
                    .addCommand("com.hazelcast.core.server.StartServer")
                    .build();

            Protos.TaskInfo.Builder builder = Protos.TaskInfo.newBuilder()
                    .setSlaveId(slaveId)
                    .setName("Hazelcast node")
                    .addResources(resource("cpus", getCpuPerNode()))
                    .addResources(resource("mem", getMemoryPerNode()))
                    .setData(processTask.toByteString())
                    .setTaskId(taskId);

            Protos.ExecutorInfo executor = buildExecutor();
            Protos.TaskInfo taskInfo = builder.setExecutor(executor).build();
            schedulerDriver.launchTasks(singletonList(offer.getId()), singletonList(taskInfo));
            HazelcastNode hazelcastNode = new HazelcastNode(offer.getHostname(), slaveId.getValue(), taskId.getValue());
            activeNodes.add(hazelcastNode);
        } else if (needLessNodes() && slaveContainsHazelcastNode(slaveId)) {
            Protos.TaskID taskID = Protos.TaskID.newBuilder().setValue("node-" + slaveId.getValue()).build();
            schedulerDriver.killTask(taskID);
            removeNodeFromActiveNodesWithTaskID(taskID);
        } else {
            schedulerDriver.declineOffer(offer.getId());
        }
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-mesos,代码行数:44,代码来源:HazelcastScheduler.java


注:本文中的org.apache.mesos.SchedulerDriver.launchTasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。