Search in sources :

Example 1 with ClientCloudConfig

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);
}
Also used : HazelcastCloudDiscovery(com.hazelcast.client.impl.spi.impl.discovery.HazelcastCloudDiscovery) ClientCloudConfig(com.hazelcast.client.config.ClientCloudConfig) DefaultAddressProvider(com.hazelcast.client.impl.spi.impl.DefaultAddressProvider) RemoteAddressProvider(com.hazelcast.client.impl.spi.impl.discovery.RemoteAddressProvider) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Example 2 with ClientCloudConfig

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));
        }
    }
}
Also used : ClientCloudConfig(com.hazelcast.client.config.ClientCloudConfig) Node(org.w3c.dom.Node)

Example 3 with ClientCloudConfig

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());
}
Also used : ClientCloudConfig(com.hazelcast.client.config.ClientCloudConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientCloudConfig (com.hazelcast.client.config.ClientCloudConfig)3 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)1 DefaultAddressProvider (com.hazelcast.client.impl.spi.impl.DefaultAddressProvider)1 HazelcastCloudDiscovery (com.hazelcast.client.impl.spi.impl.discovery.HazelcastCloudDiscovery)1 RemoteAddressProvider (com.hazelcast.client.impl.spi.impl.discovery.RemoteAddressProvider)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1 Node (org.w3c.dom.Node)1