Inter-Service Relations

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:

main.cf
 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 [1] 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 rw+.

delete-validating state

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 Child instance. 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:

  • service_with_delete_validate

  • service_with_deallocation_and_delete_validate

  • simple_with_delete_validate

  • simple_with_deallocation_v2_and_delete_validate

and use following validation states:

  • delete_validating_creating

  • delete_validating_failed

  • delete_validating_up

  • delete_validating_update_failed

To create a custom validation state, create a State with the validate_self attribute set to null.

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.