Merge lp:~jimbaker/pyjuju/new-hook-semantics-5-docs into lp:pyjuju

Proposed by Jim Baker
Status: Merged
Approved by: Gustavo Niemeyer
Approved revision: 203
Merged at revision: 200
Proposed branch: lp:~jimbaker/pyjuju/new-hook-semantics-5-docs
Merge into: lp:pyjuju
Diff against target: 353 lines (+166/-113)
1 file modified
docs/source/formula.rst (+166/-113)
To merge this branch: bzr merge lp:~jimbaker/pyjuju/new-hook-semantics-5-docs
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Approve
Review via email: mp+57536@code.launchpad.net

Description of the change

This branch updates the description of the hooks so as to update them with respect to the new hook semantic changes. It also copy edits this formula section as a whole. In particular, the copy editing focus was on clarifying how hooks actually execute, and under what conditions. This is to avoid the confusion that prompted the new-hook-semantics- branches in the first place.

To post a comment you must log in.
Revision history for this message
Ahmed Kamal (kim0) wrote :

Typo line-259 says "with with respect"

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :
Download full text (5.8 KiB)

Very good changes overall, thanks Jim.

We'll need another round:

[1]

17 +A formula is deployed as a service, potentially multiple times. Each

This is very open and perhaps even misleading. Please take this specific
sentence off. The rest of the paragraph should give better background.

[2]

+The `metadata.yaml` file, at the root of the formula definition,

s/definition/directory/

[3]

