ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emblempar...@apache.org
Subject incubator-ariatosca git commit: Plugin policy enabled; store found plugin for spec [Forced Update!]
Date Fri, 14 Apr 2017 17:16:01 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-92-plugin-in-implementation-string 6e807d9ce -> fe5e964dd (forced update)


Plugin policy enabled; store found plugin for spec


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/fe5e964d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/fe5e964d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/fe5e964d

Branch: refs/heads/ARIA-92-plugin-in-implementation-string
Commit: fe5e964dd33cd9e6a7471de46f47f1d7de80c306
Parents: 08ecf43
Author: Tal Liron <tal.liron@gmail.com>
Authored: Fri Apr 14 12:10:01 2017 -0500
Committer: Tal Liron <tal.liron@gmail.com>
Committed: Fri Apr 14 12:15:54 2017 -0500

----------------------------------------------------------------------
 aria/modeling/service_template.py               | 65 ++++++++++++++------
 .../profiles/aria-1.0/aria-1.0.yaml             |  5 +-
 .../simple_v1_0/modeling/__init__.py            |  6 +-
 .../node-cellar/node-cellar.yaml                |  2 +-
 4 files changed, 53 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fe5e964d/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index 6bd92b3..d0e776b 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -293,13 +293,14 @@ class ServiceTemplateBase(TemplateModelMixin):
         context.modeling.instance = service
 
         for plugin_specification in self.plugin_specifications.itervalues():
-            plugin = plugin_specification.find_plugin()
-            if plugin is not None:
-                service.plugins[plugin.name] = plugin
-            elif plugin_specification.required:
-                context = ConsumptionContext.get_thread_local()
-                context.validation.report('plugin not found for specification: {0}'.format(
-                    plugin_specification.name), level=validation.Issue.EXTERNAL)
+            if plugin_specification.enabled:
+                if plugin_specification.resolve():
+                    plugin = plugin_specification.plugin
+                    service.plugins[plugin.name] = plugin
+                else:
+                    context = ConsumptionContext.get_thread_local()
+                    context.validation.report('specified plugin not found: {0}'.format(
+                        plugin_specification.name), level=validation.Issue.EXTERNAL)
 
         utils.instantiate_dict(self, service.meta_data, self.meta_data)
 
@@ -1864,13 +1865,21 @@ class OperationTemplateBase(TemplateModelMixin):
 
     def instantiate(self, container):
         from . import models
-        plugin = self.plugin_specification.find_plugin() \
-            if self.plugin_specification is not None else None
+        if self.plugin_specification and self.plugin_specification.enabled:
+            plugin = self.plugin_specification.plugin
+            implementation = self.implementation if plugin is not None else None
+            # "plugin" would be none if a match was not found. In that case, a validation
error
+            # should already have been reported in ServiceTemplateBase.instantiate, so we
will
+            # continue silently here
+        else:
+            # If the plugin is disabled, the operation should be disabled, too
+            plugin = None
+            implementation = None
         operation = models.Operation(name=self.name,
                                      description=deepcopy_with_locators(self.description),
                                      relationship_edge=self.relationship_edge,
                                      plugin=plugin,
-                                     implementation=self.implementation,
+                                     implementation=implementation,
                                      configuration=self.configuration,
                                      dependencies=self.dependencies,
                                      executor=self.executor,
@@ -2061,14 +2070,19 @@ class PluginSpecificationBase(TemplateModelMixin):
     :vartype name: basestring
     :ivar version: Minimum plugin version
     :vartype version: basestring
+    :ivar enabled: Whether the plugin is enabled
+    :vartype enabled: bool
+    :ivar plugin: The matching plugin (or None if not matched)
+    :vartype plugin: :class:`Plugin`
     """
 
     __tablename__ = 'plugin_specification'
 
-    __private_fields__ = ['service_template_fk']
+    __private_fields__ = ['service_template_fk',
+                          'plugin_fk']
 
     version = Column(Text)
-    required = Column(Boolean, nullable=False, default=True)
+    enabled = Column(Boolean, nullable=False, default=True)
 
     # region foreign keys
 
@@ -2077,27 +2091,39 @@ class PluginSpecificationBase(TemplateModelMixin):
         """For ServiceTemplate one-to-many to PluginSpecification"""
         return relationship.foreign_key('service_template', nullable=True)
 
+    @declared_attr
+    def plugin_fk(cls):
+        """For PluginSpecification many-to-one to Plugin"""
+        return relationship.foreign_key('plugin', nullable=True)
+
     # endregion
 
+    # region many_to_one relationships
+
     @declared_attr
     def service_template(cls):
         return relationship.many_to_one(cls, 'service_template')
 
+    @declared_attr
+    def plugin(cls): # pylint: disable=method-hidden
+        return relationship.many_to_one(cls, 'plugin', back_populates=relationship.NO_BACK_POP)
+
+    # endregion
+
     @property
     def as_raw(self):
         return collections.OrderedDict((
             ('name', self.name),
-            ('version', self.version)))
+            ('version', self.version),
+            ('enabled', self.enabled)))
 
     def coerce_values(self, container, report_issues):
         pass
 
     def instantiate(self, container):
-        from . import models
-        return models.PluginSpecification(name=self.name,
-                                          version=self.version)
+        pass
 
-    def find_plugin(self):
+    def resolve(self):
         # TODO: we are planning a separate "instantiation" module where this will be called
or
         # moved to. There, we will probably have a context with a storage manager. Until
then,
         # this is the only potentially available context, which of course will only be available
@@ -2116,7 +2142,8 @@ class PluginSpecificationBase(TemplateModelMixin):
                 if (plugin.name == self.name) and \
                     ((self.version is None) or (plugin.package_version >= self.version)):
                     matching_plugins.append(plugin)
+        self.plugin = None
         if matching_plugins:
             # Return highest version of plugin
-            return sorted(matching_plugins, key=lambda plugin: plugin.package_version)[-1]
-        return None
+            self.plugin = sorted(matching_plugins, key=lambda plugin: plugin.package_version)[-1]
+        return self.plugin is not None

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fe5e964d/extensions/aria_extension_tosca/profiles/aria-1.0/aria-1.0.yaml
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/profiles/aria-1.0/aria-1.0.yaml b/extensions/aria_extension_tosca/profiles/aria-1.0/aria-1.0.yaml
index a16e4af..0c5e77f 100644
--- a/extensions/aria_extension_tosca/profiles/aria-1.0/aria-1.0.yaml
+++ b/extensions/aria_extension_tosca/profiles/aria-1.0/aria-1.0.yaml
@@ -31,9 +31,10 @@ policy_types:
           Minimum plugin version.
         type: version
         required: false
-      required:
+      enabled:
         description: >-
-          Whether the plugin is required.
+          If the policy is to disable the plugin then it will be ignored and all operations
and
+          workflows depending on it will also be disabled.
         type: boolean
         default: true
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fe5e964d/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
index 7a20a2e..0e9177f 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
@@ -463,13 +463,13 @@ def create_substitution_template_model(context, service_template, substitution_m
 def create_plugin_specification_model(context, policy):
     properties = policy.properties
 
-    def get(name):
+    def get(name, default=None):
         prop = properties.get(name)
-        return prop.value if prop is not None else None
+        return prop.value if prop is not None else default
 
     model = PluginSpecification(name=policy._name,
                                 version=get('version'),
-                                required=get('required'))
+                                enabled=get('enabled', True))
 
     return model
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/fe5e964d/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
----------------------------------------------------------------------
diff --git a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
index e21e1f0..349a166 100644
--- a/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
+++ b/tests/resources/service-templates/tosca-simple-1.0/node-cellar/node-cellar.yaml
@@ -276,7 +276,7 @@ topology_template:
       type: aria.Plugin
       properties:
         version: 1.0
-        required: false
+        enabled: false
 
     maintenance_on:
       type: MaintenanceWorkflow


Mime
View raw message