Commit 5c8a037e authored by Aman Verma's avatar Aman Verma Committed by Kishore Battula
Browse files

consuming new methods defined in BlobStore class

parent 4f761651
......@@ -50,6 +50,7 @@ az keyvault secret show --vault-name $KEY_VAULT_NAME --name $KEY_VAULT_SECRET_NA
| `AZURE_CLIENT_ID` | `********` | Identity to run the service locally. This enables access to Azure resources. You only need this if running locally | yes | keyvault secret: `$KEYVAULT_URI/secrets/app-dev-sp-username` |
| `AZURE_TENANT_ID` | `********` | AD tenant to authenticate users from | yes | keyvault secret: `$KEYVAULT_URI/secrets/app-dev-sp-tenant-id` |
| `AZURE_CLIENT_SECRET` | `********` | Secret for `$AZURE_CLIENT_ID` | yes | keyvault secret: `$KEYVAULT_URI/secrets/app-dev-sp-password` |
| `server.port` | ex `8085` | port for schema service | no | -- |
**Required to run integration tests**
......
......@@ -40,7 +40,7 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>0.0.17</version>
<version>0.0.23</version>
</dependency>
<dependency>
......
......@@ -28,6 +28,9 @@ public class AzureBootstrapConfig {
@Value("${azure.storage.account-name}")
private String storageAccount;
@Value("${azure.storage.container-name}")
private String storageContainer;
@Value("${azure.keyvault.url}")
private String keyVaultURL;
......@@ -43,7 +46,7 @@ public class AzureBootstrapConfig {
@Bean
@Named("STORAGE_CONTAINER_NAME")
public String containerName() {
return "opendes";
return storageContainer;
}
@Bean
......
......@@ -17,6 +17,7 @@ package org.opengroup.osdu.schema.azure.impl.schemastore;
import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.NotFoundException;
......@@ -38,6 +39,9 @@ public class AzureSchemaStore implements ISchemaStore {
@Autowired
private BlobStore blobStore;
@Autowired
private AzureBootstrapConfig config;
@Autowired
JaxRsDpsLog log;
......@@ -55,7 +59,7 @@ public class AzureSchemaStore implements ISchemaStore {
public String getSchema(String dataPartitionId, String filePath) throws ApplicationException, NotFoundException {
filePath = dataPartitionId + ":" + filePath + SchemaConstants.JSON_EXTENSION;
try {
String content = blobStore.readFromBlob(dataPartitionId, filePath);
String content = blobStore.readFromStorageContainer(dataPartitionId, filePath, config.containerName());
if (content != null)
return content;
else
......@@ -81,7 +85,7 @@ public class AzureSchemaStore implements ISchemaStore {
filePath = dataPartitionId + ":" + filePath + SchemaConstants.JSON_EXTENSION;
try {
blobStore.writeToBlob(dataPartitionId, filePath, content);
blobStore.writeToStorageContainer(dataPartitionId, filePath, content, config.containerName());
return filePath;
} catch (Exception ex) {
throw new ApplicationException(SchemaConstants.INTERNAL_SERVER_ERROR);
......@@ -101,7 +105,7 @@ public class AzureSchemaStore implements ISchemaStore {
try
{
return blobStore.deleteFromBlob(dataPartitionId, filePath);
return blobStore.deleteFromStorageContainer(dataPartitionId, filePath, config.containerName());
}
catch (Exception e)
{
......
......@@ -30,6 +30,7 @@ azure.cosmosdb.database=${cosmosdb_database}
# Azure Blob Storage configuration
azure.storage.account-name=${storage_account}
azure.storage.container-name=opendes
azure.storage.enable-https=true
#Azure App Insights configuration
......@@ -43,7 +44,7 @@ entity-type.container.name=EntityType
schema-info.container.name=SchemaInfo
source.container.name=Source
tenantInfo.container.name=TenantInfo
server.port=8080
server.port=${server.port}
#logging configuration
logging.transaction.enabled=true
......
......@@ -25,6 +25,7 @@ import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.schema.azure.impl.schemastore.AzureSchemaStore;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
......@@ -40,6 +41,9 @@ public class AzureSchemaStoreTest {
@Mock
BlobStore blobStore;
@Mock
AzureBootstrapConfig config;
@Mock
DpsHeaders headers;
......@@ -52,17 +56,19 @@ public class AzureSchemaStoreTest {
private static final String dataPartitionId = "dataPartitionId";
private static final String FILE_PATH = "/test-folder/test-file";
private static final String CONTENT = "Hello World";
private static final String containerName = "opendes";
private static final String filePath = dataPartitionId + ":" + FILE_PATH + SchemaConstants.JSON_EXTENSION;
@Before
public void init(){
initMocks(this);
doReturn(dataPartitionId).when(headers).getPartitionId();
when(config.containerName()).thenReturn(containerName);
}
@Test
public void testGetSchema() throws ApplicationException, NotFoundException {
doReturn(CONTENT).when(blobStore).readFromBlob(dataPartitionId, filePath);
doReturn(CONTENT).when(blobStore).readFromStorageContainer(dataPartitionId, filePath, containerName);
Assert.assertEquals(CONTENT, schemaStore.getSchema(dataPartitionId, FILE_PATH));
}
......@@ -70,7 +76,7 @@ public class AzureSchemaStoreTest {
public void testGetSchema_NotFound() throws ApplicationException, NotFoundException {
expectedException.expect(NotFoundException.class);
expectedException.expectMessage(SchemaConstants.SCHEMA_NOT_PRESENT);
doReturn(null).when(blobStore).readFromBlob(dataPartitionId, filePath);
doReturn(null).when(blobStore).readFromStorageContainer(dataPartitionId, filePath, containerName);
schemaStore.getSchema(dataPartitionId, FILE_PATH);
}
......@@ -79,13 +85,13 @@ public class AzureSchemaStoreTest {
expectedException.expect(NotFoundException.class);
expectedException.expectMessage(SchemaConstants.SCHEMA_NOT_PRESENT);
doThrow(AppException.class).when(blobStore).readFromBlob(dataPartitionId, filePath);
doThrow(AppException.class).when(blobStore).readFromStorageContainer(dataPartitionId, filePath, containerName);
schemaStore.getSchema(dataPartitionId, FILE_PATH);
}
@Test
public void testDeleteSchema() throws ApplicationException {
doReturn(true).when(blobStore).deleteFromBlob(dataPartitionId, filePath);
doReturn(true).when(blobStore).deleteFromStorageContainer(dataPartitionId, filePath, containerName);
Boolean result = schemaStore.cleanSchemaProject(FILE_PATH);
Assert.assertEquals(true, result);
......@@ -96,14 +102,14 @@ public class AzureSchemaStoreTest {
expectedException.expect(ApplicationException.class);
expectedException.expectMessage(SchemaConstants.INTERNAL_SERVER_ERROR);
doThrow(AppException.class).when(blobStore).deleteFromBlob(dataPartitionId, filePath);
doThrow(AppException.class).when(blobStore).deleteFromStorageContainer(dataPartitionId, filePath, containerName);
schemaStore.cleanSchemaProject(FILE_PATH);
}
@Test
public void testCreateSchema() throws ApplicationException {
doNothing().when(blobStore).writeToBlob(dataPartitionId, filePath, CONTENT);
doNothing().when(blobStore).writeToStorageContainer(dataPartitionId, filePath, CONTENT, containerName);
Assert.assertEquals(filePath, schemaStore.createSchema(FILE_PATH, CONTENT));
}
......@@ -112,7 +118,7 @@ public class AzureSchemaStoreTest {
expectedException.expect(ApplicationException.class);
expectedException.expectMessage(SchemaConstants.INTERNAL_SERVER_ERROR);
doThrow(AppException.class).when(blobStore).writeToBlob(dataPartitionId, filePath, CONTENT);
doThrow(AppException.class).when(blobStore).writeToStorageContainer(dataPartitionId, filePath, CONTENT, containerName);
schemaStore.createSchema(FILE_PATH, CONTENT);
}
}
Markdown is supported
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