Пример #1
0
    def __init__(self,
                 broker,
                 rpcServer,
                 reqAdapterList,
                 siteAdapterList,
                 intAdapterList,
                 autoRun=True,
                 maximumManageIterations=None):
        """
        Main core object which knows adapters, brokers and calls SiteBroker.

        Contains all adapter boxes & broker objects.
        SiteBroker decides on and issues new orders to the site adapter(s).
        """
        self.broker = broker
        self.autoRun = autoRun
        self.manageInterval = 30
        # will count the number of iterations that have been executed
        self.manageIterations = 0
        self.maximumManageIterations = maximumManageIterations
        self.mr = MachineRegistry.MachineRegistry()
        self._rpcServer = rpcServer
        # self._rpcServer.register_function(self.getDescription,"ScaleCore_getDescription" )

        # REQ
        self.reqBox = RequirementBox()

        for a in reqAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.reqBox.addAdapterList(reqAdapterList)

        # SITE
        self.siteBox = SiteBox()

        for a in siteAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.siteBox.addAdapterList(siteAdapterList)

        # INTEGRATION
        self.intBox = IntegrationBox()

        for a in intAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.intBox.addAdapterList(intAdapterList)
Пример #2
0
    def __init__(
        self,
        broker,
        rpcServer,
        reqAdapterList,
        siteAdapterList,
        intAdapterList,
        autoRun=True,
        maximumManageIterations=None,
    ):
        """
        Main core object which knows adapters, brokers and calls SiteBroker.

        Contains all adapter boxes & broker objects.
        SiteBroker decides on and issues new orders to the site adapter(s).
        """
        self.broker = broker
        self.autoRun = autoRun
        self.manageInterval = 30
        # will count the number of iterations that have been executed
        self.manageIterations = 0
        self.maximumManageIterations = maximumManageIterations
        self.mr = MachineRegistry.MachineRegistry()
        self._rpcServer = rpcServer
        # self._rpcServer.register_function(self.getDescription,"ScaleCore_getDescription" )

        # REQ
        self.reqBox = RequirementBox()

        for a in reqAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.reqBox.addAdapterList(reqAdapterList)

        # SITE
        self.siteBox = SiteBox()

        for a in siteAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.siteBox.addAdapterList(siteAdapterList)

        # INTEGRATION
        self.intBox = IntegrationBox()

        for a in intAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.intBox.addAdapterList(intAdapterList)
Пример #3
0
class ScaleCore(object):
    _rpcServer = None

    def exportMethod(self, meth, name):
        if self._rpcServer is not None:
            self._rpcServer.register_function(meth, name)
        else:
            logger.warning('Can\'t register method %s with RPCServer "%s".' % (name, self._rpcServer))

    def __init__(
        self,
        broker,
        rpcServer,
        reqAdapterList,
        siteAdapterList,
        intAdapterList,
        autoRun=True,
        maximumManageIterations=None,
    ):
        """
        Main core object which knows adapters, brokers and calls SiteBroker.

        Contains all adapter boxes & broker objects.
        SiteBroker decides on and issues new orders to the site adapter(s).
        """
        self.broker = broker
        self.autoRun = autoRun
        self.manageInterval = 30
        # will count the number of iterations that have been executed
        self.manageIterations = 0
        self.maximumManageIterations = maximumManageIterations
        self.mr = MachineRegistry.MachineRegistry()
        self._rpcServer = rpcServer
        # self._rpcServer.register_function(self.getDescription,"ScaleCore_getDescription" )

        # REQ
        self.reqBox = RequirementBox()

        for a in reqAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.reqBox.addAdapterList(reqAdapterList)

        # SITE
        self.siteBox = SiteBox()

        for a in siteAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.siteBox.addAdapterList(siteAdapterList)

        # INTEGRATION
        self.intBox = IntegrationBox()

        for a in intAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.intBox.addAdapterList(intAdapterList)

    def startManagementTimer(self):
        t = Timer(self.manageInterval, self.startManage)
        t.start()

    def init(self):
        # self.exportMethod(self.setMachineTypeMaxInstances, "setMachineTypeMaxInstances")
        self.mr.machines = MachineRegistryLogger.load()

    def startManage(self):
        logger.info("----------------------------------")
        logger.info("Management cycle triggered")
        logger.info("Time: %s" % datetime.today().strftime("%Y-%m-%d %H:%M:%S"))

        # regular management
        self.reqBox.manage()
        self.siteBox.manage()
        self.intBox.manage()

        # scaling
        mReq = self.reqBox.getMachineTypeRequirement()
        logger.info("Current requirement: %s" % mReq)

        siteInfo = self.siteBox.siteInformation
        runningBySite = self.siteBox.runningMachinesCount

        # contains a list of all machine types merged
        runningOverall = summarize_dicts(list(runningBySite.values()))

        machStat = dict()
        for (key_, value_) in runningOverall.items():
            machStat[key_] = MachineStatus(mReq.get(key_, 0), value_)

        for key_ in mReq:
            if not key_ in machStat:
                machStat[key_] = MachineStatus(mReq.get(key_, 0), 0)

        decision = self.broker.decide(machStat, siteInfo.values())

        # Service machines may modify site decision(s).
        decision = self.siteBox.modServiceMachineDecision(decision)

        logger.info("Decision: %s" % decision)

        # make machine counts absolute, as they come in relative from the broker
        for (ksite, vmach) in decision.items():
            for kmach in vmach:
                decision[ksite][kmach] += runningBySite[ksite].get(kmach, [])
        logger.info("Absolute Decision: %s" % decision)

        self.siteBox.applyMachineDecision(decision)

        logger.info(self.mr.getMachineOverview())

        MachineRegistryLogger.dump(self.mr.machines)

        log = JsonLog()
        log.writeLog()

        self.manageIterations += 1

        lastIteration = False
        if self.maximumManageIterations is not None:
            lastIteration = self.maximumManageIterations <= self.manageIterations

        if self.autoRun is True and lastIteration is False:
            self.startManagementTimer()

    @property
    def description(self):
        return "Scale Core 0.7"
