Ejemplo n.º 1
0
  private LogChangesConfiguration loadConf() throws ServiceException {
    XConfiguration configuration;
    try {
      InputStream inputStream = getDefaultConfiguration();
      configuration = loadConfig(inputStream, true);
      File file = new File(configFile);
      if (!file.exists()) {
        log.info("Missing site configuration file [{0}]", configFile);
      } else {
        inputStream = new FileInputStream(configFile);
        XConfiguration siteConfiguration = loadConfig(inputStream, false);
        XConfiguration.injectDefaults(configuration, siteConfiguration);
        configuration = siteConfiguration;
      }
    } catch (IOException ex) {
      throw new ServiceException(ErrorCode.E0024, configFile, ex.getMessage(), ex);
    }

    if (log.isTraceEnabled()) {
      try {
        StringWriter writer = new StringWriter();
        for (Map.Entry<String, String> entry : configuration) {
          String value = getValue(configuration, entry.getKey());
          writer.write(" " + entry.getKey() + " = " + value + "\n");
        }
        writer.close();
        log.trace("Configuration:\n{0}---", writer.toString());
      } catch (IOException ex) {
        throw new ServiceException(ErrorCode.E0025, ex.getMessage(), ex);
      }
    }

    String[] ignoreSysProps = configuration.getStrings(CONF_IGNORE_SYS_PROPS);
    if (ignoreSysProps != null) {
      IGNORE_SYS_PROPS.addAll(Arrays.asList(ignoreSysProps));
    }

    for (Map.Entry<String, String> entry : configuration) {
      String sysValue = System.getProperty(entry.getKey());
      if (sysValue != null && !IGNORE_SYS_PROPS.contains(entry.getKey())) {
        log.info("Configuration change via System Property, [{0}]=[{1}]", entry.getKey(), sysValue);
        configuration.set(entry.getKey(), sysValue);
      }
    }
    for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
      String name = (String) entry.getKey();
      if (!IGNORE_SYS_PROPS.contains(name)) {
        if (name.startsWith("oozie.") && !name.startsWith(IGNORE_TEST_SYS_PROPS)) {
          if (configuration.get(name) == null) {
            log.warn("System property [{0}] no defined in Oozie configuration, ignored", name);
          }
        }
      }
    }

    // Backward compatible, we should still support -Dparam.
    for (String key : CONF_SYS_PROPS) {
      String sysValue = System.getProperty(key);
      if (sysValue != null && !IGNORE_SYS_PROPS.contains(key)) {
        log.info(
            "Overriding configuration with system property. Key [{0}], Value [{1}] ",
            key, sysValue);
        configuration.set(key, sysValue);
      }
    }

    return new LogChangesConfiguration(configuration);
  }