com.hazelcast.spi.discovery.SimpleDiscoveryNode Java Examples
The following examples show how to use
com.hazelcast.spi.discovery.SimpleDiscoveryNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DockerSwarmDiscoveryStrategy.java From hazelcast-docker-swarm-discovery-spi with Apache License 2.0 | 5 votes |
@Override public Iterable<DiscoveryNode> discoverNodes() { List<DiscoveryNode> toReturn = new ArrayList<>(); try { Set<DiscoveredContainer> discoveredContainers = this.swarmDiscoveryUtil.discoverContainers(); /** * We have all the containers, convert to DiscoveryNodes and return... */ getLogger().info("discoverNodes() DiscoveredContainers[" + discoveredContainers.size() + "]: " + Arrays.toString(discoveredContainers.toArray(new DiscoveredContainer[]{}))); for (DiscoveredContainer container : discoveredContainers) { toReturn.add(new SimpleDiscoveryNode( new Address(container.getIp(), swarmDiscoveryUtil.getHazelcastPeerPort()))); } return toReturn; } catch (Exception e) { getLogger().severe("discoverNodes() unexpected error: " + e.getMessage(), e); } return toReturn; }
Example #2
Source File: KubernetesApiEndpointResolver.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
private void addAddress(List<DiscoveryNode> discoveredNodes, Endpoint endpoint) { if (Boolean.TRUE.equals(resolveNotReadyAddresses) || endpoint.isReady()) { Address privateAddress = createAddress(endpoint.getPrivateAddress()); Address publicAddress = createAddress(endpoint.getPublicAddress()); discoveredNodes .add(new SimpleDiscoveryNode(privateAddress, publicAddress, endpoint.getAdditionalProperties())); if (logger.isFinestEnabled()) { logger.finest(String.format("Found node service with addresses (private, public): %s, %s ", privateAddress, publicAddress)); } } }
Example #3
Source File: HazelcastConfig.java From dts with Apache License 2.0 | 4 votes |
@Bean public DiscoveryServiceProvider discoveryServiceProvider(DiscoveryClient discoveryClient) { return new DiscoveryServiceProvider() { @Override public DiscoveryService newDiscoveryService(DiscoveryServiceSettings settings) { return new DiscoveryService() { @Override public void destroy() { } @Override public Map<String, Object> discoverLocalMetadata() { return Collections.emptyMap(); } @Override public Iterable<DiscoveryNode> discoverNodes() { List<DiscoveryNode> nodes = new ArrayList<>(); discoveryClient.getInstances(clusterName).forEach((ServiceInstance serviceInstance) -> { try { String host = serviceInstance.getMetadata().get(HAZELCAST_HOST_KEY); String port = serviceInstance.getMetadata().get(HAZELCAST_PORT_KEY); String version = serviceInstance.getMetadata().get(HAZELCAST_VERSION_KEY); if (host != null && port != null && StringUtils.equals(version, hazelcastVersion)) { Address address = new Address(host, Integer.parseInt(port)); DiscoveryNode discoveryNode = new SimpleDiscoveryNode(address); nodes.add(discoveryNode); } } catch (Exception e) { logger.error("discoverNodes()", e); } }); return nodes; } @Override public void start() { } }; } }; }
Example #4
Source File: DockerDNSRRDiscoveryStrategy.java From hazelcast-docker-swarm-discovery-spi with Apache License 2.0 | 4 votes |
@Override public Iterable<DiscoveryNode> discoverNodes() { LinkedList<DiscoveryNode> discoveryNodes = new LinkedList<>(); //Pull properties String servicesCsv = getOrDefault( DockerDNSRRDiscoveryConfiguration.SERVICESCSV, "" ); //If there are no services configured, no point in doing anything. if ( servicesCsv == null || servicesCsv.trim().isEmpty() ) { return discoveryNodes; } Set<InetAddress> serviceNameResolutions = new HashSet<>(); String[] serviceHostnameAndPort; Integer port = 5701; //Loop for every service defined in the CSV for (String service : servicesCsv.split(",")) { if (!service.trim().isEmpty()) { //CSV should be composed of hostname:port serviceHostnameAndPort = service.split(":"); //Validate hostname exists if ( serviceHostnameAndPort[0] == null || serviceHostnameAndPort[0].trim().isEmpty() ) { logger.info( "Unable to resolve service hostname " + serviceHostnameAndPort[0] + " Skipping service entry." ); continue; } //Validate port exists; assume default port if it doesn't if ( serviceHostnameAndPort.length <= 1 || serviceHostnameAndPort[1] == null || serviceHostnameAndPort[1].trim().isEmpty() ) { port = 5701; } else { try { port = Integer.valueOf( serviceHostnameAndPort[1] ); } catch (NumberFormatException nfe) { logger.info( "Unable to parse port " + serviceHostnameAndPort[1] + " Skipping service entry." ); continue; } } //Resolve service hostname to a set of IP addresses, if any serviceNameResolutions = resolveDomainNames( serviceHostnameAndPort[0] ); //Add all IP addresses for service hostname with the given port. for (InetAddress resolution : serviceNameResolutions) { discoveryNodes.add( new SimpleDiscoveryNode( new Address( resolution, port ) ) ); } } } return discoveryNodes; }
Example #5
Source File: ConsulDiscoveryStrategy.java From hazelcast-consul-discovery-spi with Apache License 2.0 | 4 votes |
@Override public Iterable<DiscoveryNode> discoverNodes() { List<DiscoveryNode> toReturn = new ArrayList<DiscoveryNode>(); try { // discover healthy nodes only? (and its NOT the first invocation...) if (this.consulHealthyOnly && discoverNodesInvoked) { List<ServiceHealth> nodes = consulHealthClient.getHealthyServiceInstances(consulServiceName, ConsulUtility.getAclToken(this.consulAclToken)).getResponse(); for (ServiceHealth node : nodes) { toReturn.add(new SimpleDiscoveryNode( new Address(node.getService().getAddress(),node.getService().getPort()))); getLogger().info("Discovered healthy node: " + node.getService().getAddress()+":"+node.getService().getPort()); } // discover all services, regardless of health or this is the first invocation } else { ConsulResponse<List<CatalogService>> response = this.consulCatalogClient.getService(consulServiceName, ConsulUtility.getAclToken(this.consulAclToken)); for (CatalogService service : response.getResponse()) { String discoveredAddress = null; String rawServiceAddress = service.getServiceAddress(); String rawAddress = service.getAddress(); if (rawServiceAddress != null && !rawServiceAddress.trim().isEmpty()) { discoveredAddress = rawServiceAddress; } else if (rawAddress != null && !rawAddress.trim().isEmpty()) { getLogger().warning("discoverNodes() ServiceAddress was null/blank! " + "for service: " + service.getServiceName() + " falling back to Address value"); discoveredAddress = rawAddress; } else { getLogger().warning("discoverNodes() could not discover an address, " + "both ServiceAddress and Address were null/blank! " + "for service: " + service.getServiceName()); } toReturn.add(new SimpleDiscoveryNode( new Address(discoveredAddress, service.getServicePort()))); getLogger().info("Discovered healthy node: " + discoveredAddress+":"+service.getServicePort()); } } } catch(Exception e) { getLogger().severe("discoverNodes() unexpected error: " + e.getMessage(),e); } // flag we were invoked discoverNodesInvoked = true; return toReturn; }