Ejemplo n.º 1
0
def cleanup_loop():
    last_cleanup = 0
    last_run_check = 0
    last_runner_check = 0
    while True:
        with runtime.is_active_condition:
            while not runtime.is_active:
                runtime.is_active_condition.wait()

        while runtime.is_active:
            if runner_check_interval < time.time() - last_runner_check:
                try:
                    AnarchyRunner.manage_runners(runtime)
                    last_runner_check = time.time()
                except:
                    operator_logger.exception(
                        'Error in AnarchyRunner.manage_runners!')

            if cleanup_interval < time.time() - last_cleanup:
                try:
                    AnarchyGovernor.cleanup(runtime)
                    last_cleanup = time.time()
                except:
                    operator_logger.exception(
                        'Error in AnarchyGovernor.cleanup!')

            if run_check_interval < time.time() - last_run_check:
                try:
                    AnarchyRun.manage_active_runs(runtime)
                    last_run_check = time.time()
                except:
                    operator_logger.exception(
                        'Error in AnarchyRun.manage_active_runs!')

            time.sleep(5)
Ejemplo n.º 2
0
def init():
    """Initialization function before management loops."""
    global init_complete
    AnarchyGovernor.init(runtime)
    AnarchyRunner.init(runtime)

    init_complete = True
    operator_logger.debug("Completed init")
Ejemplo n.º 3
0
def watch_governors():
    '''
    Watch AnarchyGovernors to keep definition in sync.
    '''
    while True:
        try:
            AnarchyGovernor.watch(runtime)
        except Exception as e:
            operator_logger.exception("Error in AnarchyGovernor watch")
            time.sleep(5)
Ejemplo n.º 4
0
def main_loop():
    last_cleanup = 0
    last_run_check = 0
    last_runner_check = 0
    while True:
        with runtime.is_active_condition:
            while not runtime.is_active:
                runtime.is_active_condition.wait()

        if runtime.running_all_in_one:
            start_runner_process()
        elif not AnarchyRunner.get('default'):
            init_default_runner()

        while runtime.is_active:
            AnarchyAction.start_actions(runtime)

            if cleanup_interval < time.time() - last_cleanup:
                try:
                    AnarchyGovernor.cleanup(runtime)
                    last_cleanup = time.time()
                except:
                    operator_logger.exception(
                        'Error in AnarchyGovernor.cleanup!')

            if run_check_interval < time.time() - last_run_check:
                try:
                    AnarchyRun.manage_active_runs(runtime)
                    last_run_check = time.time()
                except:
                    operator_logger.exception(
                        'Error in AnarchyRun.manage_active_runs!')

            if runner_check_interval < time.time() - last_runner_check:
                try:
                    AnarchyRunner.manage_runners(runtime)
                    last_runner_check = time.time()
                except:
                    operator_logger.exception(
                        'Error in AnarchyRunner.manage_runners!')

            time.sleep(1)
Ejemplo n.º 5
0
 def governor(self):
     return AnarchyGovernor.get(self.spec['governorRef']['name'])
 def get_governor(self, runtime):
     governor = AnarchyGovernor.get(self.spec['governor'])
     if not governor:
         operator_logger.error('Unable to find governor %s',
                               self.governor_name)
     return governor
Ejemplo n.º 7
0
def init_governors():
    """Get initial list of anarchy governors"""
    for resource in runtime.custom_objects_api.list_namespaced_custom_object(
        runtime.operator_domain, 'v1', runtime.operator_namespace, 'anarchygovernors'
    ).get('items', []):
        AnarchyGovernor.register(resource)
Ejemplo n.º 8
0
def handle_governor_event(event, **_):
    if event['type'] == 'DELETED':
        AnarchyGovernor.unregister(event['object']['metadata']['name'])
    elif event['type'] in ['ADDED', 'MODIFIED', None] \
    and 'spec' in event['object']:
        AnarchyGovernor.register(event['object'])