Skip to content

Commit 12cec5c

Browse files
author
Evgenii Grigorev
committed
Add interface for pipelineExecutionFailed to ProgressListener.java
1 parent fbfe85d commit 12cec5c

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

s-pipes-core/src/main/java/cz/cvut/spipes/engine/ExecutionEngineImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package cz.cvut.spipes.engine;
22

3-
import cz.cvut.spipes.logging.AdvancedLoggingProgressListener;
43
import cz.cvut.spipes.modules.Module;
54
import org.apache.jena.rdf.model.Model;
65
import org.apache.jena.rdf.model.ModelFactory;
@@ -37,9 +36,7 @@ public ExecutionContext executePipeline(final Module module, final ExecutionCont
3736
} catch (Exception e) {
3837
log.error("Pipeline execution failed", e);
3938
fire((l) -> {
40-
if (l instanceof AdvancedLoggingProgressListener) {
41-
((AdvancedLoggingProgressListener) l).pipelineExecutionFailed(pipelineExecutionId);
42-
}
39+
l.pipelineExecutionFailed(pipelineExecutionId);
4340
return null;
4441
});
4542
throw e;

s-pipes-core/src/main/java/cz/cvut/spipes/engine/LoggingProgressListener.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public void pipelineExecutionFinished(long pipelineExecutionId) {
1717
LOG.debug("pipelineExecutionFinished - pipelineExecutionId: {}", pipelineExecutionId);
1818
}
1919

20+
@Override
21+
public void pipelineExecutionFailed(long pipelineExecutionId) {
22+
LOG.debug("pipelineExecutionFailed - pipelineExecutionId: {}", pipelineExecutionId);
23+
}
24+
2025
@Override
2126
public void moduleExecutionStarted(long pipelineExecutionId, String moduleExecutionId, Module outputModule, ExecutionContext inputContext, String predecessorModuleExecutionId) {
2227
LOG.debug("moduleExecutionStarted - pipelineExecutionId: {}, moduleExecutionId: {}, inputContext: {}, predecessorModuleExecutionId: {}", pipelineExecutionId,

s-pipes-core/src/main/java/cz/cvut/spipes/engine/ProgressListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public interface ProgressListener {
2525
*/
2626
void pipelineExecutionFinished(long pipelineExecutionId);
2727

28+
void pipelineExecutionFailed(long pipelineExecutionId);
29+
2830
/**
2931
* Triggers when execution of a module within a pipeline starts.
3032
*

s-pipes-core/src/main/java/cz/cvut/spipes/logging/SemanticLoggingProgressListener.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,34 @@ public SemanticLoggingProgressListener(Resource configResource) {
108108
}
109109
}
110110

111+
@Override
112+
public void pipelineExecutionFailed(final long pipelineExecutionId) {
113+
final EntityManager em = entityManagerMap.get(getPipelineExecutionIri(pipelineExecutionId));
114+
synchronized (em) {
115+
if (em.isOpen()) {
116+
final TurtleWriterFactory factory = new TurtleWriterFactory();
117+
try (FileOutputStream fos = new FileOutputStream(
118+
Files.createFile(getDir(pipelineExecutionId).resolve("log.ttl")).toFile())) {
119+
final RDFWriter writer = factory.getWriter(fos);
120+
writer.startRDF();
121+
RepositoryConnection con = em.unwrap(SailRepository.class).getConnection();
122+
final ValueFactory f = con.getValueFactory();
123+
final RepositoryResult<Statement> res = con
124+
.getStatements(null, null, null, true, f.createIRI(getPipelineExecutionIri(pipelineExecutionId)));
125+
while (res.hasNext()) {
126+
writer.handleStatement(res.next());
127+
}
128+
writer.endRDF();
129+
} catch (IOException e) {
130+
log.error("Error during failed pipeline execution logging.", e);
131+
}
132+
entityManagerMap.remove(em);
133+
em.close();
134+
logDir.remove(pipelineExecutionId);
135+
}
136+
}
137+
}
138+
111139
@Override public void moduleExecutionStarted(final long pipelineExecutionId, final String moduleExecutionId,
112140
final Module outputModule,
113141
final ExecutionContext inputContext,

0 commit comments

Comments
 (0)