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

iss1011: moving output parsing to BenchmarkJob

parent 8a3a764a
No related branches found
No related tags found
1 merge request!8Iss1011
......@@ -63,6 +63,8 @@ public class BenchmarkJobManager {
private SPIMComputationAccessor computationAccessor;
private int processedOutputLength = 0;
public BenchmarkJob(Job job) {
this.job = job;
......@@ -200,6 +202,39 @@ public class BenchmarkJobManager {
// Order tasks chronologically
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() {
final String OUTPUT_PARSING_RULE = "rule ";
final String OUTPUT_PARSING_COLON = ":";
String output = computationAccessor.getActualOutput().substring(processedOutputLength);
int outputLengthToBeProcessed = output.length();
int ruleRelativeIndex = -1;
int colonRelativeIndex = -1;
while (true) {
ruleRelativeIndex = output.indexOf(OUTPUT_PARSING_RULE, colonRelativeIndex);
colonRelativeIndex = output.indexOf(OUTPUT_PARSING_COLON, ruleRelativeIndex);
if (ruleRelativeIndex == -1 || colonRelativeIndex == -1) {
break;
}
String taskDescription = output.substring(ruleRelativeIndex + OUTPUT_PARSING_RULE.length(), colonRelativeIndex);
List<Task> task = tasks.stream().filter(t -> t.getDescription().equals(taskDescription)).collect(Collectors.toList());
if (1 == task.size()) {
// TODO: Consider throwing an exception
task.get(0).populateTaskComputationParameters(processedOutputLength + ruleRelativeIndex);
}
}
processedOutputLength = processedOutputLength + outputLengthToBeProcessed;
}
private void setDownloaded(boolean b) {
......
package cz.it4i.fiji.haas_spim_benchmark.core;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import cz.it4i.fiji.haas_java_client.JobState;
public class Task {
private final String description;
private final List<TaskComputation> computations;
public Task(SPIMComputationAccessor outputHolder, String description, int numComputations) {
public Task(SPIMComputationAccessor computationAccessor, String description, int numOfExpectedComputations) {
this.description = description;
this.computations = new LinkedList<>();
for (int i = 0; i < numComputations; i++) {
computations.add(new TaskComputation(outputHolder, this, i + 1));
this.computations = new LinkedList<>();
for (int i = 0; i < numOfExpectedComputations; i++) {
computations.add(new TaskComputation(computationAccessor, i + 1));
}
}
/**
* Looks up next task computation (i.e. with lowest timepoint) of the current task and populates its parameters
* @param positionInOutput: Index of the output position to search from
* @return success flag
*/
public boolean populateTaskComputationParameters(int positionInOutput) {
TaskComputation tc = computations.stream()
.filter(c -> c.getState().equals(JobState.Unknown))
.min(Comparator.comparingInt(c -> c.getTimepoint()))
.get();
if (null == tc) {
return false;
}
return tc.populateParameters(positionInOutput);
}
/**
* @return task description
*/
public String getDescription() {
return description;
}
/**
* @return list of task computations
*/
public List<TaskComputation> getComputations() {
return computations;
}
// TODO: Method stub
public void update() {
// TODO Auto-generated method stub
}
}
......@@ -9,7 +9,6 @@ import cz.it4i.fiji.haas_java_client.JobState;
public class TaskComputation {
private final SPIMComputationAccessor computationAccessor;
private final Task task;
private final int timepoint;
private JobState state;
......@@ -20,36 +19,68 @@ public class TaskComputation {
private Collection<String> logs;
private Long id;
public TaskComputation(SPIMComputationAccessor computationAccessor, Task task, int timepoint) {
/**
* 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.task = task;
this.timepoint = timepoint;
this.state = JobState.Unknown;
updateState();
}
/**
* @return current job state
*/
public JobState getState() {
updateState();
return state;
}
public void update() {
}
/**
* @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
* @return success flag
*/
public boolean populateParameters(int positionInOutput) {
// 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;
updateState();
return true;
}
private void updateState() {
// Should the state be undefined (null), try to look up job position in the computation output
if (state == null) {
positionInOutput = findPositionInOutput();
if (0 > positionInOutput || !resolveJobParameters()) {
return; // Job position has not been found or its parameters could not be resolved
}
state = JobState.Queued;
}
// 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))) {
......@@ -81,21 +112,7 @@ public class TaskComputation {
scanner.close();
}
}
private int findPositionInOutput() {
final String OUTPUT_PARSING_RULE = "rule ";
final String OUTPUT_PARSING_COLON = ":";
final String desiredPattern = OUTPUT_PARSING_RULE + task.getDescription() + OUTPUT_PARSING_COLON;
int taskComputationLineIndex = -1;
for (int i = 0; i < timepoint; i++) {
taskComputationLineIndex = computationAccessor.getActualOutput().indexOf(desiredPattern, taskComputationLineIndex);
}
return taskComputationLineIndex;
}
private boolean resolveJobParameters() {
final String OUTPUT_PARSING_COMMA_SPACE = ", ";
......
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