Java Code Examples for org.apache.hadoop.util.StringUtils#getTrimmedStringCollection()

The following examples show how to use org.apache.hadoop.util.StringUtils#getTrimmedStringCollection() . 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 check out the related API usage on the sidebar.
Example 1
Source File: FSImageFormat.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private static void setRenameReservedMapInternal(String renameReserved) {
  Collection<String> pairs =
      StringUtils.getTrimmedStringCollection(renameReserved);
  for (String p : pairs) {
    String[] pair = StringUtils.split(p, '/', '=');
    Preconditions.checkArgument(pair.length == 2,
        "Could not parse key-value pair " + p);
    String key = pair[0];
    String value = pair[1];
    Preconditions.checkArgument(DFSUtil.isReservedPathComponent(key),
        "Unknown reserved path " + key);
    Preconditions.checkArgument(DFSUtil.isValidNameForComponent(value),
        "Invalid rename path for " + key + ": " + value);
    LOG.info("Will rename reserved path " + key + " to " + value);
    renameReservedMap.put(key, value);
  }
}
 
Example 2
Source File: AccessControlList.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Build ACL from the given two Strings.
 * The Strings contain comma separated values.
 *
 * @param aclString build ACL from array of Strings
 */
private void buildACL(String[] userGroupStrings) {
  users = new HashSet<String>();
  groups = new HashSet<String>();
  for (String aclPart : userGroupStrings) {
    if (aclPart != null && isWildCardACLValue(aclPart)) {
      allAllowed = true;
      break;
    }
  }
  if (!allAllowed) {      
    if (userGroupStrings.length >= 1 && userGroupStrings[0] != null) {
      users = StringUtils.getTrimmedStringCollection(userGroupStrings[0]);
    } 
    
    if (userGroupStrings.length == 2 && userGroupStrings[1] != null) {
      groups = StringUtils.getTrimmedStringCollection(userGroupStrings[1]);
      groupsMapping.cacheGroupsAdd(new LinkedList<String>(groups));
    }
  }
}
 
Example 3
Source File: FSImageFormat.java    From big-c with Apache License 2.0 6 votes vote down vote up
private static void setRenameReservedMapInternal(String renameReserved) {
  Collection<String> pairs =
      StringUtils.getTrimmedStringCollection(renameReserved);
  for (String p : pairs) {
    String[] pair = StringUtils.split(p, '/', '=');
    Preconditions.checkArgument(pair.length == 2,
        "Could not parse key-value pair " + p);
    String key = pair[0];
    String value = pair[1];
    Preconditions.checkArgument(DFSUtil.isReservedPathComponent(key),
        "Unknown reserved path " + key);
    Preconditions.checkArgument(DFSUtil.isValidNameForComponent(value),
        "Invalid rename path for " + key + ": " + value);
    LOG.info("Will rename reserved path " + key + " to " + value);
    renameReservedMap.put(key, value);
  }
}
 
Example 4
Source File: AccessControlList.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Build ACL from the given two Strings.
 * The Strings contain comma separated values.
 *
 * @param aclString build ACL from array of Strings
 */
private void buildACL(String[] userGroupStrings) {
  users = new HashSet<String>();
  groups = new HashSet<String>();
  for (String aclPart : userGroupStrings) {
    if (aclPart != null && isWildCardACLValue(aclPart)) {
      allAllowed = true;
      break;
    }
  }
  if (!allAllowed) {      
    if (userGroupStrings.length >= 1 && userGroupStrings[0] != null) {
      users = StringUtils.getTrimmedStringCollection(userGroupStrings[0]);
    } 
    
    if (userGroupStrings.length == 2 && userGroupStrings[1] != null) {
      groups = StringUtils.getTrimmedStringCollection(userGroupStrings[1]);
      groupsMapping.cacheGroupsAdd(new LinkedList<String>(groups));
    }
  }
}
 
Example 5
Source File: Configuration.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Get the comma delimited values of the <code>name</code> property as
 * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace.
 * If no such property is specified then empty <code>Collection</code> is returned.
 *
 * @param name property name.
 * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code>
 */
public Collection<String> getTrimmedStringCollection(String name) {
  String valueString = get(name);
  if (null == valueString) {
    Collection<String> empty = new ArrayList<String>();
    return empty;
  }
  return StringUtils.getTrimmedStringCollection(valueString);
}
 
