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);
}
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());
}
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();
}
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);
}
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();
}
}
Aggregations