Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK-7481 - Sample Index Configuration completely empty on new studies #2560

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions .github/workflows/test-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ jobs:
MODULE="opencga"
fi
TAGS=$(echo ${{ inputs.test_profile }} | sed -e 's/run\([^,]*\)Tests/\1/g' | tr ',' '_' | tr '[:upper:]' '[:lower:]' )
echo "TESTS_LOG_FILE_NAME=junit_${{ inputs.hadoop }}_${TAGS}_${MODULE}.log" >> $GITHUB_OUTPUT
echo "TESTS_LOG_FILE_NAME=junit_${{ inputs.hadoop }}_${TAGS}_${MODULE}.log.gz" >> $GITHUB_OUTPUT
- name: Run Junit tests
run: mvn -B verify surefire-report:report --fail-never -Dsurefire.testFailureIgnore=true -f ${{ (inputs.module == '' || inputs.module == 'all') && '.' || inputs.module }} -P ${{ inputs.hadoop }},${{ inputs.test_profile }} -Dcheckstyle.skip ${{ inputs.mvn_opts }} |& tee ${{ steps.BuildJunitLogFileName.outputs.TESTS_LOG_FILE_NAME }} |& grep -P '^\[[^\]]*(INFO|WARNING|ERROR)' --colour=never --line-buffered
run: mvn -B verify surefire-report:report --fail-never -Dsurefire.testFailureIgnore=true -f ${{ (inputs.module == '' || inputs.module == 'all') && '.' || inputs.module }} -P ${{ inputs.hadoop }},${{ inputs.test_profile }} -Dcheckstyle.skip ${{ inputs.mvn_opts }} |& tee >(gzip > ${{ steps.BuildJunitLogFileName.outputs.TESTS_LOG_FILE_NAME }} ) |& grep -P '^\[[^\]]*(INFO|WARNING|ERROR)' --colour=never --line-buffered
- name: Upload Junit test logs
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: ${{ steps.BuildJunitLogFileName.outputs.TESTS_LOG_FILE_NAME }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.opencb.opencga.core.api.ParamConstants;
import org.opencb.opencga.core.common.BatchUtils;
import org.opencb.opencga.core.config.storage.CellBaseConfiguration;
import org.opencb.opencga.core.config.storage.SampleIndexConfiguration;
import org.opencb.opencga.core.models.cohort.Cohort;
import org.opencb.opencga.core.models.cohort.CohortStatus;
import org.opencb.opencga.core.models.cohort.CohortUpdateParams;
Expand All @@ -48,6 +49,7 @@
import org.opencb.opencga.core.models.project.Project;
import org.opencb.opencga.core.models.project.ProjectOrganism;
import org.opencb.opencga.core.models.sample.*;
import org.opencb.opencga.core.models.study.Study;
import org.opencb.opencga.core.response.OpenCGAResult;
import org.opencb.opencga.storage.core.exceptions.StorageEngineException;
import org.opencb.opencga.storage.core.metadata.VariantStorageMetadataManager;
Expand Down Expand Up @@ -421,8 +423,26 @@ protected boolean synchronizeCohorts(StudyMetadata study, String sessionId) thro
return modified;
}

private boolean synchronizeSampleIndexConfiguration(StudyMetadata studyMetadata, String token) throws CatalogException {
Study study = catalogManager.getStudyManager().get(studyMetadata.getName(), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(
StudyDBAdaptor.QueryParams.INTERNAL_CONFIGURATION.key())), token).first();
SampleIndexConfiguration sampleIndexFromCatalog = study.getInternal().getConfiguration().getVariantEngine().getSampleIndex();
SampleIndexConfiguration sampleIndexFromStorage = studyMetadata.getSampleIndexConfigurationLatest().getConfiguration();
if (!sampleIndexFromStorage.equals(sampleIndexFromCatalog)) {
logger.info("Update sample index configuration from storage for study {}", studyMetadata.getName());
catalogManager.getStudyManager().setVariantEngineConfigurationSampleIndex(studyMetadata.getName(), sampleIndexFromStorage, token);
return true;
} else {
return false;
}
}

