[ 
https://issues.apache.org/jira/browse/ARIA-118?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16360805#comment-16360805
 ] 

ASF GitHub Bot commented on ARIA-118:
-------------------------------------

djay87 closed pull request #226: ARIA-118 plugin.yaml importing
URL: https://github.com/apache/incubator-ariatosca/pull/226
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/aria/core.py b/aria/core.py
index e3b3b360..d526885d 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -21,6 +21,7 @@
 from .parser import consumption
 from .parser.loading.location import UriLocation
 from .orchestrator import topology
+from .utils import collections
 
 
 class Core(object):
@@ -46,16 +47,17 @@ def plugin_manager(self):
         return self._plugin_manager
 
     def validate_service_template(self, service_template_path):
-        self._parse_service_template(service_template_path)
+        self.parse_service_template(service_template_path)
 
     def create_service_template(self, service_template_path, 
service_template_dir,
                                 service_template_name):
-        context = self._parse_service_template(service_template_path)
+        context = self.parse_service_template(service_template_path)
         service_template = context.modeling.template
         service_template.name = service_template_name
         self.model_storage.service_template.put(service_template)
         self.resource_storage.service_template.upload(
             entry_id=str(service_template.id), source=service_template_dir)
+        return service_template
 
     def delete_service_template(self, service_template_id):
         service_template = 
self.model_storage.service_template.get(service_template_id)
@@ -114,10 +116,12 @@ def delete_service(self, service_id, force=False):
 
         self.model_storage.service.delete(service)
 
-    @staticmethod
-    def _parse_service_template(service_template_path):
+    def parse_service_template(self, service_template_path):
+        plugin_dir = self.plugin_manager._plugins_dir
         context = consumption.ConsumptionContext()
         context.presentation.location = UriLocation(service_template_path)
+        #Add plugin resource storage to import location prefixes
+        context.loading.prefixes = collections.StrictList([plugin_dir])
         # Most of the parser uses the topology package in order to manipulate 
the models.
         # However, here we use the Consumer mechanism, but this should change 
in the future.
         consumption.ConsumerChain(
diff --git a/extensions/aria_extension_tosca/simple_v1_0/presenter.py 
b/extensions/aria_extension_tosca/simple_v1_0/presenter.py
index e84decca..fef30d1d 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/presenter.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/presenter.py
@@ -38,6 +38,8 @@ class ToscaSimplePresenter1_0(Presenter):
     SIMPLE_PROFILE_LOCATION = 'tosca-simple-1.0/tosca-simple-1.0.yaml'
     SPECIAL_IMPORTS = {
         'aria-1.0': 'aria-1.0/aria-1.0.yaml'}
+    PLUGIN_IMPORT_FILE = '/plugin.yaml'
+    PLUGIN_REPOSITORY = 'plugins'
 
     @property
     @cachedmethod
@@ -74,7 +76,12 @@ def _get_import_locations(self, context):
             import_locations.append(self.SIMPLE_PROFILE_LOCATION)
         imports = self._get('service_template', 'imports')
         if imports:
-            import_locations += [self.SPECIAL_IMPORTS.get(i.file, i.file) for 
i in imports]
+            for i in imports:
+                if i.repository == self.PLUGIN_REPOSITORY:
+                    #Add plugin.yaml from plugin resource storage to import 
locations
+                    import_locations += [i.file + self.PLUGIN_IMPORT_FILE]
+                else:
+                    import_locations += [self.SPECIAL_IMPORTS.get(i.file, 
i.file)]
         return FrozenList(import_locations) if import_locations else 
EMPTY_READ_ONLY_LIST
 
     @cachedmethod
diff --git a/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py 
b/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py
index 07a0d9b1..9a023659 100644
--- a/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py
+++ b/tests/extensions/aria_extension_tosca/simple_v1_0/test_imports.py
@@ -16,6 +16,7 @@
 
 import pytest
 
+from tests.helpers import get_resource_uri
 from . import data
 from ....mechanisms.web_server import WebServer
 
@@ -38,6 +39,8 @@
     derived_from: UnknownType
 """
 
+PLUGIN_RESOURCES = "plugins"
+
 @pytest.fixture(scope='session')
 def repository():
     repository = WebServer()
@@ -146,6 +149,21 @@ def test_import_repository(parser, repository):
       type: MyNode
 """, dict(repository=repository)).assert_success()
 
