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

add command for download of statistics

parent 5c7b5818
No related branches found
No related tags found
No related merge requests found
...@@ -50,13 +50,10 @@ public class Job { ...@@ -50,13 +50,10 @@ public class Job {
private Boolean needsDownload; private Boolean needsDownload;
private JobInfo jobInfo; private JobInfo jobInfo;
private Long jobId; private Long jobId;
private String name; private String name;
public Job(String name, Path basePath, Supplier<HaaSClient> haasClientSupplier) public Job(String name, Path basePath, Supplier<HaaSClient> haasClientSupplier) throws IOException {
throws IOException {
this(haasClientSupplier); this(haasClientSupplier);
HaaSClient client = this.haasClientSupplier.get(); HaaSClient client = this.haasClientSupplier.get();
long id = client.createJob(name, Collections.emptyList()); long id = client.createJob(name, Collections.emptyList());
...@@ -105,10 +102,8 @@ public class Job { ...@@ -105,10 +102,8 @@ public class Job {
return jobId; return jobId;
} }
public void download(Progress notifier) { public void download(Progress notifier) {
download(x -> true, notifier); download(x -> true, notifier, false);
} }
public Path storeDataInWorkdirectory(UploadingFile uploadingFile) throws IOException { public Path storeDataInWorkdirectory(UploadingFile uploadingFile) throws IOException {
...@@ -119,16 +114,18 @@ public class Job { ...@@ -119,16 +114,18 @@ public class Job {
return result; return result;
} }
synchronized public void download(Predicate<String> predicate, Progress notifier) { synchronized public void download(Predicate<String> predicate, Progress notifier, boolean allowAgain) {
if (!needsDownload()) { if (!allowAgain && !needsDownload()) {
throw new IllegalStateException("Job: " + getJobId() + " doesn't need download"); throw new IllegalStateException("Job: " + getJobId() + " doesn't need download");
} }
haasClientSupplier.get().download(getJobId(), jobDir, predicate, new P_ProgressNotifierAdapter(notifier)); haasClientSupplier.get().download(getJobId(), jobDir, predicate, new P_ProgressNotifierAdapter(notifier));
needsDownload = false; if(!allowAgain) {
try { needsDownload = false;
saveJobinfo(); try {
} catch (IOException e) { saveJobinfo();
log.error(e); } catch (IOException e) {
log.error(e);
}
} }
} }
...@@ -169,11 +166,11 @@ public class Job { ...@@ -169,11 +166,11 @@ public class Job {
public String getProperty(String name) throws IOException { public String getProperty(String name) throws IOException {
return loadPropertiesIfExists().getProperty(name); return loadPropertiesIfExists().getProperty(name);
} }
public void updateInfo() { public void updateInfo() {
updateJobInfo(); updateJobInfo();
} }
public Path getDirectory() { public Path getDirectory() {
return jobDir; return jobDir;
} }
...@@ -284,6 +281,4 @@ public class Job { ...@@ -284,6 +281,4 @@ public class Job {
} }
} }
...@@ -163,11 +163,11 @@ public class JobManager { ...@@ -163,11 +163,11 @@ public class JobManager {
} }
public void downloadData(Progress notifier) { public void downloadData(Progress notifier) {
downloadData(x -> true, notifier); downloadData(x -> true, notifier, false);
} }
public void downloadData(Predicate<String> predicate, Progress notifier) { public void downloadData(Predicate<String> predicate, Progress notifier, boolean allowAgain) {
job.download(predicate, notifier); job.download(predicate, notifier, allowAgain);
fireValueChangedEvent(); fireValueChangedEvent();
} }
......
...@@ -26,15 +26,16 @@ import javafx.beans.value.ObservableValueBase; ...@@ -26,15 +26,16 @@ import javafx.beans.value.ObservableValueBase;
import net.imagej.updater.util.Progress; import net.imagej.updater.util.Progress;
public class BenchmarkJobManager { public class BenchmarkJobManager {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Logger log = LoggerFactory private static Logger log = LoggerFactory
.getLogger(cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.class); .getLogger(cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.class);
public final class Job extends ObservableValueBase<Job> { public final class Job extends ObservableValueBase<Job> {
private JobInfo jobInfo; private JobInfo jobInfo;
private JobState oldState; private JobState oldState;
public Job(JobInfo ji) { public Job(JobInfo ji) {
super(); super();
this.jobInfo = ji; this.jobInfo = ji;
...@@ -56,12 +57,16 @@ public class BenchmarkJobManager { ...@@ -56,12 +57,16 @@ public class BenchmarkJobManager {
if (ji.needsDownload()) { if (ji.needsDownload()) {
if (ji.getState() == JobState.Finished) { if (ji.getState() == JobState.Finished) {
String filePattern = ji.getProperty(SPIM_OUTPUT_FILENAME_PATTERN); String filePattern = ji.getProperty(SPIM_OUTPUT_FILENAME_PATTERN);
ji.downloadData(downloadFinishedData(filePattern), progress); ji.downloadData(downloadFinishedData(filePattern), progress, false);
} else if (ji.getState() == JobState.Failed) { } else if (ji.getState() == JobState.Failed) {
ji.downloadData(downloadFailedData(), progress); ji.downloadData(downloadFailedData(), progress, false);
} }
} }
}
public void downloadStatistics(Progress progress) throws IOException {
JobInfo ji = jobInfo;
ji.downloadData(BenchmarkJobManager.downloadStatistics(), progress, true);
} }
public List<String> getOutput(List<JobSynchronizableFile> files) { public List<String> getOutput(List<JobSynchronizableFile> files) {
...@@ -111,8 +116,6 @@ public class BenchmarkJobManager { ...@@ -111,8 +116,6 @@ public class BenchmarkJobManager {
} }
} }
public boolean downloaded() { public boolean downloaded() {
return !jobInfo.needsDownload(); return !jobInfo.needsDownload();
} }
...@@ -137,7 +140,7 @@ public class BenchmarkJobManager { ...@@ -137,7 +140,7 @@ public class BenchmarkJobManager {
private static final String CONFIG_YAML = "config.yaml"; private static final String CONFIG_YAML = "config.yaml";
private JobManager jobManager; private JobManager jobManager;
public BenchmarkJobManager(BenchmarkSPIMParameters params) throws IOException { public BenchmarkJobManager(BenchmarkSPIMParameters params) throws IOException {
jobManager = new JobManager(params.workingDirectory(), constructSettingsFromParams(params)); jobManager = new JobManager(params.workingDirectory(), constructSettingsFromParams(params));
} }
...@@ -149,7 +152,7 @@ public class BenchmarkJobManager { ...@@ -149,7 +152,7 @@ public class BenchmarkJobManager {
} }
public Collection<Job> getJobs() throws IOException { public Collection<Job> getJobs() throws IOException {
return jobManager.getJobs().stream().map(this::convertJob).collect(Collectors.toList()); return jobManager.getJobs().stream().map(this::convertJob).collect(Collectors.toList());
} }
...@@ -191,6 +194,14 @@ public class BenchmarkJobManager { ...@@ -191,6 +194,14 @@ public class BenchmarkJobManager {
}; };
} }
static private Predicate<String> downloadStatistics() {
return name -> {
Path p = Paths.get(name);
String fileName = p.getFileName().toString();
return fileName.equals("benchmark_result.csv");
};
}
private Predicate<String> downloadFailedData() { private Predicate<String> downloadFailedData() {
return name -> { return name -> {
Path p = Paths.get(name); Path p = Paths.get(name);
......
...@@ -94,9 +94,13 @@ public class BenchmarkSPIMController implements FXFrame.Controller { ...@@ -94,9 +94,13 @@ public class BenchmarkSPIMController implements FXFrame.Controller {
menu.addItem("Create job", x -> executeJobActionAsync("Creating job", p -> manager.createJob()), j -> true); menu.addItem("Create job", x -> executeJobActionAsync("Creating job", p -> manager.createJob()), j -> true);
menu.addItem("Start job", job -> executeJobActionAsync("Starting job", p -> job.startJob(p)), menu.addItem("Start job", job -> executeJobActionAsync("Starting job", p -> job.startJob(p)),
job -> notNullValue(job, j -> j.getState() == JobState.Configuring)); job -> notNullValue(job, j -> j.getState() == JobState.Configuring));
menu.addItem("Download", job -> executeJobActionAsync("Downloading data", p -> job.downloadData(p)), menu.addItem("Download result", job -> executeJobActionAsync("Downloading data", p -> job.downloadData(p)),
job -> notNullValue(job, job -> notNullValue(job,
j -> EnumSet.of(JobState.Failed, JobState.Finished).contains(j.getState()) && !j.downloaded())); j -> EnumSet.of(JobState.Failed, JobState.Finished).contains(j.getState()) && !j.downloaded()));
menu.addItem("Download statistics",
job -> executeJobActionAsync("Downloading data", p -> job.downloadStatistics(p)),
job -> notNullValue(job, j -> j.getState() == JobState.Finished));
menu.addItem("Show output", j -> new JobOutputView(root, executorService, j, Constants.HAAS_UPDATE_TIMEOUT), menu.addItem("Show output", j -> new JobOutputView(root, executorService, j, Constants.HAAS_UPDATE_TIMEOUT),
job -> notNullValue(job, job -> notNullValue(job,
j -> EnumSet.of(JobState.Failed, JobState.Finished, JobState.Running).contains(j.getState()))); j -> EnumSet.of(JobState.Failed, JobState.Finished, JobState.Running).contains(j.getState())));
......
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