Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
80246f8
[BI-1555] - Converted ProgramCache to use Redis instead of Guava cache.
timparsons Aug 5, 2022
5762506
[BI-1555] - Additional changes for cache to work properly
timparsons Aug 5, 2022
3800527
[BI-1555] - removing embedded micronaut dependencies
timparsons Aug 18, 2022
8a5de9b
[BI-1555] - Converting Redis library to Redisson.
timparsons Aug 18, 2022
f000245
[BI-1555] - Configuring redis container for integration tests
timparsons Aug 18, 2022
4331f42
[BI-1555] - Updating ProgramCacheUnitTest
timparsons Aug 18, 2022
6176d84
[BI-1555] - Stopping redis container on integration tests
timparsons Aug 18, 2022
4c34b71
[BI-1555] - Adding docker network config to tests
timparsons Aug 19, 2022
b1c7b7f
[BI-1555] - adding robustness to the caching processor queue
timparsons Sep 7, 2022
74f7880
[BI-1555] - removing redundant injected constructor from ProgramService
timparsons Sep 7, 2022
8afd892
[BI-1555] - Refactoring TraitDAO and ProgramDAO to follow the interfa…
timparsons Sep 7, 2022
99281b6
[BI-1555] - Fixing unit tests
timparsons Sep 7, 2022
fb96326
[BI-1555] Cleanup
timparsons Sep 7, 2022
34f0b08
[BI-1555] - Fixing unit tests
timparsons Sep 8, 2022
2a61f14
[BI-1555] - bumping heap size for unit tests
timparsons Sep 8, 2022
3693c4a
[BI-1555] - bumping surefire plugin version
timparsons Sep 8, 2022
bb5883d
Update pom.xml
timparsons Sep 8, 2022
0113e01
[BI-1555] - removing unnecessary surefire dependencies
timparsons Sep 8, 2022
cf95ad1
[BI-1555] - Refactoring how containers are created and managed
timparsons Sep 8, 2022
f726923
[BI-1555] - fixing compilation error
timparsons Sep 8, 2022
ac6437e
[BI-1555] - Fixing failed tests
timparsons Sep 8, 2022
4e282a6
[BI-1555] - Updating cache post method to put values in the cache to …
timparsons Sep 15, 2022
8ae5ef3
[BI-1555] - fixing unit test failure
timparsons Sep 19, 2022
9290dd6
[BI-1555] - removing commented out code
timparsons Sep 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ services:
depends_on:
- bidb
- brapi-server
- redis
- mailhog
volumes:
- /usr/bin/docker:/usr/bin/docker
- /var/run/docker.sock:/var/run/docker.sock
Expand All @@ -51,6 +53,9 @@ services:
- EMAIL_RELAY_HOST=${EMAIL_RELAY_HOST}
- EMAIL_RELAY_PORT=${EMAIL_RELAY_PORT}
- EMAIL_FROM=${EMAIL_FROM}
- REDIS_URL=${REDIS_URL:-redis://redis:6379}
- REDIS_TIMEOUT=${REDIS_TIMEOUT:-30s}
- REDIS_SSL=${REDIS_SSL:-false}
ports:
- ${API_INTERNAL_PORT}:${API_INTERNAL_PORT}
networks:
Expand All @@ -62,15 +67,15 @@ services:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
ports:
- 5432:5432
- "5432:5432"
volumes:
- biapi_data:/var/lib/postgresql/data
networks:
backend:
aliases:
- dbserver
brapi-server:
image: breedinginsight/brapi-java-server:latest
image: breedinginsight/brapi-java-server:develop
container_name: brapi-server
depends_on:
- bidb
Expand All @@ -93,8 +98,16 @@ services:
container_name: mailhog
restart: always
ports:
- 1025:1025
- 8025:8025
- "1025:1025"
- "8025:8025"
redis:
image: redis
container_name: redis
restart: always
ports:
- "6379:6379"
networks:
backend:

networks:
backend:
Expand Down
Binary file removed io-micronaut/jar_files.zip
Binary file not shown.
Binary file removed io-micronaut/jar_files/aop-1.0.0.RC2.jar
Binary file not shown.
Binary file removed io-micronaut/jar_files/core-1.0.0.RC2.jar
Binary file not shown.
Binary file removed io-micronaut/jar_files/http-1.0.0.RC2.jar
Binary file not shown.
Binary file removed io-micronaut/jar_files/inject-1.0.0.RC2.jar
Binary file not shown.
Binary file not shown.
Binary file removed io-micronaut/jar_files/jackson-core-2.9.7.jar
Binary file not shown.
Binary file removed io-micronaut/jar_files/jackson-databind-2.9.7.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed io-micronaut/jar_files/javax.inject-1.jar
Binary file not shown.
Binary file removed io-micronaut/jar_files/jsr305-3.0.2.jar
Binary file not shown.
Binary file removed io-micronaut/jar_files/reactive-streams-1.0.2.jar
Binary file not shown.
Binary file removed io-micronaut/jar_files/runtime-1.0.0.RC2.jar
Binary file not shown.
Binary file removed io-micronaut/jar_files/rxjava-2.2.2.jar
Binary file not shown.
Binary file removed io-micronaut/jar_files/slf4j-api-1.7.25.jar
Binary file not shown.
Binary file removed io-micronaut/jar_files/snakeyaml-1.23.jar
Binary file not shown.
Binary file not shown.
37 changes: 21 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<exec.mainClass>org.breedinginsight.api.Application</exec.mainClass>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version> <!-- 2.22.2 -->
<maven-failsafe-plugin.version>2.19.1</maven-failsafe-plugin.version>
<jvm.options>--enable-preview</jvm.options>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version> <!-- 2.22.2 -->
<maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
<jvm.options>-Xmx1024m -XX:MaxPermSize=256m --enable-preview</jvm.options>

<jooq.version>3.16.3</jooq.version>
<postgres.version>42.3.2</postgres.version>
Expand Down Expand Up @@ -395,6 +395,11 @@
<artifactId>cloning</artifactId>
<version>${cloning.version}</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-micronaut-20</artifactId>
<version>3.17.5</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -571,21 +576,21 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0</version>
</dependency>
</dependencies>
<!-- <dependencies>-->
<!-- <dependency>-->
<!-- <groupId>org.junit.platform</groupId>-->
<!-- <artifactId>junit-platform-surefire-provider</artifactId>-->
<!-- <version>1.3.2</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.junit.jupiter</groupId>-->
<!-- <artifactId>junit-jupiter-engine</artifactId>-->
<!-- <version>5.9.0</version>-->
<!-- </dependency>-->
<!-- </dependencies>-->
<configuration>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<argLine>${jvm.options}</argLine>
<argLine>${jvm.options}</argLine>
<detail>true</detail>
<includes>
<include>%regex[.*]</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.breedinginsight.brapi.v1.services;

import lombok.extern.slf4j.Slf4j;
import org.brapi.v2.model.pheno.BrAPIScaleValidValuesCategories;
import org.breedinginsight.api.auth.AuthenticatedUser;
import org.breedinginsight.brapi.v1.model.*;
import org.breedinginsight.dao.db.enums.DataType;
Expand Down Expand Up @@ -111,8 +112,15 @@ private ObservationVariable mapBiTraitToBrapiV1ObservationVariable(org.breedingi

TraitDataType dataType = mapBiDataTypeToBrapiV1TraitDataType(biScale.getDataType());

List<String> categories = biScale.getCategories().stream()
.map(category -> category.getValue()).collect(Collectors.toList());

List<String> categories = new ArrayList<>();

if(biScale.getCategories() != null) {
categories = biScale.getCategories()
.stream()
.map(BrAPIScaleValidValuesCategories::getValue)
.collect(Collectors.toList());
}

ValidValues validValues = ValidValues.builder()
.categories(categories)
Expand Down Expand Up @@ -169,7 +177,7 @@ private ObservationVariable mapBiTraitToBrapiV1ObservationVariable(org.breedingi
//.scientist() // missing from bi trait model but stored in BrAPI service
//.status(trait.getStatus())
.submissionTimestamp(trait.getCreatedAt())
.synonyms(trait.getSynonyms().isEmpty() ? synonyms : trait.getSynonyms()) // TODO: fix need to have synonym for field book bug
.synonyms(trait.getSynonyms() == null || trait.getSynonyms().isEmpty() ? synonyms : trait.getSynonyms()) // TODO: fix need to have synonym for field book bug
.trait(brapiTrait)
.xref(trait.getId().toString())
.observationVariableDbId(trait.getId().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.breedinginsight.brapps.importer.model.exports.FileType;
import org.breedinginsight.model.DownloadFile;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.utilities.Utilities;
import org.breedinginsight.utilities.response.ResponseUtils;

import javax.inject.Inject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,28 @@
import io.micronaut.context.annotation.Context;
import io.micronaut.context.annotation.Property;
import io.micronaut.http.server.exceptions.InternalServerException;
import io.micronaut.scheduling.annotation.Scheduled;
import lombok.extern.slf4j.Slf4j;
import org.brapi.client.v2.ApiResponse;
import org.brapi.client.v2.model.exceptions.ApiException;
import org.brapi.client.v2.model.queryParams.germplasm.GermplasmQueryParams;
import org.brapi.client.v2.modules.germplasm.GermplasmApi;
import org.brapi.v2.model.BrAPIExternalReference;
import org.brapi.v2.model.germ.BrAPIGermplasm;
import org.brapi.v2.model.germ.BrAPIGermplasmSynonyms;
import org.brapi.v2.model.germ.request.BrAPIGermplasmSearchRequest;
import org.brapi.v2.model.germ.response.BrAPIGermplasmListResponse;
import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields;
import org.breedinginsight.brapps.importer.daos.ImportDAO;
import org.breedinginsight.brapps.importer.model.ImportUpload;
import org.breedinginsight.daos.ProgramDAO;
import org.breedinginsight.daos.cache.ProgramCache;
import org.breedinginsight.daos.cache.ProgramCacheProvider;
import org.breedinginsight.model.Program;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.utilities.BrAPIDAOUtil;
import org.breedinginsight.utilities.Utilities;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.*;
Expand All @@ -56,20 +61,30 @@ public class BrAPIGermplasmDAO {
@Property(name = "brapi.server.reference-source")
private String referenceSource;

ProgramCache<String, BrAPIGermplasm> programGermplasmCache;
@Property(name = "micronaut.bi.api.run-scheduled-tasks")
private boolean runScheduledTasks;

private final ProgramCache<BrAPIGermplasm> programGermplasmCache;

@Inject
public BrAPIGermplasmDAO(ProgramDAO programDAO, ImportDAO importDAO, BrAPIDAOUtil brAPIDAOUtil) {
public BrAPIGermplasmDAO(ProgramDAO programDAO, ImportDAO importDAO, BrAPIDAOUtil brAPIDAOUtil, ProgramCacheProvider programCacheProvider) {
this.programDAO = programDAO;
this.importDAO = importDAO;
this.brAPIDAOUtil = brAPIDAOUtil;
this.programGermplasmCache = programCacheProvider.getProgramCache(this::fetchProgramGermplasm, BrAPIGermplasm.class);
}

@PostConstruct
private void setup() {
@Scheduled(initialDelay = "2s")
public void setup() {
if(!runScheduledTasks) {
return;
}
// Populate germplasm cache for all programs on startup
List<UUID> programs = programDAO.getAll().stream().filter(Program::getActive).map(Program::getId).collect(Collectors.toList());
programGermplasmCache = new ProgramCache<>(this::fetchProgramGermplasm, programs);
log.debug("populating germplasm cache");
List<Program> programs = programDAO.getActive();
if(programs != null) {
programGermplasmCache.populate(programs.stream().map(Program::getId).collect(Collectors.toList()));
}
}

/**
Expand Down Expand Up @@ -111,10 +126,11 @@ public List<BrAPIGermplasm> getRawGermplasm(UUID programId) throws ApiException
*/
private Map<String, BrAPIGermplasm> fetchProgramGermplasm(UUID programId) throws ApiException {
GermplasmApi api = new GermplasmApi(programDAO.getCoreClient(programId));

// Get the program key
List<Program> programs = programDAO.get(programId);
if (programs.size() != 1) throw new InternalServerException("Program was not found for given key");
if (programs.size() != 1) {
throw new InternalServerException("Program was not found for given key");
}
Program program = programs.get(0);

// Set query params and make call
Expand All @@ -137,7 +153,7 @@ private Map<String, BrAPIGermplasm> fetchProgramGermplasm(UUID programId) throws
private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplasm> programGermplasm, String programKey) {
// Process the germplasm
Map<String, BrAPIGermplasm> programGermplasmMap = new HashMap<>();
log.debug("processing germ for display: " + programGermplasm);
log.trace("processing germ for display: " + programGermplasm);
Map<String, BrAPIGermplasm> programGermplasmByFullName = new HashMap<>();
for (BrAPIGermplasm germplasm: programGermplasm) {
programGermplasmByFullName.put(germplasm.getGermplasmName(), germplasm);
Expand Down Expand Up @@ -212,13 +228,15 @@ private Map<String,BrAPIGermplasm> processGermplasmForDisplay(List<BrAPIGermplas

public List<BrAPIGermplasm> importBrAPIGermplasm(List<BrAPIGermplasm> brAPIGermplasmList, UUID programId, ImportUpload upload) throws ApiException {
GermplasmApi api = new GermplasmApi(programDAO.getCoreClient(programId));
var program = programDAO.fetchOneById(programId);
try {
Callable<List<BrAPIGermplasm>> postFunction = () -> brAPIDAOUtil.post(brAPIGermplasmList, upload, api::germplasmPost, importDAO::update);
Callable<Map<String, BrAPIGermplasm>> postFunction = () -> {
List<BrAPIGermplasm> postResponse = brAPIDAOUtil.post(brAPIGermplasmList, upload, api::germplasmPost, importDAO::update);
return processGermplasmForDisplay(postResponse, program.getKey());
};
return programGermplasmCache.post(programId, postFunction);
} catch (ApiException e) {
throw e;
} catch (Exception e) {
throw new InternalServerException("Unknown error has occurred: " + e.getMessage());
throw new InternalServerException("Unknown error has occurred: " + e.getMessage(), e);
}
}

Expand Down
Loading