corefx - updated node types to use sets and have the controller maintain default service mapping for other components to leverage
This commit is contained in:
parent
7e2a79335c
commit
8423bae0af
8 changed files with 23 additions and 39 deletions
|
@ -51,6 +51,7 @@ public class Controller implements Initializable {
|
||||||
private Application application;
|
private Application application;
|
||||||
private Stage window;
|
private Stage window;
|
||||||
private Configuration configuration;
|
private Configuration configuration;
|
||||||
|
private Map<String, Set<String>> defaultServices = new HashMap<>();
|
||||||
|
|
||||||
// core client utilities
|
// core client utilities
|
||||||
private ICoreClient coreClient = new CoreRestClient();
|
private ICoreClient coreClient = new CoreRestClient();
|
||||||
|
@ -237,9 +238,7 @@ public class Controller implements Initializable {
|
||||||
|
|
||||||
private void setCoreDefaultServices() {
|
private void setCoreDefaultServices() {
|
||||||
try {
|
try {
|
||||||
Map<String, List<String>> defaults = configuration.getNodeTypeConfigs().stream()
|
coreClient.setDefaultServices(defaultServices);
|
||||||
.collect(Collectors.toMap(NodeTypeConfig::getModel, NodeTypeConfig::getServices));
|
|
||||||
coreClient.setDefaultServices(defaults);
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Toast.error("Error updating core default services", ex);
|
Toast.error("Error updating core default services", ex);
|
||||||
}
|
}
|
||||||
|
@ -247,10 +246,6 @@ public class Controller implements Initializable {
|
||||||
|
|
||||||
public void updateNodeTypes() {
|
public void updateNodeTypes() {
|
||||||
graphToolbar.setupNodeTypes();
|
graphToolbar.setupNodeTypes();
|
||||||
Map<String, Set<String>> defaults = configuration.getNodeTypeConfigs().stream()
|
|
||||||
.collect(Collectors.toMap(NodeTypeConfig::getModel,
|
|
||||||
nodeTypeConfig -> new HashSet<>(nodeTypeConfig.getServices())));
|
|
||||||
nodeServicesDialog.setDefaultServices(defaults);
|
|
||||||
setCoreDefaultServices();
|
setCoreDefaultServices();
|
||||||
try {
|
try {
|
||||||
ConfigUtils.save(configuration);
|
ConfigUtils.save(configuration);
|
||||||
|
@ -433,10 +428,8 @@ public class Controller implements Initializable {
|
||||||
|
|
||||||
// set node types / default services
|
// set node types / default services
|
||||||
graphToolbar.setupNodeTypes();
|
graphToolbar.setupNodeTypes();
|
||||||
Map<String, Set<String>> defaults = configuration.getNodeTypeConfigs().stream()
|
defaultServices = configuration.getNodeTypeConfigs().stream()
|
||||||
.collect(Collectors.toMap(NodeTypeConfig::getModel,
|
.collect(Collectors.toMap(NodeTypeConfig::getModel, NodeTypeConfig::getServices));
|
||||||
nodeTypeConfig -> new HashSet<>(nodeTypeConfig.getServices())));
|
|
||||||
nodeServicesDialog.setDefaultServices(defaults);
|
|
||||||
|
|
||||||
// set graph toolbar
|
// set graph toolbar
|
||||||
borderPane.setLeft(graphToolbar);
|
borderPane.setLeft(graphToolbar);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface ICoreClient {
|
public interface ICoreClient {
|
||||||
void setUrl(String url);
|
void setUrl(String url);
|
||||||
|
@ -33,7 +34,7 @@ public interface ICoreClient {
|
||||||
|
|
||||||
Map<String, List<String>> getDefaultServices() throws IOException;
|
Map<String, List<String>> getDefaultServices() throws IOException;
|
||||||
|
|
||||||
boolean setDefaultServices(Map<String, List<String>> defaults) throws IOException;
|
boolean setDefaultServices(Map<String, Set<String>> defaults) throws IOException;
|
||||||
|
|
||||||
CoreService getService(CoreNode node, String serviceName) throws IOException;
|
CoreService getService(CoreNode node, String serviceName) throws IOException;
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,7 @@ import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class CoreRestClient implements ICoreClient {
|
public class CoreRestClient implements ICoreClient {
|
||||||
|
@ -136,7 +133,7 @@ public class CoreRestClient implements ICoreClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setDefaultServices(Map<String, List<String>> defaults) throws IOException {
|
public boolean setDefaultServices(Map<String, Set<String>> defaults) throws IOException {
|
||||||
String url = getUrl(String.format("sessions/%s/services/default", sessionId));
|
String url = getUrl(String.format("sessions/%s/services/default", sessionId));
|
||||||
return WebUtils.postJson(url, defaults);
|
return WebUtils.postJson(url, defaults);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class NodeType {
|
||||||
@EqualsAndHashCode.Include
|
@EqualsAndHashCode.Include
|
||||||
private final int id;
|
private final int id;
|
||||||
private final int value;
|
private final int value;
|
||||||
private final List<String> services = new ArrayList<>();
|
private final Set<String> services = new TreeSet<>();
|
||||||
private String display;
|
private String display;
|
||||||
private String model;
|
private String model;
|
||||||
private String icon;
|
private String icon;
|
||||||
|
|
|
@ -19,7 +19,6 @@ public class NodeServicesDialog extends StageDialog {
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
private final Map<String, List<ServiceItem>> serviceItemGroups = new HashMap<>();
|
private final Map<String, List<ServiceItem>> serviceItemGroups = new HashMap<>();
|
||||||
private final Map<String, ServiceItem> serviceItemMap = new HashMap<>();
|
private final Map<String, ServiceItem> serviceItemMap = new HashMap<>();
|
||||||
private final Map<String, Set<String>> defaultServices = new HashMap<>();
|
|
||||||
private CoreNode node;
|
private CoreNode node;
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
@FXML private GridPane gridPane;
|
@FXML private GridPane gridPane;
|
||||||
|
@ -73,11 +72,6 @@ public class NodeServicesDialog extends StageDialog {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultServices(Map<String, Set<String>> defaultServices) {
|
|
||||||
this.defaultServices.clear();
|
|
||||||
this.defaultServices.putAll(defaultServices);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServices(Map<String, List<String>> serviceGroups) {
|
public void setServices(Map<String, List<String>> serviceGroups) {
|
||||||
serviceItemGroups.clear();
|
serviceItemGroups.clear();
|
||||||
|
|
||||||
|
@ -135,7 +129,7 @@ public class NodeServicesDialog extends StageDialog {
|
||||||
|
|
||||||
Set<String> nodeServices = node.getServices();
|
Set<String> nodeServices = node.getServices();
|
||||||
if (nodeServices.isEmpty()) {
|
if (nodeServices.isEmpty()) {
|
||||||
nodeServices = defaultServices.get(node.getModel());
|
nodeServices = getController().getDefaultServices().get(node.getModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (List<ServiceItem> items : serviceItemGroups.values()) {
|
for (List<ServiceItem> items : serviceItemGroups.values()) {
|
||||||
|
|
|
@ -17,8 +17,8 @@ import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class NodeTypesDialog extends StageDialog {
|
public class NodeTypesDialog extends StageDialog {
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
|
@ -52,7 +52,7 @@ public class NodeTypesDialog extends StageDialog {
|
||||||
iconTextField.setText(nodeType.getIcon());
|
iconTextField.setText(nodeType.getIcon());
|
||||||
iconImage.setImage(new Image(nodeType.getIcon()));
|
iconImage.setImage(new Image(nodeType.getIcon()));
|
||||||
selectedNodeType = nodeType;
|
selectedNodeType = nodeType;
|
||||||
List<String> services = nodeType.getServices();
|
Set<String> services = nodeType.getServices();
|
||||||
nodeServicesListView.getItems().setAll(services);
|
nodeServicesListView.getItems().setAll(services);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ public class NodeTypesDialog extends StageDialog {
|
||||||
NodeType.remove(nodeType);
|
NodeType.remove(nodeType);
|
||||||
listView.getItems().remove(display);
|
listView.getItems().remove(display);
|
||||||
NodeTypeConfig nodeTypeConfig = createNodeTypeConfig(nodeType);
|
NodeTypeConfig nodeTypeConfig = createNodeTypeConfig(nodeType);
|
||||||
|
getController().getDefaultServices().remove(nodeTypeConfig.getModel());
|
||||||
getController().getConfiguration().getNodeTypeConfigs().remove(nodeTypeConfig);
|
getController().getConfiguration().getNodeTypeConfigs().remove(nodeTypeConfig);
|
||||||
getController().updateNodeTypes();
|
getController().updateNodeTypes();
|
||||||
});
|
});
|
||||||
|
@ -102,6 +103,7 @@ public class NodeTypesDialog extends StageDialog {
|
||||||
nodeTypeMap.put(nodeType.getDisplay(), nodeType);
|
nodeTypeMap.put(nodeType.getDisplay(), nodeType);
|
||||||
listView.getItems().add(nodeType.getDisplay());
|
listView.getItems().add(nodeType.getDisplay());
|
||||||
NodeTypeConfig nodeTypeConfig = createNodeTypeConfig(nodeType);
|
NodeTypeConfig nodeTypeConfig = createNodeTypeConfig(nodeType);
|
||||||
|
getController().getDefaultServices().put(nodeTypeConfig.getModel(), nodeTypeConfig.getServices());
|
||||||
getController().getConfiguration().getNodeTypeConfigs().add(nodeTypeConfig);
|
getController().getConfiguration().getNodeTypeConfigs().add(nodeTypeConfig);
|
||||||
getController().updateNodeTypes();
|
getController().updateNodeTypes();
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,9 +10,7 @@ import java.io.PrintWriter;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public final class ConfigUtils {
|
public final class ConfigUtils {
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
|
@ -42,19 +40,19 @@ public final class ConfigUtils {
|
||||||
|
|
||||||
private static List<NodeTypeConfig> createDefaults() throws IOException {
|
private static List<NodeTypeConfig> createDefaults() throws IOException {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
createDefault("host", "Host", "/icons/host-100.png", Arrays.asList(
|
createDefault("host", "Host", "/icons/host-100.png", new TreeSet<>(Arrays.asList(
|
||||||
"DefaultRoute", "SSH"
|
"DefaultRoute", "SSH"
|
||||||
)),
|
))),
|
||||||
createDefault("PC", "PC", "/icons/pc-100.png",
|
createDefault("PC", "PC", "/icons/pc-100.png",
|
||||||
Collections.singletonList("DefaultRoute")),
|
new TreeSet<>(Collections.singletonList("DefaultRoute"))),
|
||||||
createDefault("mdr", "MDR", "/icons/router-100.png", Arrays.asList(
|
createDefault("mdr", "MDR", "/icons/router-100.png", new TreeSet<>(Arrays.asList(
|
||||||
"zebra", "OSPFv3MDR", "IPForward"
|
"zebra", "OSPFv3MDR", "IPForward"
|
||||||
))
|
)))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NodeTypeConfig createDefault(String model, String display, String icon,
|
private static NodeTypeConfig createDefault(String model, String display, String icon,
|
||||||
List<String> services) throws IOException {
|
Set<String> services) throws IOException {
|
||||||
String fileName = Paths.get(icon).getFileName().toString();
|
String fileName = Paths.get(icon).getFileName().toString();
|
||||||
Path iconPath = Paths.get(ICON_DIR.toString(), fileName);
|
Path iconPath = Paths.get(ICON_DIR.toString(), fileName);
|
||||||
Files.copy(ConfigUtils.class.getResourceAsStream(icon), iconPath);
|
Files.copy(ConfigUtils.class.getResourceAsStream(icon), iconPath);
|
||||||
|
@ -93,7 +91,6 @@ public final class ConfigUtils {
|
||||||
nodeTypeConfig.getDisplay(),
|
nodeTypeConfig.getDisplay(),
|
||||||
nodeTypeConfig.getIcon()
|
nodeTypeConfig.getIcon()
|
||||||
);
|
);
|
||||||
nodeTypeConfig.getServices().sort(String::compareTo);
|
|
||||||
nodeType.getServices().addAll(nodeTypeConfig.getServices());
|
nodeType.getServices().addAll(nodeTypeConfig.getServices());
|
||||||
NodeType.add(nodeType);
|
NodeType.add(nodeType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
|
@ -16,5 +16,5 @@ public class NodeTypeConfig {
|
||||||
private String model;
|
private String model;
|
||||||
private String display;
|
private String display;
|
||||||
private String icon;
|
private String icon;
|
||||||
private List<String> services;
|
private Set<String> services;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue