org.apache.mesos.Executor Java Examples

The following examples show how to use org.apache.mesos.Executor. 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: MockExecutorDriver.java    From cassandra-mesos-deprecated with Apache License 2.0 6 votes vote down vote up
public MockExecutorDriver(@NotNull final Executor executor, @NotNull final Protos.ExecutorID executorId) {
    this.executor = executor;

    slaveInfo = Protos.SlaveInfo.newBuilder()
            .setHostname("localhost")
            .setId(Protos.SlaveID.newBuilder().setValue(UUID.randomUUID().toString()))
            .setPort(42)
            .build();
    frameworkInfo = Protos.FrameworkInfo.newBuilder()
            .setHostname(slaveInfo.getHostname())
            .setId(Protos.FrameworkID.newBuilder().setValue(UUID.randomUUID().toString()))
            .setName("some-framework")
            .setUser("me-myself-and-i")
            .build();
    executorInfo = Protos.ExecutorInfo.newBuilder()
            .setExecutorId(executorId)
            .setCommand(Protos.CommandInfo.getDefaultInstance())
            .setContainer(Protos.ContainerInfo.newBuilder()
                    .setType(Protos.ContainerInfo.Type.MESOS))
            .setFrameworkId(frameworkInfo.getId())
            .setSource("source")
            .build();
}
 
Example #2
Source File: JesosExecutorDriver.java    From jesos with Apache License 2.0 5 votes vote down vote up
public JesosExecutorDriver(final Executor executor,
                           final UPID slaveUpid,
                           final SlaveID slaveId,
                           final FrameworkID frameworkId,
                           final ExecutorID executorId) throws IOException
{
    super(executor, slaveUpid, slaveId, frameworkId, executorId);
}
 
Example #3
Source File: LocalExecutorMessageProcessor.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void shutdownExecutor(final ShutdownExecutorMessageEnvelope envelope)
{
    checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");

    if (context.isStateMachine(DRIVER_ABORTED)) {
        LOG.warn("driver is aborted!");
        return;
    }

    eventBus.post(new ExecutorCallback() {
        @Override
        public Runnable getCallback(final Executor executor, final ExecutorDriver executorDriver)
        {
            return new Runnable() {
                @Override
                public void run()
                {
                    executorDriver.abort();
                    executor.shutdown(executorDriver);
                }

                @Override
                public String toString()
                {
                    return "callback for abort()";
                }
            };
        }
    });
}
 
Example #4
Source File: LocalExecutorMessageProcessor.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void frameworkToExecutor(final FrameworkToExecutorMessageEnvelope envelope)
{
    checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");

    if (context.isStateMachine(DRIVER_ABORTED)) {
        LOG.warn("driver is aborted!");
        return;
    }

    final FrameworkToExecutorMessage message = envelope.getMessage();

    eventBus.post(new ExecutorCallback() {
        @Override
        public Runnable getCallback(final Executor executor, final ExecutorDriver executorDriver)
        {
            return new Runnable() {
                @Override
                public void run()
                {
                    executor.frameworkMessage(executorDriver, message.getData().toByteArray());
                }

                @Override
                public String toString()
                {
                    return "callback for frameworkMessage()";
                }
            };
        }
    });
}
 
Example #5
Source File: LocalExecutorMessageProcessor.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void killTask(final KillTaskMessageEnvelope envelope)
{
    checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");

    if (context.isStateMachine(DRIVER_ABORTED)) {
        LOG.warn("driver is aborted!");
        return;
    }

    final KillTaskMessage message = envelope.getMessage();

    eventBus.post(new ExecutorCallback() {
        @Override
        public Runnable getCallback(final Executor executor, final ExecutorDriver executorDriver)
        {
            return new Runnable() {
                @Override
                public void run()
                {
                    executor.killTask(executorDriver, message.getTaskId());
                }

                @Override
                public String toString()
                {
                    return "callback for killTask()";
                }
            };
        }
    });
}
 
Example #6
Source File: LocalExecutorMessageProcessor.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void runTask(final RunTaskMessageEnvelope envelope)
{
    checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");

    if (context.isStateMachine(DRIVER_ABORTED)) {
        LOG.warn("driver is aborted!");
        return;
    }

    final RunTaskMessage message = envelope.getMessage();

    final TaskInfo task = message.getTask();

    checkState(!tasks.containsKey(task.getTaskId()), "Task %s already started!", task.getTaskId().getValue());

    tasks.put(task.getTaskId(), task);

    eventBus.post(new ExecutorCallback() {
        @Override
        public Runnable getCallback(final Executor executor, final ExecutorDriver executorDriver)
        {
            return new Runnable() {
                @Override
                public void run()
                {
                    executor.launchTask(executorDriver, task);
                }

                @Override
                public String toString()
                {
                    return "callback for launchTask()";
                }
            };
        }
    });
}
 
Example #7
Source File: LocalExecutorMessageProcessor.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void executorReregistered(final ExecutorReregisteredMessageEnvelope envelope)
{
    checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");

    if (context.isStateMachine(DRIVER_ABORTED)) {
        LOG.warn("driver is aborted!");
        return;
    }

    final ExecutorReregisteredMessage message = envelope.getMessage();

    eventBus.post(new ExecutorCallback() {
        @Override
        public Runnable getCallback(final Executor executor, final ExecutorDriver executorDriver)
        {
            return new Runnable() {
                @Override
                public void run()
                {
                    executor.reregistered(executorDriver, message.getSlaveInfo());
                }

                @Override
                public String toString()
                {
                    return "callback for reregistered()";
                }
            };
        }
    });
}
 
Example #8
Source File: LocalExecutorMessageProcessor.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void executorRegistered(final ExecutorRegisteredMessageEnvelope envelope)
{
    checkState(envelope.getRecipient().equals(context.getDriverUPID()), "Received a remote message for local delivery");

    if (context.isStateMachine(DRIVER_ABORTED)) {
        LOG.warn("driver is aborted!");
        return;
    }

    final ExecutorRegisteredMessage message = envelope.getMessage();

    eventBus.post(new ExecutorCallback() {
        @Override
        public Runnable getCallback(final Executor executor, final ExecutorDriver executorDriver)
        {
            return new Runnable() {
                @Override
                public void run()
                {
                    executor.registered(executorDriver, message.getExecutorInfo(), message.getFrameworkInfo(), message.getSlaveInfo());
                }

                @Override
                public String toString()
                {
                    return "callback for registered()";
                }
            };
        }
    });
}
 
Example #9
Source File: CassandraDaemonController.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new controller.
 * @param executor The Executor instance that will be controlled.
 */
@Inject
public CassandraDaemonController(Executor executor) {

    LOGGER.info("Setting executor to {}", executor);
    this.executor = (CassandraExecutor) executor;
    LOGGER.info("Set executor to {}", this.executor);
}
 
Example #10
Source File: JesosExecutorDriver.java    From jesos with Apache License 2.0 5 votes vote down vote up
public JesosExecutorDriver(final Executor executor) throws IOException
{
    this(executor,
         UPID.create(System.getenv("MESOS_SLAVE_PID")),
         SlaveID.newBuilder().setValue(System.getenv("MESOS_SLAVE_ID")).build(),
         FrameworkID.newBuilder().setValue(System.getenv("MESOS_FRAMEWORK_ID")).build(),
         ExecutorID.newBuilder().setValue(System.getenv("MESOS_EXECUTOR_ID")).build());
}
 
Example #11
Source File: InternalExecutorDriver.java    From jesos with Apache License 2.0 4 votes vote down vote up
protected InternalExecutorDriver(final Executor executor,
                                 final UPID slaveUpid,
                                 final SlaveID slaveId,
                                 final FrameworkID frameworkId,
                                 final ExecutorID executorId) throws IOException
{
    this.executor = checkNotNull(executor, "executor is null");

    checkNotNull(slaveUpid, "slaveUpid is null");
    checkNotNull(slaveId, "slaveId is null");
    checkNotNull(frameworkId, "frameworkId is null");
    checkNotNull(executorId, "executorId is null");

    LOG.debug("Slave UPID:       %s", slaveUpid.asString());
    LOG.debug("Slave ID:         %s", slaveId.getValue());
    LOG.debug("Framework ID:     %s", frameworkId.getValue());
    LOG.debug("Executor ID:      %s", executorId.getValue());

    // Enforce using of the IP, when using the hostname this might "flap" between IPs which in turn
    // confuses the heck out of Mesos.
    final String hostName = NetworkUtil.findPublicIp();

    LOG.debug("Host name:        %s", hostName);

    this.context = new ExecutorDriverContext(hostName, slaveUpid, slaveId, frameworkId, executorId);

    this.eventBus = new ManagedEventBus("executor");

    this.localMessageProcessor = new LocalExecutorMessageProcessor(context, eventBus);

    // Closer closes in reverse registration order.

    // Close the callback executor last, so that everything that was still scheduled to be delivered to the framework still has a chance.
    this.callbackExecutor = closer.register(CloseableExecutors.decorate(Executors.newScheduledThreadPool(5, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("executor-callback-%d").build())));

    this.receiver = closer.register(new HttpProtocolReceiver(context.getDriverUPID(), ExecutorMessageEnvelope.class, eventBus));

    // The sender is closed before the receiver, so that possible responses are still caught
    this.sender = closer.register(new HttpProtocolSender(context.getDriverUPID()));

    // Make sure that the event bus is drained first at shutdown.
    closer.register(eventBus);
}
 
Example #12
Source File: App.java    From docker-compose-executor with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	ExecutorComponent executorComponent = DaggerExecutorComponent.builder().build();
	Executor executor = executorComponent.getExecutor();
	ExecutorDriver driver= new MesosExecutorDriver(executor);
	driver.run();
}
 
Example #13
Source File: ExecutorModule.java    From docker-compose-executor with Apache License 2.0 4 votes vote down vote up
@Provides
Executor provideDockerComposeExecutor(ComposeFileList fileFetcher, DockerComposeProcessObserver processObserver,
                                      ComposeMonitor composeMonitor, ComposeRewriteHelper helper) {
    return new DockerComposeExecutor(fileFetcher, processObserver, composeMonitor, helper);
}
 
Example #14
Source File: MesosExecutorDriverFactory.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Override
public ExecutorDriver getDriver(Executor executor) {
    return new MesosExecutorDriver(executor);
}
 
Example #15
Source File: ExecutorModule.java    From dcos-cassandra-service with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
    bind(ExecutorService.class).toInstance(Executors.newCachedThreadPool());
    bind(Executor.class).to(CassandraExecutor.class).asEagerSingleton();
    bind(ExecutorDriverFactory.class).to(MesosExecutorDriverFactory.class).asEagerSingleton();
}
 
Example #16
Source File: ExecutorDriverDispatcher.java    From dcos-cassandra-service with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a new ExecutorDriverDispatcher
 * @param driverFactory The ExecutorDriverFactroy that will be used to
 *                      retrieve the ExecutorDriver
 * @param executor The Executor corresponding to the ExecutorDriver.
 * @param executorService The ExecutorService used to execute the
 *                        ExecutorDriver.
 */
@Inject
public ExecutorDriverDispatcher(final ExecutorDriverFactory driverFactory,
                                final Executor executor,
                                final ExecutorService executorService) {
    this.driver = driverFactory.getDriver(executor);
    this.executor = executorService;
}
 
Example #17
Source File: ExecutorDriverFactory.java    From dcos-cassandra-service with Apache License 2.0 2 votes vote down vote up
/**
 * Gets a driver.
 * @param executor The Executor for which the driver will be returned.
 * @return The ExecutorDriver for executor
 */
ExecutorDriver getDriver(Executor executor);
 
Example #18
Source File: ExecutorCallback.java    From jesos with Apache License 2.0 votes vote down vote up
Runnable getCallback(Executor executor, ExecutorDriver executorDriver); 
Example #19
Source File: ExecutorComponent.java    From docker-compose-executor with Apache License 2.0 votes vote down vote up
Executor getExecutor();