Skip to content
Snippets Groups Projects
Commit 03cb32eb authored by Petr Bainar's avatar Petr Bainar
Browse files

iss1011: committing preliminary implementation of the getState method

parent 48a79a0b
No related branches found
No related tags found
1 merge request!6Iss1011
...@@ -68,8 +68,8 @@ public class BenchmarkJobManager { ...@@ -68,8 +68,8 @@ public class BenchmarkJobManager {
} }
@Override @Override
public boolean fileExists(Path filePath) { public boolean fileExists(String filePath) {
File f = new File(filePath.toString()); File f = new File(filePath);
return f.exists() && !f.isDirectory(); return f.exists() && !f.isDirectory();
} }
}; };
......
...@@ -5,5 +5,5 @@ import java.nio.file.Path; ...@@ -5,5 +5,5 @@ import java.nio.file.Path;
import cz.it4i.fiji.haas.HaaSOutputHolder; import cz.it4i.fiji.haas.HaaSOutputHolder;
public interface SPIMComputationAccessor extends HaaSOutputHolder { public interface SPIMComputationAccessor extends HaaSOutputHolder {
boolean fileExists(Path fileName); boolean fileExists(String fileName);
} }
...@@ -24,6 +24,7 @@ public class TaskComputation { ...@@ -24,6 +24,7 @@ public class TaskComputation {
} }
} }
private final SPIMComputationAccessor computationAccessor;
private final Task task; private final Task task;
private final int timepoint; private final int timepoint;
private final Collection<String> inputs; private final Collection<String> inputs;
...@@ -34,14 +35,16 @@ public class TaskComputation { ...@@ -34,14 +35,16 @@ public class TaskComputation {
//TASK 1011 what states will be defined and how it will be defined //TASK 1011 what states will be defined and how it will be defined
private JobState state = JobState.Unknown; private JobState state = JobState.Unknown;
public TaskComputation(SPIMComputationAccessor outputHolder, Task task, int timepoint) { public TaskComputation(SPIMComputationAccessor computationAccessor, Task task, int timepoint) {
this.computationAccessor = computationAccessor;
this.task = task; this.task = task;
this.timepoint = timepoint; this.timepoint = timepoint;
ParsedTaskComputationValues parsedValues = parseStuff(outputHolder); ParsedTaskComputationValues parsedValues = parseStuff(computationAccessor);
this.inputs = parsedValues.inputs; this.inputs = parsedValues.inputs;
this.outputs = parsedValues.outputs; this.outputs = parsedValues.outputs;
this.logs = parsedValues.logs; this.logs = parsedValues.logs;
this.id = parsedValues.id; this.id = parsedValues.id;
updateState();
} }
public JobState getState() { public JobState getState() {
...@@ -52,14 +55,39 @@ public class TaskComputation { ...@@ -52,14 +55,39 @@ public class TaskComputation {
private void updateState() { private void updateState() {
//TASK 1011 This should never happen, add some error handling to resolveId() //TASK 1011 This should never happen, add some error handling to resolveId()
if (id == null) { if (id == null) {
state = JobState.Unknown;
return; return;
} }
//String snakeOutput = outputHolder.getActualOutput(); state = JobState.Queued;
//TASK 1011 // Check whether a log file exists
//resolve if job is queued (defined id), started (exists log file), finished (in log is Finished job 10.) or if (!logs.stream().anyMatch(logFile -> computationAccessor.fileExists(logFile))) {
//or failed (some error in log) return;
}
state = JobState.Running;
// Check whether the corresponding job has finished
final String OUTPUT_PARSING_FINISHED_JOB = "Finished job ";
final String desiredPatternFinishedJob = OUTPUT_PARSING_FINISHED_JOB + id.toString();
final String OUTPUT_PARSING_ERRONEOUS_JOB = "Error job ";
final String desiredPatternErroneousJob = OUTPUT_PARSING_ERRONEOUS_JOB + id.toString();
String currentLine;
Scanner scanner = new Scanner(computationAccessor.getActualOutput());
while (scanner.hasNextLine()) {
currentLine = scanner.nextLine();
if (currentLine.contains(desiredPatternErroneousJob)) {
state = JobState.Failed;
break;
} else if (currentLine.contains(desiredPatternFinishedJob)) {
state = JobState.Finished;
break;
}
}
scanner.close();
return;
} }
private Long getId() { private Long getId() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment