From 5e33583dd487e7af11cd79ffcc725cda244fa904 Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Wed, 21 Nov 2018 09:59:51 -0800 Subject: [PATCH] moved initial join logic to controller to help avoid tying it into the core client --- corefx/src/main/java/com/core/Controller.java | 33 ++++++++++++++--- .../java/com/core/client/ICoreClient.java | 6 ++- .../com/core/client/rest/CoreRestClient.java | 37 ++++++------------- .../core/client/rest/GetMobilityConfigs.java | 11 ++++++ 4 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 corefx/src/main/java/com/core/client/rest/GetMobilityConfigs.java diff --git a/corefx/src/main/java/com/core/Controller.java b/corefx/src/main/java/com/core/Controller.java index 155d3d4e..a92345e6 100644 --- a/corefx/src/main/java/com/core/Controller.java +++ b/corefx/src/main/java/com/core/Controller.java @@ -1,10 +1,7 @@ package com.core; import com.core.client.ICoreClient; -import com.core.client.rest.ConfigOption; -import com.core.client.rest.CoreRestClient; -import com.core.client.rest.GetConfig; -import com.core.client.rest.SetConfig; +import com.core.client.rest.*; import com.core.data.CoreLink; import com.core.data.CoreNode; import com.core.data.MobilityConfig; @@ -95,7 +92,8 @@ public class Controller implements Initializable { executorService.submit(() -> { try { coreWebSocket.start(coreUrl); - coreClient.initialJoin(coreUrl); + coreClient.setUrl(coreUrl); + initialJoin(); } catch (IOException | URISyntaxException ex) { Toast.error(String.format("Connection failure: %s", ex.getMessage()), ex); Platform.runLater(() -> connectDialog.showDialog()); @@ -103,6 +101,31 @@ public class Controller implements Initializable { }); } + private void initialJoin() throws IOException { + GetServices services = coreClient.getServices(); + logger.info("core services: {}", services); + nodeServicesDialog.setServices(services); + + logger.info("initial core session join"); + GetSessions response = coreClient.getSessions(); + + logger.info("existing sessions: {}", response); + if (response.getSessions().isEmpty()) { + logger.info("creating initial session"); + coreClient.createSession(); + graphToolbar.setRunButton(coreClient.isRunning()); + hooksDialog.updateHooks(); + } else { + GetSessionsData getSessionsData = response.getSessions().get(0); + Integer joinId = getSessionsData.getId(); + coreClient.joinSession(joinId, true); + } + + // set emane models + List emaneModels = coreClient.getEmaneModels().getModels(); + nodeEmaneDialog.setModels(emaneModels); + } + public void sessionStarted() { // configure and add mobility player CoreNode node = mobilityDialog.getNode(); diff --git a/corefx/src/main/java/com/core/client/ICoreClient.java b/corefx/src/main/java/com/core/client/ICoreClient.java index fd4efca0..2d977051 100644 --- a/corefx/src/main/java/com/core/client/ICoreClient.java +++ b/corefx/src/main/java/com/core/client/ICoreClient.java @@ -8,6 +8,8 @@ import java.io.IOException; import java.util.List; public interface ICoreClient { + void setUrl(String url); + void joinSession(Integer joinId, boolean notification) throws IOException; void createSession() throws IOException; @@ -16,8 +18,6 @@ public interface ICoreClient { GetSession getSession(Integer sessionId) throws IOException; - void initialJoin(String url) throws IOException; - boolean start() throws IOException; boolean stop() throws IOException; @@ -76,6 +76,8 @@ public interface ICoreClient { String getTerminalCommand(CoreNode node) throws IOException; + GetMobilityConfigs getMobilityConfigs() throws IOException; + boolean setMobilityConfig(CoreNode node, MobilityConfig config) throws IOException; MobilityConfig getMobilityConfig(CoreNode node) throws IOException; diff --git a/corefx/src/main/java/com/core/client/rest/CoreRestClient.java b/corefx/src/main/java/com/core/client/rest/CoreRestClient.java index 897cba92..b923b2e6 100644 --- a/corefx/src/main/java/com/core/client/rest/CoreRestClient.java +++ b/corefx/src/main/java/com/core/client/rest/CoreRestClient.java @@ -31,6 +31,11 @@ public class CoreRestClient implements ICoreClient { this.networkGraph = controller.getNetworkGraph(); } + @Override + public void setUrl(String url) { + this.baseUrl = url; + } + private String getUrl(String path) { return String.format("%s/%s", baseUrl, path); } @@ -89,32 +94,6 @@ public class CoreRestClient implements ICoreClient { return WebUtils.getJson(url, GetServices.class); } - @Override - public void initialJoin(String url) throws IOException { - this.baseUrl = url; - GetServices services = getServices(); - logger.info("core services: {}", services); - controller.getNodeServicesDialog().setServices(services); - - logger.info("initial core session join"); - GetSessions response = getSessions(); - - logger.info("existing sessions: {}", response); - if (response.getSessions().isEmpty()) { - logger.info("creating initial session"); - createSession(); - updateController(); - } else { - GetSessionsData getSessionsData = response.getSessions().get(0); - Integer joinId = getSessionsData.getId(); - joinSession(joinId, true); - } - - // set emane models - List emaneModels = getEmaneModels().getModels(); - controller.getNodeEmaneDialog().setModels(emaneModels); - } - @Override public GetSession getSession(Integer sessionId) throws IOException { String path = String.format("sessions/%s", sessionId); @@ -393,6 +372,12 @@ public class CoreRestClient implements ICoreClient { return WebUtils.postJson(url, config); } + @Override + public GetMobilityConfigs getMobilityConfigs() throws IOException { + String url = getUrl(String.format("sessions/%s/mobility/configs", sessionId)); + return WebUtils.getJson(url, GetMobilityConfigs.class); + } + @Override public MobilityConfig getMobilityConfig(CoreNode node) throws IOException { String url = getUrl(String.format("sessions/%s/nodes/%s/mobility", sessionId, node.getId())); diff --git a/corefx/src/main/java/com/core/client/rest/GetMobilityConfigs.java b/corefx/src/main/java/com/core/client/rest/GetMobilityConfigs.java new file mode 100644 index 00000000..4367476c --- /dev/null +++ b/corefx/src/main/java/com/core/client/rest/GetMobilityConfigs.java @@ -0,0 +1,11 @@ +package com.core.client.rest; + +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + +@Data +public class GetMobilityConfigs { + private Map> configurations = new HashMap<>(); +}