private void startService(Bootstrap c) { c.start(); }
private void stopService(Bootstrap c) { c.stop(); }
private void internalStart(List<Bootstrap> componentsToStart) { componentsToStart.forEach(this::startService); HadoopUtils.INSTANCE.printBanner(System.out); componentsToStart.forEach(c -> HadoopUtils.printColorLine(System.out, GREEN, "\t\t - " + c.getName() + " " + c.getProperties())); System.out.println(); }
public static void main(String[] args) throws BootstrapException { try { configuration = new PropertiesConfiguration("hadoop.properties"); } catch (ConfigurationException e) { throw new BootstrapException("bad config", e); } HadoopBootstrap bootstrap = HadoopBootstrap.INSTANCE; bootstrap.componentsToStart = bootstrap.componentsToStart.stream().filter(c -> configuration.containsKey(c.getName().toLowerCase()) && configuration.getBoolean(c.getName().toLowerCase()) ).collect(Collectors.toList()); bootstrap.componentsToStop = bootstrap.componentsToStop.stream().filter(c -> configuration.containsKey(c.getName().toLowerCase()) && configuration.getBoolean(c.getName().toLowerCase()) ).collect(Collectors.toList()); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { LOGGER.info("All services are going to be stopped"); bootstrap.stopAll(); } }); bootstrap.startAll(); } }
default String getName() { return getMetadata().getName(); }
private void internalStart(List<Bootstrap> componentsToStart) { componentsToStart.forEach(this::startService); HadoopUtils.INSTANCE.printBanner(System.out); componentsToStart.forEach(c -> HadoopUtils.printColorLine(System.out, GREEN, "\t\t - " + c.getName() + " " + c.getProperties())); System.out.println(); }
private List<String> computeStartingOrder() { Graph<String, DefaultEdge> dependenciesGraph = generateGraph(commands); Map<String, List<String>> dependenciesMapByComponent = commands.values().stream().collect(Collectors.toMap(Bootstrap::getName, c -> DependenciesCalculator.calculateParents(dependenciesGraph, c.getName()))); Map<String, List<String>> transitiveDependenciesMapByComponent = DependenciesCalculator.findTransitiveDependenciesByComponent(dependenciesMapByComponent); return DependenciesCalculator.dryRunToDefineCorrectOrder(transitiveDependenciesMapByComponent); }
default String getName() { return getMetadata().getName(); }
private List<String> computeStartingOrder() { Graph<String, DefaultEdge> dependenciesGraph = generateGraph(commands); Map<String, List<String>> dependenciesMapByComponent = commands.values().stream().collect(Collectors.toMap(Bootstrap::getName, c -> DependenciesCalculator.calculateParents(dependenciesGraph, c.getName()))); Map<String, List<String>> transitiveDependenciesMapByComponent = DependenciesCalculator.findTransitiveDependenciesByComponent(dependenciesMapByComponent); return DependenciesCalculator.dryRunToDefineCorrectOrder(transitiveDependenciesMapByComponent); }
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 void stopService(Bootstrap c) { c.stop(); }
private void startService(Bootstrap c) { c.start(); }
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; }