Java Code Examples for org.apache.mesos.SchedulerDriver#requestResources()

The following examples show how to use org.apache.mesos.SchedulerDriver#requestResources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchScheduler.java    From elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void registered(SchedulerDriver driver, Protos.FrameworkID frameworkId, Protos.MasterInfo masterInfo) {
    LOGGER.info("Framework registered as " + frameworkId.getValue());

    List<Protos.Resource> resources = Resources.buildFrameworkResources(configuration);

    Protos.Request request = Protos.Request.newBuilder()
            .addAllResources(resources)
            .build();

    List<Protos.Request> requests = Collections.singletonList(request);
    driver.requestResources(requests);

    frameworkState.markRegistered(frameworkId, driver);
}
 
Example 2
Source File: IgniteScheduler.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public synchronized void statusUpdate(SchedulerDriver schedulerDriver, Protos.TaskStatus taskStatus) {
    final String taskId = taskStatus.getTaskId().getValue();

    log.log(Level.INFO, "Received update event task: {0} is in state: {1}",
        new Object[]{taskId, taskStatus.getState()});

    if (taskStatus.getState().equals(Protos.TaskState.TASK_FAILED)
        || taskStatus.getState().equals(Protos.TaskState.TASK_ERROR)
        || taskStatus.getState().equals(Protos.TaskState.TASK_FINISHED)
        || taskStatus.getState().equals(Protos.TaskState.TASK_KILLED)
        || taskStatus.getState().equals(Protos.TaskState.TASK_LOST)) {
        IgniteTask failedTask = tasks.remove(taskId);

        if (failedTask != null) {
            List<Protos.Request> requests = new ArrayList<>();

            Protos.Request request = Protos.Request.newBuilder()
                .addResources(Protos.Resource.newBuilder()
                    .setType(Protos.Value.Type.SCALAR)
                    .setName(MEM)
                    .setScalar(Protos.Value.Scalar.newBuilder().setValue(failedTask.mem())))
                .addResources(Protos.Resource.newBuilder()
                    .setType(Protos.Value.Type.SCALAR)
                    .setName(CPU)
                    .setScalar(Protos.Value.Scalar.newBuilder().setValue(failedTask.cpuCores())))
                .build();

            requests.add(request);

            schedulerDriver.requestResources(requests);
        }
    }
}