Пример #4
0
class ScaleCore(object):
    _rpcServer = None

    def exportMethod(self, meth, name):
        if self._rpcServer is not None:
            self._rpcServer.register_function(meth, name)
        else:
            logger.warning("Can't register method %s with RPCServer \"%s\"." % (name, self._rpcServer))

    def __init__(self,
                 broker,
                 rpcServer,
                 reqAdapterList,
                 siteAdapterList,
                 intAdapterList,
                 autoRun=True,
                 maximumManageIterations=None):
        """
        Main core object which knows adapters, brokers and calls SiteBroker.

        Contains all adapter boxes & broker objects.
        SiteBroker decides on and issues new orders to the site adapter(s).
        """
        self.broker = broker
        self.autoRun = autoRun
        self.manageInterval = 30
        # will count the number of iterations that have been executed
        self.manageIterations = 0
        self.maximumManageIterations = maximumManageIterations
        self.mr = MachineRegistry.MachineRegistry()
        self._rpcServer = rpcServer
        # self._rpcServer.register_function(self.getDescription,"ScaleCore_getDescription" )

        # REQ
        self.reqBox = RequirementBox()

        for a in reqAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.reqBox.addAdapterList(reqAdapterList)

        # SITE
        self.siteBox = SiteBox()

        for a in siteAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.siteBox.addAdapterList(siteAdapterList)

        # INTEGRATION
        self.intBox = IntegrationBox()

        for a in intAdapterList:
            a._rpcServer = self._rpcServer
            a.init()

        self.intBox.addAdapterList(intAdapterList)

    def init(self):
        # self.exportMethod(self.setMachineTypeMaxInstances, "setMachineTypeMaxInstances")
        self.mr.machines = MachineRegistryLogger.load()

    def startManagementTimer(self):
        t = Timer(self.manageInterval, self.startManage)
        t.start()

    def startManage(self):
        logger.info("----------------------------------")
        logger.info("Management cycle triggered")
        logger.info("Time: %s" % datetime.today().strftime("%Y-%m-%d %H:%M:%S"))

        # regular management
        self.reqBox.manage()
        self.siteBox.manage()
        self.intBox.manage()

        # scaling
        mReq = self.reqBox.getMachineTypeRequirement()
        logger.info("Current requirement: %s" % mReq)

        siteInfo = self.siteBox.siteInformation
        runningBySite = self.siteBox.runningMachinesCount

        # contains a list of all machine types merged
        runningOverall = summarize_dicts(list(runningBySite.values()))

        machStat = dict()
        for (key_, value_) in runningOverall.items():
            machStat[key_] = MachineStatus(mReq.get(key_, 0), value_)

        for key_ in mReq:
            if not key_ in machStat:
                machStat[key_] = MachineStatus(mReq.get(key_, 0), 0)

        decision = self.broker.decide(machStat, siteInfo.values())

        # Service machines may modify site decision(s).
        decision = self.siteBox.modServiceMachineDecision(decision)

        logger.info("Decision: %s" % decision)

        # make machine counts absolute, as they come in relative from the broker
        for (ksite, vmach) in decision.items():
            for kmach in vmach:
                decision[ksite][kmach] += runningBySite[ksite].get(kmach, [])
        logger.info("Absolute Decision: %s" % decision)

        self.siteBox.applyMachineDecision(decision)

        logger.info(self.mr.getMachineOverview())

        MachineRegistryLogger.dump(self.mr.machines)

        log = JsonLog()
        log.writeLog()

        self.manageIterations += 1

        lastIteration = False
        if self.maximumManageIterations is not None:
            lastIteration = self.maximumManageIterations <= self.manageIterations

        if self.autoRun is True and lastIteration is False:
            self.startManagementTimer()

    @property
    def description(self):
        return "Scale Core 0.7"