コード例 #1
0
  static Configuration parseConfiguration(String[] args) {
    Configuration configuration = new Configuration();
    JCommander jCommander;

    List<String> crateArgs = new ArrayList<>();
    List<String> safeArgs = new ArrayList<>(args.length);
    for (String arg : args) {
      if (HELP_OPTIONS.contains(arg)) {
        jCommander = new JCommander(configuration);
        jCommander.usage();
        System.exit(1);
      }
      if (arg.startsWith("-Des.")) {
        String argKey = arg.split("\\=")[0];
        if (PROTECTED_CRATE_ARGS.contains(argKey)) {
          throw new IllegalArgumentException(
              String.format(
                  "Argument \"%s\" is protected and managed by the framework. "
                      + "It cannot be set by the user",
                  argKey));
        } else {
          crateArgs.add(arg);
        }
      } else {
        safeArgs.add(arg);
      }
    }
    jCommander = new JCommander(configuration, safeArgs.toArray(new String[safeArgs.size()]));
    configuration.crateArgs(crateArgs);
    LOGGER.debug("args: {}", configuration);
    return configuration;
  }
コード例 #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);
  }