def checkConnection(name): """ Method to test connection Args: name (string): resource to test. Can be 'actinia-core' or 'geonetwork' Returns: response (Response): of type SimpleStatusCodeResponseModel 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( SimpleStatusCodeResponseModel(status=200, message="success")) return make_response(res, 200) elif records is None: res = jsonify( SimpleStatusCodeResponseModel(status=404, message="failure")) return make_response(res, 200)
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(SimpleStatusCodeResponseModel( 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(SimpleStatusCodeResponseModel( status=500, message="failure")) return make_response(res, 500)
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( SimpleStatusCodeResponseModel(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(SimpleStatusCodeResponseModel(status=404, message=msg))) return make_response(res, 404)
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( SimpleStatusCodeResponseModel( status=404, message='Error looking for module "' + grassmodule + '".'))) return make_response(res, 404)
def get(self, tags): try: gnosresp = getRecordsByTags(tags) records = makeItJson(gnosresp) res = make_response(records, 200) res.headers['Content-Type'] = 'application/json' return res except Exception: res = (jsonify( SimpleStatusCodeResponseModel( status=404, message='Error looking for tags "' + tags + '".'))) return make_response(res, 404)
def get(self, tags): try: records = getMetaByTags(tags) res_json = json.dumps(records.to_struct()) res = make_response(res_json, 200) res.headers['Content-Type'] = 'application/json' return res except Exception: res = (jsonify( SimpleStatusCodeResponseModel( status=404, message='Error looking for tags "' + tags + '".'))) return make_response(res, 404)
def get(self, uuid): try: record = getMetaByUUID(uuid) # 47e7d99e-b227-4f80-8f4c-8ff1b5016c27 res_json = json.dumps(record.to_struct()) res = make_response(res_json, 200) res.headers['Content-Type'] = 'application/json' return res except Exception: res = (jsonify( SimpleStatusCodeResponseModel( status=404, message='Error looking for uuid "' + uuid + '".'))) return make_response(res, 404)
def get(self, uuid): try: gnosresp = getRecordByUUID(uuid) record = makeItJson(gnosresp) # 47e7d99e-b227-4f80-8f4c-8ff1b5016c27 res = make_response(record, 200) res.headers['Content-Type'] = 'application/json' return res except Exception: res = (jsonify( SimpleStatusCodeResponseModel( status=404, message='Error looking for uuid "' + uuid + '".'))) return make_response(res, 404)
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( SimpleStatusCodeResponseModel(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( SimpleStatusCodeResponseModel( status=404, message='Error looking for uuid "' + uuid + '".'))) return make_response(res, 404)
def get(self, category): try: gnosresp = getRecordsByCategory(category) records = makeItJson(gnosresp) 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( SimpleStatusCodeResponseModel(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( SimpleStatusCodeResponseModel(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( SimpleStatusCodeResponseModel(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( SimpleStatusCodeResponseModel(status=404, message='Not Found: ' + request.url))) return make_response(res, 404)
def post(self): res = jsonify( SimpleStatusCodeResponseModel(status=405, message="Method Not Allowed")) return make_response(res, 405)