You are here

API.txt in Deploy - Content Staging 7.3

Same filename and directory in other branches
  1. 7.2 API.txt
CONTENTS OF THIS FILE
---------------------

 * API outline
 * Summary of the deployment cycle
 * The plan object
 * The endpoint object
 * The aggregator plugin
 * The processor plugin
 * The service plugin
 * The authenticator plugin

API OUTLINE
-----------

The Deploy module is used to deploy Drupal content to other Drupal sites or
arbritary systems. The definition used here for "content" is Drupal entities.
Thus, entities are the only Drupal object that can be deployed. Other objects
(usually configuration objects), like Views and Panels are preferably deployed
in code with the Features module and a version control system.

The Deploy module depends on the Entity API module, which gives us the
advantage of wrapping more meta data around each entity and makes us able to
handle all entities in one generic way.

A deployment cycle is represented by six types of objects. The two main objects
are:

 * Plans
 * Endpoints

Those two objects are basically configuration and factory objects around the
following plugins, which are all CTools plugins:

 * Aggregators
 * Processors
 * Authenticators
 * Services

The API and the relation between all the objects is built around the dependency
injection pattern as much as possible. Read more about that pattern here:
http://en.wikipedia.org/wiki/Dependency_injection

SUMMARY OF THE DEPLOYMENT CYCLE
-------------------------------

This section is intended to give a brief summary of how the deployment cycle
works. For more in-depth information about each specific object type, please
refer to the later topics in this document.

 0. Deployment of a plan is due. The plan is loaded with 'deploy_plan_load()',
    (1) either from the database or from the default hook.

 1. The plan object is configured through 'deploy_plan_create()' or loaded from
    a default hook. The fully configured plan object is returned to the load
    function which returns it back to the trigger.

 2. The trigger calls the 'deploy' method on the plan object which starts the
    whole deployment cycle.

 3. The plan iterates over its endpoint references and hands them over to the
    processor.

 4. The processor processes each endpoint by requesting all entities from the
    aggregator (5) and hands them over to the endpoint when appropriate (6).
    Between 5 and 6 the processor decides to either process all endpoints and
    entities directly, batch them into smaller pieces or queue the process for
    later.

 5. The aggregator gets called by the processor and aggregates all entities for
    deployment. It passes all the entity types and entity ids into the
    'DeployIterator', which will discover all dependencies. Since 'DeployIterator'
    is recursive, the aggregator passes it into 'DeployIteratorIterator', which
    basically flattens it.

 6. The endpoint is loaded by the processor, with a fully configured
    authenticator plugin. It is also handed a batch of entities for deployment.
    The endpoint wraps all entities with some additional meta data.

 7. The endpoint calls 'deploy' on the authenticator (8) with the batch of
    entities it was handed.

 8. The authenticator gets called and can do its magic. Since the authenticator
    wraps the service object, it has access to modify it or add parameters as
    needed. When it's done it calls 'deploy' on the service (9) with the batch
    of entities it was handed.

 9. The service plugin is handed the batch of entities and deploys them over
    its service.

THE PLAN OBJECT
---------------

One plan consists of one aggregator plugin and one processor plugin and
references to one or many endpoints. This gives us a good representation of
what a plan actually is -- a workflow for aggregating and processing entities
for deployment to one or many endpoints.

When a deployment is triggered for a plan object, that object is responsible
for iterating over its endpoints and processing them with its processor. The
plan's responsibility ends there.

Plans are CTools exportable objects and are instances of the 'DeployPlan'
class. 'DeployPlan' must be fully configured before calling 'deploy()' on it.
See how that is done in its factory function 'deploy_plan_create()'.

Deployment of plans can be triggered in different ways, e.g. manually by an end
user, by a custom Rules event or through a Drush command. More ways of
triggering deployment of a plan can be provided by contrib modules.

THE ENDPOINT OBJECT
-------------------

One endpoint consists of one authenticator plugin and one service plugin. This
gives us a good representation of what an endpoint actually is -- another site
or system accessible through one specific type of service with one specific
type of authentication method.

