@Override public List<String[]> getAutoStartOrder(CubeDockerConfiguration config) { return AutoStartOrderUtil.getAutoStartOrder(config); }
@Override public List<String[]> getAutoStopOrder(CubeDockerConfiguration config) { return AutoStartOrderUtil.getAutoStopOrder(config); } }
@Override public String toString() { return AutoStartOrderUtil.toString(parse()); } }
static Set<Node> from(CubeDockerConfiguration config) { Map<String, Node> nodes = new HashMap<>(); AutoStartParser autoStartParser = config.getAutoStartContainers(); if (autoStartParser != null) { nodes.putAll(autoStartParser.parse()); } // add all children links Map<String, Node> autoStartNodes = new HashMap<>(nodes); for (Map.Entry<String, Node> node : autoStartNodes.entrySet()) { addAll(nodes, config, node.getKey()); } return new HashSet<>(nodes.values()); }
private static boolean nodesInStep(List<Step> steps, Set<Node> nodes) { for (Node node : nodes) { if (!nodeInStep(steps, node)) { return false; } } return true; }
public static String toString(Map<String, Node> nodeMap) { return nodeList(new HashSet<Node>(nodeMap.values())); }
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; }
@Override public String toString() { return AutoStartOrderUtil.toString(parse()); } }
static Set<Node> from(CubeDockerConfiguration config) { Map<String, Node> nodes = new HashMap<>(); AutoStartParser autoStartParser = config.getAutoStartContainers(); if (autoStartParser != null) { nodes.putAll(autoStartParser.parse()); } // add all children links Map<String, Node> autoStartNodes = new HashMap<>(nodes); for (Map.Entry<String, Node> node : autoStartNodes.entrySet()) { addAll(nodes, config, node.getKey()); } return new HashSet<>(nodes.values()); }
private static boolean nodesInStep(List<Step> steps, Set<Node> nodes) { for (Node node : nodes) { if (!nodeInStep(steps, node)) { return false; } } return true; }
public static String toString(Map<String, Node> nodeMap) { return nodeList(new HashSet<Node>(nodeMap.values())); }
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; }
@Override public List<String[]> getAutoStartOrder(CubeDockerConfiguration config) { return AutoStartOrderUtil.getAutoStartOrder(config); }
@Override public List<String[]> getAutoStopOrder(CubeDockerConfiguration config) { return AutoStartOrderUtil.getAutoStopOrder(config); } }
@Override public String toString() { return AutoStartOrderUtil.toString(parse()); } }
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); } } } }
public static List<String[]> getAutoStopOrder(CubeDockerConfiguration config) { List<String[]> autoStartOrder = getAutoStartOrder(config); Collections.reverse(autoStartOrder); return autoStartOrder; }
@Test public void shouldSortInReverseMultiRootWithMultipleLinks() throws Exception { List<String[]> sorted = AutoStartOrderUtil.getAutoStopOrder( create(SCENARIO_MULTI_ROOT_AND_MULTIPLE_LINKS, "A", "F")); assertExecutionSteps(sorted, new String[] {"A", "F"}, new String[] {"D", "C"}, new String[] {"B", "E"}); }