def post(job_id): result, result_code = dict(status="ERROR", message=gettext('Not found')), 404 job = Job.query.get(job_id) if job is not None: data = json.loads(request.data) try: JobService.lock(job, data['user'], data['computer']) result, result_code = dict(status="OK", message=gettext('Locked')), 200 except JobException as je: log.exception('Error in POST') result, result_code = dict(status="ERROR", message=jstr(e), code=je.error_code), 422 if je.error_code == JobException.ALREADY_LOCKED: result_code = 409 except Exception as e: log.exception('Error in POST') result, result_code = dict( status="ERROR", message=gettext('Internal error')), 500 if current_app.debug: result['debug_detail'] = str(e) db.session.rollback() return result, result_code
def post(job_id): result, result_code = dict(status="ERROR", message=gettext("Not found")), 404 job = Job.query.get(job_id) if job is not None: response_schema = JobItemResponseSchema() try: JobService.stop(job) result, result_code = dict( status="OK", message=gettext("Deleted"), data=response_schema.dump(job).data), 200 except JobException as je: log.exception(gettext('Error in POST')) result, result_code = dict(status="ERROR", message=jstr(e), code=je.error_code), 422 # if je.error_code == JobException.ALREADY_FINISHED: # result['status'] = 'OK' # result['data'] = response_schema.dump(job).data # result_code = 200 except Exception as e: log.exception(gettext('Error in POST')) result, result_code = dict( status="ERROR", message=gettext("Internal error")), 500 if current_app.debug: result['debug_detail'] = str(e) db.session.rollback() return result, result_code
def post(): result, result_code = dict( status="ERROR", message=gettext("Missing json in the request body")), 400 if request.json is not None: try: request_json = request.json request_json['user']['id'] = g.user.id request_json['user']['login'] = g.user.login request_json['user']['name'] = ' '.join( [g.user.first_name, g.user.last_name]) request_json['job_key'] = '' request_schema = JobCreateRequestSchema() response_schema = JobItemResponseSchema() request_json['workflow']['locale'] = request.headers.get( 'Locale', 'en') or 'en' request_json['status'] = StatusExecution.WAITING if not request_json.get('name'): request_json['name'] = request_json.get('workflow_name') form = request_schema.load(request_json) if form.errors: result, result_code = dict( status="ERROR", message=gettext("Validation error"), errors=form.errors), 422 else: job = form.data JobService.start(job, request_json['workflow'], request_json.get('app_configs', {})) result_code = 200 result = dict(data=response_schema.dump(job).data, message='', status='OK') except KeyError: result['detail'] = gettext('Missing information in JSON') except ValueError: pass # default return value except JobException as je: log.exception(gettext('Error in POST')) result = dict(status="ERROR", message=str(je), code=je.error_code) result_code = 422 except Exception as e: log.exception(gettext('Error in POST')) result, result_code = dict( status="ERROR", message=gettext("Internal error")), 500 if current_app.debug or True: result['debug_detail'] = str(e) db.session.rollback() return result, result_code
def post(job_id, task_id): result, result_code = dict(status="ERROR", message=gettext('Not found')), 404 job = Job.query.get(job_id) if job is not None: try: data = json.loads(request.data) resp = JobService.retrieve_sample(data['user'], job, task_id, data['port'], wait=30) result, result_code = dict(status=resp['status'], message=resp['message'], data=data, sample=resp['sample']), 200 except JobException as je: log.exception('Error in POST') result, result_code = dict(status="ERROR", message=jstr(e), code=je.error_code), 422 except Exception as e: log.exception('Error in POST') result, result_code = dict( status="ERROR", message=gettext('Internal error')), 500 if current_app.debug: result['debug_detail'] = str(e) db.session.rollback() return result, result_code
def get(job_id): result, result_code = dict(status="ERROR", message=gettext('Not found')), 404 job = Job.query.get(job_id) if job is not None: lock_status = JobService.get_lock_status(job) result, result_code = dict(status="OK", message="", lock=lock_status), 200 return result, result_code
def post(model_id): # Deadline in seconds if request.json is None: return { 'status': 'ERROR', 'message': 'You need to inform the deadline' } deadline = request.json.get('deadline', 3600) return JobService.execute_performance_model( int(request.json.get('cluster_id', 0)), model_id, deadline, request.json.get('cores', [2]), request.json.get('platform', 'keras'), int(request.json.get('data_size', 1000)), int(request.json.get('iterations', 1000)), int(request.json.get('batch_size', 1000)), )
def post(): if request.json is None: return { 'status': 'ERROR', 'message': gettext('You need to inform the parameters') } workflow_id = request.json.get('workflow_id') if not workflow_id: return { 'status': 'ERROR', 'message': gettext('You must inform workflow_id.') } payload = {'data': request.json, 'workflow_id': workflow_id} now = datetime.datetime.now() name = 'Workflow {} @ {}'.format(workflow_id, now.isoformat()) job = Job( created=now, status=StatusExecution.WAITING, workflow_id=workflow_id, workflow_name=name, user_id=g.user.id, user_login=g.user.login, user_name=g.user.name, name=payload.get('name', name), type=JobType.BATCH, ) # Retrieves the workflow from tahiti tahiti_config = current_app.config['STAND_CONFIG']['services'][ 'tahiti'] url = '{}/workflows/{}'.format(tahiti_config.get('url'), workflow_id) headers = {'X-Auth-Token': str(tahiti_config['auth_token'])} try: r = requests.get(url, headers=headers) if r.status_code == 200: workflow = r.json() cluster_id = request.json.get( 'cluster_id', workflow.get('preferred_cluster_id')) if not cluster_id: return { 'status': 'ERROR', 'message': gettext('You must inform cluster_id or define a ' 'preferred one in workflow.') } job.cluster = Cluster.query.get(int(cluster_id)) job.workflow_definition = r.text JobService.start(job, workflow, {}, JobType.BATCH) return {'data': {'job': {'id': job.id}}} else: logging.error( gettext('Error retrieving workflow {}: {}').format( workflow_id, r.text)) return { 'status': 'ERROR', 'message': gettext('Workflow not found or error retrieving it.') } except Exception as e: logging.error(e) return { 'status': 'ERROR', 'message': gettext('Workflow not found or error retrieving it.') }
def get(key): return JobService.get_performance_model_result(key)