com.hazelcast.spi.discovery.DiscoveryNode Java Examples
The following examples show how to use
com.hazelcast.spi.discovery.DiscoveryNode.
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: KubernetesApiEndpointResolverTest.java From hazelcast-kubernetes with Apache License 2.0 | 6 votes |
@Test public void resolveWithPodLabelWhenNodeWithPodLabel() { // given List<Endpoint> endpoints = createEndpoints(2); given(client.endpointsByPodLabel(POD_LABEL, POD_LABEL_VALUE)).willReturn(endpoints); KubernetesApiEndpointResolver sut = new KubernetesApiEndpointResolver(LOGGER, null, 0, null, null, POD_LABEL, POD_LABEL_VALUE, null, client); // when List<DiscoveryNode> nodes = sut.resolve(); // then assertEquals(1, nodes.size()); assertEquals(2, nodes.get(0).getPrivateAddress().getPort()); }
Example #2
Source File: KubernetesApiEndpointResolverTest.java From hazelcast-kubernetes with Apache License 2.0 | 6 votes |
@Test public void resolveWithServiceLabelWhenNodeWithServiceLabel() { // given List<Endpoint> endpoints = createEndpoints(2); given(client.endpointsByServiceLabel(SERVICE_LABEL, SERVICE_LABEL_VALUE)).willReturn(endpoints); KubernetesApiEndpointResolver sut = new KubernetesApiEndpointResolver(LOGGER, null, 0, SERVICE_LABEL, SERVICE_LABEL_VALUE, null, null, null, client); // when List<DiscoveryNode> nodes = sut.resolve(); // then assertEquals(1, nodes.size()); assertEquals(2, nodes.get(0).getPrivateAddress().getPort()); }
Example #3
Source File: LocalDiscoveryNodeRegistrator.java From hazelcast-consul-discovery-spi with Apache License 2.0 | 6 votes |
@Override public Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig) { Address myLocalAddress = localDiscoveryNode.getPrivateAddress(); Object usePublicAddress = (Object)registratorConfig.get(CONFIG_PROP_PREFER_PUBLIC_ADDRESS); if (usePublicAddress != null && usePublicAddress instanceof Boolean && (Boolean)usePublicAddress) { logger.info("Registrator config property: " + CONFIG_PROP_PREFER_PUBLIC_ADDRESS +":"+usePublicAddress + " attempting to use it..."); Address publicAddress = localDiscoveryNode.getPublicAddress(); if (publicAddress != null) { myLocalAddress = publicAddress; } } return myLocalAddress; }
Example #4
Source File: DoNothingRegistrator.java From hazelcast-consul-discovery-spi with Apache License 2.0 | 6 votes |
@Override public void init( String consulHost, Integer consulPort, String consulServiceName, String[] consulServiceTags, String consulAclToken, boolean consulSslEnabled, String consulSslServerCertFilePath, String consulSslServerCertBase64, boolean consulServerHostnameVerify, DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig, ILogger logger) { }
Example #5
Source File: KubernetesApiEndpointResolver.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
private List<DiscoveryNode> getSimpleDiscoveryNodes(List<Endpoint> endpoints) { List<DiscoveryNode> discoveredNodes = new ArrayList<DiscoveryNode>(); for (Endpoint address : endpoints) { addAddress(discoveredNodes, address); } return discoveredNodes; }
Example #6
Source File: KubernetesApiEndpointResolverTest.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
@Test public void resolveWithServiceNameWhenNotReadyAddressesAndNotReadyDisabled() { // given List<Endpoint> endpoints = createNotReadyEndpoints(2); given(client.endpointsByName(SERVICE_NAME)).willReturn(endpoints); KubernetesApiEndpointResolver sut = new KubernetesApiEndpointResolver(LOGGER, SERVICE_NAME, 0, null, null, null, null, null, client); // when List<DiscoveryNode> nodes = sut.resolve(); // then assertEquals(0, nodes.size()); }
Example #7
Source File: KubernetesApiEndpointResolverTest.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
@Test public void resolveWithServiceNameWhenNotReadyAddressesAndNotReadyEnabled() { // given List<Endpoint> endpoints = createNotReadyEndpoints(2); given(client.endpointsByName(SERVICE_NAME)).willReturn(endpoints); KubernetesApiEndpointResolver sut = new KubernetesApiEndpointResolver(LOGGER, SERVICE_NAME, 0, null, null, null, null, RESOLVE_NOT_READY_ADDRESSES, client); // when List<DiscoveryNode> nodes = sut.resolve(); // then assertEquals(1, nodes.size()); }
Example #8
Source File: KubernetesApiEndpointResolverTest.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
private void resolveWithServiceNameWhenNodeInNamespace(final int port, final int expectedPort) { // given List<Endpoint> endpoints = createEndpoints(1); given(client.endpointsByName(SERVICE_NAME)).willReturn(endpoints); KubernetesApiEndpointResolver sut = new KubernetesApiEndpointResolver(LOGGER, SERVICE_NAME, port, null, null, null, null, null, client); // when List<DiscoveryNode> nodes = sut.resolve(); // then assertEquals(1, nodes.size()); assertEquals(expectedPort, nodes.get(0).getPrivateAddress().getPort()); }
Example #9
Source File: KubernetesApiEndpointResolverTest.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
@Test public void resolveWhenNodeInFound() { // given List<Endpoint> endpoints = Collections.<Endpoint>emptyList(); given(client.endpoints()).willReturn(endpoints); KubernetesApiEndpointResolver sut = new KubernetesApiEndpointResolver(LOGGER, null, 0, null, null, null, null, null, client); // when List<DiscoveryNode> nodes = sut.resolve(); // then assertEquals(0, nodes.size()); }
Example #10
Source File: DnsEndpointResolverTest.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
@Test public void resolveNotFound() throws Exception { // given when(servers.hasMore()).thenReturn(false); DnsEndpointResolver dnsEndpointResolver = new DnsEndpointResolver(LOGGER, SERVICE_DNS, UNSET_PORT, dirContext); // when List<DiscoveryNode> result = dnsEndpointResolver.resolve(); // then assertEquals(0, result.size()); }
Example #11
Source File: DnsEndpointResolverTest.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
@Test public void resolveException() throws Exception { // given when(dirContext.getAttributes(SERVICE_DNS, new String[]{"SRV"})).thenThrow(new NameNotFoundException()); DnsEndpointResolver dnsEndpointResolver = new DnsEndpointResolver(LOGGER, SERVICE_DNS, UNSET_PORT, dirContext); // when List<DiscoveryNode> result = dnsEndpointResolver.resolve(); // then assertEquals(0, result.size()); }
Example #12
Source File: DnsEndpointResolverTest.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
@Test public void resolveCustomPort() { // given DnsEndpointResolver dnsEndpointResolver = new DnsEndpointResolver(LOGGER, SERVICE_DNS, CUSTOM_PORT, dirContext); // when List<DiscoveryNode> result = dnsEndpointResolver.resolve(); // then Set<?> resultAddresses = setOf(result.get(0).getPrivateAddress().getHost(), result.get(1).getPrivateAddress().getHost()); Set<?> resultPorts = setOf(result.get(0).getPrivateAddress().getPort(), result.get(1).getPrivateAddress().getPort()); assertEquals(setOf(IP_SERVER_1, IP_SERVER_2), resultAddresses); assertEquals(setOf(CUSTOM_PORT), resultPorts); }
Example #13
Source File: DnsEndpointResolverTest.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
@Test public void resolve() { // given DnsEndpointResolver dnsEndpointResolver = new DnsEndpointResolver(LOGGER, SERVICE_DNS, UNSET_PORT, dirContext); // when List<DiscoveryNode> result = dnsEndpointResolver.resolve(); // then Set<?> resultAddresses = setOf(result.get(0).getPrivateAddress().getHost(), result.get(1).getPrivateAddress().getHost()); Set<?> resultPorts = setOf(result.get(0).getPrivateAddress().getPort(), result.get(1).getPrivateAddress().getPort()); assertEquals(setOf(IP_SERVER_1, IP_SERVER_2), resultAddresses); assertEquals(setOf(DEFAULT_PORT), resultPorts); }
Example #14
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 #15
Source File: KubernetesApiEndpointResolver.java From hazelcast-kubernetes with Apache License 2.0 | 5 votes |
@Override List<DiscoveryNode> resolve() { if (serviceName != null && !serviceName.isEmpty()) { logger.fine("Using service name to discover nodes."); return getSimpleDiscoveryNodes(client.endpointsByName(serviceName)); } else if (serviceLabel != null && !serviceLabel.isEmpty()) { logger.fine("Using service label to discover nodes."); return getSimpleDiscoveryNodes(client.endpointsByServiceLabel(serviceLabel, serviceLabelValue)); } else if (podLabel != null && !podLabel.isEmpty()) { logger.fine("Using pod label to discover nodes."); return getSimpleDiscoveryNodes(client.endpointsByPodLabel(podLabel, podLabelValue)); } return getSimpleDiscoveryNodes(client.endpoints()); }
Example #16
Source File: DockerDNSRRDiscoveryStrategyFactory.java From hazelcast-docker-swarm-discovery-spi with Apache License 2.0 | 5 votes |
@Override public DiscoveryStrategy newDiscoveryStrategy( DiscoveryNode discoveryNode, ILogger logger, //Implementing DiscoveryStrategyFactory method with a raw type @SuppressWarnings("rawtypes") Map<String, Comparable> properties ) { return new DockerDNSRRDiscoveryStrategy( logger, properties ); }
Example #17
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 #18
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 #19
Source File: HazelcastKubernetesDiscoveryStrategyFactory.java From hazelcast-kubernetes with Apache License 2.0 | 4 votes |
public DiscoveryStrategy newDiscoveryStrategy(DiscoveryNode discoveryNode, ILogger logger, Map<String, Comparable> properties) { return new HazelcastKubernetesDiscoveryStrategy(logger, properties); }
Example #20
Source File: HazelcastKubernetesDiscoveryStrategy.java From hazelcast-kubernetes with Apache License 2.0 | 4 votes |
@Override public Iterable<DiscoveryNode> discoverNodes() { return endpointResolver.resolve(); }
Example #21
Source File: BaseRegistrator.java From hazelcast-consul-discovery-spi with Apache License 2.0 | 4 votes |
@Override public void init(String consulHost, Integer consulPort, String consulServiceName, String[] consulTags, String consulAclToken, boolean consulSslEnabled, String consulSslServerCertFilePath, String consulSslServerCertBase64, boolean consulServerHostnameVerify, DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig, ILogger logger) throws Exception { this.logger = logger; this.tags = consulTags; this.consulHost = consulHost; this.consulPort = consulPort; this.consulServiceName = consulServiceName; this.consulAclToken = consulAclToken; this.registratorConfig = registratorConfig; try { /** * Determine my local address */ this.myLocalAddress = determineMyLocalAddress(localDiscoveryNode, registratorConfig); logger.info("Determined local DiscoveryNode address to use: " + myLocalAddress); //Build our consul client to use. We pass in optional TLS information ConsulBuilder builder = ConsulClientBuilder.class.newInstance(); Consul consul = builder.buildConsul(consulHost, consulPort, consulSslEnabled, consulSslServerCertFilePath, consulSslServerCertBase64, consulServerHostnameVerify, consulAclToken); // build my Consul agent client that we will register with this.consulAgentClient = consul.agentClient(); } catch(Exception e) { String msg = "Unexpected error in configuring LocalDiscoveryNodeRegistration: " + e.getMessage(); logger.severe(msg,e); throw new Exception(msg,e); } }
Example #22
Source File: BaseRegistrator.java From hazelcast-consul-discovery-spi with Apache License 2.0 | 4 votes |
protected abstract Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig) throws Exception;
Example #23
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; }
Example #24
Source File: ConsulDiscoveryStrategyFactory.java From hazelcast-consul-discovery-spi with Apache License 2.0 | 4 votes |
public DiscoveryStrategy newDiscoveryStrategy(DiscoveryNode discoveryNode, ILogger logger, Map<String, Comparable> properties ) { return new ConsulDiscoveryStrategy( discoveryNode, logger, properties ); }
Example #25
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 #26
Source File: DockerSwarmDiscoveryStrategyFactory.java From hazelcast-docker-swarm-discovery-spi with Apache License 2.0 | 4 votes |
public DiscoveryStrategy newDiscoveryStrategy(DiscoveryNode discoveryNode, ILogger logger, Map<String, Comparable> properties) { return new DockerSwarmDiscoveryStrategy(discoveryNode, logger, properties); }
Example #27
Source File: ConsulRegistrator.java From hazelcast-consul-discovery-spi with Apache License 2.0 | 3 votes |
/** * Initialize the registrator * * @param consulHost * @param consulPort * @param consulServiceName * @param consulTags * @param consulAclToken * @param consulSslEnabled * @param consulSslServerCertFilePath * @param consulSslServerCertBase64 * @param consulServerHostnameVerify * @param localDiscoveryNode * @param registratorConfig * @param logger * @throws Exception */ public void init(String consulHost, Integer consulPort, String consulServiceName, String[] consulTags, String consulAclToken, boolean consulSslEnabled, String consulSslServerCertFilePath, String consulSslServerCertBase64, boolean consulServerHostnameVerify, DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig, ILogger logger) throws Exception;
Example #28
Source File: ExplicitIpPortRegistrator.java From hazelcast-consul-discovery-spi with Apache License 2.0 | 3 votes |
@Override public Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig) throws Exception { String registerWithIpAddress = (String)registratorConfig.get(CONFIG_PROP_REGISTER_WITH_IP_ADDRESS); Integer registerWithPort = (Integer)registratorConfig.get(CONFIG_PROP_REGISTER_WITH_PORT); logger.info("Registrator config properties: " + CONFIG_PROP_REGISTER_WITH_IP_ADDRESS +":"+registerWithIpAddress + " " + CONFIG_PROP_REGISTER_WITH_PORT + ":" + registerWithPort + ", will attempt to register with this IP/PORT..."); return new Address(registerWithIpAddress, registerWithPort); }
Example #29
Source File: HazelcastKubernetesDiscoveryStrategy.java From hazelcast-kubernetes with Apache License 2.0 | votes |
abstract List<DiscoveryNode> resolve();