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

another refactoring of HaaSClient

parent e07fe64d
No related branches found
No related tags found
No related merge requests found
......@@ -13,8 +13,8 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.scijava.log.LogService;
import org.scijava.plugin.Parameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.haas.JobManager.JobManager4Job;
import cz.it4i.fiji.haas.JobManager.JobSynchronizableFile;
......@@ -36,8 +36,7 @@ public class Job {
private static String JOB_INFO_FILE = ".jobinfo";
@Parameter
private LogService log;
private static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas.Job.class);
private Path jobDir;
......@@ -120,7 +119,7 @@ public class Job {
synchronized public void download(Predicate<String> predicate, Progress notifier) {
try (HaaSFileTransfer fileTransfer = haasClientSupplier.get().startFileTransfer(jobId, new P_ProgressNotifierAdapter(notifier))) {
fileTransfer.download(fileTransfer.getChangedFiles().stream().filter(predicate).collect(Collectors.toList()), jobDir);
fileTransfer.download(haasClientSupplier.get().getChangedFiles(jobId).stream().filter(predicate).collect(Collectors.toList()), jobDir);
}
}
......@@ -246,4 +245,6 @@ public class Job {
}
......@@ -306,6 +306,15 @@ public class HaaSClient {
}
}
public Collection<String> getChangedFiles(long jobId) {
try {
return Arrays.asList(fileTransfer.listChangedFilesForJob(jobId, getSessionID()));
} catch (RemoteException | ServiceException e) {
throw new HaaSClientException(e);
}
}
private void doSubmitJob(long jobId) throws RemoteException, ServiceException {
getJobManagement().submitJob(jobId, getSessionID());
}
......
......@@ -2,20 +2,20 @@ package cz.it4i.fiji.haas_java_client;
import java.io.Closeable;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import cz.it4i.fiji.haas_java_client.HaaSClient.UploadingFile;
public interface HaaSFileTransfer extends Closeable {
Collection<String> getChangedFiles();
@Override
void close();
void upload(Iterable<UploadingFile> files);
void download(Iterable<String> files, Path workDIrectory);
List<Long> obtainSize(List<String> files);
}
......@@ -4,12 +4,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.rmi.RemoteException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jcraft.jsch.JSchException;
import cz.it4i.fiji.haas_java_client.HaaSClient.P_ProgressNotifierDecorator4Size;
......@@ -20,6 +21,8 @@ import cz.it4i.fiji.scpclient.ScpClient;
class HaaSFileTransferImp implements HaaSFileTransfer {
private static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas_java_client.HaaSFileTransferImp.class);
private FileTransferMethodExt ft;
private ScpClient scpClient;
private FileTransferWsSoap fileTransfer;
......@@ -27,7 +30,6 @@ class HaaSFileTransferImp implements HaaSFileTransfer {
private long jobId;
private ProgressNotifier notifier;
public HaaSFileTransferImp(FileTransferMethodExt ft, String sessionId, long jobId, FileTransferWsSoap fileTransfer,
ScpClient scpClient, ProgressNotifier notifier) {
super();
......@@ -39,15 +41,6 @@ class HaaSFileTransferImp implements HaaSFileTransfer {
this.notifier = notifier;
}
@Override
public Collection<String> getChangedFiles() {
try {
return Arrays.asList(fileTransfer.listChangedFilesForJob(jobId, sessionId));
} catch (RemoteException e) {
throw new HaaSClientException(e);
}
}
@Override
public void close() {
scpClient.close();
......@@ -112,4 +105,15 @@ class HaaSFileTransferImp implements HaaSFileTransfer {
}
}
@Override
public List<Long> obtainSize(List<String> files) {
try {
return HaaSClient.getSizes(files.stream()
.map(filename -> "'" + ft.getSharedBasepath() + "/" + filename + "'").collect(Collectors.toList()), scpClient, notifier);
} catch (JSchException | IOException e) {
throw new HaaSClientException(e);
}
}
}
......@@ -46,7 +46,7 @@ public class TestHaaSJavaClient {
client.downloadPartsOfJobFiles(jobId, taskFileOffset).forEach(jfc -> showJFC(jfc));
if (info.getState() == JobState.Finished) {
try (HaaSFileTransfer fileTransfer = client.startFileTransfer(jobId, HaaSClient.DUMMY_NOTIFIER)) {
fileTransfer.download(fileTransfer.getChangedFiles(), workDir);
fileTransfer.download(client.getChangedFiles(jobId), workDir);
}
}
log.info("JobId :" + jobId + ", state" + info.getState());
......
......@@ -46,7 +46,7 @@ public class TestHaaSJavaClientWithSPIM {
client.downloadPartsOfJobFiles(jobId, taskFileOffset).forEach(jfc -> showJFC(jfc));
if (info.getState() == JobState.Finished) {
try (HaaSFileTransfer fileTransfer = client.startFileTransfer(jobId, HaaSClient.DUMMY_NOTIFIER)) {
fileTransfer.download(fileTransfer.getChangedFiles(), workDir);
fileTransfer.download(client.getChangedFiles(jobId), workDir);
}
}
......
......@@ -203,6 +203,7 @@ public class BenchmarkJobManager {
public boolean remove() {
return job.remove();
}
}
public BenchmarkJobManager(BenchmarkSPIMParameters params) throws IOException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment