use of com.hazelcast.client.impl.spi.impl.discovery.HazelcastCloudDiscovery in project hazelcast by hazelcast.
the class ClusterDiscoveryServiceBuilder method createAddressProvider.
private AddressProvider createAddressProvider(ClientConfig clientConfig, DiscoveryService discoveryService) {
ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
ClientCloudConfig cloudConfig = networkConfig.getCloudConfig();
List<String> addresses = networkConfig.getAddresses();
boolean addressListProvided = addresses.size() != 0;
boolean awsDiscoveryEnabled = networkConfig.getAwsConfig() != null && networkConfig.getAwsConfig().isEnabled();
boolean gcpDiscoveryEnabled = networkConfig.getGcpConfig() != null && networkConfig.getGcpConfig().isEnabled();
boolean azureDiscoveryEnabled = networkConfig.getAzureConfig() != null && networkConfig.getAzureConfig().isEnabled();
boolean kubernetesDiscoveryEnabled = networkConfig.getKubernetesConfig() != null && networkConfig.getKubernetesConfig().isEnabled();
boolean eurekaDiscoveryEnabled = networkConfig.getEurekaConfig() != null && networkConfig.getEurekaConfig().isEnabled();
boolean discoverySpiEnabled = discoverySpiEnabled(networkConfig);
String cloudDiscoveryToken = properties.getString(HAZELCAST_CLOUD_DISCOVERY_TOKEN);
if (cloudDiscoveryToken != null && cloudConfig.isEnabled()) {
throw new IllegalStateException("Ambiguous hazelcast.cloud configuration. " + "Both property based and client configuration based settings are provided for " + "Hazelcast cloud discovery together. Use only one.");
}
boolean hazelcastCloudEnabled = cloudDiscoveryToken != null || cloudConfig.isEnabled();
isDiscoveryConfigurationConsistent(addressListProvided, awsDiscoveryEnabled, gcpDiscoveryEnabled, azureDiscoveryEnabled, kubernetesDiscoveryEnabled, eurekaDiscoveryEnabled, discoverySpiEnabled, hazelcastCloudEnabled);
if (hazelcastCloudEnabled) {
String discoveryToken = cloudDiscoveryToken(cloudConfig, cloudDiscoveryToken);
String cloudUrlBase = properties.getString(HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY);
String urlEndpoint = HazelcastCloudDiscovery.createUrlEndpoint(cloudUrlBase, discoveryToken);
int connectionTimeoutMillis = getConnectionTimeoutMillis(networkConfig);
HazelcastCloudDiscovery cloudDiscovery = new HazelcastCloudDiscovery(urlEndpoint, connectionTimeoutMillis);
// are never in the same network even-tough they can be in the same group/zone etc.
return new RemoteAddressProvider(cloudDiscovery::discoverNodes, true);
} else if (networkConfig.getAddresses().isEmpty() && discoveryService != null) {
return new RemoteAddressProvider(() -> discoverAddresses(discoveryService), usePublicAddress(clientConfig));
}
return new DefaultAddressProvider(networkConfig);
}
Aggregations