[1/2] incubator-ariatosca git commit: linted code
Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-44-Merge-parser-and-storage-models e1534cb08 -> 7b4c35130 linted code Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/93d91fca Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/93d91fca Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/93d91fca Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 93d91fca10cc444386748eb5e640d9dcb68d8dd9 Parents: e1534cb Author: mxmrlv Authored: Sun Jan 29 19:20:08 2017 +0200 Committer: mxmrlv Committed: Sun Jan 29 19:20:08 2017 +0200 -- aria/parser/modeling/__init__.py | 2 - aria/parser/modeling/utils.py | 2 +- aria/storage/exceptions.py | 6 ++ aria/storage/modeling/elements.py | 97 - aria/storage/modeling/model.py | 3 +- aria/storage/modeling/structure.py | 97 - aria/storage/modeling/utils.py | 3 +- 7 files changed, 105 insertions(+), 105 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/93d91fca/aria/parser/modeling/__init__.py -- diff --git a/aria/parser/modeling/__init__.py b/aria/parser/modeling/__init__.py index a1efd9f..b8e1286 100644 --- a/aria/parser/modeling/__init__.py +++ b/aria/parser/modeling/__init__.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .exceptions import CannotEvaluateFunctionException from .context import IdType, ModelingContext from .elements import Element, ModelElement, Function, Parameter, Metadata from .instance_elements import (ServiceInstance, Node, Capability, Relationship, Artifact, Group, @@ -27,7 +26,6 @@ from .types import TypeHierarchy, Type, RelationshipType, PolicyType, PolicyTrig from .storage import initialize_storage __all__ = ( -'CannotEvaluateFunctionException', 'IdType', 'ModelingContext', 'Element', http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/93d91fca/aria/parser/modeling/utils.py -- diff --git a/aria/parser/modeling/utils.py b/aria/parser/modeling/utils.py index 906106e..1638604 100644 --- a/aria/parser/modeling/utils.py +++ b/aria/parser/modeling/utils.py @@ -21,7 +21,7 @@ from ...utils.collections import OrderedDict from ...utils.console import puts from ..exceptions import InvalidValueError from ..presentation import Value -from .exceptions import CannotEvaluateFunctionException +from ...storage.exceptions import CannotEvaluateFunctionException # UUID = ShortUUID() # default alphabet is base57, which is alphanumeric without visually ambiguous # characters; ID length is 22 http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/93d91fca/aria/storage/exceptions.py -- diff --git a/aria/storage/exceptions.py b/aria/storage/exceptions.py index f982f63..6b69859 100644 --- a/aria/storage/exceptions.py +++ b/aria/storage/exceptions.py @@ -23,3 +23,9 @@ class StorageError(exceptions.AriaError): General storage exception """ pass + + +class CannotEvaluateFunctionException(exceptions.AriaException): +""" +ARIA modeling exception: cannot evaluate the function at this time. +""" http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/93d91fca/aria/storage/modeling/elements.py -- diff --git a/aria/storage/modeling/elements.py b/aria/storage/modeling/elements.py index caceb78..7dd3230 100644 --- a/aria/storage/modeling/elements.py +++ b/aria/storage/modeling/elements.py @@ -13,20 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from sqlalchemy import ( -Column, -Text, -) - -from aria.utils.collections import OrderedDict -from aria.utils.console import puts - -from .utils import coerce_value -from . import ( -structure, -type, -) - # pylint: disable=no-self-argument, no-member, abstract-method @@ -72,86 +58,3 @@ class ElementBase(object): pass -class ModelElementBase(ElementBase): -""" -Base class for :class:`ServiceModel` elements. - -All model elements can be instantiated into :class:`ServiceInstance` elements. -""" - -def instantiate(self, context, container): -raise NotImplementedError - - -class ParameterBase(ModelElementBase, structure.ModelMixin): -""" -Represents a typed value. - -This class is used by both service model and service instance elem
[2/2] incubator-ariatosca git commit: moved things around
moved things around Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/7b4c3513 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7b4c3513 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7b4c3513 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 7b4c3513036d7ab663d9290dac17f6f8fa47edad Parents: 93d91fc Author: mxmrlv Authored: Sun Jan 29 19:24:44 2017 +0200 Committer: mxmrlv Committed: Sun Jan 29 19:24:44 2017 +0200 -- aria/storage/modeling/elements.py | 90 --- aria/storage/modeling/model.py | 3 +- aria/storage/modeling/structure.py | 122 +++- 3 files changed, 108 insertions(+), 107 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7b4c3513/aria/storage/modeling/elements.py -- diff --git a/aria/storage/modeling/elements.py b/aria/storage/modeling/elements.py index 7dd3230..b58e757 100644 --- a/aria/storage/modeling/elements.py +++ b/aria/storage/modeling/elements.py @@ -13,48 +13,90 @@ # See the License for the specific language governing permissions and # limitations under the License. +from sqlalchemy import ( +Column, +Text +) + +from ...utils.collections import OrderedDict +from ...utils.console import puts +from .utils import coerce_value + +from . import structure +from . import type + # pylint: disable=no-self-argument, no-member, abstract-method -class Function(object): +class ParameterBase(structure.ModelElementBase, structure.ModelMixin): """ -An intrinsic function. +Represents a typed value. -Serves as a placeholder for a value that should eventually be derived -by calling the function. +This class is used by both service model and service instance elements. """ +__tablename__ = 'parameter' +name = Column(Text, nullable=False) +type = Column(Text, nullable=False) + +# Check: value type +value = Column(Text) +description = Column(Text) @property def as_raw(self): -raise NotImplementedError - -def _evaluate(self, context, container): -raise NotImplementedError +return OrderedDict(( +('name', self.name), +('type_name', self.type), +('value', self._coerce_value()), +('description', self.description))) + +# TODO: change name +def _coerce_value(self): +if self.type is None: +return + +if self.type.lower() == 'str': +return str(self.value) +elif self.type.lower() == 'int': +return int(self.value) +elif self.type.lower() == 'bool': +return bool(self.value) +elif self.type.lower() == 'float': +return float(self.value) +else: +raise Exception('No supported type_name was provided') + +def instantiate(self, context, container): +return ParameterBase(self.type, self.value, self.description) -def __deepcopy__(self, memo): -# Circumvent cloning in order to maintain our state -return self +def coerce_values(self, context, container, report_issues): +if self.value is not None: +self.value = coerce_value(context, container, self.value, report_issues) -class ElementBase(object): +class MetadataBase(structure.ModelElementBase, structure.ModelMixin): """ -Base class for :class:`ServiceInstance` elements. +Custom values associated with the deployment template and its plans. -All elements support validation, diagnostic dumping, and representation as -raw data (which can be translated into JSON or YAML) via :code:`as_raw`. +This class is used by both service model and service instance elements. + +Properties: + +* :code:`values`: Dict of custom values """ +values = Column(type.StrictDict(key_cls=basestring)) @property def as_raw(self): -raise NotImplementedError - -def validate(self, context): -pass +return self.values -def coerce_values(self, context, container, report_issues): -pass +def instantiate(self, context, container): +metadata = MetadataBase() +metadata.values.update(self.values) +return metadata def dump(self, context): -pass - - +puts('Metadata:') +with context.style.indent: +for name, value in self.values.iteritems(): +puts('%s: %s' % (name, context.style.meta(value))) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7b4c3513/aria/storage/modeling/model.py -
incubator-ariatosca git commit: linted code
Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-44-Merge-parser-and-storage-models 362dd6b1e -> e1534cb08 linted code Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e1534cb0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e1534cb0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e1534cb0 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: e1534cb08c0003ec0d28ef764c3bc219fc0ee001 Parents: 362dd6b Author: mxmrlv Authored: Sun Jan 29 18:57:32 2017 +0200 Committer: mxmrlv Committed: Sun Jan 29 18:57:32 2017 +0200 -- aria/orchestrator/runner.py | 5 - aria/orchestrator/workflows/api/task.py | 10 +- aria/orchestrator/workflows/executor/process.py | 3 --- aria/parser/modeling/__init__.py| 2 +- aria/parser/modeling/storage.py | 2 +- 5 files changed, 15 insertions(+), 7 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e1534cb0/aria/orchestrator/runner.py -- diff --git a/aria/orchestrator/runner.py b/aria/orchestrator/runner.py index c0a303e..57e0f83 100644 --- a/aria/orchestrator/runner.py +++ b/aria/orchestrator/runner.py @@ -75,7 +75,10 @@ class Runner(object): finally: self.cleanup() -def create_workflow_context(self, workflow_name, service_instance_id, initialize_model_storage_fn): +def create_workflow_context(self, +workflow_name, +service_instance_id, +initialize_model_storage_fn): model_storage = self.create_sqlite_model_storage() initialize_model_storage_fn(model_storage) resource_storage = self.create_fs_resource_storage() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e1534cb0/aria/orchestrator/workflows/api/task.py -- diff --git a/aria/orchestrator/workflows/api/task.py b/aria/orchestrator/workflows/api/task.py index 546cfde..50fe6a9 100644 --- a/aria/orchestrator/workflows/api/task.py +++ b/aria/orchestrator/workflows/api/task.py @@ -188,7 +188,15 @@ class OperationTask(BaseTask): **kwargs) @classmethod -def _instance(cls, instance, name, operation_template, inputs, plugins, runs_on, *args, **kwargs): +def _instance(cls, + instance, + name, + operation_template, + inputs, + plugins, + runs_on, + *args, + **kwargs): matching_plugins = [p for p in plugins if p['name'] == operation_template.plugin] # All matching plugins should have identical package_name/package_version, so it's safe to # take the first found. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e1534cb0/aria/orchestrator/workflows/executor/process.py -- diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py index 6798854..96e6b46 100644 --- a/aria/orchestrator/workflows/executor/process.py +++ b/aria/orchestrator/workflows/executor/process.py @@ -304,9 +304,6 @@ def _patch_session(ctx, messenger, instrument): def _main(): -# import pydevd -# pydevd.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True, suspend=False) - arguments_json_path = sys.argv[1] with open(arguments_json_path) as f: arguments = jsonpickle.loads(f.read()) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e1534cb0/aria/parser/modeling/__init__.py -- diff --git a/aria/parser/modeling/__init__.py b/aria/parser/modeling/__init__.py index 2c4122d..a1efd9f 100644 --- a/aria/parser/modeling/__init__.py +++ b/aria/parser/modeling/__init__.py @@ -24,7 +24,7 @@ from .model_elements import (ServiceModel, NodeTemplate, RequirementTemplate, Ca GroupPolicyTemplate, GroupPolicyTriggerTemplate, MappingTemplate, SubstitutionTemplate, InterfaceTemplate, OperationTemplate) from .types import TypeHierarchy, Type, RelationshipType, PolicyType, PolicyTriggerType -# from .storage import initialize_storage +from .storage import initialize_storage __all__ = ( 'CannotEvaluateFunctionException', http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e1534cb0/aria/parser/modeling/storage.py -
incubator-ariatosca git commit: linted tests
Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-44-Merge-parser-and-storage-models 68a818823 -> 362dd6b1e linted tests Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/362dd6b1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/362dd6b1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/362dd6b1 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 362dd6b1eddc0ad44c4d969e08078c1910f36141 Parents: 68a8188 Author: mxmrlv Authored: Sun Jan 29 17:15:05 2017 +0200 Committer: mxmrlv Committed: Sun Jan 29 17:15:05 2017 +0200 -- tests/mock/topology.py| 15 +++ tests/orchestrator/context/test_operation.py | 4 ++-- tests/orchestrator/workflows/api/test_task.py | 1 - 3 files changed, 9 insertions(+), 11 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/362dd6b1/tests/mock/topology.py -- diff --git a/tests/mock/topology.py b/tests/mock/topology.py index 304b9a0..67d1378 100644 --- a/tests/mock/topology.py +++ b/tests/mock/topology.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime - from aria.storage import model from . import models @@ -29,12 +27,13 @@ def create_simple_topology_single_node(model_storage, create_operation): node_template = models.get_dependency_node(service_instance) node_template.interface_templates = [models.get_interface_template( -'tosca.interfaces.node.lifecycle.Standard.create', -operation_kwargs=dict(implementation=create_operation, - inputs=[model.Parameter(name='key', value='create', type='str'), - model.Parameter(name='value', value=True, type='bool')] - ) -)] +'tosca.interfaces.node.lifecycle.Standard.create', +operation_kwargs=dict( +implementation=create_operation, +inputs=[model.Parameter(name='key', value='create', type='str'), +model.Parameter(name='value', value=True, type='bool')] +) +)] model_storage.node_template.put(node_template) node = models.get_dependency_node_instance(node_template, service_instance) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/362dd6b1/tests/orchestrator/context/test_operation.py -- diff --git a/tests/orchestrator/context/test_operation.py b/tests/orchestrator/context/test_operation.py index 15b056a..7706db3 100644 --- a/tests/orchestrator/context/test_operation.py +++ b/tests/orchestrator/context/test_operation.py @@ -83,7 +83,7 @@ def test_node_operation_task_execution(ctx, executor): # Task bases assertions assert operation_context.task.actor == node assert operation_context.task.name == op_name(node, operation_name) -operations = interface.operations.filter_by(name=operation_name) +operations = interface.operations.filter_by(name=operation_name) # pylint: disable=no-member assert operations.count() == 1 assert operation_context.task.implementation == operations[0].implementation assert operation_context.task.inputs == inputs @@ -126,7 +126,7 @@ def test_relationship_operation_task_execution(ctx, executor): # Task bases assertions assert operation_context.task.actor == relationship assert operation_context.task.name.startswith(operation_name) -operation = interface.operations.filter_by(name=operation_name) +operation = interface.operations.filter_by(name=operation_name) # pylint: disable=no-member assert operation_context.task.implementation == operation.all()[0].implementation assert operation_context.task.inputs == inputs http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/362dd6b1/tests/orchestrator/workflows/api/test_task.py -- diff --git a/tests/orchestrator/workflows/api/test_task.py b/tests/orchestrator/workflows/api/test_task.py index cc25988..cddacfe 100644 --- a/tests/orchestrator/workflows/api/test_task.py +++ b/tests/orchestrator/workflows/api/test_task.py @@ -16,7 +16,6 @@ import pytest -from aria.storage import model from aria.orchestrator import context from aria.orchestrator.workflows import api from aria.storage.modeling import model
[2/5] incubator-ariatosca git commit: ARIA-44-Merge-parser-and-storage-models
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68a81882/tests/mock/models.py -- diff --git a/tests/mock/models.py b/tests/mock/models.py index 8229038..e735230 100644 --- a/tests/mock/models.py +++ b/tests/mock/models.py @@ -15,8 +15,7 @@ from datetime import datetime -from aria.storage import model - +from aria.storage.modeling import model from . import operations DEPLOYMENT_NAME = 'test_deployment_id' @@ -35,84 +34,78 @@ RELATIONSHIP_INSTANCE_NAME = 'relationship_instance' def get_dependency_node(deployment): -return model.Node( +return model.NodeTemplate( name=DEPENDENCY_NODE_NAME, -type='test_node_type', +type_name='test_node_type', type_hierarchy=[], -number_of_instances=1, -planned_number_of_instances=1, -deploy_number_of_instances=1, -properties={}, -operations=dict((key, {}) for key in operations.NODE_OPERATIONS), -min_number_of_instances=1, -max_number_of_instances=1, -deployment_fk=deployment.id +default_instances=1, +min_instances=1, +max_instances=1, +service_template=deployment.service_template, ) -def get_dependency_node_instance(dependency_node): -return model.NodeInstance( +def get_dependency_node_instance(dependency_node, deployment): +return model.Node( name=DEPENDENCY_NODE_INSTANCE_NAME, +service_instance=deployment, runtime_properties={'ip': '1.1.1.1'}, version=None, -node_fk=dependency_node.id, +node_template=dependency_node, state='', scaling_groups=[] ) -def get_relationship(source=None, target=None): -return model.Relationship( -source_node_fk=source.id, -target_node_fk=target.id, -source_interfaces={}, -source_operations=dict((key, {}) for key in operations.RELATIONSHIP_OPERATIONS), -target_interfaces={}, -target_operations=dict((key, {}) for key in operations.RELATIONSHIP_OPERATIONS), -type='rel_type', -type_hierarchy=[], -properties={}, -) +def get_relationship(target): +requirement_template = model.RequirementTemplate(target_node_template_name=target.name) +capability_template = model.CapabilityTemplate() + +return requirement_template, capability_template -def get_relationship_instance(source_instance, target_instance, relationship): -return model.RelationshipInstance( -relationship_fk=relationship.id, -target_node_instance_fk=target_instance.id, -source_node_instance_fk=source_instance.id, +def get_relationship_instance(source_instance, target_instance): +return model.Relationship( +target_node=target_instance, +source_node=source_instance, ) -def get_dependent_node(deployment): -return model.Node( +def get_dependent_node(deployment, requirement_template, capability_template): +operation_templates = [model.OperationTemplate(implementation=op, + service_template=deployment.service_template) + for op in operations.NODE_OPERATIONS] +interface_template = model.InterfaceTemplate(operation_templates=operation_templates) + +return model.NodeTemplate( name=DEPENDENT_NODE_NAME, -deployment_fk=deployment.id, -type='test_node_type', +type_name='test_node_type', type_hierarchy=[], -number_of_instances=1, -planned_number_of_instances=1, -deploy_number_of_instances=1, -properties={}, -operations=dict((key, {}) for key in operations.NODE_OPERATIONS), -min_number_of_instances=1, -max_number_of_instances=1, +default_instances=1, +min_instances=1, +max_instances=1, +service_template=deployment.service_template, +interface_templates=[interface_template], +requirement_templates=[requirement_template], +capability_templates=[capability_template], ) -def get_dependent_node_instance(dependent_node): -return model.NodeInstance( +def get_dependent_node_instance(dependent_node, deployment): +return model.Node( name=DEPENDENT_NODE_INSTANCE_NAME, +service_instance=deployment, runtime_properties={}, version=None, -node_fk=dependent_node.id, +node_template=dependent_node, state='', -scaling_groups=[] +scaling_groups=[], ) def get_blueprint(): now = datetime.now() -return model.Blueprint( +return model.ServiceTemplate( plan={}, name=BLUEPRINT_NAME, description=None, @@ -124,7 +117,7 @@ def get_blueprint(): def get_execution(deployment): return model.Execution( -deployment_fk=deployment.id, +service_instance=deployment,
[3/5] incubator-ariatosca git commit: ARIA-44-Merge-parser-and-storage-models
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68a81882/aria/storage/modeling/template_elements.py -- diff --git a/aria/storage/modeling/template_elements.py b/aria/storage/modeling/template_elements.py new file mode 100644 index 000..becd45b --- /dev/null +++ b/aria/storage/modeling/template_elements.py @@ -0,0 +1,1352 @@ +# 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 copy import deepcopy +from types import FunctionType + +from sqlalchemy import ( +Column, +Text, +Integer, +DateTime, +Boolean, +) +from sqlalchemy.ext.associationproxy import association_proxy +from sqlalchemy.ext.declarative import declared_attr + +from aria.parser import validation +from aria.utils import collections, formatting, console + +from . import ( +utils, +instance_elements, +structure, +type as aria_type +) + +# pylint: disable=no-self-argument, no-member, abstract-method + + +# region Element templates + + +class ServiceTemplateBase(structure.ModelMixin): + +__tablename__ = 'service_template' + +description = Column(Text) +metadata = Column(Text) + +# region orchestrator required columns + +created_at = Column(DateTime, nullable=False, index=True) +main_file_name = Column(Text) +plan = Column(aria_type.Dict) +updated_at = Column(DateTime) + +# endregion + +# region foreign keys +@declared_attr +def substitution_template_fk(cls): +return cls.foreign_key('substitution_template', nullable=True) + +# endregion + +# region one-to-one relationships +@declared_attr +def substitution_template(cls): +return cls.one_to_one_relationship('substitution_template') +# endregion + +# # region one-to-many relationships +@declared_attr +def node_templates(cls): +return cls.one_to_many_relationship('node_template') + +@declared_attr +def group_templates(cls): +return cls.one_to_many_relationship('group_template') + +@declared_attr +def policy_templates(cls): +return cls.one_to_many_relationship('policy_template') + +@declared_attr +def operation_templates(cls): +""" +Custom workflows +:return: +""" +return cls.one_to_many_relationship('operation_template') + +# endregion + +# region many-to-many relationships + +@declared_attr +def inputs(cls): +return cls.many_to_many_relationship('parameter', table_prefix='inputs') + +@declared_attr +def outputs(cls): +return cls.many_to_many_relationship('parameter', table_prefix='outputs') + +# endregion + +@property +def as_raw(self): +return collections.OrderedDict(( +('description', self.description), +('metadata', formatting.as_raw(self.metadata)), +('node_templates', formatting.as_raw_list(self.node_templates)), +('group_templates', formatting.as_raw_list(self.group_templates)), +('policy_templates', formatting.as_raw_list(self.policy_templates)), +('substitution_template', formatting.as_raw(self.substitution_template)), +('inputs', formatting.as_raw_dict(self.inputs)), +('outputs', formatting.as_raw_dict(self.outputs)), +('operation_templates', formatting.as_raw_list(self.operation_templates + +def instantiate(self, context, container): +service_instance = instance_elements.ServiceInstanceBase() +context.modeling.instance = service_instance + +service_instance.description = deepcopy_with_locators(self.description) + +if self.metadata is not None: +service_instance.metadata = self.metadata.instantiate(context, container) + +for node_template in self.node_templates.itervalues(): +for _ in range(node_template.default_instances): +node = node_template.instantiate(context, container) +service_instance.nodes[node.id] = node + +utils.instantiate_dict(context, self, service_instance.groups, self.group_templates) +utils.instantiate_dict(context, self, service_instance.policies,
[1/5] incubator-ariatosca git commit: ARIA-44-Merge-parser-and-storage-models [Forced Update!]
Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-44-Merge-parser-and-storage-models 401e4752f -> 68a818823 (forced update) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68a81882/tests/storage/test_instrumentation.py -- diff --git a/tests/storage/test_instrumentation.py b/tests/storage/test_instrumentation.py index 8b826e9..16a655b 100644 --- a/tests/storage/test_instrumentation.py +++ b/tests/storage/test_instrumentation.py @@ -17,16 +17,15 @@ import pytest from sqlalchemy import Column, Text, Integer, event from aria.storage import ( -model, +modeling, structure, -type as aria_type, ModelStorage, sql_mapi, instrumentation ) +from aria.storage.modeling import type as aria_type from ..storage import get_sqlite_api_kwargs, release_sqlite_storage - STUB = instrumentation._STUB Value = instrumentation._Value instruments_holder = [] @@ -305,9 +304,9 @@ class _MockModel(structure.ModelMixin): string2 = Column(Text) -class MockModel1(model.DeclarativeBase, _MockModel): +class MockModel1(modeling.declarative_base, _MockModel): __tablename__ = 'mock_model1' -class MockModel2(model.DeclarativeBase, _MockModel): +class MockModel2(modeling.declarative_base, _MockModel): __tablename__ = 'mock_model2' http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68a81882/tests/storage/test_model_storage.py -- diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py index 0e8d1a0..1b91269 100644 --- a/tests/storage/test_model_storage.py +++ b/tests/storage/test_model_storage.py @@ -14,27 +14,25 @@ # limitations under the License. import pytest - from sqlalchemy import Column, Text, Integer +from aria import application_model_storage from aria.storage import ( ModelStorage, -model, exceptions, sql_mapi, structure, -type as aria_type, +modeling, ) -from aria import application_model_storage -from ..storage import get_sqlite_api_kwargs, release_sqlite_storage +from aria.storage.modeling import type as aria_type from ..mock import ( context as mock_context, -models, -operations +models ) +from ..storage import get_sqlite_api_kwargs, release_sqlite_storage -class MockModel(model.DeclarativeBase, structure.ModelMixin): #pylint: disable=abstract-method +class MockModel(modeling.model.DB, structure.ModelMixin): #pylint: disable=abstract-method __tablename__ = 'mock_models' model_dict = Column(aria_type.Dict) model_list = Column(aria_type.List) @@ -57,7 +55,7 @@ def context(): @pytest.fixture(scope='module', autouse=True) def module_cleanup(): -model.DeclarativeBase.metadata.remove(MockModel.__table__) #pylint: disable=no-member +modeling.model.DB.metadata.remove(MockModel.__table__) #pylint: disable=no-member def test_storage_base(storage): @@ -112,24 +110,21 @@ def test_inner_list_update(storage): assert storage_mm.model_list[1][0] == 'new_inner_value' assert storage_mm.model_list[0] == 'new_value' - +# TODO: choose a new model to deployment def test_model_to_dict(context): -deployment = context.deployment +deployment = context.service_instance deployment_dict = deployment.to_dict() expected_keys = [ 'created_at', 'description', -'inputs', -'groups', -'permalink', 'policy_triggers', 'policy_types', -'outputs', 'scaling_groups', 'updated_at', 'workflows', -'blueprint_name', +'service_template_name', +'description' ] for expected_key in expected_keys: @@ -137,93 +132,103 @@ def test_model_to_dict(context): assert 'blueprint_fk' not in deployment_dict - +# TODO: change factory to create different models def test_application_storage_factory(): storage = application_model_storage(sql_mapi.SQLAlchemyModelAPI, api_kwargs=get_sqlite_api_kwargs()) + +assert storage.parameter +assert storage.mapping_template +assert storage.substitution_template +assert storage.service_template +assert storage.node_template +assert storage.group_template +assert storage.interface_template +assert storage.operation_template +assert storage.artifact_template +assert storage.policy_template +assert storage.group_policy_template +assert storage.group_policy_trigger_template +assert storage.requirement_template +assert storage.capability_template + +assert storage.mapping +assert storage.substitution +assert storage.service_instance assert storage.node -assert storage.node_instance -assert storage.plugin -assert storage.blueprint -assert storage.deployment -assert storage.deployme
[5/5] incubator-ariatosca git commit: ARIA-44-Merge-parser-and-storage-models
ARIA-44-Merge-parser-and-storage-models Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/68a81882 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/68a81882 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/68a81882 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 68a81882307742417a41e786c10ceab5cb3370b6 Parents: 4447829 Author: mxmrlv Authored: Thu Jan 19 11:39:36 2017 +0200 Committer: mxmrlv Committed: Sun Jan 29 17:11:27 2017 +0200 -- aria/__init__.py| 49 +- aria/cli/commands.py|2 +- aria/orchestrator/context/common.py | 22 +- aria/orchestrator/context/operation.py | 41 +- aria/orchestrator/context/serialization.py |2 +- aria/orchestrator/context/toolbelt.py |2 +- aria/orchestrator/context/workflow.py | 16 +- aria/orchestrator/runner.py | 10 +- aria/orchestrator/workflows/api/task.py | 120 +- aria/orchestrator/workflows/core/engine.py |2 +- aria/orchestrator/workflows/core/task.py| 26 +- aria/orchestrator/workflows/executor/process.py | 17 +- aria/orchestrator/workflows/executor/thread.py |2 +- aria/parser/modeling/__init__.py|2 +- aria/parser/modeling/storage.py | 147 +- aria/storage/__init__.py| 11 +- aria/storage/base_model.py | 757 -- aria/storage/instrumentation.py |4 +- aria/storage/model.py | 110 -- aria/storage/modeling/__init__.py | 37 + aria/storage/modeling/elements.py | 157 ++ aria/storage/modeling/instance_elements.py | 1247 aria/storage/modeling/model.py | 175 +++ aria/storage/modeling/orchestrator_elements.py | 461 ++ aria/storage/modeling/structure.py | 270 aria/storage/modeling/template_elements.py | 1352 ++ aria/storage/modeling/type.py | 275 aria/storage/modeling/utils.py | 146 ++ aria/storage/structure.py | 190 --- aria/storage/type.py| 120 -- aria/utils/application.py | 14 +- tests/mock/context.py |4 +- tests/mock/models.py| 119 +- tests/mock/topology.py | 96 +- tests/orchestrator/context/test_operation.py| 119 +- .../context/test_resource_render.py |2 +- tests/orchestrator/context/test_serialize.py| 17 +- tests/orchestrator/context/test_toolbelt.py | 72 +- tests/orchestrator/context/test_workflow.py | 14 +- .../orchestrator/execution_plugin/test_local.py | 61 +- tests/orchestrator/execution_plugin/test_ssh.py |2 +- tests/orchestrator/test_runner.py |9 +- tests/orchestrator/workflows/__init__.py|2 +- tests/orchestrator/workflows/api/test_task.py | 76 +- .../workflows/builtin/test_execute_operation.py | 56 - .../workflows/builtin/test_install.py | 43 - .../workflows/builtin/test_uninstall.py | 44 - .../orchestrator/workflows/core/test_engine.py | 23 +- tests/orchestrator/workflows/core/test_task.py | 74 +- .../test_task_graph_into_exececution_graph.py | 14 +- .../workflows/executor/test_executor.py |9 +- .../workflows/executor/test_process_executor.py | 10 +- .../executor/test_process_executor_extension.py | 13 +- .../test_process_executor_tracked_changes.py| 49 +- tests/resources/scripts/test_ssh.sh | 30 +- tests/storage/__init__.py | 12 +- tests/storage/test_instrumentation.py |9 +- tests/storage/test_model_storage.py | 176 ++- tests/storage/test_models.py| 919 59 files changed, 4877 insertions(+), 2983 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68a81882/aria/__init__.py -- diff --git a/aria/__init__.py b/aria/__init__.py index 248aa1a..7f9fe8c 100644 --- a/aria/__init__.py +++ b/aria/__init__.py @@ -61,25 +61,46 @@ def application_model_storage(api, api_kwargs=None): """ Initiate model storage """ -models = [ -storage.model.Plugin, +models_to_register = [ +storage.modeling.model.Parameter, -storage.model.Blueprint, -storage.model.Deployment, -storage.model.DeploymentUpdate, -storage.model.De
[4/5] incubator-ariatosca git commit: ARIA-44-Merge-parser-and-storage-models
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/68a81882/aria/storage/modeling/instance_elements.py -- diff --git a/aria/storage/modeling/instance_elements.py b/aria/storage/modeling/instance_elements.py new file mode 100644 index 000..ce6a83d --- /dev/null +++ b/aria/storage/modeling/instance_elements.py @@ -0,0 +1,1247 @@ +# 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 sqlalchemy import ( +Column, +Text, +Integer, +Boolean, +) +from sqlalchemy import DateTime +from sqlalchemy.ext.associationproxy import association_proxy +from sqlalchemy.ext.declarative import declared_attr +from sqlalchemy.ext.orderinglist import ordering_list + +from aria.parser import validation +from aria.utils import collections, formatting, console + +from . import ( +utils, +structure, +type as aria_types +) + +# pylint: disable=no-self-argument, no-member, abstract-method + +# region Element instances + +class ServiceInstanceBase(structure.ModelMixin): +__tablename__ = 'service_instance' + +description = Column(Text) +_metadata = Column(Text) + +# region orchestrator required columns + +created_at = Column(DateTime, nullable=False, index=True) +permalink = Column(Text) +policy_triggers = Column(aria_types.Dict) +policy_types = Column(aria_types.Dict) +scaling_groups = Column(aria_types.Dict) +updated_at = Column(DateTime) +workflows = Column(aria_types.Dict) + +@declared_attr +def service_template_name(cls): +return association_proxy('service_template', 'name') + +# endregion + +# region foreign keys +@declared_attr +def substitution_fk(cls): +return cls.foreign_key('substitution', nullable=True) + +@declared_attr +def service_template_fk(cls): +return cls.foreign_key('service_template') + +# endregion + +# region one-to-one relationships +@declared_attr +def substitution(cls): +return cls.one_to_one_relationship('substitution') +# endregion + +# region one-to-many relationships +@declared_attr +def nodes(cls): +return cls.one_to_many_relationship('node') + +@declared_attr +def groups(cls): +return cls.one_to_many_relationship('group') + +@declared_attr +def policies(cls): +return cls.one_to_many_relationship('policy') + +@declared_attr +def operations(cls): +return cls.one_to_many_relationship('operation') + +# endregion + +# region many-to-one relationships +@declared_attr +def service_template(cls): +return cls.many_to_one_relationship('service_template') + +# endregion + +# region many-to-many relationships +@declared_attr +def inputs(cls): +return cls.many_to_many_relationship('parameter', table_prefix='inputs') + +@declared_attr +def outputs(cls): +return cls.many_to_many_relationship('parameter', table_prefix='outputs') + +# endregion + +# association proxies + +def satisfy_requirements(self, context): +satisfied = True +for node in self.nodes.all(): +if not node.satisfy_requirements(context): +satisfied = False +return satisfied + +def validate_capabilities(self, context): +satisfied = True +for node in self.nodes.all(): +if not node.validate_capabilities(context): +satisfied = False +return satisfied + +def find_nodes(self, node_template_name): +nodes = [] +for node in self.nodes.all(): +if node.template_name == node_template_name: +nodes.append(node) +return collections.FrozenList(nodes) + +def get_node_ids(self, node_template_name): +return collections.FrozenList((node.id for node in self.find_nodes(node_template_name))) + +def find_groups(self, group_template_name): +groups = [] +for group in self.groups.all(): +if group.template_name == group_template_name: +groups.append(group) +return collections.FrozenList(groups) + +def get_group_ids(self, group_template_na
[01/16] incubator-ariatosca git commit: ARIA-46 Execution plugin [Forced Update!]
Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-44-Merge-parser-and-storage-models 82d9be7d5 -> 401e4752f (forced update) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c4429dd5/tests/orchestrator/execution_plugin/test_ctx_proxy_server.py -- diff --git a/tests/orchestrator/execution_plugin/test_ctx_proxy_server.py b/tests/orchestrator/execution_plugin/test_ctx_proxy_server.py new file mode 100644 index 000..98ceff9 --- /dev/null +++ b/tests/orchestrator/execution_plugin/test_ctx_proxy_server.py @@ -0,0 +1,359 @@ +# 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. + +import os +import time +import sys +import subprocess +import StringIO + +import pytest + +from aria.orchestrator.execution_plugin import ctx_proxy + + +class TestCtxProxy(object): + +def test_attribute_access(self, server): +response = self.request(server, 'stub_attr', 'some_property') +assert response == 'some_value' + +def test_sugared_attribute_access(self, server): +response = self.request(server, 'stub-attr', 'some-property') +assert response == 'some_value' + +def test_dict_prop_access_get_key(self, server): +response = self.request(server, 'node', 'properties', 'prop1') +assert response == 'value1' + +def test_dict_prop_access_get_key_nested(self, server): +response = self.request(server, 'node', 'properties', 'prop2.nested_prop1') +assert response == 'nested_value1' + +def test_dict_prop_access_get_with_list_index(self, server): +response = self.request(server, 'node', 'properties', 'prop3[2].value') +assert response == 'value_2' + +def test_dict_prop_access_set(self, server, ctx): +self.request(server, 'node', 'properties', 'prop4.key', 'new_value') +self.request(server, 'node', 'properties', 'prop3[2].value', 'new_value_2') +self.request(server, 'node', 'properties', 'prop4.some.new.path', + 'some_new_value') +assert ctx.node.properties['prop4']['key'] == 'new_value' +assert ctx.node.properties['prop3'][2]['value'] == 'new_value_2' +assert ctx.node.properties['prop4']['some']['new']['path'] == 'some_new_value' + +def test_illegal_dict_access(self, server): +self.request(server, 'node', 'properties', 'prop4.key', 'new_value') +with pytest.raises(RuntimeError): +self.request(server, 'node', 'properties', 'prop4.key', 'new_value', 'what') + +def test_method_invocation(self, server): +args = ['arg1', 'arg2', 'arg3'] +response_args = self.request(server, 'stub-method', *args) +assert response_args == args + +def test_method_invocation_no_args(self, server): +response = self.request(server, 'stub-method') +assert response == [] + +def test_method_invocation_kwargs(self, server): +arg1 = 'arg1' +arg2 = 'arg2' +arg4 = 'arg4_override' +arg5 = 'arg5' +kwargs = dict( +arg4=arg4, +arg5=arg5) +response = self.request(server, 'stub_args', arg1, arg2, kwargs) +assert response == dict( +arg1=arg1, +arg2=arg2, +arg3='arg3', +arg4=arg4, +args=[], +kwargs=dict( +arg5=arg5)) + +def test_empty_return_value(self, server): +response = self.request(server, 'stub_none') +assert response is None + +def test_client_request_timeout(self, server): +with pytest.raises(IOError): +ctx_proxy.client._client_request(server.socket_url, + args=['stub-sleep', '0.5'], + timeout=0.1) + +def test_processing_exception(self, server): +with pytest.raises(ctx_proxy.client._RequestError): +self.request(server, 'property_that_does_not_exist') + +def test_not_json_serializable(self, server): +with pytest.raises(ctx_proxy.client._RequestError): +self.request(server, 'logger') + +def test_no_string_arg(self, server): +args = ['stub_met
[16/16] incubator-ariatosca git commit: ARIA-44-Merge-parser-and-storage-models
ARIA-44-Merge-parser-and-storage-models Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/401e4752 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/401e4752 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/401e4752 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 401e4752f869072aa7e3578b03eb9d8f1acd5974 Parents: 4447829 Author: mxmrlv Authored: Thu Jan 19 11:39:36 2017 +0200 Committer: mxmrlv Committed: Sun Jan 29 15:22:41 2017 +0200 -- aria/__init__.py| 49 +- aria/cli/commands.py|2 +- aria/orchestrator/context/common.py | 22 +- aria/orchestrator/context/operation.py | 41 +- aria/orchestrator/context/serialization.py |2 +- aria/orchestrator/context/toolbelt.py |2 +- aria/orchestrator/context/workflow.py | 16 +- aria/orchestrator/workflows/api/task.py | 114 +- aria/orchestrator/workflows/core/engine.py |2 +- aria/orchestrator/workflows/core/task.py| 26 +- aria/orchestrator/workflows/executor/process.py | 17 +- aria/orchestrator/workflows/executor/thread.py |2 +- aria/parser/modeling/__init__.py|2 +- aria/parser/modeling/storage.py | 448 +++--- aria/storage/__init__.py| 11 +- aria/storage/base_model.py | 757 -- aria/storage/instrumentation.py |4 +- aria/storage/model.py | 110 -- aria/storage/modeling/__init__.py | 37 + aria/storage/modeling/elements.py | 157 ++ aria/storage/modeling/instance_elements.py | 1247 aria/storage/modeling/model.py | 175 +++ aria/storage/modeling/orchestrator_elements.py | 461 ++ aria/storage/modeling/structure.py | 270 aria/storage/modeling/template_elements.py | 1352 ++ aria/storage/modeling/type.py | 275 aria/storage/modeling/utils.py | 146 ++ aria/storage/structure.py | 190 --- aria/storage/type.py| 120 -- aria/utils/application.py | 14 +- tests/mock/context.py |4 +- tests/mock/models.py| 119 +- tests/mock/topology.py | 37 +- tests/orchestrator/context/test_operation.py| 119 +- .../context/test_resource_render.py |2 +- tests/orchestrator/context/test_serialize.py| 17 +- tests/orchestrator/context/test_toolbelt.py | 72 +- tests/orchestrator/context/test_workflow.py | 14 +- .../orchestrator/execution_plugin/test_local.py | 61 +- tests/orchestrator/execution_plugin/test_ssh.py |2 +- tests/orchestrator/workflows/__init__.py|2 +- tests/orchestrator/workflows/api/test_task.py | 84 +- .../workflows/builtin/test_execute_operation.py | 56 - .../workflows/builtin/test_install.py | 43 - .../workflows/builtin/test_uninstall.py | 44 - .../orchestrator/workflows/core/test_engine.py | 23 +- tests/orchestrator/workflows/core/test_task.py | 74 +- .../test_task_graph_into_exececution_graph.py | 14 +- .../workflows/executor/test_executor.py |9 +- .../workflows/executor/test_process_executor.py | 10 +- .../executor/test_process_executor_extension.py | 13 +- .../test_process_executor_tracked_changes.py| 49 +- tests/resources/scripts/test_ssh.sh | 30 +- tests/storage/__init__.py | 12 +- tests/storage/test_instrumentation.py |9 +- tests/storage/test_model_storage.py | 176 ++- tests/storage/test_models.py| 919 57 files changed, 5037 insertions(+), 3048 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/401e4752/aria/__init__.py -- diff --git a/aria/__init__.py b/aria/__init__.py index 248aa1a..7f9fe8c 100644 --- a/aria/__init__.py +++ b/aria/__init__.py @@ -61,25 +61,46 @@ def application_model_storage(api, api_kwargs=None): """ Initiate model storage """ -models = [ -storage.model.Plugin, +models_to_register = [ +storage.modeling.model.Parameter, -storage.model.Blueprint, -storage.model.Deployment, -storage.model.DeploymentUpdate, -storage.model.DeploymentUpdateStep, -storage.model.DeploymentModification, +storage.modeling.model.MappingTemplate
[13/16] incubator-ariatosca git commit: ARIA-44-Merge-parser-and-storage-models
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/401e4752/tests/mock/models.py -- diff --git a/tests/mock/models.py b/tests/mock/models.py index 8229038..e735230 100644 --- a/tests/mock/models.py +++ b/tests/mock/models.py @@ -15,8 +15,7 @@ from datetime import datetime -from aria.storage import model - +from aria.storage.modeling import model from . import operations DEPLOYMENT_NAME = 'test_deployment_id' @@ -35,84 +34,78 @@ RELATIONSHIP_INSTANCE_NAME = 'relationship_instance' def get_dependency_node(deployment): -return model.Node( +return model.NodeTemplate( name=DEPENDENCY_NODE_NAME, -type='test_node_type', +type_name='test_node_type', type_hierarchy=[], -number_of_instances=1, -planned_number_of_instances=1, -deploy_number_of_instances=1, -properties={}, -operations=dict((key, {}) for key in operations.NODE_OPERATIONS), -min_number_of_instances=1, -max_number_of_instances=1, -deployment_fk=deployment.id +default_instances=1, +min_instances=1, +max_instances=1, +service_template=deployment.service_template, ) -def get_dependency_node_instance(dependency_node): -return model.NodeInstance( +def get_dependency_node_instance(dependency_node, deployment): +return model.Node( name=DEPENDENCY_NODE_INSTANCE_NAME, +service_instance=deployment, runtime_properties={'ip': '1.1.1.1'}, version=None, -node_fk=dependency_node.id, +node_template=dependency_node, state='', scaling_groups=[] ) -def get_relationship(source=None, target=None): -return model.Relationship( -source_node_fk=source.id, -target_node_fk=target.id, -source_interfaces={}, -source_operations=dict((key, {}) for key in operations.RELATIONSHIP_OPERATIONS), -target_interfaces={}, -target_operations=dict((key, {}) for key in operations.RELATIONSHIP_OPERATIONS), -type='rel_type', -type_hierarchy=[], -properties={}, -) +def get_relationship(target): +requirement_template = model.RequirementTemplate(target_node_template_name=target.name) +capability_template = model.CapabilityTemplate() + +return requirement_template, capability_template -def get_relationship_instance(source_instance, target_instance, relationship): -return model.RelationshipInstance( -relationship_fk=relationship.id, -target_node_instance_fk=target_instance.id, -source_node_instance_fk=source_instance.id, +def get_relationship_instance(source_instance, target_instance): +return model.Relationship( +target_node=target_instance, +source_node=source_instance, ) -def get_dependent_node(deployment): -return model.Node( +def get_dependent_node(deployment, requirement_template, capability_template): +operation_templates = [model.OperationTemplate(implementation=op, + service_template=deployment.service_template) + for op in operations.NODE_OPERATIONS] +interface_template = model.InterfaceTemplate(operation_templates=operation_templates) + +return model.NodeTemplate( name=DEPENDENT_NODE_NAME, -deployment_fk=deployment.id, -type='test_node_type', +type_name='test_node_type', type_hierarchy=[], -number_of_instances=1, -planned_number_of_instances=1, -deploy_number_of_instances=1, -properties={}, -operations=dict((key, {}) for key in operations.NODE_OPERATIONS), -min_number_of_instances=1, -max_number_of_instances=1, +default_instances=1, +min_instances=1, +max_instances=1, +service_template=deployment.service_template, +interface_templates=[interface_template], +requirement_templates=[requirement_template], +capability_templates=[capability_template], ) -def get_dependent_node_instance(dependent_node): -return model.NodeInstance( +def get_dependent_node_instance(dependent_node, deployment): +return model.Node( name=DEPENDENT_NODE_INSTANCE_NAME, +service_instance=deployment, runtime_properties={}, version=None, -node_fk=dependent_node.id, +node_template=dependent_node, state='', -scaling_groups=[] +scaling_groups=[], ) def get_blueprint(): now = datetime.now() -return model.Blueprint( +return model.ServiceTemplate( plan={}, name=BLUEPRINT_NAME, description=None, @@ -124,7 +117,7 @@ def get_blueprint(): def get_execution(deployment): return model.Execution( -deployment_fk=deployment.id, +service_instance=deployment,
[14/16] incubator-ariatosca git commit: ARIA-44-Merge-parser-and-storage-models
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/401e4752/aria/storage/modeling/template_elements.py -- diff --git a/aria/storage/modeling/template_elements.py b/aria/storage/modeling/template_elements.py new file mode 100644 index 000..becd45b --- /dev/null +++ b/aria/storage/modeling/template_elements.py @@ -0,0 +1,1352 @@ +# 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 copy import deepcopy +from types import FunctionType + +from sqlalchemy import ( +Column, +Text, +Integer, +DateTime, +Boolean, +) +from sqlalchemy.ext.associationproxy import association_proxy +from sqlalchemy.ext.declarative import declared_attr + +from aria.parser import validation +from aria.utils import collections, formatting, console + +from . import ( +utils, +instance_elements, +structure, +type as aria_type +) + +# pylint: disable=no-self-argument, no-member, abstract-method + + +# region Element templates + + +class ServiceTemplateBase(structure.ModelMixin): + +__tablename__ = 'service_template' + +description = Column(Text) +metadata = Column(Text) + +# region orchestrator required columns + +created_at = Column(DateTime, nullable=False, index=True) +main_file_name = Column(Text) +plan = Column(aria_type.Dict) +updated_at = Column(DateTime) + +# endregion + +# region foreign keys +@declared_attr +def substitution_template_fk(cls): +return cls.foreign_key('substitution_template', nullable=True) + +# endregion + +# region one-to-one relationships +@declared_attr +def substitution_template(cls): +return cls.one_to_one_relationship('substitution_template') +# endregion + +# # region one-to-many relationships +@declared_attr +def node_templates(cls): +return cls.one_to_many_relationship('node_template') + +@declared_attr +def group_templates(cls): +return cls.one_to_many_relationship('group_template') + +@declared_attr +def policy_templates(cls): +return cls.one_to_many_relationship('policy_template') + +@declared_attr +def operation_templates(cls): +""" +Custom workflows +:return: +""" +return cls.one_to_many_relationship('operation_template') + +# endregion + +# region many-to-many relationships + +@declared_attr +def inputs(cls): +return cls.many_to_many_relationship('parameter', table_prefix='inputs') + +@declared_attr +def outputs(cls): +return cls.many_to_many_relationship('parameter', table_prefix='outputs') + +# endregion + +@property +def as_raw(self): +return collections.OrderedDict(( +('description', self.description), +('metadata', formatting.as_raw(self.metadata)), +('node_templates', formatting.as_raw_list(self.node_templates)), +('group_templates', formatting.as_raw_list(self.group_templates)), +('policy_templates', formatting.as_raw_list(self.policy_templates)), +('substitution_template', formatting.as_raw(self.substitution_template)), +('inputs', formatting.as_raw_dict(self.inputs)), +('outputs', formatting.as_raw_dict(self.outputs)), +('operation_templates', formatting.as_raw_list(self.operation_templates + +def instantiate(self, context, container): +service_instance = instance_elements.ServiceInstanceBase() +context.modeling.instance = service_instance + +service_instance.description = deepcopy_with_locators(self.description) + +if self.metadata is not None: +service_instance.metadata = self.metadata.instantiate(context, container) + +for node_template in self.node_templates.itervalues(): +for _ in range(node_template.default_instances): +node = node_template.instantiate(context, container) +service_instance.nodes[node.id] = node + +utils.instantiate_dict(context, self, service_instance.groups, self.group_templates) +utils.instantiate_dict(context, self, service_instance.policies,
[02/16] incubator-ariatosca git commit: ARIA-46 Execution plugin
ARIA-46 Execution plugin Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/c4429dd5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/c4429dd5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/c4429dd5 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: c4429dd59a80bd6e58ba3bec4a2528eeda27a897 Parents: 385b209 Author: Dan Kilman Authored: Tue Jan 3 17:00:46 2017 +0200 Committer: Dan Kilman Committed: Thu Jan 19 18:13:51 2017 +0200 -- appveyor.yml| 2 +- aria/orchestrator/context/common.py | 4 +- aria/orchestrator/context/operation.py | 5 +- aria/orchestrator/exceptions.py | 2 +- aria/orchestrator/execution_plugin/__init__.py | 33 ++ aria/orchestrator/execution_plugin/common.py| 150 + aria/orchestrator/execution_plugin/constants.py | 51 ++ .../execution_plugin/ctx_proxy/__init__.py | 16 + .../execution_plugin/ctx_proxy/client.py| 105 .../execution_plugin/ctx_proxy/server.py| 239 .../execution_plugin/environment_globals.py | 60 ++ .../orchestrator/execution_plugin/exceptions.py | 38 ++ aria/orchestrator/execution_plugin/local.py | 125 .../orchestrator/execution_plugin/operations.py | 63 ++ .../execution_plugin/ssh/__init__.py| 14 + .../execution_plugin/ssh/operations.py | 192 ++ .../orchestrator/execution_plugin/ssh/tunnel.py | 91 +++ aria/orchestrator/workflows/api/task.py | 12 +- aria/orchestrator/workflows/core/engine.py | 1 - aria/orchestrator/workflows/core/task.py| 3 +- aria/orchestrator/workflows/executor/process.py | 3 +- aria/storage/base_model.py | 26 +- aria/storage/filesystem_rapi.py | 2 +- aria/utils/exceptions.py| 19 + requirements.txt| 5 + setup.py| 9 +- tests/orchestrator/execution_plugin/__init__.py | 14 + .../execution_plugin/test_common.py | 193 ++ .../execution_plugin/test_ctx_proxy_server.py | 359 .../execution_plugin/test_global_ctx.py | 28 + .../orchestrator/execution_plugin/test_local.py | 587 +++ tests/orchestrator/execution_plugin/test_ssh.py | 481 +++ tests/orchestrator/workflows/api/test_task.py | 5 + tests/orchestrator/workflows/core/test_task.py | 38 +- tests/orchestrator/workflows/helpers.py | 37 ++ tests/resources/scripts/test_ssh.sh | 81 +++ tests/test_logger.py| 5 +- tests/utils/test_exceptions.py | 73 +++ tox.ini | 7 + 39 files changed, 3150 insertions(+), 28 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c4429dd5/appveyor.yml -- diff --git a/appveyor.yml b/appveyor.yml index 3ea8635..cb1ae42 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,7 @@ environment: TOX_ENV: pywin matrix: -- PYTHON: C:\Python27 +- PYTHON: "C:\\Python27" PYTHON_VERSION: 2.7.8 PYTHON_ARCH: 32 http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c4429dd5/aria/orchestrator/context/common.py -- diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py index 53844e8..691c17d 100644 --- a/aria/orchestrator/context/common.py +++ b/aria/orchestrator/context/common.py @@ -113,9 +113,7 @@ class BaseContext(logger.LoggerMixin): template using the provided variables. ctx is available to the template without providing it explicitly. """ -self.download_resource(destination=destination, path=path) -with open(destination, 'rb') as f: -resource_content = f.read() +resource_content = self.get_resource(path=path) resource_content = self._render_resource(resource_content=resource_content, variables=variables) with open(destination, 'wb') as f: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c4429dd5/aria/orchestrator/context/operation.py -- diff --git a/aria/orchestrator/context/operation.py b/aria/orchestrator/context/operation.py index 19bb73a..b33d107 100644 --- a/aria/orchestrator/context/operation.py +++ b/aria/orchestrator/context/operation.py @@ -42,6 +42,7 @@ class BaseOperationContext(BaseContext):
[08/16] incubator-ariatosca git commit: ARIA-12 New "Runner" class for simple workflow executions
ARIA-12 New "Runner" class for simple workflow executions Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/372f2a15 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/372f2a15 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/372f2a15 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 372f2a15011800d3503a8688800ce18fc02aa04e Parents: 4c75aeb Author: Tal Liron Authored: Tue Jan 24 17:57:50 2017 +0200 Committer: Tal Liron Committed: Wed Jan 25 15:05:55 2017 +0200 -- aria/orchestrator/runner.py | 135 + tests/mock/__init__.py| 2 +- tests/mock/context.py | 36 + tests/mock/topology.py| 96 +++ tests/orchestrator/test_runner.py | 74 ++ 5 files changed, 309 insertions(+), 34 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/372f2a15/aria/orchestrator/runner.py -- diff --git a/aria/orchestrator/runner.py b/aria/orchestrator/runner.py new file mode 100644 index 000..16acc19 --- /dev/null +++ b/aria/orchestrator/runner.py @@ -0,0 +1,135 @@ +# 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. + +""" +Workflow runner +""" + +import platform +import tempfile +import os + +from sqlalchemy import (create_engine, orm) # @UnresolvedImport +from sqlalchemy.pool import StaticPool # @UnresolvedImport + +from .context.workflow import WorkflowContext +from .workflows.core.engine import Engine +from .workflows.executor.thread import ThreadExecutor +from ..storage import model +from ..storage.sql_mapi import SQLAlchemyModelAPI +from ..storage.filesystem_rapi import FileSystemResourceAPI +from .. import (application_model_storage, application_resource_storage) + + +SQLITE_IN_MEMORY = 'sqlite:///:memory:' + + +class Runner(object): +""" +Runs workflows on a deployment. By default uses temporary storage (either on disk or in memory) +but can also be used with existing storage. + +Handles the initialization of the storage engine and provides convenience methods for +sub-classes to create tasks. + +:param path: path to Sqlite database file; use '' (the default) to use a temporary file, + and None to use an in-memory database +:type path: string +""" + +def __init__(self, workflow_name, workflow_fn, inputs, initialize_model_storage_fn, + deployment_id, storage_path='', is_storage_temporary=True): +if storage_path == '': +# Temporary file storage +the_file, storage_path = tempfile.mkstemp(suffix='.db', prefix='aria-') +os.close(the_file) + +self._storage_path = storage_path +self._is_storage_temporary = is_storage_temporary + +workflow_context = self.create_workflow_context(workflow_name, deployment_id, + initialize_model_storage_fn) + +tasks_graph = workflow_fn(ctx=workflow_context, **inputs) + +self._engine = Engine( +executor=ThreadExecutor(), +workflow_context=workflow_context, +tasks_graph=tasks_graph) + +def run(self): +try: +self._engine.execute() +finally: +self.cleanup() + +def create_workflow_context(self, workflow_name, deployment_id, initialize_model_storage_fn): +model_storage = self.create_sqlite_model_storage() +initialize_model_storage_fn(model_storage) +resource_storage = self.create_fs_resource_storage() +return WorkflowContext( +name=workflow_name, +model_storage=model_storage, +resource_storage=resource_storage, +deployment_id=deployment_id, +workflow_name=self.__class__.__name__, +task_max_attempts=1, +task_retry_interval=1) + +def create_sqlite_model_storage(s
[12/16] incubator-ariatosca git commit: ARIA-44-Merge-parser-and-storage-models
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/401e4752/tests/storage/test_model_storage.py -- diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py index 0e8d1a0..1b91269 100644 --- a/tests/storage/test_model_storage.py +++ b/tests/storage/test_model_storage.py @@ -14,27 +14,25 @@ # limitations under the License. import pytest - from sqlalchemy import Column, Text, Integer +from aria import application_model_storage from aria.storage import ( ModelStorage, -model, exceptions, sql_mapi, structure, -type as aria_type, +modeling, ) -from aria import application_model_storage -from ..storage import get_sqlite_api_kwargs, release_sqlite_storage +from aria.storage.modeling import type as aria_type from ..mock import ( context as mock_context, -models, -operations +models ) +from ..storage import get_sqlite_api_kwargs, release_sqlite_storage -class MockModel(model.DeclarativeBase, structure.ModelMixin): #pylint: disable=abstract-method +class MockModel(modeling.model.DB, structure.ModelMixin): #pylint: disable=abstract-method __tablename__ = 'mock_models' model_dict = Column(aria_type.Dict) model_list = Column(aria_type.List) @@ -57,7 +55,7 @@ def context(): @pytest.fixture(scope='module', autouse=True) def module_cleanup(): -model.DeclarativeBase.metadata.remove(MockModel.__table__) #pylint: disable=no-member +modeling.model.DB.metadata.remove(MockModel.__table__) #pylint: disable=no-member def test_storage_base(storage): @@ -112,24 +110,21 @@ def test_inner_list_update(storage): assert storage_mm.model_list[1][0] == 'new_inner_value' assert storage_mm.model_list[0] == 'new_value' - +# TODO: choose a new model to deployment def test_model_to_dict(context): -deployment = context.deployment +deployment = context.service_instance deployment_dict = deployment.to_dict() expected_keys = [ 'created_at', 'description', -'inputs', -'groups', -'permalink', 'policy_triggers', 'policy_types', -'outputs', 'scaling_groups', 'updated_at', 'workflows', -'blueprint_name', +'service_template_name', +'description' ] for expected_key in expected_keys: @@ -137,93 +132,103 @@ def test_model_to_dict(context): assert 'blueprint_fk' not in deployment_dict - +# TODO: change factory to create different models def test_application_storage_factory(): storage = application_model_storage(sql_mapi.SQLAlchemyModelAPI, api_kwargs=get_sqlite_api_kwargs()) + +assert storage.parameter +assert storage.mapping_template +assert storage.substitution_template +assert storage.service_template +assert storage.node_template +assert storage.group_template +assert storage.interface_template +assert storage.operation_template +assert storage.artifact_template +assert storage.policy_template +assert storage.group_policy_template +assert storage.group_policy_trigger_template +assert storage.requirement_template +assert storage.capability_template + +assert storage.mapping +assert storage.substitution +assert storage.service_instance assert storage.node -assert storage.node_instance -assert storage.plugin -assert storage.blueprint -assert storage.deployment -assert storage.deployment_update -assert storage.deployment_update_step -assert storage.deployment_modification +assert storage.group +assert storage.interface +assert storage.operation +assert storage.capability +assert storage.artifact +assert storage.policy +assert storage.group_policy +assert storage.group_policy_trigger +assert storage.relationship + assert storage.execution +assert storage.service_instance_update +assert storage.service_instance_update_step +assert storage.service_instance_modification +assert storage.plugin +assert storage.task release_sqlite_storage(storage) def test_relationship_model_ordering(context): -deployment = context.model.deployment.get_by_name(models.DEPLOYMENT_NAME) -source_node = context.model.node.get_by_name(models.DEPENDENT_NODE_NAME) -source_node_instance = context.model.node_instance.get_by_name( +deployment = context.model.service_instance.get_by_name(models.DEPLOYMENT_NAME) +source_node = context.model.node_template.get_by_name(models.DEPENDENT_NODE_NAME) +source_node_instance = context.model.node.get_by_name( models.DEPENDENT_NODE_INSTANCE_NAME) -target_node = context.model.node.get_by_name(models.DEPENDENCY_NODE_NAME) -target_node_instance = context.model.node_instance.get_by_name( +target_node = context.model.
[07/16] incubator-ariatosca git commit: ARIA-68 Update runtime properties during operation
ARIA-68 Update runtime properties during operation Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/4c75aeba Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/4c75aeba Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/4c75aeba Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 4c75aeba322761471b247dc4e29692cde20043e9 Parents: db9ae9c Author: Dan Kilman Authored: Tue Jan 24 16:58:10 2017 +0200 Committer: Dan Kilman Committed: Wed Jan 25 14:06:55 2017 +0200 -- aria/orchestrator/workflows/executor/process.py | 93 ++-- aria/storage/instrumentation.py | 18 +++- .../test_process_executor_tracked_changes.py| 62 - tests/storage/test_instrumentation.py | 38 4 files changed, 179 insertions(+), 32 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/4c75aeba/aria/orchestrator/workflows/executor/process.py -- diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py index 9fa0302..7d990fa 100644 --- a/aria/orchestrator/workflows/executor/process.py +++ b/aria/orchestrator/workflows/executor/process.py @@ -29,6 +29,7 @@ script_dir = os.path.dirname(__file__) if script_dir in sys.path: sys.path.remove(script_dir) +import contextlib import io import threading import socket @@ -136,37 +137,39 @@ class ProcessExecutor(base.BaseExecutor): while not self._stopped: try: # Accept messages written to the server socket -message = self._recv_message() -message_type = message['type'] -if message_type == 'closed': -break -task_id = message['task_id'] -if message_type == 'started': -self._task_started(self._tasks[task_id]) -elif message_type == 'succeeded': -task = self._remove_task(task_id) -instrumentation.apply_tracked_changes( -tracked_changes=message['tracked_changes'], -model=task.context.model) -self._task_succeeded(task) -elif message_type == 'failed': -task = self._remove_task(task_id) -instrumentation.apply_tracked_changes( -tracked_changes=message['tracked_changes'], -model=task.context.model) -self._task_failed(task, exception=message['exception']) -else: -raise RuntimeError('Invalid state') +with contextlib.closing(self._server_socket.accept()[0]) as connection: +message = self._recv_message(connection) +message_type = message['type'] +if message_type == 'closed': +break +task_id = message['task_id'] +if message_type == 'started': +self._task_started(self._tasks[task_id]) +elif message_type == 'apply_tracked_changes': +task = self._tasks[task_id] +instrumentation.apply_tracked_changes( +tracked_changes=message['tracked_changes'], +model=task.context.model) +elif message_type == 'succeeded': +task = self._remove_task(task_id) +instrumentation.apply_tracked_changes( +tracked_changes=message['tracked_changes'], +model=task.context.model) +self._task_succeeded(task) +elif message_type == 'failed': +task = self._remove_task(task_id) +instrumentation.apply_tracked_changes( +tracked_changes=message['tracked_changes'], +model=task.context.model) +self._task_failed(task, exception=message['exception']) +else: +raise RuntimeError('Invalid state') except BaseException as e: self.logger.debug('Error in process executor listener: {0}'.format(e)) -def _recv_message(self): -connection, _ = self._server_socket.accept() -try: -message_len, = struct.unpack(_INT_FMT, self._recv_bytes(connection, _INT_SIZE)) -return jsonpickle.loads(self._recv_bytes(connection, message_len)) -finally
[09/16] incubator-ariatosca git commit: ARIA-73 Transfer parser's TOSCA model to storage
ARIA-73 Transfer parser's TOSCA model to storage Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e3056d44 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e3056d44 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e3056d44 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: e3056d44961cf838bcce65004a8a0076825abb56 Parents: 372f2a1 Author: Tal Liron Authored: Wed Jan 25 15:25:33 2017 +0200 Committer: Tal Liron Committed: Wed Jan 25 15:25:33 2017 +0200 -- aria/parser/modeling/storage.py | 224 +++ 1 file changed, 224 insertions(+) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e3056d44/aria/parser/modeling/storage.py -- diff --git a/aria/parser/modeling/storage.py b/aria/parser/modeling/storage.py new file mode 100644 index 000..46c3a7c --- /dev/null +++ b/aria/parser/modeling/storage.py @@ -0,0 +1,224 @@ +# 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 datetime import datetime +from threading import RLock + +from ...storage import model +from ...orchestrator import operation +from ...utils.console import puts, Colored +from ...utils.formatting import safe_repr + + +def initialize_storage(context, model_storage, deployment_id): +blueprint = create_blueprint(context) +model_storage.blueprint.put(blueprint) + +deployment = create_deployment(context, blueprint, deployment_id) +model_storage.deployment.put(deployment) + +# Create nodes and node instances +for node_template in context.modeling.model.node_templates.itervalues(): +node = create_node(context, deployment, node_template) +model_storage.node.put(node) + +for a_node in context.modeling.instance.find_nodes(node_template.name): +node_instance = create_node_instance(node, a_node) +model_storage.node_instance.put(node_instance) + +# Create relationships +for node_template in context.modeling.model.node_templates.itervalues(): +for index, requirement_template in enumerate(node_template.requirement_templates): +# We are currently limited only to requirements for specific node templates! +if requirement_template.target_node_template_name: +source = model_storage.node.get_by_name(node_template.name) +target = model_storage.node.get_by_name( +requirement_template.target_node_template_name) +relationship = create_relationship(context, source, target, + requirement_template.relationship_template) +model_storage.relationship.put(relationship) + +for node in context.modeling.instance.find_nodes(node_template.name): +for relationship_model in node.relationships: +if relationship_model.source_requirement_index == index: +source_instance = \ + model_storage.node_instance.get_by_name(node.id) +target_instance = \ +model_storage.node_instance.get_by_name( +relationship_model.target_node_id) +relationship_instance = \ +create_relationship_instance(relationship, source_instance, + target_instance) + model_storage.relationship_instance.put(relationship_instance) + + +def create_blueprint(context): +now = datetime.utcnow() +main_file_name = unicode(context.presentation.location) +try: +name = context.modeling.model.metadata.values.get('template_name') +except AttributeError: +name = None +return model.Blueprint( +plan={}, +name=name or main_file_name, +des
[11/16] incubator-ariatosca git commit: ARIA-61 Initial version of CLI "workflow" command
ARIA-61 Initial version of CLI "workflow" command Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/44478293 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/44478293 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/44478293 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 44478293c0f16ed1c60fb5c8b8b12e73954fddfe Parents: 8469917 Author: Tal Liron Authored: Wed Jan 25 16:30:16 2017 +0200 Committer: Tal Liron Committed: Thu Jan 26 12:38:16 2017 +0200 -- aria/cli/args_parser.py | 141 + aria/cli/cli.py | 10 +- aria/cli/commands.py| 313 --- aria/cli/csar.py| 2 +- aria/orchestrator/__init__.py | 2 +- aria/orchestrator/decorators.py | 3 + aria/parser/modeling/__init__.py| 4 +- aria/parser/modeling/types.py | 28 +- .../simple_v1_0/modeling/__init__.py| 1 + 9 files changed, 313 insertions(+), 191 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/44478293/aria/cli/args_parser.py -- diff --git a/aria/cli/args_parser.py b/aria/cli/args_parser.py index 8eacf05..e661620 100644 --- a/aria/cli/args_parser.py +++ b/aria/cli/args_parser.py @@ -68,6 +68,7 @@ def config_parser(parser=None): add_init_parser(sub_parser) add_execute_parser(sub_parser) add_parse_parser(sub_parser) +add_workflow_parser(sub_parser) add_spec_parser(sub_parser) add_csar_create_parser(sub_parser) add_csar_open_parser(sub_parser) @@ -76,6 +77,73 @@ def config_parser(parser=None): @sub_parser_decorator( +name='parse', +help='Parse a blueprint', +formatter_class=SmartFormatter) +def add_parse_parser(parse): +""" +``parse`` command parser configuration +""" +parse.add_argument( +'uri', +help='URI or file path to service template') +parse.add_argument( +'consumer', +nargs='?', +default='validate', +help='"validate" (default), "presentation", "model", "types", "instance", or consumer ' + 'class name (full class path or short name)') +parse.add_argument( +'--loader-source', +default='aria.parser.loading.DefaultLoaderSource', +help='loader source class for the parser') +parse.add_argument( +'--reader-source', +default='aria.parser.reading.DefaultReaderSource', +help='reader source class for the parser') +parse.add_argument( +'--presenter-source', +default='aria.parser.presentation.DefaultPresenterSource', +help='presenter source class for the parser') +parse.add_argument( +'--presenter', +help='force use of this presenter class in parser') +parse.add_argument( +'--prefix', nargs='*', +help='prefixes for imports') +parse.add_flag_argument( +'debug', +help_true='print debug info', +help_false='don\'t print debug info') +parse.add_flag_argument( +'cached-methods', +help_true='enable cached methods', +help_false='disable cached methods', +default=True) + + +@sub_parser_decorator( +name='workflow', +help='Run a workflow on a blueprint', +formatter_class=SmartFormatter) +def add_workflow_parser(workflow): +""" +``workflow`` command parser configuration +""" +workflow.add_argument( +'uri', +help='URI or file path to service template') +workflow.add_argument( +'-w', '--workflow', +default='install', +help='The workflow name') +workflow.add_argument( +'-d', '--deployment-id', +required=False, +help='A unique ID for the deployment') + + +@sub_parser_decorator( name='init', help='Initialize environment', formatter_class=SmartFormatter) @@ -146,65 +214,6 @@ def add_execute_parser(execute): @sub_parser_decorator( -name='parse', -help='Parse a blueprint', -formatter_class=SmartFormatter) -def add_parse_parser(parse): -""" -``parse`` command parser configuration -""" -parse.add_argument( -'uri', -help='URI or file path to profile') -parse.add_argument( -'consumer', -nargs='?', -default='instance', -help='consumer class name (full class path or short name)') -parse.add_argument( -'--loader-source', -default='aria.parser.loading.DefaultLoaderSource', -help='loader source class for the parser') -parse.add
[05/16] incubator-ariatosca git commit: ARIA-74 Add process executor extension registration hooks
ARIA-74 Add process executor extension registration hooks Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/0382b229 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/0382b229 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/0382b229 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 0382b229c8eddcbf95ea7792b2bdcd9d9dda303b Parents: eaf9974 Author: Dan Kilman Authored: Mon Jan 23 16:55:41 2017 +0200 Committer: Dan Kilman Committed: Mon Jan 23 19:21:32 2017 +0200 -- aria/extension.py | 15 aria/orchestrator/plugin.py | 9 ++- aria/orchestrator/workflows/executor/process.py | 5 ++ .../executor/test_process_executor_extension.py | 80 4 files changed, 106 insertions(+), 3 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0382b229/aria/extension.py -- diff --git a/aria/extension.py b/aria/extension.py index ddb7c25..4dba74f 100644 --- a/aria/extension.py +++ b/aria/extension.py @@ -118,8 +118,23 @@ class _ParserExtensionRegistration(_ExtensionRegistration): parser = _ParserExtensionRegistration() +class _ProcessExecutorExtensionRegistration(_ExtensionRegistration): +"""Process executor extension class decorator""" + +@_registrar +def decorate(self): +""" +The operation function executed by the process executor will be decorated with the function +returned from decorate(). +""" +return [] + +process_executor = _ProcessExecutorExtensionRegistration() + + def init(): """ Initialize all registrars by calling all registered functions """ parser.init() +process_executor.init() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0382b229/aria/orchestrator/plugin.py -- diff --git a/aria/orchestrator/plugin.py b/aria/orchestrator/plugin.py index 3005756..381504e 100644 --- a/aria/orchestrator/plugin.py +++ b/aria/orchestrator/plugin.py @@ -39,14 +39,17 @@ class PluginManager(object): """ metadata = wagon.show(source) cls = self._model.plugin.model_cls + +os_props = metadata['build_server_os_properties'] + plugin = cls( archive_name=metadata['archive_name'], supported_platform=metadata['supported_platform'], supported_py_versions=metadata['supported_python_versions'], # Remove suffix colon after upgrading wagon to > 0.5.0 - distribution=metadata['build_server_os_properties']['distribution:'], - distribution_release=metadata['build_server_os_properties']['distribution_version'], - distribution_version=metadata['build_server_os_properties']['distribution_release'], +distribution=os_props.get('distribution:') or os_props.get('distribution'), +distribution_release=os_props['distribution_version'], +distribution_version=os_props['distribution_release'], package_name=metadata['package_name'], package_version=metadata['package_version'], package_source=metadata['package_source'], http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0382b229/aria/orchestrator/workflows/executor/process.py -- diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py index 2cc9178..9fa0302 100644 --- a/aria/orchestrator/workflows/executor/process.py +++ b/aria/orchestrator/workflows/executor/process.py @@ -39,6 +39,8 @@ import Queue import jsonpickle +import aria +from aria.extension import process_executor from aria.utils import imports from aria.utils import exceptions from aria.orchestrator.workflows.executor import base @@ -291,6 +293,9 @@ def _main(): try: ctx = serialization.operation_context_from_dict(context_dict) task_func = imports.load_attribute(operation_mapping) +aria.install_aria_extensions() +for decorate in process_executor.decorate(): +task_func = decorate(task_func) task_func(ctx=ctx, **operation_inputs) messenger.succeeded(tracked_changes=instrument.tracked_changes) except BaseException as e: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0382b229/tests/orchestrator/workflows/executor/test_process_executor_extension.py -- diff --git a/tests/orchestrator/workflows
[03/16] incubator-ariatosca git commit: ARIA-65 Add validation for relationship assignment type
ARIA-65 Add validation for relationship assignment type Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/8ecf5bba Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/8ecf5bba Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/8ecf5bba Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 8ecf5bba9a53135f993a43cf6e3b499857b19701 Parents: c4429dd Author: Tal Liron Authored: Sun Jan 22 12:49:12 2017 +0200 Committer: Ran Ziv Committed: Sun Jan 22 12:50:54 2017 +0200 -- .../simple_v1_0/modeling/requirements.py | 17 + .../aria_extension_tosca/simple_v1_0/types.py | 8 2 files changed, 21 insertions(+), 4 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8ecf5bba/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py -- diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py index 8f6c38f..97e30ee 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py +++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/requirements.py @@ -159,12 +159,21 @@ def convert_requirement_from_definition_to_assignment(context, requirement_defin relationship_template = relationship_type relationship_type = relationship_template._get_type(context) +definition_relationship_type = None +relationship_definition = requirement_definition.relationship # RelationshipDefinition +if relationship_definition is not None: +definition_relationship_type = relationship_definition._get_type(context) + # If not exists, try at the node type -relationship_definition = None if relationship_type is None: -relationship_definition = requirement_definition.relationship # RelationshipDefinition -if relationship_definition is not None: -relationship_type = relationship_definition._get_type(context) +relationship_type = definition_relationship_type +else: +# Make sure the type is derived +if not definition_relationship_type._is_descendant(context, relationship_type): +context.validation.report( +'assigned relationship type "%s" is not a descendant of declared relationship type "%s"' +% (relationship_type._name, definition_relationship_type._name), +locator=container._locator, level=Issue.BETWEEN_TYPES) if relationship_type is not None: raw['relationship'] = OrderedDict() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8ecf5bba/extensions/aria_extension_tosca/simple_v1_0/types.py -- diff --git a/extensions/aria_extension_tosca/simple_v1_0/types.py b/extensions/aria_extension_tosca/simple_v1_0/types.py index 39843ac..2112f7f 100644 --- a/extensions/aria_extension_tosca/simple_v1_0/types.py +++ b/extensions/aria_extension_tosca/simple_v1_0/types.py @@ -484,6 +484,14 @@ class RelationshipType(ExtensiblePresentation): 'relationship_types') @cachedmethod +def _is_descendant(self, context, the_type): +if the_type is None: +return False +elif the_type._name == self._name: +return True +return self._is_descendant(context, the_type._get_parent(context)) + +@cachedmethod def _get_properties(self, context): return FrozenDict(get_inherited_property_definitions(context, self, 'properties'))
[15/16] incubator-ariatosca git commit: ARIA-44-Merge-parser-and-storage-models
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/401e4752/aria/storage/modeling/elements.py -- diff --git a/aria/storage/modeling/elements.py b/aria/storage/modeling/elements.py new file mode 100644 index 000..0d7d0c1 --- /dev/null +++ b/aria/storage/modeling/elements.py @@ -0,0 +1,157 @@ +# 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 sqlalchemy import ( +Column, +Text, +) + +from aria.utils.collections import OrderedDict +from aria.utils.console import puts + +from .utils import coerce_value +from . import ( +structure, +type, +) + +# pylint: disable=no-self-argument, no-member, abstract-method + + +class Function(object): +""" +An intrinsic function. + +Serves as a placeholder for a value that should eventually be derived +by calling the function. +""" + +@property +def as_raw(self): +raise NotImplementedError + +def _evaluate(self, context, container): +raise NotImplementedError + +def __deepcopy__(self, memo): +# Circumvent cloning in order to maintain our state +return self + + +class ElementBase(object): +""" +Base class for :class:`ServiceInstance` elements. + +All elements support validation, diagnostic dumping, and representation as +raw data (which can be translated into JSON or YAML) via :code:`as_raw`. +""" + +@property +def as_raw(self): +raise NotImplementedError + +def validate(self, context): +pass + +def coerce_values(self, context, container, report_issues): +pass + +def dump(self, context): +pass + + +class ModelElementBase(ElementBase): +""" +Base class for :class:`ServiceModel` elements. + +All model elements can be instantiated into :class:`ServiceInstance` elements. +""" + +def instantiate(self, context, container): +raise NotImplementedError + + +class ParameterBase(ModelElementBase, structure.ModelMixin): +""" +Represents a typed value. + +This class is used by both service model and service instance elements. +""" +__tablename__ = 'parameter' +name = Column(Text, nullable=False) + +type_name = Column(Text) +# Check: value type +value = Column(Text) +description = Column(Text) + +@property +def as_raw(self): +return OrderedDict(( +('type_name', self.type_name), +('value', self.value), +('description', self.description))) + +# TODO: change name +def _cast_value(self): +if self.type_name is None: +return + +translate_map = { +'string': str(self.value), +'int': int(self.value), +'boolean': bool(self.value), +'float': float(self.value) +} + +if self.type_name.lower() not in translate_map: +raise Exception('No supported type_name was provided') +else: +return translate_map[self.type_name.lower()] + +def instantiate(self, context, container): +return ParameterBase(self.type_name, self.value, self.description) + +def coerce_values(self, context, container, report_issues): +if self.value is not None: +self.value = coerce_value(context, container, self.value, report_issues) + + +class MetadataBase(ModelElementBase, structure.ModelMixin): +""" +Custom values associated with the deployment template and its plans. + +This class is used by both service model and service instance elements. + +Properties: + +* :code:`values`: Dict of custom values +""" +values = Column(type.StrictDict(key_cls=basestring)) + +@property +def as_raw(self): +return self.values + +def instantiate(self, context, container): +metadata = MetadataBase() +metadata.values.update(self.values) +return metadata + +def dump(self, context): +puts('Metadata:') +with context.style.indent: +for name, value in self.values.iteritems(): +puts('%s: %s' % (name, context.style.meta(value))) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/
[06/16] incubator-ariatosca git commit: ARIA-72 Rework built-in workflows to match TOSCA normative lifecycle
ARIA-72 Rework built-in workflows to match TOSCA normative lifecycle Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/db9ae9c7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/db9ae9c7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/db9ae9c7 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: db9ae9c70ae0703cb3f357bf53b95d1a351a8ab0 Parents: 0382b22 Author: Tal Liron Authored: Tue Jan 24 09:52:36 2017 +0200 Committer: Tal Liron Committed: Tue Jan 24 15:48:42 2017 +0200 -- aria/orchestrator/workflows/builtin/__init__.py | 12 +- .../workflows/builtin/execute_operation.py | 30 +- aria/orchestrator/workflows/builtin/heal.py | 4 +- aria/orchestrator/workflows/builtin/install.py | 42 +-- aria/orchestrator/workflows/builtin/start.py| 28 ++ aria/orchestrator/workflows/builtin/stop.py | 28 ++ .../orchestrator/workflows/builtin/uninstall.py | 41 +-- aria/orchestrator/workflows/builtin/utils.py| 70 + .../orchestrator/workflows/builtin/workflows.py | 280 +++ tests/mock/operations.py| 48 +++- .../orchestrator/workflows/builtin/__init__.py | 39 +-- .../orchestrator/workflows/builtin/test_heal.py | 2 + tests/orchestrator/workflows/core/test_task.py | 6 +- .../test_task_graph_into_exececution_graph.py | 2 +- 14 files changed, 342 insertions(+), 290 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/db9ae9c7/aria/orchestrator/workflows/builtin/__init__.py -- diff --git a/aria/orchestrator/workflows/builtin/__init__.py b/aria/orchestrator/workflows/builtin/__init__.py index 0449a8e..d43a962 100644 --- a/aria/orchestrator/workflows/builtin/__init__.py +++ b/aria/orchestrator/workflows/builtin/__init__.py @@ -19,13 +19,17 @@ A set of builtin workflows from .install import install from .uninstall import uninstall -from .execute_operation import execute_operation -from .heal import heal +from .start import start +from .stop import stop + + +BUILTIN_WORKFLOWS = ('install', 'uninstall', 'start', 'stop') __all__ = [ +'BUILTIN_WORKFLOWS', 'install', 'uninstall', -'execute_operation', -'heal', +'start', +'stop' ] http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/db9ae9c7/aria/orchestrator/workflows/builtin/execute_operation.py -- diff --git a/aria/orchestrator/workflows/builtin/execute_operation.py b/aria/orchestrator/workflows/builtin/execute_operation.py index ddbb8e7..e76993d 100644 --- a/aria/orchestrator/workflows/builtin/execute_operation.py +++ b/aria/orchestrator/workflows/builtin/execute_operation.py @@ -17,9 +17,8 @@ Builtin execute_operation workflow """ -from aria import workflow - -from .workflows import execute_operation_on_instance +from ..api.task import OperationTask +from ... import workflow @workflow @@ -68,7 +67,7 @@ def execute_operation( # registering actual tasks to sequences for node_instance in filtered_node_instances: graph.add_tasks( -execute_operation_on_instance( +_create_node_instance_task( node_instance=node_instance, operation=operation, operation_kwargs=operation_kwargs, @@ -102,3 +101,26 @@ def _filter_node_instances(context, node_ids=(), node_instance_ids=(), type_name _is_node_instance_by_id(node_instance.id), _is_node_by_type(node_instance.node.type_hierarchy))): yield node_instance + + +def _create_node_instance_task( +node_instance, +operation, +operation_kwargs, +allow_kwargs_override): +""" +A workflow which executes a single operation +:param node_instance: the node instance to install +:param basestring operation: the operation name +:param dict operation_kwargs: +:param bool allow_kwargs_override: +:return: +""" + +if allow_kwargs_override is not None: +operation_kwargs['allow_kwargs_override'] = allow_kwargs_override + +return OperationTask.node_instance( +instance=node_instance, +name=operation, +inputs=operation_kwargs) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/db9ae9c7/aria/orchestrator/workflows/builtin/heal.py -- diff --git a/aria/orchestrator/workflows/builtin/heal.py b/aria/orchestrator/workflows/builtin/heal.py index 21da2ed..87ac492 100644 --- a/aria/orchestrator/workflows/builtin/heal.py +++ b/aria/orchestrator/workflows/buil
[04/16] incubator-ariatosca git commit: ARIA-70 fix task plugin_name
ARIA-70 fix task plugin_name Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/eaf99748 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/eaf99748 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/eaf99748 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: eaf9974840c101a98d3a626723e37f4990e12ecb Parents: 8ecf5bb Author: Dan Kilman Authored: Sun Jan 22 20:43:40 2017 +0200 Committer: Dan Kilman Committed: Sun Jan 22 20:43:40 2017 +0200 -- aria/orchestrator/workflows/core/task.py | 1 + aria/storage/base_model.py | 5 + tests/orchestrator/workflows/core/test_task.py | 6 -- 3 files changed, 6 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eaf99748/aria/orchestrator/workflows/core/task.py -- diff --git a/aria/orchestrator/workflows/core/task.py b/aria/orchestrator/workflows/core/task.py index 1deb66a..4017ed0 100644 --- a/aria/orchestrator/workflows/core/task.py +++ b/aria/orchestrator/workflows/core/task.py @@ -135,6 +135,7 @@ class OperationTask(BaseTask): retry_interval=api_task.retry_interval, ignore_failure=api_task.ignore_failure, plugin=plugins[0] if plugins else None, +plugin_name=plugin.get('name'), execution=self._workflow_context.execution, runs_on=api_task.runs_on ) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eaf99748/aria/storage/base_model.py -- diff --git a/aria/storage/base_model.py b/aria/storage/base_model.py index 8566e66..f7d0e5b 100644 --- a/aria/storage/base_model.py +++ b/aria/storage/base_model.py @@ -662,10 +662,6 @@ class TaskBase(ModelMixin): return cls.one_to_many_relationship('plugin_fk') @declared_attr -def plugin_name(cls): -return association_proxy('plugin', 'name') - -@declared_attr def execution_fk(cls): return cls.foreign_key(ExecutionBase, nullable=True) @@ -723,6 +719,7 @@ class TaskBase(ModelMixin): # Operation specific fields operation_mapping = Column(String) inputs = Column(Dict) +plugin_name = Column(String) _runs_on = Column(Enum(*RUNS_ON, name='runs_on'), name='runs_on') @property http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eaf99748/tests/orchestrator/workflows/core/test_task.py -- diff --git a/tests/orchestrator/workflows/core/test_task.py b/tests/orchestrator/workflows/core/test_task.py index 020de32..34088f5 100644 --- a/tests/orchestrator/workflows/core/test_task.py +++ b/tests/orchestrator/workflows/core/test_task.py @@ -63,12 +63,14 @@ class TestOperationTask(object): node_instance = ctx.model.node_instance.get_by_name( mock.models.DEPENDENCY_NODE_INSTANCE_NAME) node = node_instance.node -node.plugins = [{'name': 'plugin1', +plugin_name = 'plugin1' +node.plugins = [{'name': plugin_name, 'package_name': 'p1', 'package_version': '0.1'}] -node.operations['aria.interfaces.lifecycle.create'] = {'plugin': 'plugin1'} +node.operations['aria.interfaces.lifecycle.create'] = {'plugin': plugin_name} api_task, core_task = self._create_node_operation_task(ctx, node_instance) storage_task = ctx.model.task.get_by_name(core_task.name) +assert storage_task.plugin_name == plugin_name assert storage_task.execution_name == ctx.execution.name assert storage_task.runs_on.id == core_task.context.node_instance.id assert core_task.model_task == storage_task
[10/16] incubator-ariatosca git commit: ARIA-36 plugin workdir
ARIA-36 plugin workdir Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/84699172 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/84699172 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/84699172 Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 84699172270e9d538958a9ff0dbb874243f962c6 Parents: e3056d4 Author: Dan Kilman Authored: Wed Jan 25 16:22:41 2017 +0200 Committer: Dan Kilman Committed: Thu Jan 26 12:03:49 2017 +0200 -- aria/orchestrator/context/common.py | 2 ++ aria/orchestrator/context/operation.py | 15 +- aria/orchestrator/context/serialization.py | 1 + aria/orchestrator/workflows/core/task.py | 3 +- aria/utils/file.py | 28 ++ tests/orchestrator/context/test_operation.py | 35 ++- tests/orchestrator/context/test_serialize.py | 13 +++-- 7 files changed, 91 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/84699172/aria/orchestrator/context/common.py -- diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py index 691c17d..6ab27ef 100644 --- a/aria/orchestrator/context/common.py +++ b/aria/orchestrator/context/common.py @@ -34,6 +34,7 @@ class BaseContext(logger.LoggerMixin): deployment_id, model_storage, resource_storage, +workdir=None, **kwargs): super(BaseContext, self).__init__(**kwargs) self._name = name @@ -41,6 +42,7 @@ class BaseContext(logger.LoggerMixin): self._model = model_storage self._resource = resource_storage self._deployment_id = deployment_id +self._workdir = workdir def __repr__(self): return ( http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/84699172/aria/orchestrator/context/operation.py -- diff --git a/aria/orchestrator/context/operation.py b/aria/orchestrator/context/operation.py index b33d107..23a6fd4 100644 --- a/aria/orchestrator/context/operation.py +++ b/aria/orchestrator/context/operation.py @@ -17,7 +17,7 @@ Workflow and operation contexts """ - +from aria.utils import file from .common import BaseContext @@ -60,6 +60,19 @@ class BaseOperationContext(BaseContext): self._task = self.model.task.get(self._task_id) return self._task +@property +def plugin_workdir(self): +""" +A work directory that is unique to the plugin and the deployment id +""" +if not self.task.plugin_name: +return None +plugin_workdir = '{0}/plugins/{1}/{2}'.format(self._workdir, + self.deployment.id, + self.task.plugin_name) +file.makedirs(plugin_workdir) +return plugin_workdir + class NodeOperationContext(BaseOperationContext): """ http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/84699172/aria/orchestrator/context/serialization.py -- diff --git a/aria/orchestrator/context/serialization.py b/aria/orchestrator/context/serialization.py index 93cb38a..760818f 100644 --- a/aria/orchestrator/context/serialization.py +++ b/aria/orchestrator/context/serialization.py @@ -26,6 +26,7 @@ def operation_context_to_dict(context): 'deployment_id': context._deployment_id, 'task_id': context._task_id, 'actor_id': context._actor_id, +'workdir': context._workdir } if context.model: model = context.model http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/84699172/aria/orchestrator/workflows/core/task.py -- diff --git a/aria/orchestrator/workflows/core/task.py b/aria/orchestrator/workflows/core/task.py index 4017ed0..f65fc0d 100644 --- a/aria/orchestrator/workflows/core/task.py +++ b/aria/orchestrator/workflows/core/task.py @@ -146,7 +146,8 @@ class OperationTask(BaseTask): resource_storage=self._workflow_context.resource, deployment_id=self._workflow_context._deployment_id, task_id=operation_task.id, - actor_id=api_task.actor.id) + actor_id=api_task.actor.id, + workdir=self._workflow_context._workdir) self._task_i
[5/5] incubator-ariatosca git commit: wip
wip Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/82d9be7d Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/82d9be7d Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/82d9be7d Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models Commit: 82d9be7d51a77cd97228abf876401a698128838f Parents: 385b209 Author: mxmrlv Authored: Thu Jan 19 11:39:36 2017 +0200 Committer: mxmrlv Committed: Sun Jan 29 11:00:18 2017 +0200 -- aria/__init__.py| 49 +- aria/cli/commands.py|2 +- aria/orchestrator/context/common.py | 22 +- aria/orchestrator/context/operation.py | 39 +- aria/orchestrator/context/serialization.py |2 +- aria/orchestrator/context/toolbelt.py |2 +- aria/orchestrator/context/workflow.py | 16 +- aria/orchestrator/workflows/api/task.py | 82 +- aria/orchestrator/workflows/core/engine.py |2 +- aria/orchestrator/workflows/core/task.py| 24 +- aria/orchestrator/workflows/executor/process.py | 14 +- aria/orchestrator/workflows/executor/thread.py |2 +- aria/storage/__init__.py| 11 +- aria/storage/base_model.py | 744 -- aria/storage/instrumentation.py |4 +- aria/storage/model.py | 110 -- aria/storage/modeling/__init__.py | 37 + aria/storage/modeling/elements.py | 157 ++ aria/storage/modeling/instance_elements.py | 1247 aria/storage/modeling/model.py | 175 +++ aria/storage/modeling/orchestrator_elements.py | 446 ++ aria/storage/modeling/structure.py | 270 aria/storage/modeling/template_elements.py | 1352 ++ aria/storage/modeling/type.py | 275 aria/storage/modeling/utils.py | 146 ++ aria/storage/structure.py | 190 --- aria/storage/type.py| 120 -- aria/utils/application.py | 14 +- tests/mock/context.py | 39 +- tests/mock/models.py| 120 +- tests/orchestrator/context/test_operation.py| 100 +- .../context/test_resource_render.py |2 +- tests/orchestrator/context/test_serialize.py| 15 +- tests/orchestrator/context/test_toolbelt.py | 70 +- tests/orchestrator/context/test_workflow.py | 14 +- tests/orchestrator/workflows/__init__.py|2 +- tests/orchestrator/workflows/api/test_task.py | 86 +- .../orchestrator/workflows/builtin/__init__.py | 53 - .../workflows/builtin/test_execute_operation.py | 56 - .../orchestrator/workflows/builtin/test_heal.py | 99 -- .../workflows/builtin/test_install.py | 43 - .../workflows/builtin/test_uninstall.py | 44 - .../orchestrator/workflows/core/test_engine.py | 23 +- tests/orchestrator/workflows/core/test_task.py | 36 +- .../test_task_graph_into_exececution_graph.py | 14 +- .../workflows/executor/test_executor.py |9 +- .../workflows/executor/test_process_executor.py | 10 +- .../test_process_executor_tracked_changes.py| 14 +- tests/storage/__init__.py | 12 +- tests/storage/test_instrumentation.py |9 +- tests/storage/test_model_storage.py | 176 ++- tests/storage/test_models.py| 919 52 files changed, 4655 insertions(+), 2864 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/__init__.py -- diff --git a/aria/__init__.py b/aria/__init__.py index 248aa1a..7f9fe8c 100644 --- a/aria/__init__.py +++ b/aria/__init__.py @@ -61,25 +61,46 @@ def application_model_storage(api, api_kwargs=None): """ Initiate model storage """ -models = [ -storage.model.Plugin, +models_to_register = [ +storage.modeling.model.Parameter, -storage.model.Blueprint, -storage.model.Deployment, -storage.model.DeploymentUpdate, -storage.model.DeploymentUpdateStep, -storage.model.DeploymentModification, +storage.modeling.model.MappingTemplate, +storage.modeling.model.SubstitutionTemplate, +storage.modeling.model.ServiceTemplate, +storage.modeling.model.NodeTemplate, +storage.modeling.model.GroupTemplate, +storage.modeling.model.InterfaceTemplate, +storage.modeling.model.OperationTemplate, +storage.modeling.model.Arti
[4/5] incubator-ariatosca git commit: wip
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/modeling/instance_elements.py -- diff --git a/aria/storage/modeling/instance_elements.py b/aria/storage/modeling/instance_elements.py new file mode 100644 index 000..ce6a83d --- /dev/null +++ b/aria/storage/modeling/instance_elements.py @@ -0,0 +1,1247 @@ +# 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 sqlalchemy import ( +Column, +Text, +Integer, +Boolean, +) +from sqlalchemy import DateTime +from sqlalchemy.ext.associationproxy import association_proxy +from sqlalchemy.ext.declarative import declared_attr +from sqlalchemy.ext.orderinglist import ordering_list + +from aria.parser import validation +from aria.utils import collections, formatting, console + +from . import ( +utils, +structure, +type as aria_types +) + +# pylint: disable=no-self-argument, no-member, abstract-method + +# region Element instances + +class ServiceInstanceBase(structure.ModelMixin): +__tablename__ = 'service_instance' + +description = Column(Text) +_metadata = Column(Text) + +# region orchestrator required columns + +created_at = Column(DateTime, nullable=False, index=True) +permalink = Column(Text) +policy_triggers = Column(aria_types.Dict) +policy_types = Column(aria_types.Dict) +scaling_groups = Column(aria_types.Dict) +updated_at = Column(DateTime) +workflows = Column(aria_types.Dict) + +@declared_attr +def service_template_name(cls): +return association_proxy('service_template', 'name') + +# endregion + +# region foreign keys +@declared_attr +def substitution_fk(cls): +return cls.foreign_key('substitution', nullable=True) + +@declared_attr +def service_template_fk(cls): +return cls.foreign_key('service_template') + +# endregion + +# region one-to-one relationships +@declared_attr +def substitution(cls): +return cls.one_to_one_relationship('substitution') +# endregion + +# region one-to-many relationships +@declared_attr +def nodes(cls): +return cls.one_to_many_relationship('node') + +@declared_attr +def groups(cls): +return cls.one_to_many_relationship('group') + +@declared_attr +def policies(cls): +return cls.one_to_many_relationship('policy') + +@declared_attr +def operations(cls): +return cls.one_to_many_relationship('operation') + +# endregion + +# region many-to-one relationships +@declared_attr +def service_template(cls): +return cls.many_to_one_relationship('service_template') + +# endregion + +# region many-to-many relationships +@declared_attr +def inputs(cls): +return cls.many_to_many_relationship('parameter', table_prefix='inputs') + +@declared_attr +def outputs(cls): +return cls.many_to_many_relationship('parameter', table_prefix='outputs') + +# endregion + +# association proxies + +def satisfy_requirements(self, context): +satisfied = True +for node in self.nodes.all(): +if not node.satisfy_requirements(context): +satisfied = False +return satisfied + +def validate_capabilities(self, context): +satisfied = True +for node in self.nodes.all(): +if not node.validate_capabilities(context): +satisfied = False +return satisfied + +def find_nodes(self, node_template_name): +nodes = [] +for node in self.nodes.all(): +if node.template_name == node_template_name: +nodes.append(node) +return collections.FrozenList(nodes) + +def get_node_ids(self, node_template_name): +return collections.FrozenList((node.id for node in self.find_nodes(node_template_name))) + +def find_groups(self, group_template_name): +groups = [] +for group in self.groups.all(): +if group.template_name == group_template_name: +groups.append(group) +return collections.FrozenList(groups) + +def get_group_ids(self, group_template_na
[3/5] incubator-ariatosca git commit: wip
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/modeling/template_elements.py -- diff --git a/aria/storage/modeling/template_elements.py b/aria/storage/modeling/template_elements.py new file mode 100644 index 000..becd45b --- /dev/null +++ b/aria/storage/modeling/template_elements.py @@ -0,0 +1,1352 @@ +# 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 copy import deepcopy +from types import FunctionType + +from sqlalchemy import ( +Column, +Text, +Integer, +DateTime, +Boolean, +) +from sqlalchemy.ext.associationproxy import association_proxy +from sqlalchemy.ext.declarative import declared_attr + +from aria.parser import validation +from aria.utils import collections, formatting, console + +from . import ( +utils, +instance_elements, +structure, +type as aria_type +) + +# pylint: disable=no-self-argument, no-member, abstract-method + + +# region Element templates + + +class ServiceTemplateBase(structure.ModelMixin): + +__tablename__ = 'service_template' + +description = Column(Text) +metadata = Column(Text) + +# region orchestrator required columns + +created_at = Column(DateTime, nullable=False, index=True) +main_file_name = Column(Text) +plan = Column(aria_type.Dict) +updated_at = Column(DateTime) + +# endregion + +# region foreign keys +@declared_attr +def substitution_template_fk(cls): +return cls.foreign_key('substitution_template', nullable=True) + +# endregion + +# region one-to-one relationships +@declared_attr +def substitution_template(cls): +return cls.one_to_one_relationship('substitution_template') +# endregion + +# # region one-to-many relationships +@declared_attr +def node_templates(cls): +return cls.one_to_many_relationship('node_template') + +@declared_attr +def group_templates(cls): +return cls.one_to_many_relationship('group_template') + +@declared_attr +def policy_templates(cls): +return cls.one_to_many_relationship('policy_template') + +@declared_attr +def operation_templates(cls): +""" +Custom workflows +:return: +""" +return cls.one_to_many_relationship('operation_template') + +# endregion + +# region many-to-many relationships + +@declared_attr +def inputs(cls): +return cls.many_to_many_relationship('parameter', table_prefix='inputs') + +@declared_attr +def outputs(cls): +return cls.many_to_many_relationship('parameter', table_prefix='outputs') + +# endregion + +@property +def as_raw(self): +return collections.OrderedDict(( +('description', self.description), +('metadata', formatting.as_raw(self.metadata)), +('node_templates', formatting.as_raw_list(self.node_templates)), +('group_templates', formatting.as_raw_list(self.group_templates)), +('policy_templates', formatting.as_raw_list(self.policy_templates)), +('substitution_template', formatting.as_raw(self.substitution_template)), +('inputs', formatting.as_raw_dict(self.inputs)), +('outputs', formatting.as_raw_dict(self.outputs)), +('operation_templates', formatting.as_raw_list(self.operation_templates + +def instantiate(self, context, container): +service_instance = instance_elements.ServiceInstanceBase() +context.modeling.instance = service_instance + +service_instance.description = deepcopy_with_locators(self.description) + +if self.metadata is not None: +service_instance.metadata = self.metadata.instantiate(context, container) + +for node_template in self.node_templates.itervalues(): +for _ in range(node_template.default_instances): +node = node_template.instantiate(context, container) +service_instance.nodes[node.id] = node + +utils.instantiate_dict(context, self, service_instance.groups, self.group_templates) +utils.instantiate_dict(context, self, service_instance.policies,
[2/5] incubator-ariatosca git commit: wip
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/mock/context.py -- diff --git a/tests/mock/context.py b/tests/mock/context.py index 5559675..f7be6b7 100644 --- a/tests/mock/context.py +++ b/tests/mock/context.py @@ -24,38 +24,39 @@ from . import models def simple(mapi_kwargs, resources_dir=None, **kwargs): model_storage = aria.application_model_storage(SQLAlchemyModelAPI, api_kwargs=mapi_kwargs) blueprint = models.get_blueprint() -model_storage.blueprint.put(blueprint) +model_storage.service_template.put(blueprint) deployment = models.get_deployment(blueprint) -model_storage.deployment.put(deployment) +model_storage.service_instance.put(deployment) # # Creating a simple deployment with node -> node as a graph dependency_node = models.get_dependency_node(deployment) -model_storage.node.put(dependency_node) -storage_dependency_node = model_storage.node.get(dependency_node.id) +model_storage.node_template.put(dependency_node) +storage_dependency_node = model_storage.node_template.get(dependency_node.id) -dependency_node_instance = models.get_dependency_node_instance(storage_dependency_node) -model_storage.node_instance.put(dependency_node_instance) -storage_dependency_node_instance = model_storage.node_instance.get(dependency_node_instance.id) +dependency_node_instance = models.get_dependency_node_instance(storage_dependency_node, + deployment) +model_storage.node.put(dependency_node_instance) +storage_dependency_node_instance = model_storage.node.get(dependency_node_instance.id) -dependent_node = models.get_dependent_node(deployment) -model_storage.node.put(dependent_node) -storage_dependent_node = model_storage.node.get(dependent_node.id) +req_template, cap_template = models.get_relationship(storage_dependency_node) +model_storage.requirement_template.put(req_template) +model_storage.capability_template.put(cap_template) -dependent_node_instance = models.get_dependent_node_instance(storage_dependent_node) -model_storage.node_instance.put(dependent_node_instance) -storage_dependent_node_instance = model_storage.node_instance.get(dependent_node_instance.id) +dependent_node = models.get_dependent_node(deployment, req_template, cap_template) +model_storage.node_template.put(dependent_node) +storage_dependent_node = model_storage.node_template.get(dependent_node.id) + +dependent_node_instance = models.get_dependent_node_instance(storage_dependent_node, deployment) +model_storage.node.put(dependent_node_instance) +storage_dependent_node_instance = model_storage.node.get(dependent_node_instance.id) -relationship = models.get_relationship(storage_dependent_node, storage_dependency_node) -model_storage.relationship.put(relationship) -storage_relationship = model_storage.relationship.get(relationship.id) relationship_instance = models.get_relationship_instance( -relationship=storage_relationship, target_instance=storage_dependency_node_instance, source_instance=storage_dependent_node_instance ) -model_storage.relationship_instance.put(relationship_instance) +model_storage.relationship.put(relationship_instance) # pytest tmpdir if resources_dir: @@ -70,7 +71,7 @@ def simple(mapi_kwargs, resources_dir=None, **kwargs): name='simple_context', model_storage=model_storage, resource_storage=resource_storage, -deployment_id=deployment.id, +service_instance_id=deployment.id, workflow_name=models.WORKFLOW_NAME, task_max_attempts=models.TASK_MAX_ATTEMPTS, task_retry_interval=models.TASK_RETRY_INTERVAL http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/mock/models.py -- diff --git a/tests/mock/models.py b/tests/mock/models.py index 8229038..0dbf8cc 100644 --- a/tests/mock/models.py +++ b/tests/mock/models.py @@ -15,8 +15,7 @@ from datetime import datetime -from aria.storage import model - +from aria.storage.modeling import model from . import operations DEPLOYMENT_NAME = 'test_deployment_id' @@ -35,84 +34,78 @@ RELATIONSHIP_INSTANCE_NAME = 'relationship_instance' def get_dependency_node(deployment): -return model.Node( +return model.NodeTemplate( name=DEPENDENCY_NODE_NAME, -type='test_node_type', +type_name='test_node_type', type_hierarchy=[], -number_of_instances=1, -planned_number_of_instances=1, -deploy_number_of_instances=1, -properties={}, -operations=dict((key, {}) for key in operations.N
[1/5] incubator-ariatosca git commit: wip [Forced Update!]
Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-44-Merge-parser-and-storage-models 0072cd64d -> 82d9be7d5 (forced update) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/storage/test_models.py -- diff --git a/tests/storage/test_models.py b/tests/storage/test_models.py deleted file mode 100644 index 2088676..000 --- a/tests/storage/test_models.py +++ /dev/null @@ -1,919 +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 datetime import datetime -from contextlib import contextmanager - -import pytest - -from aria import application_model_storage -from aria.storage import ( -exceptions, -sql_mapi, -) -from aria.storage.model import ( -DeploymentUpdateStep, -Blueprint, -Execution, -Task, -Plugin, -Deployment, -Node, -NodeInstance, -Relationship, -RelationshipInstance, -DeploymentUpdate, -DeploymentModification, -) - - -from tests import mock -from tests.storage import get_sqlite_api_kwargs, release_sqlite_storage - - -@contextmanager -def sql_storage(storage_func): -storage = None -try: -storage = storage_func() -yield storage -finally: -if storage: -release_sqlite_storage(storage) - - -def _empty_storage(): -return application_model_storage(sql_mapi.SQLAlchemyModelAPI, - api_kwargs=get_sqlite_api_kwargs()) - - -def _blueprint_storage(): -storage = _empty_storage() -blueprint = mock.models.get_blueprint() -storage.blueprint.put(blueprint) -return storage - - -def _deployment_storage(): -storage = _blueprint_storage() -deployment = mock.models.get_deployment(storage.blueprint.list()[0]) -storage.deployment.put(deployment) -return storage - - -def _deployment_update_storage(): -storage = _deployment_storage() -deployment_update = DeploymentUpdate( -deployment=storage.deployment.list()[0], -created_at=now, -deployment_plan={}, -) -storage.deployment_update.put(deployment_update) -return storage - - -def _node_storage(): -storage = _deployment_storage() -node = mock.models.get_dependency_node(storage.deployment.list()[0]) -storage.node.put(node) -return storage - - -def _nodes_storage(): -storage = _deployment_storage() -dependent_node = mock.models.get_dependent_node(storage.deployment.list()[0]) -dependency_node = mock.models.get_dependency_node(storage.deployment.list()[0]) -storage.node.put(dependent_node) -storage.node.put(dependency_node) -return storage - - -def _node_instances_storage(): -storage = _nodes_storage() -dependent_node = storage.node.get_by_name(mock.models.DEPENDENT_NODE_NAME) -dependency_node = storage.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME) -dependency_node_instance = mock.models.get_dependency_node_instance(dependency_node) -dependent_node_instance = mock.models.get_dependent_node_instance(dependent_node) -storage.node_instance.put(dependency_node_instance) -storage.node_instance.put(dependent_node_instance) -return storage - - -def _execution_storage(): -storage = _deployment_storage() -execution = mock.models.get_execution(storage.deployment.list()[0]) -plugin = mock.models.get_plugin() -storage.execution.put(execution) -storage.plugin.put(plugin) -return storage - - -@pytest.fixture -def empty_storage(): -with sql_storage(_empty_storage) as storage: -yield storage - - -@pytest.fixture -def blueprint_storage(): -with sql_storage(_blueprint_storage) as storage: -yield storage - - -@pytest.fixture -def deployment_storage(): -with sql_storage(_deployment_storage) as storage: -yield storage - - -@pytest.fixture -def deployment_update_storage(): -with sql_storage(_deployment_update_storage) as storage: -yield storage - - -@pytest.fixture -def node_storage(): -with sql_storage(_node_storage) as storage: -yield storage - - -@pytest.fixture -def nodes_storage(): -with sql_storage(_nodes_storage) as storage: -yield storage - - -@pytes