Skip to content
Snippets Groups Projects
Commit da74aec5 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

fix progress

parent 407d3648
Branches
Tags
No related merge requests found
...@@ -170,6 +170,8 @@ public class BenchmarkJobManager { ...@@ -170,6 +170,8 @@ public class BenchmarkJobManager {
if (tasks == null) { if (tasks == null) {
fillTasks(); fillTasks();
} }
// Carry on in output processing
processOutput();
return tasks; return tasks;
} }
...@@ -203,8 +205,7 @@ public class BenchmarkJobManager { ...@@ -203,8 +205,7 @@ public class BenchmarkJobManager {
List<String> chronologicList = STATISTICS_TASK_NAME_MAP.keySet().stream().collect(Collectors.toList()); List<String> chronologicList = STATISTICS_TASK_NAME_MAP.keySet().stream().collect(Collectors.toList());
Collections.sort(tasks, Comparator.comparingInt(task -> chronologicList.indexOf(task.getDescription()))); Collections.sort(tasks, Comparator.comparingInt(task -> chronologicList.indexOf(task.getDescription())));
// Carry on in output processing
processOutput();
} }
private void processOutput() { private void processOutput() {
......
...@@ -10,93 +10,98 @@ public class TaskComputation { ...@@ -10,93 +10,98 @@ public class TaskComputation {
private final SPIMComputationAccessor computationAccessor; private final SPIMComputationAccessor computationAccessor;
private final int timepoint; private final int timepoint;
private JobState state; private JobState state;
private int positionInOutput; private int positionInOutput;
private Collection<String> inputs; private Collection<String> inputs;
@SuppressWarnings("unused")
private Collection<String> outputs; private Collection<String> outputs;
private Collection<String> logs; private Collection<String> logs;
private Long id; private Long id;
/** /**
* Creates a TaskComputation object * Creates a TaskComputation object Note: At the time of creation, the job
* Note: At the time of creation, the job parameters are not populated * parameters are not populated
*/ */
public TaskComputation(SPIMComputationAccessor computationAccessor, int timepoint) { public TaskComputation(SPIMComputationAccessor computationAccessor, int timepoint) {
this.computationAccessor = computationAccessor; this.computationAccessor = computationAccessor;
this.timepoint = timepoint; this.timepoint = timepoint;
this.state = JobState.Unknown; this.state = JobState.Unknown;
updateState(); updateState();
} }
/** /**
* @return current job state * @return current job state
*/ */
public JobState getState() { public JobState getState() {
updateState();
return state; return state;
} }
/** /**
* @return job timepoint * @return job timepoint
*/ */
public int getTimepoint() { public int getTimepoint() {
return timepoint; return timepoint;
} }
/** /**
* @return job id * @return job id
*/ */
public Long getId() { public Long getId() {
return id; return id;
} }
// TODO: Method stub // TODO: Method stub
public void update() { public void update() {
} }
/** /**
* Populates parameters of the current object by searching the output * Populates parameters of the current object by searching the output
* @param positionInOutput: Index of the output position to search from *
* @param positionInOutput:
* Index of the output position to search from
* @return success flag * @return success flag
*/ */
public boolean populateParameters(int positionInOutput) { public boolean populateParameters(int positionInOutput) {
// Should the state be different than unknown, there is no need to populate parameters // Should the state be different than unknown, there is no need to populate
// parameters
if (state != JobState.Unknown) { if (state != JobState.Unknown) {
return false; return false;
} }
this.positionInOutput = positionInOutput; this.positionInOutput = positionInOutput;
if (!resolveJobParameters()) { if (!resolveJobParameters()) {
return false; return false;
} }
state = JobState.Queued; state = JobState.Queued;
updateState(); updateState();
return true; return true;
} }
private void updateState() { private void updateState() {
// Should the state be queued, try to find out whether a log file exists // Should the state be queued, try to find out whether a log file exists
if (state == JobState.Queued ) { if (state == JobState.Queued) {
if (!logs.stream().anyMatch(logFile -> computationAccessor.fileExists(logFile))) { if (null != logs && !logs.stream().anyMatch(logFile -> computationAccessor.fileExists(logFile))) {
return; // No log file exists yet return; // No log file exists yet
} }
state = JobState.Running; state = JobState.Running;
} }
// Finally, look up any traces that the job has failed or finished // Finally, look up any traces that the job has failed or finished
if (state == JobState.Running) { if (state == JobState.Running) {
final String OUTPUT_PARSING_FINISHED_JOB = "Finished job "; final String OUTPUT_PARSING_FINISHED_JOB = "Finished job ";
final String desiredPatternFinishedJob = OUTPUT_PARSING_FINISHED_JOB + id.toString(); final String desiredPatternFinishedJob = OUTPUT_PARSING_FINISHED_JOB + id.toString();
final String OUTPUT_PARSING_ERRONEOUS_JOB = "Error job "; final String OUTPUT_PARSING_ERRONEOUS_JOB = "Error job ";
final String desiredPatternErroneousJob = OUTPUT_PARSING_ERRONEOUS_JOB + id.toString(); final String desiredPatternErroneousJob = OUTPUT_PARSING_ERRONEOUS_JOB + id.toString();
Scanner scanner = new Scanner(computationAccessor.getActualOutput().substring(positionInOutput)); Scanner scanner = new Scanner(computationAccessor.getActualOutput().substring(positionInOutput));
String currentLine; String currentLine;
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
...@@ -112,15 +117,15 @@ public class TaskComputation { ...@@ -112,15 +117,15 @@ public class TaskComputation {
scanner.close(); scanner.close();
} }
} }
private boolean resolveJobParameters() { private boolean resolveJobParameters() {
final String OUTPUT_PARSING_COMMA_SPACE = ", "; final String OUTPUT_PARSING_COMMA_SPACE = ", ";
final String OUTPUT_PARSING_INPUTS = "input: "; final String OUTPUT_PARSING_INPUTS = "input: ";
final String OUTPUT_PARSING_OUTPUTS = "output: "; final String OUTPUT_PARSING_OUTPUTS = "output: ";
final String OUTPUT_PARSING_LOGS = "log: "; final String OUTPUT_PARSING_LOGS = "log: ";
final String OUTPUT_PARSING_JOB_ID = "jobid: "; final String OUTPUT_PARSING_JOB_ID = "jobid: ";
Scanner scanner = new Scanner(computationAccessor.getActualOutput().substring(positionInOutput)); Scanner scanner = new Scanner(computationAccessor.getActualOutput().substring(positionInOutput));
String currentLine; String currentLine;
while (scanner.hasNextLine()) { while (scanner.hasNextLine()) {
...@@ -131,16 +136,15 @@ public class TaskComputation { ...@@ -131,16 +136,15 @@ public class TaskComputation {
outputs = Arrays.asList(currentLine.split(OUTPUT_PARSING_OUTPUTS)[1].split(OUTPUT_PARSING_COMMA_SPACE)); outputs = Arrays.asList(currentLine.split(OUTPUT_PARSING_OUTPUTS)[1].split(OUTPUT_PARSING_COMMA_SPACE));
} else if (currentLine.contains(OUTPUT_PARSING_LOGS)) { } else if (currentLine.contains(OUTPUT_PARSING_LOGS)) {
logs = Arrays.asList(currentLine.split(OUTPUT_PARSING_LOGS)[1].split(OUTPUT_PARSING_COMMA_SPACE)); logs = Arrays.asList(currentLine.split(OUTPUT_PARSING_LOGS)[1].split(OUTPUT_PARSING_COMMA_SPACE));
} else } else if (currentLine.contains(OUTPUT_PARSING_JOB_ID)) {
if (currentLine.contains(OUTPUT_PARSING_JOB_ID)) {
id = Long.parseLong(currentLine.split(OUTPUT_PARSING_JOB_ID)[1]); id = Long.parseLong(currentLine.split(OUTPUT_PARSING_JOB_ID)[1]);
} else if (currentLine.trim().isEmpty()) { } else if (currentLine.trim().isEmpty()) {
break; break;
} }
} }
scanner.close(); scanner.close();
return !(inputs == null || outputs == null || logs == null || id == null); return !(inputs == null || id == null);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment