Search in sources :

Example 1 with OMClientRequest

use of org.apache.hadoop.ozone.om.request.OMClientRequest in project ozone by apache.

the class TestOzoneManagerRatisRequest method testRequestWithNonExistentBucket.

@Test(timeout = 300_000)
public void testRequestWithNonExistentBucket() throws Exception {
    ozoneManager = Mockito.mock(OzoneManager.class);
    ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
    omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
    when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
    String volumeName = "vol1";
    String bucketName = "invalidBuck";
    OzoneManagerProtocolProtos.OMRequest omRequest = OMRequestTestUtils.createCompleteMPURequest(volumeName, bucketName, "mpuKey", "mpuKeyID", new ArrayList<>());
    OMClientRequest req = OzoneManagerRatisUtils.createClientRequest(omRequest, ozoneManager);
    Assert.assertNotNull(req);
    Assert.assertTrue("Unexpected request on invalid bucket", req instanceof S3MultipartUploadCompleteRequest);
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) S3MultipartUploadCompleteRequest(org.apache.hadoop.ozone.om.request.s3.multipart.S3MultipartUploadCompleteRequest) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) Test(org.junit.Test)

Example 2 with OMClientRequest

use of org.apache.hadoop.ozone.om.request.OMClientRequest in project ozone by apache.

the class OzoneManagerProtocolServerSideTranslatorPB method processRequest.

private OMResponse processRequest(OMRequest request) throws ServiceException {
    if (isRatisEnabled) {
        boolean s3Auth = false;
        try {
            // if current OM is leader and then proceed with processing the request.
            if (request.hasS3Authentication()) {
                s3Auth = true;
                checkLeaderStatus();
                S3SecurityUtil.validateS3Credential(request, ozoneManager);
            }
        } catch (IOException ex) {
            // If validate credentials fail return error OM Response.
            return createErrorResponse(request, ex);
        }
        // Check if the request is a read only request
        if (OmUtils.isReadOnly(request)) {
            try {
                if (request.hasS3Authentication()) {
                    ozoneManager.setS3Auth(request.getS3Authentication());
                }
                return submitReadRequestToOM(request);
            } finally {
                ozoneManager.setS3Auth(null);
            }
        } else {
            // This will skip of checking leader status again if request has S3Auth.
            if (!s3Auth) {
                checkLeaderStatus();
            }
            try {
                OMClientRequest omClientRequest = createClientRequest(request, ozoneManager);
                request = omClientRequest.preExecute(ozoneManager);
            } catch (IOException ex) {
                // As some of the preExecute returns error. So handle here.
                return createErrorResponse(request, ex);
            }
            return submitRequestToRatis(request);
        }
    } else {
        return submitRequestDirectlyToOM(request);
    }
}
Also used : OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) IOException(java.io.IOException)

Example 3 with OMClientRequest

use of org.apache.hadoop.ozone.om.request.OMClientRequest in project ozone by apache.

the class TestOMVersionManager method testAllOMRequestClassesHaveRequestType.

@Ignore("Since there is no longer a need to enforce the getRequestType " + "method in OM request classes, disabling the " + "test. Potentially revisit later.")
@Test
public void testAllOMRequestClassesHaveRequestType() throws InvocationTargetException, IllegalAccessException {
    Set<Class<? extends OMClientRequest>> requestClasses = getRequestClasses(OM_REQUEST_CLASS_PACKAGE);
    Set<String> requestTypes = new HashSet<>();
    for (Class<? extends OMClientRequest> requestClass : requestClasses) {
        try {
            Method getRequestTypeMethod = requestClass.getMethod("getRequestType");
            String type = (String) getRequestTypeMethod.invoke(null);
            int lVersion = INITIAL_VERSION.layoutVersion();
            BelongsToLayoutVersion annotation = requestClass.getAnnotation(BelongsToLayoutVersion.class);
            if (annotation != null) {
                lVersion = annotation.value().layoutVersion();
            }
            if (requestTypes.contains(type + "-" + lVersion)) {
                Assert.fail("Duplicate request/version type found : " + type);
            }
            requestTypes.add(type + "-" + lVersion);
        } catch (NoSuchMethodException nsmEx) {
            Assert.fail("getRequestType method not defined in a class." + nsmEx.getMessage());
        }
    }
}
Also used : OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.doCallRealMethod(org.mockito.Mockito.doCallRealMethod) Method(java.lang.reflect.Method) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with OMClientRequest

use of org.apache.hadoop.ozone.om.request.OMClientRequest in project ozone by apache.

the class TestOmVersionManagerRequestFactory method testAllOMRequestClassesHaveGetRequestTypeMethod.

@Test
public void testAllOMRequestClassesHaveGetRequestTypeMethod() throws Exception {
    Reflections reflections = new Reflections("org.apache.hadoop.ozone.om.request");
    Set<Class<? extends OMClientRequest>> subTypes = reflections.getSubTypesOf(OMClientRequest.class);
    List<Class<? extends OMClientRequest>> collect = subTypes.stream().filter(c -> !Modifier.isAbstract(c.getModifiers())).collect(Collectors.toList());
    for (Class<? extends OMClientRequest> c : collect) {
        Method getRequestTypeMethod = null;
        try {
            getRequestTypeMethod = c.getMethod("getRequestType");
        } catch (NoSuchMethodException nsmEx) {
            Assert.fail(String.format("%s does not have the 'getRequestType' method " + "which should be defined or inherited for every OM request class.", c));
        }
        String type = (String) getRequestTypeMethod.invoke(null);
        Assert.assertNotNull(String.format("Cannot get handler for %s", type), omVersionManager.getHandler(type));
    }
}
Also used : OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) BeforeClass(org.junit.BeforeClass) Set(java.util.Set) OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) Test(org.junit.Test) Reflections(org.reflections.Reflections) Constructor(java.lang.reflect.Constructor) Collectors(java.util.stream.Collectors) List(java.util.List) OMKeyCreateRequest(org.apache.hadoop.ozone.om.request.key.OMKeyCreateRequest) Ignore(org.junit.Ignore) CreateKey(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.Type.CreateKey) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) Modifier(java.lang.reflect.Modifier) OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) Assert(org.junit.Assert) Method(java.lang.reflect.Method) BeforeClass(org.junit.BeforeClass) Method(java.lang.reflect.Method) Reflections(org.reflections.Reflections) Test(org.junit.Test)

Example 5 with OMClientRequest

use of org.apache.hadoop.ozone.om.request.OMClientRequest in project ozone by apache.

the class TrashOzoneFileSystem method submitRequest.

private void submitRequest(OzoneManagerProtocolProtos.OMRequest omRequest) throws Exception {
    ozoneManager.getMetrics().incNumTrashWriteRequests();
    if (ozoneManager.isRatisEnabled()) {
        OMClientRequest omClientRequest = OzoneManagerRatisUtils.createClientRequest(omRequest, ozoneManager);
        omRequest = omClientRequest.preExecute(ozoneManager);
        RaftClientRequest req = getRatisRequest(omRequest);
        ozoneManager.getOmRatisServer().submitRequest(omRequest, req);
    } else {
        ozoneManager.getOmServerProtocol().submitRequest(NULL_RPC_CONTROLLER, omRequest);
    }
}
Also used : OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) RaftClientRequest(org.apache.ratis.protocol.RaftClientRequest)

Aggregations

OMClientRequest (org.apache.hadoop.ozone.om.request.OMClientRequest)9 Test (org.junit.Test)4 Method (java.lang.reflect.Method)3 Reflections (org.reflections.Reflections)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)2 BeforeClass (org.junit.BeforeClass)2 Ignore (org.junit.Ignore)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Constructor (java.lang.reflect.Constructor)1 Modifier (java.lang.reflect.Modifier)1 List (java.util.List)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 OmMetadataManagerImpl (org.apache.hadoop.ozone.om.OmMetadataManagerImpl)1 OzoneManager (org.apache.hadoop.ozone.om.OzoneManager)1 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)1 OMKeyCreateRequest (org.apache.hadoop.ozone.om.request.key.OMKeyCreateRequest)1