diff --git a/src/main/java/cloudgene/mapred/plugins/nextflow/NextflowStep.java b/src/main/java/cloudgene/mapred/plugins/nextflow/NextflowStep.java index 04cfc817..9189a7b0 100644 --- a/src/main/java/cloudgene/mapred/plugins/nextflow/NextflowStep.java +++ b/src/main/java/cloudgene/mapred/plugins/nextflow/NextflowStep.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -16,6 +17,9 @@ import cloudgene.mapred.jobs.CloudgeneStep; import cloudgene.mapred.jobs.Message; import cloudgene.mapred.jobs.workspace.IWorkspace; +import cloudgene.mapred.plugins.nextflow.report.Report; +import cloudgene.mapred.plugins.nextflow.report.ReportEvent; +import cloudgene.mapred.plugins.nextflow.report.ReportEventExecutor; import cloudgene.mapred.util.Settings; import cloudgene.mapred.wdl.WdlStep; import genepi.io.FileUtil; @@ -152,6 +156,18 @@ public boolean run(WdlStep step, CloudgeneContext context) { collector.cleanProcesses(context); + File report = new File(executionDir, Report.DEFAULT_FILENAME); + if (!report.exists()) { + return successful; + } + + context.log("Load report file from '" + report.getCanonicalPath() + "'"); + try { + parseReport(report); + } catch (Exception e) { + log.error("[Job {}] Invalid report file.", e); + } + return successful; } catch (Exception e) { @@ -161,6 +177,15 @@ public boolean run(WdlStep step, CloudgeneContext context) { } + private void parseReport(File file) throws IOException { + Report report = new Report(file.getAbsolutePath()); + context.log("Execute " + report.getEvents().size() + " events."); + for (ReportEvent event : report.getEvents()) { + context.log("Event: " + event); + ReportEventExecutor.execute(event, context); + } + } + @Override public void updateProgress() { diff --git a/src/main/java/cloudgene/mapred/plugins/nextflow/report/ReportEvent.java b/src/main/java/cloudgene/mapred/plugins/nextflow/report/ReportEvent.java index 6fd9ff67..e8226e3c 100644 --- a/src/main/java/cloudgene/mapred/plugins/nextflow/report/ReportEvent.java +++ b/src/main/java/cloudgene/mapred/plugins/nextflow/report/ReportEvent.java @@ -65,7 +65,7 @@ public static String format(ReportEvent event) { } case MESSAGE: { String message = (String) event.getParams()[0]; - int type = ((Integer) event.getParams()[1]); + int type = asInteger(event.getParams()[1]); return message(message, type); } case BEGIN_TASK: { @@ -88,12 +88,12 @@ public static String format(ReportEvent event) { } case END_TASK: { String name = (String) event.getParams()[0]; - int type = ((Integer) event.getParams()[1]).intValue(); + int type = asInteger(event.getParams()[1]); return message(name, type); } case INC_COUNTER: { String counter = (String) event.getParams()[0]; - int value = ((Integer) event.getParams()[1]); + int value = asInteger(event.getParams()[1]); return incCounter(counter, value); } default: @@ -137,5 +137,12 @@ public static String message(String message, int type) { } } + + public static int asInteger(Object object) { + //groovy writes integers also as doubles + Double value = Double.parseDouble(object.toString()); + return value.intValue(); + + } }