configurationengine/doc/plugins/dev-plugin/plugin-interface.rst
author m2lahtel
Tue, 10 Aug 2010 14:29:28 +0300
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
permissions -rw-r--r--
ConE 1.2.11 release
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     1
.. _plugin-howto-plugin-interface:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     2
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     3
Plug-in interface
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     4
=================
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     5
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
     6
Implementation languages
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
     7
------------------------
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
     8
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
     9
A ConE plug-in that adds support for an implementation language has two points
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    10
for interfacing with ConE:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    11
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    12
#. Reader classes that derive from ``cone.public.plugin.ReaderBase`` . These classes
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    13
   define supported Implementation Markup Languages (i.e. supported XML namespaces)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    14
   and other attributes related to them like file extensions. As the name suggests, they are
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    15
   also responsible for reading implementation instances from XML data.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    16
#. Implementation classes that derive from ``cone.public.plugin.ImplBase``. These classes
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    17
   supply the actual run-time functionality of the plug-ins.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
The following UML diagram shows the most important classes and their interdependencies:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
.. image:: plugin_classes.jpg
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    23
For more information on the classes see the
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    24
`ConE API epydoc <../../epydoc/cone.public.plugin-module.html>`_.
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    25
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
ConE generation can be seen to consist of two phases, implementation parsing
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
and output generation:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
Parsing phase:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
- Implementation file list is filtered based on a user-given file name pattern
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
  and supported file extensions
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
- All remaining files are parsed into ``ElementTree`` instances
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
- The ``ElementTree`` instance is scanned for supported ImplML namespaces and
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
  implementation instances are created using the correct reader classes
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
  (the ``read_impl()`` method)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
- All implementations are collected into an ``ImplSet`` instance
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
Generation phase:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
- Implementation instances are further filtered using tags and ConfML references
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
  (the ``has_tag()`` and ``has_ref()`` methods)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
- Implementations instances are divided into separate sets based on their invocation
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
  phases
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
- Output is generated using each implementation set. For each implementation set:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
    - The ``generation_context`` variable of each implementation instance is set
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    48
      (this context contains generation-scope information implementation instances may use)
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
    - The ``generate()`` method of each instance is called
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
    - The ``post_generate()`` method of each instance is called
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
From a plug-in's point of view, the sequence of method calls goes as follows:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
.. image:: plugin_lifecycle.jpg
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
Explanations of the steps in the diagram:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
====== ========================================================================
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
Step   Explanation
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60
====== ========================================================================
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    61
1      ``read_impl()`` is called to create an implementation instance based on
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    62
       XML data.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    63
2      ``read_impl()`` creates the instance.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    64
3-6    Filtering based on ConfML references and implementation tags is done.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    65
       The implementation instance returns True in all cases, so it is included
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    66
       in the actual generation.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    67
7-8    The instance is asked for its invocation phase (here it returns "normal")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    68
9      The implementation instance's ``generation_context`` variable is set, so
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
       then it can be used in the actual generation.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
10-11  Output generation methods are called
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
====== ========================================================================
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    73
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    74
.. _plugin-howto-plugin-interface-validation:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    75
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    76
Validation
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    77
----------
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    78
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    79
.. note::
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    80
    
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    81
    See also :ref:`validation-overview`
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    82
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    83
The ConE plug-in interface allows for the extension of ConfML and ImplML validation.
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    84
In the same way as support for new implementation languages can be provided
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    85
by exposing implementation reader classes via egg entry points, validation
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    86
can be extended by exposing validator classes.
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    87
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    88
Validation happens roughly in the following manner:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    89
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    90
1. A list of *validator classes* is obtained through some means. In practice
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    91
   this usually means finding all validator classes, and then filtering them
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    92
   down to those that produce the problems that we are interested in.
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    93
2. A *validation context* is created. This contains everything associated with
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    94
   the validation, and here all found problems are reported. All validators
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    95
   have access to it.
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    96
3. For each entity (configuration or implementation instance) that is being
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    97
   validated, an instance of each validator class is created and invoked.
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    98
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    99
This process is nearly the same for ConfML and ImplML validation, only some
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   100
details about the validation context and the entities being validated are
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   101
different, as well as the fact ConfML validation on the entire configuration,
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   102
whereas ImplML validation happens on individual implementation instances, with
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   103
a few exceptions.
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   104
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   105
The following diagram illustrates ImplML validation:
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   106
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   107
.. image:: impl-validation-classes.jpg
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   108
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   109
The following diagram illustrates ConfML validation:
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   110
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   111
.. image:: confml-validation-classes.jpg
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   112
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   113
For more information on the classes involved in validate see the
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   114
ConE API epydoc for `cone.validation.implmlvalidation <../../epydoc/cone.validation.implmlvalidation-module.html>`_
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   115
and `cone.validation.confmlvalidation <../../epydoc/cone.validation.confmlvalidation-module.html>`_.
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   116
Also the built-in validators in the package `cone.validation.builtinvalidators <../../epydoc/cone.validation.builtinvalidators-module.html>`_
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   117
can serve as examples.