diff --git a/haas-java-client/src/main/java/cz/it4i/fiji/haas_java_client/HaaSClient.java b/haas-java-client/src/main/java/cz/it4i/fiji/haas_java_client/HaaSClient.java index 9f240f82a1812aadab6bf7d989f20d813b2177de..62ae6e0f3ce97cd26c4c50eca79ebbc42137af9f 100644 --- a/haas-java-client/src/main/java/cz/it4i/fiji/haas_java_client/HaaSClient.java +++ b/haas-java-client/src/main/java/cz/it4i/fiji/haas_java_client/HaaSClient.java @@ -157,8 +157,6 @@ public class HaaSClient { FileTransferMethodExt fileTransfer = getFileTransfer().getFileTransferMethod(job.getId(), getSessionID()); List<Long> totalSizes = getSizes(files); long totalSize = totalSizes.stream().mapToLong(l -> l.longValue()).sum(); - final long step = totalSize / 100; - try (ScpClient scpClient = getScpClient(fileTransfer)) { final int[] index = { 0 }; final long[] totalTransfered = { 0 }; @@ -170,9 +168,10 @@ public class HaaSClient { public void dataTransfered(long bytesTransfered) { fileTransfered[0] += bytesTransfered; totalTransfered[0] += bytesTransfered; - notifier.setItemCount((int) (fileTransfered[0] >> 10), - (int) (totalSizes.get(index[0]) >> 10)); - notifier.setCount((int) (totalTransfered[0] >> 10), (int) (totalSize >> 10)); + int[] sizes = normalizaSizes(fileTransfered[0], totalSizes.get(index[0])); + notifier.setItemCount(sizes[0], sizes[1]); + sizes = normalizaSizes(totalTransfered[0], totalSize); + notifier.setCount(sizes[0], sizes[1]); } }; notifier.addItem(item = "Uploading file: " + file.getFileName()); @@ -197,6 +196,21 @@ public class HaaSClient { } + private int[] normalizaSizes(long part, long total) { + int[] result = new int[2]; + if(total > Integer.MAX_VALUE) { + part = part>>10; + total = total>>10; + } + result[0] = (int) part; + result[1] = (int) total; + + if(result[0]==0 && result[1] == 0) { + result[0] = result[1] = 1; + } + return result; + } + public JobInfo obtainJobInfo(long jobId) { try { final SubmittedJobInfoExt info = getJobManagement().getCurrentInfoForJob(jobId, getSessionID()); @@ -267,18 +281,12 @@ public class HaaSClient { String item; notifier.addItem(item = fileName); scpClient.download(fileToDownload, rFile, new TransferFileProgress() { - @Override public void dataTransfered(long bytesTransfered) { - if (fileDownloaded[0] == 0 && bytesTransfered == 0) { - notifier.setItemCount(1, 1); - } else { - totalDownloaded[0] += bytesTransfered; - fileDownloaded[0] += bytesTransfered; - notifier.setCount((int) (totalDownloaded[0] >> 10), (int) (totalFileSize >> 10)); - notifier.setItemCount((int) (fileDownloaded[0] >> 10), - (int) (fileSizes.get(idx[0]) >> 10)); - } + int[] sizes = normalizaSizes(fileDownloaded[0], fileSizes.get(idx[0])); + notifier.setItemCount(sizes[0], sizes[1]); + sizes = normalizaSizes(totalDownloaded[0], totalFileSize); + notifier.setCount(sizes[0], sizes[1]); } }); diff --git a/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/ScpClient.java b/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/ScpClient.java index 88bcfdb41a285e3e97ff4d0455390159462b49cb..85b5b25f0ce82e6c4949d40c4cd88c8cb5cc5eaa 100644 --- a/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/ScpClient.java +++ b/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/ScpClient.java @@ -231,6 +231,58 @@ public class ScpClient implements Closeable { return true; } + 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; + } + @SuppressWarnings("unchecked") public List<Long> sizeByLs(String lfile) throws JSchException, IOException { Session session = connectionSession(); @@ -337,56 +389,4 @@ 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; - } }