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 os |
| 19 | import json |
| 20 | import sys |
| 21 | |
| 22 | import requests |
| 23 | from requests import ConnectionError, HTTPError |
| 24 | |
| 25 | def bootstrap(): |
| 26 | asterix_host = "localhost" |
| 27 | asterix_port = 19002 |
| 28 | |
| 29 | # First, let's get the path to this script, we'll need it to configure the demo. |
| 30 | base = os.path.dirname(os.path.realpath(__file__)) |
| 31 | print "Running AdmAQL101 from",base |
| 32 | |
| 33 | # First, we bootstrap our request query |
| 34 | print "Loading TinySocial Dataset..." |
| 35 | query_statement = open("tinysocial/query.txt").read().split("load") |
| 36 | for i in range(1,5): |
| 37 | query_statement[i] = "load" + query_statement[i].replace("FULL_PATH",base + "/tinysocial") |
| 38 | |
| 39 | ddl = { |
| 40 | 'ddl': query_statement[0] |
| 41 | } |
| 42 | |
| 43 | load = { |
| 44 | "statements" : "use dataverse TinySocial; " + "\n".join(query_statement[1:5]) |
| 45 | } |
| 46 | |
| 47 | http_header = { |
| 48 | 'content-type': 'application/json' |
| 49 | } |
| 50 | |
| 51 | # Now we run our query |
| 52 | print "Running query...\n" |
| 53 | |
| 54 | ddl_url = "http://" + asterix_host + ":" + str(asterix_port) + "/ddl" |
| 55 | update_url = "http://" + asterix_host + ":" + str(asterix_port) + "/update" |
| 56 | |
| 57 | try: |
| 58 | requests.get(ddl_url, params=ddl) |
| 59 | response = requests.get(update_url, params=load, headers=http_header) |
| 60 | except (ConnectionError, HTTPError): |
| 61 | print "Encountered connection error; stopping execution" |
| 62 | sys.exit(1) |
| 63 | |
| 64 | return True |