Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import time
- import requests
- HOST = "localhost"
- PORT = "10000"
- CDAP_SDK_PATH = "/Users/christopherchoi/Downloads/cdap-sdk-2.5.2"
- HELLO_WORLD_APP = "{0}/examples/{1}/target/{1}-2.5.2.jar".format(CDAP_SDK_PATH, "HelloWorld")
- PURCHASE_APP = "{0}/examples/{1}/target/{1}-2.5.2.jar".format(CDAP_SDK_PATH, "Purchase")
- class ClientRestAPI(object):
- def __init__(self):
- self.base_url = "http://{0}:{1}/v2".format(HOST, PORT)
- def deploy_app(self, jar_path):
- path = self.base_url + "/apps"
- payload = open(jar_path, "rb").read()
- jar_name = os.path.basename(jar_path)
- headers = {"X-Archive-Name": jar_name}
- return requests.post(path, headers=headers, data=payload)
- def undeploy_app(self, app_id):
- p = "apps/" + app_id
- return requests.delete(self.base_url + "/" + p)
- def list_apps(self):
- p = "apps"
- return requests.get(self.base_url + "/" + p)
- def unrecoverable_reset(self):
- path = 'unrecoverable/reset'
- return requests.post(self.base_url + '/' + path)
- class DatasetRestAPI(object):
- def __init__(self):
- self.base_url = "http://{0}:{1}/v2".format(HOST, PORT)
- def delete_all(self):
- p = "data/unrecoverable/datasets"
- return requests.delete(self.base_url + "/" + p)
- if __name__ == "__main__":
- client = ClientRestAPI()
- datasets = DatasetRestAPI()
- os.system(os.path.join(CDAP_SDK_PATH, "bin/cdap.sh") + " start")
- # deploy hello world app
- resp = client.deploy_app(HELLO_WORLD_APP)
- if resp.status_code != 200:
- print "Error deploying [{0}]!".format(HELLO_WORLD_APP)
- print resp.status_code, resp.content
- # deploy purchase app
- resp = client.deploy_app(PURCHASE_APP)
- if resp.status_code != 200:
- print "Error deploying [{0}]!".format(PURCHASE_APP)
- print resp.status_code, resp.content
- time.sleep(2)
- datasets.delete_all()
- client.unrecoverable_reset()
- # deploy hello world app
- resp = client.deploy_app(HELLO_WORLD_APP)
- if resp.status_code != 200:
- print "Error deploying [{0}]!".format(HELLO_WORLD_APP)
- print resp.status_code, resp.content
- # deploy purchase app
- resp = client.deploy_app(PURCHASE_APP)
- if resp.status_code != 200:
- print "Error deploying [{0}]!".format(PURCHASE_APP)
- print resp.status_code, resp.content
- time.sleep(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement