moved initial join logic to controller to help avoid tying it into the core client

This commit is contained in:
Blake J. Harnden 2018-11-21 09:59:51 -08:00
parent ac81b7c81a
commit 5e33583dd4
4 changed files with 54 additions and 33 deletions

View file

@ -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<String> emaneModels = coreClient.getEmaneModels().getModels();
nodeEmaneDialog.setModels(emaneModels);
}
public void sessionStarted() {
// configure and add mobility player
CoreNode node = mobilityDialog.getNode();

View file

@ -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;

View file

@ -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<String> 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()));

View file

@ -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<Integer, Map<String, ConfigGroup>> configurations = new HashMap<>();
}