org.apache.mesos.Protos.Status Java Examples

The following examples show how to use org.apache.mesos.Protos.Status. 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: MyriadDriverManager.java    From incubator-myriad with Apache License 2.0 6 votes vote down vote up
public Status kill(final TaskID taskId) {
  LOGGER.info("Killing task {}", taskId);
  this.driverLock.lock();
  try {
    if (isRunning()) {
      this.driverStatus = driver.kill(taskId);
      LOGGER.info("Task {} killed with status: {}", taskId, this.driverStatus);
    } else {
      LOGGER.warn("Cannot kill task, driver is not running");
    }
  } finally {
    this.driverLock.unlock();
  }

  return driverStatus;
}
 
Example #2
Source File: InternalExecutorDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status stop()
{
    Status status = context.getStateMachine();

    if (!context.isStateMachine(DRIVER_RUNNING, DRIVER_ABORTED)) {
        return status;
    }

    try {
        closer.close();
    }
    catch (final IOException e) {
        LOG.warn(e, "While stopping");
    }

    context.setStateMachine(DRIVER_STOPPED);

    // If the driver was aborted, preserve that
    // state on the return.
    if (status != DRIVER_ABORTED) {
        status = DRIVER_STOPPED;
    }

    return status;
}
 
Example #3
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status launchTasks(final Collection<OfferID> offerIds, final Collection<TaskInfo> tasks)
{
    checkNotNull(offerIds, "offerIds is null");
    checkNotNull(tasks, "tasks is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final LaunchTasksMessage message = LaunchTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addAllOfferIds(offerIds)
        .addAllTasks(tasks)
        .setFilters(Filters.newBuilder().build())
        .build();

    doLaunchTasks(message);
    return context.getStateMachine();
}
 
Example #4
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status launchTasks(final OfferID offerId, final Collection<TaskInfo> tasks)
{
    checkNotNull(offerId, "offerId is null");
    checkNotNull(tasks, "tasks is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final LaunchTasksMessage message = LaunchTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addOfferIds(offerId)
        .addAllTasks(tasks)
        .setFilters(Filters.newBuilder().build())
        .build();

    doLaunchTasks(message);
    return context.getStateMachine();
}
 
Example #5
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status launchTasks(final Collection<OfferID> offerIds, final Collection<TaskInfo> tasks, final Filters filters)
{
    checkNotNull(offerIds, "offerIds is null");
    checkNotNull(tasks, "tasks is null");
    checkNotNull(filters, "filters is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final LaunchTasksMessage message = LaunchTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addAllOfferIds(offerIds)
        .addAllTasks(tasks)
        .setFilters(filters)
        .build();

    doLaunchTasks(message);
    return context.getStateMachine();
}
 
Example #6
Source File: InternalExecutorDriver.java    From jesos with Apache License 2.0 6 votes vote down vote up
@Override
public Status sendFrameworkMessage(final byte[] data)
{
    checkNotNull(data, "data is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final ExecutorToFrameworkMessage message = ExecutorToFrameworkMessage.newBuilder()
        .setSlaveId(context.getSlaveId())
        .setFrameworkId(context.getFrameworkId())
        .setExecutorId(context.getExecutorId())
        .setData(ByteString.copyFrom(data))
        .build();

    eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getSlaveUPID(), message));

    return context.getStateMachine();
}
 
Example #7
Source File: MyriadDriverManager.java    From incubator-myriad with Apache License 2.0 6 votes vote down vote up
/**
 * Stop driver, executor, and tasks if false, otherwise just the driver.
 *
 * @return driver status
 */
public Status stopDriver(boolean failover) {
  this.driverLock.lock();
  try {
    if (isRunning()) {
      if (failover) {
        LOGGER.info("Stopping driver ...");
      } else {
        LOGGER.info("Stopping driver and terminating tasks...");
      }
      this.driverStatus = this.driver.stop(failover);
      LOGGER.info("Stopped driver with status: {}", this.driverStatus);
    }
  } finally {
    this.driverLock.unlock();
  }
  return driverStatus;
}
 
Example #8
Source File: MesosDriverHealthCheck.java    From myriad with Apache License 2.0 5 votes vote down vote up
@Override
protected Result check() throws Exception {
	Status driverStatus = driverManager.getDriverStatus();
	if (Status.DRIVER_RUNNING == driverStatus)
		return Result.healthy();
	else
		return Result.unhealthy("Driver status: " + driverStatus);
}
 
Example #9
Source File: TaskTerminator.java    From myriad with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	Set<String> killableTasks = schedulerState.getKillableTasks();

	if (CollectionUtils.isEmpty(killableTasks)) {
		return;
	}

	Status driverStatus = driverManager.getDriverStatus();
	if (Status.DRIVER_RUNNING != driverStatus) {
		LOGGER.warn(
				"Cannot kill tasks, as driver is not running. Status: {}",
				driverStatus);
		return;
	}

	Iterator<String> iterator = killableTasks.iterator();

	while (iterator.hasNext()) {
		String taskIdToKill = iterator.next();
		NodeTask task = this.schedulerState.getTask(taskIdToKill);
		TaskID mesosTaskId = task.getMesosTaskId();
		Status status = this.driverManager.kill(mesosTaskId);
		this.schedulerState.removeTask(taskIdToKill);
		Preconditions.checkState(status == Status.DRIVER_RUNNING);
	}
}
 
Example #10
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Override
public Status reconcileTasks(final Collection<TaskStatus> statuses)
{
    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final ReconcileTasksMessage message = ReconcileTasksMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .addAllStatuses(statuses)
        .build();
    eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), message));

    return context.getStateMachine();
}
 
Example #11
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Override
public Status sendFrameworkMessage(final ExecutorID executorId, final SlaveID slaveId, final byte[] data)
{
    checkNotNull(executorId, "executorId is null");
    checkNotNull(slaveId, "slaveId is null");
    checkNotNull(data, "data is null");

    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    final FrameworkToExecutorMessage message = FrameworkToExecutorMessage.newBuilder()
        .setFrameworkId(context.getFrameworkId())
        .setExecutorId(executorId)
        .setSlaveId(slaveId)
        .setData(ByteString.copyFrom(data)).build();

    // If the UPID of that slave is known (from the slave cache, then send the message
    // directly to the slave, otherwise to the master and let the master sort it out.
    if (context.containsSlave(message.getSlaveId())) {
        final UPID slave = context.getSlaveUPID(message.getSlaveId());
        eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), slave, message));
    }
    else {
        eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), message));
    }

    return context.getStateMachine();
}
 
Example #12
Source File: SimulatedLocalMesosSchedulerDriver.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
@Override
public Status stop() {
    if (statusRef.compareAndSet(Status.DRIVER_RUNNING, Status.DRIVER_STOPPED)) {

        ObservableExt.safeUnsubscribe(offerUpdateSubscription, taskStatusSubscription);

        logger.info("Mesos driver stopped");
    } else {
        throw new IllegalStateException("Cannot stop mesos driver that is not running");
    }
    return Status.DRIVER_STOPPED;
}
 
Example #13
Source File: FakeMaster.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public Status launchTasks(Collection<OfferID> offerIds, Collection<TaskInfo> tasks) {
  assertNotStopped();

  OfferID id = Iterables.getOnlyElement(offerIds);
  Offer offer = sentOffers.remove(id);
  checkState(offer != null, "Offer " + id + " is invalid.");

  final TaskInfo task = Iterables.getOnlyElement(tasks);
  synchronized (activeTasks) {
    checkState(
        !activeTasks.containsKey(task.getTaskId()),
        "Task " + task.getTaskId() + " already exists.");
    activeTasks.put(task.getTaskId(), new Task(offer, task));
  }

  executor.schedule(
      () -> Futures.getUnchecked(schedulerFuture).statusUpdate(
          this,
          TaskStatus.newBuilder()
              .setTaskId(task.getTaskId())
              .setState(TaskState.TASK_RUNNING)
              .build()),
      1,
      TimeUnit.SECONDS);

  return Status.DRIVER_RUNNING;
}
 
