corefx - updated client interface to use non rest specific classes

This commit is contained in:
Blake J. Harnden 2018-11-26 10:42:02 -08:00
parent 1877d864dc
commit bd1edabb7c
26 changed files with 132 additions and 119 deletions

View file

@ -1,7 +1,7 @@
package com.core;
import com.core.client.ICoreClient;
import com.core.client.rest.*;
import com.core.client.rest.CoreRestClient;
import com.core.data.*;
import com.core.graph.NetworkGraph;
import com.core.ui.*;
@ -100,30 +100,30 @@ public class Controller implements Initializable {
}
private void initialJoin() throws IOException {
GetServices services = coreClient.getServices();
logger.info("core services: {}", services);
nodeServicesDialog.setServices(services);
Map<String, List<String>> serviceGroups = coreClient.getServices();
logger.info("core services: {}", serviceGroups);
nodeServicesDialog.setServices(serviceGroups);
logger.info("initial core session join");
GetSessions response = coreClient.getSessions();
List<SessionOverview> sessions = coreClient.getSessions();
logger.info("existing sessions: {}", response);
logger.info("existing sessions: {}", sessions);
Integer sessionId;
if (response.getSessions().isEmpty()) {
if (sessions.isEmpty()) {
logger.info("creating initial session");
CreatedSession createdSession = coreClient.createSession();
sessionId = createdSession.getId();
SessionOverview sessionOverview = coreClient.createSession();
sessionId = sessionOverview.getId();
Toast.info(String.format("Created Session %s", sessionId));
} else {
GetSessionsData getSessionsData = response.getSessions().get(0);
sessionId = getSessionsData.getId();
SessionOverview sessionOverview = sessions.get(0);
sessionId = sessionOverview.getId();
Toast.info(String.format("Joined Session %s", sessionId));
}
joinSession(sessionId);
// set emane models
List<String> emaneModels = coreClient.getEmaneModels().getModels();
List<String> emaneModels = coreClient.getEmaneModels();
nodeEmaneDialog.setModels(emaneModels);
}
@ -132,7 +132,7 @@ public class Controller implements Initializable {
networkGraph.reset();
// get session to join
GetSession session = coreClient.getSession(joinId);
Session session = coreClient.getSession(joinId);
SessionState sessionState = SessionState.get(session.getState());
// update client to use this session
@ -170,11 +170,11 @@ public class Controller implements Initializable {
hooksDialog.updateHooks();
// display first mobility script in player
GetMobilityConfigs getMobilityConfigs = coreClient.getMobilityConfigs();
Optional<Integer> nodeIdOptional = getMobilityConfigs.getConfigurations().keySet().stream().findFirst();
Map<Integer, MobilityConfig> mobilityConfigMap = coreClient.getMobilityConfigs();
Optional<Integer> nodeIdOptional = mobilityConfigMap.keySet().stream().findFirst();
if (nodeIdOptional.isPresent()) {
Integer nodeId = nodeIdOptional.get();
MobilityConfig mobilityConfig = getMobilityConfigs.getConfigurations().get(nodeId);
MobilityConfig mobilityConfig = mobilityConfigMap.get(nodeId);
CoreNode node = networkGraph.getVertex(nodeId);
mobilityPlayer.show(node, mobilityConfig);
Platform.runLater(() -> bottom.getChildren().add(mobilityPlayer));
@ -305,8 +305,8 @@ public class Controller implements Initializable {
if (file != null) {
logger.info("opening session xml: {}", file.getPath());
try {
CreatedSession createdSession = coreClient.openSession(file);
Integer sessionId = createdSession.getId();
SessionOverview sessionOverview = coreClient.openSession(file);
Integer sessionId = sessionOverview.getId();
joinSession(sessionId);
Toast.info(String.format("Joined Session %s", sessionId));
} catch (IOException ex) {
@ -352,12 +352,11 @@ public class Controller implements Initializable {
@FXML
private void onSessionOptionsMenu(ActionEvent event) {
try {
GetConfig config = coreClient.getSessionConfig();
configDialog.showDialog("Session Options", config, () -> {
List<ConfigGroup> configGroups = coreClient.getSessionConfig();
configDialog.showDialog("Session Options", configGroups, () -> {
List<ConfigOption> options = configDialog.getOptions();
SetConfig setConfig = new SetConfig(options);
try {
boolean result = coreClient.setSessionConfig(setConfig);
boolean result = coreClient.setSessionConfig(options);
if (result) {
Toast.info("Session options saved");
} else {

View file

@ -1,12 +1,14 @@
package com.core.client;
import com.core.client.rest.*;
import com.core.client.rest.ServiceFile;
import com.core.client.rest.WlanConfig;
import com.core.data.*;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public interface ICoreClient {
void setUrl(String url);
@ -15,11 +17,11 @@ public interface ICoreClient {
void updateState(SessionState state);
CreatedSession createSession() throws IOException;
SessionOverview createSession() throws IOException;
GetSessions getSessions() throws IOException;
List<SessionOverview> getSessions() throws IOException;
GetSession getSession(Integer sessionId) throws IOException;
Session getSession(Integer sessionId) throws IOException;
boolean start(Collection<CoreNode> nodes, Collection<CoreLink> links, List<Hook> hooks) throws IOException;
@ -27,7 +29,7 @@ public interface ICoreClient {
boolean setState(SessionState state) throws IOException;
GetServices getServices() throws IOException;
Map<String, List<String>> getServices() throws IOException;
CoreService getService(CoreNode node, String serviceName) throws IOException;
@ -37,13 +39,13 @@ public interface ICoreClient {
boolean setServiceFile(CoreNode node, String serviceName, ServiceFile serviceFile) throws IOException;
GetConfig getEmaneConfig(CoreNode node) throws IOException;
List<ConfigGroup> getEmaneConfig(CoreNode node) throws IOException;
GetEmaneModels getEmaneModels() throws IOException;
List<String> getEmaneModels() throws IOException;
boolean setEmaneConfig(CoreNode node, List<ConfigOption> options) throws IOException;
GetConfig getEmaneModelConfig(Integer id, String model) throws IOException;
List<ConfigGroup> getEmaneModelConfig(Integer id, String model) throws IOException;
boolean setEmaneModelConfig(Integer id, String model, List<ConfigOption> options) throws IOException;
@ -51,11 +53,11 @@ public interface ICoreClient {
void saveSession(File file) throws IOException;
CreatedSession openSession(File file) throws IOException;
SessionOverview openSession(File file) throws IOException;
GetConfig getSessionConfig() throws IOException;
List<ConfigGroup> getSessionConfig() throws IOException;
boolean setSessionConfig(SetConfig config) throws IOException;
boolean setSessionConfig(List<ConfigOption> configOptions) throws IOException;
boolean createNode(CoreNode node) throws IOException;
@ -69,7 +71,7 @@ public interface ICoreClient {
boolean createHook(Hook hook) throws IOException;
GetHooks getHooks() throws IOException;
List<Hook> getHooks() throws IOException;
WlanConfig getWlanConfig(CoreNode node) throws IOException;
@ -77,7 +79,7 @@ public interface ICoreClient {
String getTerminalCommand(CoreNode node) throws IOException;
GetMobilityConfigs getMobilityConfigs() throws IOException;
Map<Integer, MobilityConfig> getMobilityConfigs() throws IOException;
boolean setMobilityConfig(CoreNode node, MobilityConfig config) throws IOException;

View file

@ -41,27 +41,29 @@ public class CoreRestClient implements ICoreClient {
}
@Override
public CreatedSession createSession() throws IOException {
public SessionOverview createSession() throws IOException {
String url = getUrl("sessions");
return WebUtils.post(url, CreatedSession.class);
return WebUtils.post(url, SessionOverview.class);
}
public GetServices getServices() throws IOException {
public Map<String, List<String>> getServices() throws IOException {
String url = getUrl("services");
return WebUtils.getJson(url, GetServices.class);
GetServices getServices = WebUtils.getJson(url, GetServices.class);
return getServices.getGroups();
}
@Override
public GetSession getSession(Integer sessionId) throws IOException {
public Session getSession(Integer sessionId) throws IOException {
String path = String.format("sessions/%s", sessionId);
String url = getUrl(path);
return WebUtils.getJson(url, GetSession.class);
return WebUtils.getJson(url, Session.class);
}
@Override
public GetSessions getSessions() throws IOException {
public List<SessionOverview> getSessions() throws IOException {
String url = getUrl("sessions");
return WebUtils.getJson(url, GetSessions.class);
GetSessions getSessions = WebUtils.getJson(url, GetSessions.class);
return getSessions.getSessions();
}
@Override
@ -155,26 +157,29 @@ public class CoreRestClient implements ICoreClient {
}
@Override
public GetEmaneModels getEmaneModels() throws IOException {
public List<String> getEmaneModels() throws IOException {
String url = getUrl(String.format("sessions/%s/emane/models", sessionId));
return WebUtils.getJson(url, GetEmaneModels.class);
GetEmaneModels getEmaneModels = WebUtils.getJson(url, GetEmaneModels.class);
return getEmaneModels.getModels();
}
@Override
public GetConfig getEmaneModelConfig(Integer id, String model) throws IOException {
public List<ConfigGroup> getEmaneModelConfig(Integer id, String model) throws IOException {
String url = getUrl(String.format("sessions/%s/emane/model/config", sessionId));
Map<String, String> args = new HashMap<>();
args.put("node", id.toString());
args.put("name", model);
return WebUtils.getJson(url, GetConfig.class, args);
GetConfig getConfig = WebUtils.getJson(url, GetConfig.class, args);
return getConfig.getGroups();
}
@Override
public GetConfig getEmaneConfig(CoreNode node) throws IOException {
public List<ConfigGroup> getEmaneConfig(CoreNode node) throws IOException {
String url = getUrl(String.format("sessions/%s/emane/config", sessionId));
Map<String, String> args = new HashMap<>();
args.put("node", node.getId().toString());
return WebUtils.getJson(url, GetConfig.class, args);
GetConfig getConfig = WebUtils.getJson(url, GetConfig.class, args);
return getConfig.getGroups();
}
@Override
@ -209,21 +214,23 @@ public class CoreRestClient implements ICoreClient {
}
@Override
public CreatedSession openSession(File file) throws IOException {
public SessionOverview openSession(File file) throws IOException {
String url = getUrl("sessions/xml");
return WebUtils.postFile(url, file, CreatedSession.class);
return WebUtils.postFile(url, file, SessionOverview.class);
}
@Override
public GetConfig getSessionConfig() throws IOException {
public List<ConfigGroup> getSessionConfig() throws IOException {
String url = getUrl(String.format("sessions/%s/options", sessionId));
return WebUtils.getJson(url, GetConfig.class);
GetConfig getConfig = WebUtils.getJson(url, GetConfig.class);
return getConfig.getGroups();
}
@Override
public boolean setSessionConfig(SetConfig config) throws IOException {
public boolean setSessionConfig(List<ConfigOption> configOptions) throws IOException {
String url = getUrl(String.format("sessions/%s/options", sessionId));
return WebUtils.putJson(url, config);
SetConfig setConfig = new SetConfig(configOptions);
return WebUtils.putJson(url, setConfig);
}
@Override
@ -275,9 +282,10 @@ public class CoreRestClient implements ICoreClient {
}
@Override
public GetHooks getHooks() throws IOException {
public List<Hook> getHooks() throws IOException {
String url = getUrl(String.format("sessions/%s/hooks", sessionId));
return WebUtils.getJson(url, GetHooks.class);
GetHooks getHooks = WebUtils.getJson(url, GetHooks.class);
return getHooks.getHooks();
}
@Override
@ -311,9 +319,10 @@ public class CoreRestClient implements ICoreClient {
}
@Override
public GetMobilityConfigs getMobilityConfigs() throws IOException {
public Map<Integer, MobilityConfig> getMobilityConfigs() throws IOException {
String url = getUrl(String.format("sessions/%s/mobility/configs", sessionId));
return WebUtils.getJson(url, GetMobilityConfigs.class);
GetMobilityConfigs getMobilityConfigs = WebUtils.getJson(url, GetMobilityConfigs.class);
return getMobilityConfigs.getConfigurations();
}
@Override

View file

@ -1,10 +0,0 @@
package com.core.client.rest;
import lombok.Data;
@Data
public class CreatedSession {
private Integer id;
private Integer state;
private String url;
}

View file

@ -1,5 +1,6 @@
package com.core.client.rest;
import com.core.data.ConfigGroup;
import lombok.Data;
import java.util.ArrayList;

View file

@ -1,5 +1,6 @@
package com.core.client.rest;
import com.core.data.SessionOverview;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -9,5 +10,5 @@ import java.util.List;
@Data
@NoArgsConstructor
public class GetSessions {
private List<GetSessionsData> sessions = new ArrayList<>();
private List<SessionOverview> sessions = new ArrayList<>();
}

View file

@ -1,5 +1,6 @@
package com.core.client.rest;
import com.core.data.ConfigOption;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

View file

@ -1,5 +1,6 @@
package com.core.client.rest;
import com.core.data.ConfigOption;
import lombok.Data;
import java.util.ArrayList;

View file

@ -1,5 +1,6 @@
package com.core.client.rest;
import com.core.data.ConfigOption;
import lombok.Data;
import java.util.ArrayList;

View file

@ -1,4 +1,4 @@
package com.core.client.rest;
package com.core.data;
import lombok.Data;

View file

@ -1,4 +1,4 @@
package com.core.client.rest;
package com.core.data;
import lombok.Data;

View file

@ -1,7 +1,5 @@
package com.core.client.rest;
package com.core.data;
import com.core.data.CoreNode;
import com.core.data.CoreLink;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -10,7 +8,7 @@ import java.util.List;
@Data
@NoArgsConstructor
public class GetSession {
public class Session {
private Integer state;
private List<CoreNode> nodes = new ArrayList<>();
private List<CoreLink> links = new ArrayList<>();

View file

@ -0,0 +1,13 @@
package com.core.data;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class SessionOverview {
private Integer id;
private Integer state;
private Integer nodes = 0;
private String url;
}

View file

@ -1,6 +1,6 @@
package com.core.ui.config;
import com.core.client.rest.ConfigOption;
import com.core.data.ConfigOption;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import lombok.Data;

View file

@ -1,6 +1,6 @@
package com.core.ui.config;
import com.core.client.rest.ConfigOption;
import com.core.data.ConfigOption;
import com.jfoenix.controls.JFXToggleButton;
import javafx.scene.Node;
import javafx.stage.Stage;

View file

@ -1,6 +1,6 @@
package com.core.ui.config;
import com.core.client.rest.ConfigOption;
import com.core.data.ConfigOption;
import com.core.data.ConfigDataType;
import javafx.stage.Stage;

View file

@ -1,6 +1,6 @@
package com.core.ui.config;
import com.core.client.rest.ConfigOption;
import com.core.data.ConfigOption;
import com.jfoenix.controls.JFXTextField;
import javafx.scene.Node;
import javafx.stage.Stage;

View file

@ -1,6 +1,6 @@
package com.core.ui.config;
import com.core.client.rest.ConfigOption;
import com.core.data.ConfigOption;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXTextField;
import javafx.scene.Node;

View file

@ -1,6 +1,6 @@
package com.core.ui.config;
import com.core.client.rest.ConfigOption;
import com.core.data.ConfigOption;
import javafx.scene.Node;
import javafx.scene.control.Label;

View file

@ -1,6 +1,6 @@
package com.core.ui.config;
import com.core.client.rest.ConfigOption;
import com.core.data.ConfigOption;
import com.jfoenix.controls.JFXComboBox;
import javafx.scene.Node;
import javafx.stage.Stage;

View file

@ -1,9 +1,8 @@
package com.core.ui.dialogs;
import com.core.Controller;
import com.core.client.rest.ConfigGroup;
import com.core.client.rest.ConfigOption;
import com.core.client.rest.GetConfig;
import com.core.data.ConfigGroup;
import com.core.data.ConfigOption;
import com.core.ui.config.ConfigItemUtils;
import com.core.ui.config.IConfigItem;
import com.jfoenix.controls.JFXButton;
@ -38,12 +37,12 @@ public class ConfigDialog extends StageDialog {
return configItems.stream().map(IConfigItem::getOption).collect(Collectors.toList());
}
public void showDialog(String title, GetConfig getConfig, Runnable runnable) {
public void showDialog(String title, List<ConfigGroup> configGroups, Runnable runnable) {
setTitle(title);
configItems.clear();
tabPane.getTabs().clear();
for (ConfigGroup group : getConfig.getGroups()) {
for (ConfigGroup group : configGroups) {
String groupName = group.getName();
Tab tab = new Tab(groupName);
ScrollPane scrollPane = new ScrollPane();

View file

@ -1,7 +1,6 @@
package com.core.ui.dialogs;
import com.core.Controller;
import com.core.client.rest.GetHooks;
import com.core.data.Hook;
import com.core.data.SessionState;
import com.core.ui.Toast;
@ -98,8 +97,8 @@ public class HooksDialog extends StageDialog {
// update hooks
try {
GetHooks getHooks = getCoreClient().getHooks();
for (Hook hook : getHooks.getHooks()) {
List<Hook> hooks = getCoreClient().getHooks();
for (Hook hook : hooks) {
SessionState state = SessionState.get(hook.getState());
hook.setStateDisplay(state.name());
hooksTable.getItems().add(hook);

View file

@ -1,8 +1,8 @@
package com.core.ui.dialogs;
import com.core.Controller;
import com.core.client.rest.ConfigOption;
import com.core.client.rest.GetConfig;
import com.core.data.ConfigGroup;
import com.core.data.ConfigOption;
import com.core.data.CoreNode;
import com.core.ui.Toast;
import com.jfoenix.controls.JFXButton;
@ -50,10 +50,10 @@ public class NodeEmaneDialog extends StageDialog {
private void emaneButtonHandler(ActionEvent event) {
try {
GetConfig getConfig = getCoreClient().getEmaneConfig(coreNode);
logger.debug("emane model config: {}", getConfig);
List<ConfigGroup> configGroups = getCoreClient().getEmaneConfig(coreNode);
logger.debug("emane model config: {}", configGroups);
String title = String.format("%s EMANE Config", coreNode.getName());
getController().getConfigDialog().showDialog(title, getConfig, () -> {
getController().getConfigDialog().showDialog(title, configGroups, () -> {
List<ConfigOption> options = getController().getConfigDialog().getOptions();
try {
getCoreClient().setEmaneConfig(coreNode, options);
@ -73,10 +73,10 @@ public class NodeEmaneDialog extends StageDialog {
public void displayEmaneModelConfig(Integer id, String model) {
try {
GetConfig getConfig = getCoreClient().getEmaneModelConfig(id, model);
logger.debug("emane model config: {}", getConfig);
List<ConfigGroup> configGroups = getCoreClient().getEmaneModelConfig(id, model);
logger.debug("emane model config: {}", configGroups);
String title = String.format("EMANE(%s) %s Config", id, model);
getController().getConfigDialog().showDialog(title, getConfig, () -> {
getController().getConfigDialog().showDialog(title, configGroups, () -> {
List<ConfigOption> options = getController().getConfigDialog().getOptions();
try {
getCoreClient().setEmaneModelConfig(id, model, options);

View file

@ -1,7 +1,6 @@
package com.core.ui.dialogs;
import com.core.Controller;
import com.core.client.rest.GetServices;
import com.core.data.CoreNode;
import com.core.ui.ServiceItem;
import com.jfoenix.controls.JFXButton;
@ -81,14 +80,14 @@ public class NodeServicesDialog extends StageDialog {
});
}
public void setServices(GetServices getServices) {
public void setServices(Map<String, List<String>> serviceGroups) {
serviceItemGroups.clear();
getServices.getGroups().keySet().stream()
serviceGroups.keySet().stream()
.sorted()
.forEach(group -> {
groupListView.getItems().add(group);
getServices.getGroups().get(group).stream()
serviceGroups.get(group).stream()
.sorted()
.forEach(service -> {
ServiceItem serviceItem = new ServiceItem(service);

View file

@ -1,8 +1,7 @@
package com.core.ui.dialogs;
import com.core.Controller;
import com.core.client.rest.GetSessions;
import com.core.client.rest.GetSessionsData;
import com.core.data.SessionOverview;
import com.core.data.SessionState;
import com.core.ui.Toast;
import com.jfoenix.controls.JFXButton;
@ -15,6 +14,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
public class SessionsDialog extends StageDialog {
@ -55,17 +55,17 @@ public class SessionsDialog extends StageDialog {
private String state;
private Integer nodes;
public SessionRow(GetSessionsData getSessionsData) {
id = getSessionsData.getId();
state = SessionState.get(getSessionsData.getState()).name();
nodes = getSessionsData.getNodes();
public SessionRow(SessionOverview sessionOverview) {
id = sessionOverview.getId();
state = SessionState.get(sessionOverview.getState()).name();
nodes = sessionOverview.getNodes();
}
}
public void showDialog() throws IOException {
sessionsTable.getItems().clear();
GetSessions getSessions = getCoreClient().getSessions();
sessionsTable.getItems().addAll(getSessions.getSessions().stream()
List<SessionOverview> sessions = getCoreClient().getSessions();
sessionsTable.getItems().addAll(sessions.stream()
.map(SessionRow::new)
.collect(Collectors.toList()));

View file

@ -1,8 +1,7 @@
package com.core.ui.dialogs;
import com.core.Controller;
import com.core.client.rest.GetSessions;
import com.core.client.rest.GetSessionsData;
import com.core.data.SessionOverview;
import com.core.data.SessionState;
import com.core.ui.Toast;
import com.jfoenix.controls.JFXButton;
@ -15,6 +14,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
public class SessionsFoenixDialog extends CoreFoenixDialog {
@ -52,17 +52,17 @@ public class SessionsFoenixDialog extends CoreFoenixDialog {
private String state;
private Integer nodes;
public SessionRow(GetSessionsData getSessionsData) {
id = getSessionsData.getId();
state = SessionState.get(getSessionsData.getState()).name();
nodes = getSessionsData.getNodes();
public SessionRow(SessionOverview sessionOverview) {
id = sessionOverview.getId();
state = SessionState.get(sessionOverview.getState()).name();
nodes = sessionOverview.getNodes();
}
}
public void showDialog() throws IOException {
sessionsTable.getItems().clear();
GetSessions getSessions = getCoreClient().getSessions();
sessionsTable.getItems().addAll(getSessions.getSessions().stream()
List<SessionOverview> sessions = getCoreClient().getSessions();
sessionsTable.getItems().addAll(sessions.stream()
.map(SessionRow::new)
.collect(Collectors.toList()));
getDialog().show(getController().getStackPane());