-
Notifications
You must be signed in to change notification settings - Fork 5
Add more metadata for pipelines #399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6a7067b
8d03fa9
0f069e8
2b3a3a9
51818c4
ca1cf7d
762237d
5164968
569af8f
cf0d58e
c2ba608
e069214
ac5c94e
2d05501
9b23dfd
b7be03e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -26,10 +26,27 @@ public ExecutionContext executePipeline(final Module module, final ExecutionCont | |||||
| log.info("Executing script {} with context {}.", module.getResource(), inputContext.toSimpleString()); | ||||||
| final long pipelineExecutionId = Instant.now().toEpochMilli()*1000+(i++); | ||||||
|
|
||||||
| fire((l) -> {l.pipelineExecutionStarted(pipelineExecutionId); return null;}); | ||||||
| ExecutionContext outputContext = _executePipeline(pipelineExecutionId, module, inputContext, null); | ||||||
| fire((l) -> {l.pipelineExecutionFinished(pipelineExecutionId); return null;}); | ||||||
| return outputContext; | ||||||
| String functionName = inputContext.getId(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it is IRI, right? |
||||||
| String scriptPath; | ||||||
| if (inputContext.getValue(ExecutionContext.P_SCRIPT_URI) != null) { | ||||||
| scriptPath = inputContext.getScriptFile().toString(); | ||||||
| } else { | ||||||
| scriptPath = module.getScriptPath(); | ||||||
| } | ||||||
|
Comment on lines
+31
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not enough to use: |
||||||
| String script = module.getResource().toString().replaceAll("\\/[^.]*$", ""); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea what following is doing .. |
||||||
| fire((l) -> {l.pipelineExecutionStarted(pipelineExecutionId, functionName, scriptPath, script); return null;}); | ||||||
| try { | ||||||
| ExecutionContext outputContext = _executePipeline(pipelineExecutionId, module, inputContext, null); | ||||||
| fire((l) -> {l.pipelineExecutionFinished(pipelineExecutionId); return null;}); | ||||||
| return outputContext; | ||||||
| } catch (Exception e) { | ||||||
| log.error("Pipeline execution failed", e); | ||||||
| fire((l) -> { | ||||||
| l.pipelineExecutionFailed(pipelineExecutionId); | ||||||
| return null; | ||||||
| }); | ||||||
| throw e; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private void fire(final Function<ProgressListener,Void> function) { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ | |
| import java.io.*; | ||
| import java.net.MalformedURLException; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
|
|
@@ -103,7 +104,7 @@ private static Property getParameter(final String name) { | |
| } | ||
|
|
||
| @Override | ||
| public void pipelineExecutionStarted(final long pipelineExecutionId) { | ||
| public void pipelineExecutionStarted(final long pipelineExecutionId, String functionName, String scriptPath, String script) { | ||
| PipelineExecution pipelineExecution = new PipelineExecution(); | ||
| pipelineExecution.setId(getPipelineExecutionIri(pipelineExecutionId)); | ||
| pipelineExecution.setTypes(Collections.singleton(Vocabulary.s_c_transformation)); | ||
|
|
@@ -113,6 +114,11 @@ public void pipelineExecutionStarted(final long pipelineExecutionId) { | |
| pipelineExecutionDir.toFile().mkdir(); | ||
| logDir.put(pipelineExecutionId, pipelineExecutionDir); | ||
|
|
||
| metadataMap.clear(); | ||
| metadataMap.put(SPIPES.has_executed_function.toString(), URI.create(functionName)); | ||
| metadataMap.put(SPIPES.has_executed_function_script_path.toString(), scriptPath); | ||
| metadataMap.put(SPIPES.has_script.toString(), URI.create(script)); | ||
|
|
||
| final EntityManager metadataEM = getMetadataEmf().createEntityManager(); | ||
| synchronized (metadataEM) { | ||
| persistPipelineExecutionStarted(metadataEM, pipelineExecutionId, pipelineExecution); | ||
|
|
@@ -133,7 +139,8 @@ private void persistPipelineExecutionStarted(final EntityManager em, long pipeli | |
| Date startDate = new Date(); | ||
| addProperty(pipelineExecution, SPIPES.has_pipeline_execution_start_date, startDate); | ||
| addProperty(pipelineExecution, SPIPES.has_pipeline_execution_start_date_unix, startDate.getTime()); | ||
|
|
||
| addProperty(pipelineExecution, SPIPES.has_executed_function, getURIFromMetadataMap(SPIPES.has_executed_function)); | ||
| addProperty(pipelineExecution, SPIPES.has_executed_function_script_path, metadataMap.get(SPIPES.has_executed_function_script_path.toString())); | ||
| if (pipelineExecutionGroupId != null) { | ||
| addProperty(pipelineExecution, PIPELINE_EXECUTION_GROUP_ID, pipelineExecutionGroupId); | ||
| } | ||
|
|
@@ -182,14 +189,29 @@ private void persistPipelineExecutionFinished(final EntityManager em, final long | |
| final PipelineExecution pipelineExecution = | ||
| em.find(PipelineExecution.class, pipelineExecutionIri, pd); | ||
|
|
||
| String pipelineName = metadataMap.get(SPIPES.has_pipeline_name.toString()).toString(); | ||
| addProperty(pipelineExecution, SPIPES.has_script, getURIFromMetadataMap(SPIPES.has_script)); | ||
| // new | ||
| Date startDate = pipelineExecution.getHas_pipepline_execution_date(); | ||
| addProperty(pipelineExecution, SPIPES.has_pipeline_execution_finish_date, finishDate); | ||
| addProperty(pipelineExecution, SPIPES.has_pipeline_execution_finish_date_unix, finishDate.getTime()); | ||
| addProperty(pipelineExecution, SPIPES.has_pipeline_execution_duration, computeDuration(startDate, finishDate)); | ||
| addProperty(pipelineExecution, SPIPES.has_pipeline_name, pipelineName); | ||
| // addScript(pipelineExecution, scriptManager.getScriptByContextId(pipelineName)); | ||
| addProperty(pipelineExecution, ResourceFactory.createProperty(Vocabulary.s_p_has_pipeline_execution_status), URI.create(Vocabulary.s_p_finished_pipeline_execution)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to use so
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MSattrtand, please read carefully the comment #399 (comment) as well as the whole thread where it occurs. |
||
| // addScript(pipelineExecution, scriptManager.getScriptByContextId(script)); | ||
| em.getTransaction().commit(); | ||
| em.close(); | ||
| } | ||
| } | ||
|
|
||
| private void persistPipelineExecutionFailed(final EntityManager em, final long pipelineExecutionId) { | ||
| if (em.isOpen()) { | ||
| em.getTransaction().begin(); | ||
|
|
||
| String pipelineExecutionIri = getPipelineExecutionIri(pipelineExecutionId); | ||
| final EntityDescriptor pd = new EntityDescriptor(URI.create(pipelineExecutionIri)); | ||
| final PipelineExecution pipelineExecution = | ||
| em.find(PipelineExecution.class, pipelineExecutionIri, pd); | ||
| addProperty(pipelineExecution, SPIPES.has_script, getURIFromMetadataMap(SPIPES.has_script)); | ||
| addProperty(pipelineExecution, ResourceFactory.createProperty(Vocabulary.s_p_has_pipeline_execution_status), URI.create(Vocabulary.s_p_failed_pipeline_execution)); | ||
| em.getTransaction().commit(); | ||
| em.close(); | ||
| } | ||
|
|
@@ -220,6 +242,16 @@ public void pipelineExecutionFinished(final long pipelineExecutionId) { | |
| } | ||
| } | ||
|
|
||
| public void pipelineExecutionFailed(final long pipelineExecutionId) { | ||
| final EntityManager em = entityManagerMap.get(getPipelineExecutionIri(pipelineExecutionId)); | ||
|
|
||
| synchronized (em) { | ||
| persistPipelineExecutionFailed(em, pipelineExecutionId); | ||
| entityManagerMap.remove(em); | ||
| executionMap.remove(getPipelineExecutionIri(pipelineExecutionId)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void moduleExecutionStarted(final long pipelineExecutionId, final String moduleExecutionId, | ||
| final Module outputModule, | ||
|
|
@@ -314,9 +346,10 @@ public void moduleExecutionFinished(long pipelineExecutionId, final String modul | |
| addProperty(moduleExecution, SPIPES.has_module_execution_duration, computeDuration(startDate, finishDate)); | ||
| addProperty(moduleExecution, SPIPES.has_output_model_triple_count, module.getOutputContext().getDefaultModel().size()); | ||
| addContentProperty(moduleExecution, module.getOutputContext(), "output"); | ||
| addProperty(moduleExecution, SPIPES.has_pipeline_name, module.getResource().toString().replaceAll("\\/[^.]*$", "")); | ||
| if(!metadataMap.containsKey(SPIPES.has_pipeline_name.toString())){ | ||
| metadataMap.put(SPIPES.has_pipeline_name.toString(), module.getResource().toString().replaceAll("\\/[^.]*$", "")); | ||
| String script = module.getResource().toString().replaceAll("\\/[^.]*$", ""); | ||
| addProperty(moduleExecution, SPIPES.has_script, URI.create(script)); | ||
| if(!metadataMap.containsKey(SPIPES.has_script.toString())){ | ||
| metadataMap.put(SPIPES.has_script.toString(), URI.create(script)); | ||
| } | ||
|
|
||
| // input binding | ||
|
|
@@ -567,5 +600,16 @@ public String toString() { | |
| } | ||
| } | ||
|
|
||
|
|
||
| private URI getURIFromMetadataMap(Property property){ | ||
| URI uri; | ||
| try { | ||
| if (!metadataMap.containsKey(property.toString())) { | ||
| throw new IllegalStateException("Metadata map does not contain property: " + property); | ||
| } | ||
| uri = URI.create((metadataMap.get(property.toString()).toString())); | ||
| return uri; | ||
| } catch (NullPointerException e) { | ||
| throw new IllegalStateException("Metadata map is null or does not contain property: " + property, e); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -484,6 +484,26 @@ private List<Resource> sortConstraintQueries(List<Resource> constraintQueries) { | |||||||||||||||||||||||||||||||||||||||
| }).collect(Collectors.toList()); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private String functionName; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public void setFunctionName(String functionName) { | ||||||||||||||||||||||||||||||||||||||||
| this.functionName = functionName; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public String getFunctionName() { | ||||||||||||||||||||||||||||||||||||||||
| return functionName; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private String scriptPath; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public void setScriptPath(String scriptPath) { | ||||||||||||||||||||||||||||||||||||||||
| this.scriptPath = scriptPath; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public String getScriptPath() { | ||||||||||||||||||||||||||||||||||||||||
| return scriptPath; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+487
to
+506
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we do not need any of this ... everything is available in ExecutionContext right? |
||||||||||||||||||||||||||||||||||||||||
| // @Override | ||||||||||||||||||||||||||||||||||||||||
| // public String toString() { | ||||||||||||||||||||||||||||||||||||||||
| // String resourceId = (resource != null) ? ( " (" + resource.getId() + ")") : ""; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would refactor the name as suggested to be compliant with execution to existing module instead of execution of a function that references to the module.
Some use-cases are described in:
s-pipes/s-pipes-web/src/main/java/cz/cvut/spipes/rest/SPipesServiceController.java
Line 90 in 6f1d537