Example usage for org.apache.hadoop.conf Configuration iterator

List of usage examples for org.apache.hadoop.conf Configuration iterator

Introduction

In this page you can find the example usage for org.apache.hadoop.conf Configuration iterator.

Prototype

@Override
public Iterator<Map.Entry<String, String>> iterator() 

Source Link

Document

Get an Iterator to go through the list of String key-value pairs in the configuration.

Usage

From source file:org.apache.mahout.classifier.svm.mapreduce.MapReduceUtil.java

License:Apache License

/**
 * It may not copy all the things in a configuration. Be careful when using
 * it.//ww  w .j  a  va 2 s  . co  m
 * 
 * @param conf
 * @return
 */
public static Configuration copyConfiguration(Configuration conf) {
    Configuration nconf = new Configuration();
    Iterator<Entry<String, String>> it = conf.iterator();
    Entry<String, String> e = null;
    while (it.hasNext()) {
        e = it.next();
        nconf.set(e.getKey(), e.getKey());
    }
    return nconf;
}

From source file:org.apache.nutch.api.impl.RAMConfManager.java

License:Apache License

public Map<String, String> getAsMap(String confId) {
    Configuration configuration = configurations.get(confId);
    if (configuration == null) {
        return Collections.emptyMap();
    }//from   w ww. j a v  a 2 s .  c om

    Iterator<Entry<String, String>> iterator = configuration.iterator();
    Map<String, String> configMap = Maps.newTreeMap();
    while (iterator.hasNext()) {
        Entry<String, String> entry = iterator.next();
        configMap.put(entry.getKey(), entry.getValue());
    }
    return configMap;
}

From source file:org.apache.nutch.indexer.lucene.LuceneWriter.java

License:Apache License

@SuppressWarnings("unchecked")
private void processOptions(Configuration conf) {
    final Iterator iterator = conf.iterator();
    while (iterator.hasNext()) {
        final String key = (String) ((Map.Entry) iterator.next()).getKey();
        if (!key.startsWith(LuceneConstants.LUCENE_PREFIX)) {
            continue;
        }/* w  ww. j  a va2s  .  c om*/
        if (key.startsWith(LuceneConstants.FIELD_STORE_PREFIX)) {
            final String field = key.substring(LuceneConstants.FIELD_STORE_PREFIX.length());
            final LuceneWriter.STORE store = LuceneWriter.STORE.valueOf(conf.get(key));
            switch (store) {
            case YES:
            case COMPRESS:
                fieldStore.put(field, Field.Store.YES);
                break;
            case NO:
                fieldStore.put(field, Field.Store.NO);
                break;
            }
        } else if (key.startsWith(LuceneConstants.FIELD_INDEX_PREFIX)) {
            final String field = key.substring(LuceneConstants.FIELD_INDEX_PREFIX.length());
            final LuceneWriter.INDEX index = LuceneWriter.INDEX.valueOf(conf.get(key));
            switch (index) {
            case NO:
                fieldIndex.put(field, Field.Index.NO);
                break;
            case NO_NORMS:
                fieldIndex.put(field, Field.Index.NOT_ANALYZED_NO_NORMS);
                break;
            case TOKENIZED:
                fieldIndex.put(field, Field.Index.ANALYZED);
                break;
            case UNTOKENIZED:
                fieldIndex.put(field, Field.Index.NOT_ANALYZED);
                break;
            }
        } else if (key.startsWith(LuceneConstants.FIELD_VECTOR_PREFIX)) {
            final String field = key.substring(LuceneConstants.FIELD_VECTOR_PREFIX.length());
            final LuceneWriter.VECTOR vector = LuceneWriter.VECTOR.valueOf(conf.get(key));
            switch (vector) {
            case NO:
                fieldVector.put(field, Field.TermVector.NO);
                break;
            case OFFSET:
                fieldVector.put(field, Field.TermVector.WITH_OFFSETS);
                break;
            case POS:
                fieldVector.put(field, Field.TermVector.WITH_POSITIONS);
                break;
            case POS_OFFSET:
                fieldVector.put(field, Field.TermVector.WITH_POSITIONS_OFFSETS);
                break;
            case YES:
                fieldVector.put(field, Field.TermVector.YES);
                break;
            }
        }
    }
}

From source file:org.apache.nutch.indexwriter.lucene.LuceneWriter.java

License:Apache License

private void processOptions(Configuration conf) {
    final Iterator<Entry<String, String>> iterator = conf.iterator();

    while (iterator.hasNext()) {

        final String key = ((Map.Entry<String, String>) iterator.next()).getKey();
        if (!key.startsWith(LuceneConstants.LUCENE_PREFIX)) {
            continue;
        }/* w  w w.  j a  va2 s.  c o m*/
        // System.out.println(key);
        if (key.startsWith(LuceneConstants.FIELD_STORE_PREFIX)) {
            final String field = key.substring(LuceneConstants.FIELD_STORE_PREFIX.length());
            final LuceneWriter.STORE store = LuceneWriter.STORE.valueOf(conf.get(key));
            // fieldStore = conf.get(key);
            switch (store) {
            case YES:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setStored(true);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setStored(true);
                    mapField.put(field, fieldType);
                }
                break;
            case NO:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setStored(false);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setStored(false);
                    mapField.put(field, fieldType);
                }
                break;
            }
        } else if (key.startsWith(LuceneConstants.FIELD_INDEX_PREFIX)) {
            final String field = key.substring(LuceneConstants.FIELD_INDEX_PREFIX.length());
            final LuceneWriter.INDEX index = LuceneWriter.INDEX.valueOf(conf.get(key));
            switch (index) {
            case NO:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setIndexed(false);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setIndexed(false);
                    mapField.put(field, fieldType);
                }
                break;
            case NO_NORMS:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setIndexed(true);
                    fieldType.setOmitNorms(false);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setIndexed(true);
                    fieldType.setOmitNorms(false);
                    mapField.put(field, fieldType);
                }
                break;
            case TOKENIZED:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setIndexed(true);
                    fieldType.setTokenized(true);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setIndexed(true);
                    fieldType.setTokenized(true);
                    mapField.put(field, fieldType);
                }
                break;
            case UNTOKENIZED:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setIndexed(true);
                    fieldType.setTokenized(false);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setIndexed(true);
                    fieldType.setTokenized(false);
                    mapField.put(field, fieldType);
                }
                break;
            }
        } else if (key.startsWith(LuceneConstants.FIELD_VECTOR_PREFIX)) {
            final String field = key.substring(LuceneConstants.FIELD_VECTOR_PREFIX.length());
            final LuceneWriter.VECTOR vector = LuceneWriter.VECTOR.valueOf(conf.get(key));
            switch (vector) {
            case NO:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setStoreTermVectors(false);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setStoreTermVectors(false);
                    mapField.put(field, fieldType);
                }
                break;
            case OFFSET:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setStoreTermVectors(true);
                    fieldType.setStoreTermVectorOffsets(true);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setStoreTermVectors(true);
                    fieldType.setStoreTermVectorOffsets(true);
                    mapField.put(field, fieldType);
                }
                break;
            case POS:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setStoreTermVectors(true);
                    fieldType.setStoreTermVectorPositions(true);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setStoreTermVectors(true);
                    fieldType.setStoreTermVectorPositions(true);
                    mapField.put(field, fieldType);
                }
                break;
            case POS_OFFSET:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setStoreTermVectors(true);
                    fieldType.setStoreTermVectorPositions(true);
                    fieldType.setStoreTermVectorOffsets(true);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setStoreTermVectors(true);
                    fieldType.setStoreTermVectorPositions(true);
                    fieldType.setStoreTermVectorOffsets(true);
                    mapField.put(field, fieldType);
                }
                break;
            case YES:
                if (mapField.containsKey(field)) {
                    FieldType fieldType = mapField.get(field);
                    fieldType.setStoreTermVectors(true);
                    mapField.put(field, fieldType);
                } else {
                    FieldType fieldType = new FieldType();
                    fieldType.setStoreTermVectors(true);
                    mapField.put(field, fieldType);
                }
                break;
            }
        }

    }

}

From source file:org.apache.oozie.action.hadoop.OozieJobInfo.java

License:Apache License

public void addfromConf(Configuration conf, StringBuffer sb) {
    Iterator<Map.Entry<String, String>> it = conf.iterator();
    while (it.hasNext()) {
        Entry<String, String> entry = it.next();
        if (entry.getKey().startsWith("oozie.job.info.")) {
            addJobInfo(sb, entry.getKey().substring("oozie.job.info.".length()), entry.getValue());
        }/*  w w  w .ja  va 2  s. co  m*/
    }
}

From source file:org.apache.oozie.command.wf.SubmitMRCommand.java

License:Open Source License

