Example #1
0
    def maintain():
        """
        For each API type, maintain a desired capacity calculated based on number of outstanding requests.
        """
        APIContainer.log_info("Starting container maintenance...")
        APIContainer.refresh_container_list()
        APIContainer.release_queues()
        APIContainer.calc_desired_container_counts()

        def cleanup(msg):
            if 'nid' in msg:
                cont = APIContainer.get_by_name(msg['nid'])
                cont.delete()

        for (api_name, clist) in APIContainer.API_CONTAINERS.iteritems():
            ndiff = len(clist) - APIContainer.DESIRED_CONTAINER_COUNTS[api_name]

            # terminate if in excess
            while ndiff > 0:
                APIContainer.log_debug("terminating one instance of %s", api_name)
                APIConnector.send_terminate_msg(api_name, on_recv=cleanup)
                ndiff -= 1

            # launch if more required
            while ndiff < 0:
                APIContainer.log_debug("launching one instance of %s", api_name)
                APIContainer.create_new(api_name)
                ndiff += 1

        APIContainer.log_info("Finished container maintenance.")
Example #2
0
    def maintain():
        """
        For each API type, maintain a desired capacity calculated based on number of outstanding requests.
        """
        APIContainer.log_info("Starting container maintenance...")
        APIContainer.refresh_container_list()
        APIContainer.release_queues()
        APIContainer.calc_desired_container_counts()

        def cleanup(msg):
            if 'nid' in msg:
                cont = APIContainer.get_by_name(msg['nid'])
                cont.delete()

        for (api_name, clist) in APIContainer.API_CONTAINERS.iteritems():
            ndiff = len(
                clist) - APIContainer.DESIRED_CONTAINER_COUNTS[api_name]

            # terminate if in excess
            while ndiff > 0:
                APIContainer.log_debug("terminating one instance of %s",
                                       api_name)
                APIConnector.send_terminate_msg(api_name, on_recv=cleanup)
                ndiff -= 1

            # launch if more required
            while ndiff < 0:
                APIContainer.log_debug("launching one instance of %s",
                                       api_name)
                APIContainer.create_new(api_name)
                ndiff += 1

        APIContainer.log_info("Finished container maintenance.")
Example #3
0
 def release_queues():
     APIContainer.log_debug("active apis: %r", APIContainer.API_CONTAINERS)
     for api_name in APIQueue.QUEUES.keys():
         APIContainer.log_debug("checking queue for %s", api_name)
         if api_name not in APIContainer.API_CONTAINERS:
             APIConnector.release_connectors(api_name)
             APIQueue.release_queue(api_name)
Example #4
0
 def release_queues():
     APIContainer.log_debug("active apis: %r", APIContainer.API_CONTAINERS)
     for api_name in APIQueue.QUEUES.keys():
         APIContainer.log_debug("checking queue for %s", api_name)
         if api_name not in APIContainer.API_CONTAINERS:
             APIConnector.release_connectors(api_name)
             APIQueue.release_queue(api_name)