Example usage for org.apache.hadoop.util StringUtils getStrings

List of usage examples for org.apache.hadoop.util StringUtils getStrings

Introduction

In this page you can find the example usage for org.apache.hadoop.util StringUtils getStrings.

Prototype

public static String[] getStrings(String str) 

Source Link

Document

Returns an arraylist of strings.

Usage

From source file:co.cask.tigon.conf.Configuration.java

License:Apache License

/**
 * Get the comma delimited values of the <code>name</code> property as
 * an array of <code>String</code>s.
 * If no such property is specified then <code>null</code> is returned.
 *
 * @param name property name.//  ww w.  j a v  a2s  . c o m
 * @return property value as an array of <code>String</code>s,
 *         or <code>null</code>.
 */
public String[] getStrings(String name) {
    String valueString = get(name);
    return StringUtils.getStrings(valueString);
}

From source file:co.cask.tigon.conf.Configuration.java

License:Apache License

/**
 * Get the comma delimited values of the <code>name</code> property as
 * an array of <code>String</code>s.
 * If no such property is specified then default value is returned.
 *
 * @param name property name./*from  w w  w. j a  va2s  . c o  m*/
 * @param defaultValue The default value
 * @return property value as an array of <code>String</code>s,
 *         or default value.
 */
public String[] getStrings(String name, String... defaultValue) {
    String valueString = get(name);
    if (valueString == null) {
        return defaultValue;
    } else {
        return StringUtils.getStrings(valueString);
    }
}

From source file:com.alibaba.jstorm.yarn.utils.ZookeeperUtils.java

License:Apache License

/**
 * Take a quorum list and split it to (trimmed) pairs
 * @param hostPortQuorumList list of form h1:port, h2:port2,...
 * @return a possibly empty list of values between commas. They may not be
 * valid hostname:port pairs/*w w  w.  j  av  a 2  s .com*/
 */
public static List<String> splitToPairs(String hostPortQuorumList) {
    // split an address hot
    String[] strings = StringUtils.getStrings(hostPortQuorumList);
    int len = 0;
    if (strings != null) {
        len = strings.length;
    }
    List<String> tuples = new ArrayList<String>(len);
    if (strings != null) {
        for (String s : strings) {
            tuples.add(s.trim());
        }
    }
    return tuples;
}

From source file:com.alibaba.jstorm.yarn.utils.ZookeeperUtils.java

License:Apache License

/**
 * Split a quorum list into a list of hostnames and ports
 * @param hostPortQuorumList split to a list of hosts and ports
 * @return a list of values// w  ww  .  ja va  2s  . co m
 */
public static List<HostAndPort> splitToHostsAndPorts(String hostPortQuorumList) {
    // split an address hot
    String[] strings = StringUtils.getStrings(hostPortQuorumList);
    int len = 0;
    if (strings != null) {
        len = strings.length;
    }
    List<HostAndPort> list = new ArrayList<HostAndPort>(len);
    if (strings != null) {
        for (String s : strings) {
            list.add(HostAndPort.fromString(s.trim()).withDefaultPort(DEFAULT_PORT));
        }
    }
    return list;
}

From source file:com.intel.hadoop.hbase.dot.access.DataDefinitionOps.java

License:Apache License

/**
 * Check the column family contains dot required properties.
 * @param desc/*from  w  ww.  j ava2  s  .c  o m*/
 * @param column
 * @throws IOException
 */
private void checkDotColumn(HTableDescriptor desc, HColumnDescriptor column) throws IOException {
    String docElements = column.getValue(DotConstants.HBASE_DOT_COLUMNFAMILY_DOC_ELEMENT);
    if (null == docElements || docElements.equals("")) {
        LOG.error("No DOC element is defined in column family: " + column.getNameAsString()
                + " of a DOT table: " + desc.getNameAsString());
        throw new DotInvalidIOException(DotException.DOC_ELEMENTS_EMPTY);
    }

    String serializer = column.getValue(DotConstants.HBASE_DOT_COLUMNFAMILY_DOC_SERIALIZER_CLASS);
    if (null == serializer || serializer.equals("")) {
        // set the default serializer for current column family.
        column.setValue(DotConstants.HBASE_DOT_COLUMNFAMILY_DOC_SERIALIZER_CLASS,
                DotConstants.HBASE_DOT_COLUMNFAMILY_DOC_SERIALIZER_CLASS_DEFAULT);
    }

    for (String doc : StringUtils.getStrings(docElements)) {
        String schema = column.getValue(DotConstants.HBASE_DOT_COLUMNFAMILY_DOC_SCHEMA_PREFIX + doc);
        if (null == schema || schema.equals("")) {
            LOG.error("No DOC schmea is defined for DOC:" + doc + " in column family:"
                    + column.getNameAsString() + " of a DOT table: " + desc.getNameAsString());
            throw new DotInvalidIOException(DotException.DOC_SCHEMA_EMPTY);
        }
    }

}

From source file:com.intel.hadoop.hbase.dot.access.DataManipulationOps.java

License:Apache License

@Override
public void postOpen(ObserverContext<RegionCoprocessorEnvironment> e) {
    HTableDescriptor desc = e.getEnvironment().getRegion().getTableDesc();
    if (!DotUtil.isDot(desc)) {
        return;/*from   w ww  .  jav a2s. c o  m*/
    }
    for (HColumnDescriptor hcd : desc.getFamilies()) {
        String[] docs = StringUtils.getStrings(hcd.getValue(DotConstants.HBASE_DOT_COLUMNFAMILY_DOC_ELEMENT));
        for (String doc : docs) {
            // to load schema for each doc in advance
            loadSchema(hcd, doc);
        }
    }
}

From source file:com.jumptap.h2redis.RedisOutputMapper.java

License:Open Source License

@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    Configuration conf = context.getConfiguration();
    int keyIdx = conf.getInt(RedisDriver.REDIS_KEY_FIELD, -1);
    int hashIdx = conf.getInt(RedisDriver.REDIS_HASHKEY_FIELD, -1);
    int valIdx = conf.getInt(RedisDriver.REDIS_HASHVAL_FIELD, -1);

    if (keyIdx == -1 || hashIdx == -1 || valIdx == -1)
        return;//from  w  w  w .ja va  2 s. c om

    String[] payload = StringUtils.getStrings(value.toString());
    String keyStr = payload[keyIdx];
    String hashStr = payload[hashIdx];
    String valStr = payload[valIdx];

    // check filters
    Pattern p = conf.getPattern(RedisDriver.REDIS_KEY_FILTER, null);
    if (p != null && p.matcher(keyStr).find()) {
        return;
    }

    p = conf.getPattern(RedisDriver.REDIS_HASH_FILTER, null);
    if (p != null && p.matcher(hashStr).find()) {
        return;
    }

    p = conf.getPattern(RedisDriver.REDIS_VAL_FILTER, null);
    if (p != null && p.matcher(valStr).find()) {
        return;
    }

    outkey.set(keyStr);
    outvalue.set(hashStr + "," + valStr);
    context.write(outkey, outvalue);
}

From source file:ezbake.amino.job.WarehausAminoJob.java

License:Apache License

@Override
public Iterable<Class<? extends AminoReducer>> getAminoReducerClasses() {
    if (config == null) {
        throw new IllegalStateException("WarehausAminoJob was not configured");
    }/*w  w  w  .jav a 2 s.c  o  m*/

    final ArrayList<Class<? extends AminoReducer>> classes = new ArrayList<>();
    try {
        String[] classNames = StringUtils.getStrings(config.get(CFG_REDUCER_CLASSES));
        if (classNames == null) {
            throw new IllegalStateException(CFG_REDUCER_CLASSES + " missing from config");
        }
        for (String classname : classNames) {
            classes.add(config.getClassByName(classname.trim()).asSubclass(AminoReducer.class));
        }
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    return classes;
}

From source file:org.apache.ambari.log4j.hadoop.mapreduce.jobhistory.MapReduceJobHistoryUpdater.java

License:Apache License

public static WorkflowContext buildWorkflowContext(JobSubmittedEvent historyEvent) {
    String workflowId = historyEvent.getWorkflowId().replace("\\", "");
    if (workflowId.isEmpty())
        return generateWorkflowContext(historyEvent);
    String workflowName = historyEvent.getWorkflowName().replace("\\", "");
    String workflowNodeName = historyEvent.getWorkflowNodeName().replace("\\", "");
    String workflowAdjacencies = StringUtils.unEscapeString(historyEvent.getWorkflowAdjacencies(),
            StringUtils.ESCAPE_CHAR, new char[] { '"', '=', '.' });
    WorkflowContext context = new WorkflowContext();
    context.setWorkflowId(workflowId);/*from   w ww. j a v a  2  s  . co  m*/
    context.setWorkflowName(workflowName);
    context.setWorkflowEntityName(workflowNodeName);
    WorkflowDag dag = new WorkflowDag();
    Matcher matcher = adjPattern.matcher(workflowAdjacencies);

    while (matcher.find()) {
        WorkflowDagEntry dagEntry = new WorkflowDagEntry();
        dagEntry.setSource(matcher.group(1).replace("\\", ""));
        String[] values = StringUtils.getStrings(matcher.group(2).replace("\\", ""));
        if (values != null) {
            for (String target : values) {
                dagEntry.addTarget(target);
            }
        }
        dag.addEntry(dagEntry);
    }
    if (dag.getEntries().isEmpty()) {
        WorkflowDagEntry wfDagEntry = new WorkflowDagEntry();
        wfDagEntry.setSource(workflowNodeName);
        dag.addEntry(wfDagEntry);
    }
    context.setWorkflowDag(dag);
    return context;
}

From source file:org.apache.giraph.yarn.YarnUtils.java

License:Apache License

/**
 * Popuate the environment string map to be added to the environment vars
 * in a remote execution container. Adds the local classpath to pick up
 * "yarn-site.xml" and "mapred-site.xml" stuff.
 * @param env the map of env var values.
 * @param giraphConf the GiraphConfiguration to pull values from.
 *///from  w  ww.  j  a va  2 s. co  m
public static void addLocalClasspathToEnv(final Map<String, String> env, final GiraphConfiguration giraphConf) {
    StringBuilder classPathEnv = new StringBuilder("${CLASSPATH}:./*");
    for (String cpEntry : giraphConf.getStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH,
            YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH)) {
        classPathEnv.append(':').append(cpEntry.trim()); //TODO: Separator
    }
    for (String cpEntry : giraphConf.getStrings(MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH,
            StringUtils.getStrings(MRJobConfig.DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH))) {
        classPathEnv.append(':').append(cpEntry.trim());
    }
    // add the runtime classpath needed for tests to work
    if (giraphConf.getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER, false)) {
        classPathEnv.append(':').append(System.getenv("CLASSPATH"));
    }
    env.put("CLASSPATH", classPathEnv.toString());
}