Example 6
Source File: Configuration.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Get the comma delimited values of the <code>name</code> property as
 * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace.
 * If no such property is specified then empty <code>Collection</code> is returned.
 *
 * @param name property name.
 * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code>
 */
public Collection<String> getTrimmedStringCollection(String name) {
	String valueString = get(name);
	if (null == valueString) {
		Collection<String> empty = new ArrayList<String>();
		return empty;
	}
	return StringUtils.getTrimmedStringCollection(valueString);
}
 
Example 7
Source File: Configuration.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Get the comma delimited values of the <code>name</code> property as
 * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace.
 * If no such property is specified then empty <code>Collection</code> is returned.
 *
 * @param name property name.
 * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code>
 */
public Collection<String> getTrimmedStringCollection(String name) {
  String valueString = get(name);
  if (null == valueString) {
    Collection<String> empty = new ArrayList<String>();
    return empty;
  }
  return StringUtils.getTrimmedStringCollection(valueString);
}
 
Example 8
Source File: Configuration.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Get the comma delimited values of the <code>name</code> property as
 * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace.
 * If no such property is specified then empty <code>Collection</code> is returned.
 *
 * @param name property name.
 * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code>
 */
public Collection<String> getTrimmedStringCollection(String name) {
	String valueString = get(name);
	if (null == valueString) {
		Collection<String> empty = new ArrayList<String>();
		return empty;
	}
	return StringUtils.getTrimmedStringCollection(valueString);
}
 
Example 9
Source File: Configuration.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/** 
 * Get the comma delimited values of the <code>name</code> property as 
 * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace.  
 * If no such property is specified then empty <code>Collection</code> is returned.
 *
 * @param name property name.
 * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code> 
 */
public Collection<String> getTrimmedStringCollection(String name) {
  String valueString = get(name);
  if (null == valueString) {
    Collection<String> empty = new ArrayList<String>();
    return empty;
  }
  return StringUtils.getTrimmedStringCollection(valueString);
}
 
Example 10
Source File: Configuration.java    From big-c with Apache License 2.0 5 votes vote down vote up
/** 
 * Get the comma delimited values of the <code>name</code> property as 
 * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace.  
 * If no such property is specified then empty <code>Collection</code> is returned.
 *
 * @param name property name.
 * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code> 
 */
public Collection<String> getTrimmedStringCollection(String name) {
  String valueString = get(name);
  if (null == valueString) {
    Collection<String> empty = new ArrayList<String>();
    return empty;
  }
  return StringUtils.getTrimmedStringCollection(valueString);
}
 
Example 11
Source File: Configuration.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Get the comma delimited values of the <code>name</code> property as
 * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace.
 * If no such property is specified then empty <code>Collection</code> is returned.
 *
 * @param name property name.
 * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code>
 */
public Collection<String> getTrimmedStringCollection(String name) {
  String valueString = get(name);
  if (null == valueString) {
    Collection<String> empty = new ArrayList<String>();
    return empty;
  }
  return StringUtils.getTrimmedStringCollection(valueString);
}
 
Example 12
Source File: Configuration.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Get the comma delimited values of the <code>name</code> property as
 * a collection of <code>String</code>s, trimmed of the leading and trailing whitespace.
 * If no such property is specified then empty <code>Collection</code> is returned.
 *
 * @param name property name.
 * @return property value as a collection of <code>String</code>s, or empty <code>Collection</code>
 */
public Collection<String> getTrimmedStringCollection(String name) {
	String valueString = get(name);
	if (null == valueString) {
		Collection<String> empty = new ArrayList<String>();
		return empty;
	}
	return StringUtils.getTrimmedStringCollection(valueString);
}
 
Example 13
Source File: NamenodeWebHdfsMethods.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static DatanodeInfo chooseDatanode(final NameNode namenode,
    final String path, final HttpOpParam.Op op, final long openOffset,
    final long blocksize, final String excludeDatanodes) throws IOException {
  final BlockManager bm = namenode.getNamesystem().getBlockManager();
  
  HashSet<Node> excludes = new HashSet<Node>();
  if (excludeDatanodes != null) {
    for (String host : StringUtils
        .getTrimmedStringCollection(excludeDatanodes)) {
      int idx = host.indexOf(":");
      if (idx != -1) {          
        excludes.add(bm.getDatanodeManager().getDatanodeByXferAddr(
            host.substring(0, idx), Integer.parseInt(host.substring(idx + 1))));
      } else {
        excludes.add(bm.getDatanodeManager().getDatanodeByHost(host));
      }
    }
  }

  if (op == PutOpParam.Op.CREATE) {
    //choose a datanode near to client 
    final DatanodeDescriptor clientNode = bm.getDatanodeManager(
        ).getDatanodeByHost(getRemoteAddress());
    if (clientNode != null) {
      final DatanodeStorageInfo[] storages = bm.chooseTarget4WebHDFS(
          path, clientNode, excludes, blocksize);
      if (storages.length > 0) {
        return storages[0].getDatanodeDescriptor();
      }
    }
  } else if (op == GetOpParam.Op.OPEN
      || op == GetOpParam.Op.GETFILECHECKSUM
      || op == PostOpParam.Op.APPEND) {
    //choose a datanode containing a replica 
    final NamenodeProtocols np = getRPCServer(namenode);
    final HdfsFileStatus status = np.getFileInfo(path);
    if (status == null) {
      throw new FileNotFoundException("File " + path + " not found.");
    }
    final long len = status.getLen();
    if (op == GetOpParam.Op.OPEN) {
      if (openOffset < 0L || (openOffset >= len && len > 0)) {
        throw new IOException("Offset=" + openOffset
            + " out of the range [0, " + len + "); " + op + ", path=" + path);
      }
    }

    if (len > 0) {
      final long offset = op == GetOpParam.Op.OPEN? openOffset: len - 1;
      final LocatedBlocks locations = np.getBlockLocations(path, offset, 1);
      final int count = locations.locatedBlockCount();
      if (count > 0) {
        return bestNode(locations.get(0).getLocations(), excludes);
      }
    }
  } 

  return (DatanodeDescriptor)bm.getDatanodeManager().getNetworkTopology(
      ).chooseRandom(NodeBase.ROOT);
}
 
Example 14
Source File: NamenodeWebHdfsMethods.java    From big-c with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
static DatanodeInfo chooseDatanode(final NameNode namenode,
    final String path, final HttpOpParam.Op op, final long openOffset,
    final long blocksize, final String excludeDatanodes) throws IOException {
  final BlockManager bm = namenode.getNamesystem().getBlockManager();
  
  HashSet<Node> excludes = new HashSet<Node>();
  if (excludeDatanodes != null) {
    for (String host : StringUtils
        .getTrimmedStringCollection(excludeDatanodes)) {
      int idx = host.indexOf(":");
      if (idx != -1) {          
        excludes.add(bm.getDatanodeManager().getDatanodeByXferAddr(
            host.substring(0, idx), Integer.parseInt(host.substring(idx + 1))));
      } else {
        excludes.add(bm.getDatanodeManager().getDatanodeByHost(host));
      }
    }
  }

  if (op == PutOpParam.Op.CREATE) {
    //choose a datanode near to client 
    final DatanodeDescriptor clientNode = bm.getDatanodeManager(
        ).getDatanodeByHost(getRemoteAddress());
    if (clientNode != null) {
      final DatanodeStorageInfo[] storages = bm.chooseTarget4WebHDFS(
          path, clientNode, excludes, blocksize);
      if (storages.length > 0) {
        return storages[0].getDatanodeDescriptor();
      }
    }
  } else if (op == GetOpParam.Op.OPEN
      || op == GetOpParam.Op.GETFILECHECKSUM
      || op == PostOpParam.Op.APPEND) {
    //choose a datanode containing a replica 
    final NamenodeProtocols np = getRPCServer(namenode);
    final HdfsFileStatus status = np.getFileInfo(path);
    if (status == null) {
      throw new FileNotFoundException("File " + path + " not found.");
    }
    final long len = status.getLen();
    if (op == GetOpParam.Op.OPEN) {
      if (openOffset < 0L || (openOffset >= len && len > 0)) {
        throw new IOException("Offset=" + openOffset
            + " out of the range [0, " + len + "); " + op + ", path=" + path);
      }
    }

    if (len > 0) {
      final long offset = op == GetOpParam.Op.OPEN? openOffset: len - 1;
      final LocatedBlocks locations = np.getBlockLocations(path, offset, 1);
      final int count = locations.locatedBlockCount();
      if (count > 0) {
        return bestNode(locations.get(0).getLocations(), excludes);
      }
    }
  } 

  return (DatanodeDescriptor)bm.getDatanodeManager().getNetworkTopology(
      ).chooseRandom(NodeBase.ROOT);
}