corefx updated to use latest proto file, moved websocket into rest client

This commit is contained in:
Blake J. Harnden 2019-05-30 10:15:00 -07:00
parent 2ed2b4a879
commit 2ba8669c5c
3 changed files with 19 additions and 16 deletions

View file

@ -9,7 +9,6 @@ import com.core.ui.dialogs.*;
import com.core.utils.ConfigUtils;
import com.core.utils.Configuration;
import com.core.utils.NodeTypeConfig;
import com.core.websocket.CoreWebSocket;
import com.jfoenix.controls.JFXDecorator;
import com.jfoenix.controls.JFXProgressBar;
import javafx.application.Application;
@ -33,7 +32,6 @@ import org.apache.logging.log4j.Logger;
import java.awt.event.ItemEvent;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ExecutorService;
@ -63,7 +61,6 @@ public class Controller implements Initializable {
// core client utilities
private ICoreClient coreClient = new CoreGrpcClient();
private CoreWebSocket coreWebSocket;
// ui elements
private NetworkGraph networkGraph = new NetworkGraph(this);
@ -91,15 +88,12 @@ public class Controller implements Initializable {
private NodeTypeCreateDialog nodeTypeCreateDialog = new NodeTypeCreateDialog(this);
public void connectToCore(String address, int port) {
coreWebSocket.stop();
ExecutorService executorService = Executors.newSingleThreadExecutor();
// ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(() -> {
try {
coreWebSocket.start(address, port);
coreClient.setConnection(address, port);
initialJoin();
} catch (IOException | URISyntaxException ex) {
} catch (IOException ex) {
Toast.error(String.format("Connection failure: %s", ex.getMessage()), ex);
Platform.runLater(() -> connectDialog.showDialog());
}
@ -456,7 +450,6 @@ public class Controller implements Initializable {
@Override
public void initialize(URL location, ResourceBundle resources) {
coreWebSocket = new CoreWebSocket(this);
configuration = ConfigUtils.load();
String address = configuration.getCoreAddress();
int port = configuration.getCorePort();

View file

@ -39,7 +39,7 @@ public class CoreGrpcClient implements ICoreClient {
.build();
CoreProto.Node.Builder builder = CoreProto.Node.newBuilder()
.addAllServices(node.getServices())
.setType(CoreProto.NodeType.forNumber(node.getType()))
.setType(CoreProto.NodeType.Enum.forNumber(node.getType()))
.setPosition(position);
if (node.getId() != null) {
builder.setId(node.getId());
@ -300,7 +300,7 @@ public class CoreGrpcClient implements ICoreClient {
CoreProto.GetSessionResponse response = blockingStub.getSession(request);
Session session = new Session();
for (CoreProto.Node protoNode : response.getSession().getNodesList()) {
if (CoreProto.NodeType.NODE_PEER_TO_PEER == protoNode.getType()) {
if (CoreProto.NodeType.Enum.PEER_TO_PEER == protoNode.getType()) {
continue;
}
@ -498,7 +498,7 @@ public class CoreGrpcClient implements ICoreClient {
.setSessionId(sessionId)
.setNodeId(node.getId())
.setService(serviceName)
.setAction(CoreProto.ServiceAction.SERVICE_START)
.setAction(CoreProto.ServiceAction.Enum.START)
.build();
try {
return blockingStub.serviceAction(request).getResult();
@ -513,7 +513,7 @@ public class CoreGrpcClient implements ICoreClient {
.setSessionId(sessionId)
.setNodeId(node.getId())
.setService(serviceName)
.setAction(CoreProto.ServiceAction.SERVICE_STOP)
.setAction(CoreProto.ServiceAction.Enum.STOP)
.build();
try {
return blockingStub.serviceAction(request).getResult();
@ -528,7 +528,7 @@ public class CoreGrpcClient implements ICoreClient {
.setSessionId(sessionId)
.setNodeId(node.getId())
.setService(serviceName)
.setAction(CoreProto.ServiceAction.SERVICE_RESTART)
.setAction(CoreProto.ServiceAction.Enum.RESTART)
.build();
try {
return blockingStub.serviceAction(request).getResult();
@ -543,7 +543,7 @@ public class CoreGrpcClient implements ICoreClient {
.setSessionId(sessionId)
.setNodeId(node.getId())
.setService(serviceName)
.setAction(CoreProto.ServiceAction.SERVICE_VALIDATE)
.setAction(CoreProto.ServiceAction.Enum.VALIDATE)
.build();
try {
return blockingStub.serviceAction(request).getResult();
@ -1003,7 +1003,7 @@ public class CoreGrpcClient implements ICoreClient {
CoreProto.MobilityActionRequest request = CoreProto.MobilityActionRequest.newBuilder()
.setSessionId(sessionId)
.setNodeId(node.getId())
.setAction(CoreProto.MobilityAction.valueOf(action))
.setAction(CoreProto.MobilityAction.Enum.valueOf(action))
.build();
try {
CoreProto.MobilityActionResponse response = blockingStub.mobilityAction(request);

View file

@ -4,12 +4,14 @@ import com.core.Controller;
import com.core.client.ICoreClient;
import com.core.data.*;
import com.core.utils.WebUtils;
import com.core.websocket.CoreWebSocket;
import lombok.Data;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.*;
@Data
@ -19,6 +21,7 @@ public class CoreRestClient implements ICoreClient {
private int port;
private Integer sessionId;
private SessionState sessionState;
private CoreWebSocket coreWebSocket;
@Override
public void setConnection(String address, int port) {
@ -416,5 +419,12 @@ public class CoreRestClient implements ICoreClient {
@Override
public void setupEventHandlers(Controller controller) throws IOException {
coreWebSocket.stop();
coreWebSocket = new CoreWebSocket(controller);
try {
coreWebSocket.start(address, port);
} catch (URISyntaxException ex) {
throw new IOException("error starting web socket", ex);
}
}
}