From c8a91c818c5640a86ce1493e19ca0aecdbd49ff7 Mon Sep 17 00:00:00 2001 From: Jan Kozusznik <jan@kozusznik.cz> Date: Mon, 22 Jan 2018 11:00:38 +0100 Subject: [PATCH] add command for download of statistics --- .../src/main/java/cz/it4i/fiji/haas/Job.java | 31 ++++++++----------- .../java/cz/it4i/fiji/haas/JobManager.java | 6 ++-- .../core/BenchmarkJobManager.java | 27 +++++++++++----- .../ui/BenchmarkSPIMController.java | 6 +++- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java index 38058e58..0c226e28 100644 --- a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java +++ b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java @@ -50,13 +50,10 @@ public class Job { private Boolean needsDownload; private JobInfo jobInfo; private Long jobId; - - private String name; - public Job(String name, Path basePath, Supplier<HaaSClient> haasClientSupplier) - throws IOException { + public Job(String name, Path basePath, Supplier<HaaSClient> haasClientSupplier) throws IOException { this(haasClientSupplier); HaaSClient client = this.haasClientSupplier.get(); long id = client.createJob(name, Collections.emptyList()); @@ -105,10 +102,8 @@ public class Job { return jobId; } - - public void download(Progress notifier) { - download(x -> true, notifier); + download(x -> true, notifier, false); } public Path storeDataInWorkdirectory(UploadingFile uploadingFile) throws IOException { @@ -119,16 +114,18 @@ public class Job { return result; } - synchronized public void download(Predicate<String> predicate, Progress notifier) { - if (!needsDownload()) { + synchronized public void download(Predicate<String> predicate, Progress notifier, boolean allowAgain) { + if (!allowAgain && !needsDownload()) { throw new IllegalStateException("Job: " + getJobId() + " doesn't need download"); } haasClientSupplier.get().download(getJobId(), jobDir, predicate, new P_ProgressNotifierAdapter(notifier)); - needsDownload = false; - try { - saveJobinfo(); - } catch (IOException e) { - log.error(e); + if(!allowAgain) { + needsDownload = false; + try { + saveJobinfo(); + } catch (IOException e) { + log.error(e); + } } } @@ -169,11 +166,11 @@ public class Job { public String getProperty(String name) throws IOException { return loadPropertiesIfExists().getProperty(name); } - + public void updateInfo() { updateJobInfo(); } - + public Path getDirectory() { return jobDir; } @@ -284,6 +281,4 @@ public class Job { } - - } diff --git a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/JobManager.java b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/JobManager.java index 2b5d9913..c2697635 100644 --- a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/JobManager.java +++ b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/JobManager.java @@ -163,11 +163,11 @@ public class JobManager { } public void downloadData(Progress notifier) { - downloadData(x -> true, notifier); + downloadData(x -> true, notifier, false); } - public void downloadData(Predicate<String> predicate, Progress notifier) { - job.download(predicate, notifier); + public void downloadData(Predicate<String> predicate, Progress notifier, boolean allowAgain) { + job.download(predicate, notifier, allowAgain); fireValueChangedEvent(); } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java index 375a00fb..10183f09 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java @@ -26,15 +26,16 @@ import javafx.beans.value.ObservableValueBase; import net.imagej.updater.util.Progress; public class BenchmarkJobManager { - + @SuppressWarnings("unused") private static Logger log = LoggerFactory .getLogger(cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.class); - + public final class Job extends ObservableValueBase<Job> { private JobInfo jobInfo; private JobState oldState; + public Job(JobInfo ji) { super(); this.jobInfo = ji; @@ -56,12 +57,16 @@ public class BenchmarkJobManager { if (ji.needsDownload()) { if (ji.getState() == JobState.Finished) { 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) { - 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) { @@ -111,8 +116,6 @@ public class BenchmarkJobManager { } } - - public boolean downloaded() { return !jobInfo.needsDownload(); } @@ -137,7 +140,7 @@ public class BenchmarkJobManager { private static final String CONFIG_YAML = "config.yaml"; private JobManager jobManager; - + public BenchmarkJobManager(BenchmarkSPIMParameters params) throws IOException { jobManager = new JobManager(params.workingDirectory(), constructSettingsFromParams(params)); } @@ -149,7 +152,7 @@ public class BenchmarkJobManager { } public Collection<Job> getJobs() throws IOException { - + return jobManager.getJobs().stream().map(this::convertJob).collect(Collectors.toList()); } @@ -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() { return name -> { Path p = Paths.get(name); diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java index 9010a3b0..78a9ef0d 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java @@ -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("Start job", job -> executeJobActionAsync("Starting job", p -> job.startJob(p)), 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, 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), job -> notNullValue(job, j -> EnumSet.of(JobState.Failed, JobState.Finished, JobState.Running).contains(j.getState()))); -- GitLab