Till Westmann | 5b431ca | 2015-10-01 19:16:11 -0700 | [diff] [blame] | 1 | # Licensed to the Apache Software Foundation (ASF) under one |
| 2 | # or more contributor license agreements. See the NOTICE file |
| 3 | # distributed with this work for additional information |
| 4 | # regarding copyright ownership. The ASF licenses this file |
| 5 | # to you under the Apache License, Version 2.0 (the |
| 6 | # "License"); you may not use this file except in compliance |
| 7 | # with the License. You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, |
| 12 | # software distributed under the License is distributed on an |
| 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | # KIND, either express or implied. See the License for the |
| 15 | # specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
genia.likes.science@gmail.com | 6760586 | 2013-10-04 05:43:57 -0700 | [diff] [blame] | 18 | import admaql101 |
| 19 | import requests |
| 20 | from bottle import route, run, template, get, debug, static_file, request, response |
| 21 | |
| 22 | debug(True) |
| 23 | http_header = { "content-type": "application/json" } |
| 24 | |
| 25 | # Core Routing |
| 26 | @route('/') |
| 27 | def jsontest(): |
| 28 | return template('demo') |
| 29 | |
| 30 | @route('/static/<filename:path>') |
| 31 | def send_static(filename): |
| 32 | return static_file(filename, root='static') |
| 33 | |
| 34 | # API Helpers |
| 35 | def build_response(endpoint, data): |
| 36 | api_endpoint = "http://localhost:19002/" + endpoint |
| 37 | response = requests.get(api_endpoint, params=data, headers=http_header) |
| 38 | try: |
| 39 | return response.json(); |
| 40 | except ValueError: |
| 41 | return [] |
| 42 | |
| 43 | # API Endpoints |
| 44 | @route('/query') |
| 45 | def run_asterix_query(): |
| 46 | return (build_response("query", dict(request.query))) |
| 47 | |
| 48 | @route('/query/status') |
| 49 | def run_asterix_query_status(): |
| 50 | return (build_response("query/status", dict(request.query))) |
| 51 | |
| 52 | @route('/query/result') |
| 53 | def run_asterix_query_result(): |
| 54 | return (build_response("query/result", dict(request.query))) |
| 55 | |
| 56 | |
| 57 | @route('/ddl') |
| 58 | def run_asterix_ddl(): |
| 59 | return (build_response("ddl", dict(request.query))) |
| 60 | |
| 61 | @route('/update') |
| 62 | def run_asterix_update(): |
| 63 | return (build_response("update", dict(request.query))) |
| 64 | |
| 65 | res = admaql101.bootstrap() |
| 66 | run(host='localhost', port=8081, debug=True) |