Пример #1
0
    def loop_start_th(self):
        """The Scheduler thread loop."""
        auto_trigger_base = 60  # seconds
        auto_trigger = auto_trigger_base
        while True:
            ret = self.trigger_semaphore.acquire(timeout=1)
            if not ret:  # Semaphore timeout, do some thread cleanup
                counter = len(self.async_threads)
                while counter > 0:
                    if len(self.async_threads) == 0:
                        break
                    th = self.async_threads.pop(0)
                    th.join(0.1)
                    if th.isAlive():  # join failed
                        log.debug('Thread {} join failed'.format(th.name))
                        self.async_threads.append(th)
                    counter -= 1
                auto_trigger -= 1
                if auto_trigger == 0:
                    auto_trigger = auto_trigger_base
                    self.trigger()
                continue
            if self.loop_quit:
                break

            log.debug("Scheduler start loop has been triggered")
            if len(self.fifo_queue) == 0:
                continue

            e = self.fifo_queue[0]
            assert isinstance(e, Execution)
            e.set_starting()
            self.fifo_queue.pop(0)  # remove the execution form the queue

            try:
                execution_to_containers(e)
            except ZoeStartExecutionRetryException as ex:
                log.warning('Temporary failure starting execution {}: {}'.format(e.id, ex.message))
                e.set_error_message(ex.message)
                terminate_execution(e)
                e.set_scheduled()
                self.fifo_queue.append(e)
            except ZoeStartExecutionFatalException as ex:
                log.error('Fatal error trying to start execution {}: {}'.format(e.id, ex.message))
                e.set_error_message(ex.message)
                terminate_execution(e)
                e.set_error()
            except Exception as ex:
                log.exception('BUG, this error should have been caught earlier')
                e.set_error_message(str(ex))
                terminate_execution(e)
                e.set_error()
            else:
                e.set_running()
Пример #2
0
    def loop_start_th(self):
        """The Scheduler thread loop."""
        while True:
            ret = self.trigger_semaphore.acquire(timeout=1)
            if not ret:  # Semaphore timeout, do some thread cleanup
                counter = len(self.async_threads)
                while counter > 0:
                    if len(self.async_threads) == 0:
                        break
                    th = self.async_threads.pop(0)
                    th.join(0.1)
                    if th.isAlive():  # join failed
                        log.debug('Thread {} join failed'.format(th.name))
                        self.async_threads.append(th)
                    counter -= 1
                continue
            if self.loop_quit:
                break

            log.debug("Scheduler start loop has been triggered")
            if len(self.fifo_queue) == 0:
                continue

            e = self.fifo_queue[0]
            assert isinstance(e, Execution)
            e.set_starting()
            self.fifo_queue.pop(0)  # remove the execution form the queue

            try:
                execution_to_containers(e)
            except ZoeStartExecutionRetryException as ex:
                log.warning(
                    'Temporary failure starting execution {}: {}'.format(
                        e.id, ex.message))
                e.set_error_message(ex.message)
                terminate_execution(e)
                e.set_scheduled()
                self.fifo_queue.append(e)
            except ZoeStartExecutionFatalException as ex:
                log.error(
                    'Fatal error trying to start execution {}: {}'.format(
                        e.id, ex.message))
                e.set_error_message(ex.message)
                terminate_execution(e)
                e.set_error()
            except Exception as ex:
                log.exception(
                    'BUG, this error should have been caught earlier')
                e.set_error_message(str(ex))
                terminate_execution(e)
                e.set_error()
            else:
                e.set_running()
Пример #3
0
def main():
    """The main entrypoint function."""
    conf = load_configuration()
    config.load_configuration(conf)
    args = config.get_conf()
    if args.debug:
        logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
    else:
        logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)

    logging.getLogger('kazoo').setLevel(logging.WARNING)
    logging.getLogger('requests').setLevel(logging.WARNING)
    logging.getLogger('urllib3').setLevel(logging.WARNING)
    logging.getLogger('docker').setLevel(logging.INFO)
    logging.getLogger("tornado").setLevel(logging.DEBUG)

    state = FakeSQLManager()

    zapp_description = json.load(args.jsonfile)

    print('Validating zapp description...')
    zoe_lib.applications.app_validate(zapp_description)

    exec_id = state.execution_new('test', 'fake_user', zapp_description)
    e = state.execution_list(only_one=True, id=exec_id)
    _digest_application_description(state, e)

    print('Zapp digested, starting containers...')
    execution_to_containers(e)

    print('Giving the containers a few seconds to start...')
    time.sleep(5)

    swarm = SwarmClient(args)
    for service in e.services:
        print("Service {}, docker ID: {}".format(service.name, service.docker_id))
        logs = swarm.logs(service.docker_id, False)
        logs = logs.decode('utf-8').split('\n')
        for log_line in logs[-10:]:
            print(log_line)

    print("Execution as been started, press CTRL-C to terminate it")
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass

    print('Terminating...')
    terminate_execution(e)
Пример #4
0
def main():
    conf = load_configuration()
    config.load_configuration(conf)
    args = config.get_conf()
    if args.debug:
        logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
    else:
        logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)

    logging.getLogger('kazoo').setLevel(logging.WARNING)
    logging.getLogger('requests').setLevel(logging.WARNING)
    logging.getLogger('urllib3').setLevel(logging.WARNING)
    logging.getLogger('docker').setLevel(logging.INFO)
    logging.getLogger("tornado").setLevel(logging.DEBUG)

    state = FakeSQLManager()
    config.singletons['sql_manager'] = state

    zapp_description = json.load(args.jsonfile)

    print('Validating zapp description...')
    zoe_lib.applications.app_validate(zapp_description)

    exec_id = state.execution_new('test', 'fake_user', zapp_description)
    e = state.execution_list(only_one=True, id=exec_id)
    _digest_application_description(e)

    print('Zapp digested, starting containers...')
    execution_to_containers(e)

    for service in e.services:
        print("Service {}, docker ID: {}".format(service.name,
                                                 service.docker_id))

    print("Execution as been started, press CTRL-C to terminate it")
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass

    print('Terminating...')
    terminate_execution(e)
Пример #5
0
def main():
    conf = load_configuration()
    config.load_configuration(conf)
    args = config.get_conf()
    if args.debug:
        logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
    else:
        logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)

    logging.getLogger("kazoo").setLevel(logging.WARNING)
    logging.getLogger("requests").setLevel(logging.WARNING)
    logging.getLogger("urllib3").setLevel(logging.WARNING)
    logging.getLogger("docker").setLevel(logging.INFO)
    logging.getLogger("tornado").setLevel(logging.DEBUG)

    state = FakeSQLManager()
    config.singletons["sql_manager"] = state

    zapp_description = json.load(args.jsonfile)

    print("Validating zapp description...")
    zoe_lib.applications.app_validate(zapp_description)

    exec_id = state.execution_new("test", "fake_user", zapp_description)
    e = state.execution_list(only_one=True, id=exec_id)
    _digest_application_description(e)

    print("Zapp digested, starting containers...")
    execution_to_containers(e)

    for service in e.services:
        print("Service {}, docker ID: {}".format(service.name, service.docker_id))

    print("Execution as been started, press CTRL-C to terminate it")
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass

    print("Terminating...")
    terminate_execution(e)
Пример #6
0
    def loop_start_th(self):
        while True:
            ret = self.trigger_semaphore.acquire()
            if not ret:  # Semaphore timeout, do some thread cleanup
                counter = len(self.async_threads)
                while counter > 0:
                    if len(self.async_threads) == 0:
                        break
                    th = self.async_threads.pop(0)
                    th.join(0.1)
                    if th.isAlive():  # join failed
                        self.async_threads.append(th)
                    counter -= 1
                continue
            if self.loop_quit:
                break

            log.debug("Scheduler start loop has been triggered")
            if len(self.fifo_queue) == 0:
                continue

            e = self.fifo_queue[0]
            assert isinstance(e, Execution)
            e.set_starting()
            self.fifo_queue.pop(0)  # remove the execution form the queue

            try:
                execution_to_containers(e)
            except ZoeStartExecutionRetryException as ex:
                log.warning('Temporary failure starting execution {}: {}'.format(e.id, ex.message))
                e.set_error_message(ex.message)
                terminate_execution(e)
                e.set_scheduled()
                self.fifo_queue.append(e)
            except ZoeStartExecutionFatalException as ex:
                log.error('Fatal error trying to start execution {}: {}'.format(e.id, ex.message))
                e.set_error_message(ex.message)
                terminate_execution(e)
                e.set_error()
            else:
                e.set_running()