use of com.hazelcast.client.config.ClientCloudConfig 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);
}
use of com.hazelcast.client.config.ClientCloudConfig in project hazelcast by hazelcast.
the class ClientDomConfigProcessor method handleHazelcastCloud.
private void handleHazelcastCloud(Node node, ClientNetworkConfig clientNetworkConfig) {
ClientCloudConfig cloudConfig = clientNetworkConfig.getCloudConfig();
Node enabledNode = getNamedItemNode(node, "enabled");
boolean enabled = enabledNode != null && getBooleanValue(getTextContent(enabledNode).trim());
cloudConfig.setEnabled(enabled);
for (Node child : childElements(node)) {
String nodeName = cleanNodeName(child);
if (matches("discovery-token", nodeName)) {
cloudConfig.setDiscoveryToken(getTextContent(child));
}
}
}
use of com.hazelcast.client.config.ClientCloudConfig in project hazelcast by hazelcast.
the class TestClientApplicationContext method testCloudConfig.
@Test
public void testCloudConfig() {
ClientCloudConfig cloudConfig = hazelcastCloudClient.getClientConfig().getNetworkConfig().getCloudConfig();
assertEquals(false, cloudConfig.isEnabled());
assertEquals("EXAMPLE_TOKEN", cloudConfig.getDiscoveryToken());
}
Aggregations