use of org.apache.tez.client.TezApiVersionInfo in project tez by apache.
the class TestDAGAppMaster method testDagCredentials.
@SuppressWarnings("deprecation")
private void testDagCredentials(boolean doMerge) throws IOException {
TezConfiguration conf = new TezConfiguration();
conf.setBoolean(TezConfiguration.TEZ_AM_CREDENTIALS_MERGE, doMerge);
conf.setBoolean(TezConfiguration.TEZ_LOCAL_MODE, true);
conf.set(TezConfiguration.TEZ_AM_STAGING_DIR, TEST_DIR.toString());
ApplicationId appId = ApplicationId.newInstance(1, 1);
ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1);
// create some sample AM credentials
Credentials amCreds = new Credentials();
JobTokenSecretManager jtsm = new JobTokenSecretManager();
JobTokenIdentifier identifier = new JobTokenIdentifier(new Text(appId.toString()));
Token<JobTokenIdentifier> sessionToken = new Token<JobTokenIdentifier>(identifier, jtsm);
sessionToken.setService(identifier.getJobId());
TokenCache.setSessionToken(sessionToken, amCreds);
TestTokenSecretManager ttsm = new TestTokenSecretManager();
Text tokenAlias1 = new Text("alias1");
Token<TestTokenIdentifier> amToken1 = new Token<TestTokenIdentifier>(new TestTokenIdentifier(new Text("amtoken1")), ttsm);
amCreds.addToken(tokenAlias1, amToken1);
Text tokenAlias2 = new Text("alias2");
Token<TestTokenIdentifier> amToken2 = new Token<TestTokenIdentifier>(new TestTokenIdentifier(new Text("amtoken2")), ttsm);
amCreds.addToken(tokenAlias2, amToken2);
FileSystem fs = FileSystem.getLocal(conf);
FSDataOutputStream sessionJarsPBOutStream = TezCommonUtils.createFileForAM(fs, new Path(TEST_DIR.toString(), TezConstants.TEZ_AM_LOCAL_RESOURCES_PB_FILE_NAME));
DAGProtos.PlanLocalResourcesProto.getDefaultInstance().writeDelimitedTo(sessionJarsPBOutStream);
sessionJarsPBOutStream.close();
DAGAppMaster am = new DAGAppMaster(attemptId, ContainerId.newInstance(attemptId, 1), "127.0.0.1", 0, 0, new SystemClock(), 1, true, TEST_DIR.toString(), new String[] { TEST_DIR.toString() }, new String[] { TEST_DIR.toString() }, new TezApiVersionInfo().getVersion(), amCreds, "someuser", null);
am.init(conf);
am.start();
// create some sample DAG credentials
Credentials dagCreds = new Credentials();
Token<TestTokenIdentifier> dagToken1 = new Token<TestTokenIdentifier>(new TestTokenIdentifier(new Text("dagtoken1")), ttsm);
dagCreds.addToken(tokenAlias2, dagToken1);
Text tokenAlias3 = new Text("alias3");
Token<TestTokenIdentifier> dagToken2 = new Token<TestTokenIdentifier>(new TestTokenIdentifier(new Text("dagtoken2")), ttsm);
dagCreds.addToken(tokenAlias3, dagToken2);
TezDAGID dagId = TezDAGID.getInstance(appId, 1);
DAGPlan dagPlan = DAGPlan.newBuilder().setName("somedag").setCredentialsBinary(DagTypeConverters.convertCredentialsToProto(dagCreds)).build();
DAGImpl dag = am.createDAG(dagPlan, dagId);
Credentials fetchedDagCreds = dag.getCredentials();
am.stop();
Token<? extends TokenIdentifier> fetchedToken1 = fetchedDagCreds.getToken(tokenAlias1);
if (doMerge) {
assertNotNull("AM creds missing from DAG creds", fetchedToken1);
compareTestTokens(amToken1, fetchedDagCreds.getToken(tokenAlias1));
} else {
assertNull("AM creds leaked to DAG creds", fetchedToken1);
}
compareTestTokens(dagToken1, fetchedDagCreds.getToken(tokenAlias2));
compareTestTokens(dagToken2, fetchedDagCreds.getToken(tokenAlias3));
}
Aggregations