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 test_postActiniaCore(self): with open('tests/resources/postbody.processes.success.json') as file: jsonDict = json.load(file) process = postActiniaCore('test', jsonDict, 'http://127.0.0.1:5000') assert type(process) == dict
def createJob(jsonDict, process): """ Method to parse prePC including fetching information from geonetwork and writing information to Jobtable as well as starting job in actinia-core This method can be called by HTTP POST @app.route('/processes/test/jobs') """ prePC_orig = json.dumps(jsonDict) # TODO: define prePC (pre processchain) model if differs from pc # prePC = prePC(**jsonDict) # as we don't hava a model yet # prePC = json.dumps(jsonDict) connection = checkConnectionWithoutResponse('actinia-core') if connection is not None: actiniaCoreResp = postActiniaCore(process, jsonDict) log.debug(actiniaCoreResp) # try: # prePCDict = prePC.to_struct() # except Exception as e: # log.error('prePC is invalid!') # log.error(e) # return None job = insertNewJob( jsonDict, jsonDict, # as we don't hava a model yet process, jsonDict.get( 'feature_type'), # empty at the moment (polygon later) actiniaCoreResp) if actiniaCoreResp['status'] == 'error': log.error("Error start processing in actinia-core") resourceId = parseActiniaIdFromUrl(actiniaCoreResp['resource_id']) job = updateJob(resourceId, actiniaCoreResp) return job else: return None