We need to start working on some introductory materials for the project and service. We may also need to document our thoughts and design decisions when moving forward. This patch tries to provide a basic layout of the documents. Change-Id: Iad4affead02d605c6fce2720adc85141fd1dc419
4.3 KiB
4.3 KiB
Webhook
A webhook is an URI that encodes a tuple (entity, action, params), where:
- the
entitycan be a cluster, a node, a policy object;actionis the name of a built-in action supported by the object;paramsis a dictionary feeding values as arguments to the action.
Webhooks are used to trigger a specific action on a senlin entity,
typically scaling out/in action on a cluster. In the long term, senlin
may support user-provided actions where action will be
interpreted as the UUID or name of a user-provided action.
Design
Workflow
- User creates a webhook through webhook API. User needs to specify what action and which senlin entity this webhook is bound to. Also for some specific actions, user can define the parameters they want to use when invoking the cluster action API, e.g. the adjustment of scaling operation; User also HAVE TO specify the credential(usually a user_id and its password) explicitly/implicitly. This credential will be used by Senlin service later to execute the real action, e.g. cluster scaling, when webhook is triggered later.
- Senlin service receives the request and does three things:
- Creating a webhook object that contains all necessary information used to trigger specific action of a senlin entity;
- Encrypting the credential information to ensure it won't be hacked and then storing the encrypted password into DB;
- Generating a webhook url with the following format and return it to user:
-
http://{server_ip:port}/v1/{tenant_id}/webhooks/{webhook_id}/trigger?key=$KEY
- User triggers the webhook by sending a post request to its url. No any extra credential is needed here, e.g. curl -i -X 'POST' $WEBHOOK_URL Also user can choose to take some extra parameters for the action execution when triggering the webhook, e.g. curl -i -X 'POST' $WEBHOOK_URL -H 'Content-type: application/json' --data '{"params": {"count": 2}}'
- Webhook middleware of Senlin service handles this post request and decrypt the credential. Then it tries to validate the credential by querying a token based on it from keystone. If succeed, the token will be added to this post request and then send to next middleware in pipeline, usually keystone auth_token. If not, an exception will be raised and this webhook triggering fail.
- Senlin engine receives the webhook triggering request and generates action based on the information stored in webhook object, e.g. obj_type, obj_id and action name;
- Action is dispatched and scheduled by Senlin scheduler to finish the expected operation, e.g. cluster scaling in/out.
Implementation
DB model
A webhook DB object includes the following properties:
- id: the uuid of webhook
- name: the name of webhook (optional)
- user: the id of user who created the webhook
- project: the project id of user who created the webhook.
- domain: the domain of the user who created the webhook
- created_time: time of webhook was created
- deleted_time: time of webhook was deleted
- obj_id: the id of senlin entity(e.g. cluster) that the webhook bound to
- obj_type: the type of senlin entity that the webhook bound to
- action: action(e.g. scalingin, scalingout) of the target the webhook bound to
- credential: credential that will be used to invoke target action API, e.g. clusters/$cluster_id/action when webhook is triggered
- params: parameters that will be included when invoke the target action API, e.g. adjustment of scaling operation