@Test public void testConfigFileContainsMultipleNodes_matchingNodeHostPortSpecified() { Node node1 = Testing.newTestNode("node1", "localhost"); Node node2 = Testing.newTestNode("node2", "localhost", 1234); Cluster cluster = Testing.newTestCluster(new Stripe().addNodes(node1, node2)); Node matchingNode = STARTUP_MANAGER.getMatchingNodeFromConfigFileUsingHostPort(node2.getHostname(), String.valueOf(node2.getPort().get()), CONFIG_FILE, cluster); assertThat(matchingNode, equalTo(node2)); }
Node getMatchingNodeFromConfigFileUsingHostPort(String specifiedHostName, String specifiedPort, String configFilePath, Cluster cluster) { requireNonNull(configFilePath); boolean isHostnameSpecified = specifiedHostName != null; boolean isPortSpecified = specifiedPort != null; String substitutedHost = parameterSubstitutor.substitute(isHostnameSpecified ? specifiedHostName : Setting.NODE_HOSTNAME.getDefaultValue()); int port = isPortSpecified ? Integer.parseInt(specifiedPort) : Setting.NODE_PORT.getDefaultValue(); InetSocketAddress specifiedSockAddr = InetSocketAddress.createUnresolved(substitutedHost, port); Collection<Node> allNodes = cluster.getNodes(); Optional<Node> matchingNode = allNodes.stream() .filter(node1 -> InetSocketAddressUtils.areEqual(node1.getInternalAddress(), specifiedSockAddr)) .findAny(); HashMap<String, String> logParams = new HashMap<>(); logParams.put(NODE_HOSTNAME, substitutedHost); logParams.put(NODE_PORT, String.valueOf(port)); Node node; if (!isHostnameSpecified && !isPortSpecified && allNodes.size() == 1) { server.console("Found only one node information in config file: {}", configFilePath); node = allNodes.iterator().next(); } else if (matchingNode.isPresent()) { server.console(log("Found matching node entry", configFilePath, logParams)); node = matchingNode.get(); } else { throw new IllegalArgumentException(log("Did not find a matching node entry", configFilePath, logParams)); } return node; }
ConfigurationGeneratorVisitor { Node getMatchingNodeFromConfigFileUsingHostPort(String specifiedHostName, String specifiedPort, String configFilePath, Cluster cluster) { requireNonNull(configFilePath); boolean isHostnameSpecified = specifiedHostName != null; boolean isPortSpecified = specifiedPort != null; String substitutedHost = parameterSubstitutor.substitute(isHostnameSpecified ? specifiedHostName : Setting.NODE_HOSTNAME.getDefaultValue()); int port = isPortSpecified ? Integer.parseInt(specifiedPort) : Setting.NODE_PORT.getDefaultValue(); InetSocketAddress specifiedSockAddr = InetSocketAddress.createUnresolved(substitutedHost, port); Collection<Node> allNodes = cluster.getNodes(); Optional<Node> matchingNode = allNodes.stream() .filter(node1 -> InetSocketAddressUtils.areEqual(node1.getInternalAddress(), specifiedSockAddr)) .findAny(); HashMap<String, String> logParams = new HashMap<>(); logParams.put(NODE_HOSTNAME, substitutedHost); logParams.put(NODE_PORT, String.valueOf(port)); Node node; if (!isHostnameSpecified && !isPortSpecified && allNodes.size() == 1) { server.console("Found only one node information in config file: {}", configFilePath); node = allNodes.iterator().next(); } else if (matchingNode.isPresent()) { server.console(log("Found matching node entry", configFilePath, logParams)); node = matchingNode.get(); } else { throw new IllegalArgumentException(log("Did not find a matching node entry", configFilePath, logParams)); } return node; } }
ConfigurationGeneratorVisitor { Node getMatchingNodeFromConfigFileUsingHostPort(String specifiedHostName, String specifiedPort, String configFilePath, Cluster cluster) { requireNonNull(configFilePath); boolean isHostnameSpecified = specifiedHostName != null; boolean isPortSpecified = specifiedPort != null; String substitutedHost = parameterSubstitutor.substitute(isHostnameSpecified ? specifiedHostName : Setting.NODE_HOSTNAME.getDefaultValue()); int port = isPortSpecified ? Integer.parseInt(specifiedPort) : Setting.NODE_PORT.getDefaultValue(); InetSocketAddress specifiedSockAddr = InetSocketAddress.createUnresolved(substitutedHost, port); Collection<Node> allNodes = cluster.getNodes(); Optional<Node> matchingNode = allNodes.stream() .filter(node1 -> InetSocketAddressUtils.areEqual(node1.getInternalAddress(), specifiedSockAddr)) .findAny(); HashMap<String, String> logParams = new HashMap<>(); logParams.put(NODE_HOSTNAME, substitutedHost); logParams.put(NODE_PORT, String.valueOf(port)); Node node; if (!isHostnameSpecified && !isPortSpecified && allNodes.size() == 1) { server.console("Found only one node information in config file: {}", configFilePath); node = allNodes.iterator().next(); } else if (matchingNode.isPresent()) { server.console(log("Found matching node entry", configFilePath, logParams)); node = matchingNode.get(); } else { throw new IllegalArgumentException(log("Did not find a matching node entry", configFilePath, logParams)); } return node; } ConfigurationGeneratorVisitor(IParameterSubstitutor parameterSubstitutor,
                                       NomadServerManager nomadServerManager,
                                       ClassLoader classLoader,
                                       PathResolver pathResolver,
                                       ObjectMapperFactory objectMapperFactory,
                                       Server server); }
ConfigurationGeneratorVisitor { Node getMatchingNodeFromConfigFileUsingHostPort(String specifiedHostName, String specifiedPort, String configFilePath, Cluster cluster) { requireNonNull(configFilePath); boolean isHostnameSpecified = specifiedHostName != null; boolean isPortSpecified = specifiedPort != null; String substitutedHost = parameterSubstitutor.substitute(isHostnameSpecified ? specifiedHostName : Setting.NODE_HOSTNAME.getDefaultValue()); int port = isPortSpecified ? Integer.parseInt(specifiedPort) : Setting.NODE_PORT.getDefaultValue(); InetSocketAddress specifiedSockAddr = InetSocketAddress.createUnresolved(substitutedHost, port); Collection<Node> allNodes = cluster.getNodes(); Optional<Node> matchingNode = allNodes.stream() .filter(node1 -> InetSocketAddressUtils.areEqual(node1.getInternalAddress(), specifiedSockAddr)) .findAny(); HashMap<String, String> logParams = new HashMap<>(); logParams.put(NODE_HOSTNAME, substitutedHost); logParams.put(NODE_PORT, String.valueOf(port)); Node node; if (!isHostnameSpecified && !isPortSpecified && allNodes.size() == 1) { server.console("Found only one node information in config file: {}", configFilePath); node = allNodes.iterator().next(); } else if (matchingNode.isPresent()) { server.console(log("Found matching node entry", configFilePath, logParams)); node = matchingNode.get(); } else { throw new IllegalArgumentException(log("Did not find a matching node entry", configFilePath, logParams)); } return node; } ConfigurationGeneratorVisitor(IParameterSubstitutor parameterSubstitutor,
                                       NomadServerManager nomadServerManager,
                                       ClassLoader classLoader,
                                       PathResolver pathResolver,
                                       ObjectMapperFactory objectMapperFactory,
                                       Server server); boolean isUnConfiguredMode(); boolean isRepairMode(); StartupConfiguration generateConfiguration(); }
ConfigurationGeneratorVisitor { Node getMatchingNodeFromConfigFileUsingHostPort(String specifiedHostName, String specifiedPort, String configFilePath, Cluster cluster) { requireNonNull(configFilePath); boolean isHostnameSpecified = specifiedHostName != null; boolean isPortSpecified = specifiedPort != null; String substitutedHost = parameterSubstitutor.substitute(isHostnameSpecified ? specifiedHostName : Setting.NODE_HOSTNAME.getDefaultValue()); int port = isPortSpecified ? Integer.parseInt(specifiedPort) : Setting.NODE_PORT.getDefaultValue(); InetSocketAddress specifiedSockAddr = InetSocketAddress.createUnresolved(substitutedHost, port); Collection<Node> allNodes = cluster.getNodes(); Optional<Node> matchingNode = allNodes.stream() .filter(node1 -> InetSocketAddressUtils.areEqual(node1.getInternalAddress(), specifiedSockAddr)) .findAny(); HashMap<String, String> logParams = new HashMap<>(); logParams.put(NODE_HOSTNAME, substitutedHost); logParams.put(NODE_PORT, String.valueOf(port)); Node node; if (!isHostnameSpecified && !isPortSpecified && allNodes.size() == 1) { server.console("Found only one node information in config file: {}", configFilePath); node = allNodes.iterator().next(); } else if (matchingNode.isPresent()) { server.console(log("Found matching node entry", configFilePath, logParams)); node = matchingNode.get(); } else { throw new IllegalArgumentException(log("Did not find a matching node entry", configFilePath, logParams)); } return node; } ConfigurationGeneratorVisitor(IParameterSubstitutor parameterSubstitutor,
                                       NomadServerManager nomadServerManager,
                                       ClassLoader classLoader,
                                       PathResolver pathResolver,
                                       ObjectMapperFactory objectMapperFactory,
                                       Server server); boolean isUnConfiguredMode(); boolean isRepairMode(); StartupConfiguration generateConfiguration();  }