Пример #1
0
 private static Optional<Protos.Credential> readCredentials() {
   if (System.getenv("MESOS_AUTHENTICATE") != null) {
     LOGGER.debug("Enabling authentication for the framework");
     final String principal = System.getenv("DEFAULT_PRINCIPAL");
     final String secret = System.getenv("DEFAULT_SECRET");
     if (principal == null) {
       LOGGER.error("Expecting authentication principal in the environment");
       System.exit(1);
     }
     Protos.Credential.Builder credential = Protos.Credential.newBuilder().setPrincipal(principal);
     if (secret == null) {
       LOGGER.error("Expecting authentication secret in the environment");
     } else {
       credential.setSecret(ByteString.copyFrom(secret.getBytes()));
     }
     return Optional.of(credential.build());
   } else {
     return Optional.absent();
   }
 }
Пример #2
0
  public static void main(String[] args) throws Exception {

    Configuration configuration = new Configuration(args);

    Protos.FrameworkInfo.Builder frameworkBuilder =
        Protos.FrameworkInfo.newBuilder()
            .setUser("") // Have Mesos fill in the current user.
            .setName("Hello world example")
            .setCheckpoint(true);

    String principal = configuration.getFrameworkPrincipal();
    if (principal != null) {
      frameworkBuilder.setPrincipal(principal);
    }

    org.apache.mesos.Scheduler scheduler = new FrameworkScheduler(configuration);

    Protos.FrameworkInfo frameworkInfo = frameworkBuilder.build();
    String mesosMaster = configuration.getMesosMaster();

    MesosSchedulerDriver driver =
        principal != null
            ? new MesosSchedulerDriver(
                scheduler,
                frameworkInfo,
                mesosMaster,
                Protos.Credential.newBuilder()
                    .setPrincipal(principal)
                    .setSecret(configuration.getFrameworkSecret())
                    .build())
            : new MesosSchedulerDriver(scheduler, frameworkInfo, mesosMaster);

    // Ensure that the driver process terminates.
    driver.stop();

    if (driver.run() != Protos.Status.DRIVER_STOPPED) {
      throw new RuntimeException("Mesos Scheduler Driver is not stopped");
    }
  }