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

fix progress

parent 407d3648
No related branches found
No related tags found
No related merge requests found
......@@ -170,6 +170,8 @@ public class BenchmarkJobManager {
if (tasks == null) {
fillTasks();
}
// Carry on in output processing
processOutput();
return tasks;
}
......@@ -203,8 +205,7 @@ public class BenchmarkJobManager {
List<String> chronologicList = STATISTICS_TASK_NAME_MAP.keySet().stream().collect(Collectors.toList());
Collections.sort(tasks, Comparator.comparingInt(task -> chronologicList.indexOf(task.getDescription())));
// Carry on in output processing
processOutput();
}
private void processOutput() {
......
......@@ -10,93 +10,98 @@ public class TaskComputation {
private final SPIMComputationAccessor computationAccessor;
private final int timepoint;
private JobState state;
private int positionInOutput;
private Collection<String> inputs;
@SuppressWarnings("unused")
private Collection<String> outputs;
private Collection<String> logs;
private Long id;
/**
* Creates a TaskComputation object
* Note: At the time of creation, the job parameters are not populated
*/
* Creates a TaskComputation object Note: At the time of creation, the job
* parameters are not populated
*/
public TaskComputation(SPIMComputationAccessor computationAccessor, int timepoint) {
this.computationAccessor = computationAccessor;
this.timepoint = timepoint;
this.state = JobState.Unknown;
updateState();
}
/**
* @return current job state
*/
public JobState getState() {
updateState();
return state;
}
/**
* @return job timepoint
*/
public int getTimepoint() {
return timepoint;
}
/**
* @return job id
*/
public Long getId() {
return id;
}
// TODO: Method stub
public void update() {
}
/**
* 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
*/
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) {
return false;
}
this.positionInOutput = positionInOutput;
if (!resolveJobParameters()) {
return false;
}
state = JobState.Queued;
state = JobState.Queued;
updateState();
return true;
}
private void updateState() {
// Should the state be queued, try to find out whether a log file exists
if (state == JobState.Queued ) {
if (!logs.stream().anyMatch(logFile -> computationAccessor.fileExists(logFile))) {
if (state == JobState.Queued) {
if (null != logs && !logs.stream().anyMatch(logFile -> computationAccessor.fileExists(logFile))) {
return; // No log file exists yet
}
state = JobState.Running;
state = JobState.Running;
}
// Finally, look up any traces that the job has failed or finished
if (state == JobState.Running) {
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();
Scanner scanner = new Scanner(computationAccessor.getActualOutput().substring(positionInOutput));
String currentLine;
while (scanner.hasNextLine()) {
......@@ -112,15 +117,15 @@ public class TaskComputation {
scanner.close();
}
}
private boolean resolveJobParameters() {
final String OUTPUT_PARSING_COMMA_SPACE = ", ";
final String OUTPUT_PARSING_INPUTS = "input: ";
final String OUTPUT_PARSING_OUTPUTS = "output: ";
final String OUTPUT_PARSING_LOGS = "log: ";
final String OUTPUT_PARSING_JOB_ID = "jobid: ";
Scanner scanner = new Scanner(computationAccessor.getActualOutput().substring(positionInOutput));
String currentLine;
while (scanner.hasNextLine()) {
......@@ -131,16 +136,15 @@ public class TaskComputation {
outputs = Arrays.asList(currentLine.split(OUTPUT_PARSING_OUTPUTS)[1].split(OUTPUT_PARSING_COMMA_SPACE));
} else if (currentLine.contains(OUTPUT_PARSING_LOGS)) {
logs = Arrays.asList(currentLine.split(OUTPUT_PARSING_LOGS)[1].split(OUTPUT_PARSING_COMMA_SPACE));
} else
if (currentLine.contains(OUTPUT_PARSING_JOB_ID)) {
} else if (currentLine.contains(OUTPUT_PARSING_JOB_ID)) {
id = Long.parseLong(currentLine.split(OUTPUT_PARSING_JOB_ID)[1]);
} else if (currentLine.trim().isEmpty()) {
break;
break;
}
}
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.
Finish editing this message first!
Please register or to comment