+#Plugin
+
+def test_import_plugin(parser):
+    plugin_dir = get_resource_uri(PLUGIN_RESOURCES)
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+  - aria-1.0
+  - file: import-plugin-1.0.0
+    repository: plugins
+topology_template:
+  node_templates:
+    Network:
+      type: myapp.nodes.Network
+""", plugin_dir=plugin_dir).assert_success()
 
 # Namespace
 
diff --git a/tests/mechanisms/parsing/aria.py b/tests/mechanisms/parsing/aria.py
index 67adcc98..77ea9755 100644
--- a/tests/mechanisms/parsing/aria.py
+++ b/tests/mechanisms/parsing/aria.py
@@ -24,6 +24,7 @@
     ServiceTemplate
 )
 from aria.utils.imports import import_fullname
+from aria.utils import collections
 
 from . import (Parser, Parsed)
 
@@ -32,6 +33,7 @@ class AriaParser(Parser):
     def _parse_literal(self, text, **kwargs):
         context = 
AriaParser.create_context(import_profile=kwargs.get('import_profile', False),
                                             
adhoc_inputs=kwargs.get('adhoc_inputs', True),
+                                            
plugin_dir=kwargs.get('plugin_dir', None),
                                             
validate_normative=kwargs.get('validate_normative',
                                                                           
False))
         context.presentation.location = LiteralLocation(text)
@@ -52,6 +54,7 @@ def 
create_context(loader_source='aria.parser.loading.DefaultLoaderSource',
                        cache=True,
                        import_profile=None,
                        adhoc_inputs=None,
+                       plugin_dir=None,
                        validate_normative=None):
         context = ConsumptionContext()
         context.loading.loader_source = import_fullname(loader_source)()
@@ -66,6 +69,8 @@ def 
create_context(loader_source='aria.parser.loading.DefaultLoaderSource',
             context.presentation.configuration['tosca.adhoc_inputs'] = 
adhoc_inputs
         if validate_normative is not None:
             context.presentation.configuration['validate_normative'] = 
validate_normative
+        if plugin_dir:
+            context.loading.prefixes = collections.StrictList([plugin_dir])
         context.presentation.print_exceptions = debug
         return context
 
diff --git a/tests/resources/plugins/import-plugin-1.0.0/plugin.yaml 
b/tests/resources/plugins/import-plugin-1.0.0/plugin.yaml
new file mode 100644
index 00000000..9f7fe21e
--- /dev/null
+++ b/tests/resources/plugins/import-plugin-1.0.0/plugin.yaml
@@ -0,0 +1,16 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+
+topology_template:
+
+  policies:
+    import-plugin:
+      description: >-
+        plugin to test import of plugin.yaml.
+      type: aria.Plugin
+      properties:
+        version: 1.0.0
+
+node_types:
+
+  myapp.nodes.Network: {}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> plugin.yaml importing
> ---------------------
>
>                 Key: ARIA-118
>                 URL: https://issues.apache.org/jira/browse/ARIA-118
>             Project: AriaTosca
>          Issue Type: Story
>            Reporter: Ran Ziv
>            Assignee: D Jayachandran
>            Priority: Minor
>              Labels: plugins, wishlist
>
> Using a plugin currently requires a user first installs the plugin (using 
> PluginManager), then import the relevant plugin.yaml file in the service 
> template file. The import will currently likely point to a URL, or be a path 
> relative to the service-template yaml file.
> Some ideas for improvement and easing the import;
>  - If a plugin contained its plugin.yaml as part of its wagon archive, then 
> once installed, users could import the yaml file more easily using a notation 
> such as {{plugins/openstack.yaml}} (or perhaps {{openstack.yaml}}, having the 
> import mechanism iterate over plugins looking for this resource file or so)
>  - The import mechanism could look for imports in the resource-storage as 
> well - There could be a directory on the resource-storage designated for 
> storing global yaml files for import, thereby simplifying reuse of yaml 
> imports across service-templates.
>  - Perhaps ARIA should also support importing yaml files by using paths 
> relative to the service-template's package root (as opposed to only looking 
> for paths relative to the current yaml file)? Note that this could lead to 
> ambiguities in some cases.
> Note that the last two don't necessarily have to do with plugins directly, 
> but it's more likely to be relevant for plugins as they're used across 
> service-templates more often.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to