An endpoint object is handed an iterator of entities and is responsible for
calling its authenticator and handing the entities over to its service. The
endpoint's responsibility ends there.

Endpoints are CTools exportable objects and are instances of the
'DeployEndpoint' class. 'DeployEndpoint' must be fully configured before
'deploy()' is called on it. See how that is done in its factory function
'deploy_endpoint_create()'.

Depending on the processor used in the plan, the endpoint might be handed one
or many entities to deploy.

THE AGGREGATOR PLUGIN
---------------------

The aggregator plugin is responsible for aggregating entities to be processed by
a processor for eventual deployment. The method of aggregation of entities can
vary greatly between plugins. One of the aggregator plugins that come with the
Deploy module aggregates entities using a user defined view. The other, provided
by the Deploy Manager submodule, allows the user to arbitrarily choose items for
deployment, which are then held in a database table.

Aggregator plugins need to implement the 'DeployAggregator' interface. This
interface extends the Standard PHP Library (SPL) inteface 'IteratorAggregate'
which makes the object traversable.

One requirement for implementing the 'IteratorAggregate' inteface is to define a
'getIterator' method which must return an iterator. In this method, the
aggregator will aggregate all its entities and construct a 'DeployIterator'
with the entity types and entity ids. The 'DeployIterator' will then iterate
over all aggregated entities and recursively find all their dependencies. This
means the aggregator does not need to figure out dependencies.

Since the nature of 'DeployIterator' is recursive with all dependencies, and we
want processors to process all entities in a flat way, the 'getIterator' method
needs to return an instance of 'DeployIteratorIterator', which will flatten the
result.

Aggregator plugins are defined by implementing 'hook_deploy_aggregators()'.
See 'deploy_deploy_aggregators()' for more information on what an
implementation should look like.

THE PROCESSOR PLUGIN
--------------------

The processor plugin is responsible for processing all aggregated entities and
handing them over to an endpoint for deployment. The reason processors exist
is that large plans might take a long time to walk through. Processors make it
possible to queue or batch the deployment into smaller operations.

Processor plugins need to implement the 'DeployProcessor' interface and take
a fully configured aggregator object upon construction. When the 'process'
method is called it's handed the name of an endpoint, which it must load, and to
which it must hand off the traversable aggregator (or pieces of it, in the case
of batched or queued deployments).

Processor plugins are defined by implementing 'hook_deploy_processors()'. See
'deploy_deploy_processors()' for more information on what an implementation
should look like.

THE SERVICE PLUGIN
------------------

The service plugin is responsible for doing the actual deployment of one or
many entities to a remote site or arbritary system, through a specific type of
service.

When deployment is due, the service object is handed a traversable iterator of
entities to deploy. Depending on the processor there might be one or many
entities in that iterator.

Service plugins are defined by implementing 'hook_deploy_services()'. See
'deploy_deploy_services()' for more information on what an implementation
should look like.

THE AUTHENTICATOR PLUGIN
------------------------

The authenticator plugin is responsible for authenticating on the endpoint.
Configured in an endpoit, authenticators wrap the service object. This gives
us a good representation of how it actually works -- the 'deploy' method needs
to go through the authenticator.

Authenticators need to implement the 'DeployAuthenticator' interface and take
a fully configured service object upon construction. When deployment is due, the
'deploy' method is called on the authenticator which is where it performs its
authentication magic. After it has successfully authenticated, it needs to call
'deploy' on its service object.

Authenticator plugins are defined by implementing
'hook_deploy_authenticators()'. See 'deploy_deploy_authenticators()' for more
information on what an implementation should look like.

File

