corefx - moved join session out into controller
This commit is contained in:
parent
5e33583dd4
commit
2694ae3630
5 changed files with 81 additions and 77 deletions
|
@ -2,9 +2,7 @@ package com.core;
|
||||||
|
|
||||||
import com.core.client.ICoreClient;
|
import com.core.client.ICoreClient;
|
||||||
import com.core.client.rest.*;
|
import com.core.client.rest.*;
|
||||||
import com.core.data.CoreLink;
|
import com.core.data.*;
|
||||||
import com.core.data.CoreNode;
|
|
||||||
import com.core.data.MobilityConfig;
|
|
||||||
import com.core.graph.NetworkGraph;
|
import com.core.graph.NetworkGraph;
|
||||||
import com.core.ui.*;
|
import com.core.ui.*;
|
||||||
import com.core.ui.dialogs.*;
|
import com.core.ui.dialogs.*;
|
||||||
|
@ -110,22 +108,68 @@ public class Controller implements Initializable {
|
||||||
GetSessions response = coreClient.getSessions();
|
GetSessions response = coreClient.getSessions();
|
||||||
|
|
||||||
logger.info("existing sessions: {}", response);
|
logger.info("existing sessions: {}", response);
|
||||||
|
Integer sessionId;
|
||||||
if (response.getSessions().isEmpty()) {
|
if (response.getSessions().isEmpty()) {
|
||||||
logger.info("creating initial session");
|
logger.info("creating initial session");
|
||||||
coreClient.createSession();
|
CreatedSession createdSession = coreClient.createSession();
|
||||||
graphToolbar.setRunButton(coreClient.isRunning());
|
sessionId = createdSession.getId();
|
||||||
hooksDialog.updateHooks();
|
Toast.info(String.format("Created Session %s", sessionId));
|
||||||
} else {
|
} else {
|
||||||
GetSessionsData getSessionsData = response.getSessions().get(0);
|
GetSessionsData getSessionsData = response.getSessions().get(0);
|
||||||
Integer joinId = getSessionsData.getId();
|
sessionId = getSessionsData.getId();
|
||||||
coreClient.joinSession(joinId, true);
|
Toast.info(String.format("Joined Session %s", sessionId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
joinSession(sessionId);
|
||||||
|
|
||||||
// set emane models
|
// set emane models
|
||||||
List<String> emaneModels = coreClient.getEmaneModels().getModels();
|
List<String> emaneModels = coreClient.getEmaneModels().getModels();
|
||||||
nodeEmaneDialog.setModels(emaneModels);
|
nodeEmaneDialog.setModels(emaneModels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void joinSession(Integer joinId) throws IOException {
|
||||||
|
// clear graph
|
||||||
|
networkGraph.reset();
|
||||||
|
|
||||||
|
// get session to join
|
||||||
|
GetSession session = coreClient.getSession(joinId);
|
||||||
|
SessionState sessionState = SessionState.get(session.getState());
|
||||||
|
|
||||||
|
// update client to use this session
|
||||||
|
coreClient.updateSession(joinId);
|
||||||
|
coreClient.updateState(sessionState);
|
||||||
|
|
||||||
|
// display all nodes
|
||||||
|
logger.info("joining core session({}) state({}): {}", joinId, sessionState, session);
|
||||||
|
for (CoreNode node : session.getNodes()) {
|
||||||
|
NodeType nodeType = NodeType.find(node.getType(), node.getModel());
|
||||||
|
if (nodeType == null) {
|
||||||
|
logger.info(String.format("failed to find node type(%s) model(%s): %s",
|
||||||
|
node.getType(), node.getModel(), node.getName()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
node.setNodeType(nodeType);
|
||||||
|
networkGraph.addNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// display all links
|
||||||
|
for (CoreLink link : session.getLinks()) {
|
||||||
|
if (link.getInterfaceOne() != null || link.getInterfaceTwo() != null) {
|
||||||
|
link.setType(LinkTypes.WIRED.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
networkGraph.addLink(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
// refresh graph
|
||||||
|
networkGraph.getGraphViewer().repaint();
|
||||||
|
|
||||||
|
// update other components for new session
|
||||||
|
graphToolbar.setRunButton(coreClient.isRunning());
|
||||||
|
hooksDialog.updateHooks();
|
||||||
|
}
|
||||||
|
|
||||||
public void sessionStarted() {
|
public void sessionStarted() {
|
||||||
// configure and add mobility player
|
// configure and add mobility player
|
||||||
CoreNode node = mobilityDialog.getNode();
|
CoreNode node = mobilityDialog.getNode();
|
||||||
|
@ -152,7 +196,7 @@ public class Controller implements Initializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWindow(Stage window) {
|
void setWindow(Stage window) {
|
||||||
this.window = window;
|
this.window = window;
|
||||||
sessionsDialog.setOwner(window);
|
sessionsDialog.setOwner(window);
|
||||||
hooksDialog.setOwner(window);
|
hooksDialog.setOwner(window);
|
||||||
|
@ -221,7 +265,10 @@ public class Controller implements Initializable {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
logger.info("opening session xml: {}", file.getPath());
|
logger.info("opening session xml: {}", file.getPath());
|
||||||
try {
|
try {
|
||||||
coreClient.openSession(file);
|
CreatedSession createdSession = coreClient.openSession(file);
|
||||||
|
Integer sessionId = createdSession.getId();
|
||||||
|
joinSession(sessionId);
|
||||||
|
Toast.info(String.format("Joined Session %s", sessionId));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error("error opening session xml", ex);
|
logger.error("error opening session xml", ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,11 @@ import java.util.List;
|
||||||
public interface ICoreClient {
|
public interface ICoreClient {
|
||||||
void setUrl(String url);
|
void setUrl(String url);
|
||||||
|
|
||||||
void joinSession(Integer joinId, boolean notification) throws IOException;
|
void updateSession(Integer sessionId);
|
||||||
|
|
||||||
void createSession() throws IOException;
|
void updateState(SessionState state);
|
||||||
|
|
||||||
|
CreatedSession createSession() throws IOException;
|
||||||
|
|
||||||
GetSessions getSessions() throws IOException;
|
GetSessions getSessions() throws IOException;
|
||||||
|
|
||||||
|
@ -22,8 +24,6 @@ public interface ICoreClient {
|
||||||
|
|
||||||
boolean stop() throws IOException;
|
boolean stop() throws IOException;
|
||||||
|
|
||||||
void updateState(SessionState state);
|
|
||||||
|
|
||||||
boolean setState(SessionState state) throws IOException;
|
boolean setState(SessionState state) throws IOException;
|
||||||
|
|
||||||
GetServices getServices() throws IOException;
|
GetServices getServices() throws IOException;
|
||||||
|
@ -50,7 +50,7 @@ public interface ICoreClient {
|
||||||
|
|
||||||
void saveSession(File file) throws IOException;
|
void saveSession(File file) throws IOException;
|
||||||
|
|
||||||
void openSession(File file) throws IOException;
|
CreatedSession openSession(File file) throws IOException;
|
||||||
|
|
||||||
GetConfig getSessionConfig() throws IOException;
|
GetConfig getSessionConfig() throws IOException;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import com.core.Controller;
|
||||||
import com.core.client.ICoreClient;
|
import com.core.client.ICoreClient;
|
||||||
import com.core.data.*;
|
import com.core.data.*;
|
||||||
import com.core.graph.NetworkGraph;
|
import com.core.graph.NetworkGraph;
|
||||||
import com.core.ui.Toast;
|
|
||||||
import com.core.utils.WebUtils;
|
import com.core.utils.WebUtils;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
@ -36,57 +35,24 @@ public class CoreRestClient implements ICoreClient {
|
||||||
this.baseUrl = url;
|
this.baseUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(SessionState state) {
|
||||||
|
sessionState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSession(Integer sessionId) {
|
||||||
|
this.sessionId = sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
private String getUrl(String path) {
|
private String getUrl(String path) {
|
||||||
return String.format("%s/%s", baseUrl, path);
|
return String.format("%s/%s", baseUrl, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void joinSession(Integer joinId, boolean notification) throws IOException {
|
public CreatedSession createSession() throws IOException {
|
||||||
networkGraph.reset();
|
|
||||||
GetSession session = getSession(joinId);
|
|
||||||
sessionId = joinId;
|
|
||||||
sessionState = SessionState.get(session.getState());
|
|
||||||
|
|
||||||
logger.info("joining core session({}) state({}): {}", sessionId, sessionState, session);
|
|
||||||
for (CoreNode node : session.getNodes()) {
|
|
||||||
NodeType nodeType = NodeType.find(node.getType(), node.getModel());
|
|
||||||
if (nodeType == null) {
|
|
||||||
logger.info(String.format("failed to find node type(%s) model(%s): %s",
|
|
||||||
node.getType(), node.getModel(), node.getName()));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
node.setNodeType(nodeType);
|
|
||||||
networkGraph.addNode(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (CoreLink link : session.getLinks()) {
|
|
||||||
if (link.getInterfaceOne() != null || link.getInterfaceTwo() != null) {
|
|
||||||
link.setType(LinkTypes.WIRED.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
networkGraph.addLink(link);
|
|
||||||
}
|
|
||||||
|
|
||||||
networkGraph.getGraphViewer().repaint();
|
|
||||||
|
|
||||||
if (notification) {
|
|
||||||
Toast.info(String.format("Joined Session %s", sessionId.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
updateController();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createSession() throws IOException {
|
|
||||||
String url = getUrl("sessions");
|
String url = getUrl("sessions");
|
||||||
CreatedSession session = WebUtils.post(url, CreatedSession.class);
|
return WebUtils.post(url, CreatedSession.class);
|
||||||
|
|
||||||
logger.info("created session: {}", session);
|
|
||||||
sessionId = session.getId();
|
|
||||||
sessionState = SessionState.get(session.getState());
|
|
||||||
Toast.info(String.format("Created Session %s", sessionId.toString()));
|
|
||||||
joinSession(sessionId, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetServices getServices() throws IOException {
|
public GetServices getServices() throws IOException {
|
||||||
|
@ -159,11 +125,6 @@ public class CoreRestClient implements ICoreClient {
|
||||||
return setState(SessionState.SHUTDOWN);
|
return setState(SessionState.SHUTDOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateState(SessionState state) {
|
|
||||||
sessionState = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setState(SessionState state) throws IOException {
|
public boolean setState(SessionState state) throws IOException {
|
||||||
String url = getUrl(String.format("sessions/%s/state", sessionId));
|
String url = getUrl(String.format("sessions/%s/state", sessionId));
|
||||||
|
@ -252,11 +213,6 @@ public class CoreRestClient implements ICoreClient {
|
||||||
return WebUtils.putJson(url, setEmaneModelConfig);
|
return WebUtils.putJson(url, setEmaneModelConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateController() {
|
|
||||||
controller.getGraphToolbar().setRunButton(isRunning());
|
|
||||||
controller.getHooksDialog().updateHooks();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRunning() {
|
public boolean isRunning() {
|
||||||
return sessionState == SessionState.RUNTIME;
|
return sessionState == SessionState.RUNTIME;
|
||||||
|
@ -270,10 +226,9 @@ public class CoreRestClient implements ICoreClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openSession(File file) throws IOException {
|
public CreatedSession openSession(File file) throws IOException {
|
||||||
String url = getUrl("sessions/xml");
|
String url = getUrl("sessions/xml");
|
||||||
CreatedSession createdSession = WebUtils.postFile(url, file, CreatedSession.class);
|
return WebUtils.postFile(url, file, CreatedSession.class);
|
||||||
joinSession(createdSession.getId(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,7 +34,8 @@ public class SessionsDialog extends StageDialog {
|
||||||
SessionRow row = sessionsTable.getSelectionModel().getSelectedItem();
|
SessionRow row = sessionsTable.getSelectionModel().getSelectedItem();
|
||||||
logger.info("selected session: {}", row);
|
logger.info("selected session: {}", row);
|
||||||
try {
|
try {
|
||||||
getCoreClient().joinSession(row.getId(), true);
|
getController().joinSession(row.getId());
|
||||||
|
Toast.info(String.format("Joined Session %s", row.getId()));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Toast.error(String.format("error joining session: %s", row.getId()), ex);
|
Toast.error(String.format("error joining session: %s", row.getId()), ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import com.core.Controller;
|
||||||
import com.core.client.rest.GetSessions;
|
import com.core.client.rest.GetSessions;
|
||||||
import com.core.client.rest.GetSessionsData;
|
import com.core.client.rest.GetSessionsData;
|
||||||
import com.core.data.SessionState;
|
import com.core.data.SessionState;
|
||||||
import com.core.ui.dialogs.CoreFoenixDialog;
|
import com.core.ui.Toast;
|
||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
|
@ -32,7 +32,8 @@ public class SessionsFoenixDialog extends CoreFoenixDialog {
|
||||||
SessionRow row = sessionsTable.getSelectionModel().getSelectedItem();
|
SessionRow row = sessionsTable.getSelectionModel().getSelectedItem();
|
||||||
logger.info("selected session: {}", row);
|
logger.info("selected session: {}", row);
|
||||||
try {
|
try {
|
||||||
getCoreClient().joinSession(row.getId(), true);
|
getController().joinSession(row.getId());
|
||||||
|
Toast.info(String.format("Joined Session %s", row.getId()));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error("error joining session: {}", row.getId());
|
logger.error("error joining session: {}", row.getId());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue