Exemplo n.º 1
0
    def test_real_instance_ids(self):
        even_instance_id = 'i-0cfefd19c9a8db976'
        property_provider = TestPropertyProvider({
            ALLOCATOR_KEY:
            AB_TEST,
            CPU_ALLOCATOR_A:
            IP,
            CPU_ALLOCATOR_B:
            GREEDY,
            EC2_INSTANCE_ID:
            even_instance_id
        })
        config_manager = ConfigManager(property_provider)

        allocator_class = get_allocator_class(config_manager, 12)
        self.assertEqual(IntegerProgramCpuAllocator, allocator_class)

        odd_instance_id = 'i-0cfefd19c9a8db977'
        property_provider = TestPropertyProvider({
            ALLOCATOR_KEY:
            AB_TEST,
            CPU_ALLOCATOR_A:
            IP,
            CPU_ALLOCATOR_B:
            GREEDY,
            EC2_INSTANCE_ID:
            odd_instance_id
        })
        config_manager = ConfigManager(property_provider)

        allocator_class = get_allocator_class(config_manager, 12)
        self.assertEqual(GreedyCpuAllocator, allocator_class)
Exemplo n.º 2
0
    def test_ab_allocator_fallback(self):
        property_provider = TestPropertyProvider({ALLOCATOR_KEY: AB_TEST})
        config_manager = ConfigManager(property_provider)

        allocator_class = get_allocator_class(config_manager)
        self.assertEqual(NoopCpuAllocator, allocator_class)

        allocator_class = get_allocator_class(config_manager)
        self.assertEqual(NoopCpuAllocator, allocator_class)
Exemplo n.º 3
0
    def detect_allocator_change(self):
        current_allocator_name = get_allocator_class(self.__config_manager).__name__

        if current_allocator_name != self.__last_allocator_name:
            log.info("The CPU allocator has changed from: '{}' to: '{}'".format(
                self.__last_allocator_name, current_allocator_name))

            self.__exit_handler.exit(ALLOCATOR_CONFIG_CHANGE_EXIT)
Exemplo n.º 4
0
    def test_undefined_instance_id(self):
        property_provider = TestPropertyProvider({
            ALLOCATOR_KEY: AB_TEST,
            CPU_ALLOCATOR_A: IP,
            CPU_ALLOCATOR_B: GREEDY
        })
        config_manager = ConfigManager(property_provider)

        allocator_class = get_allocator_class(config_manager)
        self.assertEqual(NoopCpuAllocator, allocator_class)
Exemplo n.º 5
0
    def __get_tags():
        ec2_instance_id = 'EC2_INSTANCE_ID'

        tags = {}
        if ec2_instance_id in os.environ:
            tags["node"] = os.environ[ec2_instance_id]

        allocator_name = get_allocator_class(get_config_manager()).__name__
        tags["cpu_allocator"] = allocator_name

        return tags
Exemplo n.º 6
0
    def __init__(
            self,
            config_manager,
            exit_handler,
            detection_interval=PROPERTY_CHANGE_DETECTION_INTERVAL_SEC):

        self.__config_manager = config_manager
        self.__exit_handler = exit_handler

        self.__last_allocator_name = get_allocator_class(self.__config_manager).__name__
        schedule.every(detection_interval).seconds.do(self.detect_allocator_change)
Exemplo n.º 7
0
 def test_get_noop_cpu_allocator(self):
     property_provider = TestPropertyProvider({ALLOCATOR_KEY: NOOP})
     config_manager = ConfigManager(property_provider)
     allocator_class = get_allocator_class(config_manager)
     self.assertEqual(NoopCpuAllocator, allocator_class)