@Override
  public void run() {
    // clone a copy of the killable tasks
    Set<TaskID> killableTasks = Sets.newHashSet(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;
    }

    for (TaskID taskIdToKill : killableTasks) {
      if (this.schedulerState.getPendingTaskIds().contains(taskIdToKill)) {
        this.schedulerState.removeTask(taskIdToKill);
      } else {
        Status status = this.driverManager.kill(taskIdToKill);
        NodeTask task = schedulerState.getTask(taskIdToKill);
        if (task != null) {
          offerLifeCycleManager.declineOutstandingOffers(task.getHostname());
          this.schedulerState.removeTask(taskIdToKill);
        } else {
          schedulerState.removeTask(taskIdToKill);
          LOGGER.warn("NodeTask with taskId: {} does not exist", taskIdToKill);
        }
        Preconditions.checkState(status == Status.DRIVER_RUNNING);
      }
    }
  }
Esempio n. 2
0
  @Provides
  @Singleton
  SchedulerDriver providesSchedulerDriver(
      MyriadScheduler scheduler, MyriadConfiguration cfg, SchedulerState schedulerState) {

    Builder frameworkInfoBuilder =
        FrameworkInfo.newBuilder()
            .setUser("")
            .setName(cfg.getFrameworkName())
            .setCheckpoint(cfg.isCheckpoint())
            .setFailoverTimeout(cfg.getFrameworkFailoverTimeout());

    if (StringUtils.isNotEmpty(cfg.getFrameworkRole())) {
      frameworkInfoBuilder.setRole(cfg.getFrameworkRole());
    }

    FrameworkID frameworkId = schedulerState.getFrameworkID();
    if (frameworkId != null) {
      LOGGER.info("Attempting to re-register with frameworkId: {}", frameworkId.getValue());
      frameworkInfoBuilder.setId(frameworkId);
    }

    String mesosAuthenticationPrincipal = cfg.getMesosAuthenticationPrincipal();
    String mesosAuthenticationSecretFilename = cfg.getMesosAuthenticationSecretFilename();
    if (StringUtils.isNotEmpty(mesosAuthenticationPrincipal)) {
      frameworkInfoBuilder.setPrincipal(mesosAuthenticationPrincipal);

      Credential.Builder credentialBuilder = Credential.newBuilder();
      credentialBuilder.setPrincipal(mesosAuthenticationPrincipal);
      if (StringUtils.isNotEmpty(mesosAuthenticationSecretFilename)) {
        try {
          credentialBuilder.setSecretBytes(
              ByteString.readFrom(new FileInputStream(mesosAuthenticationSecretFilename)));
        } catch (FileNotFoundException ex) {
          LOGGER.error("Mesos authentication secret file was not found", ex);
          throw new RuntimeException(ex);
        } catch (IOException ex) {
          LOGGER.error("Error reading Mesos authentication secret file", ex);
          throw new RuntimeException(ex);
        }
      }
      return new MesosSchedulerDriver(
          scheduler, frameworkInfoBuilder.build(), cfg.getMesosMaster(), credentialBuilder.build());
    } else {
      return new MesosSchedulerDriver(
          scheduler, frameworkInfoBuilder.build(), cfg.getMesosMaster());
    }
  }