Commit 2a80c27a authored by Artem Dobrynin (EPAM)'s avatar Artem Dobrynin (EPAM)
Browse files

Bugfix: Storage Exception is not being processed by Schema

* Added Storage Exception
parent cd922bee
Pipeline #103721 passed with stages
in 64 minutes and 24 seconds
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.opengroup.osdu.schema.impl.schemastore; package org.opengroup.osdu.schema.impl.schemastore;
import com.google.cloud.storage.StorageException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
...@@ -33,6 +34,7 @@ import org.opengroup.osdu.schema.exceptions.NotFoundException; ...@@ -33,6 +34,7 @@ import org.opengroup.osdu.schema.exceptions.NotFoundException;
import org.opengroup.osdu.schema.impl.mapper.AbstractMapperRepository; import org.opengroup.osdu.schema.impl.mapper.AbstractMapperRepository;
import org.opengroup.osdu.schema.provider.interfaces.schemastore.ISchemaStore; import org.opengroup.osdu.schema.provider.interfaces.schemastore.ISchemaStore;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
...@@ -77,8 +79,8 @@ public class ObmSchemaStore extends AbstractMapperRepository<String, ObmDestinat ...@@ -77,8 +79,8 @@ public class ObmSchemaStore extends AbstractMapperRepository<String, ObmDestinat
try { try {
blob = driver.getBlobContent(bucketName, filePath, getDestination()); blob = driver.getBlobContent(bucketName, filePath, getDestination());
} catch (ObmDriverRuntimeException | NullPointerException ex){ } catch (ObmDriverRuntimeException | NullPointerException ex){
if (ex instanceof NullPointerException if (isNotFoundException(ex)){
|| NO_SUCH_KEY.equals(((ObmDriverRuntimeException)ex.getCause()).getError())){ log.warning(ex.getMessage());
throw new NotFoundException(SchemaConstants.SCHEMA_NOT_PRESENT); throw new NotFoundException(SchemaConstants.SCHEMA_NOT_PRESENT);
} }
else { else {
...@@ -92,6 +94,25 @@ public class ObmSchemaStore extends AbstractMapperRepository<String, ObmDestinat ...@@ -92,6 +94,25 @@ public class ObmSchemaStore extends AbstractMapperRepository<String, ObmDestinat
throw new NotFoundException(SchemaConstants.SCHEMA_NOT_PRESENT); throw new NotFoundException(SchemaConstants.SCHEMA_NOT_PRESENT);
} }
private boolean isNotFoundException(RuntimeException ex) {
if (ex instanceof NullPointerException){
return true;
}
ObmDriverRuntimeException obmException = (ObmDriverRuntimeException) ex;
if (obmException.getCause() instanceof ObmDriverRuntimeException){
ObmDriverRuntimeException cause = (ObmDriverRuntimeException) obmException.getCause();
return NO_SUCH_KEY.equals(cause.getError());
}
if (obmException.getCause() instanceof StorageException){
return HttpStatus.NOT_FOUND.value() == (((StorageException) obmException.getCause()).getCode());
}
return false;
}
/** /**
* Method to get System schema from Blob Storage * Method to get System schema from Blob Storage
* @param filePath * @param filePath
......
package org.opengroup.osdu.schema.impl.schemastore; package org.opengroup.osdu.schema.impl.schemastore;
import com.google.cloud.storage.StorageException;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -163,6 +164,20 @@ public class ObmSchemaStoreTest { ...@@ -163,6 +164,20 @@ public class ObmSchemaStoreTest {
schemaStore.getSchema(dataPartitionId, FILE_PATH); schemaStore.getSchema(dataPartitionId, FILE_PATH);
} }
@Test
public void testGetSchema_NotFound_StorageException() throws ApplicationException, NotFoundException {
expectedException.expect(NotFoundException.class);
expectedException.expectMessage(SchemaConstants.SCHEMA_NOT_PRESENT);
String filePath = FILE_PATH + SchemaConstants.JSON_EXTENSION;
ObmDriverRuntimeException obmDriverRuntimeException = new ObmDriverRuntimeException(new StorageException(404, "test"));
when(tenantFactory.getTenantInfo(dataPartitionId)).thenReturn(TenantInfo);
when(TenantInfo.getProjectId()).thenReturn("test");
when(driver.getBlobContent(BUCKET, filePath, DESTINATION)).thenThrow(obmDriverRuntimeException);
schemaStore.getSchema(dataPartitionId, FILE_PATH);
}
@Test @Test
public void testGetSchema_NotFound_SystemSchemas() throws ApplicationException, NotFoundException { public void testGetSchema_NotFound_SystemSchemas() throws ApplicationException, NotFoundException {
expectedException.expect(NotFoundException.class); expectedException.expect(NotFoundException.class);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment