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
Beispiel #2
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
    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.handle_uve_notifq, self._conf.host_ip(),
                        self._us)
                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