private Element generateConfigurationSection(Configuration conf, Namespace ns) {
    Element configuration = null;
    Iterator<Map.Entry<String, String>> iter = conf.iterator();
    while (iter.hasNext()) {
        Map.Entry<String, String> entry = iter.next();
        String name = entry.getKey();
        if (MANDATORY_OOZIE_CONFS.contains(name) || OPTIONAL_OOZIE_CONFS.contains(name)
                || SKIPPED_CONFS.contains(name)) {
            continue;
        }/*from   w w w . j  av a2 s . c  o  m*/

        if (configuration == null) {
            configuration = new Element("configuration", ns);
        }

        String value = entry.getValue();
        Element property = new Element("property", ns);
        Element nameElement = new Element("name", ns);
        nameElement.addContent(name != null ? name : "");
        property.addContent(nameElement);
        Element valueElement = new Element("value", ns);
        valueElement.addContent(value != null ? value : "");
        property.addContent(valueElement);
        configuration.addContent(property);
    }

    return configuration;
}

From source file:org.apache.oozie.command.wf.SubmitMRXCommand.java

License:Apache License

private Element generateConfigurationSection(Configuration conf, Namespace ns) {
    Element configuration = null;
    Iterator<Map.Entry<String, String>> iter = conf.iterator();
    while (iter.hasNext()) {
        Map.Entry<String, String> entry = iter.next();
        String name = entry.getKey();
        if (MANDATORY_OOZIE_CONFS.contains(name) || OPTIONAL_OOZIE_CONFS.contains(name)
                || SKIPPED_CONFS.contains(name) || DEPRECATE_MAP.containsValue(name)) {
            continue;
        }// www  .j  a v  a  2  s.c  o  m

        if (configuration == null) {
            configuration = new Element("configuration", ns);
        }

        String value = entry.getValue();
        Element property = new Element("property", ns);
        Element nameElement = new Element("name", ns);
        nameElement.addContent(name != null ? name : "");
        property.addContent(nameElement);
        Element valueElement = new Element("value", ns);
        valueElement.addContent(value != null ? value : "");
        property.addContent(valueElement);
        configuration.addContent(property);
    }

    return configuration;
}

From source file:org.apache.oozie.test.ZKXTestCase.java

License:Apache License

protected void setUp(Configuration conf) throws Exception {
    super.setUp();
    Services services = new Services();
    if (conf != null && conf.size() > 0) {
        for (Iterator<Entry<String, String>> itr = (Iterator<Entry<String, String>>) conf.iterator(); itr
                .hasNext();) {/*from ww w .j a  v  a2s  .com*/
            Entry<String, String> entry = itr.next();
            services.getConf().set(entry.getKey(), entry.getValue());
        }
    }
    services.init();
    setUpZK();
}

From source file:org.apache.phoenix.coprocessor.MetaDataEndpointImpl.java

License:Apache License

@Override
public void getVersion(RpcController controller, GetVersionRequest request,
        RpcCallback<GetVersionResponse> done) {

    GetVersionResponse.Builder builder = GetVersionResponse.newBuilder();
    Configuration config = env.getConfiguration();
    boolean isTablesMappingEnabled = SchemaUtil.isNamespaceMappingEnabled(PTableType.TABLE,
            new ReadOnlyProps(config.iterator()));
    if (isTablesMappingEnabled
            && PhoenixDatabaseMetaData.MIN_NAMESPACE_MAPPED_PHOENIX_VERSION > request.getClientVersion()) {
        logger.error("Old client is not compatible when" + " system tables are upgraded to map to namespace");
        ProtobufUtil.setControllerException(controller,
                ServerUtil.createIOException(
                        SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES,
                                isTablesMappingEnabled).toString(),
                        new DoNotRetryIOException("Old client is not compatible when"
                                + " system tables are upgraded to map to namespace")));
    }//from   www  .j  av a  2 s  . com
    long version = MetaDataUtil.encodeVersion(env.getHBaseVersion(), config);

    builder.setVersion(version);
    done.run(builder.build());
}

From source file:org.apache.phoenix.hive.util.PhoenixStorageHandlerUtil.java

License:Apache License

public static void printConfiguration(Configuration config) {
    if (Boolean.getBoolean("dev")) {
        for (Iterator<Entry<String, String>> iterator = config.iterator(); iterator.hasNext();) {
            Entry<String, String> entry = iterator.next();

            System.out.println(entry.getKey() + "=" + entry.getValue());
        }//w  w w  . j  a v  a  2s .c  o m
    }
}