Skip to content
Snippets Groups Projects
Commit a1f12be4 authored by Abhishek Patil's avatar Abhishek Patil Committed by Kishore Battula
Browse files

Code refactoring for using BlobStore

parent 5c805c30
No related branches found
No related tags found
No related merge requests found
......@@ -17,20 +17,17 @@ package org.opengroup.osdu.legal.azure.countries;
import javax.inject.Inject;
import javax.inject.Named;
import org.opengroup.osdu.azure.blobstorage.IBlobContainerClientFactory;
import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReader;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReaderFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class StorageReaderFactoryImpl implements IStorageReaderFactory {
@Inject
private IBlobContainerClientFactory blobContainerClientFactory;
@Inject
private DpsHeaders headers;
......@@ -38,11 +35,11 @@ public class StorageReaderFactoryImpl implements IStorageReaderFactory {
@Named("STORAGE_CONTAINER_NAME")
private String containerName;
@Inject
private JaxRsDpsLog logger;
@Autowired
private BlobStore blobStore;
@Override
public IStorageReader getReader(TenantInfo tenant, String projectRegion) {
return new StorageReaderImpl(tenant, projectRegion, blobContainerClientFactory.getClient(headers.getPartitionId(), containerName), logger);
return new StorageReaderImpl(headers.getPartitionId(), containerName, blobStore);
}
}
......@@ -14,57 +14,29 @@
package org.opengroup.osdu.legal.azure.countries;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.specialized.BlockBlobClient;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.azure.blobstorage.BlobStore;
import org.opengroup.osdu.legal.provider.interfaces.IStorageReader;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
public class StorageReaderImpl implements IStorageReader {
private final TenantInfo tenantInfo;
private final String cloudRegion;
private BlobContainerClient blobContainerClient;
private JaxRsDpsLog logger;
private final BlobStore blobStore;
private final String dataPartitionId;
private final String containerName;
private static final String fileName = "Legal_COO.json";
public StorageReaderImpl(TenantInfo tenantInfo, String cloudRegion, BlobContainerClient blobContainerClient, JaxRsDpsLog logger) {
this.tenantInfo = tenantInfo;
this.cloudRegion = cloudRegion;
this.blobContainerClient = blobContainerClient;
this.logger = logger;
public StorageReaderImpl(String dataPartitionId, String containerName, BlobStore blobStore) {
this.dataPartitionId = dataPartitionId;
this.containerName = containerName;
this.blobStore = blobStore;
}
@Override
public byte[] readAllBytes() {
return readFromBlobStorage().getBytes(StandardCharsets.UTF_8); //should return a json format of an array of Country class
return blobStore.readFromStorageContainer(dataPartitionId, fileName, containerName).getBytes(StandardCharsets.UTF_8); //should return a json format of an array of Country class
}
/**
* This function should be fail close. It reads the pre-configuration file for the partition. As a security requirement, we should
* fail the corresponding request instead of assuming the content is empty, but it should only fail close on the request level not
* service level meaning the service could still start and running probably for the APIs which do not need the pre-configuration file
*/
public String readFromBlobStorage() {
BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(fileName).getBlockBlobClient();
if (blockBlobClient.exists())
{
try (ByteArrayOutputStream downloadStream = new ByteArrayOutputStream()) {
blockBlobClient.download(downloadStream);
String content = downloadStream.toString(StandardCharsets.UTF_8.name());
return content;
} catch (Exception e) {
String message = String.format("read %s failed", fileName);
throw new AppException(500, "Server error", message);
}
} else {
String message = String.format("%s does not exist on partition %s", fileName, tenantInfo.getDataPartitionId());
throw new AppException(500, "Server error", message);
}
}
}
\ No newline at end of file
......@@ -42,6 +42,7 @@ azure.cosmosdb.legal.collection=LegalTag
# Azure Blob Storage configuration
azure.storage.container-name=legal-service-azure-configuration
azure.storage.enable-https=true
azure.blobStore.required=true
# Azure Service Bus configuration
azure.servicebus.topic-name=${servicebus_topic_name}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment