-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TSPS-138 add cbas client integration (#49)
Co-authored-by: Jose Soto <[email protected]>
- Loading branch information
1 parent
b73f3bf
commit 9116527
Showing
19 changed files
with
430 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
service/src/main/java/bio/terra/pipelines/app/configuration/external/CbasConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> { | ||
T execute() throws ApiException; | ||
} | ||
|
||
static <T> T executionWithRetryTemplate( | ||
RetryTemplate retryTemplate, CbasService.CbasAction<T> action) | ||
throws CbasServiceApiException { | ||
|
||
return retryTemplate.execute( | ||
context -> { | ||
try { | ||
return action.execute(); | ||
} catch (ApiException e) { | ||
throw new CbasServiceApiException(e); | ||
} | ||
}); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasServiceApiException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
service/src/main/java/bio/terra/pipelines/dependencies/cbas/CbasServiceException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
service/src/test/java/bio/terra/pipelines/configuration/external/CbasConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
service/src/test/java/bio/terra/pipelines/dependencies/cbas/CbasClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
Oops, something went wrong.