Example #14
Source File: SchedulerDriverContext.java    From jesos with Apache License 2.0 5 votes vote down vote up
synchronized void setStateMachine(final Status status)
{
    final Status oldStatus = stateMachine.getAndSet(status);

    if (status != oldStatus) {
        // Fire all the futures waiting for a status change.
        final List<SettableFuture<Status>> settableFutures = new ArrayList<>(stateMachineFutures.size());
        stateMachineFutures.drainTo(settableFutures);

        for (final SettableFuture<Status> future : settableFutures) {
            future.set(status);
        }
    }
}
 
Example #15
Source File: FakeSchedulerDriver.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public Protos.Status launchTasks(
    Protos.OfferID offerId,
    Collection<Protos.TaskInfo> tasks,
    Protos.Filters filters) {
  return null;
}
 
Example #16
Source File: SchedulerDriverService.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
protected void startUp() {
  Optional<String> frameworkId = storage.read(
      storeProvider -> storeProvider.getSchedulerStore().fetchFrameworkId());

  LOG.info("Connecting to mesos master: " + driverSettings.getMasterUri());
  if (!driverSettings.getCredentials().isPresent()) {
    LOG.warn("Connecting to master without authentication!");
  }

  Protos.FrameworkInfo.Builder frameworkBuilder = infoFactory.getFrameworkInfo().toBuilder();

  if (frameworkId.isPresent()) {
    LOG.info("Found persisted framework ID: " + frameworkId);
    frameworkBuilder.setId(Protos.FrameworkID.newBuilder().setValue(frameworkId.get()));
  } else {
    LOG.warn("Did not find a persisted framework ID, connecting as a new framework.");
  }

  SchedulerDriver schedulerDriver = driverFactory.create(
      scheduler,
      driverSettings.getCredentials(),
      frameworkBuilder.build(),
      driverSettings.getMasterUri());
  Status status = schedulerDriver.start();
  LOG.info("Driver started with code " + status);

  driverFuture.set(schedulerDriver);
}
 
Example #17
Source File: MesosBatchManager.java    From oodt with Apache License 2.0 5 votes vote down vote up
@Override
public boolean killJob(String jobId, ResourceNode node) {
    TaskID id = (TaskID)map.get(jobId);
    driver.killTask(id);
    Status status = driver.killTask(id);
    if (status != Status.DRIVER_RUNNING)
        throw new MesosFrameworkException("Mesos Schedule Driver is dead: "+status.toString());
    return true;
}
 
Example #18
Source File: REEFExecutor.java    From reef with Apache License 2.0 5 votes vote down vote up
private void onStart() {
  this.executorService.submit(new Thread() {
    public void run() {
      final Status status;
      status = mesosExecutorDriver.run();
      LOG.log(Level.INFO, "MesosExecutorDriver ended with status {0}", status);
    }
  });
}
 
Example #19
Source File: MyriadDriverManager.java    From incubator-myriad with Apache License 2.0 5 votes vote down vote up
/**
 * Aborting driver without stopping tasks.
 *
 * @return driver status
 */
public Status abortDriver() {
  this.driverLock.lock();
  try {
    if (isRunning()) {
      LOGGER.info("Aborting driver...");
      this.driverStatus = this.driver.abort();
      LOGGER.info("Aborted driver with status: {}", this.driverStatus);
    }
  } finally {
    this.driverLock.unlock();
  }
  return driverStatus;
}
 
Example #20
Source File: FakeSchedulerDriver.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Override
public Protos.Status launchTasks(
    Collection<Protos.OfferID> offerIds,
    Collection<Protos.TaskInfo> tasks,
    Protos.Filters filters) {
  return null;
}
 
Example #21
Source File: MyriadDriverManager.java    From incubator-myriad with Apache License 2.0 5 votes vote down vote up
public Status startDriver() {
  this.driverLock.lock();
  try {
    Preconditions.checkState(this.isStartable());
    LOGGER.info("Starting driver...");
    this.driverStatus = driver.start();
    LOGGER.info("Driver started with status: {}", this.driverStatus);
  } finally {
    this.driverLock.unlock();
  }
  return this.driverStatus;
}
 
Example #22
Source File: MyriadDriverManager.java    From myriad with Apache License 2.0 5 votes vote down vote up
public Status startDriver() {
	this.driverLock.lock();
	try {
		Preconditions.checkState(this.isStartable());
		LOGGER.info("Starting driver...");
		this.driverStatus = driver.start();
		LOGGER.info("Driver started with status: {}", this.driverStatus);
	} finally {
		this.driverLock.unlock();
	}
	return this.driverStatus;
}
 
Example #23
Source File: InternalExecutorDriver.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Override
public Status abort()
{
    if (!context.isStateMachine(DRIVER_RUNNING)) {
        return context.getStateMachine();
    }

    context.setStateMachine(DRIVER_ABORTED);

    return context.getStateMachine();
}
 
Example #24
Source File: MyriadExecutorAuxService.java    From incubator-myriad with Apache License 2.0 5 votes vote down vote up
@Override
protected void serviceStart() throws Exception {
  LOGGER.info("Starting MyriadExecutor...");

  myriadExecutorThread = new Thread(new Runnable() {
    public void run() {
      driver = new MesosExecutorDriver(new MyriadExecutor(containerIds));
      LOGGER.error("MyriadExecutor exit with status " + Integer.toString(driver.run() == Status.DRIVER_STOPPED ? 0 : 1));
    }
  });
  myriadExecutorThread.start();
}
 
Example #25
Source File: InternalSchedulerDriver.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Override
public Status stop(final boolean failover)
{
    Status status = context.getStateMachine();

    if (!context.isStateMachine(DRIVER_RUNNING, DRIVER_ABORTED)) {
        return status;
    }

    if (context.isConnected() && !failover) {
        final UnregisterFrameworkMessage message = UnregisterFrameworkMessage.newBuilder()
            .setFrameworkId(context.getFrameworkId())
            .build();
        eventBus.post(new RemoteMessageEnvelope(context.getDriverUPID(), context.getMasterUPID(), message));
    }

    try {
        closer.close();
    }
    catch (final IOException e) {
        LOG.warn(e, "While stopping");
    }

    context.setStateMachine(DRIVER_STOPPED);

    // If the driver was aborted, preserve that
    // state on the return.
    if (status != DRIVER_ABORTED) {
        status = DRIVER_STOPPED;
    }

    return status;
}
 
Example #26
Source File: MyriadDriverManager.java    From myriad with Apache License 2.0 5 votes vote down vote up
@Inject
public MyriadDriverManager(final MyriadScheduler scheduler,
		MyriadDriver driver) {
	this.driver = driver;
	this.driverLock = new ReentrantLock();
	this.driverStatus = Protos.Status.DRIVER_NOT_STARTED;
}
 
Example #27
Source File: MyriadDriver.java    From myriad with Apache License 2.0 4 votes vote down vote up
public Status start() {
	LOGGER.info("Starting driver");
	Status status = driver.start();
	LOGGER.info("Driver started with status: {}", status);
	return status;
}
 
Example #28
Source File: MockSchedulerDriver.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
@Override
public Status reviveOffers() {
  return null;
}
 
Example #29
Source File: FakeSchedulerDriver.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Override
public Protos.Status declineOffer(
    Protos.OfferID offerId,
    Protos.Filters filters) {
  return null;
}
 
Example #30
Source File: MockSchedulerDriver.java    From incubator-myriad with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public Status launchTasks(OfferID offerId, Collection<TaskInfo> tasks, Filters filters) {
  return null;
}