Exemplo n.º 1
0
def service_list_to_containers(execution: Execution,
                               service_list: List[Service],
                               placement=None) -> str:
    """Given a subset of services from an execution, tries to start them, return one of 'ok', 'requeue' for temporary failures and 'fatal' for fatal failures."""
    backend = _get_backend()

    ordered_service_list = sorted(service_list, key=lambda x: x.startup_order)

    env_subst_dict = {
        'execution_id': execution.id,
        "execution_name": execution.name,
        'user_name': execution.user_id,
        'deployment_name': get_conf().deployment_name,
    }

    for service in execution.services:
        env_subst_dict['dns_name#' + service.name] = service.dns_name

    for service in ordered_service_list:
        env_subst_dict['dns_name#self'] = service.dns_name
        if placement is not None:
            service.assign_backend_host(placement[service.id])
        service.set_starting()
        instance = ServiceInstance(execution, service, env_subst_dict)
        try:
            backend_id, ip_address, ports = backend.spawn_service(instance)
        except ZoeStartExecutionRetryException as ex:
            log.warning(
                'Temporary failure starting service {} of execution {}: {}'.
                format(service.id, execution.id, ex.message))
            service.set_error(ex.message)
            execution.set_error_message(ex.message)
            terminate_execution(execution)
            execution.set_scheduled()
            return "requeue"
        except ZoeStartExecutionFatalException as ex:
            log.error(
                'Fatal error trying to start service {} of execution {}: {}'.
                format(service.id, execution.id, ex.message))
            service.set_error(ex.message)
            execution.set_error_message(ex.message)
            terminate_execution(execution)
            execution.set_error()
            return "fatal"
        except Exception as ex:
            log.error('Fatal error trying to start service {} of execution {}'.
                      format(service.id, execution.id))
            log.exception('BUG, this error should have been caught earlier')
            execution.set_error_message(str(ex))
            terminate_execution(execution)
            execution.set_error()
            return "fatal"
        else:
            log.debug('Service {} started'.format(instance.name))
            service.set_active(backend_id, ip_address, ports)

    return "ok"
Exemplo n.º 2
0
def execution_submit(state: SQLManager, scheduler: ZoeBaseScheduler,
                     execution: Execution):
    """Submit a new execution to the scheduler."""
    if _digest_application_description(state, execution):
        execution.set_scheduled()
        scheduler.incoming(execution)