protected boolean synchronizeFiles(StudyMetadata study, List<File> files, String token) throws CatalogException {
boolean modified = false;

// FIXME: This method call should be relocated
modified |= synchronizeSampleIndexConfiguration(study, token);

Map<String, Integer> fileNameMap = new HashMap<>();
Map<Integer, String> filePathMap = new HashMap<>();
Set<Integer> virtualFiles = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public final void setUpAbstract() throws Exception {
outputPath = "data/index/";
studyId2 = catalogManager.getStudyManager().create(projectId, "s2", "s2", "s2", "Study " + "2", null, null,
null, Collections.singletonMap(VariantStatsAnalysis.STATS_AGGREGATION_CATALOG, getAggregation()),
new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getId();
new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getId();
outputId2 = catalogManager.getFileManager().createFolder(studyId2, Paths.get("data", "index").toString(),
true, null, QueryOptions.empty(), sessionId).first().getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import org.opencb.opencga.catalog.db.api.CohortDBAdaptor;
import org.opencb.opencga.catalog.db.api.FileDBAdaptor;
import org.opencb.opencga.catalog.db.api.SampleDBAdaptor;
import org.opencb.opencga.catalog.db.api.StudyDBAdaptor;
import org.opencb.opencga.catalog.exceptions.CatalogException;
import org.opencb.opencga.catalog.utils.Constants;
import org.opencb.opencga.core.api.ParamConstants;
import org.opencb.opencga.core.common.UriUtils;
import org.opencb.opencga.core.config.storage.SampleIndexConfiguration;
import org.opencb.opencga.core.models.cohort.CohortStatus;
import org.opencb.opencga.core.models.file.File;
import org.opencb.opencga.core.models.file.FileInternalVariantIndex;
Expand Down Expand Up @@ -172,7 +174,20 @@ public void testIndex() throws Exception {
QueryOptions queryOptions = new QueryOptions(VariantStorageOptions.ANNOTATE.key(), false)
.append(VariantStorageOptions.STATS_CALCULATE.key(), false);

QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.INTERNAL_CONFIGURATION.key()));
SampleIndexConfiguration sampleIndex = catalogManager.getStudyManager().get(studyId, options, sessionId)
.first().getInternal().getConfiguration().getVariantEngine().getSampleIndex();
assertNotNull(sampleIndex);

catalogManager.getStudyManager().setVariantEngineConfigurationSampleIndex(studyId, null, sessionId);
sampleIndex = catalogManager.getStudyManager().get(studyId, options, sessionId)
.first().getInternal().getConfiguration().getVariantEngine().getSampleIndex();
assertNull(sampleIndex);

indexFile(getFile(0), queryOptions, outputId);
sampleIndex = catalogManager.getStudyManager().get(studyId, options, sessionId)
.first().getInternal().getConfiguration().getVariantEngine().getSampleIndex();
assertNotNull(sampleIndex);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package org.opencb.opencga.app.migrations.v3.v3_4_0.storage;
package org.opencb.opencga.app.migrations.v4.v4_0_0.storage;

import org.apache.commons.collections4.CollectionUtils;
import org.opencb.opencga.app.migrations.StorageMigrationTool;
import org.opencb.opencga.catalog.migration.Migration;
import org.opencb.opencga.core.config.storage.SampleIndexConfiguration;
import org.opencb.opencga.core.models.study.Study;
import org.opencb.opencga.storage.core.metadata.models.StudyMetadata;
import org.opencb.opencga.storage.core.variant.VariantStorageEngine;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.function.Supplier;

@Migration(id = "ensure_sample_index_configuration_is_defined",
description = "Ensure that the SampleIndexConfiguration object is correctly defined. #TASK-6765", version = "4.0.0",
language = Migration.MigrationLanguage.JAVA,
domain = Migration.MigrationDomain.STORAGE,
patch = 1,
patch = 2,
date = 20240910)
public class EnsureSampleIndexConfigurationIsAlwaysDefined extends StorageMigrationTool {

Expand All @@ -25,7 +27,9 @@ protected void run() throws Exception {

for (String variantStorageProject : getVariantStorageProjects()) {
VariantStorageEngine engine = getVariantStorageEngineByProject(variantStorageProject);
logger.info("Checking project '" + variantStorageProject + "'");
if (engine.getMetadataManager().exists()) {
logger.info("Project '" + variantStorageProject + "' exists in variant storage. Checking studies.");
for (Integer studyId : engine.getMetadataManager().getStudyIds()) {
StudyMetadata studyMetadata = engine.getMetadataManager().getStudyMetadata(studyId);
if (CollectionUtils.isEmpty(studyMetadata.getSampleIndexConfigurations())) {
Expand All @@ -42,11 +46,32 @@ protected void run() throws Exception {
}
});
}
Study study = catalogManager.getStudyManager().get(studyMetadata.getName(), null, token).first();
SampleIndexConfiguration sampleIndexConfFromStorage = studyMetadata.getSampleIndexConfigurationLatest().getConfiguration();
SampleIndexConfiguration sampleIndexConfFromCatalog = orDefault(() -> study.getInternal()
.getConfiguration().getVariantEngine().getSampleIndex(), null);

if (sampleIndexConfFromStorage.equals(sampleIndexConfFromCatalog)) {
logger.info("SampleIndexConfiguration for study '" + studyMetadata.getName() + "' (" + studyId + ") is up to date.");
} else {
logger.info("Updating SampleIndexConfiguration for study '" + studyMetadata.getName() + "' (" + studyId + ")");
catalogManager.getStudyManager().setVariantEngineConfigurationSampleIndex(studyMetadata.getName(),
sampleIndexConfFromStorage, token);
}
}
} else {
logger.info("Project '" + variantStorageProject + "' does not exist in variant storage. Skipping.");
}
}
}

public static <T> T orDefault(Supplier<T> supplier, T defaultValue) {
try {
return supplier.get();
} catch (Exception e) {
return defaultValue;
}
}

public static SampleIndexConfiguration preFileDataConfiguration() {
// If missing, it was assuming cellbase v5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public OpenCGAResult<Study> create(String projectStr, Study study, QueryOptions

authorizationManager.checkIsAtLeastOrganizationOwnerOrAdmin(organizationId, userId);
String cellbaseVersion;
if (project.getCellbase() == null || StringUtils.isEmpty(project.getCellbase().getUrl())) {
if (project.getCellbase() != null && StringUtils.isNotEmpty(project.getCellbase().getUrl())) {
CellBaseValidator cellBaseValidator = new CellBaseValidator(
project.getCellbase(),
project.getOrganism().getScientificName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,16 @@ private MigrationRun run(String organizationId, Class<? extends MigrationTool> r
}
migrationTool.setup(configuration, catalogManager, dbAdaptorFactory, migrationRun, organizationId, appHome, params, token);

String userId;
try {
userId = catalogManager.getUserManager().validateToken(token).getUserId();
} catch (CatalogException e) {
throw new MigrationException(e);
}
StopWatch stopWatch = StopWatch.createStarted();
String path = Paths.get("JOBS")
.resolve("opencga")
.resolve(organizationId)
.resolve(userId)
.resolve(TimeUtils.getDay())
.resolve(annotation.id()).toString();
String jobId = "migration"
Expand Down
Loading