API.txt
View source
  1. CONTENTS OF THIS FILE
  2. ---------------------
  3. * API outline
  4. * Summary of the deployment cycle
  5. * The plan object
  6. * The endpoint object
  7. * The aggregator plugin
  8. * The processor plugin
  9. * The service plugin
  10. * The authenticator plugin
  11. API OUTLINE
  12. -----------
  13. The Deploy module is used to deploy Drupal content to other Drupal sites or
  14. arbritary systems. The definition used here for "content" is Drupal entities.
  15. Thus, entities are the only Drupal object that can be deployed. Other objects
  16. (usually configuration objects), like Views and Panels are preferably deployed
  17. in code with the Features module and a version control system.
  18. The Deploy module depends on the Entity API module, which gives us the
  19. advantage of wrapping more meta data around each entity and makes us able to
  20. handle all entities in one generic way.
  21. A deployment cycle is represented by six types of objects. The two main objects
  22. are:
  23. * Plans
  24. * Endpoints
  25. Those two objects are basically configuration and factory objects around the
  26. following plugins, which are all CTools plugins:
  27. * Aggregators
  28. * Processors
  29. * Authenticators
  30. * Services
  31. The API and the relation between all the objects is built around the dependency
  32. injection pattern as much as possible. Read more about that pattern here:
  33. http://en.wikipedia.org/wiki/Dependency_injection
  34. SUMMARY OF THE DEPLOYMENT CYCLE
  35. -------------------------------
  36. This section is intended to give a brief summary of how the deployment cycle
  37. works. For more in-depth information about each specific object type, please
  38. refer to the later topics in this document.
  39. 0. Deployment of a plan is due. The plan is loaded with 'deploy_plan_load()',
  40. (1) either from the database or from the default hook.
  41. 1. The plan object is configured through 'deploy_plan_create()' or loaded from
  42. a default hook. The fully configured plan object is returned to the load
  43. function which returns it back to the trigger.
  44. 2. The trigger calls the 'deploy' method on the plan object which starts the
  45. whole deployment cycle.
  46. 3. The plan iterates over its endpoint references and hands them over to the
  47. processor.
  48. 4. The processor processes each endpoint by requesting all entities from the
  49. aggregator (5) and hands them over to the endpoint when appropriate (6).
  50. Between 5 and 6 the processor decides to either process all endpoints and
  51. entities directly, batch them into smaller pieces or queue the process for
  52. later.
  53. 5. The aggregator gets called by the processor and aggregates all entities for
  54. deployment. It passes all the entity types and entity ids into the
  55. 'DeployIterator', which will discover all dependencies. Since 'DeployIterator'
  56. is recursive, the aggregator passes it into 'DeployIteratorIterator', which
  57. basically flattens it.
  58. 6. The endpoint is loaded by the processor, with a fully configured
  59. authenticator plugin. It is also handed a batch of entities for deployment.
  60. The endpoint wraps all entities with some additional meta data.
  61. 7. The endpoint calls 'deploy' on the authenticator (8) with the batch of
  62. entities it was handed.
  63. 8. The authenticator gets called and can do its magic. Since the authenticator
  64. wraps the service object, it has access to modify it or add parameters as
  65. needed. When it's done it calls 'deploy' on the service (9) with the batch
  66. of entities it was handed.
  67. 9. The service plugin is handed the batch of entities and deploys them over
  68. its service.
  69. THE PLAN OBJECT
  70. ---------------
  71. One plan consists of one aggregator plugin and one processor plugin and
  72. references to one or many endpoints. This gives us a good representation of
  73. what a plan actually is -- a workflow for aggregating and processing entities
  74. for deployment to one or many endpoints.
  75. When a deployment is triggered for a plan object, that object is responsible
  76. for iterating over its endpoints and processing them with its processor. The
  77. plan's responsibility ends there.
  78. Plans are CTools exportable objects and are instances of the 'DeployPlan'
  79. class. 'DeployPlan' must be fully configured before calling 'deploy()' on it.
  80. See how that is done in its factory function 'deploy_plan_create()'.
  81. Deployment of plans can be triggered in different ways, e.g. manually by an end
  82. user, by a custom Rules event or through a Drush command. More ways of
  83. triggering deployment of a plan can be provided by contrib modules.
  84. THE ENDPOINT OBJECT
  85. -------------------
  86. One endpoint consists of one authenticator plugin and one service plugin. This
  87. gives us a good representation of what an endpoint actually is -- another site
  88. or system accessible through one specific type of service with one specific
  89. type of authentication method.
  90. An endpoint object is handed an iterator of entities and is responsible for
  91. calling its authenticator and handing the entities over to its service. The
  92. endpoint's responsibility ends there.
  93. Endpoints are CTools exportable objects and are instances of the
  94. 'DeployEndpoint' class. 'DeployEndpoint' must be fully configured before
  95. 'deploy()' is called on it. See how that is done in its factory function
  96. 'deploy_endpoint_create()'.
  97. Depending on the processor used in the plan, the endpoint might be handed one
  98. or many entities to deploy.
  99. THE AGGREGATOR PLUGIN
  100. ---------------------
  101. The aggregator plugin is responsible for aggregating entities to be processed by
  102. a processor for eventual deployment. The method of aggregation of entities can
  103. vary greatly between plugins. One of the aggregator plugins that come with the
  104. Deploy module aggregates entities using a user defined view. The other, provided
  105. by the Deploy Manager submodule, allows the user to arbitrarily choose items for
  106. deployment, which are then held in a database table.
  107. Aggregator plugins need to implement the 'DeployAggregator' interface. This
  108. interface extends the Standard PHP Library (SPL) inteface 'IteratorAggregate'
  109. which makes the object traversable.
  110. One requirement for implementing the 'IteratorAggregate' inteface is to define a
  111. 'getIterator' method which must return an iterator. In this method, the
  112. aggregator will aggregate all its entities and construct a 'DeployIterator'
  113. with the entity types and entity ids. The 'DeployIterator' will then iterate
  114. over all aggregated entities and recursively find all their dependencies. This
  115. means the aggregator does not need to figure out dependencies.
  116. Since the nature of 'DeployIterator' is recursive with all dependencies, and we
  117. want processors to process all entities in a flat way, the 'getIterator' method
  118. needs to return an instance of 'DeployIteratorIterator', which will flatten the
  119. result.
  120. Aggregator plugins are defined by implementing 'hook_deploy_aggregators()'.
  121. See 'deploy_deploy_aggregators()' for more information on what an
  122. implementation should look like.
  123. THE PROCESSOR PLUGIN
  124. --------------------
  125. The processor plugin is responsible for processing all aggregated entities and
  126. handing them over to an endpoint for deployment. The reason processors exist
  127. is that large plans might take a long time to walk through. Processors make it
  128. possible to queue or batch the deployment into smaller operations.
  129. Processor plugins need to implement the 'DeployProcessor' interface and take
  130. a fully configured aggregator object upon construction. When the 'process'
  131. method is called it's handed the name of an endpoint, which it must load, and to
  132. which it must hand off the traversable aggregator (or pieces of it, in the case
  133. of batched or queued deployments).
  134. Processor plugins are defined by implementing 'hook_deploy_processors()'. See
  135. 'deploy_deploy_processors()' for more information on what an implementation
  136. should look like.
  137. THE SERVICE PLUGIN
  138. ------------------
  139. The service plugin is responsible for doing the actual deployment of one or
  140. many entities to a remote site or arbritary system, through a specific type of
  141. service.
  142. When deployment is due, the service object is handed a traversable iterator of
  143. entities to deploy. Depending on the processor there might be one or many
  144. entities in that iterator.
  145. Service plugins are defined by implementing 'hook_deploy_services()'. See
  146. 'deploy_deploy_services()' for more information on what an implementation
  147. should look like.
  148. THE AUTHENTICATOR PLUGIN
  149. ------------------------
  150. The authenticator plugin is responsible for authenticating on the endpoint.
  151. Configured in an endpoit, authenticators wrap the service object. This gives
  152. us a good representation of how it actually works -- the 'deploy' method needs
  153. to go through the authenticator.
  154. Authenticators need to implement the 'DeployAuthenticator' interface and take
  155. a fully configured service object upon construction. When deployment is due, the
  156. 'deploy' method is called on the authenticator which is where it performs its
  157. authentication magic. After it has successfully authenticated, it needs to call
  158. 'deploy' on its service object.
  159. Authenticator plugins are defined by implementing
  160. 'hook_deploy_authenticators()'. See 'deploy_deploy_authenticators()' for more
  161. information on what an implementation should look like.