public boolean init()

in metron-analytics/metron-maas-service/src/main/java/org/apache/metron/maas/service/ApplicationMaster.java [342:427]


  public boolean init(String[] args) throws ParseException, IOException {
    CommandLine cliParser = AMOptions.parse(new GnuParser(), args);

    //Check whether customer log4j.properties file exists
    if (fileExist(log4jPath)) {
      try {
        Log4jPropertyHelper.updateLog4jConfiguration(ApplicationMaster.class,
                log4jPath);
      } catch (Exception e) {
        LOG.warn("Can not set up custom log4j properties. " + e);
      }
    }

    if (AMOptions.HELP.has(cliParser)) {
      AMOptions.printHelp();
      return false;
    }


    zkQuorum = AMOptions.ZK_QUORUM.get(cliParser);
    zkRoot = AMOptions.ZK_ROOT.get(cliParser);
    appJarPath = new Path(AMOptions.APP_JAR_PATH.get(cliParser));

    Map<String, String> envs = System.getenv();

    if (!envs.containsKey(Environment.CONTAINER_ID.name())) {
      if (AMOptions.APP_ATTEMPT_ID.has(cliParser)) {
        String appIdStr = AMOptions.APP_ATTEMPT_ID.get(cliParser, "");
        appAttemptID = ConverterUtils.toApplicationAttemptId(appIdStr);
      } else {
        throw new IllegalArgumentException(
                "Application Attempt Id not set in the environment");
      }
    } else {
      ContainerId containerId = ConverterUtils.toContainerId(envs
              .get(Environment.CONTAINER_ID.name()));
      appAttemptID = containerId.getApplicationAttemptId();
    }

    if (!envs.containsKey(ApplicationConstants.APP_SUBMIT_TIME_ENV)) {
      throw new RuntimeException(ApplicationConstants.APP_SUBMIT_TIME_ENV
              + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_HOST.name())) {
      throw new RuntimeException(Environment.NM_HOST.name()
              + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_HTTP_PORT.name())) {
      throw new RuntimeException(Environment.NM_HTTP_PORT
              + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_PORT.name())) {
      throw new RuntimeException(Environment.NM_PORT.name()
              + " not set in the environment");
    }

    LOG.info("Application master for app" + ", appId="
            + appAttemptID.getApplicationId().getId() + ", clustertimestamp="
            + appAttemptID.getApplicationId().getClusterTimestamp()
            + ", attemptId=" + appAttemptID.getAttemptId());


    if (cliParser.hasOption("shell_env")) {
      String shellEnvs[] = cliParser.getOptionValues("shell_env");
      for (String env : shellEnvs) {
        env = env.trim();
        int index = env.indexOf('=');
        if (index == -1) {
          shellEnv.put(env, "");
          continue;
        }
        String key = env.substring(0, index);
        String val = "";
        if (index < (env.length() - 1)) {
          val = env.substring(index + 1);
        }
        shellEnv.put(key, val);
      }
    }


    if (envs.containsKey(Constants.TIMELINEDOMAIN)) {
      domainId = envs.get(Constants.TIMELINEDOMAIN);
    }
    return true;
  }