In some situations, it might be useful to specify relations between services.
In the model, an inter-service-relation is indicated using a relation with the
lsm::__service__ annotation. One can also specify Attribute modifiers on a relationship.
Consider the following example:
1import lsm 2import lsm::fsm 3 4entity Parent extends lsm::ServiceEntity: 5 """ 6 Definition Parent 7 8 :attr name: The name of the parent 9 """ 10 string name 11end 12 13index Parent(instance_id) 14 15Child.parent_entity  lsm::__service__, lsm::__rwplus__ Parent 16 17entity Child extends lsm::ServiceEntity: 18 """ 19 Definition Child 20 21 :attr name: The name of the child 22 """ 23 string name 24end 25 26index Child(instance_id) 27 28implement Parent using parents 29implement Child using parents 30 31binding_parent = lsm::ServiceEntityBinding( 32service_entity="__config__::Parent", 33lifecycle=lsm::fsm::service_with_delete_validate, 34service_entity_name="parent_service", 35) 36 37binding_child = lsm::ServiceEntityBinding( 38service_entity="__config__::Child", 39lifecycle=lsm::fsm::service_with_delete_validate, 40service_entity_name="child_service", 41)
Here, an inter-service-relation is indicated for service
Child in field
parent_entity with arity
1 and modifier
Using inter-service-relations can introduce some difficulties with deleting of instances. If we consider the previous example,
deleting an instance of a
Parent can make the configuration invalid if the instance is part of an inter-service-relation with a
The solution to deal with this, is to use an intermediate validation state. Some pre-constructed lifecycles also exist in the
lsm module with additional validation states.
Those lifecycles are:
and use following validation states:
To create a custom validation state, create a
State with the
validate_self attribute set to
If the compilation succeeds the deletion is accepted, if it fails, this means we are trying to delete an instance that is still in use in an inter-service relation. Lsm can then accordingly move the state of the service back to the original state or proceed with the delete operation.