Skip to content

Commit 1609842

Browse files
committed
Roles reference
1 parent 735d4f1 commit 1609842

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

doc/reference/configuration/configuration_reference.rst

+123
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,94 @@ This section describes configuration parameters related to roles.
28772877

28782878
**Since:** :doc:`3.0.0 </release/3.0.0>`.
28792879

2880+
Application roles of an instance.
2881+
An application role is a Lua module that implement specific functions or logic.
2882+
2883+
There two types of application roles:
2884+
2885+
- Built-in roles. For example, the `CRUD <https://github.com/tarantool/crud>`__ module provides the ``roles.crud-storage`` and ``roles.crud-router`` roles that enable CRUD operations in a sharded cluster.
2886+
- Custom roles. For example, you create a custom role to define a stored procedure or implement a supplementary service, such as an e-mail notifier or a replicator.
2887+
2888+
To create a custom role, you need to define the following functions and fields:
2889+
2890+
- ``validate()``
2891+
2892+
Validate a role's configuration.
2893+
2894+
- ``apply()``
2895+
2896+
Apply a role's configuration.
2897+
2898+
- ``stop()``:
2899+
2900+
Stop a role.
2901+
2902+
- (Optional) ``dependencies``
2903+
2904+
Define a role's dependencies.
2905+
2906+
Functions should throw an error if it occurs.
2907+
2908+
**Example: Built-in role**
2909+
2910+
The examples below shows how to enable the ``roles.crud-router`` and ``roles.crud-storage`` roles provided by the `CRUD <https://github.com/tarantool/crud>`__ module on routers and storages, respectively:
2911+
2912+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
2913+
:language: yaml
2914+
:start-at: routers
2915+
:end-at: roles.crud-router
2916+
:dedent:
2917+
2918+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
2919+
:language: yaml
2920+
:start-at: storages
2921+
:end-at: roles.crud-storage
2922+
:dedent:
2923+
2924+
You can find the full example here: `sharded_cluster_crud <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud>`_.
2925+
2926+
**Example: Custom role**
2927+
2928+
The configuration below shows how to assign a custom ``greeter`` role to ``instance001`` and specify configuration for this role:
2929+
2930+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/config.yaml
2931+
:language: yaml
2932+
:start-at: instance001
2933+
:end-at: greeting
2934+
:dedent:
2935+
2936+
Then, you need to define the ``validate()``, ``apply()``, and ``stop()`` functions in the role's code as follows:
2937+
2938+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/greeter.lua
2939+
:language: lua
2940+
:dedent:
2941+
2942+
You can find the full example here: `sharded_cluster_crud <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/application_role>`_.
2943+
2944+
**Example: Role dependency**
2945+
2946+
The example below shows how to implement the ``greeter`` role:
2947+
2948+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/greeter.lua
2949+
:language: lua
2950+
:dedent:
2951+
2952+
The ``byeer`` role has a similar implementation but also has the ``dependencies`` field specified:
2953+
2954+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/byeer.lua
2955+
:language: lua
2956+
:dedent:
2957+
2958+
In the configuration, an instance can't have only the ``byeer`` role because it depends on the ``greeter`` role.
2959+
In this example, ``instance001`` has both roles:
2960+
2961+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/config.yaml
2962+
:language: yaml
2963+
:dedent:
2964+
2965+
You can find the full example here: `sharded_cluster_crud <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/application_role>`_.
2966+
2967+
28802968
|
28812969
| Type: array
28822970
| Default: nil
@@ -2889,6 +2977,41 @@ This section describes configuration parameters related to roles.
28892977

28902978
**Since:** :doc:`3.0.0 </release/3.0.0>`.
28912979

2980+
Specify a role's configuration.
2981+
This option accepts a role name as the key and a role's configuration as the value.
2982+
2983+
To specify the roles of an instance, use the :ref:`roles <configuration_reference_roles>` option.
2984+
2985+
**Example: Built-in role**
2986+
2987+
The example below shows how to enable and configure the ``roles.crud-router`` role provided by the `CRUD <https://github.com/tarantool/crud>`__ module:
2988+
2989+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
2990+
:language: yaml
2991+
:start-at: roles.crud-router
2992+
:end-at: stats_quantile_max_age_time
2993+
:dedent:
2994+
2995+
You can find the full example here: `sharded_cluster_crud <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud>`_.
2996+
2997+
**Example: Custom role**
2998+
2999+
The configuration below shows how to assign a custom ``greeter`` role to ``instance001`` and specify configuration for this role:
3000+
3001+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/config.yaml
3002+
:language: yaml
3003+
:start-at: instance001
3004+
:end-at: greeting
3005+
:dedent:
3006+
3007+
Then, you need to define the ``validate()``, ``apply()``, and ``stop()`` functions in the role's code as follows:
3008+
3009+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/greeter.lua
3010+
:language: lua
3011+
:dedent:
3012+
3013+
You can find the full example here: `sharded_cluster_crud <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/application_role>`_.
3014+
28923015
|
28933016
| Type: map
28943017
| Default: nil

0 commit comments

Comments
 (0)