Search in sources :

Example 1 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.

the class DelegationTokenAuthenticationHandler method initTokenManager.

@VisibleForTesting
@SuppressWarnings("unchecked")
public void initTokenManager(Properties config) {
    Configuration conf = new Configuration(false);
    for (Map.Entry entry : config.entrySet()) {
        conf.set((String) entry.getKey(), (String) entry.getValue());
    }
    String tokenKind = conf.get(TOKEN_KIND);
    if (tokenKind == null) {
        throw new IllegalArgumentException("The configuration does not define the token kind");
    }
    tokenKind = tokenKind.trim();
    tokenManager = new DelegationTokenManager(conf, new Text(tokenKind));
    tokenManager.init();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Text(org.apache.hadoop.io.Text) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.

the class DelegationTokenAuthenticationHandler method initJsonFactory.

@VisibleForTesting
public void initJsonFactory(Properties config) {
    boolean hasFeature = false;
    JsonFactory tmpJsonFactory = new JsonFactory();
    for (Map.Entry entry : config.entrySet()) {
        String key = (String) entry.getKey();
        if (key.startsWith(JSON_MAPPER_PREFIX)) {
            JsonGenerator.Feature feature = JsonGenerator.Feature.valueOf(key.substring(JSON_MAPPER_PREFIX.length()));
            if (feature != null) {
                hasFeature = true;
                boolean enabled = Boolean.parseBoolean((String) entry.getValue());
                tmpJsonFactory.configure(feature, enabled);
            }
        }
    }
    if (hasFeature) {
        jsonFactory = tmpJsonFactory;
    }
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.

the class ShellBasedUnixGroupsMapping method resolveFullGroupNames.

/**
   * Split group names into a linked list.
   *
   * @param groupNames a string representing the user's group names
   * @return a linked list of group names
   */
@VisibleForTesting
protected List<String> resolveFullGroupNames(String groupNames) {
    StringTokenizer tokenizer = new StringTokenizer(groupNames, Shell.TOKEN_SEPARATOR_REGEX);
    List<String> groups = new LinkedList<String>();
    while (tokenizer.hasMoreTokens()) {
        groups.add(tokenizer.nextToken());
    }
    return groups;
}
Also used : StringTokenizer(java.util.StringTokenizer) LinkedList(java.util.LinkedList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.

the class SecureIOUtils method forceSecureOpenFSDataInputStream.

/**
   * Same as openFSDataInputStream except that it will run even if security is
   * off. This is used by unit tests.
   */
@VisibleForTesting
protected static FSDataInputStream forceSecureOpenFSDataInputStream(File file, String expectedOwner, String expectedGroup) throws IOException {
    final FSDataInputStream in = rawFilesystem.open(new Path(file.getAbsolutePath()));
    boolean success = false;
    try {
        Stat stat = NativeIO.POSIX.getFstat(in.getFileDescriptor());
        checkStat(file, stat.getOwner(), stat.getGroup(), expectedOwner, expectedGroup);
        success = true;
        return in;
    } finally {
        if (!success) {
            in.close();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Stat(org.apache.hadoop.io.nativeio.NativeIO.POSIX.Stat) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.

the class SecureIOUtils method forceSecureOpenForRead.

/**
   * Same as openForRead() except that it will run even if security is off.
   * This is used by unit tests.
   */
@VisibleForTesting
protected static FileInputStream forceSecureOpenForRead(File f, String expectedOwner, String expectedGroup) throws IOException {
    FileInputStream fis = new FileInputStream(f);
    boolean success = false;
    try {
        Stat stat = NativeIO.POSIX.getFstat(fis.getFD());
        checkStat(f, stat.getOwner(), stat.getGroup(), expectedOwner, expectedGroup);
        success = true;
        return fis;
    } finally {
        if (!success) {
            fis.close();
        }
    }
}
Also used : Stat(org.apache.hadoop.io.nativeio.NativeIO.POSIX.Stat) FileInputStream(java.io.FileInputStream) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)760 IOException (java.io.IOException)128 ArrayList (java.util.ArrayList)52 Path (java.nio.file.Path)46 Map (java.util.Map)46 File (java.io.File)40 HashMap (java.util.HashMap)34 Path (org.apache.hadoop.fs.Path)30 ImmutableList (com.google.common.collect.ImmutableList)28 Matcher (java.util.regex.Matcher)26 List (java.util.List)24 SourcePath (com.facebook.buck.rules.SourcePath)20 ImmutableMap (com.google.common.collect.ImmutableMap)20 HashSet (java.util.HashSet)19 FileStatus (org.apache.hadoop.fs.FileStatus)19 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)19 DFSClient (org.apache.hadoop.hdfs.DFSClient)18 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)18 ImmutableSet (com.google.common.collect.ImmutableSet)16 CigarElement (htsjdk.samtools.CigarElement)13