- and `peers` relations (note: that's not yet supported).
(...)
- that the relation is required (note: that's not yet supported).

Please add back both unsupported notes. All documentation which is not
under drafts should reflect what is implemented and may be trusted upon,
or declare explicitly what is not yet in place.

130 + At this time, Ensemble does not enforce the `limit` and
131 + `optional` constraints, but Ensemble will do so in the future.

The note really has to be closer to the explanation. Someone reading about
the field to tweak a formula will not read the whole text to see what is
supported or not.

[4]

188 +changes on its underlying machine, and change its own relation
189 +settings. Changes to relation settings then trigger further events
190 +that hooks can respond to. The following section on hook tools

s/its own relation settings/the relation settings/ (the subject of the
sentence is "the hook").

Also, please drop the sentence starting at "Changes to relation". You're
describing what happens from the perspective of an individual unit. For
an individual unit, changing relation settings will not trigger its own
hooks to execute again.

[5]

194 +the desired hook name under the ``hooks/`` directory of the formula
195 +bundle or directory

s/bundle or directory/directory/

Conceptually, we use the bundle term to reference to a file, so it can't
have directories.

[6]

195 +bundle or directory. Ensemble then executes the hook without command
196 +line arguments when the corresponding event occurs.

Please use this in place of the latter sentence:

  Ensemble will execute the hook based on its file name when the corresponding
  event occurs.

Note that in general we don't have to document the lack of something. If it's
not documented to exist, it's fine to not exist.

[7]

198 +Each hook is optional. Not including a corresponding executable in the

s/Each hook is/All hooks are/

[8]

213 + * **stop** - Runs when the service unit is stopped. This hook will run
214 + after any established relations are broken.

Let's take the chance to fix the pre-existing ambiguity in the latter sentence:

  If relations exist, they will be broken and the respective hooks called before
  this hook is called.

[9]

+ 1. A remote service unit joins the relation.

Let's complement:

    1. A remote service unit joins the relation, right after the
       relation-joined hook was called.

[10]

229 + This hook is the most common hook for a formula to implement. It
230 + enables service units to handshake and otherwise negotiate their
231 + interaction, especially with respect to scaling up and down
232 + service deployments.

This doesn't feel very helpful. It's taking assumptions about how the user
sh...

Read more...

review: Needs Fixing
Revision history for this message
Jim Baker (jimbaker) wrote :

Thanks, I forgot to run my double-word-typo script that I have just for this
case! (Need to integrate that into my push process or maybe the emacs fly
mode support.)

On Thu, Apr 14, 2011 at 8:06 AM, Ahmed Kamal <email address hidden>wrote:

> Typo line-259 says "with with respect"
> --
>
> https://code.launchpad.net/~jimbaker/ensemble/new-hook-semantics-5-docs/+merge/57536<https://code.launchpad.net/%7Ejimbaker/ensemble/new-hook-semantics-5-docs/+merge/57536>
> You are the owner of lp:~jimbaker/ensemble/new-hook-semantics-5-docs.
>

Revision history for this message
Jim Baker (jimbaker) wrote :
Download full text (7.1 KiB)

On Thu, Apr 14, 2011 at 8:59 AM, Gustavo Niemeyer <email address hidden>wrote:

> Review: Needs Fixing
> Very good changes overall, thanks Jim.
>
> We'll need another round:
>
> [1]
>
> 17 +A formula is deployed as a service, potentially multiple times.
> Each
>
> This is very open and perhaps even misleading. Please take this specific
> sentence off. The rest of the paragraph should give better background.
>
>
Reworked intro

>
> [2]
>
> +The `metadata.yaml` file, at the root of the formula definition,
>
> s/definition/directory/
>

Changed

>
>
> [3]
>
> - and `peers` relations (note: that's not yet supported).
> (...)
> - that the relation is required (note: that's not yet supported).
>
> Please add back both unsupported notes. All documentation which is not
> under drafts should reflect what is implemented and may be trusted upon,
> or declare explicitly what is not yet in place.
>
> 130 + At this time, Ensemble does not enforce the `limit` and
> 131 + `optional` constraints, but Ensemble will do so in the
> future.
>
> The note really has to be closer to the explanation. Someone reading about
> the field to tweak a formula will not read the whole text to see what is
> supported or not.
>

Moved description to being closer as suggested

>
>
> [4]
>
> 188 +changes on its underlying machine, and change its own relation
> 189 +settings. Changes to relation settings then trigger further events
> 190 +that hooks can respond to. The following section on hook tools
>
> s/its own relation settings/the relation settings/ (the subject of the
> sentence is "the hook").
>
> Also, please drop the sentence starting at "Changes to relation". You're
> describing what happens from the perspective of an individual unit. For
> an individual unit, changing relation settings will not trigger its own
> hooks to execute again.
>

Fixed

>
>
> [5]
>
> 194 +the desired hook name under the ``hooks/`` directory of the
> formula
> 195 +bundle or directory
>
> s/bundle or directory/directory/
>
> Conceptually, we use the bundle term to reference to a file, so it can't
> have directories.
>

This was from the old text in trunk, so thanks for spotting this so it
doesn't get perpetuated

>
>
> [6]
>
> 195 +bundle or directory. Ensemble then executes the hook without
> command
> 196 +line arguments when the corresponding event occurs.
>
> Please use this in place of the latter sentence:
>
> Ensemble will execute the hook based on its file name when the
> corresponding
> event occurs.
>

Much better

>
> Note that in general we don't have to document the lack of something. If
> it's
> not documented to exist, it's fine to not exist.
>

Ack

>
>
> [7]
>
> 198 +Each hook is optional. Not including a corresponding executable in
> the
>
> s/Each hook is/All hooks are/
>

Changed

>
>
> [8]
>
>
> 213 + * **stop** - Runs when the service unit is stopped. This hook
> will run
> 214 + after any established relations are broken.
>
> Let's take the chance to fix the pre-existing ambiguity in the latter
> sentence:
>
> If relations exist, they will be broken and the respective hooks ca...

Read more...

203. By Jim Baker

Removed intro for incorporation into a future branch

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Thanks, +1 with a small fix for that:

[15]

  Its purpose is to allow the formula to
255 + clean up established state
256 +
257 + The service unit can then clean up any established state.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'docs/source/formula.rst'
--- docs/source/formula.rst 2011-04-08 17:37:35 +0000
+++ docs/source/formula.rst 2011-04-19 15:20:54 +0000
@@ -1,80 +1,86 @@
1
2Formulas1Formulas
3========2========
43
5Introduction4Introduction
6------------5------------
76
8In Ensemble, formulas are the description of how services should7Formulas define how services integrate and how their service units
9behave when deployed and run. A single service definition may be run8react to events in the distributed environment, as orchestrated by
10multiple times with the same formula and configuration, so we call a9Ensemble.
11deployed and running service as a service unit. Each of those units
12will have an independent copy of the same formula guiding its behavior.
1310
14This specification describes how formulas are built and how they11This specification describes how formulas are defined, including their
15react once integrated in an Ensemble environment.12metadata and hooks. It also describes the resources available to hooks
13in working with the Ensemble environment.
1614
1715
18The metadata file16The metadata file
19-----------------17-----------------
2018
21The file named `metadata.yaml`, at the root of the formula, contains19The `metadata.yaml` file, at the root of the formula directory,
22details about the formula.20describes the formula. The following fields are supported:
23
24The following fields are supported:
2521
26 * **name:** - The formula name itself.22 * **name:** - The formula name itself.
2723
28 * **revision:** - A monothonically increasing integer which defines the24 * **revision:** - A monotonically increasing integer which defines
29 formula version.25 the formula version. This number is used to determine if the
3026 formula needs to be updated in the Ensemble environment. It is
31 * **summary:** - A one line description of the formula27 also displayed as output for the ``ensemble status`` command, so
3228 you can ensure you have the right formula deployed.
33 * **description:** - Long explanation about the formula features29
3430 * **summary:** - A one-line description of the formula.
35 * **provides:** - The deployed service unit must have the given relations31
36 established with another service unit whose formula requires them for32 * **description:** - Long explanation of the formula and its
37 the service to work properly. See below for how to define a relation.33 features.
3834
39 * **requires:** - The deployed service unit must have the given relations35 * **provides:** - The deployed service unit must have the given
40 established with another service unit whose formula provides them for36 relations established with another service unit whose formula
41 the service to work properly. See below for how to define a relation.37 requires them for the service to work properly. See below for how
4238 to define a relation.
43 * **peers:** - Relations which are established not in a provides/requires39
44 (or client/server) style, but with P2P semantics. When the formula40 * **requires:** - The deployed service unit must have the given
45 is deployed as a service unit, all the units from the given service41 relations established with another service unit whose formula
46 will automatically be made part of the relation. See below for how to42 provides them for the service to work properly. See below for how
47 define a relation.43 to define a relation.
44
45 * **peers:** - Relations that are established with P2P semantics
46 instead of a provides/requires (or client/server) style. When the
47 formula is deployed as a service unit, all the units from the
48 given service will automatically be made part of the relation.
49 See below for how to define a relation.
4850
4951
50Relations available in `provides`, `requires`, and `peers` are defined52Relations available in `provides`, `requires`, and `peers` are defined
51the following way:53as follows:
5254
53 * **provides|requires|peers:**55 * **provides|requires|peers:**
5456
55 * **<relation name>:** - This is a user-provided value which identifies57 * **<relation name>:** - This name is a user-provided value which
56 this relation uniquely within the given formula. Examples might be58 identifies the relation uniquely within the given formula.
57 "database", or "cache", or "proxy", or "appserver".59 Examples include "database", "cache", "proxy", and "appserver".
5860
59 Each relation may have the following fields defined:61 Each relation may have the following fields defined:
6062
61 * **interface:** - This defines the type of this relation. This63 * **interface:** - This field defines the type of the
62 relation will only be established with service units which64 relation. The relation will only be established with service
63 define a compatible relation with the same interface. Examples65 units that define a compatible relation with the same
64 here might be "http", or "mysql", or "backup-schedule".66 interface. Examples include "http", "mysql", and
67 "backup-schedule".
6568
66 * **limit:** - The maximum number of relations of this kind which69 * **limit:** - The maximum number of relations of this kind
67 may be established to other service units. Defaults to 1 for70 which may be established to other service units. Defaults to
68 `requires` relations, and to "none" (no limit) for `provides`71 1 for `requires` relations, and to "none" (no limit) for
69 and `peers` relations (note: that's not yet supported).72 `provides` and `peers` relations. While you may define it,
73 this field is not yet enforced by Ensemble.
7074
71 * **optional:** - Whether this relation is required for the75 * **optional:** - Whether this relation is required for the
72 service unit to function or not. Defaults to `false`, meaning76 service unit to function or not. Defaults to `false`, which
73 that the relation is required (note: that's not yet supported).77 means the relation is required. While you may define it, this
78 field is not yet enforced by Ensemble.
7479
75 As a shortcut, if these properties are not defined, and instead80 As a shortcut, if these properties are not defined, and instead
76 a single string value is provided next to the relation name,81 a single string value is provided next to the relation name, the
77 the string is taken as the interface value. For example::82 string is taken as the interface value, as seen in this
83 example::
7884
79 requires:85 requires:
80 db: mysql86 db: mysql
@@ -86,88 +92,129 @@
86Hooks92Hooks
87-----93-----
8894
89Hooks are the mechanism through which service units are notified of95Ensemble uses hooks to notify a service unit about changes happening
90events happening around them. Each hook is an executable within the96in its lifecycle or the larger distributed environment. A hook running
91`hooks/` directory of the formula bundle or directory.97for a service unit can query this environment, make any desired local
9298changes on its underlying machine, and change the relation
93Hooks are able to modify the relation settings via command line tools99settings.
94offered by Ensemble. These changes are only perceived by its peers100
95when the hook has finished running successfully. If a hook exits with101Each hook for a formula is implemented by placing an executable with
96a non-zero error code state changes are not committed.102the desired hook name under the ``hooks/`` directory of the formula
97103directory. Ensemble will execute the hook based on its file name when
98Some hooks are named after the formula relation which they want to be104the corresponding event occurs.
99notified about.105
100106All hooks are optional. Not including a corresponding executable in
101The following hooks are currently defined:107the formula is treated by Ensemble as if the hook executed and then
102108exited with an exit code of 0.
103 * **install** - Run just once during the life time of a service unit.109
104110The following hooks are with respect to the lifecycle of a service unit:
105 * **start** - Run when the formula is started. This happens before111
106 any relation hooks are called. The purpose of this hook is to get112 * **install** - Runs just once during the life time of a service
107 the service ready for relations to be established.113 unit. Currently this hook is the right place to ensure any package
108114 dependencies are met. However, in the future Ensemble will use the
109 * **stop** - Run when the formula is stopped. This will run after any115 formula metadata to perform this role instead.
110 established relations are broken.116
111117 * **start** - Runs when the service unit is started. This happens
112 * **<relation name>-relation-established** - This hook is run when a118 before any relation hooks are called. The purpose of this hook is
113 defined relation is established with one or more peers. Any119 to get the service unit ready for relations to be established.
114 actions related to this relation being established should be120
115 performed.121 * **stop** - Runs when the service unit is stopped. If relations
116122 exist, they will be broken and the respective hooks called before
117 An example might be providing via `relation-set` the TCP port of123 this hook is called.
118 an offered XML-RPC service, or perhaps notifying the started web124
119 application that the MySQL database is now available.125The following hooks are called on each service unit as the membership
120126of an established relation changes:
121 * **<relation name>-relation-broken** - This hook is run when a127
122 relation which had at least one other relation hook run for it128 * **<relation name>-relation-joined** - Runs upon each time a remote
123 (successfully or not) is now unavailable. Its purpose is to129 service unit joins the relation.
124 allow the formula to clean up established state.130
125131 * **<relation name>-relation-changed** - Runs upon each time the
126 An example might be cleaning up the configuration changes which132 following events occur:
127 were performed when HAProxy was asked to load-balance for another133
134 1. A remote service unit joins the relation, right after the
135 **<relation name>-relation-joined** hook was called.
136
137 2. A remote service unit changes its relation settings.
138
139 This hook enables the formula to modify the service unit state
140 (configuration, running processes, or anything else) to adapt to
141 the relation settings of remote units.
142
143 An example usage is that HAProxy needs to be aware of web servers
144 as they become available, including details like its IP
145 address. Web server service units can publish their availability
146 by making the appropriate relation settings in the hook that makes
147 the most sense. Assume the HAProxy uses the relation name of
148 ``server``. Then upon that happening, the HAProxy in its
149 ``server-relation-changed hook`` can then change its own
150 configuration as to what is available to be proxied.
151
152 * **<relation name>-relation-departed** - Runs upon each time a
153 remote service unit leaves a relation. This could happen because
154 the service unit has been removed, its service has been destroyed,
155 or the relation between this service and the remote service has
156 been removed.
157
158 An example usage is that HAProxy needs to be aware of web servers
159 when they are no longer available. It can remove each web server
160 its configuration as the corresponding service unit departs the
161 relation.
162
163This relation hook is with respect to the relation itself:
164
165 * **<relation name>-relation-broken** - Runs when a relation which
166 had at least one other relation hook run for it (successfully or
167 not) is now unavailable. Its purpose is to allow the formula to
168 clean up established state
169
170 The service unit can then clean up any established state. An
171 example might be cleaning up the configuration changes which were
172 performed when HAProxy was asked to load-balance for another
128 service unit.173 service unit.
129174
130 * **<name>-relation-changed** - This hook is called when:175Note that the coupling between formulas is defined by which settings
131176are required and made available to them through the relation hooks and
132 1. A new remote service unit joins the relation.177how these settings are used. Those conventions then define what the
133178relation interface really is, and the **interface** name in the
134 2. A remote service unit changes its relation settings.179`metadata.yaml` file is simply a way to refer to them and avoid the
135180attempting of incompatible conversations. Keep that in mind when
136 3. A remote service unit which was part of the relation has181designing your formulas and relations, since it is a good idea to
137 had its relation broken.182allow the implementation of the formula to change and be replaced with
183alternative versions without changing the relation conventions in a
184backwards incompatible way.
138185
139186
140Hook environment187Hook environment
141----------------188----------------
142189
143Hooks can expect to be invoked with a standard environment and190Hooks can expect to be invoked with a standard environment and
144context. The following be included:191context. The following environment variables are set:
145192
146 * `$ENSEMBLE_UNIT_NAME` - The name of the local unit executing,193 * **$ENSEMBLE_UNIT_NAME** - The name of the local unit executing,
147 in the form `<service name>/<unit sequence>`. E.g. myblog/3.194 in the form ``<service name>/<unit sequence>``. E.g. ``myblog/3``.
148195
149Hooks called for relation changes will have the follow additional196Hooks called for relation changes will have the follow additional
150environment variables available to them.197environment variables set:
151198
152 * `$ENSEMBLE_RELATION` - The relation name this hook is running199 * **$ENSEMBLE_RELATION** - The relation name this hook is running
153 for. It's redundant with the hook name, but is necessary for200 for. It's redundant with the hook name, but is necessary for
154 the command line tools to know the current context.201 the command line tools to know the current context.
155202
156 * `$ENSEMBLE_REMOTE_UNIT` - The unit name of the remote unit203 * **$ENSEMBLE_REMOTE_UNIT** - The unit name of the remote unit
157 which has triggered the hook execution.204 which has triggered the hook execution.
158205
159206
160Hook tools207Hook tools
161----------208----------
162209
163To implement their functionality, hooks may leaverage a set of210In implementing their functionality, hooks can leverage a set of
164utilities provided by Ensemble. These utilities enable the hook to211command tools provided by Ensemble. These utilities enable the hook
165collaborate about configuration state, and to inquire about the peers212to collaborate on their relation settings, and to inquire about the
166the service unit has relations with.213peers the service unit has relations with.
167214
168The following command line tools are made available:215The following command line tools are made available:
169216
170 * **relation-get** - Queries a setting from an established relation217 * **relation-get** - Queries a setting from an established relation
171 with one or more service units. This command will read some218 with one or more service units. This command will read some
172 context information from environment variables (e.g.219 context information from environment variables (e.g.
173 $ENSEMBLE_RELATION_NAME).220 $ENSEMBLE_RELATION_NAME).
@@ -210,13 +257,19 @@
210257
211 * **relation-list** - List all service units participating in the258 * **relation-list** - List all service units participating in the
212 established relation. This list excludes the local service unit259 established relation. This list excludes the local service unit
213 which is executing the command. For provides and requires260 which is executing the command. For `provides` and `requires`
214 relation, this will always return a single service unit.261 relations, this command will always return a single service unit.
215262
216 Example::263 Example::
217264
218 MEMBERS=$(relation-list)265 MEMBERS=$(relation-list)
219266
267Changes to relation settings are only committed if the hook exits with
268a non-zero status code. Such changes will then trigger further hook
269execution in the remote unit(s), through the **<relation
270name>-relation-changed** hook. This mechanism enables a general
271communication mechanism for service units to coordinate.
272
220273
221Sample metadata.yaml files274Sample metadata.yaml files
222--------------------------275--------------------------

Subscribers

People subscribed via source and target branches

to status/vote changes: