diff --git a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ProgressDialog.java b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ProgressDialog.java index 93ad84c8caeaf3a21849ad29d8b5a489ac80af6a..d32daed9ea44e1da7064025bda00b7d7d05047bd 100644 --- a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ProgressDialog.java +++ b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ProgressDialog.java @@ -110,7 +110,7 @@ public class ProgressDialog extends JDialog implements Progress { if (title != null) setTitle(title); pack(); - + //TASK: vyresit centrovani na predka if (owner != null) { final Dimension o = owner.getSize(); final Dimension size = getSize(); diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/TaskComputation.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/TaskComputation.java index f34934f4f6b9de56e192c09ba1a359c892c11a81..0c4d392560477f31c140c39f89d1a58866e6e18e 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/TaskComputation.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/TaskComputation.java @@ -2,6 +2,7 @@ package cz.it4i.fiji.haas_spim_benchmark.core; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -83,8 +84,8 @@ public class TaskComputation { private int positionInOutput; private Collection<String> inputs; - private Collection<String> outputs; - private Collection<String> logs; + private Collection<String> outputs = Collections.emptyList(); + private Collection<String> logs = Collections.emptyList(); private Long id; private final List<BenchmarkError> errors; diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/RemoteFilesInfoControl.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/RemoteFilesInfoControl.java index c1297b9a8a7336e01709a398e5185aa465046c62..3b2f64db03ace0d8c2ca91a1833ac7e3931c2755 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/RemoteFilesInfoControl.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/RemoteFilesInfoControl.java @@ -21,18 +21,21 @@ public class RemoteFilesInfoControl extends BorderPane implements CloseableContr @SuppressWarnings("unused") private static Logger log = LoggerFactory .getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.RemoteFilesInfoControl.class); - + @SuppressWarnings("unused") private Window root; @FXML private TableView<ObservableValue<RemoteFileInfo>> files; - public RemoteFilesInfoControl(List<ObservableValue< RemoteFileInfo>> files) { + public RemoteFilesInfoControl() { JavaFXRoutines.initRootAndController("RemoteFilesInfo.fxml", this); - files.forEach(file->this.files.getItems().add(file)); } - + + public void setFiles(List<ObservableValue<RemoteFileInfo>> files) { + files.forEach(file -> this.files.getItems().add(file)); + } + @Override public void init(Window parameter) { this.root = parameter; @@ -47,8 +50,9 @@ public class RemoteFilesInfoControl extends BorderPane implements CloseableContr private void initTable() { JavaFXRoutines.setCellValueFactory(files, 0, file -> file.getName()); JavaFXRoutines.setCellValueFactory(files, 1, - (Function<RemoteFileInfo, String>) file -> file.getSize() >= 0 ? formatSize(file.getSize()) : "Not exists"); - + (Function<RemoteFileInfo, String>) file -> file.getSize() >= 0 ? formatSize(file.getSize()) + : "Not exists"); + } private String formatSize(long size) { diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/SPIMPipelineProgressViewController.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/SPIMPipelineProgressViewController.java index a72344edfde9cd0e2b323b0326c682b336feda1b..f25a30b5d6ec236991de06290a25cf95f2371851 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/SPIMPipelineProgressViewController.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/SPIMPipelineProgressViewController.java @@ -1,5 +1,6 @@ package cz.it4i.fiji.haas_spim_benchmark.ui; +import java.awt.Window; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -13,8 +14,12 @@ import java.util.concurrent.Executors; import java.util.function.Function; import java.util.stream.Collectors; +import javax.swing.WindowConstants; + import cz.it4i.fiji.haas.ui.CloseableControl; +import cz.it4i.fiji.haas.ui.InitiableControl; import cz.it4i.fiji.haas.ui.JavaFXRoutines; +import cz.it4i.fiji.haas.ui.ModalDialogs; import cz.it4i.fiji.haas.ui.TableViewContextMenu; import cz.it4i.fiji.haas_java_client.JobState; import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob; @@ -30,7 +35,7 @@ import javafx.scene.control.TableView; import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; -public class SPIMPipelineProgressViewController extends BorderPane implements CloseableControl { +public class SPIMPipelineProgressViewController extends BorderPane implements CloseableControl,InitiableControl { private static final String EMPTY_VALUE = "\u2007\u2007\u2007"; @@ -68,6 +73,7 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl private ObservableTaskRegistry registry; private ExecutorService executorServiceWS; private Executor executorFx = new FXFrameExecutorService(); + private Window root; public SPIMPipelineProgressViewController() { executorServiceWS = Executors.newSingleThreadExecutor(); @@ -96,6 +102,11 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl executorServiceWS.shutdown(); } + @Override + public void init(Window parameter) { + this.root = parameter; + } + private void init() { JavaFXRoutines.initRootAndController("SPIMPipelineProgressView.fxml", this); tasks.setPrefWidth(PREFERRED_WIDTH); @@ -106,9 +117,7 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl } private void proof(ObservableValue<Task> task) { - //executorServiceWS.execute(()-> { - new TaskComputationWindow(null, task.getValue().getComputations().get(0)).setVisible(true); - //}); + ModalDialogs.doModal(new TaskComputationWindow(root, task.getValue().getComputations().get(0)),WindowConstants.DISPOSE_ON_CLOSE); } static void add(Collection<ObservableValue<RemoteFileInfo>> files, String name, long size) { diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/TaskComputationControl.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/TaskComputationControl.java index 335fef6a6abc14b7e9340f616b7f876a246d5dd8..7d77691215e74a684689c2a2f8d8271f2eb76fe4 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/TaskComputationControl.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/TaskComputationControl.java @@ -1,6 +1,13 @@ package cz.it4i.fiji.haas_spim_benchmark.ui; import java.awt.Window; +import java.util.Collection; +import java.util.LinkedList; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import javax.swing.WindowConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,40 +15,59 @@ import org.slf4j.LoggerFactory; import cz.it4i.fiji.haas.ui.CloseableControl; import cz.it4i.fiji.haas.ui.InitiableControl; import cz.it4i.fiji.haas.ui.JavaFXRoutines; +import cz.it4i.fiji.haas.ui.ModalDialogs; +import cz.it4i.fiji.haas.ui.ProgressDialog; +import cz.it4i.fiji.haas_spim_benchmark.core.FXFrameExecutorService; import cz.it4i.fiji.haas_spim_benchmark.core.TaskComputation; import cz.it4i.fiji.haas_spim_benchmark.ui.TaskComputationAdapter.ObservableLog; +import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; //TASK: context menu udělat pro TaskComputation (buňku) nikoliv řádek -//TASK: TaskComputationWindow - vyřešit vlákna na kterých se to spouští -//TASK: dodělat progress dialog + modalita //TASK: vyřešit problém při konkurentním scp -//TASK: TaskComputationWindow - iniciální velikost okna public class TaskComputationControl extends TabPane implements CloseableControl, InitiableControl { @SuppressWarnings("unused") private static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.TaskComputationControl.class); - private final TaskComputationAdapter adapter; + private TaskComputationAdapter adapter; + + private Executor uiExecutor = new FXFrameExecutorService(); + + private ExecutorService wsExecutorService = Executors.newSingleThreadExecutor(); + @FXML + private RemoteFilesInfoControl remoteFilesInfo; + + private TaskComputation computation; public TaskComputationControl(TaskComputation computation) { JavaFXRoutines.initRootAndController("TaskComputationView.fxml", this); - adapter = new TaskComputationAdapter(computation); - + this.computation = computation; } @Override public void init(Window parameter) { - RemoteFilesInfoControl infoControl= new RemoteFilesInfoControl(adapter.getOutputs()); - infoControl.init(parameter); - addTab("Output files", infoControl); - for (ObservableLog log: adapter.getLogs()) { - LogViewControl logViewControl = new LogViewControl(); - logViewControl.setObservable(log.getContent()); - addTab(log.getName(), logViewControl); - } + wsExecutorService.execute(() -> { + ProgressDialog dialog = ModalDialogs.doModal(new ProgressDialog(parameter, "Updating infos..."), + WindowConstants.DO_NOTHING_ON_CLOSE); + try { + adapter = new TaskComputationAdapter(computation); + } finally { + dialog.done(); + } + + remoteFilesInfo.setFiles(adapter.getOutputs()); + remoteFilesInfo.init(parameter); + Collection<Runnable> runs = new LinkedList<>(); + for (ObservableLog log : adapter.getLogs()) { + LogViewControl logViewControl = new LogViewControl(); + logViewControl.setObservable(log.getContent()); + runs.add(() -> addTab(log.getName(), logViewControl)); + } + uiExecutor.execute(() -> runs.forEach(r -> r.run())); + }); } private void addTab(String title, Node control) { @@ -56,6 +82,7 @@ public class TaskComputationControl extends TabPane implements CloseableControl, @Override public void close() { adapter.close(); + wsExecutorService.shutdown(); } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/TaskComputationView.fxml b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/TaskComputationView.fxml index 7d3d465d0e0a3c0e132b4ab70a8f5fe3ee227fab..6964bc2e111b00a7c2324beab046ac8ddc933f34 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/TaskComputationView.fxml +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/TaskComputationView.fxml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<?import cz.it4i.fiji.haas_spim_benchmark.ui.LogViewControl?> -<?import cz.it4i.fiji.haas_spim_benchmark.ui.SPIMPipelineProgressViewController?> +<?import cz.it4i.fiji.haas_spim_benchmark.ui.RemoteFilesInfoControl?> <?import javafx.scene.control.Tab?> <?import javafx.scene.control.TabPane?> <?import javafx.scene.layout.AnchorPane?> @@ -10,4 +9,13 @@ <fx:root type="TabPane" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.65" fx:controller="cz.it4i.fiji.haas_spim_benchmark.ui.TaskComputationControl"> + <Tab closable="false" text="Output files"> + <content> + <HBox> + <RemoteFilesInfoControl fx:id="remoteFilesInfo" + HBox.hgrow="ALWAYS" /> + + </HBox> + </content> + </Tab> </fx:root> diff --git a/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/RunRemoteFilesView.java b/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/RunRemoteFilesView.java index 8eff0c9bbcac67063bd8213e276675c6c59aaa70..fc6190b4024ab749e97c2a70152725f8970bf29a 100644 --- a/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/RunRemoteFilesView.java +++ b/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/RunRemoteFilesView.java @@ -19,7 +19,7 @@ public class RunRemoteFilesView { @SuppressWarnings("serial") class Window extends cz.it4i.fiji.haas.ui.FXFrame<RemoteFilesInfoControl>{ public Window() { - super(()-> new RemoteFilesInfoControl(files)); + super(()-> new RemoteFilesInfoControl()); } } diff --git a/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/RunSPIMPipelineView.java b/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/RunSPIMPipelineView.java deleted file mode 100644 index c73535a5e9bfa4958469dfce131be4a0ab0295e0..0000000000000000000000000000000000000000 --- a/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/RunSPIMPipelineView.java +++ /dev/null @@ -1,21 +0,0 @@ -package cz.it4i.fiji.haas; - -import cz.it4i.fiji.haas.ui.FXFrameNative; - -public class RunSPIMPipelineView { - - - public static void main(String[] args) { - class Window extends FXFrameNative<SPIMPipelineProgressViewController>{ - - public Window() { - super(()-> new SPIMPipelineProgressViewController()); - - } - - } - - new Window().setVisible(true); - } - -} diff --git a/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/SPIMPipelineProgressViewController.java b/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/SPIMPipelineProgressViewController.java deleted file mode 100644 index d3bc5de9384b8a5594ac8470049a4c738a3f5732..0000000000000000000000000000000000000000 --- a/haas-spim-benchmark/src/test/java/cz/it4i/fiji/haas/SPIMPipelineProgressViewController.java +++ /dev/null @@ -1,115 +0,0 @@ -package cz.it4i.fiji.haas; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -import cz.it4i.fiji.haas.ui.CloseableControl; -import cz.it4i.fiji.haas.ui.JavaFXRoutines; -import cz.it4i.fiji.haas.ui.ResizeableControl; -import cz.it4i.fiji.haas_java_client.JobState; -import javafx.beans.value.ObservableValue; -import javafx.beans.value.ObservableValueBase; -import javafx.fxml.FXML; -import javafx.scene.control.TableCell; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; -import javafx.scene.layout.BorderPane; -import javafx.scene.paint.Color; - -public class SPIMPipelineProgressViewController extends BorderPane implements CloseableControl, ResizeableControl { - - protected static final String RUNNING_STATE_COMPUTATION = Color.YELLOW.toString(); - - protected static final String FINISHED_STATE_COMPUTATION = null; - - protected static final String UNKNOWN_STATE_COMPUTATION = Color.GRAY.toString(); - - private final Map<JobState, Color> taskExecutionState2Color = new HashMap<>(); - { - taskExecutionState2Color.put(JobState.Running, Color.YELLOW); - taskExecutionState2Color.put(JobState.Finished, Color.GREEN); - taskExecutionState2Color.put(JobState.Failed, Color.RED); - taskExecutionState2Color.put(JobState.Unknown, Color.GRAY); - } - - private String getColorTaskExecState(JobState jobState) { - Color result = null; - if (jobState == null) { - result = Color.GRAY; - } else { - result = taskExecutionState2Color.get(jobState); - } - return toCss(result != null ? result : Color.ORANGE); - } - - private static String toCss(Color color) { - return "rgb(" + Math.round(color.getRed() * 255.0) + "," + Math.round(color.getGreen() * 255.0) + "," - + Math.round(color.getBlue() * 255.0) + ")"; - } - - @FXML - public TableView<ObservableValue<String>> tasks; - - public SPIMPipelineProgressViewController() { - init(); - } - - public void close() { - - } - - @Override - public void setSize(double width, double height) { - tasks.setPrefSize(width, height); - } - - private void init() { - JavaFXRoutines.initRootAndController("SPIMPipelineProgressView.fxml", this); - fillTable(); - - } - - private void fillTable() { - - JavaFXRoutines.setCellValueFactory(this.tasks, 0, (Function<String, String>) v -> v); - for (int i = 1; i <= 91; i++) { - this.tasks.getColumns().add(new TableColumn<>(i + "")); - constructCellFactory(i); - } - for (int i = 0; i < 10; i++) { - tasks.getItems().add(new ObservableValueBase<String>() { - - @Override - public String getValue() { - return "Value"; - } - - }); - } - - } - - @SuppressWarnings("unchecked") - private void constructCellFactory(int index) { - JavaFXRoutines.setCellValueFactory(this.tasks, index, (Function<String, String>) v -> { - return v; - }); - ((TableColumn<ObservableValue<String>, String>) this.tasks.getColumns().get(index)).setCellFactory(column -> { - TableCell<ObservableValue<String>, String> result = new TableCell<ObservableValue<String>, String>() { - - @Override - protected void updateItem(String computation, boolean empty) { - if (computation == null || empty) { - setText(null); - setStyle(""); - } else { - setText("\u2007\u2007\u2007"); - setStyle("-fx-background-color: " + getColorTaskExecState(JobState.Finished)); - } - } - }; - return result; - }); - } -} 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 49247986b3fd2a1234021e7647ea23366173ad1c..a25697caf0d88cfb3c9daa69c7429fc79710fb06 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 @@ -23,6 +23,7 @@ import com.jcraft.jsch.SftpException; import com.jcraft.jsch.UserInfo; public class ScpClient implements Closeable { + private String hostName; private String username; private JSch jsch = new JSch(); @@ -314,6 +315,15 @@ public class ScpClient implements Closeable { return null; } + @Override + public void close() { + if (session != null && session.isConnected()) { + //log.info("disconnect"); + session.disconnect(); + session = null; + } + } + private int getBufferSize() { return 1024 * 1024; } @@ -327,6 +337,7 @@ public class ScpClient implements Closeable { session.setUserInfo(ui); } if (!session.isConnected()) { + //log.info("connect"); session.connect(); } return session; @@ -392,12 +403,4 @@ public class ScpClient implements Closeable { } return b; } - - @Override - public void close() { - if (session != null && session.isConnected()) { - session.disconnect(); - session = null; - } - } }