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

Merge branch 'iss1027' into iss1026

parents 687dfa0c 0666d856
Branches
Tags
1 merge request!14Iss1026
Showing
with 48 additions and 69 deletions
package cz.it4i.fiji.haas.ui;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.function.Consumer;
......@@ -29,7 +29,7 @@ public class ObservableValueRegistry<T> {
}
private Map<T,UpdatableObservableValue<T>> map = new HashMap<>();
private Map<T,UpdatableObservableValue<T>> map = new LinkedHashMap<>();
public ObservableValue<T> addIfAbsent(T value) {
UpdatableObservableValue<T> uov = map.computeIfAbsent(value, v-> new UpdatableObservableValue<T>(v, updateFunction, stateProvider));
......
......@@ -2,10 +2,16 @@ package cz.it4i.fiji.haas.ui;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javafx.beans.value.ObservableValueBase;
public class UpdatableObservableValue<T> extends ObservableValueBase<T> {
@SuppressWarnings("unused")
private static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas.ui.UpdatableObservableValue.class);
public enum UpdateStatus {
Deleted, Updated, NotUpdated
}
......
package cz.it4i.fiji.haas_spim_benchmark.commands;
import java.awt.Frame;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
......@@ -12,14 +11,13 @@ import org.scijava.Context;
import org.scijava.command.Command;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.ui.ApplicationFrame;
import org.scijava.ui.UIService;
import org.scijava.widget.FileWidget;
import org.scijava.widget.TextWidget;
import org.scijava.widget.UIComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.haas_spim_benchmark.core.Constants;
import cz.it4i.fiji.haas_spim_benchmark.ui.BenchmarkSPIMWindow;
import net.imagej.ImageJ;
......@@ -40,27 +38,25 @@ public class ManageSPIMBenchmark implements Command {
@Parameter
private Context context;
@Parameter(style = TextWidget.FIELD_STYLE)
@Parameter(style = TextWidget.FIELD_STYLE, label = "User name")
private String userName;
@Parameter(style = TextWidget.PASSWORD_STYLE)
private String password;
@Parameter(style = TextWidget.FIELD_STYLE)
private String phone;
@Parameter(style = TextWidget.FIELD_STYLE)
private String email;
@Parameter(label = "Work directory", persist = true, style = FileWidget.DIRECTORY_STYLE)
private File workDirectory;
@Parameter(label = "Working directory", persist = true, style = FileWidget.DIRECTORY_STYLE)
private File workingDirectory;
@Override
public void run() {
try {
JDialog dialog =
new BenchmarkSPIMWindow(null, new BenchmarkSPIMParametersImpl(userName, password, phone,
email, Paths.get(workDirectory.getPath())));
new BenchmarkSPIMWindow(null, new BenchmarkSPIMParametersImpl(userName, password, Constants.PHONE,
email, Paths.get(workingDirectory.getPath())));
dialog.setTitle("SPIM workflow computation manager");
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
......@@ -71,19 +67,6 @@ public class ManageSPIMBenchmark implements Command {
}
private Frame getFrame() {
ApplicationFrame af = uiService.getDefaultUI().getApplicationFrame();
if (af instanceof Frame) {
return (Frame) af;
} else if (af instanceof UIComponent) {
Object component = ((UIComponent<?>) af).getComponent();
if (component instanceof Frame) {
return (Frame) component;
}
}
return null;
}
public static void main(final String... args) {
// Launch ImageJ as usual.
final ImageJ ij = new ImageJ();
......
......@@ -65,7 +65,7 @@ public class BenchmarkJobManager {
private JobState verifiedState;
private boolean verifiedStateProcessed;
private CompletableFuture<JobState> running;
public BenchmarkJob(Job job) {
this.job = job;
tasks = new LinkedList<Task>();
......@@ -85,14 +85,18 @@ public class BenchmarkJobManager {
}
public JobState getState() {
return getStateAsync(r->r.run()).getNow(JobState.Unknown);
return getStateAsync(r -> r.run()).getNow(JobState.Unknown);
}
public synchronized CompletableFuture<JobState> getStateAsync(Executor executor) {
if(running != null) {
if (running != null) {
return running;
}
return running = doGetStateAsync(executor);
CompletableFuture<JobState> result = doGetStateAsync(executor);
if (!result.isCancelled() && !result.isCompletedExceptionally() && !result.isDone()) {
running = result;
}
return result;
}
private synchronized CompletableFuture<JobState> doGetStateAsync(Executor executor) {
......@@ -103,7 +107,7 @@ public class BenchmarkJobManager {
return CompletableFuture.completedFuture(verifiedState);
}
verifiedStateProcessed = true;
return CompletableFuture.supplyAsync(()->{
return CompletableFuture.supplyAsync(() -> {
try {
verifiedState = Stream
.concat(Arrays.asList(state).stream(), getTasks().stream()
......@@ -113,18 +117,18 @@ public class BenchmarkJobManager {
if (verifiedState != JobState.Finished && verifiedState != JobState.Canceled) {
verifiedState = JobState.Failed;
}
synchronized(BenchmarkJob.this) {
//test whether job was restarted - it sets running to null
if(!verifiedStateProcessed) {
synchronized (BenchmarkJob.this) {
// test whether job was restarted - it sets running to null
if (!verifiedStateProcessed) {
verifiedState = null;
return doGetStateAsync(r->r.run()).getNow(null);
}
return doGetStateAsync(r -> r.run()).getNow(null);
}
running = null;
return verifiedState;
}
} finally {
synchronized(BenchmarkJob.this) {
if(running != null) {
synchronized (BenchmarkJob.this) {
if (running != null) {
running = null;
}
}
......@@ -233,7 +237,7 @@ public class BenchmarkJobManager {
public List<String> getActualOutput(List<SynchronizableFileType> content) {
return computationAccessor.getActualOutput(content);
}
@Override
public String toString() {
return "" + getId();
......
......@@ -4,6 +4,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
public interface Constants {
String PHONE = "123456789";
int HAAS_UPDATE_TIMEOUT = 30000;
short UI_TO_HAAS_FREQUENCY_UPDATE_RATIO = 10;
String HAAS_JOB_NAME = "HaaSSPIMBenchmark";
......@@ -50,4 +51,5 @@ public interface Constants {
String STATISTICS_SUMMARY_FILENAME = "summary.csv";
String SUMMARY_FILE_HEADER = "Task;AvgMemoryUsage;AvgWallTime;MaxWallTime;TotalTime;JobCount";
}
......@@ -3,9 +3,10 @@ package cz.it4i.fiji.haas_spim_benchmark.ui;
import java.awt.Desktop;
import java.awt.Window;
import java.io.IOException;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
......@@ -30,7 +31,6 @@ import cz.it4i.fiji.haas.ui.ModalDialogs;
import cz.it4i.fiji.haas.ui.ProgressDialog;
import cz.it4i.fiji.haas.ui.TableViewContextMenu;
import cz.it4i.fiji.haas_java_client.JobState;
import cz.it4i.fiji.haas_java_client.SynchronizableFileType;
import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager;
import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob;
import cz.it4i.fiji.haas_spim_benchmark.core.Constants;
......@@ -107,7 +107,7 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
registry.get(job.getValue()).update();
}), job -> notNullValue(job, j -> j.getState() == JobState.Running));
menu.addItem("Show details", job -> {
menu.addItem("Execution details", job -> {
try {
new JobDetailWindow(root, job.getValue()).setVisible(true);
} catch (IOException e) {
......@@ -129,16 +129,7 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
menu.addItem("Explore errors", job -> job.getValue().exploreErrors(),
job -> notNullValue(job, j -> j.getState().equals(JobState.Failed)));
menu.addItem("Show output", j -> {
new JobOutputView(root, executorServiceUI, j.getValue(), SynchronizableFileType.StandardErrorFile,
job -> job.getSnakemakeOutput(), Constants.HAAS_UPDATE_TIMEOUT);
new JobOutputView(root, executorServiceUI, j.getValue(), SynchronizableFileType.StandardOutputFile,
job -> job.getAnotherOutput(), Constants.HAAS_UPDATE_TIMEOUT);
}, job -> notNullValue(job, j -> EnumSet
.of(JobState.Failed, JobState.Finished, JobState.Running, JobState.Canceled).contains(j.getState())));
menu.addItem("Open working directory", j -> open(j.getValue()), x -> notNullValue(x, j -> true));
menu.addItem("Update table", job -> updateJobs(), j -> true);
}
private void open(BenchmarkJob j) {
......@@ -187,8 +178,8 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
: new DummyProgress();
try {
Collection<BenchmarkJob> jobs = manager.getJobs();
//jobs.forEach(bj->bj.getStateAsync(executorServiceJobState));
List<BenchmarkJob> jobs = new LinkedList<>(manager.getJobs());
jobs.sort((bj1, bj2) -> (int) (bj1.getId() - bj2.getId()));
Set<ObservableValue<BenchmarkJob>> actual = new HashSet<>(this.jobs.getItems());
for (BenchmarkJob bj : jobs) {
registry.addIfAbsent(bj);
......@@ -210,13 +201,13 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
}
private void initTable() {
registry = new ObservableBenchmarkJobRegistry(bj -> remove(bj),executorServiceJobState);
registry = new ObservableBenchmarkJobRegistry(bj -> remove(bj), executorServiceJobState);
setCellValueFactory(0, j -> j.getId() + "");
setCellValueFactoryCompletable(1,
j -> j.getStateAsync(executorServiceJobState).thenApply(state -> "" + state));
setCellValueFactoryCompletable(1, j -> j.getStateAsync(executorServiceJobState).thenApply(state -> "" + state));
setCellValueFactory(2, j -> j.getCreationTime().toString());
setCellValueFactory(3, j -> j.getStartTime().toString());
setCellValueFactory(4, j -> j.getEndTime().toString());
// jobs.getSortOrder().add(jobs.getColumns().get(0));
}
private void remove(BenchmarkJob bj) {
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.geometry.Insets?>
<fx:root type="BorderPane" xmlns="http://javafx.com/javafx/8.0.65"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="cz.it4i.fiji.haas_spim_benchmark.ui.SPIMPipelineProgressViewController">
<fx:root type="BorderPane" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cz.it4i.fiji.haas_spim_benchmark.ui.SPIMPipelineProgressViewController">
<center>
<HBox>
<children>
<TableView fx:id="tasks" HBox.hgrow="ALWAYS">
<TableView fx:id="tasks" HBox.hgrow="ALWAYS">
<columns>
<TableColumn prefWidth="101.0" text="Task name" />
<TableColumn prefWidth="179.0" text="Task name" />
</columns>
</TableView>
......
......@@ -32,18 +32,13 @@ public class SPIMPipelineProgressViewController extends BorderPane implements Cl
private static final String EMPTY_VALUE = "\u2007\u2007\u2007";
private static final int PREFERRED_WIDTH = 900;
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 static final Map<JobState, Color> taskExecutionState2Color = new HashMap<>();
static {
taskExecutionState2Color.put(JobState.Running, Color.YELLOW);
taskExecutionState2Color.put(JobState.Finished, Color.GREEN);
taskExecutionState2Color.put(JobState.Failed, Color.RED);
taskExecutionState2Color.put(JobState.Queued, Color.AZURE);
taskExecutionState2Color.put(JobState.Unknown, Color.GRAY);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment