com.hazelcast.cluster.Address Java Examples

The following examples show how to use com.hazelcast.cluster.Address. 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: LocalDiscoveryNodeRegistrator.java    From hazelcast-consul-discovery-spi with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: TcpHealthCheckBuilder.java    From hazelcast-consul-discovery-spi with Apache License 2.0 6 votes vote down vote up
@Override
public RegCheck buildRegistrationCheck(Map<String, Object> registratorConfig, Address localAddress) {
	
	RegCheck regCheck = null;
	
	try {
		/**
		 * Deal with health check tcp
		 */
		String healthCheckTcp = (String)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_TCP);
		
		if (healthCheckTcp != null && !healthCheckTcp.trim().isEmpty()) {
			
			healthCheckTcp = healthCheckTcp.replaceAll(TCP_TEMPLATE_MYIP, localAddress.getInetAddress().getHostAddress())
					  						 .replaceAll(TCP_TEMPLATE_MYPORT, String.valueOf(localAddress.getPort()));
			
			Long healthCheckTcpIntervalSeconds = Long.valueOf((Integer)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_TCP_INTERVAL_SECONDS));
			regCheck = Registration.RegCheck.tcp(healthCheckTcp, healthCheckTcpIntervalSeconds);
		}
		
	} catch(Exception e) {
		logger.severe("Unexpected error occured trying to build TCP health check : " + e.getMessage(), e);
	}
	
	return regCheck;
}
 
Example #3
Source File: UnboundedSourceP.java    From beam with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Function<? super Address, ? extends ProcessorSupplier> get(
    @Nonnull List<Address> addresses) {
  return address ->
      ProcessorSupplier.of(
          () -> new UnboundedSourceP<>(shards, options.get(), outputCoder, ownerId));
}
 
Example #4
Source File: BoundedSourceP.java    From beam with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nonnull
@Override
public Function<? super Address, ? extends ProcessorSupplier> get(
    @Nonnull List<Address> addresses) {
  return address ->
      new BoundedSourceProcessorSupplier(
          Utils.roundRobinSubList(shards, addresses.indexOf(address), addresses.size()),
          options,
          outputCoder,
          ownerId);
}
 
Example #5
Source File: ImpulseP.java    From beam with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nonnull
@Override
public Function<? super Address, ? extends ProcessorSupplier> get(
    @Nonnull List<Address> addresses) {
  return address -> new ImpulseProcessorSupplier(outputCoder, ownerId);
}
 
Example #6
Source File: HttpHealthCheckBuilder.java    From hazelcast-consul-discovery-spi with Apache License 2.0 5 votes vote down vote up
@Override
public RegCheck buildRegistrationCheck( Map<String, Object> registratorConfig, Address localAddress) {
	
	RegCheck regCheck = null;
	
	try{
		/**
		 * Deal with health check http
		 */
		String healthCheckHttp = (String)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_HTTP);
		
		if (healthCheckHttp != null && !healthCheckHttp.trim().isEmpty()) {
			
			healthCheckHttp = healthCheckHttp.replaceAll(HTTP_TEMPLATE_MYIP, localAddress.getInetAddress().getHostAddress())
					  						 .replaceAll(HTTP_TEMPLATE_MYPORT, String.valueOf(localAddress.getPort()));
			
			Long healthCheckHttpIntervalSeconds = Long.valueOf((Integer)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_HTTP_INTERVAL_SECONDS));
			regCheck = Registration.RegCheck.http(healthCheckHttp, healthCheckHttpIntervalSeconds);
		}
	
	}catch(Exception e){
		logger.severe("Unexpected error occured trying to build HTTP health check : " + e.getMessage(), e);

	}
	
	return regCheck;
}
 
Example #7
Source File: KubernetesApiEndpointResolver.java    From hazelcast-kubernetes with Apache License 2.0 5 votes vote down vote up
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 #8
Source File: KubernetesApiEndpointResolver.java    From hazelcast-kubernetes with Apache License 2.0 5 votes vote down vote up
private Address createAddress(KubernetesClient.EndpointAddress address) {
    if (address == null) {
        return null;
    }
    String ip = address.getIp();
    InetAddress inetAddress = mapAddress(ip);
    int port = port(address);
    return new Address(inetAddress, port);
}
 
Example #9
Source File: ConsulDiscoveryStrategy.java    From hazelcast-consul-discovery-spi with Apache License 2.0 4 votes vote down vote up
@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 #10
Source File: BaseRegistrator.java    From hazelcast-consul-discovery-spi with Apache License 2.0 4 votes vote down vote up
protected abstract Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode,  
Map<String, Object> registratorConfig) throws Exception;
 
Example #11
Source File: RegistratorTestBase.java    From hazelcast-consul-discovery-spi with Apache License 2.0 4 votes vote down vote up
public Address getAddress() {
	return this.hazelcastInstance.getCluster().getLocalMember().getAddress();
}
 
Example #12
Source File: TestDoNothingRegistrator.java    From hazelcast-consul-discovery-spi with Apache License 2.0 4 votes vote down vote up
public Address getAddress() {
	return this.hazelcastInstance.getCluster().getLocalMember().getAddress();
}
 
Example #13
Source File: ScriptHealthCheckBuilder.java    From hazelcast-consul-discovery-spi with Apache License 2.0 3 votes vote down vote up
@Override
public RegCheck buildRegistrationCheck(Map<String, Object> registratorConfig, Address localAddress) {
	
	RegCheck regCheck = null;
	
	try{
		/**
		 * Deal with health check script
		 */
		String rawScript = (String)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_SCRIPT);
		
		if (rawScript != null && !rawScript.trim().isEmpty()) {
			
			Long healthCheckScriptIntervalSeconds = Long.valueOf((Integer)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_SCRIPT_INTERVAL_SECONDS));
			String healthCheckScript = rawScript.replaceAll(HEALTH_SCRIPT_TEMPLATE_MYIP, localAddress.getInetAddress().getHostAddress())
											    .replaceAll(HEALTH_SCRIPT_TEMPLATE_MYPORT, String.valueOf(localAddress.getPort()));
		
			regCheck = Registration.RegCheck.args(Arrays.asList(healthCheckScript.split(" ")), healthCheckScriptIntervalSeconds);
		}
	
	}catch(Exception e){
		logger.severe("Unexpected error occured trying to build HTTP health check : " + e.getMessage(), e);
	}
	
	return regCheck;
	
	
	
}
 
Example #14
Source File: ExplicitIpPortRegistrator.java    From hazelcast-consul-discovery-spi with Apache License 2.0 3 votes vote down vote up
@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 #15
Source File: HealthCheckBuilder.java    From hazelcast-consul-discovery-spi with Apache License 2.0 2 votes vote down vote up
/**
 * Method to build a registration check object
 * 
 * @param registratorConfig
 * @param localAddress
 * @return RegCheck object
 */
public RegCheck buildRegistrationCheck( Map<String, Object> registratorConfig, Address localAddress);