Exemplo n.º 1
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());
    }
  }