def execute_compute_job(): """Call the execution of a workflow. Method deprecated, it will be replaced by `/execute` in further versions swagger_from_file: docs/execute_compute_job.yml """ data = request.args required_attributes = [ 'serviceAgreementId', 'consumerAddress', 'signature', 'workflowDID' ] msg, status = check_required_attributes(required_attributes, data, 'consume') if msg: return msg, status if not (data.get('signature')): return f'`signature is required in the call to "consume".', 400 try: agreement_id = data.get('serviceAgreementId') consumer_address = data.get('consumerAddress') asset_id = keeper_instance().agreement_manager.get_agreement( agreement_id).did did = id_to_did(asset_id) if not was_compute_triggered(agreement_id, did, consumer_address, keeper_instance()): msg = ( 'Checking if the compute was triggered failed. Either consumer address does not ' 'have permission to executre this workflow or consumer address and/or service ' 'agreement id is invalid.') logger.warning(msg) return msg, 401 workflow = DIDResolver(keeper_instance().did_registry).resolve( data.get('workflowDID')) body = { "serviceAgreementId": agreement_id, "workflow": workflow.as_dictionary() } response = requests_session.post( get_config().compute_api_url + '/api/v1/nevermined-compute-api/init', data=json.dumps(body), headers={'content-type': 'application/json'}) return jsonify({"workflowId": response.content.decode('utf-8')}) except Exception as e: logger.error(f'Error- {str(e)}', exc_info=1) return f'Error : {str(e)}', 500
def execute(agreement_id): """Call the execution of a workflow. swagger_from_file: docs/execute.yml """ consumer_address = current_token["client_id"] workflow_did = current_token["did"] agreement_id = current_token["sub"] try: keeper = keeper_instance() asset_id = keeper_instance().agreement_manager.get_agreement( agreement_id).did did = id_to_did(asset_id) signature = '0x00' workflow = DIDResolver( keeper_instance().did_registry).resolve(workflow_did) body = { "serviceAgreementId": agreement_id, "workflow": workflow.as_dictionary() } response = requests_session.post( get_config().compute_api_url + '/api/v1/nevermined-compute-api/init', data=json.dumps(body), headers={'content-type': 'application/json'}) if response.status_code != 200: msg = f'The compute API was not able to create the workflow. {response.content}' logger.warning(msg) return msg, 401 used_by(generate_random_id(), did, consumer_address, 'compute', signature, 'compute', provider_acc, keeper) return jsonify({"workflowId": response.content.decode('utf-8')}) except Exception as e: logger.error(f'Error- {str(e)}', exc_info=1) return f'Error : {str(e)}', 500