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