コード例 #1
0
    def handle_PartitionOwnershipReq(self, req):
        self._logger.info("Got PartitionOwnershipReq: %s" % str(req))
        status = False
        if req.ownership:
            if self._workers.has_key(req.partition):
                self._logger.info("Dup partition %d" % req.partition)
            else:
                uvedb = self._us.get_part(req.partition)
                ph = UveStreamProc(','.join(self._conf.kafka_broker_list()),
                                   req.partition, "uve-" + str(req.partition),
                                   self._logger, uvedb, self.handle_uve_notif)
                ph.start()
                self._workers[req.partition] = ph
                status = True
        else:
            #import pdb; pdb.set_trace()
            if self._workers.has_key(req.partition):
                ph = self._workers[req.partition]
                gevent.kill(ph)
                res, db = ph.get()
                print "Returned " + str(res)
                print "State :"
                for k, v in db.iteritems():
                    print "%s -> %s" % (k, str(v))
                del self._workers[req.partition]
                status = True
            else:
                self._logger.info("No partition %d" % req.partition)

        resp = PartitionOwnershipResp()
        resp.status = status
        resp.response(req.context())
コード例 #2
0
    def handle_PartitionOwnershipReq(self, req):
        self._logger.info("Got PartitionOwnershipReq: %s" % str(req))
        status = False
        if req.ownership:
            if self._workers.has_key(req.partition):
                self._logger.info("Dup partition %d" % req.partition)
            else:
                uvedb = self._us.get_part(req.partition)
                ph = UveStreamProc(','.join(self._conf.kafka_broker_list()),
                                   req.partition, "uve-" + str(req.partition),
                                   self._logger, uvedb,
                                   self.handle_uve_notif)
                ph.start()
                self._workers[req.partition] = ph
                status = True
        else:
            #import pdb; pdb.set_trace()
            if self._workers.has_key(req.partition):
                ph = self._workers[req.partition]
                gevent.kill(ph)
                res,db = ph.get()
                print "Returned " + str(res)
                print "State :"
                for k,v in db.iteritems():
                    print "%s -> %s" % (k,str(v)) 
                del self._workers[req.partition]
                status = True
            else:
                self._logger.info("No partition %d" % req.partition)

        resp = PartitionOwnershipResp()
        resp.status = status
	resp.response(req.context())
コード例 #3
0
    def partition_change(self, partno, enl):
        """
        Call this function when getting or giving up
        ownership of a partition
        Args:
            partno : Partition Number
            enl    : True for acquiring, False for giving up
        Returns: 
            status of operation (True for success)
        """
        status = False
        if enl:
            if self._workers.has_key(partno):
                self._logger.info("Dup partition %d" % partno)
            else:
                #uvedb = self._us.get_part(partno)
                ph = UveStreamProc(','.join(self._conf.kafka_broker_list()),
                                   partno, "uve-" + str(partno),
                                   self._logger, self._us.get_part,
                                   self.handle_uve_notif)
                ph.start()
                self._workers[partno] = ph
                status = True
        else:
            if self._workers.has_key(partno):
                ph = self._workers[partno]
                gevent.kill(ph)
                res,db = ph.get()
                print "Returned " + str(res)
                print "State :"
                for k,v in db.iteritems():
                    print "%s -> %s" % (k,str(v)) 
                del self._workers[partno]
                status = True
            else:
                self._logger.info("No partition %d" % partno)

        return status
コード例 #4
0
    def partition_change(self, partno, enl):
        """
        Call this function when getting or giving up
        ownership of a partition
        Args:
            partno : Partition Number
            enl    : True for acquiring, False for giving up
        Returns: 
            status of operation (True for success)
        """
        status = False
        if enl:
            if self._workers.has_key(partno):
                self._logger.info("Dup partition %d" % partno)
            else:
                #uvedb = self._us.get_part(partno)
                ph = UveStreamProc(','.join(self._conf.kafka_broker_list()),
                                   partno, "uve-" + str(partno),
                                   self._logger, self._us.get_part,
                                   self.handle_uve_notif)
                ph.start()
                self._workers[partno] = ph
                status = True
        else:
            if self._workers.has_key(partno):
                ph = self._workers[partno]
                gevent.kill(ph)
                res,db = ph.get()
                print "Returned " + str(res)
                print "State :"
                for k,v in db.iteritems():
                    print "%s -> %s" % (k,str(v)) 
                del self._workers[partno]
                status = True
            else:
                self._logger.info("No partition %d" % partno)

        return status
コード例 #5
0
    def partition_change(self, partno, enl):
        """
        Call this function when getting or giving up
        ownership of a partition
        Args:
            partno : Partition Number
            enl    : True for acquiring, False for giving up
        Returns: 
            status of operation (True for success)
        """
        status = False
        if enl:
            if partno in self._workers:
                self._logger.info("Dup partition %d" % partno)
            else:
                cdisc = None
                if self.disc:
                    cdisc = client.DiscoveryClient(
                        self._conf.discovery()['server'],
                        self._conf.discovery()['port'],
                        ModuleNames[Module.ALARM_GENERATOR], '%s-%s-%d' %
                        (self._hostname, self._instance_id, partno))
                ph = UveStreamProc(','.join(self._conf.kafka_broker_list()),
                                   partno, "uve-" + str(partno),
                                   self._logger, self.handle_uve_notifq,
                                   self._conf.host_ip(),
                                   self.handle_resource_check,
                                   self._instance_id,
                                   self._conf.redis_server_port(), cdisc)
                ph.start()
                self._workers[partno] = ph
                tout = 600
                idx = 0
                while idx < tout:
                    # When this partitions starts,
                    # uveq will get created
                    if partno not in self._uveq:
                        gevent.sleep(.1)
                    else:
                        break
                    idx += 1
                if partno in self._uveq:
                    status = True
                else:
                    # TODO: The partition has not started yet,
                    #       but it still might start later.
                    #       We possibly need to exit
                    status = False
                    self._logger.error("Unable to start partition %d" % partno)
        else:
            if partno in self._workers:
                ph = self._workers[partno]
                self._logger.error("Kill part %s" % str(partno))
                ph.kill()
                res, db = ph.get(False)
                self._logger.error("Returned " + str(res))
                del self._workers[partno]
                self._uveqf[partno] = True

                tout = 600
                idx = 0
                while idx < tout:
                    # When this partitions stop.s
                    # uveq will get destroyed
                    if partno in self._uveq:
                        gevent.sleep(.1)
                    else:
                        break
                    idx += 1
                if partno not in self._uveq:
                    status = True
                else:
                    # TODO: The partition has not stopped yet
                    #       but it still might stop later.
                    #       We possibly need to exit
                    status = False
                    self._logger.error("Unable to stop partition %d" % partno)
            else:
                self._logger.info("No partition %d" % partno)

        return status
コード例 #6
0
    def partition_change(self, partno, enl):
        """
        Call this function when getting or giving up
        ownership of a partition
        Args:
            partno : Partition Number
            enl    : True for acquiring, False for giving up
        Returns: 
            status of operation (True for success)
        """
        status = False
        if enl:
            if partno in self._workers:
                self._logger.info("Dup partition %d" % partno)
            else:
                cdisc = None
                if self.disc:
                    cdisc = client.DiscoveryClient(
                        self._conf.discovery()["server"],
                        self._conf.discovery()["port"],
                        ModuleNames[Module.ALARM_GENERATOR],
                        "%s-%s-%d" % (self._hostname, self._instance_id, partno),
                    )
                ph = UveStreamProc(
                    ",".join(self._conf.kafka_broker_list()),
                    partno,
                    "uve-" + str(partno),
                    self._logger,
                    self.handle_uve_notifq,
                    self._conf.host_ip(),
                    self.handle_resource_check,
                    self._instance_id,
                    self._conf.redis_server_port(),
                    cdisc,
                )
                ph.start()
                self._workers[partno] = ph
                self._uvestats[partno] = {}
                tout = 600
                idx = 0
                while idx < tout:
                    # When this partitions starts,
                    # uveq will get created
                    if partno not in self._uveq:
                        gevent.sleep(0.1)
                    else:
                        break
                    idx += 1
                if partno in self._uveq:
                    status = True
                else:
                    # TODO: The partition has not started yet,
                    #       but it still might start later.
                    #       We possibly need to exit
                    status = False
                    self._logger.error("Unable to start partition %d" % partno)
        else:
            if partno in self._workers:
                ph = self._workers[partno]
                self._logger.error("Kill part %s" % str(partno))
                ph.kill()
                res, db = ph.get(False)
                self._logger.error("Returned " + str(res))
                del self._workers[partno]
                del self._uvestats[partno]
                self._uveqf[partno] = True

                tout = 600
                idx = 0
                while idx < tout:
                    # When this partitions stop.s
                    # uveq will get destroyed
                    if partno in self._uveq:
                        gevent.sleep(0.1)
                    else:
                        break
                    idx += 1
                if partno not in self._uveq:
                    status = True
                else:
                    # TODO: The partition has not stopped yet
                    #       but it still might stop later.
                    #       We possibly need to exit
                    status = False
                    self._logger.error("Unable to stop partition %d" % partno)
            else:
                self._logger.info("No partition %d" % partno)

        return status
コード例 #7
0
    def partition_change(self, partno, enl):
        """
        Call this function when getting or giving up
        ownership of a partition
        Args:
            partno : Partition Number
            enl    : True for acquiring, False for giving up
        Returns: 
            status of operation (True for success)
        """
        status = False
        if enl:
            if partno in self._workers:
                self._logger.info("Dup partition %d" % partno)
            else:
                ph = UveStreamProc(','.join(self._conf.kafka_broker_list()),
                                   partno, "uve-" + str(partno),
                                   self._logger, self._us.get_part,
                                   self.handle_uve_notifq)
                ph.start()
                self._workers[partno] = ph
                tout = 600
                idx = 0
                while idx < tout:
                    # When this partitions starts,
                    # uveq will get created
                    if partno not in self._uveq:
                        gevent.sleep(.1)
                    else:
                        break
                    idx += 1
                if partno in self._uveq:
                    status = True 
                else:
                    # TODO: The partition has not started yet,
                    #       but it still might start later.
                    #       We possibly need to exit
                    status = False
                    self._logger.error("Unable to start partition %d" % partno)
        else:
            if partno in self._workers:
                ph = self._workers[partno]
                gevent.kill(ph)
                res,db = ph.get()
                print "Returned " + str(res)
                print "State :"
                for k,v in db.iteritems():
                    print "%s -> %s" % (k,str(v)) 
                del self._workers[partno]
                self._uveqf[partno] = True

                tout = 600
                idx = 0
                while idx < tout:
                    # When this partitions stop.s
                    # uveq will get destroyed
                    if partno in self._uveq:
                        gevent.sleep(.1)
                    else:
                        break
                    idx += 1
                if partno not in self._uveq:
                    status = True 
                else:
                    # TODO: The partition has not stopped yet
                    #       but it still might stop later.
                    #       We possibly need to exit
                    status = False
                    self._logger.error("Unable to stop partition %d" % partno)
            else:
                self._logger.info("No partition %d" % partno)

        return status