def execution_submit(state: SQLManager, scheduler: ZoeBaseScheduler, execution: Execution): """Submit a new execution to the scheduler.""" if execution.status != execution.SUBMIT_STATUS: log.warning('Trying to start an execution in state {}'.format( execution.status)) return if _digest_application_description(state, execution): execution.set_queued() scheduler.incoming(execution)
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.owner.username, '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) terminate_execution(execution, reason=ex.message) execution.set_queued() 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) terminate_execution(execution, reason=ex.message) 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') terminate_execution(execution, reason=str(ex)) execution.set_error() return "fatal" else: log.debug('Service {} started'.format(instance.name)) service.set_active(backend_id, ip_address, ports) return "ok"