corefx - added start/stop/restart/validate service to running node context menu

This commit is contained in:
Blake J. Harnden 2018-11-28 17:16:00 -08:00
parent 4f5ac43a06
commit 0805552aea
3 changed files with 133 additions and 2 deletions

View file

@ -42,6 +42,14 @@ public interface ICoreClient {
String getServiceFile(CoreNode node, String serviceName, String fileName) throws IOException;
boolean startService(CoreNode node, String serviceName) throws IOException;
boolean stopService(CoreNode node, String serviceName) throws IOException;
boolean restartService(CoreNode node, String serviceName) throws IOException;
boolean validateService(CoreNode node, String serviceName) throws IOException;
boolean setServiceFile(CoreNode node, String serviceName, ServiceFile serviceFile) throws IOException;
List<ConfigGroup> getEmaneConfig(CoreNode node) throws IOException;

View file

@ -159,6 +159,34 @@ public class CoreRestClient implements ICoreClient {
return WebUtils.getJson(url, String.class, args);
}
@Override
public boolean startService(CoreNode node, String serviceName) throws IOException {
String url = getUrl(String.format("sessions/%s/nodes/%s/services/%s/start", sessionId, node.getId(),
serviceName));
return WebUtils.putJson(url);
}
@Override
public boolean stopService(CoreNode node, String serviceName) throws IOException {
String url = getUrl(String.format("sessions/%s/nodes/%s/services/%s/stop", sessionId, node.getId(),
serviceName));
return WebUtils.putJson(url);
}
@Override
public boolean restartService(CoreNode node, String serviceName) throws IOException {
String url = getUrl(String.format("sessions/%s/nodes/%s/services/%s/restart", sessionId, node.getId(),
serviceName));
return WebUtils.putJson(url);
}
@Override
public boolean validateService(CoreNode node, String serviceName) throws IOException {
String url = getUrl(String.format("sessions/%s/nodes/%s/services/%s/validate", sessionId, node.getId(),
serviceName));
return WebUtils.putJson(url);
}
@Override
public boolean setServiceFile(CoreNode node, String serviceName, ServiceFile serviceFile) throws IOException {
String url = getUrl(String.format("sessions/%s/nodes/%s/services/%s/file", sessionId, node.getId(),

View file

@ -2,17 +2,112 @@ package com.core.graph;
import com.core.Controller;
import com.core.data.CoreNode;
import com.core.ui.Toast;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.Collections;
import java.util.Set;
class NodeContextMenu extends AbstractNodeContextMenu {
private static final Logger logger = LogManager.getLogger();
NodeContextMenu(Controller controller, CoreNode coreNode) {
super(controller, coreNode);
setup();
}
private MenuItem createStartItem(String service) {
MenuItem menuItem = new MenuItem("Start");
menuItem.setOnAction(event -> {
try {
boolean result = controller.getCoreClient().startService(coreNode, service);
if (result) {
Toast.success("Started " + service);
} else {
Toast.error("Failure to start " + service);
}
} catch (IOException ex) {
Toast.error("Error starting " + service, ex);
}
});
return menuItem;
}
private MenuItem createStopItem(String service) {
MenuItem menuItem = new MenuItem("Stop");
menuItem.setOnAction(event -> {
try {
boolean result = controller.getCoreClient().stopService(coreNode, service);
if (result) {
Toast.success("Stopped " + service);
} else {
Toast.error("Failure to stop " + service);
}
} catch (IOException ex) {
Toast.error("Error stopping " + service, ex);
}
});
return menuItem;
}
private MenuItem createRestartItem(String service) {
MenuItem menuItem = new MenuItem("Restart");
menuItem.setOnAction(event -> {
try {
boolean result = controller.getCoreClient().restartService(coreNode, service);
if (result) {
Toast.success("Restarted " + service);
} else {
Toast.error("Failure to restart " + service);
}
} catch (IOException ex) {
Toast.error("Error restarting " + service, ex);
}
});
return menuItem;
}
private MenuItem createValidateItem(String service) {
MenuItem menuItem = new MenuItem("Validate");
menuItem.setOnAction(event -> {
try {
boolean result = controller.getCoreClient().validateService(coreNode, service);
if (result) {
Toast.success("Validated " + service);
} else {
Toast.error("Validation failed for " + service);
}
} catch (IOException ex) {
Toast.error("Error validating " + service, ex);
}
});
return menuItem;
}
private void setup() {
if (controller.getCoreClient().isRunning()) {
addMenuItem("Manage Services", event -> {
});
Set<String> services = coreNode.getServices();
if (services.isEmpty()) {
services = controller.getDefaultServices().getOrDefault(coreNode.getModel(), Collections.emptySet());
}
if (!services.isEmpty()) {
Menu menu = new Menu("Manage Services");
for (String service : services) {
Menu serviceMenu = new Menu(service);
MenuItem startItem = createStartItem(service);
MenuItem stopItem = createStopItem(service);
MenuItem restartItem = createRestartItem(service);
MenuItem validateItem = createValidateItem(service);
serviceMenu.getItems().addAll(startItem, stopItem, restartItem, validateItem);
menu.getItems().add(serviceMenu);
}
getItems().add(menu);
}
} else {
addMenuItem("Services", event -> controller.getNodeServicesDialog().showDialog(coreNode));
addMenuItem("Delete Node", event -> controller.deleteNode(coreNode));