How to undeploy an application using the XL Deploy REST API

Follow

Cath Tayag -

Apart from adding, modifying, and removing items from XL Deploy repository, you will want to undeploy Deployed Applications. Undeploying an Deployed Application is a task that is composed  of 4 steps , Prepare an undeployment,Create the Deployment task, Start the task and Archive the Executed task

Here, we'll give some examples of how to use XL Deploy's REST API to:

  • Prepare an undeployment
  • Create the deployment task
  • Start a task
  • Archive an executed task

Prepare an undeployment

Use  GET /deployment/prepare/undeploy to prepare an undeployment. Here, we'll prepare an undeployment for a  Deployed Application with ID Environments/myEnv/my-App.

INPUT:

curl -u<username>:<password> -X GET -H "content-type:application/xml" http://<xl-deploy-server>:<xl-deploy-port>/deployit/deployment/prepare/undeploy?deployedApplication=Environments/myEnv/my-App

OUTPUT:

<deployment id="deployment-0aa49c10-03fe-4ee4-8015-222abac3ba55" type="UNDEPLOYMENT">

  <application>

    <udm.DeployedApplication id="Environments/myEnv/my-App" token="384d1559-4aa9-4ae6-9c3e-fd6ab491b866">

      <version ref="Applications/my-App/1.0"/>

      <environment ref="Environments/myEnv/"/>

      <deployeds>

        <ci ref="Infrastructure/localhost/file"/>

      </deployeds>

      <orchestrator>default</orchestrator>

    </udm.DeployedApplication>

  </application>

  <deployeds/>

  <deployables>

    <ci ref="Applications/my-App/1.0/file" type="file.File"/>

  </deployables>

  <containers>

    <ci ref="Infrastructure/localhost" type="overthere.LocalHost"/>

  </containers>

</deployment>

A new Deployment object which contains no deployeds is returned. We need the response to be saved for the next step. Save it in a undeploy.xml file for the need of this example

Create the deployment task

Use  POST /deployment/ to create a deployment task. Here, we'll create an deployment task using the the response of the previous step. .

INPUT:

curl -u<username>:<password> -X POST -H "content-type:application/xml" http://<xl-deploy-server>:<xl-deploy-port>/deployit/deployment/ -d@/tmp/undeploy.xml

OUTPUT:

1327d3b8-40b9-4909-8080-b21e2c32f9a5

A reference to a Task ID that can be executed by the TaskService .

Start a task

Use  POST /task/{taskid}/start to start a task. Here, we'll start a task by using the Task ID from the response in the previous step .

INPUT:

curl -u<username>:<password> -X POST -H "content-type:application/xml" http://<xl-deploy-server>:<xl-deploy-port>/deployit/task/1327d3b8-40b9-4909-8080-b21e2c32f9a5/start

OUTPUT:

none

 

Archive an executed task

And finally, once the previous call,in the previous step has returned, use POST /task/{taskid}/archive to archive the task. Use the same Task ID as in the previous step

INPUT:

curl -u<username>:<password> -X POST -H "content-type:application/xml" http://<xl-deploy-server>:<xl-deploy-port>/deployit/task/1327d3b8-40b9-4909-8080-b21e2c32f9a5/archive/

OUTPUT:

none

 

 

 FOLLOW UP COMMENTS:

After "start a task" above, what would be the exit code of the curl command in case the task has problems in any of the steps? Will archiving an incomplete task (step 4 above) work?

John Fontanilla  5 years ago  
 
Hi John

Thanks for getting in touch!

> Will archiving an incomplete task (step 4 above) work?

Good question - off the top of my head, I'm not quite sure. If it works via the UI, it should also work via the API. Could you try and see whether they kind of "incomplete task" you're looking to archive can be archived through the UI?

> After "start a task" above, what would be the exit code of the curl command in case the task has problems in any of the steps?

With the exception of the "archive" step (i.e. your first question), the other steps do not look at the task status, so the response code of the calls should not change. If you would like to find out about the status of a running task, GET /task/{taskid} seems like the best bet. The GET call itself should succeed, but the TaskState object in the response body should allow you to check the status of the task.

Hope that helps!

Regards

Andrew

Have more questions? Submit a request