Commit 88cd2161 authored by Kishore Battula's avatar Kishore Battula
Browse files

Merge branch 'new-workflow-apis' into h2-ingestion

parents 1061d4f7 2b372acd
Pipeline #16244 failed with stages
in 4 minutes and 4 seconds
package org.opengroup.osdu.workflow.provider.azure.fileshare;
import com.azure.storage.file.share.ShareClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class FileShareClientFactory implements IFileShareClientFactory {
@Autowired
private ShareClient client;
@Override
public ShareClient getClient() {
return this.client;
}
}
...@@ -11,4 +11,5 @@ import org.springframework.context.annotation.Configuration; ...@@ -11,4 +11,5 @@ import org.springframework.context.annotation.Configuration;
@Setter @Setter
public class FileShareConfig { public class FileShareConfig {
private String shareName; private String shareName;
private String dagsFolder;
} }
package org.opengroup.osdu.workflow.provider.azure.fileshare; package org.opengroup.osdu.workflow.provider.azure.fileshare;
import com.azure.storage.file.share.ShareClient; import com.azure.storage.file.share.ShareDirectoryClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@Component
public class FileShareStore { public class FileShareStore {
@Autowired private ShareDirectoryClient directoryClient;
private IFileShareClientFactory fileShareClientFactory; public FileShareStore(final ShareDirectoryClient directoryClient) {
this.directoryClient = directoryClient;
}
public void createFile(final String contents, final String name) { public void createFile(final String contents, final String name) {
getShareClient().createFile(name, contents.getBytes().length) directoryClient.createFile(name, contents.getBytes().length)
.upload(new ByteArrayInputStream(contents.getBytes()), contents.getBytes().length); .upload(new ByteArrayInputStream(contents.getBytes()), contents.getBytes().length);
} }
private ShareClient getShareClient() {
return this.fileShareClientFactory.getClient();
}
} }
package org.opengroup.osdu.workflow.provider.azure.fileshare;
import com.azure.storage.file.share.ShareClient;
import com.azure.storage.file.share.ShareDirectoryClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FileShareStoreProvider {
@Bean
@Qualifier("dags")
public FileShareStore buildDagsStore(ShareClient shareClient, FileShareConfig config) {
ShareDirectoryClient client = shareClient.getDirectoryClient(config.getDagsFolder());
return new FileShareStore(client);
}
}
package org.opengroup.osdu.workflow.provider.azure.fileshare;
import com.azure.storage.file.share.ShareClient;
public interface IFileShareClientFactory {
ShareClient getClient();
}
...@@ -3,11 +3,13 @@ package org.opengroup.osdu.workflow.provider.azure.repository; ...@@ -3,11 +3,13 @@ package org.opengroup.osdu.workflow.provider.azure.repository;
import org.opengroup.osdu.workflow.provider.azure.fileshare.FileShareStore; import org.opengroup.osdu.workflow.provider.azure.fileshare.FileShareStore;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowDefinitionRepository; import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowDefinitionRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class WorkflowDefinitionRepository implements IWorkflowDefinitionRepository { public class WorkflowDefinitionRepository implements IWorkflowDefinitionRepository {
@Autowired @Autowired
@Qualifier("dags")
private FileShareStore fileShareStore; private FileShareStore fileShareStore;
@Override @Override
......
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
# limitations under the License. # limitations under the License.
# Application name # Application name
spring.application.name=workflow spring.application.name=workflow-azure
LOG_PREFIX=workflow LOG_PREFIX=workflow
# Server Path Configuration # Server Path Configuration
server.servlet.contextPath=/api/workflow/v1/ server.servlet.contextPath=/api/workflow/v1/
# Istio Auth Config Toggle # Istio Auth Config Toggle
azure.istio.auth.enabled=${azure_istioauth_enabled} azure.istio.auth.enabled=${azure_istioauth_enabled}
# Partition service # Partition service
...@@ -41,13 +41,13 @@ osdu.azure.cosmosdb.workflowRunCollection=WorkflowRun ...@@ -41,13 +41,13 @@ osdu.azure.cosmosdb.workflowRunCollection=WorkflowRun
# Azure fileshare configuration # Azure fileshare configuration
osdu.azure.fileshare.shareName=airflowdags osdu.azure.fileshare.shareName=airflowdags
osdu.azure.fileshare.dagsFolder=dags
# Azure KeyVault configuration # Azure KeyVault configuration
azure.keyvault.url=${KEYVAULT_URI} azure.keyvault.url=${KEYVAULT_URI}
# Azure App Insights configuration # Azure App Insights configuration
azure.application-insights.instrumentation-key=${appinsights_key} azure.application-insights.instrumentation-key=${appinsights_key}
spring.application.name=workflow-azure
# Airflow configuration # Airflow configuration
osdu.azure.airflow.url=${airflow_url} osdu.azure.airflow.url=${airflow_url}
......
package org.opengroup.osdu.workflow.provider.azure.fileshare; package org.opengroup.osdu.workflow.provider.azure.fileshare;
import com.azure.storage.file.share.ShareClient; import com.azure.storage.file.share.ShareClient;
import com.azure.storage.file.share.ShareDirectoryClient;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** /**
* Tests for {@link FileShareClientFactory} * Tests for {@link FileShareStoreProvider}
*/ */
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class FileShareClientFactoryTest { public class FileShareStoreProviderTest {
private static final String DAGS_FOLDER = "dagsTest";
@Mock @Mock
private ShareClient shareClient; private ShareClient shareClient;
@Mock
private FileShareConfig config;
@Mock
private ShareDirectoryClient directoryClient;
@InjectMocks @InjectMocks
private FileShareClientFactory fileShareClientFactory; private FileShareStoreProvider fileShareStoreProvider;
@Test @Test
public void testGetClient() { public void testBuildDagsStore() {
assertThat(fileShareClientFactory.getClient(), equalTo(shareClient)); when(config.getDagsFolder()).thenReturn(DAGS_FOLDER);
} when(shareClient.getDirectoryClient(eq(DAGS_FOLDER))).thenReturn(directoryClient);
fileShareStoreProvider.buildDagsStore(shareClient, config);
verify(config).getDagsFolder();
verify(shareClient).getDirectoryClient(eq(DAGS_FOLDER));
}
} }
package org.opengroup.osdu.workflow.provider.azure.fileshare; package org.opengroup.osdu.workflow.provider.azure.fileshare;
import com.azure.storage.file.share.ShareClient; import com.azure.storage.file.share.ShareClient;
import com.azure.storage.file.share.ShareDirectoryClient;
import com.azure.storage.file.share.ShareFileClient; import com.azure.storage.file.share.ShareFileClient;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -30,10 +31,7 @@ public class FileShareStoreTest { ...@@ -30,10 +31,7 @@ public class FileShareStoreTest {
private static final long CONTENT_LENGTH = CONTENTS.getBytes().length; private static final long CONTENT_LENGTH = CONTENTS.getBytes().length;
@Mock @Mock
private IFileShareClientFactory fileShareClientFactory; private ShareDirectoryClient shareDirectoryClient;
@Mock
private ShareClient shareClient;
@Mock @Mock
private ShareFileClient shareFileClient; private ShareFileClient shareFileClient;
...@@ -41,19 +39,13 @@ public class FileShareStoreTest { ...@@ -41,19 +39,13 @@ public class FileShareStoreTest {
@InjectMocks @InjectMocks
private FileShareStore fileShareStore; private FileShareStore fileShareStore;
@BeforeEach
public void setup() {
when(fileShareClientFactory.getClient()).thenReturn(shareClient);
}
@Test @Test
public void testCreateFile() { public void testCreateFile() {
when(shareClient.createFile(eq(NAME), eq(CONTENT_LENGTH))).thenReturn(shareFileClient); when(shareDirectoryClient.createFile(eq(NAME), eq(CONTENT_LENGTH))).thenReturn(shareFileClient);
final ArgumentCaptor<InputStream> inputStreamArgumentCaptor = ArgumentCaptor.forClass(InputStream.class); final ArgumentCaptor<InputStream> inputStreamArgumentCaptor = ArgumentCaptor.forClass(InputStream.class);
when(shareFileClient.upload(inputStreamArgumentCaptor.capture(), eq(CONTENT_LENGTH))).thenReturn(null); when(shareFileClient.upload(inputStreamArgumentCaptor.capture(), eq(CONTENT_LENGTH))).thenReturn(null);
fileShareStore.createFile(CONTENTS, NAME); fileShareStore.createFile(CONTENTS, NAME);
verify(fileShareClientFactory, times(1)).getClient(); verify(shareDirectoryClient, times(1)).createFile(eq(NAME), eq(CONTENT_LENGTH));
verify(shareClient, times(1)).createFile(eq(NAME), eq(CONTENT_LENGTH));
verify(shareFileClient, times(1)).upload(any(InputStream.class), eq(CONTENT_LENGTH)); verify(shareFileClient, times(1)).upload(any(InputStream.class), eq(CONTENT_LENGTH));
} }
} }
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