From 1a09f9944d29e1984d567d473923731f77235c8c Mon Sep 17 00:00:00 2001
From: Jan Kozusznik <jan@kozusznik.cz>
Date: Fri, 23 Feb 2018 17:03:07 +0100
Subject: [PATCH] remove phone, fix not updating state of jobs

---
 .../commands/ManageSPIMBenchmark.java         |  5 ++-
 .../core/BenchmarkJobManager.java             | 33 ++++++++++---------
 .../haas_spim_benchmark/core/Constants.java   |  2 ++
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java
index 4f54ce6b..f7e6b93d 100644
--- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java
+++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java
@@ -17,6 +17,7 @@ import org.scijava.widget.TextWidget;
 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;
 
@@ -43,8 +44,6 @@ public class ManageSPIMBenchmark implements Command {
 	@Parameter(style = TextWidget.PASSWORD_STYLE)
 	private String password;
 	
-	@Parameter(style = TextWidget.FIELD_STYLE)
-	private String phone;
 	
 	@Parameter(style = TextWidget.FIELD_STYLE)
 	private String email;
@@ -56,7 +55,7 @@ public class ManageSPIMBenchmark implements Command {
 	public void run() {
 		try {
 			JDialog dialog = 
-					new BenchmarkSPIMWindow(null, new BenchmarkSPIMParametersImpl(userName, password, phone,
+					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);
diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java
index c8b5a5fb..7ba88371 100644
--- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java
+++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java
@@ -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,18 +85,21 @@ 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) {
-			job.updateInfo();
 			JobState state = job.getState();
 			if (state != JobState.Finished) {
 				return CompletableFuture.completedFuture(state);
@@ -104,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()
@@ -114,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;
 						}
 					}
@@ -234,7 +237,7 @@ public class BenchmarkJobManager {
 		public List<String> getActualOutput(List<SynchronizableFileType> content) {
 			return computationAccessor.getActualOutput(content);
 		}
-		
+
 		@Override
 		public String toString() {
 			return "" + getId();
diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/Constants.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/Constants.java
index fb92a8c2..0327e917 100644
--- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/Constants.java
+++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/Constants.java
@@ -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";
+	
 }
-- 
GitLab