diff --git a/src/main/resources/mule/modify-app.py b/src/main/resources/mule/modify-app.py index 04fd5ed..dd3a5ba 100644 --- a/src/main/resources/mule/modify-app.py +++ b/src/main/resources/mule/modify-app.py @@ -10,7 +10,14 @@ print "Modifying application." client = mulesoftClient.create_client_from_deployed(deployed) domain = str(deployed.domain) -client.modify_package(deployed.file.path, domain) +workers = str(deployed.workers) +Enabled = deployed.monitoringAutoRestart +muleVersion = deployed.MulesoftVersion +numWorkers = deployed.numWorkers +region = deployed.region +appProperties = deployed.appProperties +# print previousDeployed.file +client.modify_package(deployed.file.path, domain, workers, Enabled, muleVersion, numWorkers, region, appProperties) # print "deploy" # client.deploy_package(deployed.file.path) diff --git a/src/main/resources/mule/mulesoftClient.py b/src/main/resources/mule/mulesoftClient.py index 95cb1c2..d17d0f9 100644 --- a/src/main/resources/mule/mulesoftClient.py +++ b/src/main/resources/mule/mulesoftClient.py @@ -50,14 +50,14 @@ def get_token(self): return response['access_token'] def deploy_package(self, file_path, domain, workers, Enabled, muleVersion, numWorkers, region, appProperties): - + workers = json.loads(workers) url = "https://anypoint.mulesoft.com/cloudhub/api/v2/applications" - + prop = {} - for (k,v) in appProperties.items() : + for (k,v) in appProperties.items() : prop[k] = v - + payload = { 'appInfoJson': { "domain": domain, @@ -72,10 +72,10 @@ def deploy_package(self, file_path, domain, workers, Enabled, muleVersion, numWo }, 'autoStart': "true", } - + # Convert inner appInfojson to string payload['appInfoJson']= json.dumps(payload['appInfoJson']) - + files = [ ('file', open(file_path,'rb')) ] @@ -84,7 +84,7 @@ def deploy_package(self, file_path, domain, workers, Enabled, muleVersion, numWo 'x-anypnt-org-id': str(self.OrgId), 'Authorization': 'Bearer %s' % self.token } - + response = requests.request("POST", url, headers=headers, data = payload, files = files) # response = requests.request("POST", url, headers=headers, files=payload) @@ -93,9 +93,9 @@ def deploy_package(self, file_path, domain, workers, Enabled, muleVersion, numWo print response.text raise Exception("Failed to deploy. Server returned %s.\n%s" % (response.status_code, response.reason)) else: - try : + try : responseJson = response.json() - except : + except : print "(Could not decode JSON)" print response.status_code print response.text; @@ -119,19 +119,43 @@ def undeploy_package(self, domain): else: print "Application successfully deleted" - def modify_package(self, file_path, domain): - url = self._url + "/cloudhub/api/v2/applications/%s/files" % domain + def modify_package(self, file_path, domain, workers, Enabled, muleVersion, numWorkers, region, appProperties): + #url = self._url + "/cloudhub/api/v2/applications/%s/files" % domain + url = self._url + ("/cloudhub/api/v2/applications/%s" % domain) # url = "https://anypoint.mulesoft.com/cloudhub/api/v2/applications/%s/files" % domain headers = { 'x-anypnt-env-id': str(self.EnvId), - 'x-anypnt-org-id': str(self.OrgId), 'Authorization': 'Bearer %s' % self.token } - data = {} + + workers = json.loads(workers) + prop = {} + for (k,v) in appProperties.items() : + prop[k] = v + + payload = { + 'appInfoJson': { + "domain": domain, + "muleVersion" : {"version":muleVersion}, #infra + "region" : region, #infra" ca-c1.cloudhub.io"# + "monitoringEnabled": True, + "monitoringAutoRestart" : Enabled, + "workers": {"amount": numWorkers, "type": workers}, + "loggingNgEnabled": True, + "persistentQueues": False, + "properties": prop + }, + 'autoStart': "true", + } + + # Convert inner appInfojson to string + payload['appInfoJson']= json.dumps(payload['appInfoJson']) + + files = [ - ('file', open(file_path,'rb')) + ('file', open(file_path,'rb')) ] - response = requests.request("POST", url, headers=headers, data = data, files = files) + response = requests.request("PUT", url, headers=headers, data = payload, files = files) if response.raise_for_status(): raise Exception("Failed to modify package. Server returned %s.\n%s" % (response.status_code, response.reason)) else: diff --git a/src/main/resources/xl-rules.xml b/src/main/resources/xl-rules.xml index 6dc3036..ab111d9 100644 --- a/src/main/resources/xl-rules.xml +++ b/src/main/resources/xl-rules.xml @@ -23,19 +23,19 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI - +