Commit 333011be authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Merge branch 'gcp/bugfix/storage_exception_processing' into 'master'

Bugfix: Storage Exception is not being processed by Schema

See merge request !273
parents cd922bee 2a80c27a
Pipeline #105305 failed with stages
in 10 seconds
......@@ -17,6 +17,7 @@
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.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
......@@ -33,6 +34,7 @@ import org.opengroup.osdu.schema.exceptions.NotFoundException;
import org.opengroup.osdu.schema.impl.mapper.AbstractMapperRepository;
import org.opengroup.osdu.schema.provider.interfaces.schemastore.ISchemaStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Repository;
import java.nio.charset.StandardCharsets;
......@@ -77,8 +79,8 @@ public class ObmSchemaStore extends AbstractMapperRepository<String, ObmDestinat
try {
blob = driver.getBlobContent(bucketName, filePath, getDestination());
} catch (ObmDriverRuntimeException | NullPointerException ex){
if (ex instanceof NullPointerException
|| NO_SUCH_KEY.equals(((ObmDriverRuntimeException)ex.getCause()).getError())){
if (isNotFoundException(ex)){
log.warning(ex.getMessage());
throw new NotFoundException(SchemaConstants.SCHEMA_NOT_PRESENT);
}
else {
......@@ -92,6 +94,25 @@ public class ObmSchemaStore extends AbstractMapperRepository<String, ObmDestinat
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
* @param filePath
......
package org.opengroup.osdu.schema.impl.schemastore;
import com.google.cloud.storage.StorageException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -163,6 +164,20 @@ public class ObmSchemaStoreTest {
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
public void testGetSchema_NotFound_SystemSchemas() throws ApplicationException, NotFoundException {
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