diff --git a/src/main/resources/synthetic.xml b/src/main/resources/synthetic.xml
index 0145eb1..f4dfbd4 100644
--- a/src/main/resources/synthetic.xml
+++ b/src/main/resources/synthetic.xml
@@ -36,7 +36,20 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/xldeploy/XLDeployClient.py b/src/main/resources/xldeploy/XLDeployClient.py
index b4f05f3..e2b9fc4 100644
--- a/src/main/resources/xldeploy/XLDeployClient.py
+++ b/src/main/resources/xldeploy/XLDeployClient.py
@@ -103,14 +103,25 @@ def invoke_task_and_wait_for_result(self, task_id, polling_interval = 10, number
break
time.sleep(polling_interval)
return status
-
- def deploymentExists(self, deploymentPackage, environment):
- deploymentExistsUrl = "/deployit/deployment/exists?application=%s&environment=%s" % (deploymentPackage.rsplit('/',1)[0],environment)
- # print 'DEBUG: checking deployment exists with url %s \n' % deploymentExistsUrl
- deploymentExists_response = self.http_request.get(deploymentExistsUrl, contentType='application/xml')
- response = deploymentExists_response.getResponse()
+
+ def get_deployment_package(self, deployed_application_id):
+ ci = self.get_ci(deployed_application_id,'json')
+ data = json.loads(ci)
+ return data['version']
+
+
+ def deployment_exists(self, deployment_package, environment):
+ deployment_exists_url = "/deployit/deployment/exists?application=%s&environment=%s" % (deployment_package.rsplit('/',1)[0],environment)
+ # print 'DEBUG: checking deployment exists with url %s \n' % deployment_exists_url
+ deployment_exists_response = self.http_request.get(deployment_exists_url, contentType='application/xml')
+ response = deployment_exists_response.getResponse()
return 'true' in response
-
+
+ def deployment_prepare_undeploy(self, deployed_application_id):
+ deployment_prepare_undeploy_url = "/deployit/deployment/prepare/undeploy?deployedApplication=%s" % (deployed_application_id)
+ deployment_prepare_undeploy_url_response = self.http_request.get(deployment_prepare_undeploy_url, contentType='application/xml')
+ return deployment_prepare_undeploy_url_response.getResponse()
+
def deploymentPrepareUpdate(self, deploymentPackage, environment):
deploymentPrepareUpdateUrl = "/deployit/deployment/prepare/update?version=%s&deployedApplication=%s" % (deploymentPackage, "%s/%s" % (environment, deploymentPackage.rsplit('/',2)[1]))
deploymentPrepareUpdate_response = self.http_request.get(deploymentPrepareUpdateUrl, contentType='application/xml')
@@ -121,7 +132,8 @@ def deploymentPrepareInitial(self, deploymentPackage, environment):
deploymentPrepareInitial_response = self.http_request.get(deploymentPrepareInitialUrl, contentType='application/xml')
return deploymentPrepareInitial_response.getResponse()
- def add_orchestrators(self, root, orchestrators):
+ def add_orchestrators(self, deployment_xml, orchestrators):
+ root = ET.fromstring(deployment_xml)
if orchestrators:
params = root.find(".//orchestrator")
params.clear()
@@ -129,8 +141,10 @@ def add_orchestrators(self, root, orchestrators):
for orch in orchs:
orchestrator = ET.SubElement(params, 'value')
orchestrator.text = orch.strip()
+ return ET.tostring(root)
- def set_deployed_application_properties(self, root, deployed_application_properties):
+ def set_deployed_application_properties(self, deployment_xml, deployed_application_properties):
+ root = ET.fromstring(deployment_xml)
if deployed_application_properties:
deployeds_application_properties_dict = dict(ast.literal_eval(deployed_application_properties))
# print 'DEBUG: deployed application properties dict is %s \n' % deployeds_application_properties_dict
@@ -145,9 +159,11 @@ def set_deployed_application_properties(self, root, deployed_application_propert
# print "DEBUG: Searching for deployed application: %s" % child
pkey_xml = ET.SubElement(child, key)
pkey_xml.text = deployeds_application_properties_dict[key]
+ return ET.tostring(root)
- def set_deployed_properties(self, root, deployed_properties):
+ def set_deployed_properties(self, deployment_xml, deployed_properties):
+ root = ET.fromstring(deployment_xml)
if deployed_properties:
deployeds_properties_dict = dict(ast.literal_eval(deployed_properties))
for key in deployeds_properties_dict:
@@ -163,6 +179,7 @@ def set_deployed_properties(self, root, deployed_properties):
if not pkey_xml:
pkey_xml = ET.SubElement(xlr_tag_deployed, pkey)
pkey_xml.text = deployed_properties_dict[pkey]
+ return ET.tostring(root)
def deployment_prepare_deployeds(self, deployment, orchestrators = None, deployed_application_properties = None, deployed_properties = None):
@@ -172,12 +189,11 @@ def deployment_prepare_deployeds(self, deployment, orchestrators = None, deploye
# print 'DEBUG: Deployment object including mapping is now %s \n' % deployment
deployment_xml = deployment_prepare_deployeds_response.getResponse()
# print 'DEBUG: deployment_xml is ' + deployment_xml
- root = ET.fromstring(deployment_xml)
- self.add_orchestrators(root, orchestrators)
- self.set_deployed_application_properties(root, deployed_application_properties)
+ deployment_xml = self.add_orchestrators(deployment_xml, orchestrators)
+ deployment_xml = self.set_deployed_application_properties(deployment_xml, deployed_application_properties)
# print 'DEBUG: Deployment object after updating orchestrators: %s \n' % ET.tostring(root)
- self.set_deployed_properties(root, deployed_properties)
- return ET.tostring(root)
+ deployment_xml = self.set_deployed_properties(deployment_xml, deployed_properties)
+ return deployment_xml
def get_deployment_task_id(self, deployment):
getDeploymentTaskId = "/deployit/deployment"
@@ -186,22 +202,22 @@ def get_deployment_task_id(self, deployment):
# print 'DEBUG: getDeploymentTaskId response is %s \n' % (deploymentTaskId_response.getResponse())
return deploymentTaskId_response.getResponse()
- def deploymentRollback(self, taskId):
+ def deployment_rollback(self, taskId):
deploymentRollback = "/deployit/deployment/rollback/%s" % taskId
# print 'DEBUG: calling rollback for taskId %s \n' % taskId
deploymentRollback_response = self.http_request.post(deploymentRollback,'',contentType='application/xml')
# print 'DEBUG: received rollback taskId %s \n' % deploymentRollback_response.getResponse()
return deploymentRollback_response.getResponse()
- def archiveTask(self, taskId):
- archiveTask = "/deployit/task/%s/archive" % taskId
- self.http_request.post(archiveTask,'',contentType='application/xml')
+ def archive_task(self, task_id):
+ archive_task = "/deployit/task/%s/archive" % task_id
+ self.http_request.post(archive_task,'',contentType='application/xml')
- def cancelTask(self, taskId):
+ def cancel_task(self, taskId):
cancelTask = "/deployit/task/%s" % taskId
self.http_request.delete(cancelTask, contentType='application/xml')
- def stopTask(self, taskId):
+ def stop_task(self, taskId):
stopTask = "/deployit/task/%s/stop" % taskId
self.http_request.post(stopTask,'',contentType='application/xml')
@@ -214,7 +230,7 @@ def fetch_package(self, fetchURL):
fetchTask = "/deployit/package/fetch"
self.http_request.post(fetchTask, fetchURL, contentType='application/xml')
- def get_latest_package_version(self, application_id, old_implementation = False):
+ def get_latest_package_version(self, application_id):
query_task = "/deployit/repository/query?parent=%s&resultsPerPage=-1" % application_id
query_task_response = self.http_request.get(query_task, contentType='application/xml')
root = ET.fromstring(query_task_response.getResponse())
diff --git a/src/main/resources/xldeploy/controlTask.py b/src/main/resources/xldeploy/controlTask.py
index fd62945..d41089c 100644
--- a/src/main/resources/xldeploy/controlTask.py
+++ b/src/main/resources/xldeploy/controlTask.py
@@ -15,7 +15,7 @@
print 'DEBUG: About to invoke task and wait for response', task_id, '\n'
task_state = xldClient.invoke_task_and_wait_for_result(task_id, pollingInterval, numberOfPollingTrials, continueIfStepFails, numberOfContinueRetrials)
print 'DEBUG: Task state for', task_id, ':', task_state, '\n'
-xldClient.archiveTask(task_id)
+xldClient.archive_task(task_id)
if task_state in ('DONE','EXECUTED'):
sys.exit(0)
sys.exit(1)
diff --git a/src/main/resources/xldeploy/deployTask.py b/src/main/resources/xldeploy/deployTask.py
index cabc227..1f053ca 100644
--- a/src/main/resources/xldeploy/deployTask.py
+++ b/src/main/resources/xldeploy/deployTask.py
@@ -9,7 +9,7 @@
xldClient = XLDeployClientUtil.createXLDeployClient(xldeployServer, username, password)
deployment = None
-if xldClient.deploymentExists(deploymentPackage, environment):
+if xldClient.deployment_exists(deploymentPackage, environment):
print "Upgrading deployment \n"
deployment = xldClient.deploymentPrepareUpdate(deploymentPackage,environment)
else:
@@ -33,18 +33,18 @@
if taskState in ('DONE','EXECUTED'):
print "Deployment ended in %s \n" % taskState
- xldClient.archiveTask(taskId)
+ xldClient.archive_task(taskId)
sys.exit(0)
# rollbackOnError
if rollbackOnError and taskState in ('FAILED', 'STOPPED'):
print "Going to rollback \n"
- xldClient.stopTask(taskId)
- rollBackTaskId = xldClient.deploymentRollback(taskId)
+ xldClient.stop_task(taskId)
+ rollBackTaskId = xldClient.deployment_rollback(taskId)
taskState = xldClient.invoke_task_and_wait_for_result(rollBackTaskId, pollingInterval, numberOfPollingTrials, continueIfStepFails, numberOfContinueRetrials)
- xldClient.archiveTask(rollBackTaskId)
+ xldClient.archive_task(rollBackTaskId)
sys.exit(1)
elif taskState in ('FAILED', 'STOPPED'):
print "Task failed, rollback not enabled. \n"
- xldClient.cancelTask(taskId)
+ xldClient.cancel_task(taskId)
sys.exit(1)
diff --git a/src/main/resources/xldeploy/undeployTask.py b/src/main/resources/xldeploy/undeployTask.py
new file mode 100644
index 0000000..4db6146
--- /dev/null
+++ b/src/main/resources/xldeploy/undeployTask.py
@@ -0,0 +1,52 @@
+#
+# THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
+# FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS.
+#
+
+import sys
+from xldeploy.XLDeployClientUtil import XLDeployClientUtil
+
+xld_client = XLDeployClientUtil.createXLDeployClient(xldeployServer, username, password)
+
+deployment = None
+deployment_package = xld_client.get_deployment_package("%s/%s" % (environment, deployedApplication))
+if xld_client.deployment_exists(deployment_package, environment):
+ print "Undeploying [%s] from environment [%s] \n" % (deployment_package, environment)
+ deployment = xld_client.deployment_prepare_undeploy("%s/%s" % (environment, deployedApplication))
+else:
+ print "No deployed application found [%s] for environment [%s] \n" % (deployedApplication, environment)
+ sys.exit(1)
+
+# Mapping deployables to the target environment
+print "Set orchestrators \n"
+deployment = xld_client.add_orchestrators(deployment, orchestrators)
+
+print "Set Deployed Application Properties \n"
+deployment = xld_client.set_deployed_application_properties(deployment, deployedApplicationProperties)
+
+print "Creating a deployment task \n"
+task_id = xld_client.get_deployment_task_id(deployment)
+
+print "Execute task with id: %s" % task_id
+task_state = xld_client.invoke_task_and_wait_for_result(task_id, pollingInterval, numberOfPollingTrials, continueIfStepFails, numberOfContinueRetrials, failOnPause)
+
+xld_client.display_step_logs(task_id)
+
+if task_state in ('DONE','EXECUTED'):
+ print "Deployment ended in %s \n" % task_state
+ xld_client.archive_task(task_id)
+ sys.exit(0)
+
+# rollbackOnError
+if rollbackOnError and task_state in ('FAILED', 'STOPPED'):
+ print "Going to rollback \n"
+ xld_client.stop_task(task_id)
+ rollback_task_id = xld_client.deployment_rollback(task_id)
+ task_state = xld_client.invoke_task_and_wait_for_result(rollback_task_id, pollingInterval, numberOfPollingTrials, continueIfStepFails, numberOfContinueRetrials)
+ xld_client.archive_task(rollback_task_id)
+ sys.exit(1)
+elif task_state in ('FAILED', 'STOPPED'):
+ print "Task failed, rollback not enabled. \n"
+ xld_client.cancel_task(task_id)
+ sys.exit(1)