Skip to content

Commit

Permalink
Allowed modify to mulesoft deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
dbroker13 committed Sep 2, 2021
1 parent 38b7935 commit 9e23e7a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
9 changes: 8 additions & 1 deletion src/main/resources/mule/modify-app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
54 changes: 39 additions & 15 deletions src/main/resources/mule/mulesoftClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'))
]
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/xl-rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
</steps>
</rule>

<!-- <rule name="Mule.MODIFY" scope="deployed">
<rule name="Mule.MODIFY" scope="deployed">
<conditions>
<type>mule.ApplicationModule</type>
<operation>MODIFY</operation>
</conditions>
<steps>
<jython>
<description>"MODIFY"</description>
<description expression="true">"modify application %s on %s" % (deployed.domain, deployed.container.name)</description>
<script>mule/modify-app.py</script>
<order>50</order>
</jython>
</steps>
</rule> -->
</rule>

<rule name="Mule.UninstallApplicationToServerGroup" scope="deployed">
<conditions>
Expand Down

0 comments on commit 9e23e7a

Please sign in to comment.