def patch(self, process_graph_id): try: """Update a process graph in the graph database""" # TODO: Implement user specific database access if process_graph_id in self.graph_db: process_graph = request.get_json() self.graph_db[process_graph_id] = process_graph return make_response(process_graph_id, 204) else: return make_response( ErrorSchema( id="123456678", code=404, message=f"Process graph with id {process_graph_id} " f"not found in database.").to_json(), 404) except Exception: e_type, e_value, e_tb = sys.exc_info() traceback_model = dict(message=str(e_value), traceback=traceback.format_tb(e_tb), type=str(e_type)) error = ErrorSchema(id="1234567890", code=2, message=str(traceback_model)) return make_response(error.to_json(), 400)
def post(self): """Submit a new job to the job database""" # TODO: Implement user specific database access job_id = f"user-job::{str(uuid4())}" job = request.get_json() if "process_graph" not in job: error = ErrorSchema( id=uuid4(), message="A process graph is required in the request") return make_response(error.to_json(), 400) job_info = check_job(job=job, job_id=job_id) self.job_db[job_id] = job_info return make_response(job_id, 201)
def get(self, job_id): """Return information about a single job https://open-eo.github.io/openeo-api/v/0.3.0/apireference/#tag/Job-Management/paths/~1jobs~1{job_id}/get """ if job_id in self.job_db: job: JobInformation = self.job_db[job_id] # Check for the actinia id to get the latest actinia job information if job_id in self.actinia_job_db: actinia_id = self.actinia_job_db[job_id] print("Resource id", actinia_id) code, job_info = self.iface.resource_info( resource_id=actinia_id) if code == 200: # Add the actinia information to the openeo job if job.additional_info != job_info: job.additional_info = job_info job.updated = job_info["datetime"] if job_info["status"] == "finished": job.status = "finished" if job_info["status"] == "error": job.status = "error" if job_info["status"] == "accepted": job.status = "queued" if job_info["status"] == "terminated": job.status = "canceled" if job_info["status"] == "running": job.status = "running" # Store the updated job in the database self.job_db[job_id] = job else: if job.additional_info != job_info: job.additional_info = job_info self.job_db[job_id] = job if (job.additional_info['urls'] and job.additional_info['urls']['resources']): resource_links = job.additional_info['urls']['resources'] if job.links is None: job.links = [] for link in resource_links: eo_link = EoLink(href=link) job.links.append(eo_link) return make_response(job.to_json(), 200) else: return make_response( ErrorSchema( id="123456678", code=404, message=f"job with id {job_id} not found in database."). to_json(), 404)
def patch(self, job_id): try: """Update a job in the job database""" # TODO: Implement user specific database access job = request.get_json() if job_id in self.job_db: if "process_graph" not in job: error = ErrorSchema( id=uuid4(), message="A process graph is required in the job request" ) return make_response(error.to_json(), 400) job_info = check_job(job=job, job_id=job_id) self.job_db[job_id] = job_info return make_response(job_id, 204) else: return make_response( ErrorSchema( id="123456678", code=404, message=f"job with id {job_id} not found in database." ).to_json(), 404) except Exception: e_type, e_value, e_tb = sys.exc_info() traceback_model = dict(message=str(e_value), traceback=traceback.format_tb(e_tb), type=str(e_type)) error = ErrorSchema(id="1234567890", code=2, message=str(traceback_model)) return make_response(error.to_json(), 400)
def post(self): try: """Store a process graph in the graph database""" # TODO: Implement user specific database access process_graph_id = f"user-graph::{str(uuid4())}" process_graph = request.get_json() self.graph_db[process_graph_id] = process_graph return make_response(process_graph_id, 201) except Exception: e_type, e_value, e_tb = sys.exc_info() traceback_model = dict(message=str(e_value), traceback=traceback.format_tb(e_tb), type=str(e_type)) error = ErrorSchema(id="1234567890", code=2, message=str(traceback_model)) return make_response(error.to_json(), 400)
def post(self, job_id): """Start a processing job in the actinia backend https://open-eo.github.io/openeo-api/v/0.3.0/apireference/#tag/Job-Management/paths/~1jobs~1{job_id}~1results/post """ try: if job_id in self.job_db: job: JobInformation = self.job_db[job_id] status, response = self.send_actinia_processing_request( job=job) self.actinia_job_db[job_id] = response["resource_id"] job.additional_info = response job.status = "queued" job.updated = str(datetime.now()) self.job_db[job_id] = job return make_response( "The creation of the resource has been queued successfully.", 202) else: return make_response( ErrorSchema( id="123456678", code=404, message=f"job with id {job_id} not found in database." ).to_json(), 404) except Exception: e_type, e_value, e_tb = sys.exc_info() traceback_model = dict(message=str(e_value), traceback=traceback.format_tb(e_tb), type=str(e_type)) error = ErrorSchema(id="1234567890", code=2, message=str(traceback_model)) return make_response(error.to_json(), 400)
def post(self): """Run the job in an ephemeral mapset :return: """ try: # Empty the process location ActiniaInterface.PROCESS_LOCATION = {} process_graph = request.get_json() # Transform the process graph into a process chain and store the input location # Check all locations in the process graph result_name, process_list = analyse_process_graph(process_graph) if len(ActiniaInterface.PROCESS_LOCATION) == 0 or len( ActiniaInterface.PROCESS_LOCATION) > 1: msg = "Processes can only be defined for a single location!" status = 400 es = ErrorSchema(id=str(datetime.now()), code=status, message=str(msg)) return make_response(es.to_json(), status) location = ActiniaInterface.PROCESS_LOCATION.keys() location = list(location)[0] process_chain = dict(list=process_list, version="1") pprint(process_chain) status, response = self.iface.sync_ephemeral_processing_validation( location=location, process_chain=process_chain) pprint(response) if status == 200: return make_response("", 204) else: es = ErrorSchema(id=str(datetime.now()), code=status, message=str(response)) return make_response(es.to_json(), status) except Exception as e: es = ErrorSchema(id=str(datetime.now()), code=400, message=str(e)) return make_response(es.to_json(), 400)
def post(self): """Run the job in an ephemeral mapset synchronously for 10 seconds. After 10 seconds the running job will be killed on the actinia server and the response will be an termination report. """ try: # Empty the process location ActiniaInterface.PROCESS_LOCATION = {} request_doc = request.get_json() process_graph = request_doc["process_graph"] # Transform the process graph into a process chain and store the input location # Check all locations in the process graph result_name, process_list = analyse_process_graph(process_graph) if len(ActiniaInterface.PROCESS_LOCATION) == 0 or len( ActiniaInterface.PROCESS_LOCATION) > 1: return make_response( jsonify( { "description": "Processes can only be defined for a single location!" }, 400)) location = ActiniaInterface.PROCESS_LOCATION.keys() location = list(location)[0] process_chain = dict(list=process_list, version="1") # pprint.pprint(process_chain) status, response = self.iface.async_ephemeral_processing_export( location=location, process_chain=process_chain) status, response = self.wait_until_finished(response=response, max_time=10) if status == 200: return make_response( jsonify({ "job_id": response["resource_id"], "job_info": response }), status) else: error = ErrorSchema(id="1234567890", code=1, message=str(response), links=response["urls"]["status"]) return make_response(error.to_json(), status) except Exception: e_type, e_value, e_tb = sys.exc_info() traceback_model = dict(message=str(e_value), traceback=traceback.format_tb(e_tb), type=str(e_type)) error = ErrorSchema(id="1234567890", code=2, message=str(traceback_model)) return make_response(error.to_json(), 400)
def delete(self, process_graph_id): """Remove a single process graph from the database""" if process_graph_id in self.graph_db: del self.graph_db[process_graph_id] return make_response( f"Process graph {process_graph_id} have been successfully deleted", 204) else: return make_response( ErrorSchema(id=str(uuid4()), code=400, message=f"Process graph id {process_graph_id} " f"not found").to_json(), 400)
def delete(self, job_id): """Delete a single job https://open-eo.github.io/openeo-api/v/0.3.0/apireference/#tag/Job-Management/paths/~1jobs~1{job_id}/delete """ if job_id in self.job_db: del self.job_db[job_id] return make_response("The job has been successfully deleted", 204) else: return make_response( ErrorSchema( id="123456678", code=404, message=f"job with id {job_id} not found in database."). to_json(), 404)
def get(self, job_id): """Return information about a single job https://open-eo.github.io/openeo-api/v/0.3.0/apireference/#tag/Job-Management/paths/~1jobs~1{job_id}/get """ if job_id in self.job_db: job = self.job_db[job_id] return make_response(job.to_json(), 200) else: return make_response( ErrorSchema( id="123456678", code=404, message=f"job with id {job_id} not found in database."). to_json(), 404)
def get(self, process_graph_id): """Return all jobs in the job database""" # TODO: Implement user specific database access if process_graph_id in self.graph_db: graph = self.graph_db[process_graph_id] graph["process_graph_id"] = process_graph_id return make_response(jsonify(graph), 200) else: return make_response( ErrorSchema( id=str(uuid4()), code=400, message=f"Process graph id {process_graph_id} not found"). to_json(), 400)
def delete(self, job_id): """Cancel a running job https://open-eo.github.io/openeo-api/v/0.3.0/apireference/#tag/Job-Management/paths/~1jobs~1{job_id}~1results/delete """ if job_id in self.job_db: # Check for the actinia id to get the latest actinia job information if job_id in self.actinia_job_db: actinia_id = self.actinia_job_db[job_id] code, job_info = self.iface.delete_resource( resource_id=actinia_id) return make_response("The job has been successfully cancelled", 204) else: return make_response( ErrorSchema( id="123456678", code=404, message=f"job with id {job_id} not found in database."). to_json(), 404)