Getting key stakeholder buy-in for changes perceived as risky
DevOps
Organizational leaders must recognize that change is vital for the sur ...
Read MoreThis post is from the XebiaLabs blog and has not been updated since the original publish date.
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.
<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.Type
containers = 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.
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 finishAll the details on the subtasks can be found in the Reports tab under Control Tasks: