Search in sources :

Example 1 with VolumeInfo

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo in project ozone by apache.

the class TestOMVolumeRequest method createVolumeRequest.

/**
 * Create OMRequest for create volume.
 * @param volumeName
 * @param adminName
 * @param ownerName
 * @return OMRequest
 */
static OMRequest createVolumeRequest(String volumeName, String adminName, String ownerName) {
    VolumeInfo volumeInfo = VolumeInfo.newBuilder().setVolume(volumeName).setAdminName(adminName).setOwnerName(ownerName).build();
    CreateVolumeRequest createVolumeRequest = CreateVolumeRequest.newBuilder().setVolumeInfo(volumeInfo).build();
    return OMRequest.newBuilder().setClientId(UUID.randomUUID().toString()).setCmdType(OzoneManagerProtocolProtos.Type.CreateVolume).setCreateVolumeRequest(createVolumeRequest).build();
}
Also used : CreateVolumeRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateVolumeRequest) VolumeInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo)

Example 2 with VolumeInfo

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo in project ozone by apache.

the class TestSecureOzoneRpcClient method testS3Auth.

@Test
public void testS3Auth() throws Exception {
    String volumeName = UUID.randomUUID().toString();
    String strToSign = "AWS4-HMAC-SHA256\n" + "20150830T123600Z\n" + "20150830/us-east-1/iam/aws4_request\n" + "f536975d06c0309214f805bb90ccff089219ecd68b2" + "577efef23edd43b7e1a59";
    String signature = "5d672d79c15b13162d9279b0855cfba" + "6789a8edb4c82c400e06b5924a6f2b5d7";
    String secret = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY";
    String accessKey = UserGroupInformation.getCurrentUser().getUserName();
    // Add secret to S3Secret table.
    cluster.getOzoneManager().getMetadataManager().getS3SecretTable().put(accessKey, new S3SecretValue(accessKey, secret));
    OMRequest writeRequest = OMRequest.newBuilder().setCmdType(OzoneManagerProtocolProtos.Type.CreateVolume).setVersion(CURRENT_VERSION).setClientId(UUID.randomUUID().toString()).setCreateVolumeRequest(CreateVolumeRequest.newBuilder().setVolumeInfo(VolumeInfo.newBuilder().setVolume(volumeName).setAdminName(accessKey).setOwnerName(accessKey).build()).build()).setS3Authentication(S3Authentication.newBuilder().setAccessId(accessKey).setSignature(signature).setStringToSign(strToSign)).build();
    GenericTestUtils.waitFor(() -> cluster.getOzoneManager().isLeaderReady(), 100, 120000);
    OMResponse omResponse = cluster.getOzoneManager().getOmServerProtocol().submitRequest(null, writeRequest);
    // Verify response.
    Assert.assertTrue(omResponse.getStatus() == Status.OK);
    // Read Request
    OMRequest readRequest = OMRequest.newBuilder().setCmdType(OzoneManagerProtocolProtos.Type.InfoVolume).setVersion(CURRENT_VERSION).setClientId(UUID.randomUUID().toString()).setInfoVolumeRequest(InfoVolumeRequest.newBuilder().setVolumeName(volumeName).build()).setS3Authentication(S3Authentication.newBuilder().setAccessId(accessKey).setSignature(signature).setStringToSign(strToSign)).build();
    omResponse = cluster.getOzoneManager().getOmServerProtocol().submitRequest(null, readRequest);
    // Verify response.
    Assert.assertTrue(omResponse.getStatus() == Status.OK);
    VolumeInfo volumeInfo = omResponse.getInfoVolumeResponse().getVolumeInfo();
    Assert.assertNotNull(volumeInfo);
    Assert.assertEquals(volumeName, volumeInfo.getVolume());
    Assert.assertEquals(accessKey, volumeInfo.getAdminName());
    Assert.assertEquals(accessKey, volumeInfo.getOwnerName());
    // Override secret to S3Secret table with some dummy value
    cluster.getOzoneManager().getMetadataManager().getS3SecretTable().put(accessKey, new S3SecretValue(accessKey, "dummy"));
    // Write request with invalid credentials.
    omResponse = cluster.getOzoneManager().getOmServerProtocol().submitRequest(null, writeRequest);
    Assert.assertTrue(omResponse.getStatus() == Status.INVALID_TOKEN);
    // Read request with invalid credentials.
    omResponse = cluster.getOzoneManager().getOmServerProtocol().submitRequest(null, readRequest);
    Assert.assertTrue(omResponse.getStatus() == Status.INVALID_TOKEN);
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) VolumeInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo) S3SecretValue(org.apache.hadoop.ozone.om.helpers.S3SecretValue) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) Test(org.junit.Test)

Example 3 with VolumeInfo

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo in project ozone by apache.

the class OzoneManagerProtocolClientSideTranslatorPB method createVolume.

/**
 * Creates a volume.
 *
 * @param args - Arguments to create Volume.
 * @throws IOException
 */
@Override
public void createVolume(OmVolumeArgs args) throws IOException {
    CreateVolumeRequest.Builder req = CreateVolumeRequest.newBuilder();
    VolumeInfo volumeInfo = args.getProtobuf();
    req.setVolumeInfo(volumeInfo);
    OMRequest omRequest = createOMRequest(Type.CreateVolume).setCreateVolumeRequest(req).build();
    OMResponse omResponse = submitRequest(omRequest);
    handleError(omResponse);
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) CreateVolumeRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateVolumeRequest) VolumeInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)

Example 4 with VolumeInfo

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo in project ozone by apache.

the class TestOMVolumeCreateRequest method testValidateAndUpdateCacheSuccess.

@Test
public void testValidateAndUpdateCacheSuccess() throws Exception {
    String volumeName = UUID.randomUUID().toString();
    String adminName = "user1";
    String ownerName = "user1";
    OMRequest originalRequest = createVolumeRequest(volumeName, adminName, ownerName);
    OMVolumeCreateRequest omVolumeCreateRequest = new OMVolumeCreateRequest(originalRequest);
    OMRequest modifiedRequest = omVolumeCreateRequest.preExecute(ozoneManager);
    String volumeKey = omMetadataManager.getVolumeKey(volumeName);
    String ownerKey = omMetadataManager.getUserKey(ownerName);
    // As we have not still called validateAndUpdateCache, get() should
    // return null.
    Assert.assertNull(omMetadataManager.getVolumeTable().get(volumeKey));
    Assert.assertNull(omMetadataManager.getUserTable().get(ownerKey));
    omVolumeCreateRequest = new OMVolumeCreateRequest(modifiedRequest);
    long txLogIndex = 2;
    long expectedObjId = ozoneManager.getObjectIdFromTxId(txLogIndex);
    OMClientResponse omClientResponse = omVolumeCreateRequest.validateAndUpdateCache(ozoneManager, txLogIndex, ozoneManagerDoubleBufferHelper);
    OzoneManagerProtocolProtos.OMResponse omResponse = omClientResponse.getOMResponse();
    Assert.assertNotNull(omResponse.getCreateVolumeResponse());
    Assert.assertEquals(OzoneManagerProtocolProtos.Status.OK, omResponse.getStatus());
    // Get volumeInfo from request.
    VolumeInfo volumeInfo = omVolumeCreateRequest.getOmRequest().getCreateVolumeRequest().getVolumeInfo();
    OmVolumeArgs omVolumeArgs = omMetadataManager.getVolumeTable().get(volumeKey);
    // As request is valid volume table should not have entry.
    Assert.assertNotNull(omVolumeArgs);
    Assert.assertEquals(expectedObjId, omVolumeArgs.getObjectID());
    Assert.assertEquals(txLogIndex, omVolumeArgs.getUpdateID());
    // Initial modificationTime should be equal to creationTime.
    long creationTime = omVolumeArgs.getCreationTime();
    long modificationTime = omVolumeArgs.getModificationTime();
    Assert.assertEquals(creationTime, modificationTime);
    // Check data from table and request.
    Assert.assertEquals(volumeInfo.getVolume(), omVolumeArgs.getVolume());
    Assert.assertEquals(volumeInfo.getOwnerName(), omVolumeArgs.getOwnerName());
    Assert.assertEquals(volumeInfo.getAdminName(), omVolumeArgs.getAdminName());
    Assert.assertEquals(volumeInfo.getCreationTime(), omVolumeArgs.getCreationTime());
    OzoneManagerStorageProtos.PersistedUserVolumeInfo userVolumeInfo = omMetadataManager.getUserTable().get(ownerKey);
    Assert.assertNotNull(userVolumeInfo);
    Assert.assertEquals(volumeName, userVolumeInfo.getVolumeNames(0));
    // Create another volume for the user.
    originalRequest = createVolumeRequest("vol1", adminName, ownerName);
    omVolumeCreateRequest = new OMVolumeCreateRequest(originalRequest);
    modifiedRequest = omVolumeCreateRequest.preExecute(ozoneManager);
    omClientResponse = omVolumeCreateRequest.validateAndUpdateCache(ozoneManager, 2L, ozoneManagerDoubleBufferHelper);
    Assert.assertEquals(OzoneManagerProtocolProtos.Status.OK, omClientResponse.getOMResponse().getStatus());
    Assert.assertTrue(omMetadataManager.getUserTable().get(ownerKey).getVolumeNamesList().size() == 2);
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) OzoneManagerStorageProtos(org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) VolumeInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo) Test(org.junit.Test)

Example 5 with VolumeInfo

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo in project ozone by apache.

the class TestOMVolumeCreateRequest method verifyRequest.

/**
 * Verify modifiedOmRequest and originalRequest.
 * @param modifiedRequest
 * @param originalRequest
 */
private void verifyRequest(OMRequest modifiedRequest, OMRequest originalRequest) {
    VolumeInfo original = originalRequest.getCreateVolumeRequest().getVolumeInfo();
    VolumeInfo updated = modifiedRequest.getCreateVolumeRequest().getVolumeInfo();
    Assert.assertEquals(original.getAdminName(), updated.getAdminName());
    Assert.assertEquals(original.getVolume(), updated.getVolume());
    Assert.assertEquals(original.getOwnerName(), updated.getOwnerName());
    Assert.assertNotEquals(original.getCreationTime(), updated.getCreationTime());
    Assert.assertNotEquals(original.getModificationTime(), updated.getModificationTime());
}
Also used : VolumeInfo(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo)

Aggregations

VolumeInfo (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.VolumeInfo)8 OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)4 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)3 CreateVolumeRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.CreateVolumeRequest)3 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)3 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)2 PersistedUserVolumeInfo (org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos.PersistedUserVolumeInfo)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)1 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)1 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)1 S3SecretValue (org.apache.hadoop.ozone.om.helpers.S3SecretValue)1 OMVolumeCreateResponse (org.apache.hadoop.ozone.om.response.volume.OMVolumeCreateResponse)1 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)1 ListVolumeResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ListVolumeResponse)1 OzoneManagerStorageProtos (org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos)1