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

inspect size correctly

parent 2ce3b507
Branches
Tags
No related merge requests found
......@@ -16,12 +16,15 @@ public class CheckStatusOfHaaSWindow extends FXFrame<CheckStatusOfHaaSController
private Context context;
private CheckStatusOfHaaSController controller;
private Frame applicationFrame;
public CheckStatusOfHaaSWindow(Frame applicationFrame, Context context) {
super(applicationFrame,"/cz/it4i/fiji/haas/ui/CheckStatusOfHaaS.fxml");
this.context = context;
init(this::initController);
this.setResizable(false);
this.setTitle("Manage status of HaaS jobs");
this.applicationFrame = applicationFrame;
}
public void addJob(JobInfo job) {
......@@ -31,7 +34,7 @@ public class CheckStatusOfHaaSWindow extends FXFrame<CheckStatusOfHaaSController
private void initController(CheckStatusOfHaaSController controller) {
this.controller = controller;
context.inject(controller);
controller.init();
controller.init(applicationFrame);
}
}
package cz.it4i.fiji.haas.ui;
import java.awt.Frame;
import java.util.function.Function;
import org.scijava.log.LogService;
import org.scijava.plugin.Parameter;
import cz.it4i.fiji.haas.JobManager.JobInfo;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
......@@ -24,6 +26,8 @@ public class CheckStatusOfHaaSController {
@FXML
private TableView<JobInfo> jobs;
private Frame root;
public CheckStatusOfHaaSController() {
}
......@@ -32,13 +36,14 @@ public class CheckStatusOfHaaSController {
jobs.getItems().add(job);
}
public void init() {
public void init(Frame root) {
initTable();
initMenu();
this.root = root;
}
private void downloadData(ActionEvent event) {
jobs.getSelectionModel().getSelectedItem().downloadData(new ProgressDialog(null));
Platform.runLater(() -> jobs.getSelectionModel().getSelectedItem().downloadData(new ProgressDialog(root)));
}
private void initMenu() {
......
......@@ -254,8 +254,8 @@ public class HaaSClient {
try (ScpClient scpClient = getScpClient(ft)) {
String[] files = getFileTransfer().listChangedFilesForJob(jobId, getSessionID());
List<Long> fileSizes = getSizes(Arrays.asList(files).stream()
.map(filename -> ft.getSharedBasepath() + "/" + filename).collect(Collectors.toList()),
scpClient);
.map(filename -> "'" + ft.getSharedBasepath() + "/" + filename + "'").collect(Collectors.toList()),
scpClient, notifier);
final long totalFileSize = fileSizes.stream().mapToLong(i -> i.longValue()).sum();
int[] idx = { 0 };
final int[] totalDownloaded = { 0 };
......@@ -280,8 +280,8 @@ public class HaaSClient {
public void dataTransfered(long bytesTransfered) {
totalDownloaded[0] += bytesTransfered;
fileDownloaded[0] += bytesTransfered;
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));
notifier.setCount((int) (totalDownloaded[0] >> 10), (int) (totalFileSize>> 10));
notifier.setItemCount((int) (fileDownloaded[0] >> 10), (int) ( fileSizes.get(idx[0]) >> 10));
}
});
......@@ -297,11 +297,16 @@ public class HaaSClient {
}
}
private List<Long> getSizes(List<String> asList, ScpClient scpClient) throws JSchException, IOException {
private List<Long> getSizes(List<String> asList, ScpClient scpClient, ProgressNotifier notifier) throws JSchException, IOException {
List<Long> result = new LinkedList<>();
String item;
notifier.addItem(item = "Checking sizes");
for (String lfile : asList) {
result.add(0l);//scpClient.size(lfile).get(0));
result.add(scpClient.size(lfile));
notifier.setItemCount(result.size(), asList.size());
}
notifier.itemDone(item);
return result;
}
......
......@@ -247,7 +247,7 @@ public class ScpClient implements Closeable {
}
@SuppressWarnings("unchecked")
public List<Long> size(String lfile) throws JSchException, IOException {
public List<Long> sizeByLs(String lfile) throws JSchException, IOException {
Session session = connectionSession();
// exec 'scp -f rfile' remotely
......@@ -352,4 +352,56 @@ public class ScpClient implements Closeable {
session = null;
}
}
public long size(String lfile) throws JSchException, IOException {
Session session = connectionSession();
// exec 'scp -f rfile' remotely
String command = "scp -f " + lfile;
Channel channel = session.openChannel("exec");
try {
((ChannelExec) channel).setCommand(command);
// get I/O streams for remote scp
try (OutputStream out = channel.getOutputStream(); InputStream in = channel.getInputStream()) {
channel.connect();
byte[] buf = new byte[getBufferSize()];
// send '\0'
buf[0] = 0;
out.write(buf, 0, 1);
out.flush();
while (true) {
int c = checkAck(in);
if (c != 'C') {
break;
}
// read '0644 '
in.read(buf, 0, 5);
long filesize = 0L;
while (true) {
if (in.read(buf, 0, 1) < 0) {
// error
break;
}
if (buf[0] == ' ')
break;
filesize = filesize * 10L + (long) (buf[0] - '0');
}
return filesize;
}
}
} finally {
channel.disconnect();
}
return -1;
}
}
......@@ -15,7 +15,7 @@ public class TestSCP {
try(ScpClient scp = new ScpClient("salomon.it4i.cz", "koz01", "/home/koz01/.ssh/it4i_rsa-np", null)) {
// System.out.println( scp.upload(
// Paths.get("/home/koz01/Work/vyzkumnik/fiji/work/aaa/spim-data/exampleSingleChannel(9).czi"), "'/home/koz01/exampleSingleChannel(9).czi'"));
System.out.println( scp.size("/home/koz01/exampleSingleChannel(9).czi"));
System.out.println( scp.size("'/home/koz01/exampleSingleChannel(9).czi'"));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment