From f258b577fbb70848015f3a5f283c96796ffd7b61 Mon Sep 17 00:00:00 2001 From: Alexander Tivelkov Date: Wed, 28 Sep 2016 21:12:28 +0300 Subject: [PATCH] MetadataAware mixin added to Core Library Added a mixin class 'MetadataAware' which contains logic to retrieve metadata attributes from the object of class which inherits it and from all objects owning this one. Metadata attrbiutes applied to objects which are deeper in the stack ovewrite ones from objects which are higher. The mixin can also validate if the attribute may be applied to the objects of the given resource type; the type is defined by its overridable abstract method 'getResourceType'. This check uses MetadefBrowser class to retrieve the meta definition namespaces of the needed resource type. Instance and CinderVolume classes now inherit this mixin. Change-Id: I43a081fe2a88e666f61de04b8a2789e1b8e96e38 Targets-blueprint: metadata-assignment-and-propagation --- .../Classes/resources/CinderVolume.yaml | 13 +++- .../io.murano/Classes/resources/Instance.yaml | 11 +++- .../Classes/resources/MetadataAware.yaml | 64 +++++++++++++++++++ meta/io.murano/manifest.yaml | 1 + ...metadata-aware-mixin-41777dd8d1802908.yaml | 4 ++ 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 meta/io.murano/Classes/resources/MetadataAware.yaml create mode 100644 releasenotes/notes/metadata-aware-mixin-41777dd8d1802908.yaml diff --git a/meta/io.murano/Classes/resources/CinderVolume.yaml b/meta/io.murano/Classes/resources/CinderVolume.yaml index 919081f55..82520ebf7 100644 --- a/meta/io.murano/Classes/resources/CinderVolume.yaml +++ b/meta/io.murano/Classes/resources/CinderVolume.yaml @@ -13,10 +13,13 @@ Namespaces: std: io.murano =: io.murano.resources + sys: io.murano.system Name: CinderVolume -Extends: Volume +Extends: + - Volume + - MetadataAware Properties: name: @@ -53,6 +56,7 @@ Methods: Body: - $properties: size: $.size + metadata: $this.getMetadata($this.getRegion()) - If: $.availabilityZone != null Then: @@ -86,7 +90,7 @@ Methods: - Return: resources: format('vol-{0}', id($)): - type: 'OS::Cinder::Volume' + type: $this.getResourceType() properties: $properties outputs: format('vol-{0}-id', id($)): @@ -133,3 +137,8 @@ Methods: Body: Return: get_resource: format('vol-{0}', id($)) + + + getResourceType: + Body: + - Return: 'OS::Cinder::Volume' diff --git a/meta/io.murano/Classes/resources/Instance.yaml b/meta/io.murano/Classes/resources/Instance.yaml index 5ba599996..4c05a5774 100644 --- a/meta/io.murano/Classes/resources/Instance.yaml +++ b/meta/io.murano/Classes/resources/Instance.yaml @@ -17,7 +17,9 @@ Namespaces: Name: Instance -Extends: std:CloudResource +Extends: + - std:CloudResource + - MetadataAware Properties: name: @@ -138,6 +140,7 @@ Methods: user_data: $preparedUserData.data user_data_format: $preparedUserData.format key_name: $.keyname + metadata: $this.getMetadata($region) - If: len($.blockDevices) > 0 Then: @@ -149,7 +152,7 @@ Methods: - $template: resources: $.name: - type: 'OS::Nova::Server' + type: $this.getResourceType() properties: $properties outputs: @@ -382,3 +385,7 @@ Methods: Body: Return: get_resource: $.name + + getResourceType: + Body: + - Return: 'OS::Nova::Server' diff --git a/meta/io.murano/Classes/resources/MetadataAware.yaml b/meta/io.murano/Classes/resources/MetadataAware.yaml new file mode 100644 index 000000000..522df5a3f --- /dev/null +++ b/meta/io.murano/Classes/resources/MetadataAware.yaml @@ -0,0 +1,64 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +Namespaces: + =: io.murano.resources + std: io.murano + sys: io.murano.system + +Name: MetadataAware + +Properties: + checkApplicability: + Contract: $.bool().notNull() + Default: true + +Methods: + .init: + Body: + - $this._metadefBrowsers: {} + + getMetadefBrowser: + Arguments: + - region: + Contract: $.class(std:CloudRegion).notNull() + Body: + - $browser: $this._metadefBrowsers.get($region.name) + - If: $browser = null + Then: + - $browser: new(sys:MetadefBrowser, $region) + - $this._metadefBrowsers[$region.name]: $browser + - Return: $browser + + getMetadata: + Arguments: + - region: + Contract: $.class(std:CloudRegion).notNull() + Body: + - $thisMeta: metadata($this) or {} + - $parentsMeta: {} + - $p: $this.find(std:Object) + - While: $p != null + Do: + - $pmeta: metadata($p) or {} + - $pmeta: dict($pmeta.items().where(not $[0] in $parentsMeta.keys())) + - $parentsMeta: $parentsMeta.set($pmeta) + - $p: $p.find(std:Object) + - $resourceType: $this.getResourceType() + - If: $this.checkApplicability and $resourceType + Then: + - $browser: $this.getMetadefBrowser($region) + - $parentsMeta: dict($parentsMeta.items().where($browser.canBeAppliedTo($[0], $resourceType))) + - Return: $parentsMeta.set($thisMeta) + + getResourceType: + diff --git a/meta/io.murano/manifest.yaml b/meta/io.murano/manifest.yaml index 0ae22c5fc..34b1e53ae 100644 --- a/meta/io.murano/manifest.yaml +++ b/meta/io.murano/manifest.yaml @@ -57,6 +57,7 @@ Classes: io.murano.resources.ExistingCinderVolume: resources/ExistingCinderVolume.yaml io.murano.resources.CinderVolumeBackup: resources/CinderVolumeBackup.yaml io.murano.resources.CinderVolumeSnapshot: resources/CinderVolumeSnapshot.yaml + io.murano.resources.MetadataAware: resources/MetadataAware.yaml io.murano.system.Agent: system/Agent.yaml io.murano.system.AgentListener: system/AgentListener.yaml diff --git a/releasenotes/notes/metadata-aware-mixin-41777dd8d1802908.yaml b/releasenotes/notes/metadata-aware-mixin-41777dd8d1802908.yaml new file mode 100644 index 000000000..b8740c68c --- /dev/null +++ b/releasenotes/notes/metadata-aware-mixin-41777dd8d1802908.yaml @@ -0,0 +1,4 @@ +--- +features: + - Added a MetadataAware mixin class capable to retrieve the metadata + attributes from the implementing objects and all its parents.