Пример #1
0
def main(argv):
  usage = "usage: %prog [options]"
  parser = OptionParser(usage=usage)
  parser.add_option("-f", "--force", action="store_true", dest="force", help="Overwrite existing Sensei node info")
  parser.add_option("-c", "--reset", action="store_true", dest="reset", help="Remove all registered nodes and then exit")
  parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Verbose mode")
  (options, args) = parser.parse_args()

  logging.basicConfig(format='[%(asctime)s] %(levelname)-8s"%(message)s"', datefmt='%Y-%m-%d %a %H:%M:%S')
  
  if options.verbose:
    logger.setLevel(logging.NOTSET)

  initialize()

  zookeeper.set_log_stream(open("/dev/null"))
  cc = SinClusterClient(settings.SIN_SERVICE_NAME, settings.ZOOKEEPER_URL, settings.ZOOKEEPER_TIMEOUT)
  cc.logger.setLevel(logging.INFO)
  cc.logger.addHandler(logging.StreamHandler())
  cc.add_listener(SinClusterListener())

  if options.force or options.reset:
    cc.reset()
    Node.objects.all().delete()
    logger.info("Removed all registered nodes from the system.")
    logger.info("You may want to shut down all the agents.")
    if options.reset:
      return

  # Reset online status.  Some node(s) might have gone offline while Sin
  # server was down, therefore the server did not get notified and still
  # keeps the old "online" status for the node(s).  If the node(s) are
  # still online, we will send the start-store commands to them anyway.
  # If a store is already running on a node, the start-store command
  # will simply become a no-op.
  Node.objects.filter(online=True).update(online=False)

  for node in settings.SENSEI_NODES["nodes"]:
    if not Node.objects.filter(id=node["node_id"]).exists():
      Node.objects.create(id=node["node_id"], host=node["host"], agent_port=node["port"],
                          online=False, group=Group(pk=1))
      cc.register_node(node["node_id"], node["host"], port=node["port"])

  static_files = static.File(os.path.join(os.path.join(SIN_HOME, 'admin')))
  WSGI = wsgi.WSGIResource(reactor, pool, WSGIHandler())
  root = Root(WSGI)
  root.putChild('static', static_files)
  
  log.startLogging(sys.stdout)
  site = server.Site(root)
  reactor.listenTCP(settings.SIN_LISTEN, site)
  pool.start()

  def post_initialization():
    cc.notify_all()

  reactor.callInThread(post_initialization)

  reactor.run(installSignalHandlers=False)
Пример #2
0
def main(argv):
    usage = "usage: %prog [options]"
    parser = OptionParser(usage=usage)
    parser.add_option("-f",
                      "--force",
                      action="store_true",
                      dest="force",
                      help="Overwrite existing Sensei node info")
    parser.add_option("-c",
                      "--reset",
                      action="store_true",
                      dest="reset",
                      help="Remove all registered nodes and then exit")
    parser.add_option("-i",
                      "--init",
                      action="store_true",
                      dest="init",
                      help="Initialize nodes")
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      help="Verbose mode")
    (options, args) = parser.parse_args()

    logging.basicConfig(format='[%(asctime)s] %(levelname)-8s"%(message)s"',
                        datefmt='%Y-%m-%d %a %H:%M:%S')

    if options.verbose:
        logger.setLevel(logging.NOTSET)

    initialize()

    zookeeper.set_log_stream(open("/dev/null"))
    global cluster_client
    cluster_client = SinClusterClient(settings.SIN_SERVICE_NAME,
                                      settings.ZOOKEEPER_URL,
                                      settings.ZOOKEEPER_TIMEOUT)
    cluster_client.logger.setLevel(logging.INFO)
    cluster_client.logger.addHandler(logging.StreamHandler())
    cluster_client.add_listener(SinClusterListener())

    if options.force or options.reset:
        cluster_client.reset()
        Node.objects.all().delete()
        logger.info("Removed all registered nodes from the system.")
        logger.info("You may want to shut down all the agents.")
        if options.reset:
            return

    for node in settings.SIN_NODES["nodes"]:
        n, created = Node.objects.get_or_create(id=node["node_id"],
                                                defaults={
                                                    "id": node["node_id"],
                                                    "host": node["host"],
                                                    "agent_port": node["port"],
                                                    "online": False,
                                                    "group": Group(pk=1),
                                                })
        if not created:
            if n.host != node["host"] or n.agent_port != node["port"]:
                n.host = node["host"]
                n.agent_port = node["port"]
                n.save()
                cluster_client.remove_node(node["node_id"])
        cluster_client.register_node(node["node_id"],
                                     node["host"],
                                     port=node["port"])

    if options.init:
        return

    # Reset online status.  Some node(s) might have gone offline while Sin
    # server was down, therefore the server did not get notified and still
    # keeps the old "online" status for the node(s).  If the node(s) are
    # still online, we will send the start-store commands to them anyway.
    # If a store is already running on a node, the start-store command
    # will simply become a no-op.
    Node.objects.filter(online=True).update(online=False)

    static_files = static.File(os.path.join(os.path.join(SIN_HOME, 'admin')))
    WSGI = wsgi.WSGIResource(reactor, pool, WSGIHandler())
    root = Root(WSGI)
    root.putChild('static', static_files)

    log.startLogging(sys.stdout)
    site = server.Site(root)
    reactor.listenTCP(settings.SIN_LISTEN, site)
    pool.start()

    def post_initialization():
        cluster_client.notify_all()

    reactor.callInThread(post_initialization)

    reactor.callInThread(monitoring)

    reactor.run(installSignalHandlers=False)
Пример #3
0
    print "Required argument, node_id, is missing"
    print usage
    sys.exit(1)

  node_id = int(args[0])

  root = Root()
  for viewName, className in VIEWS.items():
    # Add the view to the web service
    root.putChild(viewName, className)
  log.startLogging(sys.stdout)
  log.msg("Starting server: %s" % str(datetime.now()))

  server = server.Site(root)
  
  cluster_client = SinClusterClient(settings.SIN_SERVICE_NAME, settings.ZOOKEEPER_URL, settings.ZOOKEEPER_TIMEOUT)
  cluster_client.logger.setLevel(logging.DEBUG)
  cluster_client.logger.addHandler(logging.StreamHandler())
  cluster_client.add_listener(SinClusterListener())

  nodes = cluster_client.get_registered_nodes()
  if nodes.get(node_id):
    node = nodes[node_id]
    host = None
    if options.host != "":
      host = options.host
    if is_current_host(node.get_host(), host):
      # Force this node to be offline first.  (In the case where
      # sin_agent is stopped and then immediately restarted, the
      # ephemeral node created in the last session may still be there
      # when sin_agent is restarted.)
Пример #4
0
        print usage
        sys.exit(1)

    node_id = int(args[0])

    root = Root()
    for viewName, className in VIEWS.items():
        # Add the view to the web service
        root.putChild(viewName, className)
    log.startLogging(sys.stdout)
    log.msg("Starting server: %s" % str(datetime.now()))

    server = server.Site(root)

    cluster_client = SinClusterClient(settings.SIN_SERVICE_NAME,
                                      settings.ZOOKEEPER_URL,
                                      settings.ZOOKEEPER_TIMEOUT)
    cluster_client.logger.setLevel(logging.DEBUG)
    cluster_client.logger.addHandler(logging.StreamHandler())
    cluster_client.add_listener(SinClusterListener())

    nodes = cluster_client.get_registered_nodes()
    if nodes.get(node_id):
        node = nodes[node_id]
        host = None
        if options.host != "":
            host = options.host
        if settings.DISABLE_HOST_CHECK or is_current_host(
                node.get_host(), host):
            # Force this node to be offline first.  (In the case where
            # sin_agent is stopped and then immediately restarted, the