Skip to main content
DevOps Image

This post is from the XebiaLabs blog and has not been updated since the original publish date.

Last Updated Mar 30, 2016 — DevOps Expert

Running Bulk Restarts Through Control Tasks in XL Deploy

DevOps

A question I often get from clients is how certain operational tasks, like restarts of application servers, can be done through XL Deploy. They want XL Deploy to be the 'one stop shop', where deployments and simple operational tasks alike can be started.


  XL Deploy has a concept for that called control tasks. A good resource to start out from is this blog post, which defines a good, generic framework to start out this specific use case. Browse through this blog post before reading on, it's a short and concise read. The following use case was handed to me: I want to execute a restart on an entire tree of Tomcat servers. The application servers are on hosts, and they are split in a folder hierarchy, like this:  repository hierarchy  So in this case, executing the bulk restart on the folder would restart Tomcat servers on host1, host2, host3 and host4, but executing the bulk restart on the subfolder would only restart the Tomcat servers on host1 and host4. Since 'stop' and 'start' are control tasks themselves, it's like having a master control task that starts child control tasks. First, let's start with defining a new control task on folders in XL Deploy. You simply do that by placing a snipplet like this in the synthetic.xml of your plugin (or in the ext/ folder):
<type-modification type="core.Directory"> <method name="bulkRestartTomcat" description="Performs a stop / start task on multiple Tomcat servers" task-description="Performs a stop / start task on multiple Tomcat servers" delegate="jythonScript" script="utils/bulkRestartTomcat.py"> </method> </type-modification>
This tells XL Deploy that on every folder you can execute a control task called 'bulkRestartTomcat' that will invoke a script that runs on the XL Deploy server. We're using a jython script for this control task. The jython delegate runs on the XL Deploy server itself, so you can interact directly with the Jython API. Let's explore how to find the correct servers: by invoking the query method on the repository service (API docs). Here we specify that we want to look for only configuration items (nodes) with type 'tomcat.Server', or in other words, Tomcat servers. The third parameter specifies that we only want to include nodes that are children of the folder the user right clicked on. For the rest we don't have to specify anything.import com.xebialabs.deployit.plugin.api.reflect.Typecontainers = repositoryService.query(Type.valueOf("tomcat.Server"), None, thisCi.id, None, None, None, 0, -1) print "Found Tomcat containers: " + str(containers)  For each of the results, we want to execute the 'stop' control task, and wait for that to finish.tasks = [] for container in containers: tasks.append(run_control_task(container, "stop")) wait_for_tasks_to_finish(tasks)  And once all have been stopped, we want to start them up again.tasks = [] for container in containers: tasks.append(run_control_task(container, "start")) wait_for_tasks_to_finish(tasks)  To find the full source including all the details, click here.  Executed control task  As you can see in this job log, it found three Tomcat servers on the host1 server:  
Found Tomcat containers: [Infrastructure/folder/subfolder/host1/tc1 [tomcat.Server], Infrastructure/folder/subfolder/host1/tc2 [tomcat.Server], Infrastructure/folder/subfolder/host1/tc3 [tomcat.Server]] Executing Control task [stop] for Infrastructure/folder/subfolder/host1/tc1, task id 2617a12a-3e09-4e06-ba1a-dd9f334f36b8 Executing Control task [stop] for Infrastructure/folder/subfolder/host1/tc2, task id 8b6e8125-12fc-42c7-b285-ab7e5b8da050 Executing Control task [stop] for Infrastructure/folder/subfolder/host1/tc3, task id a30e3271-f230-4854-b733-d40dc82d400f Waiting for task 2617a12a-3e09-4e06-ba1a-dd9f334f36b8 to finish Executing Control task [start] for Infrastructure/folder/subfolder/host1/tc1, task id f51d8c13-515c-4b1d-8669-f45c867e2701 Executing Control task [start] for Infrastructure/folder/subfolder/host1/tc2, task id 965bdea6-a662-489c-8369-a4754ad84d33 Executing Control task [start] for Infrastructure/folder/subfolder/host1/tc3, task id a29c6113-634b-400a-8ae9-76bd999ddac7 Waiting for task f51d8c13-515c-4b1d-8669-f45c867e2701 to finish  
All the details on the subtasks can be found in the Reports tab under Control Tasks:  Control task report  As you see it's really easy to satisfy these kind of use cases, and especially with the right API documentation and examples within arm's reach. I've packaged everything into a plugin which can be checked out at this git repository.Important: The code linked to is sample code only that is not officially supported by XebiaLabs. If you have questions, please contact our support team.
Looking for more Tips and Tricks on XL Deploy? Check out our docs site and start learning how to optimize your XL Deploy experience.

More from the Blog

View more
Mar 04, 2021

Getting key stakeholder buy-in for changes perceived as risky

DevOps
Organizational leaders must recognize that change is vital for the sur ...
Read More
Mar 01, 2021

Discover the change management practices that are ripe for optimization

DevOps
Change has become the most important part of modern digital product cr ...
Read More
Feb 22, 2021

Reckoning DevOps’ role in the enterprise value stream

DevOps
If you’re a software or digital solutions company, you may use DevOps ...
Read More
Feb 10, 2021

Customer spotlight: Schneider avoiding bumps in the road with DevOps adoption

DevOps
Everyone wants to deliver software faster and more reliably. Companies ...
Read More
Contact Us