diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManager.java index bd71414a4e8..e8a3a01d35d 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManager.java @@ -1757,8 +1757,7 @@ public static DataStore defaultDataStore(CatalogManager catalogManager, Project return defaultDataStore(catalogManager.getConfiguration().getDatabasePrefix(), project.getFqn()); } - public static DataStore defaultDataStore(String databasePrefix, String projectFqnStr) - throws CatalogException { + public static DataStore defaultDataStore(String databasePrefix, String projectFqnStr) { CatalogFqn projectFqn = CatalogFqn.extractFqnFromProjectFqn(projectFqnStr); String dbName = buildDatabaseName(databasePrefix, projectFqn.getOrganizationId(), projectFqn.getProjectId()); diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/MigrationCommandExecutor.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/MigrationCommandExecutor.java index 3f5f7cee80f..5fdada19a9d 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/MigrationCommandExecutor.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/MigrationCommandExecutor.java @@ -70,7 +70,7 @@ private void runMigrationToV3() throws Exception { setCatalogDatabaseCredentials(options, options.commonOptions); OrganizationMigration organizationMigration = new OrganizationMigration(configuration, options.commonOptions.adminPassword, - options.user); + options.user, options.organizationId, Paths.get(appHome)); organizationMigration.execute(); } diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/options/MigrationCommandOptions.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/options/MigrationCommandOptions.java index a306f222c38..7d42b1e77c7 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/options/MigrationCommandOptions.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/options/MigrationCommandOptions.java @@ -46,6 +46,10 @@ public class OrganizationMigrationCommandOptions extends AdminCliOptionsParser.C @Parameter(names = {"--user"}, description = "User whose data is going to be migrated. If more than one user of type FULL contains" + " projects and studies, only the one provided will keep the data and will be fully migrated.") public String user; + + @Parameter(names = {"--organization-id"}, description = "Optional parameter to specify how the new organization will be named." + + " By default, if not provided, the organization id will match the user id that is currently owning the data.") + public String organizationId; } @Parameters(commandNames = {"summary"}, commandDescription = "Obtain migrations status summary") diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_0_0/OrganizationMigration.java b/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_0_0/OrganizationMigration.java index 9b226c0ea1a..5d6e11bacd9 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_0_0/OrganizationMigration.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_0_0/OrganizationMigration.java @@ -1,15 +1,21 @@ package org.opencb.opencga.app.migrations.v3.v3_0_0; +import org.opencb.opencga.catalog.exceptions.CatalogException; import org.opencb.opencga.catalog.migration.Migration; import org.opencb.opencga.catalog.migration.MigrationTool; import org.opencb.opencga.core.config.Configuration; +import java.io.IOException; +import java.nio.file.Path; + @Migration(id = "add_organizations", description = "Add new Organization layer #TASK-4389", version = "3.0.0", language = Migration.MigrationLanguage.JAVA, domain = Migration.MigrationDomain.CATALOG, date = 20231212, - deprecatedSince = "3.1.0") + manual = true, deprecatedSince = "3.1.0") + public class OrganizationMigration extends MigrationTool { - public OrganizationMigration(Configuration configuration, String adminPassword, String userId) { + public OrganizationMigration(Configuration configuration, String adminPassword, String userId, + String organizationId, Path appHome) throws CatalogException, IOException { } @Override diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationTool.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationTool.java index 1a57bb6a239..8f727ba9411 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationTool.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationTool.java @@ -153,7 +153,17 @@ protected final void migrateCollection(MongoCollection inputCollection .cursor()) { while (it.hasNext()) { Document document = it.next(); - migrateFunc.accept(document, list); + try { + migrateFunc.accept(document, list); + } catch (Exception e) { + try { + logger.error("Error migrating document: {}", document.toJson()); + } catch (Exception e1) { + e.addSuppressed(e1); + logger.error("Error migrating document: {}", e.getMessage()); + } + throw e; + } if (list.size() >= batchSize) { count += list.size();