blob: 5776f369d23a35cf89c5b5b709e8bb3918810aeb [file] [log] [blame]
genia.likes.science@gmail.com6d6aa8e2013-07-23 01:23:21 -07001from twisted.internet import reactor
2from twisted.web import static, proxy, server
3
4import os
5import json
6import sys
7import requests
8
9asterix_host = "localhost"
10asterix_port = 19002
11
12# First, let's get the path to this script, we'll need it to configure the demo.
13base = os.path.dirname(os.path.realpath(__file__))
14print "Running Black Cherry from",base
15
16# First, we bootstrap our request query
17print "Preparing DDL..\n"
18query_statement = open("src/data/query.txt").read().split("load")
19query_statement[1] = "load" + query_statement[1].replace("FULL_PATH",base + "/src/data")
20
21ddl = {
22 'ddl': query_statement[0]
23}
24
25load = {
26 "statements" : "use dataverse twitter; " + query_statement[1]
27}
28
29http_header = {
30 'content-type': 'application/json'
31}
32
33print query_statement
34
35# Now we run our query
36print "Running query...\n"
37
38ddl_url = "http://" + asterix_host + ":" + str(asterix_port) + "/ddl"
39update_url = "http://" + asterix_host + ":" + str(asterix_port) + "/update"
40requests.get(ddl_url, params=ddl)
41response = requests.get(update_url, params=load, headers=http_header)
42if (response.status_code != 200):
43 print "Oh no, something went wrong! Could not load dataset. Is Asterix running on this host?"
44 sys.exit()
45
46print "Please open http://localhost:8080/cherry.html"
47
48# Now we obtain the path of this simple python server, and appends src to it (where Black Cherry lives)
49path = os.path.dirname(os.path.realpath(__file__)) + "/src"
50root = static.File(path) # will be served under '/'
51
52# reverse proxy, served under '/asterix', with same endpoints as Asterix REST API
53# http://test.company.com/service1/v1/JsonService -> becomes http://localhost/svc/service1/v1/JsonService
54root.putChild('asterix', proxy.ReverseProxyResource(asterix_host, asterix_port, ''))
55
56# magic
57site = server.Site(root)
58reactor.listenTCP(8080, site)
59reactor.run()