Java Code Examples for org.apache.hadoop.conf.Configuration#forEach()

The following examples show how to use org.apache.hadoop.conf.Configuration#forEach() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: pxf   File: BaseConfigurationFactory.java    License: Apache License 2.0 6 votes vote down vote up
private void processUserResource(Configuration configuration, String serverName, String userName, File directory) {
    // add user config file as configuration resource
    try {
        Path path = Paths.get(String.format("%s/%s-user.xml", directory.toPath(), userName));
        if (Files.exists(path)) {
            Configuration userConfiguration = new Configuration(false);
            URL resourceURL = path.toUri().toURL();
            userConfiguration.addResource(resourceURL);
            LOG.debug("Adding user properties for server {} from {}", serverName, resourceURL);
            userConfiguration.forEach(entry -> configuration.set(entry.getKey(), entry.getValue()));
            configuration.set(String.format("%s.%s", PXF_CONFIG_RESOURCE_PATH_PROPERTY, path.getFileName().toString()), resourceURL.toString());
        }
    } catch (Exception e) {
        throw new RuntimeException(String.format("Unable to read user configuration for user %s using server %s from %s",
                userName, serverName, directory.getAbsolutePath()), e);
    }
}
 
Example 2
Source Project: knox   File: HadoopXmlResourceParser.java    License: Apache License 2.0 5 votes vote down vote up
private HadoopXmlResourceParserResult parseXmlConfig(Configuration xmlConfiguration, String topologyName) {
  final Map<String, ProviderConfiguration> providers = new LinkedHashMap<>();
  final Set<SimpleDescriptor> descriptors = new LinkedHashSet<>();
  xmlConfiguration.forEach(xmlDescriptor -> {
    String xmlConfigurationKey = xmlDescriptor.getKey();
    if (xmlConfigurationKey.startsWith(CONFIG_NAME_PROVIDER_CONFIGS_PREFIX)) {
      final String[] providerConfigurations = xmlConfigurationKey.replace(CONFIG_NAME_PROVIDER_CONFIGS_PREFIX, "").split(",");
      Arrays.asList(providerConfigurations).stream().map(providerConfigurationName -> providerConfigurationName.trim()).forEach(providerConfigurationName -> {
        final File providerConfigFile = resolveProviderConfiguration(providerConfigurationName);
        try {
          final ProviderConfiguration providerConfiguration = getProviderConfiguration(providers, providerConfigFile, providerConfigurationName);
          providerConfiguration.setReadOnly(true);
          providerConfiguration.saveOrUpdateProviders(parseProviderConfigurations(xmlDescriptor.getValue(), providerConfiguration));
          providers.put(providerConfigurationName, providerConfiguration);
        } catch (Exception e) {
          log.failedToParseProviderConfiguration(providerConfigurationName, e.getMessage(), e);
        }
      });
    } else {
      if (topologyName == null || xmlConfigurationKey.equals(topologyName)) {
        SimpleDescriptor descriptor = parseXmlDescriptor(xmlConfigurationKey, xmlDescriptor.getValue());
        if (descriptor != null) {
          descriptors.add(descriptor);
        }
      }
    }
  });
  return new HadoopXmlResourceParserResult(providers, descriptors);
}
 
Example 3
Source Project: eagle   File: Utils.java    License: Apache License 2.0 4 votes vote down vote up
public static Constants.JobType fetchJobType(Configuration config) {
    Map<String, String> mapConfig = new HashMap<>();
    config.forEach(entry -> mapConfig.put(entry.getKey(), entry.getValue()));
    return fetchJobType(mapConfig);
}