Skip to content

Commit

Permalink
fix: import profile task keeps running on failure (#4578)
Browse files Browse the repository at this point in the history
fix: import profile task keeps running on failure

improve logging output
  • Loading branch information
connoratrug authored Dec 20, 2024
1 parent e68dcb8 commit eabb6e1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ public void run() {
commitTask.setDescription("Committing");
});
} catch (Exception e) {
commitTask.completeWithError("Commit failed: " + e.getMessage());
this.completeWithError(e.getMessage());
throw (e);
try {
commitTask.completeWithError("CommitTask failed: " + e.getMessage());
} catch (MolgenisException e2) {
try {
this.completeWithError("ImportProfileTask failed: " + e2.getMessage());
} catch (Exception e3) {
throw (e3);
}
}
}
commitTask.complete();
this.complete();
Expand All @@ -56,7 +62,12 @@ void load(Schema schema) {
Profiles profiles = getProfiles(schema, schemaFromProfile);

// create the schema using the selected profile tags within the big model
SchemaMetadata schemaMetadata = schemaFromProfile.create();
SchemaMetadata schemaMetadata = null;
try {
schemaMetadata = schemaFromProfile.create();
} catch (Exception e) {
throw new MolgenisException("Failed to create schema from profile: " + e.getMessage(), e);
}

// special option: fixed schema import location for ontologies (not schema or data)
Schema ontologySchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

import org.junit.jupiter.api.*;
import org.molgenis.emx2.Database;
import org.molgenis.emx2.MolgenisException;
import org.molgenis.emx2.Schema;
import org.molgenis.emx2.datamodels.profiles.Profiles;
import org.molgenis.emx2.datamodels.profiles.SchemaFromProfile;
import org.molgenis.emx2.io.ImportProfileTask;
import org.molgenis.emx2.sql.TestDatabaseFactory;
import org.molgenis.emx2.tasks.TaskStatus;

@TestMethodOrder(MethodOrderer.MethodName.class)
@Tag("slow")
Expand Down Expand Up @@ -54,4 +56,13 @@ void testProfileLoader() {
assertFalse(testIncludeProfileSchema.getTableNames().contains("Individuals"));
assertTrue(testIncludeProfileSchema.getTableNames().contains("Distribution"));
}

@Test
void testProfileLoaderWithError() {
database.dropSchemaIfExists(TEST_PROFILE);
Schema testProfileSchema = database.createSchema(TEST_PROFILE);
var task = new ImportProfileTask(testProfileSchema, "TestProfileWithError.yaml", true);
assertThrows(MolgenisException.class, task::run);
assertEquals(TaskStatus.ERROR, task.getStatus());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: TestProfileError
description: "Test profile with error"

profileTags: DataCatalogue

demoData: _demodata/application/imagetest

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void run() {
try {
source.processTable(table.getName(), new ImportRowProcesssor(table, this));
} catch (Exception e) {
this.setError("Import failed: " + e.getMessage());
this.setError("Import table (%s) failed: %s".formatted(table.getName(), e.getMessage()));
throw e;
}

Expand Down Expand Up @@ -176,12 +176,19 @@ public void process(Iterator<Row> iterator, TableStore source) {
if (c.isFile()
&& source instanceof TableAndFileStore
&& row.getValueMap().get(c.getName()) != null) {
BinaryFileWrapper wrapper =
((TableAndFileStore) source).getBinaryFileWrapper(row.getString(c.getName()));
if (row.containsName(c.getName() + "_filename")) {
wrapper.setFileName(row.getString(c.getName() + "_filename"));
try {
BinaryFileWrapper wrapper =
((TableAndFileStore) source).getBinaryFileWrapper(row.getString(c.getName()));
if (row.containsName(c.getName() + "_filename")) {
wrapper.setFileName(row.getString(c.getName() + "_filename"));
}
row.setBinary(c.getName(), wrapper);
} catch (Exception e) {
throw new MolgenisException(
"Failed to read file attachment for column %s row %d"
.formatted(c.getName(), index),
e);
}
row.setBinary(c.getName(), wrapper);
}
}
batch.add(row);
Expand Down

0 comments on commit eabb6e1

Please sign in to comment.