Search in sources :

Example 26 with Text

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

the class KMSClientProvider method getDelegationTokenService.

private Text getDelegationTokenService() throws IOException {
    URL url = new URL(kmsUrl);
    InetSocketAddress addr = new InetSocketAddress(url.getHost(), url.getPort());
    Text dtService = SecurityUtil.buildTokenService(addr);
    return dtService;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Text(org.apache.hadoop.io.Text) URL(java.net.URL) AuthenticatedURL(org.apache.hadoop.security.authentication.client.AuthenticatedURL) DelegationTokenAuthenticatedURL(org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL)

Example 27 with Text

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

the class TestKeyProviderDelegationTokenExtension method testCreateExtension.

@Test
public void testCreateExtension() throws Exception {
    Configuration conf = new Configuration();
    Credentials credentials = new Credentials();
    KeyProvider kp = new UserProvider.Factory().createProvider(new URI("user:///"), conf);
    KeyProviderDelegationTokenExtension kpDTE1 = KeyProviderDelegationTokenExtension.createKeyProviderDelegationTokenExtension(kp);
    Assert.assertNotNull(kpDTE1);
    // Default implementation should be a no-op and return null
    Assert.assertNull(kpDTE1.addDelegationTokens("user", credentials));
    MockKeyProvider mock = mock(MockKeyProvider.class);
    Mockito.when(mock.getConf()).thenReturn(new Configuration());
    when(mock.addDelegationTokens("renewer", credentials)).thenReturn(new Token<?>[] { new Token(null, null, new Text("kind"), new Text("service")) });
    KeyProviderDelegationTokenExtension kpDTE2 = KeyProviderDelegationTokenExtension.createKeyProviderDelegationTokenExtension(mock);
    Token<?>[] tokens = kpDTE2.addDelegationTokens("renewer", credentials);
    Assert.assertNotNull(tokens);
    Assert.assertEquals("kind", tokens[0].getKind().toString());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Token(org.apache.hadoop.security.token.Token) Text(org.apache.hadoop.io.Text) URI(java.net.URI) Credentials(org.apache.hadoop.security.Credentials) Test(org.junit.Test)

Example 28 with Text

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

the class TestKeyProviderFactory method testUserProvider.

@Test
public void testUserProvider() throws Exception {
    Configuration conf = new Configuration();
    final String ourUrl = UserProvider.SCHEME_NAME + ":///";
    conf.set(KeyProviderFactory.KEY_PROVIDER_PATH, ourUrl);
    checkSpecificProvider(conf, ourUrl);
    // see if the credentials are actually in the UGI
    Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials();
    assertArrayEquals(new byte[] { 1 }, credentials.getSecretKey(new Text("key4@0")));
    assertArrayEquals(new byte[] { 2 }, credentials.getSecretKey(new Text("key4@1")));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Text(org.apache.hadoop.io.Text) Credentials(org.apache.hadoop.security.Credentials) Test(org.junit.Test)

Example 29 with Text

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

the class TestDelegationTokenRenewer method testStopRenewalWhenFsGone.

@Test
public void testStopRenewalWhenFsGone() throws IOException, InterruptedException {
    Configuration conf = mock(Configuration.class);
    Token<?> token = mock(Token.class);
    doReturn(new Text("myservice")).when(token).getService();
    doAnswer(new Answer<Long>() {

        public Long answer(InvocationOnMock invocation) {
            return Time.now() + RENEW_CYCLE;
        }
    }).when(token).renew(any(Configuration.class));
    RenewableFileSystem fs = mock(RenewableFileSystem.class);
    doReturn(conf).when(fs).getConf();
    doReturn(token).when(fs).getRenewToken();
    renewer.addRenewAction(fs);
    assertEquals(1, renewer.getRenewQueueLength());
    Thread.sleep(RENEW_CYCLE);
    verify(token, atLeast(1)).renew(eq(conf));
    verify(token, atMost(2)).renew(eq(conf));
    // drop weak ref
    fs = null;
    System.gc();
    System.gc();
    System.gc();
    // next renew should detect the fs as gone
    Thread.sleep(RENEW_CYCLE);
    verify(token, atLeast(1)).renew(eq(conf));
    verify(token, atMost(2)).renew(eq(conf));
    assertEquals(0, renewer.getRenewQueueLength());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 30 with Text

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

the class TestDelegationTokenRenewer method testGetNewTokenOnRenewFailure.

@Test
public void testGetNewTokenOnRenewFailure() throws IOException, InterruptedException {
    Text service = new Text("myservice");
    Configuration conf = mock(Configuration.class);
    final Token<?> token1 = mock(Token.class);
    doReturn(service).when(token1).getService();
    doThrow(new IOException("boom")).when(token1).renew(eq(conf));
    final Token<?> token2 = mock(Token.class);
    doReturn(service).when(token2).getService();
    doAnswer(new Answer<Long>() {

        public Long answer(InvocationOnMock invocation) {
            return Time.now() + RENEW_CYCLE;
        }
    }).when(token2).renew(eq(conf));
    RenewableFileSystem fs = mock(RenewableFileSystem.class);
    doReturn(conf).when(fs).getConf();
    doReturn(token1).doReturn(token2).when(fs).getRenewToken();
    doReturn(token2).when(fs).getDelegationToken(null);
    doAnswer(new Answer<Token<?>[]>() {

        public Token<?>[] answer(InvocationOnMock invocation) {
            return new Token<?>[] { token2 };
        }
    }).when(fs).addDelegationTokens(null, null);
    renewer.addRenewAction(fs);
    assertEquals(1, renewer.getRenewQueueLength());
    Thread.sleep(RENEW_CYCLE);
    verify(fs).getRenewToken();
    verify(token1, atLeast(1)).renew(eq(conf));
    verify(token1, atMost(2)).renew(eq(conf));
    verify(fs).addDelegationTokens(null, null);
    verify(fs).setDelegationToken(eq(token2));
    assertEquals(1, renewer.getRenewQueueLength());
    renewer.removeRenewAction(fs);
    verify(token2).cancel(eq(conf));
    assertEquals(0, renewer.getRenewQueueLength());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) Test(org.junit.Test)

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