Search in sources :

Example 1 with OzoneManagerProtocolClientSideTranslatorPB

use of org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB in project ozone by apache.

the class BaseFreonGenerator method createOmClient.

/**
 * Create the OM RPC client to use it for testing.
 */
public OzoneManagerProtocolClientSideTranslatorPB createOmClient(OzoneConfiguration conf, String omServiceID) throws IOException {
    UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
    RPC.setProtocolEngine(conf, OzoneManagerProtocolPB.class, ProtobufRpcEngine.class);
    String clientId = ClientId.randomId().toString();
    if (omServiceID == null) {
        // if only one serviceId is configured, use that
        final String[] configuredServiceIds = conf.getTrimmedStrings(OZONE_OM_SERVICE_IDS_KEY);
        if (configuredServiceIds.length == 1) {
            omServiceID = configuredServiceIds[0];
        }
    }
    OmTransport transport = OmTransportFactory.create(conf, ugi, omServiceID);
    return new OzoneManagerProtocolClientSideTranslatorPB(transport, clientId);
}
Also used : OzoneManagerProtocolClientSideTranslatorPB(org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB) OmTransport(org.apache.hadoop.ozone.om.protocolPB.OmTransport) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 2 with OzoneManagerProtocolClientSideTranslatorPB

use of org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB in project ozone by apache.

the class TestOMEpochForNonRatis method testUniqueTrxnIndexOnOMRestart.

@Test
public void testUniqueTrxnIndexOnOMRestart() throws Exception {
    // When OM is restarted, the transaction index for requests should not
    // start from 0. It should incrementally increase from the last
    // transaction index which was stored in DB before restart.
    String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
    String bucketName = "bucket" + RandomStringUtils.randomNumeric(5);
    String keyName = "key" + RandomStringUtils.randomNumeric(5);
    OzoneManager om = cluster.getOzoneManager();
    OzoneClient client = cluster.getClient();
    ObjectStore objectStore = client.getObjectStore();
    UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
    OzoneManagerProtocolClientSideTranslatorPB omClient = new OzoneManagerProtocolClientSideTranslatorPB(OmTransportFactory.create(conf, ugi, null), RandomStringUtils.randomAscii(5));
    objectStore.createVolume(volumeName);
    // Verify that the last transactionIndex stored in DB after volume
    // creation equals the transaction index corresponding to volume's
    // objectID. Also, the volume transaction index should be 1 as this is
    // the first transaction in this cluster.
    OmVolumeArgs volumeInfo = omClient.getVolumeInfo(volumeName);
    long volumeTrxnIndex = OmUtils.getTxIdFromObjectId(volumeInfo.getObjectID());
    Assert.assertEquals(1, volumeTrxnIndex);
    Assert.assertEquals(volumeTrxnIndex, om.getLastTrxnIndexForNonRatis());
    OzoneVolume ozoneVolume = objectStore.getVolume(volumeName);
    ozoneVolume.createBucket(bucketName);
    // Verify last transactionIndex is updated after bucket creation
    OmBucketInfo bucketInfo = omClient.getBucketInfo(volumeName, bucketName);
    long bucketTrxnIndex = OmUtils.getTxIdFromObjectId(bucketInfo.getObjectID());
    Assert.assertEquals(2, bucketTrxnIndex);
    Assert.assertEquals(bucketTrxnIndex, om.getLastTrxnIndexForNonRatis());
    // Restart the OM and create new object
    cluster.restartOzoneManager();
    String data = "random data";
    OzoneOutputStream ozoneOutputStream = ozoneVolume.getBucket(bucketName).createKey(keyName, data.length(), ReplicationType.RATIS, ReplicationFactor.ONE, new HashMap<>());
    ozoneOutputStream.write(data.getBytes(UTF_8), 0, data.length());
    ozoneOutputStream.close();
    // Verify last transactionIndex is updated after key creation and the
    // transaction index after restart is incremented from the last
    // transaction index before restart.
    OmKeyInfo omKeyInfo = omClient.lookupKey(new OmKeyArgs.Builder().setVolumeName(volumeName).setBucketName(bucketName).setKeyName(keyName).setRefreshPipeline(true).build());
    long keyTrxnIndex = OmUtils.getTxIdFromObjectId(omKeyInfo.getObjectID());
    Assert.assertEquals(3, keyTrxnIndex);
    // Key commit is a separate transaction. Hence, the last trxn index in DB
    // should be 1 more than KeyTrxnIndex
    Assert.assertEquals(4, om.getLastTrxnIndexForNonRatis());
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) OzoneManagerProtocolClientSideTranslatorPB(org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB) ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) OzoneOutputStream(org.apache.hadoop.ozone.client.io.OzoneOutputStream) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 3 with OzoneManagerProtocolClientSideTranslatorPB

use of org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB in project ozone by apache.

the class OmFailoverProxyUtil method getFailoverProxyProvider.

/**
 * Get FailoverProxyProvider from RpcClient / ClientProtocol.
 */
public static OMFailoverProxyProvider getFailoverProxyProvider(ClientProtocol clientProtocol) {
    OzoneManagerProtocolClientSideTranslatorPB ozoneManagerClient = (OzoneManagerProtocolClientSideTranslatorPB) ((RpcClient) clientProtocol).getOzoneManagerClient();
    Hadoop3OmTransport transport = (Hadoop3OmTransport) ozoneManagerClient.getTransport();
    return transport.getOmFailoverProxyProvider();
}
Also used : OzoneManagerProtocolClientSideTranslatorPB(org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB) Hadoop3OmTransport(org.apache.hadoop.ozone.om.protocolPB.Hadoop3OmTransport)

Example 4 with OzoneManagerProtocolClientSideTranslatorPB

use of org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB in project ozone by apache.

the class TestOMEpochForNonRatis method testEpochIntegrationInObjectID.

@Test
public void testEpochIntegrationInObjectID() throws Exception {
    // Create a volume and check the objectID has the epoch as
    // EPOCH_FOR_RATIS_NOT_ENABLED in the first 2 bits.
    OzoneClient client = cluster.getClient();
    ObjectStore objectStore = client.getObjectStore();
    String volumeName = "volume" + RandomStringUtils.randomNumeric(5);
    objectStore.createVolume(volumeName);
    UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
    OzoneManagerProtocolClientSideTranslatorPB omClient = new OzoneManagerProtocolClientSideTranslatorPB(OmTransportFactory.create(conf, ugi, null), RandomStringUtils.randomAscii(5));
    long volObjId = omClient.getVolumeInfo(volumeName).getObjectID();
    long epochInVolObjId = volObjId >> EPOCH_ID_SHIFT;
    Assert.assertEquals(EPOCH_WHEN_RATIS_NOT_ENABLED, epochInVolObjId);
}
Also used : OzoneManagerProtocolClientSideTranslatorPB(org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB) ObjectStore(org.apache.hadoop.ozone.client.ObjectStore) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 5 with OzoneManagerProtocolClientSideTranslatorPB

use of org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB in project ozone by apache.

the class TestSecureOzoneCluster method testDelegationTokenRenewal.

/**
 * Tests delegation token renewal.
 */
