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