def checkConnection(name): """ Method to test connection Args: name (string): resource to test. Can be 'actinia-core' or 'geonetwork' Returns: response (Response): of type SimpleResponseModel telling connection success or failure """ if name == 'actinia-core': url = ACTINIACORE.url + "version" name = 'actinia-core' type = 'json' elif name == 'geonetwork': url = GEONETWORK.csw_url name = 'geonetwork' type = 'xml' try: records = common.checkConnection(url, name, type) except Exception: log.error("Don't know which connection to test") if records is not None: res = jsonify(SimpleResponseModel(status=200, message="success")) return make_response(res, 200) elif records is None: res = jsonify(SimpleResponseModel(status=404, message="failure")) return make_response(res, 200)
def post(self): """ Update a job This method is called by HTTP POST actinia-core webhook @app.route('/resources/processes/operations/update') This method is calling core method updateJob """ postbody = request.get_json(force=True) if type(postbody) is dict: postbody = json.dumps(postbody) elif type(postbody) != 'str': postbody = str(postbody) actiniaCoreResp = json.loads(postbody) resourceID = actiniaCoreResp['resource_id'] log.info("\n Received webhook call for " + resourceID) job = updateJob(resourceID, actiniaCoreResp) if job is not None: return make_response(jsonify(job), 200) else: res = (jsonify(SimpleResponseModel( status=404, message='Error' ))) return make_response(res, 404)
def get(self, actiniamodule): """Describe an actinia module (process chain template). """ try: virtual_module = createActiniaModule(self, actiniamodule) return make_response(jsonify(virtual_module), 200) except Exception: msg = 'Error looking for actinia module "' + actiniamodule + '".' res = (jsonify(SimpleResponseModel(status=404, message=msg))) return make_response(res, 404)
def post(self): log.debug( "Received HTTP POST with process: \n" + json.dumps(request.get_json(force=True), indent=4, sort_keys=True)) try: fullResp = postActiniaCore('test', request.get_json(force=True)) resp = shortenActiniaCoreResp(fullResp) if resp is None or fullResp['status'] == 'error': res = jsonify( SimpleResponseModel(status=500, message="failure")) return make_response(res, 500) else: res = make_response(json.dumps(resp), 200) res.headers['Content-Type'] = 'application/json' return res except Exception: res = jsonify(SimpleResponseModel(status=500, message="failure")) return make_response(res, 500)
def get(self, grassmodule): """Describe a GRASS GIS module. """ try: grass_module = createGrassModule(self, grassmodule) return make_response(jsonify(grass_module), 200) except Exception: res = (jsonify( SimpleResponseModel(status=404, message='Error looking for module "' + grassmodule + '".'))) return make_response(res, 404)
def get(self, tags): try: records = getRecordsByTags(tags) res = make_response(records, 200) res.headers['Content-Type'] = 'application/json' return res except Exception: res = (jsonify( SimpleResponseModel(status=404, message='Error looking for tags "' + tags + '".'))) return make_response(res, 404)
def get(self, uuid): try: record = getRecordByUUID(uuid) # 47e7d99e-b227-4f80-8f4c-8ff1b5016c27 res = make_response(record, 200) res.headers['Content-Type'] = 'application/json' return res except Exception: res = (jsonify( SimpleResponseModel(status=404, message='Error looking for uuid "' + uuid + '".'))) return make_response(res, 404)
def post(self, location_name): """Execute a user defined process chain in an ephemeral location/mapset and store the processing results for download. """ # get grass and actinia module lists module_list = createModuleList(self) pc_list = createProcessChainTemplateList() # TODO: find out size before ? grass_module_list = [] actinia_module_list = [] for module in module_list: grass_module_list.append(module['id']) for module in pc_list: actinia_module_list.append(module['id']) rdc = self.preprocess(has_json=True, location_name=location_name) if rdc: rdc.set_storage_model_to_file() new_pc = [] for module in rdc.request_data['list']: if "module" in module: name = module["module"] if name == "importer" or name == "exporter": new_pc.append(module) elif name in grass_module_list: new_pc.append(module) elif name in actinia_module_list: module_pc = fillTemplateFromProcessChain(module) new_pc.extend(module_pc) else: msg = "Module %s is not of type importer, exporter, grass-module or an actinia-module." % name return make_response( jsonify( SimpleResponseModel(status="error", message=msg)), 409) else: new_pc.append(module) rdc.request_data['list'] = new_pc enqueue_job(self.job_timeout, start_job, rdc) html_code, response_model = pickle.loads(self.response_data) return make_response(jsonify(response_model), html_code)
def get(self, module): """Describe a module. """ try: try: virtual_module = createGrassModule(self, module) except Exception: virtual_module = createActiniaModule(self, module) finally: return make_response(jsonify(virtual_module), 200) except Exception: msg = 'Error looking for module "' + module + '".' res = (jsonify(SimpleResponseModel(status=404, message=msg))) return make_response(res, 404)
def get(self, uuid): try: utcnow = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') gnosresp = update(uuid, utcnow) if gnosresp is None: raise Exception res = make_response(gnosresp.content, 200) return res except Exception as e: log.error('error parsing gnos response') log.error(e) res = (jsonify( SimpleResponseModel(status=404, message='Error looking for uuid "' + uuid + '".'))) return make_response(res, 404)
def get(self, category): try: records = getRecordsByCategory(category) res = make_response(records, 200) res.headers['Content-Type'] = 'application/json' return res # except TemplateNotFound as e: # print('ERROR: ' + repr(e) + " - " + e.message) # return make_response('Error looking for category "' + category + # '".', 404) except Exception as e: log.error('ERROR: ' + repr(e) + " - " + str(e)) res = (jsonify( SimpleResponseModel(status=404, message='Category "' + category + '" not found.'))) return make_response(res, 404)
def post(self): """ Create new job This method is called by HTTP POST @app.route('/processes/test/jobs') This method is calling core method createJob """ log.info("\n Received HTTP POST with job:") print(request.get_json(force=True)) # We determine the process type here, depending on which endpoint # was called process = request.path.split('/')[2] job = createJob(request.get_json(force=True), process) if job is not None: return make_response(jsonify(job), 201) else: res = (jsonify(SimpleResponseModel(status=404, message='Error'))) return make_response(res, 404)
def get(self, jobid): """ Wrapper method to receive HTTP call and pass it to function This method is called by HTTP GET @app.route('/processes/test/jobs/<jobid>') This method is calling core method readJob """ if jobid is None: return make_response("Not found", 404) log.info("\n Received HTTP GET request for job with id " + str(jobid)) job = getJob(jobid) if job is not None: return make_response(jsonify(job), 200) else: res = (jsonify( SimpleResponseModel(status=404, message='Not Found: ' + request.url))) return make_response(res, 404)
def post(self, jobid): """ Wrapper method to cancel a job by using the jobId This method is called by HTTP POST @app.route('/processes/test/jobs/<jobid>/operations/cancel') This method is calling core method readJob """ if jobid is None: return make_response("Not found", 404) log.info("\n Received HTTP POST request for job with id " + str(jobid) + "to cancel the job") job = cancelJob(jobid) if job is not None: return make_response(jsonify(job), 200) else: res = (jsonify( SimpleResponseModel(status=404, message='Not Found: ' + request.url))) return make_response(res, 404)
def post(self): res = jsonify( SimpleResponseModel(status=405, message="Method Not Allowed")) return make_response(res, 405)