예제 #1
0
파일: Main.java 프로젝트: bolcom/minimesos
  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");
    }
  }
예제 #2
0
  public static void main(String[] args) throws Exception {
    BasicConfigurator.configure();
    Configuration configuration = parseConfiguration(args);

    final double frameworkFailoverTimeout = 31536000d; // 60 * 60 * 24 * 365 = 1y

    final String host = System.getenv("MESOS_HOSTNAME");
    final String webUri =
        UriBuilder.fromPath("/cluster")
            .scheme("http")
            .host(host == null ? currentHost() : host)
            .port(configuration.apiPort)
            .build()
            .toString();
    Protos.FrameworkInfo.Builder frameworkBuilder =
        Protos.FrameworkInfo.newBuilder()
            .setName(configuration.frameworkName)
            .setUser(configuration.user)
            .setRole(configuration.role)
            .setWebuiUrl(webUri)
            .setCheckpoint(true) // will be enabled by default in Mesos 0.22
            .setFailoverTimeout(frameworkFailoverTimeout);

    PersistentStateStore stateStore =
        new PersistentStateStore(
            new ZooKeeperState(
                configuration.zookeeper,
                20_000,
                TimeUnit.MILLISECONDS,
                String.format("/%s/%s", configuration.frameworkName, configuration.clusterName)),
            configuration.nodeCount);

    Optional<String> frameworkId = stateStore.state().frameworkId();
    if (frameworkId.isPresent()) {
      frameworkBuilder.setId(Protos.FrameworkID.newBuilder().setValue(frameworkId.get()).build());
    }

    final Scheduler scheduler = new CrateScheduler(stateStore, configuration);

    // create the driver
    MesosSchedulerDriver driver;

    String mesosMaster = configuration.mesosMaster();
    Optional<Protos.Credential> credential = readCredentials();
    if (credential.isPresent()) {
      frameworkBuilder.setPrincipal(credential.get().getPrincipal());
      driver =
          new MesosSchedulerDriver(
              scheduler, frameworkBuilder.build(), mesosMaster, credential.get());
    } else {
      frameworkBuilder.setPrincipal("crate-framework");
      driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), mesosMaster);
    }

    CrateHttpService api = new CrateHttpService(stateStore, configuration);
    api.start();
    int status = driver.run() == Protos.Status.DRIVER_STOPPED ? 0 : 1;

    // Ensure that the driver process terminates.
    api.stop();
    driver.stop();
    System.exit(status);
  }