default String getName() { return getMetadata().getName(); }
private static Graph<String, DefaultEdge> generateGraph(Map<String, ComponentMetadata> commands) { Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); commands.keySet().stream().forEach( c -> graph.addVertex(c) ); commands.entrySet().stream().forEach(entry -> { String key = entry.getKey(); entry.getValue().getDependencies().stream().forEach(dependency -> { try { graph.addEdge(key, dependency); } catch (IllegalArgumentException e) { //ignore it : if a dependency is declared in metadata but is not present on runtime LOGGER.warn("{} is not declared into the component's dependencies {}", key, dependency); } }); } ); return graph; }
Graph<String, DefaultEdge> generateGraph(Map<String, Bootstrap> commands) { Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); commands.keySet().stream().forEach( c -> graph.addVertex(c) ); commands.entrySet().stream().forEach(entry -> { String key = entry.getKey(); entry.getValue().getMetadata().getDependencies().stream().forEach(dependency -> { try { graph.addEdge(key, dependency); } catch (IllegalArgumentException e) { //ignore it : if a dependency is declared in metadata but is not present on runtime LOGGER.warn("{} is not declared into the component's dependencies {}", key, dependency); } }); } ); return graph; }
default String getName() { return getMetadata().getName(); }
Graph<String, DefaultEdge> generateGraph(Map<String, Bootstrap> commands) { Graph<String, DefaultEdge> graph = new SimpleDirectedGraph<>(DefaultEdge.class); commands.keySet().stream().forEach( c -> graph.addVertex(c) ); commands.entrySet().stream().forEach(entry -> { String key = entry.getKey(); entry.getValue().getMetadata().getDependencies().stream().forEach(dependency -> { try { graph.addEdge(key, dependency); } catch (IllegalArgumentException e) { //ignore it : if a dependency is declared in metadata but is not present on runtime LOGGER.warn("{} is not declared into the component's dependencies {}", key, dependency); } }); } ); return graph; }
private static List<String> computeStartingOrder(Map<String, ComponentDependencies> componentsToStartWithDependencies) { Map<String, ComponentMetadata> commands = new HashMap<>(); componentsToStartWithDependencies.entrySet().stream().forEach(entry -> { try { ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader(); Class<?> componentClass = currentThreadClassLoader.loadClass(hadoopUnitConfiguration.getString(entry.getKey() + ".metadataClass")); ComponentMetadata componentInstance = (ComponentMetadata) componentClass.getConstructor().newInstance(); commands.put(componentInstance.getName(), componentInstance); } catch (Exception e) { LOGGER.error("unable to instantiate {}", entry.getValue().getName(), e); } }); Graph<String, DefaultEdge> dependenciesGraph = generateGraph(commands); Map<String, List<String>> dependenciesMapByComponent = commands.values().stream().collect(Collectors.toMap(ComponentMetadata::getName, c -> DependenciesCalculator.calculateParents(dependenciesGraph, c.getName()))); Map<String, List<String>> transitiveDependenciesMapByComponent = DependenciesCalculator.findTransitiveDependenciesByComponent(dependenciesMapByComponent); return DependenciesCalculator.dryRunToDefineCorrectOrder(transitiveDependenciesMapByComponent); }