corefx - added start/stop/restart/validate service to running node context menu
This commit is contained in:
parent
4f5ac43a06
commit
0805552aea
3 changed files with 133 additions and 2 deletions
|
@ -42,6 +42,14 @@ public interface ICoreClient {
|
||||||
|
|
||||||
String getServiceFile(CoreNode node, String serviceName, String fileName) throws IOException;
|
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;
|
boolean setServiceFile(CoreNode node, String serviceName, ServiceFile serviceFile) throws IOException;
|
||||||
|
|
||||||
List<ConfigGroup> getEmaneConfig(CoreNode node) throws IOException;
|
List<ConfigGroup> getEmaneConfig(CoreNode node) throws IOException;
|
||||||
|
|
|
@ -159,6 +159,34 @@ public class CoreRestClient implements ICoreClient {
|
||||||
return WebUtils.getJson(url, String.class, args);
|
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
|
@Override
|
||||||
public boolean setServiceFile(CoreNode node, String serviceName, ServiceFile serviceFile) throws IOException {
|
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(),
|
String url = getUrl(String.format("sessions/%s/nodes/%s/services/%s/file", sessionId, node.getId(),
|
||||||
|
|
|
@ -2,17 +2,112 @@ package com.core.graph;
|
||||||
|
|
||||||
import com.core.Controller;
|
import com.core.Controller;
|
||||||
import com.core.data.CoreNode;
|
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 {
|
class NodeContextMenu extends AbstractNodeContextMenu {
|
||||||
|
private static final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
NodeContextMenu(Controller controller, CoreNode coreNode) {
|
NodeContextMenu(Controller controller, CoreNode coreNode) {
|
||||||
super(controller, coreNode);
|
super(controller, coreNode);
|
||||||
setup();
|
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() {
|
private void setup() {
|
||||||
if (controller.getCoreClient().isRunning()) {
|
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 {
|
} else {
|
||||||
addMenuItem("Services", event -> controller.getNodeServicesDialog().showDialog(coreNode));
|
addMenuItem("Services", event -> controller.getNodeServicesDialog().showDialog(coreNode));
|
||||||
addMenuItem("Delete Node", event -> controller.deleteNode(coreNode));
|
addMenuItem("Delete Node", event -> controller.deleteNode(coreNode));
|
||||||
|
|
Loading…
Reference in a new issue