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 {
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 {
}
}
......@@ -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();
}
......
......@@ -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);
......
......@@ -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())));
......
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