-
Notifications
You must be signed in to change notification settings - Fork 40
Example Usage
Ben Sussman edited this page Mar 7, 2014
·
1 revision
Here is a sample python application using staash that queries a table test-table in database test-db to check if the id columns are in sequence of arithmetic progression with a difference of +1, up to the size specified in the command-line parameters, for the application id specified in the appid.
The 1 time steps are to register the database and the tables, once that is done any app developer needing to access that data can access it with a uniform endpoint as described below compared to doing it via a different client library for different data stores. This makes the life of app developers a lot easier.
Instructions to run this app:
python check.py -h
check.py -a [appId] -n [expectedrange]
- Code Sample
`python check.py -a applicationId -n size`
#!/usr/bin/python
import sys, getopt
import urllib
import json
import numpy as np`
BASE_PATH = "http://hostname:port/staash/v1/"
DB_NAME = "testdb"
TABLE_NAME = "testtable"
FILTER1 = "applicationname"
def healthcheck(appid,esize):
response = urllib.urlopen(BASE_PATH+"data/"+DB_NAME+"/"+TABLE_NAME+"/"+FILTER1+"/"+appid)
json_data = response.read()
data = json.loads(json_data)
listid = []
for x in range(1,int(esize)+1):
listid.append(int(data[""+repr(x)]["Id"]))
sortedids = sorted(listid)
dx = np.diff(sortedids)
f = np.all(dx == 1)
if not f:
print 'appid is "', appid
print 'size is "', esize
print "**************************************************"
print "Order Check FAILED FOR "+FILTER1+"="+appid
print "**************************************************"
print f
print sortedids
print dx
else:
print "**************************************************"
print "Order Check SUCCEEDED FOR "+FILTER1+"="+appid
print "**************************************************"
def main(argv):
appid = ''
esize = ''
try:
opts, args = getopt.getopt(argv,"ha:n:",["appid=","number="])
except getopt.GetoptError:
print 'check2.py -a <appId> -n <expectedrange>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'check2.py -a <appId> -l <location> -n <expectedrange>'
sys.exit()
elif opt in ("-a", "--appid"):
appid = arg
elif opt in ("-n", "--size"):
esize = arg
healthcheck(appid, esize)
if __name__ == "__main__":
main(sys.argv[1:])