public boolean addAsParentOf(Node node) { if (!this.parents.contains(node)) { this.parents.add(node); node.addAsChildOf(this); return true; } return false; }
public String[] getIDs() { String[] ids = new String[this.nodes.size()]; Node[] nodes = this.nodes.toArray(new Node[] {}); for (int i = 0; i < nodes.length; i++) { ids[i] = nodes[i].getId(); } return ids; }
public static Node from(String id) { return new Node(id); }
@Override public Map<String, Node> parse() { Map<String, Node> nodes = new HashMap<>(); String regularExpression = getRegularExpression(expression); Pattern pattern = Pattern.compile(regularExpression); Set<String> definedContainers = containerDefinitions.getNoneManualContainers().keySet(); for (String containerName : definedContainers) { Matcher matcher = pattern.matcher(containerName); if (matcher.matches()) { nodes.put(containerName, Node.from(containerName)); } } return nodes; }
private static void addAll(Map<String, Node> nodes, CubeDockerConfiguration config, String id) { CubeContainer content = config.getDockerContainersContent().get(id); if (content == null) { return; } Node parent = nodes.get(id); Collection<String> dependencies = content.getDependingContainers(); for (String name : dependencies) { if (config.getDockerContainersContent().get(name) != null) { Node child = nodes.get(name); if (child == null) { child = Node.from(name); nodes.put(name, child); } // Only continue recursively if this was a new found child if (child.addAsChildOf(parent)) { addAll(nodes, config, name); } } } }
static List<Step> sort(Set<Node> nodes) { List<Step> steps = new ArrayList<>(); List<Node> remaining = new ArrayList<>(nodes); int previousSize = remaining.size(); while (!remaining.isEmpty()) { Step step = new Step(); for (int i = 0; i < remaining.size(); i++) { Node node = remaining.get(i); if (!node.hasParent() || nodesInStep(steps, node.getParents())) { step.add(node); remaining.remove(i); --i; } } if (previousSize == remaining.size()) { throw new IllegalArgumentException("Could not resolve autoStart order. " + nodes); } previousSize = remaining.size(); steps.add(step); } return steps; }
public boolean addAsChildOf(Node node) { if (!this.children.contains(node)) { this.children.add(node); node.addAsParentOf(this); return true; } return false; }
@Override public Map<String, Node> parse() { Map<String, Node> nodes = new HashMap<>(); String regularExpression = getRegularExpression(expression); Pattern pattern = Pattern.compile(regularExpression); Set<String> definedContainers = containerDefinitions.getNoneManualContainers().keySet(); for (String containerName : definedContainers) { Matcher matcher = pattern.matcher(containerName); if (matcher.matches()) { nodes.put(containerName, Node.from(containerName)); } } return nodes; }
private static void addAll(Map<String, Node> nodes, CubeDockerConfiguration config, String id) { CubeContainer content = config.getDockerContainersContent().get(id); if (content == null) { return; } Node parent = nodes.get(id); Collection<String> dependencies = content.getDependingContainers(); for (String name : dependencies) { if (config.getDockerContainersContent().get(name) != null) { Node child = nodes.get(name); if (child == null) { child = Node.from(name); nodes.put(name, child); } // Only continue recursively if this was a new found child if (child.addAsChildOf(parent)) { addAll(nodes, config, name); } } } }
static List<Step> sort(Set<Node> nodes) { List<Step> steps = new ArrayList<>(); List<Node> remaining = new ArrayList<>(nodes); int previousSize = remaining.size(); while (!remaining.isEmpty()) { Step step = new Step(); for (int i = 0; i < remaining.size(); i++) { Node node = remaining.get(i); if (!node.hasParent() || nodesInStep(steps, node.getParents())) { step.add(node); remaining.remove(i); --i; } } if (previousSize == remaining.size()) { throw new IllegalArgumentException("Could not resolve autoStart order. " + nodes); } previousSize = remaining.size(); steps.add(step); } return steps; }
public boolean addAsChildOf(Node node) { if (!this.children.contains(node)) { this.children.add(node); node.addAsParentOf(this); return true; } return false; }
@Override public Map<String, Node> parse() { Map<String, Node> nodes = new HashMap<>(); Set<String> networksIds = this.containerDefinition.getNetworkIds(); for (Map.Entry<String, CubeContainer> container : this.containerDefinition.getNoneManualContainers().entrySet()) { // If cube is not named as the deployable container (this is done in this way because containers that are named as the deployable container are started by another process). if (!this.deployableContainers.contains(container.getKey())) { final String networkMode = container.getValue().getNetworkMode(); if (networkMode != null) { // if the network that this cube must connect is registered in current cube definition if (networksIds.contains(networkMode)) { String name = container.getKey(); Node child = Node.from(name); nodes.put(name, child); } } } } return nodes; } }
public String[] getIDs() { String[] ids = new String[this.nodes.size()]; Node[] nodes = this.nodes.toArray(new Node[] {}); for (int i = 0; i < nodes.length; i++) { ids[i] = nodes[i].getId(); } return ids; }
public boolean addAsParentOf(Node node) { if (!this.parents.contains(node)) { this.parents.add(node); node.addAsChildOf(this); return true; } return false; }
public static Node from(String id) { return new Node(id); }
@Override public Map<String, Node> parse() { Map<String, Node> nodes = new HashMap<>(); Set<String> networksIds = this.containerDefinition.getNetworkIds(); for (Map.Entry<String, CubeContainer> container : this.containerDefinition.getNoneManualContainers().entrySet()) { // If cube is not named as the deployable container (this is done in this way because containers that are named as the deployable container are started by another process). if (!this.deployableContainers.contains(container.getKey())) { final String networkMode = container.getValue().getNetworkMode(); if (networkMode != null) { // if the network that this cube must connect is registered in current cube definition if (networksIds.contains(networkMode)) { String name = container.getKey(); Node child = Node.from(name); nodes.put(name, child); } } } } return nodes; } }
public String nodeList(Set<Node> nodes) { StringBuilder sb = new StringBuilder(); Node[] array = nodes.toArray(new Node[] {}); for (int i = 0; i < array.length; i++) { sb.append(array[i].getId()); if (i < array.length - 1) { sb.append(","); } } return sb.toString(); }
@Override public Map<String, Node> parse() { Map<String, Node> nodes = new HashMap<>(); String[] autoStartContainers = ConfigUtil.trim(expression.split(",")); for (String autoStart : autoStartContainers) { if (containerDefinitions.get(autoStart) != null && !containerDefinitions.get(autoStart).isManual()) { nodes.put(autoStart, Node.from(autoStart)); } } return nodes; }