Skip to content

Commit

Permalink
Merge pull request #197 from overture-stack/develop
Browse files Browse the repository at this point in the history
release 3.8.0
- add ability to customize server url in spring doc swagger to support reverse proxy rewrite path 
- ISO format dates in painless script to avoid date transformer issue in es rest client
  • Loading branch information
blabadi authored Mar 15, 2021
2 parents cff45fc + 9a71f01 commit 7f3388a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-Drevision=3.7.0
-Drevision=3.8.0
-Dsha1=
-Dchangelist=-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.util.StdDateFormat;
import io.github.resilience4j.retry.Retry;
import io.github.resilience4j.retry.RetryConfig;
import java.io.IOException;
Expand Down Expand Up @@ -146,16 +147,15 @@ private List<AnalysisCentricDocument> getAnalysisCentricDocuments(
private UpdateRequest mapAnalysisToUpsertRepositoryQuery(
AnalysisCentricDocument analysisCentricDocument) {
val mapper = new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

val paramsBuilder = new HashMap<String, Object>();
paramsBuilder.put(
"repository",
mapper.convertValue(analysisCentricDocument.getRepositories().get(0), Map.class));
paramsBuilder.put("analysis_state", analysisCentricDocument.getAnalysisState());
paramsBuilder.put("updated_at", analysisCentricDocument.getUpdatedAt());
paramsBuilder.put("updated_at", getDateIso(analysisCentricDocument.getUpdatedAt()));
if (analysisCentricDocument.getPublishedAt()
!= null) { // Nullable as may not have been published
paramsBuilder.put("published_at", analysisCentricDocument.getPublishedAt());
paramsBuilder.put("published_at", getDateIso(analysisCentricDocument.getPublishedAt()));
}

val parameters = unmodifiableMap(paramsBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CommandLineRunner analysisElasticsearchBootstrapper(AnalysisCentricElasticSearch
return (args) -> adapter.initialize();
}

@Bean
@Bean("ES_CLIENT")
RestHighLevelClient client(ApplicationProperties properties) {
val httpHostArrayList =
new ArrayList<HttpHost>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,21 @@ private List<FileCentricDocument> getFileCentricDocuments(
private UpdateRequest mapFileToUpsertRepositoryQuery(FileCentricDocument fileCentricDocument) {
val mapper = new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

// this ISO date format is added because in one instance where maestro was deployed
// an error to transform java.util.date was raised:
// cannot write time value xcontent for unknown value of type class java.util.Date
// there seem to be a class loader issue that cannot load the date transfomers in
// org.elasticsearch.common.xcontent.XContentBuilder
// root cause not found.
val paramsBuilder = new HashMap<String, Object>();
paramsBuilder.put(
"repository", mapper.convertValue(fileCentricDocument.getRepositories().get(0), Map.class));
paramsBuilder.put("analysis_state", fileCentricDocument.getAnalysis().getAnalysisState());
paramsBuilder.put("updated_at", fileCentricDocument.getAnalysis().getUpdatedAt());
paramsBuilder.put("updated_at", getDateIso(fileCentricDocument.getAnalysis().getUpdatedAt()));
if (fileCentricDocument.getAnalysis().getPublishedAt()
!= null) { // Nullable as may not have been published
paramsBuilder.put("published_at", fileCentricDocument.getAnalysis().getPublishedAt());
paramsBuilder.put(
"published_at", getDateIso(fileCentricDocument.getAnalysis().getPublishedAt()));
}

val parameters = unmodifiableMap(paramsBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import io.github.resilience4j.retry.RetryConfig;
import io.vavr.control.Try;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.*;
import java.util.function.Function;
Expand Down Expand Up @@ -234,4 +236,11 @@ private static UpdateRequest prepareUpdate(UpdateRequest req) {
Assert.notNull(req.id(), "No Id define for Query");
return req;
}

static String getDateIso(Date date)
{
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat.format(date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@
import bio.overture.maestro.app.infra.config.properties.PropertiesConfig;
import bio.overture.maestro.domain.api.DomainApiConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.List;

/** Aggregates all configuration in one place */
@Configuration
@Import({
Expand Down Expand Up @@ -97,4 +103,12 @@ class WebConfig {
public ObjectMapper objectMapper() {
return new ObjectMapper();
}

@Bean
@ConditionalOnProperty(name = "springdoc.serverOverride.enabled", havingValue = "true")
public OpenAPI maestroOpenApi(@Value("${springdoc.serverOverride.value}") String serverOverride) {
return new OpenAPI()
.servers(List.of(new Server().url(serverOverride)));
}

}
10 changes: 9 additions & 1 deletion maestro-app/src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,13 @@ spring:
maxAttempts: 1

springdoc:
## The reason this was added to support reverse proxy url rewrites like: http://xyz.com/maestro
## otherwise the swagger urls will not be sent to the correct url since swagger ui depends
## on the server definition and springdoc needs forward headers to be enabled by spring
## enabling forward headers in maestro caused it to conflict with disabling kafka
## and forced an autoconfigure for kafka client.
serverOverride:
enabled: false
value: http://localhost:11235/custom
swagger-ui:
path: /api-docs
path: /api-docs

0 comments on commit 7f3388a

Please sign in to comment.