Пример #1
0
  /**
   * Merge default configuration with user-defined configuration.
   *
   * @throws CommandException thrown if failed to read or merge configurations
   */
  protected void mergeDefaultConfig() throws CommandException {
    Path configDefault = null;
    try {
      String coordAppPathStr = conf.get(OozieClient.COORDINATOR_APP_PATH);
      Path coordAppPath = new Path(coordAppPathStr);
      String user = ParamChecker.notEmpty(conf.get(OozieClient.USER_NAME), OozieClient.USER_NAME);
      String group =
          ParamChecker.notEmpty(conf.get(OozieClient.GROUP_NAME), OozieClient.GROUP_NAME);
      FileSystem fs =
          Services.get()
              .get(HadoopAccessorService.class)
              .createFileSystem(user, group, coordAppPath.toUri(), new Configuration());

      // app path could be a directory
      if (!fs.isFile(coordAppPath)) {
        configDefault = new Path(coordAppPath, CONFIG_DEFAULT);
      } else {
        configDefault = new Path(coordAppPath.getParent(), CONFIG_DEFAULT);
      }

      if (fs.exists(configDefault)) {
        Configuration defaultConf = new XConfiguration(fs.open(configDefault));
        PropertiesUtils.checkDisallowedProperties(defaultConf, DISALLOWED_DEFAULT_PROPERTIES);
        XConfiguration.injectDefaults(defaultConf, conf);
      } else {
        LOG.info("configDefault Doesn't exist " + configDefault);
      }
      PropertiesUtils.checkDisallowedProperties(conf, DISALLOWED_USER_PROPERTIES);

      // Resolving all variables in the job properties.
      // This ensures the Hadoop Configuration semantics is preserved.
      XConfiguration resolvedVarsConf = new XConfiguration();
      for (Map.Entry<String, String> entry : conf) {
        resolvedVarsConf.set(entry.getKey(), conf.get(entry.getKey()));
      }
      conf = resolvedVarsConf;
    } catch (IOException e) {
      throw new CommandException(
          ErrorCode.E0702,
          e.getMessage() + " : Problem reading default config " + configDefault,
          e);
    } catch (HadoopAccessorException e) {
      throw new CommandException(e);
    }
    LOG.debug("Merged CONF :" + XmlUtils.prettyPrint(conf).toString());
  }
  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);
  }