/** * Read a collection {@link Token}s from a given file. * * @param tokenFilePath the token file path * @param configuration a {@link Configuration} object carrying Hadoop configuration properties * @return a collection of {@link Token}s * @throws IOException */ public static Collection<Token<? extends TokenIdentifier>> readTokensFromFile(Path tokenFilePath, Configuration configuration) throws IOException { return Credentials.readTokenStorageFile(tokenFilePath, configuration).getAllTokens(); }
/** Print out a Credentials file from the local filesystem. * @param tokenFile a local File object. * @param alias print only tokens matching alias (null matches all). * @param conf Configuration object passed along. * @param out print to this stream. * @throws IOException */ public static void printTokenFile( File tokenFile, Text alias, Configuration conf, PrintStream out) throws IOException { out.println("File: " + tokenFile.getPath()); Credentials creds = Credentials.readTokenStorageFile(tokenFile, conf); printCredentials(creds, alias, out); }
/** * Verify that tokenFile contains valid Credentials. * * If not, an exception is raised, or, if {@link #nofail} is set, * an error will be logged and the method return false. * */ private boolean verify(File tokenFile, Configuration conf, String category, String message) throws KerberosDiagsFailure { try { Credentials.readTokenStorageFile(tokenFile, conf); } catch(Exception e) { if (!nofail) { fail(category, message); } else { error(category, message); } return false; } return true; }
File tokenFile = new File(tokenFileName); if (tokenFile.exists() && tokenFile.isFile()) { Credentials cred = Credentials.readTokenStorageFile( tokenFile, conf); loginUser.addCredentials(cred); + " not found"); Credentials cred = Credentials.readTokenStorageFile( source, conf); LOG.debug("Loaded {} tokens", cred.numberOfTokens());
Credentials.readTokenStorageFile(p, conf)); conf.set("mapreduce.job.credentials.binary", p.toString(), "from -tokenCacheFile command line option");
if(StringUtils.isNotEmpty(conf.get(CREDENTIALS_LOCATION))) { String fileLoc = conf.get(CREDENTIALS_LOCATION); Credentials cred = Credentials.readTokenStorageFile(new File(fileLoc), conf); job.getCredentials().addAll(cred);
Token<?> token = null; Credentials creds = tokenFile.exists() ? Credentials.readTokenStorageFile(tokenFile, conf) : new Credentials(); ServiceLoader<DtFetcher> loader = ServiceLoader.load(DtFetcher.class); for (DtFetcher fetcher : loader) {
/** Append tokens from list of files in local filesystem, saving to last file. * @param tokenFiles list of local File objects. Last file holds the output. * @param fileFormat a string equal to FORMAT_PB or FORMAT_JAVA, for output * @param conf Configuration object passed along. * @throws IOException */ public static void appendTokenFiles( ArrayList<File> tokenFiles, String fileFormat, Configuration conf) throws IOException { Credentials newCreds = new Credentials(); File lastTokenFile = null; for (File tokenFile : tokenFiles) { lastTokenFile = tokenFile; Credentials creds = Credentials.readTokenStorageFile(tokenFile, conf); for (Token<?> token : creds.getAllTokens()) { newCreds.addToken(token.getService(), token); } } doFormattedWrite(lastTokenFile, fileFormat, newCreds, conf); }
/** Renew a token from a file in the local filesystem, matching alias. * @param tokenFile a local File object. * @param fileFormat a string equal to FORMAT_PB or FORMAT_JAVA, for output * @param alias renew only tokens matching alias; null matches all. * @param conf Configuration object passed along. * @throws IOException * @throws InterruptedException */ public static void renewTokenFile( File tokenFile, String fileFormat, Text alias, Configuration conf) throws IOException, InterruptedException { Credentials creds = Credentials.readTokenStorageFile(tokenFile, conf); for (Token<?> token : creds.getAllTokens()) { if (token.isManaged() && matchAlias(token, alias)) { long result = token.renew(conf); LOG.info("Renewed" + token.getKind() + ":" + token.getService() + " until " + formatDate(result)); } } doFormattedWrite(tokenFile, fileFormat, creds, conf); } }
/** Alias a token from a file and save back to file in the local filesystem. * @param tokenFile a local File object to hold the input and output. * @param fileFormat a string equal to FORMAT_PB or FORMAT_JAVA, for output * @param alias overwrite service field of fetched token with this text. * @param service only apply alias to tokens matching this service text. * @param conf Configuration object passed along. * @throws IOException */ public static void aliasTokenFile(File tokenFile, String fileFormat, Text alias, Text service, Configuration conf) throws Exception { Credentials newCreds = new Credentials(); Credentials creds = Credentials.readTokenStorageFile(tokenFile, conf); for (Token<?> token : creds.getAllTokens()) { newCreds.addToken(token.getService(), token); if (token.getService().equals(service)) { Token<?> aliasedToken = token.copyToken(); aliasedToken.setService(alias); newCreds.addToken(alias, aliasedToken); } } doFormattedWrite(tokenFile, fileFormat, newCreds, conf); }
/** Remove a token from a file in the local filesystem, matching alias. * @param cancel cancel token as well as remove from file. * @param tokenFile a local File object. * @param fileFormat a string equal to FORMAT_PB or FORMAT_JAVA, for output * @param alias remove only tokens matching alias; null matches all. * @param conf Configuration object passed along. * @throws IOException * @throws InterruptedException */ public static void removeTokenFromFile(boolean cancel, File tokenFile, String fileFormat, Text alias, Configuration conf) throws IOException, InterruptedException { Credentials newCreds = new Credentials(); Credentials creds = Credentials.readTokenStorageFile(tokenFile, conf); for (Token<?> token : creds.getAllTokens()) { if (matchAlias(token, alias)) { if (token.isManaged() && cancel) { token.cancel(conf); LOG.info("Canceled " + token.getKind() + ":" + token.getService()); } } else { newCreds.addToken(token.getService(), token); } } doFormattedWrite(tokenFile, fileFormat, newCreds, conf); }
private static Collection<Token<?>> readTokens(Path file, Configuration conf) throws IOException { Credentials creds = Credentials.readTokenStorageFile(file, conf); return creds.getAllTokens(); } }
private static Collection<Token<?>> readTokens(Path file, Configuration conf) throws IOException { Credentials creds = Credentials.readTokenStorageFile(file, conf); return creds.getAllTokens(); }
private static Collection<Token<?>> readTokens(Path file, Configuration conf) throws IOException { Credentials creds = Credentials.readTokenStorageFile(file, conf); return creds.getAllTokens(); }
/** * Read a collection {@link Token}s from a given file. * * @param tokenFilePath the token file path * @param configuration a {@link Configuration} object carrying Hadoop configuration properties * @return a collection of {@link Token}s * @throws IOException */ public static Collection<Token<? extends TokenIdentifier>> readTokensFromFile(Path tokenFilePath, Configuration configuration) throws IOException { return Credentials.readTokenStorageFile(tokenFilePath, configuration).getAllTokens(); }
private static void mergeBinaryTokens(Credentials creds, Configuration conf) { String binaryTokenFilename = conf.get(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY); if (binaryTokenFilename != null) { Credentials binary; try { binary = Credentials.readTokenStorageFile( FileSystem.getLocal(conf).makeQualified( new Path(binaryTokenFilename)), conf); } catch (IOException e) { throw new RuntimeException(e); } // supplement existing tokens with the tokens in the binary file creds.mergeAll(binary); } }
private static void mergeBinaryTokens(Credentials creds, Configuration conf) { String binaryTokenFilename = conf.get(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY); if (binaryTokenFilename != null) { Credentials binary; try { binary = Credentials.readTokenStorageFile( FileSystem.getLocal(conf).makeQualified( new Path(binaryTokenFilename)), conf); } catch (IOException e) { throw new RuntimeException(e); } // supplement existing tokens with the tokens in the binary file creds.mergeAll(binary); } }
private static void mergeBinaryTokens(Credentials creds, Configuration conf) { String binaryTokenFilename = conf.get(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY); if (binaryTokenFilename != null) { Credentials binary; try { binary = Credentials.readTokenStorageFile( FileSystem.getLocal(conf).makeQualified( new Path(binaryTokenFilename)), conf); } catch (IOException e) { throw new RuntimeException(e); } // supplement existing tokens with the tokens in the binary file creds.mergeAll(binary); } }
private static void mergeBinaryTokens(Credentials creds, Configuration conf) { String binaryTokenFilename = conf.get(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY); if (binaryTokenFilename != null) { Credentials binary; try { binary = Credentials.readTokenStorageFile( FileSystem.getLocal(conf).makeQualified( new Path(binaryTokenFilename)), conf); } catch (IOException e) { throw new RuntimeException(e); } // supplement existing tokens with the tokens in the binary file creds.mergeAll(binary); } }
/** * load job token from a file * @param conf * @throws IOException */ @InterfaceAudience.Private public static Credentials loadTokens(String jobTokenFile, JobConf conf) throws IOException { Path localJobTokenFile = new Path ("file:///" + jobTokenFile); Credentials ts = Credentials.readTokenStorageFile(localJobTokenFile, conf); if(LOG.isDebugEnabled()) { LOG.debug("Task: Loaded jobTokenFile from: "+ localJobTokenFile.toUri().getPath() +"; num of sec keys = " + ts.numberOfSecretKeys() + " Number of tokens " + ts.numberOfTokens()); } return ts; } /**