org.apache.mesos.ExecutorDriver Java Examples

The following examples show how to use org.apache.mesos.ExecutorDriver. 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: HelloWorldExecutor.java    From tutorials with MIT License 6 votes vote down vote up
@Override
public void launchTask(ExecutorDriver driver, TaskInfo task) {

    Protos.TaskStatus status = Protos.TaskStatus.newBuilder().setTaskId(task.getTaskId())
            .setState(Protos.TaskState.TASK_RUNNING).build();
    driver.sendStatusUpdate(status);

    String myStatus = "Hello Framework";
    driver.sendFrameworkMessage(myStatus.getBytes());

    System.out.println("Hello World!!!");

    status = Protos.TaskStatus.newBuilder().setTaskId(task.getTaskId())
            .setState(Protos.TaskState.TASK_FINISHED).build();
    driver.sendStatusUpdate(status);
}
 
Example #2
Source File: CassandraExecutor.java    From cassandra-mesos-deprecated with Apache License 2.0 6 votes vote down vote up
@Override
public void frameworkMessage(final ExecutorDriver driver, final byte[] data) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("frameworkMessage(driver : {}, data : {})", driver, data);
    }

    try {
        final TaskDetails taskDetails = TaskDetails.parseFrom(data);

        handleProcessNoLongerAlive(driver);

        switch (taskDetails.getType()) {
            case NODE_JOB_STATUS:
                jobStatus(driver, null);
                break;
            default:
                LOGGER.debug("Unhandled frameworkMessage with detail type: {}", taskDetails.getType());
                break;
        }
    } catch (final Exception e) {
        final String msg = "Error handling framework message due to exception.";
        LOGGER.error(msg, e);
    }
}
 
Example #3
Source File: SingularityExecutor.java    From Singularity with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked when a task running within this executor has been killed
 * (via SchedulerDriver::killTask). Note that no status update will
 * be sent on behalf of the executor, the executor is responsible
 * for creating a new TaskStatus (i.e., with TASK_KILLED) and
 * invoking ExecutorDriver::sendStatusUpdate.
 */
@Override
public void killTask(ExecutorDriver executorDriver, Protos.TaskID taskID) {
  final String taskId = taskID.getValue();

  LOG.info("Asked to kill task {}", taskId);

  KillState killState = monitor.requestKill(taskId);

  switch (killState) {
    case DIDNT_EXIST:
    case INCONSISTENT_STATE:
      LOG.warn("Couldn't kill task {} due to killState {}", taskId, killState);
      break;
    case DESTROYING_PROCESS:
    case INTERRUPTING_PRE_PROCESS:
    case KILLING_PROCESS:
      LOG.info("Requested kill of task {} with killState {}", taskId, killState);
      break;
  }
}
 
Example #4
Source File: CassandraExecutor.java    From cassandra-mesos-deprecated with Apache License 2.0 6 votes vote down vote up
@Override
public void killTask(final ExecutorDriver driver, final TaskID taskId) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("killTask(driver : {}, taskId : {})", driver, protoToString(taskId));
    }

    if (serverTask != null && serverTask.getTaskId().equals(taskId)) {
        killCassandraDaemon(driver);
    }
    else if (executorInfo.getExecutorId().getValue().equals(taskId.getValue())) {
        killCassandraDaemon(driver);

        driver.sendStatusUpdate(taskStatus(executorInfo.getExecutorId(), taskId, TaskState.TASK_FINISHED, ExecutorUtils.nullSlaveStatusDetails()));
        driver.stop();
    }
}
 
Example #5
Source File: SingularityExecutor.java    From Singularity with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked once the executor driver has been able to successfully
 * connect with Mesos. In particular, a scheduler can pass some
 * data to it's executors through the FrameworkInfo.ExecutorInfo's
 * data field.
 */
@Override
public void registered(
  ExecutorDriver executorDriver,
  Protos.ExecutorInfo executorInfo,
  Protos.FrameworkInfo frameworkInfo,
  Protos.SlaveInfo slaveInfo
) {
  LOG.debug(
    "Registered {} with Mesos slave {} for framework {}",
    executorInfo.getExecutorId().getValue(),
    slaveInfo.getId().getValue(),
    frameworkInfo.getId().getValue()
  );
  LOG.trace(
    "Registered {} with Mesos slave {} for framework {}",
    MesosUtils.formatForLogging(executorInfo),
    MesosUtils.formatForLogging(slaveInfo),
    MesosUtils.formatForLogging(frameworkInfo)
  );
}
 
Example #6
Source File: SingularityExecutorMonitor.java    From Singularity with Apache License 2.0 6 votes vote down vote up
private void checkIdleExecutorShutdown(ExecutorDriver driver) {
  exitLock.lock();

  try {
    clearExitCheckerUnsafe();

    if (tasks.isEmpty() && runState == RunState.RUNNING) {
      exitCheckerFuture =
        Optional.of(
          startExitChecker(driver, configuration.getIdleExecutorShutdownWaitMillis())
        );
    }
  } finally {
    exitLock.unlock();
  }
}
 
Example #7
Source File: CassandraExecutor.java    From cassandra-mesos-deprecated with Apache License 2.0 6 votes vote down vote up
/**
 * Handles the state when the Cassandra server process exited on its own and cleans up our state.
 */
private void handleProcessNoLongerAlive(@NotNull final ExecutorDriver driver) {
    if (process == null)
        return;
    try {
        final int exitCode = process.exitValue();
        LOGGER.error("Cassandra process terminated unexpectedly with exit code {}", exitCode);

        if (serverTask != null) {
            final TaskStatus taskStatus =
                ExecutorUtils.slaveErrorDetails(serverTask, "process exited with exit code " + exitCode, null, SlaveErrorDetails.ErrorType.PROCESS_EXITED);
            driver.sendStatusUpdate(taskStatus);
        }

        safeShutdown();

        forceCurrentJobAbort();

        stopCheckingHealth();

    } catch (final IllegalThreadStateException e) {
        // ignore
    }
}
 
Example #8
Source File: BackupSchema.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
private void sendStatus(ExecutorDriver driver,
                          Protos.TaskState state,
                          String message) {
      final Protos.TaskStatus status =
      cassandraTask.createStatus(state,Optional.of(message)).getTaskStatus();
      driver.sendStatusUpdate(status);
}
 
Example #9
Source File: BackupSchema.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
/**
   * Constructs a BackupSchema.
   * @param driver The ExecutorDriver used to send task status.
   * @param daemon The CassandraDaemonProcess used to fetch schema.
   * @param cassandraTask The CassandraTask that will be executed by the
   *                      BackupSchema.
   */
public BackupSchema(ExecutorDriver driver,
                    CassandraDaemonProcess daemon,
                    BackupSchemaTask cassandraTask,
                    BackupStorageDriver backupStorageDriver) {
    this.daemon = daemon;
    this.driver = driver;
    this.cassandraTask = cassandraTask;
    this.backupStorageDriver = backupStorageDriver;
    context = cassandraTask.getBackupRestoreContext();
}
 
Example #10
Source File: BdsMesosExecutor.java    From BigDataScript with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked when a task running within this executor has been killed
 * (via SchedulerDriver::killTask). Note that no status update will
 * be sent on behalf of the executor, the executor is responsible
 * for creating a new TaskStatus (i.e., with TASK_KILLED) and
 * invoking ExecutorDriver::sendStatusUpdate.
 */
@Override
public void killTask(ExecutorDriver driver, TaskID taskId) {
	String tid = taskId.getValue();
	CmdInfo cmdInfo = cmdInfoById.get(tid);
	if (cmdInfo == null) return;
	cmdInfo.cmd.kill();
}
 
Example #11
Source File: TaskExecutor.java    From shardingsphere-elasticjob-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public void frameworkMessage(final ExecutorDriver executorDriver, final byte[] bytes) {
    if (null != bytes && "STOP".equals(new String(bytes))) {
        log.error("call frameworkMessage executor stopped.");
        executorDriver.stop();
    }
}
 
Example #12
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 #13
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 #14
Source File: MyriadExecutor.java    From incubator-myriad with Apache License 2.0 5 votes vote down vote up
@Override
public void killTask(ExecutorDriver driver, TaskID taskId) {
  String taskIdString = taskId.toString();
  LOGGER.debug("killTask received for taskId: " + taskIdString);
  TaskStatus status;

  if (!taskIdString.contains(MyriadExecutorAuxService.YARN_CONTAINER_TASK_ID_PREFIX)) {
    // Inform mesos of killing all tasks corresponding to yarn containers that are
    // currently running 
    synchronized (containerIds) {
      for (String containerId : containerIds) {
        Protos.TaskID containerTaskId = Protos.TaskID.newBuilder().setValue(
            MyriadExecutorAuxService.YARN_CONTAINER_TASK_ID_PREFIX + containerId).build();
        status = TaskStatus.newBuilder().setTaskId(containerTaskId).setState(TaskState.TASK_KILLED).build();
        driver.sendStatusUpdate(status);
      }
    }

    // Now kill the node manager task
    status = TaskStatus.newBuilder().setTaskId(taskId).setState(TaskState.TASK_KILLED).build();
    driver.sendStatusUpdate(status);
    LOGGER.info("NodeManager shutdown after receiving KILL_TASK for taskId {}", taskIdString);
    Runtime.getRuntime().exit(0);

  } else {
    status = TaskStatus.newBuilder().setTaskId(taskId).setState(TaskState.TASK_KILLED).build();
    driver.sendStatusUpdate(status);
    synchronized (containerIds) {
      //Likely the container isn't in here, but just in case remove it.
      if (containerIds.remove(taskIdString.substring(MyriadExecutorAuxService.YARN_CONTAINER_FULL_PREFIX.length(),
          taskIdString.length()))) {
        LOGGER.debug("Removed taskId {} from containerIds", taskIdString);
      }
    }
    LOGGER.debug("Killing " + taskId);
  }
}
 
Example #15
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 #16
Source File: UploadSnapshot.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new UploadSnapshot
 *
 * @param driver              The ExecutorDriver used to send task status.
 * @param daemon              The CassandraDaemonProcess used clean the local snapshot.
 * @param cassandraTask       The BackUploadTask that will be executed.
 * @param backupStorageDriver The BackupStorageDriver used to upload the
 *                            snapshot.
 */
public UploadSnapshot(
    ExecutorDriver driver,
    CassandraDaemonProcess daemon,
    BackupUploadTask cassandraTask,
    BackupStorageDriver backupStorageDriver) {
    this.daemon = daemon;
    this.driver = driver;
    this.cassandraTask = cassandraTask;
    this.backupStorageDriver = backupStorageDriver;
    context = cassandraTask.getBackupRestoreContext();
}
 
Example #17
Source File: CassandraDaemonProcess.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
private ModeReporter(
        final CassandraDaemonTask task,
        final Probe probe,
        final ExecutorDriver driver,
        final AtomicBoolean open,
        final AtomicReference<CassandraMode> mode) {

    this.task = task;
    this.probe = probe;
    this.driver = driver;
    this.open = open;
    this.mode = mode;
}
 
Example #18
Source File: DockerComposeExecutor.java    From docker-compose-executor with Apache License 2.0 5 votes vote down vote up
private void sendTaskStatusUpdate(ExecutorDriver executorDriver, TaskID taskId, TaskState taskState) {
    if (taskId != null) {
        TaskStatus taskStatus = TaskStatus.newBuilder().setTaskId(taskId).setState(taskState).build();
        executorDriver.sendStatusUpdate(taskStatus);
    } else {
        log.error("taskId is null");
    }
}
 
Example #19
Source File: Repair.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new Repair.
 *
 * @param driver The ExecutorDriver used to send status updates.
 * @param daemon The CassandraDaemonProcess used to execute the repair.
 * @param task   The RepairTask that will be executed.
 */
public Repair(final ExecutorDriver driver,
              final CassandraDaemonProcess daemon,
              final RepairTask task) {
    this.driver = driver;
    this.daemon = daemon;
    this.task = task;
}
 
Example #20
Source File: SingularityExecutorMonitor.java    From Singularity with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private Future startExitChecker(
  final ExecutorDriver driver,
  final long waitTimeMillis
) {
  LOG.info(
    "Starting an exit checker that will run in {}",
    JavaUtils.durationFromMillis(waitTimeMillis)
  );

  return exitChecker.schedule(
    new Runnable() {

      @Override
      public void run() {
        LOG.info("Exit checker running...");

        try {
          checkForExit(driver, waitTimeMillis);
        } catch (Throwable t) {
          logAndExit(2, "While shutting down", t);
        }
      }
    },
    waitTimeMillis,
    TimeUnit.MILLISECONDS
  );
}
 
Example #21
Source File: ExecutorUtils.java    From Singularity with Apache License 2.0 5 votes vote down vote up
@SuppressFBWarnings("DM_EXIT")
public void sendStatusUpdate(
  ExecutorDriver driver,
  Protos.TaskID taskID,
  Protos.TaskState taskState,
  String message,
  Logger logger
) {
  logger.info("Sending status update \"{}\" ({})", message, taskState.name());

  message =
    message.substring(
      0,
      Math.min(configuration.getMaxTaskMessageLength(), message.length())
    );

  try {
    final Protos.TaskStatus.Builder builder = Protos
      .TaskStatus.newBuilder()
      .setTaskId(taskID)
      .setState(taskState)
      .setMessage(message);

    driver.sendStatusUpdate(builder.build());
  } catch (Throwable t) {
    try {
      logger.error("Exception while sending status updates, exiting", t);
    } finally {
      System.exit(4);
    }
  }
}
 
Example #22
Source File: DownloadSnapshot.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a DownloadSnapshot.
 *
 * @param driver              The ExecutorDriver used to send task status.
 * @param task                The DownloadSnapshotTask that will be executed.
 * @param backupStorageDriver The BackupStorageDriver that implements
 *                            downloading the snapshot.
 */
public DownloadSnapshot(ExecutorDriver driver,
                        DownloadSnapshotTask task,
                        BackupStorageDriver backupStorageDriver) {
    this.driver = driver;
    this.backupStorageDriver = backupStorageDriver;
    this.cassandraTask = task;
    this.context = task.getBackupRestoreContext();
}
 
Example #23
Source File: RestoreSnapshot.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new RestoreSnapshot.
 *
 * @param driver        The ExecutorDriver used to send task status.
 * @param cassandraTask The RestoreSnapshotTask that will be executed.
 * @param cassandra     The CassandraDaemonProcess running on the host
 */
public RestoreSnapshot(
        ExecutorDriver driver,
        RestoreSnapshotTask cassandraTask,
        CassandraDaemonProcess cassandra) {
    this.driver = driver;
    this.cassandraTask = cassandraTask;
    this.context = cassandraTask.getBackupRestoreContext();
    this.cassandra = cassandra;
    this.version = cassandra.getTask().getConfig().getVersion();

}
 
Example #24
Source File: ResourceExecutor.java    From oodt with Apache License 2.0 5 votes vote down vote up
@Override
public void registered(ExecutorDriver arg0, ExecutorInfo arg1,
        FrameworkInfo arg2, SlaveInfo arg3) {
    System.out.println("Do-Wah-Do-Wah");
    str.println(id+"Registered, Huzzah!");

}
 
Example #25
Source File: CassandraExecutor.java    From cassandra-mesos-deprecated with Apache License 2.0 5 votes vote down vote up
@Override
public void error(final ExecutorDriver driver, final String message) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("error(driver : {}, message : {})", driver, message);
    }
    // TODO implement
}
 
Example #26
Source File: BackupSnapshot.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a BackupSnapshot.
 * @param driver The ExecutorDriver used to send task status.
 * @param daemon The CassandraDaemonProcess used to perform the snapshot.
 * @param cassandraTask The CassandraTask that will be executed by the
 *                      BackupSnapshot.
 */
public BackupSnapshot(ExecutorDriver driver,
                      CassandraDaemonProcess daemon,
                      BackupSnapshotTask cassandraTask) {
    this.daemon = daemon;
    this.driver = driver;
    this.cassandraTask = cassandraTask;
}
 
Example #27
Source File: CassandraExecutor.java    From cassandra-mesos-deprecated with Apache License 2.0 5 votes vote down vote up
@Override
public void shutdown(final ExecutorDriver driver) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("shutdown(driver : {})", driver);
    }

    // TODO implement

    executorService.shutdown();
}
 
Example #28
Source File: CassandraExecutor.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@Override
public void registered(ExecutorDriver driver,
                       Protos.ExecutorInfo executorInfo,
                       Protos.FrameworkInfo frameworkInfo,
                       Protos.SlaveInfo slaveInfo) {
    cassandraTaskFactory = new CassandraTaskFactory(driver);
    customExecutor = new CustomExecutor(clusterJobExecutorService, cassandraTaskFactory);
}
 
Example #29
Source File: CassandraDaemonProcess.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
public static ModeReporter create(
        final CassandraDaemonTask task,
        final Probe probe,
        final ExecutorDriver driver,
        final AtomicBoolean open,
        final
        AtomicReference<CassandraMode> mode) {
    return new ModeReporter(task, probe, driver, open, mode);
}
 
Example #30
Source File: SingularityExecutor.java    From Singularity with Apache License 2.0 5 votes vote down vote up
@Override
public void frameworkMessage(ExecutorDriver executorDriver, byte[] bytes) {
  try {
    messageHandler.handleMessage(bytes);
  } catch (Throwable t) {
    LOG.warn("Unexpected exception while handling framework message", t);
  }
}