diff --git a/service/build.gradle b/service/build.gradle index d69da880..66a7585d 100644 --- a/service/build.gradle +++ b/service/build.gradle @@ -56,7 +56,8 @@ dependencies { // terra clients implementation "org.broadinstitute.dsde.workbench:sam-client_2.13:0.1-fd8ee25" implementation "org.broadinstitute.dsde.workbench:leonardo-client_2.13:1.3.6-66d9fcf" - implementation 'org.databiosphere:workspacedataservice-client-okhttp-javax:0.2.104-SNAPSHOT' + implementation "org.databiosphere:workspacedataservice-client-okhttp-javax:0.2.104-SNAPSHOT" + implementation "bio.terra:cbas-client:0.0.183" liquibaseRuntime 'org.liquibase:liquibase-core:3.10.0' liquibaseRuntime 'info.picocli:picocli:4.6.1' diff --git a/service/src/main/java/bio/terra/pipelines/app/configuration/external/CbasConfiguration.java b/service/src/main/java/bio/terra/pipelines/app/configuration/external/CbasConfiguration.java new file mode 100644 index 00000000..7540f1dd --- /dev/null +++ b/service/src/main/java/bio/terra/pipelines/app/configuration/external/CbasConfiguration.java @@ -0,0 +1,6 @@ +package bio.terra.pipelines.app.configuration.external; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "cbas") +public record CbasConfiguration(Boolean debugApiLogging) {} diff --git a/service/src/main/java/bio/terra/pipelines/app/configuration/internal/RetryConfiguration.java b/service/src/main/java/bio/terra/pipelines/app/configuration/internal/RetryConfiguration.java index 7fecc572..3085f986 100644 --- a/service/src/main/java/bio/terra/pipelines/app/configuration/internal/RetryConfiguration.java +++ b/service/src/main/java/bio/terra/pipelines/app/configuration/internal/RetryConfiguration.java @@ -26,7 +26,7 @@ public RetryTemplate listenerResetRetryTemplate() { FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy(); fixedBackOffPolicy.setBackOffPeriod(1000L); - // Inner retry (assumping the classifier hits): up to 3 times + // Inner retry (assuming the classifier hits): up to 3 times SimpleRetryPolicy srp = new SimpleRetryPolicy(); srp.setMaxAttempts(3); diff --git a/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasClient.java b/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasClient.java new file mode 100644 index 00000000..a5dbbd0e --- /dev/null +++ b/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasClient.java @@ -0,0 +1,51 @@ +package bio.terra.pipelines.dependencies.cbas; + +import bio.terra.cbas.api.MethodsApi; +import bio.terra.cbas.api.PublicApi; +import bio.terra.cbas.api.RunSetsApi; +import bio.terra.cbas.api.RunsApi; +import bio.terra.cbas.client.ApiClient; +import bio.terra.pipelines.app.configuration.external.CbasConfiguration; +import org.springframework.stereotype.Component; + +@Component +public class CbasClient { + + private final CbasConfiguration cbasConfiguration; + + public CbasClient(CbasConfiguration cbasConfiguration) { + this.cbasConfiguration = cbasConfiguration; + } + + protected ApiClient getApiClient(String cbasBaseUri, String accessToken) { + ApiClient apiClient = new ApiClient().setBasePath(cbasBaseUri); + apiClient.addDefaultHeader("Authorization", "Bearer " + accessToken); + // By closing the connection after each request, we avoid the problem of the open connection + // being force-closed ungracefully by the Azure Relay/Listener infrastructure: + apiClient.addDefaultHeader("Connection", "close"); + apiClient.setDebugging(cbasConfiguration.debugApiLogging()); + return apiClient; + } + + // used to access public endpoints like status and health + PublicApi publicApi(String cbasBaseUri, String accessToken) { + return new PublicApi(getApiClient(cbasBaseUri, accessToken)); + } + + // used to access endpoints related to methods (wdls) + // create, search, delete,etc. + MethodsApi methodsApi(String cbasBaseUri, String accessToken) { + return new MethodsApi(getApiClient(cbasBaseUri, accessToken)); + } + + // used to access endpoints to get information related to runs in a run set + RunsApi runsApi(String cbasBaseUri, String accessToken) { + return new RunsApi(getApiClient(cbasBaseUri, accessToken)); + } + + // used to access endpoints related to running of a submission of methods + // launch, abort, list run sets for a given method + RunSetsApi runSetsApi(String cbasBaseUri, String accessToken) { + return new RunSetsApi(getApiClient(cbasBaseUri, accessToken)); + } +} diff --git a/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasService.java b/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasService.java new file mode 100644 index 00000000..b0156f35 --- /dev/null +++ b/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasService.java @@ -0,0 +1,53 @@ +package bio.terra.pipelines.dependencies.cbas; + +import bio.terra.cbas.client.ApiException; +import bio.terra.cbas.model.MethodListResponse; +import bio.terra.cbas.model.SystemStatus; +import bio.terra.pipelines.dependencies.common.HealthCheckWorkspaceApps; +import org.springframework.retry.support.RetryTemplate; +import org.springframework.stereotype.Service; + +@Service +public class CbasService implements HealthCheckWorkspaceApps { + private final CbasClient cbasClient; + private final RetryTemplate listenerResetRetryTemplate; + + public CbasService(CbasClient cbasClient, RetryTemplate listenerResetRetryTemplate) { + this.cbasClient = cbasClient; + this.listenerResetRetryTemplate = listenerResetRetryTemplate; + } + + public MethodListResponse getAllMethods(String cbasBaseUri, String accesstoken) { + return executionWithRetryTemplate( + listenerResetRetryTemplate, + () -> cbasClient.methodsApi(cbasBaseUri, accesstoken).getMethods(null, null, null)); + } + + @Override + public Result checkHealth(String wdsBaseUri, String accessToken) { + try { + SystemStatus result = cbasClient.publicApi(wdsBaseUri, accessToken).getStatus(); + return new Result(result.isOk(), result.toString()); + } catch (ApiException e) { + return new Result(false, e.getMessage()); + } + } + + interface CbasAction { + T execute() throws ApiException; + } + + static T executionWithRetryTemplate( + RetryTemplate retryTemplate, CbasService.CbasAction action) + throws CbasServiceApiException { + + return retryTemplate.execute( + context -> { + try { + return action.execute(); + } catch (ApiException e) { + throw new CbasServiceApiException(e); + } + }); + } +} diff --git a/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasServiceApiException.java b/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasServiceApiException.java new file mode 100644 index 00000000..36f155b9 --- /dev/null +++ b/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasServiceApiException.java @@ -0,0 +1,10 @@ +package bio.terra.pipelines.dependencies.cbas; + +import bio.terra.cbas.client.ApiException; + +public class CbasServiceApiException extends CbasServiceException { + + public CbasServiceApiException(ApiException exception) { + super("Cbas returned an unsuccessful status code", exception); + } +} diff --git a/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasServiceException.java b/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasServiceException.java new file mode 100644 index 00000000..05177e7a --- /dev/null +++ b/service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasServiceException.java @@ -0,0 +1,11 @@ +package bio.terra.pipelines.dependencies.cbas; + +import bio.terra.common.exception.ErrorReportException; +import java.util.ArrayList; +import org.springframework.http.HttpStatus; + +public class CbasServiceException extends ErrorReportException { + protected CbasServiceException(String message, Throwable cause) { + super(message, cause, new ArrayList<>(), HttpStatus.INTERNAL_SERVER_ERROR); + } +} diff --git a/service/src/main/java/bio/terra/pipelines/dependencies/leonardo/LeonardoService.java b/service/src/main/java/bio/terra/pipelines/dependencies/leonardo/LeonardoService.java index 176b32b8..9133747b 100644 --- a/service/src/main/java/bio/terra/pipelines/dependencies/leonardo/LeonardoService.java +++ b/service/src/main/java/bio/terra/pipelines/dependencies/leonardo/LeonardoService.java @@ -15,7 +15,6 @@ public class LeonardoService implements HealthCheck { private final LeonardoClient leonardoClient; - private final AppUtils appUtils; private final RetryTemplate listenerResetRetryTemplate; @@ -49,6 +48,10 @@ public String getWdsUrlFromApps(String workspaceId, String authToken, boolean cr return appUtils.findUrlForWds(getApps(workspaceId, authToken, creatorOnly), workspaceId); } + public String getCbasUrlFromApps(String workspaceId, String authToken, boolean creatorOnly) { + return appUtils.findUrlForCbas(getApps(workspaceId, authToken, creatorOnly), workspaceId); + } + @Override public Result checkHealth() { try { diff --git a/service/src/main/java/bio/terra/pipelines/service/ImputationService.java b/service/src/main/java/bio/terra/pipelines/service/ImputationService.java index 2890f09f..3801b562 100644 --- a/service/src/main/java/bio/terra/pipelines/service/ImputationService.java +++ b/service/src/main/java/bio/terra/pipelines/service/ImputationService.java @@ -7,6 +7,8 @@ import bio.terra.pipelines.db.exception.DuplicateObjectException; import bio.terra.pipelines.db.repositories.ImputationJobsRepository; import bio.terra.pipelines.db.repositories.PipelineInputsRepository; +import bio.terra.pipelines.dependencies.cbas.CbasService; +import bio.terra.pipelines.dependencies.cbas.CbasServiceException; import bio.terra.pipelines.dependencies.leonardo.LeonardoService; import bio.terra.pipelines.dependencies.leonardo.LeonardoServiceException; import bio.terra.pipelines.dependencies.sam.SamService; @@ -38,6 +40,7 @@ public class ImputationService { private LeonardoService leonardoService; private SamService samService; private WdsService wdsService; + private CbasService cbasService; private final JobService jobService; private ImputationConfiguration imputationConfiguration; @@ -48,6 +51,7 @@ public class ImputationService { LeonardoService leonardoService, SamService samService, WdsService wdsService, + CbasService cbasService, JobService jobService, ImputationConfiguration imputationConfiguration) { this.imputationJobsRepository = imputationJobsRepository; @@ -55,6 +59,7 @@ public class ImputationService { this.leonardoService = leonardoService; this.samService = samService; this.wdsService = wdsService; + this.cbasService = cbasService; this.jobService = jobService; this.imputationConfiguration = imputationConfiguration; } @@ -118,6 +123,7 @@ public UUID writeJobToDb( public List queryForWorkspaceApps() { String workspaceId = imputationConfiguration.workspaceId(); try { + // leonardo related calls List getAppsResponse = leonardoService.getApps(workspaceId, samService.getTspsServiceAccountToken(), false); @@ -126,6 +132,7 @@ public List queryForWorkspaceApps() { imputationConfiguration.workspaceId(), getAppsResponse); + // wds related calls String wdsUri = leonardoService.getWdsUrlFromApps( workspaceId, samService.getTspsServiceAccountToken(), false); @@ -141,6 +148,19 @@ public List queryForWorkspaceApps() { samService.getTspsServiceAccountToken(), imputationConfiguration.workspaceId())); + // cbas related calls + String cbasUri = + leonardoService.getCbasUrlFromApps( + workspaceId, samService.getTspsServiceAccountToken(), false); + logger.info( + "cbas uri for workspace id {}: {}", imputationConfiguration.workspaceId(), cbasUri); + logger.info( + "Cbas health: {}", + cbasService.checkHealth(cbasUri, samService.getTspsServiceAccountToken())); + logger.info( + "list of methods available: {}", + cbasService.getAllMethods(cbasUri, samService.getTspsServiceAccountToken())); + return getAppsResponse; } catch (LeonardoServiceException e) { logger.error("Get Apps called for workspace id {} failed", workspaceId); @@ -148,6 +168,9 @@ public List queryForWorkspaceApps() { } catch (WdsServiceException e) { logger.error("Calls to Wds for workspace id {} failed", workspaceId); return Collections.emptyList(); + } catch (CbasServiceException e) { + logger.error("Calls to Cbas for workspace id {} failed", workspaceId); + return Collections.emptyList(); } } diff --git a/service/src/main/resources/application.yml b/service/src/main/resources/application.yml index 10e2acbe..b44a4ad6 100644 --- a/service/src/main/resources/application.yml +++ b/service/src/main/resources/application.yml @@ -132,10 +132,13 @@ leonardo: # The below appTypeNames are in priority order for the named app type. This order is necessary for # the appComparisonFunction() located in AppUtils.java for selecting the best app for each app type. wdsAppTypeNames: ['WDS'] - cbasAppTypeNames: ['CROMWELL'] + cbasAppTypeNames: ['WORKFLOWS_APP', 'CROMWELL'] dependencyUrlCacheTtlSeconds: 300 # Refresh every 5 minutes debugApiLogging: false wds: apiV: "v0.2" debugApiLogging: false + +cbas: + debugApiLogging: false diff --git a/service/src/test/java/bio/terra/pipelines/configuration/external/CbasConfigurationTest.java b/service/src/test/java/bio/terra/pipelines/configuration/external/CbasConfigurationTest.java new file mode 100644 index 00000000..90c0e08e --- /dev/null +++ b/service/src/test/java/bio/terra/pipelines/configuration/external/CbasConfigurationTest.java @@ -0,0 +1,18 @@ +package bio.terra.pipelines.configuration.external; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import bio.terra.pipelines.app.configuration.external.CbasConfiguration; +import bio.terra.pipelines.testutils.BaseEmbeddedDbTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +class CbasConfigurationTest extends BaseEmbeddedDbTest { + /** test reading Cbas config from application yml */ + @Autowired CbasConfiguration cbasConfiguration; + + @Test + void verifyCbasServerConfig() { + assertTrue(cbasConfiguration.debugApiLogging()); + } +} diff --git a/service/src/test/java/bio/terra/pipelines/configuration/external/SamConfigurationTest.java b/service/src/test/java/bio/terra/pipelines/configuration/external/SamConfigurationTest.java index f4e8dec1..1f2e9727 100644 --- a/service/src/test/java/bio/terra/pipelines/configuration/external/SamConfigurationTest.java +++ b/service/src/test/java/bio/terra/pipelines/configuration/external/SamConfigurationTest.java @@ -12,7 +12,7 @@ class SamConfigurationTest extends BaseEmbeddedDbTest { @Autowired SamConfiguration samConfiguration; @Test - void verifyLeonardoServerConfig() { + void verifySamServerConfig() { assertEquals("testSamUri", samConfiguration.baseUri()); } } diff --git a/service/src/test/java/bio/terra/pipelines/dependencies/cbas/CbasClientTest.java b/service/src/test/java/bio/terra/pipelines/dependencies/cbas/CbasClientTest.java new file mode 100644 index 00000000..a8c95253 --- /dev/null +++ b/service/src/test/java/bio/terra/pipelines/dependencies/cbas/CbasClientTest.java @@ -0,0 +1,42 @@ +package bio.terra.pipelines.dependencies.cbas; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import bio.terra.cbas.api.MethodsApi; +import bio.terra.cbas.api.PublicApi; +import bio.terra.cbas.api.RunSetsApi; +import bio.terra.cbas.api.RunsApi; +import bio.terra.pipelines.testutils.BaseEmbeddedDbTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +class CbasClientTest extends BaseEmbeddedDbTest { + @Autowired CbasClient cbasClient; + String cbasBaseUri = "cbasBaseUri"; + String authToken = "authToken"; + + @Test + void TestWdsClientApis() { + + PublicApi publicApi = cbasClient.publicApi(cbasBaseUri, authToken); + + assertEquals(cbasBaseUri, publicApi.getApiClient().getBasePath()); + assertTrue(publicApi.getApiClient().isDebugging()); + + MethodsApi methodsApi = cbasClient.methodsApi(cbasBaseUri, authToken); + + assertEquals(cbasBaseUri, methodsApi.getApiClient().getBasePath()); + assertTrue(methodsApi.getApiClient().isDebugging()); + + RunsApi runsApi = cbasClient.runsApi(cbasBaseUri, authToken); + + assertEquals(cbasBaseUri, runsApi.getApiClient().getBasePath()); + assertTrue(runsApi.getApiClient().isDebugging()); + + RunSetsApi runSetsApi = cbasClient.runSetsApi(cbasBaseUri, authToken); + + assertEquals(cbasBaseUri, runSetsApi.getApiClient().getBasePath()); + assertTrue(runSetsApi.getApiClient().isDebugging()); + } +} diff --git a/service/src/test/java/bio/terra/pipelines/dependencies/cbas/CbasServiceTest.java b/service/src/test/java/bio/terra/pipelines/dependencies/cbas/CbasServiceTest.java new file mode 100644 index 00000000..9a0573e1 --- /dev/null +++ b/service/src/test/java/bio/terra/pipelines/dependencies/cbas/CbasServiceTest.java @@ -0,0 +1,184 @@ +package bio.terra.pipelines.dependencies.cbas; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; +import static org.mockito.Mockito.doReturn; + +import bio.terra.cbas.api.MethodsApi; +import bio.terra.cbas.api.PublicApi; +import bio.terra.cbas.client.ApiException; +import bio.terra.cbas.model.MethodDetails; +import bio.terra.cbas.model.MethodListResponse; +import bio.terra.cbas.model.SystemStatus; +import bio.terra.pipelines.app.configuration.external.CbasConfiguration; +import bio.terra.pipelines.app.configuration.internal.RetryConfiguration; +import bio.terra.pipelines.dependencies.common.HealthCheckWorkspaceApps; +import java.net.SocketTimeoutException; +import java.util.UUID; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.stubbing.Answer; +import org.springframework.retry.backoff.FixedBackOffPolicy; +import org.springframework.retry.support.RetryTemplate; + +@ExtendWith(MockitoExtension.class) +class CbasServiceTest { + final RetryConfiguration retryConfig = new RetryConfiguration(); + RetryTemplate template = retryConfig.listenerResetRetryTemplate(); + + final CbasConfiguration cbasConfiguration = new CbasConfiguration(false); + + final Answer errorAnswer = + invocation -> { + throw new SocketTimeoutException("Timeout"); + }; + + private final String cbaseBaseUri = "baseUri"; + private final String accessToken = "accessToken"; + + @BeforeEach + void init() { + FixedBackOffPolicy smallerBackoff = new FixedBackOffPolicy(); + smallerBackoff.setBackOffPeriod(5L); // 5 ms + template.setBackOffPolicy(smallerBackoff); + } + + @Test + void socketExceptionRetriesEventuallySucceed() throws Exception { + MethodListResponse expectedResponse = + new MethodListResponse().addMethodsItem(new MethodDetails().name("methodName")); + + CbasClient cbasClient = mock(CbasClient.class); + MethodsApi methodsApi = mock(MethodsApi.class); + when(methodsApi.getMethods(any(), any(), any())) + .thenAnswer(errorAnswer) + .thenReturn(expectedResponse); + + CbasService cbasService = spy(new CbasService(cbasClient, template)); + + doReturn(methodsApi).when(cbasClient).methodsApi(any(), any()); + + assertEquals(expectedResponse, cbasService.getAllMethods(cbaseBaseUri, accessToken)); + } + + // our retry template only attempts a retryable call 3 total times + @Test + void socketExceptionRetriesEventuallyFail() throws Exception { + MethodListResponse expectedResponse = + new MethodListResponse().addMethodsItem(new MethodDetails().name("methodName")); + + CbasClient cbasClient = mock(CbasClient.class); + MethodsApi methodsApi = mock(MethodsApi.class); + when(methodsApi.getMethods(any(), any(), any())) + .thenAnswer(errorAnswer) + .thenAnswer(errorAnswer) + .thenAnswer(errorAnswer) + .thenReturn(expectedResponse); + + CbasService cbasService = spy(new CbasService(cbasClient, template)); + + doReturn(methodsApi).when(cbasClient).methodsApi(any(), any()); + + assertThrows( + SocketTimeoutException.class, + () -> { + cbasService.getAllMethods(cbaseBaseUri, accessToken); + }); + } + + @Test + void apiExceptionsDoNotRetry() throws Exception { + MethodListResponse expectedResponse = + new MethodListResponse().addMethodsItem(new MethodDetails().name("methodName")); + + ApiException expectedException = new ApiException(400, "Bad Cbas"); + + CbasClient cbasClient = mock(CbasClient.class); + MethodsApi methodsApi = mock(MethodsApi.class); + when(methodsApi.getMethods(any(), any(), any())) + .thenThrow(expectedException) + .thenReturn(expectedResponse); + + CbasService cbasService = spy(new CbasService(cbasClient, template)); + + doReturn(methodsApi).when(cbasClient).methodsApi(any(), any()); + + CbasServiceApiException thrown = + assertThrows( + CbasServiceApiException.class, + () -> { + cbasService.getAllMethods(cbaseBaseUri, accessToken); + }); + assertEquals(expectedException, thrown.getCause()); + } + + @Test + void getAllMethodsTest() throws ApiException { + MethodListResponse expectedResponse = + new MethodListResponse() + .addMethodsItem( + new MethodDetails() + .name("methodName") + .methodId(UUID.randomUUID()) + .description("this is my first method")) + .addMethodsItem( + new MethodDetails() + .name("secondMethodName") + .methodId(UUID.randomUUID()) + .description("this is my second method")); + + CbasClient cbasClient = mock(CbasClient.class); + MethodsApi methodsApi = mock(MethodsApi.class); + when(methodsApi.getMethods(any(), any(), any())).thenReturn(expectedResponse); + + CbasService cbasService = spy(new CbasService(cbasClient, template)); + + doReturn(methodsApi).when(cbasClient).methodsApi(any(), any()); + + assertEquals(expectedResponse, cbasService.getAllMethods(cbaseBaseUri, accessToken)); + } + + @Test + void checkHealth() throws ApiException { + CbasClient cbasClient = mock(CbasClient.class); + PublicApi publicApi = mock(PublicApi.class); + + SystemStatus systemStatus = new SystemStatus(); + systemStatus.setOk(true); + + doReturn(publicApi).when(cbasClient).publicApi(any(), any()); + when(publicApi.getStatus()).thenReturn(systemStatus); + + CbasService cbasService = spy(new CbasService(cbasClient, template)); + HealthCheckWorkspaceApps.Result actualResult = cbasService.checkHealth("baseuri", "token"); + + assertEquals( + new HealthCheckWorkspaceApps.Result(systemStatus.isOk(), systemStatus.toString()), + actualResult); + } + + @Test + void checkHealthWithException() throws ApiException { + CbasClient cbasClient = mock(CbasClient.class); + PublicApi publicApi = mock(PublicApi.class); + + String exceptionMessage = "this is my exception message"; + ApiException apiException = new ApiException(exceptionMessage); + + doReturn(publicApi).when(cbasClient).publicApi(any(), any()); + when(publicApi.getStatus()).thenThrow(apiException); + + HealthCheckWorkspaceApps.Result expectedResultOnFail = + new HealthCheckWorkspaceApps.Result(false, apiException.getMessage()); + + CbasService cbasService = spy(new CbasService(cbasClient, template)); + + HealthCheckWorkspaceApps.Result actualResult = cbasService.checkHealth("baseuri", "token"); + + assertEquals(expectedResultOnFail, actualResult); + } +} diff --git a/service/src/test/java/bio/terra/pipelines/dependencies/leonardo/LeonardoServiceTest.java b/service/src/test/java/bio/terra/pipelines/dependencies/leonardo/LeonardoServiceTest.java index 2d46f6b7..48363e81 100644 --- a/service/src/test/java/bio/terra/pipelines/dependencies/leonardo/LeonardoServiceTest.java +++ b/service/src/test/java/bio/terra/pipelines/dependencies/leonardo/LeonardoServiceTest.java @@ -62,6 +62,7 @@ void socketExceptionRetriesEventuallySucceed() throws Exception { assertEquals(expectedResponse, leonardoService.getApps(workspaceId, authToken, false)); } + // our retry template only attempts a retryable call 3 total times @Test void socketExceptionRetriesEventuallyFail() throws Exception { List expectedResponse = List.of(new ListAppResponse()); diff --git a/service/src/test/java/bio/terra/pipelines/dependencies/wds/WdsClientTest.java b/service/src/test/java/bio/terra/pipelines/dependencies/wds/WdsClientTest.java index 141c5bf0..74b95ed3 100644 --- a/service/src/test/java/bio/terra/pipelines/dependencies/wds/WdsClientTest.java +++ b/service/src/test/java/bio/terra/pipelines/dependencies/wds/WdsClientTest.java @@ -14,23 +14,23 @@ class WdsClientTest extends BaseEmbeddedDbTest { @Autowired WdsClient wdsClient; String wdsBaseUri = "wdsBaseUri"; - String auth_token = "authToken"; + String authToken = "authToken"; @Test void TestWdsClientApis() { - RecordsApi recordsApi = wdsClient.recordsApi(wdsBaseUri, auth_token); + RecordsApi recordsApi = wdsClient.recordsApi(wdsBaseUri, authToken); assertEquals(wdsBaseUri, recordsApi.getApiClient().getBasePath()); assertTrue(recordsApi.getApiClient().isDebugging()); GeneralWdsInformationApi generalWdsInformationApi = - wdsClient.generalWdsInformationApi(wdsBaseUri, auth_token); + wdsClient.generalWdsInformationApi(wdsBaseUri, authToken); assertEquals(wdsBaseUri, generalWdsInformationApi.getApiClient().getBasePath()); assertTrue(generalWdsInformationApi.getApiClient().isDebugging()); - SchemaApi schemaApi = wdsClient.schemaApi(wdsBaseUri, auth_token); + SchemaApi schemaApi = wdsClient.schemaApi(wdsBaseUri, authToken); assertEquals(wdsBaseUri, schemaApi.getApiClient().getBasePath()); assertTrue(schemaApi.getApiClient().isDebugging()); diff --git a/service/src/test/java/bio/terra/pipelines/dependencies/wds/WdsServiceTest.java b/service/src/test/java/bio/terra/pipelines/dependencies/wds/WdsServiceTest.java index 82b5f2ec..9dea0004 100644 --- a/service/src/test/java/bio/terra/pipelines/dependencies/wds/WdsServiceTest.java +++ b/service/src/test/java/bio/terra/pipelines/dependencies/wds/WdsServiceTest.java @@ -66,6 +66,7 @@ void socketExceptionRetriesEventuallySucceed() throws Exception { assertEquals(expectedResponse, wdsService.getRecord(any(), any(), any(), any(), any())); } + // our retry template only attempts a retryable call 3 total times @Test void socketExceptionRetriesEventuallyFail() throws Exception { RecordResponse expectedResponse = new RecordResponse().id("idTest").type("typeTest"); diff --git a/service/src/test/java/bio/terra/pipelines/service/ImputationServiceMockTest.java b/service/src/test/java/bio/terra/pipelines/service/ImputationServiceMockTest.java index b8e09176..82f2f9b3 100644 --- a/service/src/test/java/bio/terra/pipelines/service/ImputationServiceMockTest.java +++ b/service/src/test/java/bio/terra/pipelines/service/ImputationServiceMockTest.java @@ -6,6 +6,8 @@ import static org.mockito.Mockito.when; import bio.terra.pipelines.app.configuration.internal.ImputationConfiguration; +import bio.terra.pipelines.dependencies.cbas.CbasService; +import bio.terra.pipelines.dependencies.cbas.CbasServiceApiException; import bio.terra.pipelines.dependencies.leonardo.LeonardoService; import bio.terra.pipelines.dependencies.leonardo.LeonardoServiceApiException; import bio.terra.pipelines.dependencies.sam.SamService; @@ -30,6 +32,7 @@ class ImputationServiceMockTest extends BaseEmbeddedDbTest { @Mock private SamService samService; @Mock private LeonardoService leonardoService; @Mock private WdsService wdsService; + @Mock private CbasService cbasService; @Mock private JobService mockJobService; @Mock private JobBuilder mockJobBuilder; @@ -85,6 +88,14 @@ void queryForWorkspaceAppsIsEmptyWhenWdsException() throws WdsServiceException { assertTrue(imputationService.queryForWorkspaceApps().isEmpty()); } + @Test + void queryForWorkspaceAppsIsEmptyWhenCbasException() throws WdsServiceException { + when(samService.getTspsServiceAccountToken()).thenReturn("saToken"); + when(cbasService.getAllMethods(any(), any())) + .thenThrow(new CbasServiceApiException(new bio.terra.cbas.client.ApiException())); + assertTrue(imputationService.queryForWorkspaceApps().isEmpty()); + } + @Test void testCreateJob_success() { // note this doesn't actually kick off a job diff --git a/service/src/test/resources/application-test.yml b/service/src/test/resources/application-test.yml index 214dc4a2..ee6910df 100644 --- a/service/src/test/resources/application-test.yml +++ b/service/src/test/resources/application-test.yml @@ -40,3 +40,6 @@ leonardo: wds: apiV: "testapiv" debugApiLogging: true + +cbas: + debugApiLogging: true