Exemple #1
0
def _PingWorkers(config, wait_time=None):
    """A result generator for the *ping* command.

  :param ConfigParser config: Configuration information for cluster.
  :param int wait_time: Amount of time to wait for responses, in seconds.

  """
    if wait_time == None:
        wait_time = 1  # wait for one second by default
    log_url = config.get('client', 'log_backend_url')
    context = zmq.Context()
    log_socket = MakeSocket(context,
                            url=log_url,
                            type=zmq.SUB,
                            bind=False,
                            options={zmq.SUBSCRIBE: ""})
    command_url = config.get('client', 'command_frontend_url')
    pool.SendCommand(command_url, pool.COMMAND_PING)
    poll_timeout = 1000  # poll for one second
    wait_start_time = time.time()
    results = list()
    poller = zmq.Poller()
    poller.register(log_socket, zmq.POLLIN)
    while time.time() - wait_start_time < wait_time:
        # Wait for input, with timeout given in milliseconds
        if poller.poll(timeout=poll_timeout):
            stats = log_socket.recv_pyobj()
            yield stats
Exemple #2
0
def _PingWorkers(config, wait_time = None):
  """A result generator for the *ping* command.

  :param ConfigParser config: Configuration information for cluster.
  :param int wait_time: Amount of time to wait for responses, in seconds.

  """
  if wait_time == None:
    wait_time = 1  # wait for one second by default
  log_url = config.get('client', 'log_backend_url')
  context = zmq.Context()
  log_socket = MakeSocket(context, url = log_url, type = zmq.SUB, bind = False,
      options = {zmq.SUBSCRIBE : ""})
  command_url = config.get('client', 'command_frontend_url')
  pool.SendCommand(command_url, pool.COMMAND_PING)
  poll_timeout = 1000  # poll for one second
  wait_start_time = time.time()
  results = list()
  poller = zmq.Poller()
  poller.register(log_socket, zmq.POLLIN)
  while time.time() - wait_start_time < wait_time:
    # Wait for input, with timeout given in milliseconds
    if poller.poll(timeout = poll_timeout):
      stats = log_socket.recv_pyobj()
      yield stats
Exemple #3
0
 def thread_target():
     context = zmq.Context()
     log_be_socket = MakeSocket(context,
                                url=log_backend_url,
                                type=zmq.PUB,
                                bind=True)
     log_fe_socket = MakeSocket(context,
                                url=log_frontend_url,
                                type=zmq.SUB,
                                bind=True,
                                options={zmq.SUBSCRIBE: ""})
     zmq.device(zmq.FORWARDER, log_fe_socket, log_be_socket)
Exemple #4
0
def LaunchBroker(config):
    """Start a set of intermediate devices for the cluster on this machine.

  This method does not return.

  :param ConfigParser config: Configuration information for cluster.

  """
    cmd_frontend_url = config.get('server', 'command_frontend_url')
    cmd_backend_url = config.get('server', 'command_backend_url')
    log_frontend_url = config.get('server', 'log_frontend_url')
    log_backend_url = config.get('server', 'log_backend_url')

    def thread_target():
        context = zmq.Context()
        log_be_socket = MakeSocket(context,
                                   url=log_backend_url,
                                   type=zmq.PUB,
                                   bind=True)
        log_fe_socket = MakeSocket(context,
                                   url=log_frontend_url,
                                   type=zmq.SUB,
                                   bind=True,
                                   options={zmq.SUBSCRIBE: ""})
        zmq.device(zmq.FORWARDER, log_fe_socket, log_be_socket)

    thread = threading.Thread(target=thread_target)
    thread.daemon = True
    logging.info("Launching logging forwarder -- clients should SUB to "
                 "%s and PUB to %s" % (log_backend_url, log_frontend_url))
    thread.start()
    context = zmq.Context()
    cmd_be_socket = MakeSocket(context,
                               url=cmd_backend_url,
                               type=zmq.PUB,
                               bind=True)
    cmd_fe_socket = MakeSocket(context,
                               url=cmd_frontend_url,
                               type=zmq.SUB,
                               bind=True,
                               options={zmq.SUBSCRIBE: ""})
    logging.info("Launching command forwarder -- clients should SUB to "
                 "%s and PUB to %s" % (cmd_backend_url, cmd_frontend_url))
    zmq.device(zmq.FORWARDER, cmd_fe_socket, cmd_be_socket)