def __init__(self, config=None):
     self.config = config or ClientConfig()
     self.properties = ClientProperties(self.config.get_properties())
     self.id = HazelcastClient.CLIENT_ID.get_and_increment()
     self.name = self._create_client_name()
     self._init_logger()
     self._logger_extras = {"client_name": self.name, "group_name": self.config.group_config.name}
     self._log_group_password_info()
     self.lifecycle = LifecycleService(self.config, self._logger_extras)
     self.reactor = AsyncoreReactor(self._logger_extras)
     self._address_providers = self._create_address_providers()
     self._address_translator = self._create_address_translator()
     self.connection_manager = ConnectionManager(self, self.reactor.new_connection, self._address_translator)
     self.heartbeat = Heartbeat(self)
     self.invoker = InvocationService(self)
     self.listener = ListenerService(self)
     self.cluster = ClusterService(self.config, self, self._address_providers)
     self.partition_service = PartitionService(self)
     self.proxy = ProxyManager(self)
     self.load_balancer = RandomLoadBalancer(self.cluster)
     self.serialization_service = SerializationServiceV1(serialization_config=self.config.serialization_config)
     self.transaction_manager = TransactionManager(self)
     self.lock_reference_id_generator = AtomicInteger(1)
     self.near_cache_manager = NearCacheManager(self)
     self.statistics = Statistics(self)
     self._start()
Example #2
0
 def __init__(self, **kwargs):
     config = _Config.from_dict(kwargs)
     self._config = config
     self._context = _ClientContext()
     client_id = HazelcastClient._CLIENT_ID.get_and_increment()
     self.name = self._create_client_name(client_id)
     self._reactor = AsyncoreReactor()
     self._serialization_service = SerializationServiceV1(config)
     self._near_cache_manager = NearCacheManager(
         config, self._serialization_service)
     self._internal_lifecycle_service = _InternalLifecycleService(config)
     self.lifecycle_service = LifecycleService(
         self._internal_lifecycle_service)
     self._invocation_service = InvocationService(self, config,
                                                  self._reactor)
     self._address_provider = self._create_address_provider()
     self._internal_partition_service = _InternalPartitionService(self)
     self.partition_service = PartitionService(
         self._internal_partition_service, self._serialization_service)
     self._internal_cluster_service = _InternalClusterService(self, config)
     self.cluster_service = ClusterService(self._internal_cluster_service)
     self._connection_manager = ConnectionManager(
         self,
         config,
         self._reactor,
         self._address_provider,
         self._internal_lifecycle_service,
         self._internal_partition_service,
         self._internal_cluster_service,
         self._invocation_service,
         self._near_cache_manager,
     )
     self._load_balancer = self._init_load_balancer(config)
     self._listener_service = ListenerService(self, config,
                                              self._connection_manager,
                                              self._invocation_service)
     self._proxy_manager = ProxyManager(self._context)
     self.cp_subsystem = CPSubsystem(self._context)
     self._proxy_session_manager = ProxySessionManager(self._context)
     self._transaction_manager = TransactionManager(self._context)
     self._lock_reference_id_generator = AtomicInteger(1)
     self._statistics = Statistics(
         self,
         config,
         self._reactor,
         self._connection_manager,
         self._invocation_service,
         self._near_cache_manager,
     )
     self._cluster_view_listener = ClusterViewListenerService(
         self,
         self._connection_manager,
         self._internal_partition_service,
         self._internal_cluster_service,
         self._invocation_service,
     )
     self._shutdown_lock = threading.RLock()
     self._init_context()
     self._start()
Example #3
0
 def get_runtime_and_system_metrics(self, client):
     s = Statistics(client, client._config, None, None, None, None)
     try:
         # Compatibility for <4.2.1 clients
         return s._get_os_and_runtime_stats()
     except:
         return itertools.chain(s._registered_system_gauges,
                                s._registered_process_gauges)
Example #4
0
 def __init__(self, config=None):
     self._context = _ClientContext()
     self.config = config or ClientConfig()
     self.properties = ClientProperties(self.config.get_properties())
     self._id = HazelcastClient._CLIENT_ID.get_and_increment()
     self.name = self._create_client_name()
     self._init_logger()
     self._logger_extras = {
         "client_name": self.name,
         "cluster_name": self.config.cluster_name
     }
     self._reactor = AsyncoreReactor(self._logger_extras)
     self._serialization_service = SerializationServiceV1(
         serialization_config=self.config.serialization)
     self._near_cache_manager = NearCacheManager(
         self, self._serialization_service)
     self._internal_lifecycle_service = _InternalLifecycleService(
         self, self._logger_extras)
     self.lifecycle_service = LifecycleService(
         self._internal_lifecycle_service)
     self._invocation_service = InvocationService(self, self._reactor,
                                                  self._logger_extras)
     self._address_provider = self._create_address_provider()
     self._internal_partition_service = _InternalPartitionService(
         self, self._logger_extras)
     self.partition_service = PartitionService(
         self._internal_partition_service)
     self._internal_cluster_service = _InternalClusterService(
         self, self._logger_extras)
     self.cluster_service = ClusterService(self._internal_cluster_service)
     self._connection_manager = ConnectionManager(
         self, self._reactor, self._address_provider,
         self._internal_lifecycle_service, self._internal_partition_service,
         self._internal_cluster_service, self._invocation_service,
         self._near_cache_manager, self._logger_extras)
     self._load_balancer = self._init_load_balancer(self.config)
     self._listener_service = ListenerService(self,
                                              self._connection_manager,
                                              self._invocation_service,
                                              self._logger_extras)
     self._proxy_manager = ProxyManager(self._context)
     self._transaction_manager = TransactionManager(self._context,
                                                    self._logger_extras)
     self._lock_reference_id_generator = AtomicInteger(1)
     self._statistics = Statistics(self, self._reactor,
                                   self._connection_manager,
                                   self._invocation_service,
                                   self._near_cache_manager,
                                   self._logger_extras)
     self._cluster_view_listener = ClusterViewListenerService(
         self, self._connection_manager, self._internal_partition_service,
         self._internal_cluster_service, self._invocation_service)
     self._shutdown_lock = threading.RLock()
     self._init_context()
     self._start()
Example #5
0
    def test_statistics_content(self):
        config = ClientConfig()
        config.set_property(ClientProperties.STATISTICS_ENABLED.name, True)
        config.set_property(ClientProperties.STATISTICS_PERIOD_SECONDS.name,
                            self.STATS_PERIOD)

        map_name = random_string()

        near_cache_config = NearCacheConfig(map_name)
        config.near_cache_configs[map_name] = near_cache_config

        client = HazelcastClient(config)
        client_uuid = client.cluster.uuid

        test_map = client.get_map(map_name).blocking()

        time.sleep(2 * self.STATS_PERIOD)
        response = self._wait_for_statistics_collection(client_uuid)

        result = response.result.decode("utf-8")
        local_address = self._get_local_address(client)

        # Check near cache and client statistics
        self.assertEqual(1, result.count("clientName=" + client.name))
        self.assertEqual(1, result.count("lastStatisticsCollectionTime="))
        self.assertEqual(1, result.count("enterprise=false"))
        self.assertEqual(1, result.count("clientType=" + CLIENT_TYPE))
        self.assertEqual(1, result.count("clientVersion=" + CLIENT_VERSION))
        self.assertEqual(1, result.count("clusterConnectionTimestamp="))
        self.assertEqual(1, result.count("clientAddress=" + local_address))
        self.assertEqual(1, result.count("nc." + map_name + ".creationTime"))
        self.assertEqual(1, result.count("nc." + map_name + ".evictions"))
        self.assertEqual(1, result.count("nc." + map_name + ".hits"))
        self.assertEqual(1, result.count("nc." + map_name + ".misses"))
        self.assertEqual(1,
                         result.count("nc." + map_name + ".ownedEntryCount"))
        self.assertEqual(1, result.count("nc." + map_name + ".expirations"))
        self.assertEqual(1, result.count("nc." + map_name + ".invalidations"))
        self.assertEqual(
            1, result.count("nc." + map_name + ".invalidationRequests"))
        self.assertEqual(
            1, result.count("nc." + map_name + ".ownedEntryMemoryCost"))

        # Check OS and runtime statistics. We cannot know what kind of statistics will be available
        # in different platforms. So, first try to get these statistics and then check the
        # response content

        s = Statistics(client)
        psutil_stats = s._get_os_and_runtime_stats()
        for stat_name in psutil_stats:
            self.assertEqual(1, result.count(stat_name))

        client.shutdown()
Example #6
0
    def test_statistics_content(self):
        map_name = random_string()
        client = HazelcastClient(
            cluster_name=self.cluster.id,
            statistics_enabled=True,
            statistics_period=self.STATS_PERIOD,
            near_caches={
                map_name: {},
            },
        )
        client_uuid = client._connection_manager.client_uuid

        client.get_map(map_name).blocking()

        time.sleep(2 * self.STATS_PERIOD)
        response = self.wait_for_statistics_collection(client_uuid)

        result = response.result.decode("utf-8")
        info = client._internal_cluster_service.get_local_client()
        local_address = "%s:%s" % (info.address.host, info.address.port)

        # Check near cache and client statistics
        self.assertEqual(1, result.count("clientName=" + client.name))
        self.assertEqual(1, result.count("lastStatisticsCollectionTime="))
        self.assertEqual(1, result.count("enterprise=false"))
        self.assertEqual(1, result.count("clientType=" + CLIENT_TYPE))
        self.assertEqual(1, result.count("clientVersion=" + __version__))
        self.assertEqual(1, result.count("clusterConnectionTimestamp="))
        self.assertEqual(1, result.count("clientAddress=" + local_address))
        self.assertEqual(1, result.count("nc." + map_name + ".creationTime"))
        self.assertEqual(1, result.count("nc." + map_name + ".evictions"))
        self.assertEqual(1, result.count("nc." + map_name + ".hits"))
        self.assertEqual(1, result.count("nc." + map_name + ".misses"))
        self.assertEqual(1,
                         result.count("nc." + map_name + ".ownedEntryCount"))
        self.assertEqual(1, result.count("nc." + map_name + ".expirations"))
        self.assertEqual(1, result.count("nc." + map_name + ".invalidations"))
        self.assertEqual(
            1, result.count("nc." + map_name + ".invalidationRequests"))
        self.assertEqual(
            1, result.count("nc." + map_name + ".ownedEntryMemoryCost"))

        # Check OS and runtime statistics. We cannot know what kind of statistics will be available
        # in different platforms. So, first try to get these statistics and then check the
        # response content

        s = Statistics(client, client._config, None, None, None, None)
        psutil_stats = s._get_os_and_runtime_stats()
        for stat_name in psutil_stats:
            self.assertEqual(1, result.count(stat_name))

        client.shutdown()