Skip to content

Commit 800ae9a

Browse files
author
Evgenii Grigorev
committed
Add interface for pipelineExecutionFailed to ProgressListener.java
1 parent b97c2a4 commit 800ae9a

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
@@ -115,6 +115,34 @@ public SemanticLoggingProgressListener(Resource configResource) {
115115
}
116116
}
117117

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

0 commit comments

Comments
 (0)