def _init_cloud_address_provider(self, cloud_config):
        if cloud_config.enabled:
            discovery_token = cloud_config.discovery_token
            host, url = HazelcastCloudDiscovery.get_host_and_url(self.config.get_properties(), discovery_token)
            return HazelcastCloudAddressProvider(host, url, self._get_connection_timeout(), self._logger_extras)

        cloud_token = self.properties.get(self.properties.HAZELCAST_CLOUD_DISCOVERY_TOKEN)
        if cloud_token != "":
            host, url = HazelcastCloudDiscovery.get_host_and_url(self.config.get_properties(), cloud_token)
            return HazelcastCloudAddressProvider(host, url, self._get_connection_timeout(), self._logger_extras)

        return None
Example #2
0
    def _create_address_translator(self):
        network_config = self.config.network_config
        cloud_config = network_config.cloud_config
        cloud_discovery_token = self.properties.get(
            self.properties.HAZELCAST_CLOUD_DISCOVERY_TOKEN)

        address_list_provided = len(network_config.addresses) != 0
        if cloud_discovery_token != "" and cloud_config.enabled:
            raise HazelcastIllegalStateError(
                "Ambiguous Hazelcast.cloud configuration. "
                "Both property based and client configuration based settings are provided "
                "for Hazelcast cloud discovery together. Use only one.")

        hazelcast_cloud_enabled = cloud_discovery_token != "" or cloud_config.enabled
        self._is_discovery_configuration_consistent(address_list_provided,
                                                    hazelcast_cloud_enabled)

        if hazelcast_cloud_enabled:
            if cloud_config.enabled:
                discovery_token = cloud_config.discovery_token
            else:
                discovery_token = cloud_discovery_token
            host, url = HazelcastCloudDiscovery.get_host_and_url(
                self.config.get_properties(), discovery_token)
            return HazelcastCloudAddressTranslator(
                host, url, self._get_connection_timeout(), self._logger_extras)

        return DefaultAddressTranslator()
 def test_default_cloud_url(self):
     self.config.set_property(
         ClientProperties.HAZELCAST_CLOUD_DISCOVERY_TOKEN.name, self.token)
     host, url = HazelcastCloudDiscovery.get_host_and_url(
         self.config._properties, self.token)
     self.assertEqual("coordinator.hazelcast.cloud", host)
     self.assertEqual("/cluster/discovery?token=TOKEN", url)
 def test_custom_url_with_http(self):
     self.config.set_property(
         ClientProperties.HAZELCAST_CLOUD_DISCOVERY_TOKEN.name, self.token)
     self.config.set_property(
         HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY.name,
         "http://dev.hazelcast.cloud")
     host, url = HazelcastCloudDiscovery.get_host_and_url(
         self.config._properties, self.token)
     self.assertEqual("dev.hazelcast.cloud", host)
     self.assertEqual("/cluster/discovery?token=TOKEN", url)