Search in sources :

Example 21 with Text

use of org.apache.hadoop.io.Text in project flink by apache.

the class Utils method setTokensFor.

public static void setTokensFor(ContainerLaunchContext amContainer, List<Path> paths, Configuration conf) throws IOException {
    Credentials credentials = new Credentials();
    // for HDFS
    TokenCache.obtainTokensForNamenodes(credentials, paths.toArray(new Path[0]), conf);
    // for HBase
    obtainTokenForHBase(credentials, conf);
    // for user
    UserGroupInformation currUsr = UserGroupInformation.getCurrentUser();
    Collection<Token<? extends TokenIdentifier>> usrTok = currUsr.getTokens();
    for (Token<? extends TokenIdentifier> token : usrTok) {
        final Text id = new Text(token.getIdentifier());
        LOG.info("Adding user token " + id + " with " + token);
        credentials.addToken(id, token);
    }
    try (DataOutputBuffer dob = new DataOutputBuffer()) {
        credentials.writeTokenStorageToStream(dob);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Wrote tokens. Credentials buffer length: " + dob.getLength());
        }
        ByteBuffer securityTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
        amContainer.setTokens(securityTokens);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) Token(org.apache.hadoop.security.token.Token) Text(org.apache.hadoop.io.Text) ByteBuffer(java.nio.ByteBuffer) Credentials(org.apache.hadoop.security.Credentials) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 22 with Text

use of org.apache.hadoop.io.Text in project hadoop by apache.

the class UserProvider method getKeys.

@Override
public synchronized List<String> getKeys() throws IOException {
    List<String> list = new ArrayList<String>();
    List<Text> keys = credentials.getAllSecretKeys();
    for (Text key : keys) {
        if (key.find("@") == -1) {
            list.add(key.toString());
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text)

Example 23 with Text

use of org.apache.hadoop.io.Text in project hadoop by apache.

the class UserProvider method getMetadata.

@Override
public synchronized Metadata getMetadata(String name) throws IOException {
    if (cache.containsKey(name)) {
        return cache.get(name);
    }
    byte[] serialized = credentials.getSecretKey(new Text(name));
    if (serialized == null) {
        return null;
    }
    Metadata result = new Metadata(serialized);
    cache.put(name, result);
    return result;
}
Also used : Text(org.apache.hadoop.io.Text)

Example 24 with Text

use of org.apache.hadoop.io.Text in project hadoop by apache.

the class UserProvider method createKey.

@Override
public synchronized KeyVersion createKey(String name, byte[] material, Options options) throws IOException {
    Text nameT = new Text(name);
    if (credentials.getSecretKey(nameT) != null) {
        throw new IOException("Key " + name + " already exists in " + this);
    }
    if (options.getBitLength() != 8 * material.length) {
        throw new IOException("Wrong key length. Required " + options.getBitLength() + ", but got " + (8 * material.length));
    }
    Metadata meta = new Metadata(options.getCipher(), options.getBitLength(), options.getDescription(), options.getAttributes(), new Date(), 1);
    cache.put(name, meta);
    String versionName = buildVersionName(name, 0);
    credentials.addSecretKey(nameT, meta.serialize());
    credentials.addSecretKey(new Text(versionName), material);
    return new KeyVersion(name, versionName, material);
}
Also used : Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) Date(java.util.Date)

Example 25 with Text

use of org.apache.hadoop.io.Text in project hadoop by apache.

the class UserProvider method rollNewVersion.

@Override
public synchronized KeyVersion rollNewVersion(String name, byte[] material) throws IOException {
    Metadata meta = getMetadata(name);
    if (meta == null) {
        throw new IOException("Key " + name + " not found");
    }
    if (meta.getBitLength() != 8 * material.length) {
        throw new IOException("Wrong key length. Required " + meta.getBitLength() + ", but got " + (8 * material.length));
    }
    int nextVersion = meta.addVersion();
    credentials.addSecretKey(new Text(name), meta.serialize());
    String versionName = buildVersionName(name, nextVersion);
    credentials.addSecretKey(new Text(versionName), material);
    return new KeyVersion(name, versionName, material);
}
Also used : Text(org.apache.hadoop.io.Text) IOException(java.io.IOException)

Aggregations

Text (org.apache.hadoop.io.Text)1012 Test (org.junit.Test)397 Path (org.apache.hadoop.fs.Path)180 Configuration (org.apache.hadoop.conf.Configuration)169 LongWritable (org.apache.hadoop.io.LongWritable)141 IOException (java.io.IOException)139 IntWritable (org.apache.hadoop.io.IntWritable)115 FileSystem (org.apache.hadoop.fs.FileSystem)109 ArrayList (java.util.ArrayList)100 Token (org.apache.hadoop.security.token.Token)94 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)86 BytesWritable (org.apache.hadoop.io.BytesWritable)73 SequenceFile (org.apache.hadoop.io.SequenceFile)68 Credentials (org.apache.hadoop.security.Credentials)63 DeferredObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject)54 DeferredJavaObject (org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject)53 JobConf (org.apache.hadoop.mapred.JobConf)50 FloatWritable (org.apache.hadoop.io.FloatWritable)46 BooleanWritable (org.apache.hadoop.io.BooleanWritable)45 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)42