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

show progress for download

parent 105f3fa2
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import org.scijava.Context;
import org.scijava.command.Command;
......@@ -18,6 +19,8 @@ import org.scijava.widget.UIComponent;
import cz.it4i.fiji.haas.JobManager.JobInfo;
import javafx.application.Platform;
import net.imagej.ImageJ;
import net.imagej.ui.swing.updater.ProgressDialog;
import net.imagej.updater.util.Progress;
/**
*
......@@ -50,7 +53,27 @@ public class CheckStatusOfHaaS implements Command {
} else {
CheckStatusOfHaaSWindow window;
(window = new CheckStatusOfHaaSWindow(getFrame(),context)).setVisible(true);
Platform.runLater(() -> jobManager.getJobs().forEach(job -> window.addJob(job)));
Platform.runLater(() -> {
Progress dialog = new ProgressDialog(getFrame());
dialog.setTitle("Downloading info about jobs");
Collection<JobInfo> jobs = jobManager.getJobs();
int count = 0;
for(JobInfo ji: jobs) {
String item;
dialog.addItem(item = "job id:" + ji.getId());
try {
ji.updateInfo();
} catch (IOException e) {
log.error(e);
}
window.addJob(ji);
dialog.itemDone(item);
dialog.setCount(count, jobs.size());
count++;
}
dialog.done();
});
}
} catch (IOException e) {
log.error(e);
......
......@@ -41,12 +41,9 @@ public class Job {
private Supplier<HaaSClient> haasClientSupplier;
private JobState state;
private Boolean needsDownload;
private Long jobId;
private JobInfo jobInfo;
private Long jobId;
final private Progress dummy = new Progress() {
......@@ -81,15 +78,13 @@ public class Job {
long id = client.start(files, "TestOutRedirect", Collections.emptyList(), new P_ProgressNotifierAdapter(progress));
jobDir = path.resolve("" + id);
Files.createDirectory(jobDir);
state = updateJobInfo().getState();
saveJobinfo();
updateState();
}
public Job(Path p, Supplier<HaaSClient> haasClientSupplier) throws IOException {
this(haasClientSupplier);
jobDir = p;
loadJobInfo();
updateState();
}
private Job(Supplier<HaaSClient> haasClientSupplier) {
......@@ -141,6 +136,14 @@ public class Job {
return state;
}
public Calendar getStartTime() {
return jobInfo.getStartTime();
}
public Calendar getEndTime() {
return jobInfo.getEndTime();
}
private synchronized void saveJobinfo() throws IOException {
try (OutputStream ow = Files.newOutputStream(jobDir.resolve(JOB_INFO_FILE),
StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE)) {
......@@ -175,15 +178,9 @@ public class Job {
private static long getJobId(Path path) {
return Long.parseLong(path.getFileName().toString());
}
public Calendar getStartTime() {
return jobInfo.getStartTime();
}
public Calendar getEndTime() {
return jobInfo.getEndTime();
}
private class P_ProgressNotifierAdapter implements ProgressNotifier {
private Progress progress;
......
......@@ -6,6 +6,7 @@ import java.nio.file.Path;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.stream.Collectors;
import org.scijava.Context;
......@@ -25,7 +26,6 @@ public class JobManager {
private Context context;
public JobManager(Path workDirectory, Context ctx) throws IOException {
super();
this.context = ctx;
this.workDirectory = workDirectory;
context.inject(this);
......@@ -39,6 +39,7 @@ public class JobManager {
}
private Job inject(Job job) {
context.inject(job);
return job;
......@@ -52,8 +53,8 @@ public class JobManager {
return () -> jobs.stream().filter(j -> j.needsDownload()).map(j -> new JobInfo(j)).iterator();
}
public Iterable<JobInfo> getJobs() {
return () -> jobs.stream().map(j -> new JobInfo(j)).iterator();
public Collection<JobInfo> getJobs() {
return jobs.stream().map(j -> new JobInfo(j)).collect(Collectors.toList());
}
public void downloadJob(Long id) {
......@@ -97,11 +98,15 @@ public class JobManager {
public String getEndTime() {
return job.getEndTime() != null ? job.getEndTime().getTime().toString() : "N/A";
}
public void downloadData(Progress progress) {
job.download(progress);
fireValueChangedEvent();
}
public void updateInfo() throws IOException {
job.updateState();
}
@Override
public JobInfo getValue() {
......
......@@ -16,7 +16,6 @@ import org.scijava.plugin.Plugin;
import net.imagej.ImageJ;
import net.imagej.ui.swing.updater.ProgressDialog;
import net.imagej.updater.util.Progress;
/**
*
* @author koz01
......
......@@ -249,6 +249,7 @@ public class HaaSClient {
public void download(long jobId, Path workDirectory, final ProgressNotifier notifier) {
try {
notifier.setTitle("Downloading");
FileTransferMethodExt ft = getFileTransfer().getFileTransferMethod(jobId, getSessionID());
try (ScpClient scpClient = getScpClient(ft)) {
String[] files = getFileTransfer().listChangedFilesForJob(jobId, getSessionID());
......@@ -256,8 +257,6 @@ public class HaaSClient {
.map(filename -> ft.getSharedBasepath() + "/" + filename).collect(Collectors.toList()),
scpClient);
final long totalFileSize = fileSizes.stream().mapToLong(i -> i.longValue()).sum();
notifier.setTitle("Downloading");
int[] idx = { 0 };
final int[] totalDownloaded = { 0 };
for (String fileName : files) {
......@@ -281,8 +280,8 @@ public class HaaSClient {
public void dataTransfered(long bytesTransfered) {
totalDownloaded[0] += bytesTransfered;
fileDownloaded[0] += bytesTransfered;
notifier.setCount((int) (totalDownloaded[0]), (int) (totalFileSize >> 10));
notifier.setItemCount((int) (fileDownloaded[0]), (int) (fileSizes.get(idx[0]) >> 10));
notifier.setCount((int) (totalDownloaded[0] >> 10), (int) (Math.max(totalFileSize,totalDownloaded[0]) >> 10));
notifier.setItemCount((int) (fileDownloaded[0] >> 10), (int) ( Math.max(fileSizes.get(idx[0]),fileDownloaded[0]) >> 10));
}
});
......@@ -301,7 +300,7 @@ public class HaaSClient {
private List<Long> getSizes(List<String> asList, ScpClient scpClient) throws JSchException, IOException {
List<Long> result = new LinkedList<>();
for (String lfile : asList) {
result.add(scpClient.size(lfile).get(0));
result.add(0l);//scpClient.size(lfile).get(0));
}
return result;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment