code: def wait_for_stable_cluster(
      hosts,
      jolokia_port,
      jolokia_prefix,
      check_interval,
      check_count,
      unhealthy_time_limit,
  ):
      
      stable_counter = 0
      max_checks = int(math.ceil(unhealthy_time_limit / check_interval))
      for i in itertools.count():
          partitions, brokers = read_cluster_status(
              hosts,
              jolokia_port,
              jolokia_prefix,
          )
          if partitions or brokers:
              stable_counter = 0
          else:
              stable_counter += 1
          print(
              "Under replicated partitions: {p_count}, missing brokers: {b_count} ({stable}/{limit})".format(
                  p_count=partitions,
                  b_count=brokers,
                  stable=stable_counter,
                  limit=check_count,
              ))
          if stable_counter >= check_count:
              print("The cluster is stable")
              return
          if i >= max_checks:
              raise WaitTimeoutException()
          time.sleep(check_interval)
docs: Block the caller until the cluster can be considered stable.
  
      :param hosts: list of brokers ip addresses
      :type hosts: list of strings
      :param jolokia_port: HTTP port for Jolokia
      :type jolokia_port: integer
      :param jolokia_prefix: HTTP prefix on the server for the Jolokia queries
      :type jolokia_prefix: string
      :param check_interval: the number of seconds it will wait between each check
      :type check_interval: integer
      :param check_count: the number of times the check should be positive before
      restarting the next broker
      :type check_count: integer
      :param unhealthy_time_limit: the maximum number of seconds it will wait for
      the cluster to become stable before exiting with error
      :type unhealthy_time_limit: integer