We saw in Chapter 40 how individual virtual machines or instances can be retired from their Lifecycle menu button, and we can also retire services in the same way. The service retirement process follows a similar workflow to the VM retirement process, but we have the flexibility to specify per-service retirement state machines if we wish.
When we create a service catalog item, we can optionally specify a retirement entry point (see Figure 41-1).
If we specify our own retirement entry point, then this state machine will be used to retire any services created from this catalog item. If we do not specify our own entry point here, then then the Default retirement state machine will be used.
Service retirement is initiated from the Lifecycle menu on the service details frame (see Figure 41-2).
Clicking on Retire this Service raises a request_service_retire
event that begins a chain of relationships through the datastore:
request_service_retire
→
/System/Event/MiqEvent/POLICY/request_service_retire →
/Service/Retirement/StateMachines/Methods/GetRetirementEntrypoint
GetRetirementEntrypoint runs a method called get_retirement_entry_point that returns the retirement entry point state machine defined when the service catalog item was created (see Figure 41-3). If this is empty, then /Service/Retirement/StateMachines/ServiceRetirement/Default is returned.
A service object has a number of retirement-related methods:
$evm.root['service'].automate_retirement_entrypoint $evm.root['service'].finish_retirement $evm.root['service'].retire_now $evm.root['service'].retire_service_resources $evm.root['service'].retired? $evm.root['service'].retirement_state= $evm.root['service'].retirement_warn= $evm.root['service'].retires_on= $evm.root['service'].start_retirement
and attributes:
$evm.root['service'].retired = nil $evm.root['service'].retirement_last_warn = nil $evm.root['service'].retirement_requester = nil $evm.root['service'].retirement_state = nil $evm.root['service'].retirement_warn = nil $evm.root['service'].retires_on = nil
The Default service retirement state machine is simpler than its VM counterpart (see Figure 41-3).
The StartRetirement instance calls the start_retirement state machine method, which checks whether the service is already in the retired
or retiring
state, and if so it aborts. If the service is in neither of these states, it calls the service’s start_retirement
method, which sets the retirement_state
attribute to retiring
.
The RetireService instance calls the retire_service state machine method, which in turn calls the service object’s retire_service_resources
method. This method calls the retire_now
method of every VM comprising the service, to initiate their retirement. CheckServiceRetired retries the stage until all VMs are retired or deleted.
We have seen in this chapter how the process of retiring a service will also trigger the retirement of its virtual machines. If we are using service hierarchies, however, or services to manage cloud-style workloads as single entities, this might not be our desired behavior.
Fortunately, the service retirement mechanism is flexible enough that we can create per-service retirement state machines that we can customize to suit our individual use cases and workloads.
3.145.103.154