Skip to content

Commit

Permalink
TSPS-86 - connecting to leonardo client (#40)
Browse files Browse the repository at this point in the history
* add logic to connect to Leonardo java client
* reorganize app and test folders
* add PR readme template

---------

Co-authored-by: Jose Soto <[email protected]>
  • Loading branch information
jsotobroad and Jose Soto authored Nov 15, 2023
1 parent 606c777 commit c1801f1
Show file tree
Hide file tree
Showing 42 changed files with 1,565 additions and 81 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ The two tasks `report-to-sherlock` and `set-version-in-dev` will prompt Sherlock
You can check the status of the deployment in [Beehive](https://beehive.dsp-devops.broadinstitute.org/apps/tsps) and in
[ArgoCD](https://ap-argocd.dsp-devops.broadinstitute.org/applications/ap-argocd/tsps-dev).

For more information about deployment to dev, check out DevOps' [excellent documentation](https://docs.google.com/document/d/1lkUkN2KOpHKWufaqw_RIE7EN3vN4G2xMnYBU83gi8VA/).
For more information about deployment to dev, check out DevOps' [excellent documentation](https://docs.google.com/document/d/1lkUkN2KOpHKWufaqw_RIE7EN3vN4G2xMnYBU83gi8VA/).
5 changes: 5 additions & 0 deletions pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Description

_Please replace this description with a concise description of this Pull Request._

### Jira Ticket
4 changes: 3 additions & 1 deletion service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ dependencies {
implementation 'org.apache.commons:commons-dbcp2:2.9.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.7.0'
implementation 'org.springframework.boot:spring-boot-starter-web:2.7.0'
implementation 'org.springframework.retry:spring-retry:1.3.3'
implementation 'org.springframework.retry:spring-retry:1.3.4'

implementation 'org.broadinstitute.dsde.workbench:sam-client_2.12:0.1-61135c7'
implementation "org.broadinstitute.dsde.workbench:leonardo-client_2.13:1.3.6-66d9fcf"
implementation 'javax.ws.rs:javax.ws.rs-api:2.1.1'
implementation 'org.postgresql:postgresql:42.3.3'
implementation 'javax.servlet:jstl:1.2'
Expand Down Expand Up @@ -65,6 +66,7 @@ dependencies {
exclude group: 'com.vaadin.external.google', module: 'android-json'
}
testImplementation 'org.mockito:mockito-inline'
testImplementation 'org.apache.commons:commons-text:1.10.0'

// dependencies for test containers
testImplementation 'org.testcontainers:testcontainers:1.17.3'
Expand Down
12 changes: 0 additions & 12 deletions service/src/main/java/bio/terra/pipelines/App.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package bio.terra.pipelines;

import bio.terra.common.logging.LoggingInitializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
Expand Down Expand Up @@ -46,14 +42,6 @@ public App(DataSource dataSource) {
this.dataSource = dataSource;
}

@Bean("objectMapper")
public ObjectMapper objectMapper() {
return new ObjectMapper()
.registerModule(new ParameterNamesModule())
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule());
}

// This bean plus the @EnableTransactionManagement annotation above enables the use of the
// @Transaction annotation to control the transaction properties of the data source.
@Bean("transactionManager")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bio.terra.pipelines.app;

import bio.terra.common.migrate.LiquibaseMigrator;
import bio.terra.pipelines.app.configuration.TspsDatabaseConfiguration;
import bio.terra.pipelines.app.configuration.internal.TspsDatabaseConfiguration;
import org.springframework.context.ApplicationContext;

public final class StartupInitializer {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package bio.terra.pipelines.app.configuration.external;

import java.time.Duration;
import java.util.List;
import org.broadinstitute.dsde.workbench.client.leonardo.model.AppType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;

/**
* @param baseUri - Leonardo URI to send requests to
* @param wdsAppTypeNames - names used to signify what is the WDS app we want to use
* @param cbasAppTypeNames - names used to signify what is the cbas app we want to use
* @param dependencyUrlCacheTtl - how long (in seconds) to keep items in the cache
* @param debugApiLogging
*/
@ConfigurationProperties(prefix = "leonardo")
public record LeonardoServerConfiguration(
String baseUri,
List<AppType> wdsAppTypeNames,
List<AppType> cbasAppTypeNames,
Duration dependencyUrlCacheTtl,
Boolean debugApiLogging) {

private static final Logger log = LoggerFactory.getLogger(LeonardoServerConfiguration.class);

@ConstructorBinding
public LeonardoServerConfiguration(
String baseUri,
List<String> wdsAppTypeNames,
List<String> cbasAppTypeNames,
long dependencyUrlCacheTtlSeconds,
Boolean debugApiLogging) {
this(
baseUri,
wdsAppTypeNames.stream().map(AppType::fromValue).toList(),
cbasAppTypeNames.stream().map(AppType::fromValue).toList(),
Duration.ofSeconds(dependencyUrlCacheTtlSeconds),
debugApiLogging);
log.info("Setting wdsAppTypes={}", wdsAppTypeNames);
log.info("Setting cbasAppTypeNames={}", cbasAppTypeNames);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bio.terra.pipelines.config;
package bio.terra.pipelines.app.configuration.external;

import org.springframework.boot.context.properties.ConfigurationProperties;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package bio.terra.pipelines.config;
package bio.terra.pipelines.app.configuration.internal;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import bio.terra.common.iam.BearerToken;
import bio.terra.common.iam.BearerTokenFactory;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand All @@ -13,26 +11,30 @@
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.context.annotation.RequestScope;

@Configuration
@EnableRetry
@EnableTransactionManagement
@EnableConfigurationProperties
public class BeanConfig {
public class BeanConfiguration {

private final DataSource dataSource;

public BeanConfig(DataSource dataSource) {
public BeanConfiguration(DataSource dataSource) {
this.dataSource = dataSource;
}

@Bean("objectMapper")
public ObjectMapper objectMapper() {
return new ObjectMapper()
.registerModule(new ParameterNamesModule())
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule())
.setDefaultPropertyInclusion(JsonInclude.Include.NON_ABSENT);
/**
* Taken from <a
* href="https://github.com/DataBiosphere/terra-data-catalog/blob/5cda83aef8548ff98e7cfbe2a6eaaed9ad1bff45/common/src/main/java/bio/terra/catalog/config/BeanConfig.java#L34-L38">Terra
* Data Catalog</a> Lasts for the duration of one request, and is injected into dependent beans,
* even singletons
*/
@Bean("bearerToken")
@RequestScope
public BearerToken bearerToken(HttpServletRequest request) {
return new BearerTokenFactory().from(request);
}

// This bean plus the @EnableTransactionManagement annotation above enables the use of the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package bio.terra.pipelines.app.configuration.internal;

import org.springframework.boot.context.properties.ConfigurationProperties;

/** configuration for all properties related to imputation */
@ConfigurationProperties(prefix = "imputation")
public record ImputationConfiguration(String workspaceId) {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bio.terra.pipelines.app.configuration;
package bio.terra.pipelines.app.configuration.internal;

import bio.terra.pipelines.app.StartupInitializer;
import bio.terra.pipelines.generated.model.ApiVersionProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package bio.terra.pipelines.app.configuration.internal;

import bio.terra.pipelines.retry.RetryLoggingListener;
import java.net.SocketTimeoutException;
import javax.ws.rs.ProcessingException;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.retry.RetryListener;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.retry.backoff.FixedBackOffPolicy;
import org.springframework.retry.policy.ExceptionClassifierRetryPolicy;
import org.springframework.retry.policy.NeverRetryPolicy;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;

/** bean used to retry requests made by the system */
@EnableRetry
@Configuration
public class RetryConfiguration {

@Bean(name = "listenerResetRetryTemplate")
public RetryTemplate listenerResetRetryTemplate() {
RetryTemplate retryTemplate = new RetryTemplate();

// Fixed delay of 1 second between retries
FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
fixedBackOffPolicy.setBackOffPeriod(1000L);

// Inner retry (assumping the classifier hits): up to 3 times
SimpleRetryPolicy srp = new SimpleRetryPolicy();
srp.setMaxAttempts(3);

ExceptionClassifierRetryPolicy ecrp = new ExceptionClassifierRetryPolicy();
ecrp.setExceptionClassifier(
exception -> {
if (exception instanceof ProcessingException
|| exception instanceof SocketTimeoutException) {
return srp;
} else {
return new NeverRetryPolicy();
}
});

retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
retryTemplate.setRetryPolicy(ecrp);
retryTemplate.setThrowLastExceptionOnExhausted(true);
retryTemplate.setListeners(new RetryListener[] {new RetryLoggingListener()});

return retryTemplate;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bio.terra.pipelines.config;
package bio.terra.pipelines.app.configuration.internal;

import org.springframework.boot.context.properties.ConfigurationProperties;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bio.terra.pipelines.app.configuration;
package bio.terra.pipelines.app.configuration.internal;

import bio.terra.common.db.BaseDatabaseProperties;
import bio.terra.common.db.DataSourceInitializer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bio.terra.pipelines.config;
package bio.terra.pipelines.app.configuration.internal;

import org.springframework.boot.context.properties.ConfigurationProperties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import bio.terra.common.exception.ApiException;
import bio.terra.common.iam.SamUser;
import bio.terra.common.iam.SamUserFactory;
import bio.terra.pipelines.config.SamConfiguration;
import bio.terra.pipelines.app.configuration.external.SamConfiguration;
import bio.terra.pipelines.db.entities.Job;
import bio.terra.pipelines.db.exception.PipelineNotFoundException;
import bio.terra.pipelines.generated.api.JobsApi;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package bio.terra.pipelines.dependencies.common;

public interface HealthCheck {

record Result(boolean isOk, String message) {}

Result checkHealth();
}
Loading

0 comments on commit c1801f1

Please sign in to comment.