Commit 2653abd0 authored by Ronak Sakhuja's avatar Ronak Sakhuja
Browse files

refactor code

parent 0c1dd6cd
Pipeline #42139 failed with stage
in 1 minute and 49 seconds
......@@ -17,9 +17,7 @@ package org.opengroup.osdu.azure.blobstorage;
import com.azure.identity.DefaultAzureCredential;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobContainerClientBuilder;
import com.azure.storage.common.policy.RequestRetryOptions;
import org.opengroup.osdu.azure.cache.BlobContainerClientCache;
import org.opengroup.osdu.azure.di.BlobStorageRetryConfiguration;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.common.Validators;
......@@ -43,9 +41,6 @@ public class BlobContainerClientFactoryImpl implements IBlobContainerClientFacto
@Autowired
private BlobContainerClientCache clientCache;
@Autowired
private BlobStorageRetryConfiguration blobStorageRetryConfiguration;
/**
* @param dataPartitionId Data partition id
* @param containerName Blob container name
......@@ -65,13 +60,10 @@ public class BlobContainerClientFactoryImpl implements IBlobContainerClientFacto
PartitionInfoAzure pi = this.partitionService.getPartition(dataPartitionId);
String endpoint = String.format("https://%s.blob.core.windows.net", pi.getStorageAccountName());
RequestRetryOptions requestRetryOptions = blobStorageRetryConfiguration.getRequestRetryOptions();
BlobContainerClient blobContainerClient = new BlobContainerClientBuilder()
.endpoint(endpoint)
.credential(defaultAzureCredential)
.containerName(containerName)
.retryOptions(requestRetryOptions)
.buildClient();
this.clientCache.put(cacheKey, blobContainerClient);
......
......@@ -17,10 +17,13 @@ package org.opengroup.osdu.azure.blobstorage;
import com.azure.identity.DefaultAzureCredential;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
import com.azure.storage.common.policy.RequestRetryOptions;
import org.opengroup.osdu.azure.cache.BlobServiceClientCache;
import org.opengroup.osdu.azure.di.BlobStoreRetryConfiguration;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.common.Validators;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Implementation for IBlobServiceClientFactory.
......@@ -30,6 +33,9 @@ public class BlobServiceClientFactoryImpl implements IBlobServiceClientFactory {
private PartitionServiceClient partitionService;
private BlobServiceClientCache clientCache;
@Autowired
private BlobStoreRetryConfiguration blobStoreRetryConfiguration;
/**
* Constructor to initialize instance of {@link BlobServiceClientFactoryImpl}.
* @param credentials Azure Credentials to use
......@@ -61,9 +67,12 @@ public class BlobServiceClientFactoryImpl implements IBlobServiceClientFactory {
PartitionInfoAzure pi = this.partitionService.getPartition(dataPartitionId);
String endpoint = String.format("https://%s.blob.core.windows.net", pi.getStorageAccountName());
RequestRetryOptions requestRetryOptions = blobStoreRetryConfiguration.getRequestRetryOptions();
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(endpoint)
.credential(defaultAzureCredential)
.retryOptions(requestRetryOptions)
.buildClient();
this.clientCache.put(cacheKey, blobServiceClient);
......
......@@ -28,11 +28,11 @@ import java.time.Duration;
* Config for BlogStorage Retry.
*/
@Configuration
@ConfigurationProperties("azure.blobstorage")
@ConfigurationProperties("azure.blobStore")
@Getter
@Setter
public class BlobStorageRetryConfiguration {
private static final String LOGGER_NAME = BlobStorageRetryConfiguration.class.getName();
public class BlobStoreRetryConfiguration {
private static final String LOGGER_NAME = BlobStoreRetryConfiguration.class.getName();
private int maxTries = -1;
private int tryTimeoutInSeconds = -1;
......
......@@ -10,7 +10,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.azure.cache.BlobContainerClientCache;
import org.opengroup.osdu.azure.di.BlobStorageRetryConfiguration;
import org.opengroup.osdu.azure.di.BlobStoreRetryConfiguration;
import org.opengroup.osdu.azure.di.BlobStoreConfiguration;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
......@@ -32,7 +32,7 @@ public class BlobContainerClientFactoryImplTest {
@Mock
private BlobStoreConfiguration configuration;
@Mock
private BlobStorageRetryConfiguration blobStorageRetryConfiguration;
private BlobStoreRetryConfiguration blobStoreRetryConfiguration;
@InjectMocks
private BlobContainerClientFactoryImpl sut;
......@@ -75,7 +75,7 @@ public class BlobContainerClientFactoryImplTest {
PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build());
when(this.blobStorageRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
when(this.blobStoreRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
BlobContainerClient containerClient = this.sut.getClient(PARTITION_ID, STORAGE_CONTAINER_NAME);
assertNotNull(containerClient);
}
......@@ -86,7 +86,7 @@ public class BlobContainerClientFactoryImplTest {
PartitionInfoAzure.builder()
.idConfig(Property.builder().value(PARTITION_ID).build())
.storageAccountNameConfig(Property.builder().value(ACCOUNT_NAME).build()).build());
when(this.blobStorageRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
when(this.blobStoreRetryConfiguration.getRequestRetryOptions()).thenReturn(new RequestRetryOptions());
BlobContainerClient containerClient = this.sut.getClient(PARTITION_ID, STORAGE_CONTAINER_NAME);
assertNotNull(containerClient);
......
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