@Test
public void testDelegationTokenRenewal() throws Exception {
    GenericTestUtils.setLogLevel(LoggerFactory.getLogger(Server.class.getName()), INFO);
    LogCapturer omLogs = LogCapturer.captureLogs(OzoneManager.getLogger());
    // Setup secure OM for start.
    OzoneConfiguration newConf = new OzoneConfiguration(conf);
    int tokenMaxLifetime = 1000;
    newConf.setLong(DELEGATION_TOKEN_MAX_LIFETIME_KEY, tokenMaxLifetime);
    setupOm(newConf);
    OzoneManager.setTestSecureOmFlag(true);
    try {
        om.setCertClient(new CertificateClientTestImpl(conf));
        om.start();
        UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
        // Get first OM client which will authenticate via Kerberos
        omClient = new OzoneManagerProtocolClientSideTranslatorPB(OmTransportFactory.create(conf, ugi, null), RandomStringUtils.randomAscii(5));
        // Since client is already connected get a delegation token
        Token<OzoneTokenIdentifier> token = omClient.getDelegationToken(new Text("om"));
        // Check if token is of right kind and renewer is running om instance
        assertNotNull(token);
        assertEquals("OzoneToken", token.getKind().toString());
        assertEquals(OmUtils.getOmRpcAddress(conf), token.getService().toString());
        // Renew delegation token
        long expiryTime = omClient.renewDelegationToken(token);
        assertTrue(expiryTime > 0);
        omLogs.clearOutput();
        // Test failure of delegation renewal
        // 1. When token maxExpiryTime exceeds
        Thread.sleep(tokenMaxLifetime);
        OMException ex = LambdaTestUtils.intercept(OMException.class, "TOKEN_EXPIRED", () -> omClient.renewDelegationToken(token));
        assertEquals(TOKEN_EXPIRED, ex.getResult());
        omLogs.clearOutput();
        // 2. When renewer doesn't match (implicitly covers when renewer is
        // null or empty )
        Token<OzoneTokenIdentifier> token2 = omClient.getDelegationToken(new Text("randomService"));
        assertNotNull(token2);
        LambdaTestUtils.intercept(OMException.class, "Delegation token renewal failed", () -> omClient.renewDelegationToken(token2));
        assertTrue(omLogs.getOutput().contains(" with non-matching " + "renewer randomService"));
        omLogs.clearOutput();
        // 3. Test tampered token
        OzoneTokenIdentifier tokenId = OzoneTokenIdentifier.readProtoBuf(token.getIdentifier());
        tokenId.setRenewer(new Text("om"));
        tokenId.setMaxDate(System.currentTimeMillis() * 2);
        Token<OzoneTokenIdentifier> tamperedToken = new Token<>(tokenId.getBytes(), token2.getPassword(), token2.getKind(), token2.getService());
        LambdaTestUtils.intercept(OMException.class, "Delegation token renewal failed", () -> omClient.renewDelegationToken(tamperedToken));
        assertTrue(omLogs.getOutput().contains("can't be found in " + "cache"));
        omLogs.clearOutput();
    } finally {
        om.stop();
        om.join();
    }
}
Also used : OzoneManagerProtocolClientSideTranslatorPB(org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB) CertificateClientTestImpl(org.apache.hadoop.ozone.client.CertificateClientTestImpl) OzoneTokenIdentifier(org.apache.hadoop.ozone.security.OzoneTokenIdentifier) LogCapturer(org.apache.ozone.test.GenericTestUtils.LogCapturer) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) Text(org.apache.hadoop.io.Text) Token(org.apache.hadoop.security.token.Token) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Aggregations

OzoneManagerProtocolClientSideTranslatorPB (org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolClientSideTranslatorPB)10 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)8 Test (org.junit.Test)6 CertificateClientTestImpl (org.apache.hadoop.ozone.client.CertificateClientTestImpl)4 IOException (java.io.IOException)3 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)3 OmTransport (org.apache.hadoop.ozone.om.protocolPB.OmTransport)3 LogCapturer (org.apache.ozone.test.GenericTestUtils.LogCapturer)3 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)2 Text (org.apache.hadoop.io.Text)2 ObjectStore (org.apache.hadoop.ozone.client.ObjectStore)2 OzoneClient (org.apache.hadoop.ozone.client.OzoneClient)2 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)2 OzoneTokenIdentifier (org.apache.hadoop.ozone.security.OzoneTokenIdentifier)2 Provides (com.google.inject.Provides)1 SCMSecurityException (org.apache.hadoop.hdds.security.exception.SCMSecurityException)1 OzoneClientException (org.apache.hadoop.ozone.client.OzoneClientException)1 OzoneVolume (org.apache.hadoop.ozone.client.OzoneVolume)1 OzoneOutputStream (org.apache.hadoop.ozone.client.io.OzoneOutputStream)1 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)1