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

support gaining filesez

parent 0693b83f
Branches
Tags
1 merge request!14Iss1026
Showing with 121 additions and 44 deletions
package cz.it4i.fiji.haas;
import cz.it4i.fiji.haas_java_client.ProgressNotifier;
public class DummyProgressNotifier implements ProgressNotifier {
@Override
public void setCount(int count, int total) {
}
@Override
public void addItem(Object item) {
}
@Override
public void setItemCount(int count, int total) {
}
@Override
public void itemDone(Object item) {
}
@Override
public void done() {
}
@Override
public void setTitle(String title) {
}
}
......@@ -251,6 +251,13 @@ public class Job {
haasClientSupplier.get().cancelJob(jobId);
}
public List<Long> getFileSizes(List<String> names) {
try (HaaSFileTransfer transfer = haasClientSupplier.get().startFileTransfer(getId(), new DummyProgressNotifier())) {
return transfer.obtainSize(names);
}
}
......
......@@ -369,6 +369,11 @@ public class BenchmarkJobManager {
public java.util.Collection<String> getChangedFiles() {
return job.getChangedFiles();
}
@Override
public List<Long> getFileSizes(List<String> names) {
return job.getFileSizes(names);
};
};
......
package cz.it4i.fiji.haas_spim_benchmark.core;
import java.util.Collection;
import java.util.List;
import cz.it4i.fiji.haas.HaaSOutputHolder;
......@@ -11,6 +12,7 @@ public interface SPIMComputationAccessor extends HaaSOutputHolder {
default boolean fileExists(String fileName) {
return getChangedFiles().contains(FILE_SEPARATOR_UNIX + fileName);
}
Collection<String> getChangedFiles();
List<Long> getFileSizes(List<String> names);
}
......@@ -18,10 +18,12 @@ public class SPIMComputationAccessorDecoratorWithTimeout implements SPIMComputat
private final P_ResultCacheHolder<Set<String>> changedFilesCache;
private final Map<SynchronizableFileType, Integer> allowedTypesIndices = new HashMap<>();
private final List<SynchronizableFileType> allowedTypes = new LinkedList<>();
private SPIMComputationAccessor decorated;
public SPIMComputationAccessorDecoratorWithTimeout(SPIMComputationAccessor decorated,
Set<SynchronizableFileType> allowedTypes, long intervalForQueryInMs) {
this.intervalForQueryInMs = intervalForQueryInMs;
this.decorated = decorated;
initAllowedTypes(allowedTypes);
outputCache = new P_ResultCacheHolder<List<String>>(x -> decorated.getActualOutput(this.allowedTypes));
changedFilesCache = new P_ResultCacheHolder<>(set -> {
......@@ -49,6 +51,11 @@ public class SPIMComputationAccessorDecoratorWithTimeout implements SPIMComputat
return changedFilesCache.getResult();
}
@Override
public List<Long> getFileSizes(List<String> names) {
return decorated.getFileSizes(names);
}
private void initAllowedTypes(Set<SynchronizableFileType> allowedTypes) {
for (SynchronizableFileType type : allowedTypes) {
this.allowedTypes.add(type);
......
......@@ -4,7 +4,13 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import org.apache.commons.math3.util.Pair;
import com.google.common.collect.Streams;
import cz.it4i.fiji.haas_java_client.JobState;
import cz.it4i.fiji.haas_java_client.SynchronizableFileType;
......@@ -15,38 +21,39 @@ public class TaskComputation {
public static class Log {
final private String name;
final private String content;
public Log(String name, String content) {
this.name = name;
this.content = content;
}
public String getName() {
return name;
}
public String getContent() {
return content;
}
}
public static class File {
final private String name;
final private long size;
public File(String name, long size) {
this.name = name;
this.size = size;
}
public String getName() {
return name;
}
public long getSize() {
return size;
}
}
private final SPIMComputationAccessor computationAccessor;
private final String taskDescription;
private final int timepoint;
......@@ -61,7 +68,7 @@ public class TaskComputation {
private Long id;
private final List<BenchmarkError> errors;
/**
* Creates a TaskComputation object. At the time of creation, the job parameters
* are not populated
......@@ -97,18 +104,17 @@ public class TaskComputation {
return id;
}
// TODO: Method stub
public void update() {
}
/**
* @return computations errors
*/
public Collection<BenchmarkError> getErrors() {
return errors;
}
public Collection<Log> getLogs() {
throw new NotImplementedError();
}
......@@ -139,6 +145,17 @@ public class TaskComputation {
return true;
}
public Collection<String> getOutputs() {
return outputs;
}
public Map<String, Long> getOutFileSizes() {
List<String> names = new LinkedList<>(outputs);
List<Long> sizes = computationAccessor.getFileSizes(names);
return Streams.zip(names.stream(), sizes.stream(), (name, size) -> new Pair<>(name, size))
.collect(Collectors.toMap(p -> p.getFirst(), p -> p.getSecond()));
}
private void updateState() {
// Should the state be queued, try to find out whether a log file exists
......@@ -207,8 +224,4 @@ public class TaskComputation {
return computationAccessor.getActualOutput(Arrays.asList(SynchronizableFileType.StandardErrorFile)).get(0);
}
public Collection<String> getOutputs() {
return outputs;
}
}
......@@ -6,7 +6,7 @@ public interface RemoteFileInfo {
*
* @return size of file or -1 in case of absence
*/
long getSize();
Long getSize();
String getName();
}
......@@ -3,85 +3,97 @@ package cz.it4i.fiji.haas_spim_benchmark.ui;
import java.io.Closeable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import cz.it4i.fiji.haas_spim_benchmark.core.Constants;
import cz.it4i.fiji.haas_spim_benchmark.core.TaskComputation;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.ObservableValueBase;
public class TaskComputationAdapter implements Closeable{
public class TaskComputationAdapter implements Closeable {
private final TaskComputation computation;
private final List<ObservableValue<RemoteFileInfo>> outputs = new LinkedList<>();
private final List<ObservableOutputFile> outputs = new LinkedList<>();
private final List<ObservableValue<String>> logs = new LinkedList<>();
private final Timer timer;
public TaskComputationAdapter(TaskComputation computation) {
this.computation = computation;
timer = new Timer();
computation.getOutputs().forEach(outputFile->addOutputFile(outputFile));
Map<String, Long> sizes = computation.getOutFileSizes();
computation.getOutputs().forEach(outputFile -> addOutputFile(outputFile, sizes.get(outputFile)));
timer.scheduleAtFixedRate(new P_TimerTask(), Constants.HAAS_TIMEOUT, Constants.HAAS_TIMEOUT);
}
private void addOutputFile(String outputFile) {
outputs.add(new ObservableOutputFile(outputFile));
private void addOutputFile(String outputFile, Long size) {
outputs.add(new ObservableOutputFile(outputFile, size));
}
@Override
public void close() {
timer.cancel();
}
public static class Log {
public String getName() {
return null;
}
public ObservableValue<String> getContent() {
return null;
}
}
private class ObservableOutputFile extends ObservableValueBase<RemoteFileInfo> {
private final String name;
private Long size;
private final RemoteFileInfo value = new RemoteFileInfo() {
@Override
public long getSize() {
return 0;
public Long getSize() {
return size;
}
@Override
public String getName() {
return null;
return name;
}
};
public ObservableOutputFile(String name) {
public ObservableOutputFile(String name, Long size) {
this.name = name;
this.size = size;
}
@Override
public RemoteFileInfo getValue() {
return value;
}
public void setSize(Long newValue) {
Long oldValue = size;
size = newValue;
if (oldValue != newValue && oldValue != null && !oldValue.equals(newValue)) {
fireValueChangedEvent();
}
}
}
private class P_TimerTask extends TimerTask {
@Override
public void run() {
Map<String, Long> sizes = computation.getOutFileSizes();
outputs.forEach(value -> value.setSize(sizes.get(value.getValue().getName())));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment