moved initial join logic to controller to help avoid tying it into the core client
This commit is contained in:
parent
ac81b7c81a
commit
5e33583dd4
4 changed files with 54 additions and 33 deletions
|
@ -1,10 +1,7 @@
|
||||||
package com.core;
|
package com.core;
|
||||||
|
|
||||||
import com.core.client.ICoreClient;
|
import com.core.client.ICoreClient;
|
||||||
import com.core.client.rest.ConfigOption;
|
import com.core.client.rest.*;
|
||||||
import com.core.client.rest.CoreRestClient;
|
|
||||||
import com.core.client.rest.GetConfig;
|
|
||||||
import com.core.client.rest.SetConfig;
|
|
||||||
import com.core.data.CoreLink;
|
import com.core.data.CoreLink;
|
||||||
import com.core.data.CoreNode;
|
import com.core.data.CoreNode;
|
||||||
import com.core.data.MobilityConfig;
|
import com.core.data.MobilityConfig;
|
||||||
|
@ -95,7 +92,8 @@ public class Controller implements Initializable {
|
||||||
executorService.submit(() -> {
|
executorService.submit(() -> {
|
||||||
try {
|
try {
|
||||||
coreWebSocket.start(coreUrl);
|
coreWebSocket.start(coreUrl);
|
||||||
coreClient.initialJoin(coreUrl);
|
coreClient.setUrl(coreUrl);
|
||||||
|
initialJoin();
|
||||||
} catch (IOException | URISyntaxException ex) {
|
} catch (IOException | URISyntaxException ex) {
|
||||||
Toast.error(String.format("Connection failure: %s", ex.getMessage()), ex);
|
Toast.error(String.format("Connection failure: %s", ex.getMessage()), ex);
|
||||||
Platform.runLater(() -> connectDialog.showDialog());
|
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() {
|
public void sessionStarted() {
|
||||||
// configure and add mobility player
|
// configure and add mobility player
|
||||||
CoreNode node = mobilityDialog.getNode();
|
CoreNode node = mobilityDialog.getNode();
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ICoreClient {
|
public interface ICoreClient {
|
||||||
|
void setUrl(String url);
|
||||||
|
|
||||||
void joinSession(Integer joinId, boolean notification) throws IOException;
|
void joinSession(Integer joinId, boolean notification) throws IOException;
|
||||||
|
|
||||||
void createSession() throws IOException;
|
void createSession() throws IOException;
|
||||||
|
@ -16,8 +18,6 @@ public interface ICoreClient {
|
||||||
|
|
||||||
GetSession getSession(Integer sessionId) throws IOException;
|
GetSession getSession(Integer sessionId) throws IOException;
|
||||||
|
|
||||||
void initialJoin(String url) throws IOException;
|
|
||||||
|
|
||||||
boolean start() throws IOException;
|
boolean start() throws IOException;
|
||||||
|
|
||||||
boolean stop() throws IOException;
|
boolean stop() throws IOException;
|
||||||
|
@ -76,6 +76,8 @@ public interface ICoreClient {
|
||||||
|
|
||||||
String getTerminalCommand(CoreNode node) throws IOException;
|
String getTerminalCommand(CoreNode node) throws IOException;
|
||||||
|
|
||||||
|
GetMobilityConfigs getMobilityConfigs() throws IOException;
|
||||||
|
|
||||||
boolean setMobilityConfig(CoreNode node, MobilityConfig config) throws IOException;
|
boolean setMobilityConfig(CoreNode node, MobilityConfig config) throws IOException;
|
||||||
|
|
||||||
MobilityConfig getMobilityConfig(CoreNode node) throws IOException;
|
MobilityConfig getMobilityConfig(CoreNode node) throws IOException;
|
||||||
|
|
|
@ -31,6 +31,11 @@ public class CoreRestClient implements ICoreClient {
|
||||||
this.networkGraph = controller.getNetworkGraph();
|
this.networkGraph = controller.getNetworkGraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.baseUrl = url;
|
||||||
|
}
|
||||||
|
|
||||||
private String getUrl(String path) {
|
private String getUrl(String path) {
|
||||||
return String.format("%s/%s", baseUrl, path);
|
return String.format("%s/%s", baseUrl, path);
|
||||||
}
|
}
|
||||||
|
@ -89,32 +94,6 @@ public class CoreRestClient implements ICoreClient {
|
||||||
return WebUtils.getJson(url, GetServices.class);
|
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
|
@Override
|
||||||
public GetSession getSession(Integer sessionId) throws IOException {
|
public GetSession getSession(Integer sessionId) throws IOException {
|
||||||
String path = String.format("sessions/%s", sessionId);
|
String path = String.format("sessions/%s", sessionId);
|
||||||
|
@ -393,6 +372,12 @@ public class CoreRestClient implements ICoreClient {
|
||||||
return WebUtils.postJson(url, config);
|
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
|
@Override
|
||||||
public MobilityConfig getMobilityConfig(CoreNode node) throws IOException {
|
public MobilityConfig getMobilityConfig(CoreNode node) throws IOException {
|
||||||
String url = getUrl(String.format("sessions/%s/nodes/%s/mobility", sessionId, node.getId()));
|
String url = getUrl(String.format("sessions/%s/nodes/%s/mobility", sessionId, node.getId()));
|
||||||
|
|
|
@ -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<>();
|
||||||
|
}
|
Loading…
Reference in a new issue