Exemplo n.º 1
0
    def addQueue(self, store, brokerServer, brokerQueue, exchange, routingKey,
                 nodes, priority):
        exchange = exchange if exchange else brokerQueue
        routingKey = routingKey if routingKey else brokerQueue
        workApi = WorkApi()
        works = []
        if nodes and nodes[0] == "-1":
            works = workApi.getWorks()
        elif nodes:
            for node in nodes:
                workName = node.split(":")[0]
                works.append(workApi.getWork(workName))
        else:
            works = workApi.getWorks()

        brokerServer = brokerServer.split(":")[0]
        server = store.getBrokerServer(brokerServer)
        client = KombuClient(url=server.connectUri)
        client.addQueue(brokerQueue,
                        exchangeName=exchange,
                        routingKey=routingKey,
                        priority=priority)
        queue = BrokerQueue(server=brokerServer,
                            queueName=brokerQueue,
                            exchangeName=exchange,
                            routingKey=routingKey,
                            works=[work.hostName for work in works],
                            priority=priority)

        store.saveQueue(queue)
        store.addServerBrokerQueue(server, queue)

        queues = {}

        for work in works:
            jobIds = store.getJobIds()
            for jobId in jobIds:
                job = CacheHolder.getCache().get(jobId, JOBS)
                workIsRun = False
                for w in job.works:
                    if work.hostName == w.hostName and job.status != JOB_DELETE:
                        workIsRun = True

                if work.brokerServer != brokerServer and workIsRun:
                    raise Exception("有未删除的JOB【%s】在使用该节点,导致节点无法切换服务器,添加队列失败!" %
                                    job.jobId)

            if work.brokerServer != brokerServer:
                for q in work.queues:
                    if q in queues:
                        queues[q] = queues[q] + [work.hostName]
                    else:
                        queues[q] = [work.hostName]

            store.addWorkBrokerServerBrokerQueue(work, brokerServer,
                                                 brokerQueue)

        for key, values in queues.items():
            for v in values:
                store.removeWorkFromQueue(key, str(v))
Exemplo n.º 2
0
 def testUrl(self):
     client = KombuClient(
         url=
         "amqp://*****:*****@172.16.4.134:5672/cabbage_vhost"
     )
     conn = client.conn
     conn.connect()
     video_queue = Queue('hdfs',
                         exchange=Exchange("hdfs"),
                         routing_key='hdfs')
     with conn.Consumer(video_queue,
                        callbacks=[process_media],
                        accept=['json', 'pickle', 'msgpack',
                                'yaml']) as consumer:
         # Process messages and handle events on all channels
         while True:
             conn.drain_events()
Exemplo n.º 3
0
    def addServer(self, store, hostName, ip, port, connectUri, serverType):
        try:
            import socket
            socket.create_connection((ip, int(port)), timeout=3)
            KombuClient(url=connectUri)._connect()
        except Exception:
            log.exception(log)
            raise Exception("地址链接不通")

        if store.isExistBrokerServer(hostName):
            raise Exception("名称已经存在!")
        borkerServer = BrokerServer(port=port,
                                    ip=ip,
                                    serverType=serverType,
                                    connectUri=connectUri,
                                    hostName=hostName)
        store.saveBrokerServer(borkerServer)

        zope.event.notify(AddBrokerServerEvent(borkerServer))
Exemplo n.º 4
0
 def testDeleteExchage(self):
     client = KombuClient()
     client.deleteExchage("huawei")
Exemplo n.º 5
0
 def testDeleteQueue(self):
     client = KombuClient()
     client.deleteQueue("huawei", "huawei")
Exemplo n.º 6
0
 def testUrl(self):
     client = KombuClient(url="amqp://172.16.41.134")._connect()