List of usage examples for org.apache.hadoop.fs FileContext getDelegationTokens
@InterfaceAudience.LimitedPrivate({ "HDFS", "MapReduce" }) public List<Token<?>> getDelegationTokens(Path p, String renewer) throws IOException
From source file:org.apache.twill.internal.yarn.YarnUtils.java
License:Apache License
/** * Helper method to get delegation tokens for the given LocationFactory. * @param config The hadoop configuration. * @param locationFactory The LocationFactory for generating tokens. * @param credentials Credentials for storing tokens acquired. * @return List of delegation Tokens acquired. */// w w w . j a v a2 s . co m public static List<Token<?>> addDelegationTokens(Configuration config, LocationFactory locationFactory, Credentials credentials) throws IOException { if (!UserGroupInformation.isSecurityEnabled()) { LOG.debug("Security is not enabled"); return ImmutableList.of(); } LocationFactory factory = unwrap(locationFactory); String renewer = getYarnTokenRenewer(config); List<Token<?>> tokens = ImmutableList.of(); if (factory instanceof HDFSLocationFactory) { FileSystem fs = ((HDFSLocationFactory) factory).getFileSystem(); Token<?>[] fsTokens = fs.addDelegationTokens(renewer, credentials); if (fsTokens != null) { tokens = ImmutableList.copyOf(fsTokens); } } else if (factory instanceof FileContextLocationFactory) { FileContext fc = ((FileContextLocationFactory) locationFactory).getFileContext(); tokens = fc.getDelegationTokens(new Path(locationFactory.create("/").toURI()), renewer); } for (Token<?> token : tokens) { credentials.addToken(token.getService(), token); } return ImmutableList.copyOf(tokens); }