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