Skip to content

Commit

Permalink
Handle internal error for wf execution
Browse files Browse the repository at this point in the history
  • Loading branch information
hvarg committed Apr 3, 2024
1 parent dd4984d commit aaba050
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ metadata and outputs for posterior analysis.

Full documentation is available at [https://disk.readthedocs.io](https://disk.readthedocs.io)


## Installation

Please read the installation guide available at [readthedocs.io](https://disk.readthedocs.io/en/stable/admin-guide/installation/)

## Related repositories

- [DISK User Interface](https://github.com/KnowledgeCaptureAndDiscovery/DISK-UI)
18 changes: 9 additions & 9 deletions server/src/main/java/org/diskproject/server/db/DiskDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,13 @@ public boolean deleteGoal(String id) {
return false;

String goalId = createGoalURI(id);
KBAPI hypKB = getKB(goalId);
KBAPI goalKB = getKB(goalId);

if (domainKB != null && hypKB != null) {
if (domainKB != null && goalKB != null) {
this.rdf.startRead();
KBObject hypitem = domainKB.getIndividual(goalId);
if (hypitem != null) {
ArrayList<KBObject> questionBindings = domainKB.getPropertyValues(hypitem,
KBObject goalItem = domainKB.getIndividual(goalId);
if (goalItem != null) {
ArrayList<KBObject> questionBindings = domainKB.getPropertyValues(goalItem,
DISKOnt.getProperty(DISK.HAS_QUESTION_BINDINGS));
this.rdf.end();
// Remove question template bindings
Expand All @@ -474,14 +474,14 @@ public boolean deleteGoal(String id) {
for (KBObject binding : questionBindings) {
domainKB.deleteObject(binding, true, true);
}
domainKB.deleteObject(hypitem, true, true);
domainKB.deleteObject(goalItem, true, false);
this.rdf.save(domainKB);
this.rdf.end();
} else {
this.rdf.end();
}

return this.rdf.startWrite() && hypKB.delete() && this.rdf.save(hypKB) && this.rdf.end();
return this.rdf.startWrite() && goalKB.delete() && this.rdf.save(goalKB) && this.rdf.end();
}
return false;
}
Expand Down Expand Up @@ -691,7 +691,7 @@ public boolean deleteLOI(String id) {
this.rdf.startWrite();
KBObject hypitem = domainKB.getIndividual(loiId);
if (hypitem != null)
domainKB.deleteObject(hypitem, true, true);
domainKB.deleteObject(hypitem, true, false);
//TODO: remove query object too.

return this.rdf.save(domainKB) && this.rdf.end();
Expand Down Expand Up @@ -1169,7 +1169,7 @@ public boolean deleteTLOI(String id) {
this.rdf.end();
if (item != null) {
this.rdf.startWrite();
domainKB.deleteObject(item, true, true);
domainKB.deleteObject(item, true, false);
return this.rdf.save(domainKB) && this.rdf.end();
} else {
return false;
Expand Down
30 changes: 20 additions & 10 deletions server/src/main/java/org/diskproject/server/quering/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public Match (Goal goal, LineOfInquiry loi, Question question, DataAdapter dataS
return;
}

this.valid = this.analyseWorkflows();
this.valid = this.analyzeWorkflows();
}

private boolean analyseWorkflows () {
private boolean analyzeWorkflows () {
boolean isCSV = false;
List<WorkflowSeed> allSeeds = Stream.concat(loi.getWorkflowSeeds().stream(), loi.getMetaWorkflowSeeds().stream()).collect(Collectors.toList());
Set<String> reqVariables = new HashSet<String>(), arrayVars = new HashSet<String>(), selectVars = new HashSet<String>();
Expand Down Expand Up @@ -143,21 +143,31 @@ public String createQueryTemplate () {
String varName = questionVariables.get(varURI);
if (varNames.contains(varName)) {
boolean writtenVarName = false;
for (String value: vb.getBinding()) {
List<String> allValues = vb.getBinding();
for (String value: allValues) {
if (value != null && !value.equals("")) {
String datatype = vb.getDatatype();
if (!writtenVarName) {
query += "\nVALUES " + varName + " {\n";
query += "\n VALUES " + varName + " {";
if (allValues.size() > 1) {
query += "\n";
}
writtenVarName = true;
}
if (datatype != null && datatype.endsWith("anyURI")) {
query += " <" + value + ">\n";
query += " <" + value + ">";
} else {
query += " \"" + value + "\"\n";
query += " \"" + value + "\"";
}
if (allValues.size() > 1) {
query += "\n";
}
}
}
if (writtenVarName) {
if (allValues.size() > 1) {
query += " ";
}
query += "}";
}
}
Expand Down Expand Up @@ -245,12 +255,12 @@ private List<WorkflowInstantiation> createWorkflowInstance (WorkflowSeed seed) {
int count = 0, splitSize = filteredResults.size()/runs;
for (DataResult cell: filteredResults) {
count += 1;
lastList.add(cell);
if (count >= splitSize) {
count = 0;
independentResults.add(lastList);
lastList = new ArrayList<DataResult>();
}
lastList.add(cell);
}

List<WorkflowInstantiation> inst = new ArrayList<WorkflowInstantiation>();
Expand All @@ -260,7 +270,7 @@ private List<WorkflowInstantiation> createWorkflowInstance (WorkflowSeed seed) {
for (VariableBinding varB: Stream.concat(seed.getInputs().stream(), seed.getParameters().stream()).collect(Collectors.toList())) {
// These only have one value
String wfBiding = varB.getBinding().get(0);
VariableBinding newDatabinding = new VariableBinding(varB);
VariableBinding newDataBinding = new VariableBinding(varB);
List<String> newBindingValues = new ArrayList<String>();
if (wfBiding.equals(SPECIAL.CSV)) {
newBindingValues.add(csvURL);
Expand All @@ -283,8 +293,8 @@ private List<WorkflowInstantiation> createWorkflowInstance (WorkflowSeed seed) {
}
}
if (newBindingValues.size() > 0) {
newDatabinding.setBinding(newBindingValues);
dataBindings.add(newDatabinding);
newDataBinding.setBinding(newBindingValues);
dataBindings.add(newDataBinding);
}
}
current.setDataBindings(dataBindings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ public Map<LineOfInquiry, List<Map<String, String>>> getLOIByHypothesisId(String
if (allSolutions != null) {
if (allSolutions.size() == 0) {
System.out.println("No solutions for " + loi.getId());
//System.out.println(errorMesString);
//String errorMesString = "No solutions found for the query: \n" + query;
//System.out.println(errorMesString);
// throw new NotFoundException(errorMesString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void updateRun (WorkflowInstantiation wf, Execution run) {

@Override
public void run() {
System.out.println("[M] Running monitoring thread");
//System.out.println("[M] Running monitoring thread");
Execution pendingRun = this.getNextPendingRun();
if (pendingRun == null || pendingRun.getExternalId() == null) {
System.out.println("[M] No more pending runs.");
Expand All @@ -106,10 +106,13 @@ public void run() {
Execution updatedRun = methodAdapter.getRunStatus(runId);

// If we cannot get the status but the run was pending, it means that the run is in the WINGS queue.
if (updatedRun == null || updatedRun.getStatus() == null) {
if (updatedRun == null || updatedRun.getStatus() == null || updatedRun.getStatus() == Status.INTERNAL_ERROR) {
System.out.println("[E] Cannot get status for " + tloi.getId() + " - RUN " + runId);
if (pendingRun.getStatus() == Status.PENDING) { // In queue
updatedRun = pendingRun;
} else if (updatedRun != null && updatedRun.getStatus() == Status.INTERNAL_ERROR) {
updatedRun.setStatus(Status.FAILED);
System.out.println("[E] Internal error for run: " + runId);
} else {
System.out.println("[E] This should not happen");
return;
Expand All @@ -122,15 +125,15 @@ public void run() {
this.tloi.setStatus(status);
manager.updateTLOI(tloi);

if (status == Status.SUCCESSFUL || status == Status.FAILED) {
if (status == Status.SUCCESSFUL || status == Status.FAILED || status == Status.INTERNAL_ERROR) {
if (status == Status.SUCCESSFUL) {
if (metamode) {
System.out.println("[M] " + this.tloi.getId() + " was successfully executed.");
} else {
System.out.println("[M] Starting metamode after " + this.runList.size() + " runs.");
this.manager.executeTLOI(tloi, true);
}
} else if (status == Status.FAILED) {
} else if (status == Status.FAILED || status == Status.INTERNAL_ERROR) {
if (metamode) {
System.out.println("[M] " + this.tloi.getId() + " was executed with errors.");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.diskproject.shared.classes.workflow.Execution;
import org.diskproject.shared.classes.workflow.VariableBinding;
import org.diskproject.shared.classes.workflow.WorkflowTemplate;
import org.diskproject.shared.classes.workflow.WorkflowRun;

public abstract class MethodAdapter {
private String name;
Expand Down

0 comments on commit aaba050

Please sign in to comment.