[3/4] incubator-ariatosca git commit: ARIA-149 Enhance operation configuration
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/84d8da59/extensions/aria_extension_tosca/simple_v1_0/modeling/policies.py -- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/policies.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/policies.py index fba1972..7dd803b 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/policies.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/policies.py @@ -15,6 +15,7 @@ from ..presentation.types import convert_shorthand_to_full_type_name + # # PolicyType # @@ -49,6 +50,7 @@ def get_inherited_targets(context, presentation): return node_types, group_types + # # PolicyTemplate # http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/84d8da59/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py -- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py deleted file mode 100644 index 9c3ea42..000 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py +++ /dev/null @@ -1,202 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - -from aria.utils.collections import merge, deepcopy_with_locators, OrderedDict -from aria.parser.presentation import Value -from aria.parser.validation import Issue - -from .data_types import coerce_value - -# -# ArtifactType, DataType, CapabilityType, RelationshipType, NodeType, GroupType, PolicyType -# - -# Works on properties, parameters, inputs, and attributes -def get_inherited_property_definitions(context, presentation, field_name, for_presentation=None): -""" -Returns our property definitions added on top of those of our parent, if we have one -(recursively). - -Allows overriding all aspects of parent properties except data type. -""" - -# Get definitions from parent -# If we inherit from a primitive, it does not have a parent: -parent = presentation._get_parent(context) if hasattr(presentation, '_get_parent') else None -definitions = get_inherited_property_definitions(context, parent, field_name, - for_presentation=presentation) \ - if parent is not None else OrderedDict() - -# Add/merge our definitions -# If we inherit from a primitive, it does not have our field -our_definitions = getattr(presentation, field_name, None) -if our_definitions: -our_definitions_clone = OrderedDict() -for name, our_definition in our_definitions.iteritems(): -our_definitions_clone[name] = our_definition._clone(for_presentation) -our_definitions = our_definitions_clone -merge_property_definitions(context, presentation, definitions, our_definitions, field_name) - -for definition in definitions.itervalues(): -definition._reset_method_cache() - -return definitions - -# -# NodeTemplate, RelationshipTemplate, GroupTemplate, PolicyTemplate -# - -def get_assigned_and_defined_property_values(context, presentation, field_name='property', - field_name_plural='properties'): -""" -Returns the assigned property values while making sure they are defined in our type. - -The property definition's default value, if available, will be used if we did not assign it. - -Makes sure that required properties indeed end up with a value. -""" - -values = OrderedDict() - -the_type = presentation._get_type(context) -assignments = getattr(presentation, field_name_plural) -get_fn_name = '_get_{0}'.format(field_name_plural) -definitions = getattr(the_type, get_fn_name)(context) if the_type is not None else None - -# Fill in our assignments, but make sure they are defined -if assignments: -for name, value in assignments.iteritems(): -if (definitions is not None) and (name in definitions): -definition = definitions[name] -values[name] =
[3/4] incubator-ariatosca git commit: ARIA-149 Enhance operation configuration
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b1c97e24/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py -- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py deleted file mode 100644 index 9c3ea42..000 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/properties.py +++ /dev/null @@ -1,202 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - -from aria.utils.collections import merge, deepcopy_with_locators, OrderedDict -from aria.parser.presentation import Value -from aria.parser.validation import Issue - -from .data_types import coerce_value - -# -# ArtifactType, DataType, CapabilityType, RelationshipType, NodeType, GroupType, PolicyType -# - -# Works on properties, parameters, inputs, and attributes -def get_inherited_property_definitions(context, presentation, field_name, for_presentation=None): -""" -Returns our property definitions added on top of those of our parent, if we have one -(recursively). - -Allows overriding all aspects of parent properties except data type. -""" - -# Get definitions from parent -# If we inherit from a primitive, it does not have a parent: -parent = presentation._get_parent(context) if hasattr(presentation, '_get_parent') else None -definitions = get_inherited_property_definitions(context, parent, field_name, - for_presentation=presentation) \ - if parent is not None else OrderedDict() - -# Add/merge our definitions -# If we inherit from a primitive, it does not have our field -our_definitions = getattr(presentation, field_name, None) -if our_definitions: -our_definitions_clone = OrderedDict() -for name, our_definition in our_definitions.iteritems(): -our_definitions_clone[name] = our_definition._clone(for_presentation) -our_definitions = our_definitions_clone -merge_property_definitions(context, presentation, definitions, our_definitions, field_name) - -for definition in definitions.itervalues(): -definition._reset_method_cache() - -return definitions - -# -# NodeTemplate, RelationshipTemplate, GroupTemplate, PolicyTemplate -# - -def get_assigned_and_defined_property_values(context, presentation, field_name='property', - field_name_plural='properties'): -""" -Returns the assigned property values while making sure they are defined in our type. - -The property definition's default value, if available, will be used if we did not assign it. - -Makes sure that required properties indeed end up with a value. -""" - -values = OrderedDict() - -the_type = presentation._get_type(context) -assignments = getattr(presentation, field_name_plural) -get_fn_name = '_get_{0}'.format(field_name_plural) -definitions = getattr(the_type, get_fn_name)(context) if the_type is not None else None - -# Fill in our assignments, but make sure they are defined -if assignments: -for name, value in assignments.iteritems(): -if (definitions is not None) and (name in definitions): -definition = definitions[name] -values[name] = coerce_property_value(context, value, definition, value.value) -else: -context.validation.report('assignment to undefined {0} "{1}" in "{2}"' - .format(field_name, name, presentation._fullname), - locator=value._locator, level=Issue.BETWEEN_TYPES) - -# Fill in defaults from the definitions -if definitions: -for name, definition in definitions.iteritems(): -if values.get(name) is None: -values[name] = coerce_property_value(context, presentation, definition, - definition.default) - -validate_required_values(context, presentation, values, definitions) - -