You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2017/01/29 09:09:45 UTC
[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..0000000
--- 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
-
-
-@pytest.fixture
-def node_instances_storage():
- with sql_storage(_node_instances_storage) as storage:
- yield storage
-
-
-@pytest.fixture
-def execution_storage():
- with sql_storage(_execution_storage) as storage:
- yield storage
-
-
-m_cls = type('MockClass')
-now = datetime.utcnow()
-
-
-def _test_model(is_valid, storage, model_name, model_cls, model_kwargs):
- if is_valid:
- model = model_cls(**model_kwargs)
- getattr(storage, model_name).put(model)
- return model
- else:
- with pytest.raises(exceptions.StorageError):
- getattr(storage, model_name).put(model_cls(**model_kwargs))
-
-
-class TestBlueprint(object):
-
- @pytest.mark.parametrize(
- 'is_valid, plan, description, created_at, updated_at, main_file_name',
- [
- (False, None, 'description', now, now, '/path'),
- (False, {}, {}, now, now, '/path'),
- (False, {}, 'description', 'error', now, '/path'),
- (False, {}, 'description', now, 'error', '/path'),
- (False, {}, 'description', now, now, {}),
- (True, {}, 'description', now, now, '/path'),
- ]
- )
- def test_blueprint_model_creation(self, empty_storage, is_valid, plan, description, created_at,
- updated_at, main_file_name):
- _test_model(is_valid=is_valid,
- storage=empty_storage,
- model_name='blueprint',
- model_cls=Blueprint,
- model_kwargs=dict(plan=plan,
- description=description,
- created_at=created_at,
- updated_at=updated_at,
- main_file_name=main_file_name))
-
-
-class TestDeployment(object):
-
- @pytest.mark.parametrize(
- 'is_valid, name, created_at, description, inputs, groups, permalink, policy_triggers, '
- 'policy_types, outputs, scaling_groups, updated_at, workflows',
- [
- (False, m_cls, now, 'desc', {}, {}, 'perlnk', {}, {}, {}, {}, now, {}),
- (False, 'name', m_cls, 'desc', {}, {}, 'perlnk', {}, {}, {}, {}, now, {}),
- (False, 'name', now, m_cls, {}, {}, 'perlnk', {}, {}, {}, {}, now, {}),
- (False, 'name', now, 'desc', m_cls, {}, 'perlnk', {}, {}, {}, {}, now, {}),
- (False, 'name', now, 'desc', {}, m_cls, 'perlnk', {}, {}, {}, {}, now, {}),
- (False, 'name', now, 'desc', {}, {}, m_cls, {}, {}, {}, {}, now, {}),
- (False, 'name', now, 'desc', {}, {}, 'perlnk', m_cls, {}, {}, {}, now, {}),
- (False, 'name', now, 'desc', {}, {}, 'perlnk', {}, m_cls, {}, {}, now, {}),
- (False, 'name', now, 'desc', {}, {}, 'perlnk', {}, {}, m_cls, {}, now, {}),
- (False, 'name', now, 'desc', {}, {}, 'perlnk', {}, {}, {}, m_cls, now, {}),
- (False, 'name', now, 'desc', {}, {}, 'perlnk', {}, {}, {}, {}, m_cls, {}),
- (False, 'name', now, 'desc', {}, {}, 'perlnk', {}, {}, {}, {}, now, m_cls),
-
- (True, 'name', now, 'desc', {}, {}, 'perlnk', {}, {}, {}, {}, now, {}),
- (True, None, now, 'desc', {}, {}, 'perlnk', {}, {}, {}, {}, now, {}),
- (True, 'name', now, 'desc', {}, {}, 'perlnk', {}, {}, {}, {}, now, {}),
- (True, 'name', now, None, {}, {}, 'perlnk', {}, {}, {}, {}, now, {}),
- (True, 'name', now, 'desc', None, {}, 'perlnk', {}, {}, {}, {}, now, {}),
- (True, 'name', now, 'desc', {}, None, 'perlnk', {}, {}, {}, {}, now, {}),
- (True, 'name', now, 'desc', {}, {}, None, {}, {}, {}, {}, now, {}),
- (True, 'name', now, 'desc', {}, {}, 'perlnk', None, {}, {}, {}, now, {}),
- (True, 'name', now, 'desc', {}, {}, 'perlnk', {}, None, {}, {}, now, {}),
- (True, 'name', now, 'desc', {}, {}, 'perlnk', {}, {}, None, {}, now, {}),
- (True, 'name', now, 'desc', {}, {}, 'perlnk', {}, {}, {}, None, now, {}),
- (True, 'name', now, 'desc', {}, {}, 'perlnk', {}, {}, {}, {}, None, {}),
- (True, 'name', now, 'desc', {}, {}, 'perlnk', {}, {}, {}, {}, now, None),
- ]
- )
- def test_deployment_model_creation(self, deployment_storage, is_valid, name, created_at,
- description, inputs, groups, permalink, policy_triggers,
- policy_types, outputs, scaling_groups, updated_at,
- workflows):
- deployment = _test_model(is_valid=is_valid,
- storage=deployment_storage,
- model_name='deployment',
- model_cls=Deployment,
- model_kwargs=dict(
- name=name,
- blueprint=deployment_storage.blueprint.list()[0],
- created_at=created_at,
- description=description,
- inputs=inputs,
- groups=groups,
- permalink=permalink,
- policy_triggers=policy_triggers,
- policy_types=policy_types,
- outputs=outputs,
- scaling_groups=scaling_groups,
- updated_at=updated_at,
- workflows=workflows
- ))
- if is_valid:
- assert deployment.blueprint == deployment_storage.blueprint.list()[0]
-
-
-class TestExecution(object):
-
- @pytest.mark.parametrize(
- 'is_valid, created_at, started_at, ended_at, error, is_system_workflow, parameters, '
- 'status, workflow_name',
- [
- (False, m_cls, now, now, 'error', False, {}, Execution.STARTED, 'wf_name'),
- (False, now, m_cls, now, 'error', False, {}, Execution.STARTED, 'wf_name'),
- (False, now, now, m_cls, 'error', False, {}, Execution.STARTED, 'wf_name'),
- (False, now, now, now, m_cls, False, {}, Execution.STARTED, 'wf_name'),
- (False, now, now, now, 'error', False, m_cls, Execution.STARTED, 'wf_name'),
- (False, now, now, now, 'error', False, {}, m_cls, 'wf_name'),
- (False, now, now, now, 'error', False, {}, Execution.STARTED, m_cls),
-
- (True, now, now, now, 'error', False, {}, Execution.STARTED, 'wf_name'),
- (True, now, None, now, 'error', False, {}, Execution.STARTED, 'wf_name'),
- (True, now, now, None, 'error', False, {}, Execution.STARTED, 'wf_name'),
- (True, now, now, now, None, False, {}, Execution.STARTED, 'wf_name'),
- (True, now, now, now, 'error', False, None, Execution.STARTED, 'wf_name'),
- ]
- )
- def test_execution_model_creation(self, deployment_storage, is_valid, created_at, started_at,
- ended_at, error, is_system_workflow, parameters, status,
- workflow_name):
- execution = _test_model(is_valid=is_valid,
- storage=deployment_storage,
- model_name='execution',
- model_cls=Execution,
- model_kwargs=dict(
- deployment=deployment_storage.deployment.list()[0],
- created_at=created_at,
- started_at=started_at,
- ended_at=ended_at,
- error=error,
- is_system_workflow=is_system_workflow,
- parameters=parameters,
- status=status,
- workflow_name=workflow_name,
- ))
- if is_valid:
- assert execution.deployment == deployment_storage.deployment.list()[0]
- assert execution.blueprint == deployment_storage.blueprint.list()[0]
-
- def test_execution_status_transition(self):
- def create_execution(status):
- execution = Execution(
- id='e_id',
- workflow_name='w_name',
- status=status,
- parameters={},
- created_at=now,
- )
- return execution
-
- valid_transitions = {
- Execution.PENDING: [Execution.STARTED,
- Execution.CANCELLED,
- Execution.PENDING],
- Execution.STARTED: [Execution.FAILED,
- Execution.TERMINATED,
- Execution.CANCELLED,
- Execution.CANCELLING,
- Execution.STARTED],
- Execution.CANCELLING: [Execution.FAILED,
- Execution.TERMINATED,
- Execution.CANCELLED,
- Execution.CANCELLING],
- Execution.FAILED: [Execution.FAILED],
- Execution.TERMINATED: [Execution.TERMINATED],
- Execution.CANCELLED: [Execution.CANCELLED]
- }
-
- invalid_transitions = {
- Execution.PENDING: [Execution.FAILED,
- Execution.TERMINATED,
- Execution.CANCELLING],
- Execution.STARTED: [Execution.PENDING],
- Execution.CANCELLING: [Execution.PENDING,
- Execution.STARTED],
- Execution.FAILED: [Execution.PENDING,
- Execution.STARTED,
- Execution.TERMINATED,
- Execution.CANCELLED,
- Execution.CANCELLING],
- Execution.TERMINATED: [Execution.PENDING,
- Execution.STARTED,
- Execution.FAILED,
- Execution.CANCELLED,
- Execution.CANCELLING],
- Execution.CANCELLED: [Execution.PENDING,
- Execution.STARTED,
- Execution.FAILED,
- Execution.TERMINATED,
- Execution.CANCELLING],
- }
-
- for current_status, valid_transitioned_statues in valid_transitions.items():
- for transitioned_status in valid_transitioned_statues:
- execution = create_execution(current_status)
- execution.status = transitioned_status
-
- for current_status, invalid_transitioned_statues in invalid_transitions.items():
- for transitioned_status in invalid_transitioned_statues:
- execution = create_execution(current_status)
- with pytest.raises(ValueError):
- execution.status = transitioned_status
-
-
-class TestDeploymentUpdate(object):
- @pytest.mark.parametrize(
- 'is_valid, created_at, deployment_plan, deployment_update_node_instances, '
- 'deployment_update_deployment, deployment_update_nodes, modified_entity_ids, state',
- [
- (False, m_cls, {}, {}, {}, [], {}, 'state'),
- (False, now, m_cls, {}, {}, [], {}, 'state'),
- (False, now, {}, m_cls, {}, [], {}, 'state'),
- (False, now, {}, {}, m_cls, [], {}, 'state'),
- (False, now, {}, {}, {}, m_cls, {}, 'state'),
- (False, now, {}, {}, {}, [], m_cls, 'state'),
- (False, now, {}, {}, {}, [], {}, m_cls),
-
- (True, now, {}, {}, {}, [], {}, 'state'),
- (True, now, {}, None, {}, [], {}, 'state'),
- (True, now, {}, {}, None, [], {}, 'state'),
- (True, now, {}, {}, {}, None, {}, 'state'),
- (True, now, {}, {}, {}, [], None, 'state'),
- (True, now, {}, {}, {}, [], {}, None),
- ]
- )
- def test_deployment_update_model_creation(self, deployment_storage, is_valid, created_at,
- deployment_plan, deployment_update_node_instances,
- deployment_update_deployment, deployment_update_nodes,
- modified_entity_ids, state):
- deployment_update = _test_model(
- is_valid=is_valid,
- storage=deployment_storage,
- model_name='deployment_update',
- model_cls=DeploymentUpdate,
- model_kwargs=dict(
- deployment=deployment_storage.deployment.list()[0],
- created_at=created_at,
- deployment_plan=deployment_plan,
- deployment_update_node_instances=deployment_update_node_instances,
- deployment_update_deployment=deployment_update_deployment,
- deployment_update_nodes=deployment_update_nodes,
- modified_entity_ids=modified_entity_ids,
- state=state,
- ))
- if is_valid:
- assert deployment_update.deployment == deployment_storage.deployment.list()[0]
-
-
-class TestDeploymentUpdateStep(object):
-
- @pytest.mark.parametrize(
- 'is_valid, action, entity_id, entity_type',
- [
- (False, m_cls, 'id', DeploymentUpdateStep.ENTITY_TYPES.NODE),
- (False, DeploymentUpdateStep.ACTION_TYPES.ADD, m_cls,
- DeploymentUpdateStep.ENTITY_TYPES.NODE),
- (False, DeploymentUpdateStep.ACTION_TYPES.ADD, 'id', m_cls),
-
- (True, DeploymentUpdateStep.ACTION_TYPES.ADD, 'id',
- DeploymentUpdateStep.ENTITY_TYPES.NODE)
- ]
- )
- def test_deployment_update_step_model_creation(self, deployment_update_storage, is_valid,
- action, entity_id, entity_type):
- deployment_update_step = _test_model(
- is_valid=is_valid,
- storage=deployment_update_storage,
- model_name='deployment_update_step',
- model_cls=DeploymentUpdateStep,
- model_kwargs=dict(
- deployment_update=deployment_update_storage.deployment_update.list()[0],
- action=action,
- entity_id=entity_id,
- entity_type=entity_type
- ))
- if is_valid:
- assert deployment_update_step.deployment_update == \
- deployment_update_storage.deployment_update.list()[0]
-
- def test_deployment_update_step_order(self):
- add_node = DeploymentUpdateStep(
- id='add_step',
- action='add',
- entity_type='node',
- entity_id='node_id')
-
- modify_node = DeploymentUpdateStep(
- id='modify_step',
- action='modify',
- entity_type='node',
- entity_id='node_id')
-
- remove_node = DeploymentUpdateStep(
- id='remove_step',
- action='remove',
- entity_type='node',
- entity_id='node_id')
-
- for step in (add_node, modify_node, remove_node):
- assert hash((step.id, step.entity_id)) == hash(step)
-
- assert remove_node < modify_node < add_node
- assert not remove_node > modify_node > add_node
-
- add_rel = DeploymentUpdateStep(
- id='add_step',
- action='add',
- entity_type='relationship',
- entity_id='relationship_id')
-
- remove_rel = DeploymentUpdateStep(
- id='remove_step',
- action='remove',
- entity_type='relationship',
- entity_id='relationship_id')
-
- assert remove_rel < remove_node < add_node < add_rel
- assert not add_node < None
-
-
-class TestDeploymentModification(object):
- @pytest.mark.parametrize(
- 'is_valid, context, created_at, ended_at, modified_nodes, node_instances, status',
- [
- (False, m_cls, now, now, {}, {}, DeploymentModification.STARTED),
- (False, {}, m_cls, now, {}, {}, DeploymentModification.STARTED),
- (False, {}, now, m_cls, {}, {}, DeploymentModification.STARTED),
- (False, {}, now, now, m_cls, {}, DeploymentModification.STARTED),
- (False, {}, now, now, {}, m_cls, DeploymentModification.STARTED),
- (False, {}, now, now, {}, {}, m_cls),
-
- (True, {}, now, now, {}, {}, DeploymentModification.STARTED),
- (True, {}, now, None, {}, {}, DeploymentModification.STARTED),
- (True, {}, now, now, None, {}, DeploymentModification.STARTED),
- (True, {}, now, now, {}, None, DeploymentModification.STARTED),
- ]
- )
- def test_deployment_modification_model_creation(self, deployment_storage, is_valid, context,
- created_at, ended_at, modified_nodes,
- node_instances, status):
- deployment_modification = _test_model(
- is_valid=is_valid,
- storage=deployment_storage,
- model_name='deployment_modification',
- model_cls=DeploymentModification,
- model_kwargs=dict(
- deployment=deployment_storage.deployment.list()[0],
- context=context,
- created_at=created_at,
- ended_at=ended_at,
- modified_nodes=modified_nodes,
- node_instances=node_instances,
- status=status,
- ))
- if is_valid:
- assert deployment_modification.deployment == deployment_storage.deployment.list()[0]
-
-
-class TestNode(object):
- @pytest.mark.parametrize(
- 'is_valid, name, deploy_number_of_instances, max_number_of_instances, '
- 'min_number_of_instances, number_of_instances, planned_number_of_instances, plugins, '
- 'properties, operations, type, type_hierarchy',
- [
- (False, m_cls, 1, 1, 1, 1, 1, [], {}, {}, 'type', []),
- (False, 'name', m_cls, 1, 1, 1, 1, [], {}, {}, 'type', []),
- (False, 'name', 1, m_cls, 1, 1, 1, [], {}, {}, 'type', []),
- (False, 'name', 1, 1, m_cls, 1, 1, [], {}, {}, 'type', []),
- (False, 'name', 1, 1, 1, m_cls, 1, [], {}, {}, 'type', []),
- (False, 'name', 1, 1, 1, 1, m_cls, [], {}, {}, 'type', []),
- (False, 'name', 1, 1, 1, 1, 1, m_cls, {}, {}, 'type', []),
- (False, 'name', 1, 1, 1, 1, 1, [], m_cls, {}, 'type', []),
- (False, 'name', 1, 1, 1, 1, 1, [], {}, m_cls, 'type', []),
- (False, 'name', 1, 1, 1, 1, 1, [], {}, {}, m_cls, []),
- (False, 'name', 1, 1, 1, 1, 1, [], {}, {}, 'type', m_cls),
-
- (True, 'name', 1, 1, 1, 1, 1, [], {}, {}, 'type', []),
- (True, 'name', 1, 1, 1, 1, 1, None, {}, {}, 'type', []),
- (True, 'name', 1, 1, 1, 1, 1, [], None, {}, 'type', []),
- (True, 'name', 1, 1, 1, 1, 1, [], {}, None, 'type', []),
- (True, 'name', 1, 1, 1, 1, 1, [], {}, {}, 'type', None),
- ]
- )
- def test_node_model_creation(self, deployment_storage, is_valid, name,
- deploy_number_of_instances, max_number_of_instances,
- min_number_of_instances, number_of_instances,
- planned_number_of_instances, plugins,
- properties, operations, type, type_hierarchy):
- node = _test_model(
- is_valid=is_valid,
- storage=deployment_storage,
- model_name='node',
- model_cls=Node,
- model_kwargs=dict(
- name=name,
- deploy_number_of_instances=deploy_number_of_instances,
- max_number_of_instances=max_number_of_instances,
- min_number_of_instances=min_number_of_instances,
- number_of_instances=number_of_instances,
- planned_number_of_instances=planned_number_of_instances,
- plugins=plugins,
- properties=properties,
- operations=operations,
- type=type,
- type_hierarchy=type_hierarchy,
- deployment=deployment_storage.deployment.list()[0]
- ))
- if is_valid:
- assert node.deployment == deployment_storage.deployment.list()[0]
-
-
-class TestRelationship(object):
- @pytest.mark.parametrize(
- 'is_valid, source_interfaces, source_operations, target_interfaces, target_operations, '
- 'type, type_hierarchy, properties',
- [
- (False, m_cls, {}, {}, {}, 'type', [], {}),
- (False, {}, m_cls, {}, {}, 'type', [], {}),
- (False, {}, {}, m_cls, {}, 'type', [], {}),
- (False, {}, {}, {}, m_cls, 'type', [], {}),
- (False, {}, {}, {}, {}, m_cls, [], {}),
- (False, {}, {}, {}, {}, 'type', m_cls, {}),
- (False, {}, {}, {}, {}, 'type', [], m_cls),
-
- (True, {}, {}, {}, {}, 'type', [], {}),
- (True, None, {}, {}, {}, 'type', [], {}),
- (True, {}, {}, None, {}, 'type', [], {}),
- (True, {}, {}, {}, {}, 'type', None, {}),
- (True, {}, {}, {}, {}, 'type', [], None),
- ]
- )
- def test_relationship_model_ceration(self, nodes_storage, is_valid, source_interfaces,
- source_operations, target_interfaces, target_operations,
- type, type_hierarchy, properties):
- relationship = _test_model(
- is_valid=is_valid,
- storage=nodes_storage,
- model_name='relationship',
- model_cls=Relationship,
- model_kwargs=dict(
- source_node=nodes_storage.node.list()[1],
- target_node=nodes_storage.node.list()[0],
- source_interfaces=source_interfaces,
- source_operations=source_operations,
- target_interfaces=target_interfaces,
- target_operations=target_operations,
- type=type,
- type_hierarchy=type_hierarchy,
- properties=properties,
- ))
- if is_valid:
- assert relationship.source_node == nodes_storage.node.list()[1]
- assert relationship.target_node == nodes_storage.node.list()[0]
-
-
-class TestNodeInstance(object):
- @pytest.mark.parametrize(
- 'is_valid, name, runtime_properties, scaling_groups, state, version',
- [
- (False, m_cls, {}, [], 'state', 1),
- (False, 'name', m_cls, [], 'state', 1),
- (False, 'name', {}, m_cls, 'state', 1),
- (False, 'name', {}, [], m_cls, 1),
- (False, m_cls, {}, [], 'state', m_cls),
-
- (True, 'name', {}, [], 'state', 1),
- (True, None, {}, [], 'state', 1),
- (True, 'name', None, [], 'state', 1),
- (True, 'name', {}, None, 'state', 1),
- (True, 'name', {}, [], 'state', None),
- ]
- )
- def test_node_instance_model_creation(self, node_storage, is_valid, name, runtime_properties,
- scaling_groups, state, version):
- node_instance = _test_model(
- is_valid=is_valid,
- storage=node_storage,
- model_name='node_instance',
- model_cls=NodeInstance,
- model_kwargs=dict(
- node=node_storage.node.list()[0],
- name=name,
- runtime_properties=runtime_properties,
- scaling_groups=scaling_groups,
- state=state,
- version=version,
- ))
- if is_valid:
- assert node_instance.node == node_storage.node.list()[0]
- assert node_instance.deployment == node_storage.deployment.list()[0]
-
-
-class TestNodeInstanceIP(object):
-
- ip = '1.1.1.1'
-
- def test_ip_on_none_hosted_node_instance(self, deployment_storage):
- node = self._node(deployment_storage, ip='not considered')
- node_instance = self._node_instance(deployment_storage, node,
- is_host=False,
- ip='not considered')
- assert node_instance.ip is None
-
- def test_property_ip_on_host_node_instance(self, deployment_storage):
- node = self._node(deployment_storage, ip=self.ip)
- node_instance = self._node_instance(deployment_storage, node,
- is_host=True,
- ip=None)
- assert node_instance.ip == self.ip
-
- def test_runtime_property_ip_on_host_node_instance(self, deployment_storage):
- node = self._node(deployment_storage, ip='not considered')
- node_instance = self._node_instance(deployment_storage, node,
- is_host=True,
- ip=self.ip)
- assert node_instance.ip == self.ip
-
- def test_no_ip_configured_on_host_node_instance(self, deployment_storage):
- node = self._node(deployment_storage, ip=None)
- node_instance = self._node_instance(deployment_storage, node,
- is_host=True,
- ip=None)
- assert node_instance.ip is None
-
- def test_runtime_property_on_hosted_node_instance(self, deployment_storage):
- host_node = self._node(deployment_storage, ip=None)
- host_node_instance = self._node_instance(deployment_storage, host_node,
- is_host=True,
- ip=self.ip)
- node = self._node(deployment_storage, ip=None)
- node_instance = self._node_instance(deployment_storage, node,
- is_host=False,
- ip=None,
- host_fk=host_node_instance.id)
- assert node_instance.ip == self.ip
-
- def _node(self, storage, ip):
- kwargs = dict(
- name='node',
- deploy_number_of_instances=1,
- max_number_of_instances=1,
- min_number_of_instances=1,
- number_of_instances=1,
- planned_number_of_instances=1,
- properties={},
- type='',
- deployment=storage.deployment.list()[0]
- )
- if ip:
- kwargs['properties']['ip'] = ip
- node = Node(**kwargs)
- storage.node.put(node)
- return node
-
- def _node_instance(self, storage, node, is_host, ip, host_fk=None):
- kwargs = dict(
- name='node_instance',
- node=node,
- runtime_properties={},
- state=''
- )
- if ip:
- kwargs['runtime_properties']['ip'] = ip
- if is_host:
- kwargs['host_fk'] = 1
- elif host_fk:
- kwargs['host_fk'] = host_fk
- node_instance = NodeInstance(**kwargs)
- storage.node_instance.put(node_instance)
- return node_instance
-
-
-class TestRelationshipInstance(object):
- def test_relatiship_instance_model_creation(self, node_instances_storage):
- relationship = mock.models.get_relationship(
- source=node_instances_storage.node.get_by_name(mock.models.DEPENDENT_NODE_NAME),
- target=node_instances_storage.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME)
- )
- node_instances_storage.relationship.put(relationship)
- node_instances = node_instances_storage.node_instance
- source_node_instance = node_instances.get_by_name(mock.models.DEPENDENT_NODE_INSTANCE_NAME)
- target_node_instance = node_instances.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
-
- relationship_instance = _test_model(
- is_valid=True,
- storage=node_instances_storage,
- model_name='relationship_instance',
- model_cls=RelationshipInstance,
- model_kwargs=dict(
- relationship=relationship,
- source_node_instance=source_node_instance,
- target_node_instance=target_node_instance
- ))
- assert relationship_instance.relationship == relationship
- assert relationship_instance.source_node_instance == source_node_instance
- assert relationship_instance.target_node_instance == target_node_instance
-
-
-class TestPlugin(object):
- @pytest.mark.parametrize(
- 'is_valid, archive_name, distribution, distribution_release, '
- 'distribution_version, package_name, package_source, '
- 'package_version, supported_platform, supported_py_versions, uploaded_at, wheels',
- [
- (False, m_cls, 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src', 'pak_ver',
- 'sup_plat', [], now, []),
- (False, 'arc_name', m_cls, 'dis_rel', 'dis_ver', 'pak_name', 'pak_src', 'pak_ver',
- 'sup_plat', [], now, []),
- (False, 'arc_name', 'dis_name', m_cls, 'dis_ver', 'pak_name', 'pak_src', 'pak_ver',
- 'sup_plat', [], now, []),
- (False, 'arc_name', 'dis_name', 'dis_rel', m_cls, 'pak_name', 'pak_src', 'pak_ver',
- 'sup_plat', [], now, []),
- (False, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', m_cls, 'pak_src', 'pak_ver',
- 'sup_plat', [], now, []),
- (False, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', m_cls, 'pak_ver',
- 'sup_plat', [], now, []),
- (False, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src', m_cls,
- 'sup_plat', [], now, []),
- (False, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src',
- 'pak_ver', m_cls, [], now, []),
- (False, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src',
- 'pak_ver', 'sup_plat', m_cls, now, []),
- (False, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src',
- 'pak_ver', 'sup_plat', [], m_cls, []),
- (False, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src',
- 'pak_ver', 'sup_plat', [], now, m_cls),
-
- (True, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src', 'pak_ver',
- 'sup_plat', [], now, []),
- (True, 'arc_name', None, 'dis_rel', 'dis_ver', 'pak_name', 'pak_src', 'pak_ver',
- 'sup_plat', [], now, []),
- (True, 'arc_name', 'dis_name', None, 'dis_ver', 'pak_name', 'pak_src', 'pak_ver',
- 'sup_plat', [], now, []),
- (True, 'arc_name', 'dis_name', 'dis_rel', None, 'pak_name', 'pak_src', 'pak_ver',
- 'sup_plat', [], now, []),
- (True, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src',
- 'pak_ver', 'sup_plat', [], now, []),
- (True, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', None, 'pak_ver',
- 'sup_plat', [], now, []),
- (True, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src', None,
- 'sup_plat', [], now, []),
- (True, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src',
- 'pak_ver', None, [], now, []),
- (True, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src',
- 'pak_ver', 'sup_plat', None, now, []),
- (True, 'arc_name', 'dis_name', 'dis_rel', 'dis_ver', 'pak_name', 'pak_src',
- 'pak_ver', 'sup_plat', [], now, []),
- ]
- )
- def test_plugin_model_creation(self, empty_storage, is_valid, archive_name, distribution,
- distribution_release, distribution_version,
- package_name, package_source, package_version,
- supported_platform, supported_py_versions, uploaded_at, wheels):
- _test_model(is_valid=is_valid,
- storage=empty_storage,
- model_name='plugin',
- model_cls=Plugin,
- model_kwargs=dict(
- archive_name=archive_name,
- distribution=distribution,
- distribution_release=distribution_release,
- distribution_version=distribution_version,
- package_name=package_name,
- package_source=package_source,
- package_version=package_version,
- supported_platform=supported_platform,
- supported_py_versions=supported_py_versions,
- uploaded_at=uploaded_at,
- wheels=wheels,
- ))
-
-
-class TestTask(object):
-
- @pytest.mark.parametrize(
- 'is_valid, status, due_at, started_at, ended_at, max_attempts, retry_count, '
- 'retry_interval, ignore_failure, name, operation_mapping, inputs, plugin_id',
- [
- (False, m_cls, now, now, now, 1, 1, 1, True, 'name', 'map', {}, '1'),
- (False, Task.STARTED, m_cls, now, now, 1, 1, 1, True, 'name', 'map', {}, '1'),
- (False, Task.STARTED, now, m_cls, now, 1, 1, 1, True, 'name', 'map', {}, '1'),
- (False, Task.STARTED, now, now, m_cls, 1, 1, 1, True, 'name', 'map', {}, '1'),
- (False, Task.STARTED, now, now, now, m_cls, 1, 1, True, 'name', 'map', {}, '1'),
- (False, Task.STARTED, now, now, now, 1, m_cls, 1, True, 'name', 'map', {}, '1'),
- (False, Task.STARTED, now, now, now, 1, 1, m_cls, True, 'name', 'map', {}, '1'),
- (False, Task.STARTED, now, now, now, 1, 1, 1, True, m_cls, 'map', {}, '1'),
- (False, Task.STARTED, now, now, now, 1, 1, 1, True, 'name', m_cls, {}, '1'),
- (False, Task.STARTED, now, now, now, 1, 1, 1, True, 'name', 'map', m_cls, '1'),
- (False, Task.STARTED, now, now, now, 1, 1, 1, True, 'name', 'map', {}, m_cls),
-
- (True, Task.STARTED, now, now, now, 1, 1, 1, True, 'name', 'map', {}, '1'),
- (True, Task.STARTED, None, now, now, 1, 1, 1, True, 'name', 'map', {}, '1'),
- (True, Task.STARTED, now, None, now, 1, 1, 1, True, 'name', 'map', {}, '1'),
- (True, Task.STARTED, now, now, None, 1, 1, 1, True, 'name', 'map', {}, '1'),
- (True, Task.STARTED, now, now, now, 1, None, 1, True, 'name', 'map', {}, '1'),
- (True, Task.STARTED, now, now, now, 1, 1, None, True, 'name', 'map', {}, '1'),
- (True, Task.STARTED, now, now, now, 1, 1, 1, None, 'name', 'map', {}, '1'),
- (True, Task.STARTED, now, now, now, 1, 1, 1, True, None, 'map', {}, '1'),
- (True, Task.STARTED, now, now, now, 1, 1, 1, True, 'name', None, {}, '1'),
- (True, Task.STARTED, now, now, now, 1, 1, 1, True, 'name', 'map', None, '1'),
- (True, Task.STARTED, now, now, now, 1, 1, 1, True, 'name', 'map', {}, None),
- ]
- )
- def test_task_model_creation(self, execution_storage, is_valid, status, due_at, started_at,
- ended_at, max_attempts, retry_count, retry_interval,
- ignore_failure, name, operation_mapping, inputs, plugin_id):
- task = _test_model(
- is_valid=is_valid,
- storage=execution_storage,
- model_name='task',
- model_cls=Task,
- model_kwargs=dict(
- status=status,
- execution=execution_storage.execution.list()[0],
- due_at=due_at,
- started_at=started_at,
- ended_at=ended_at,
- max_attempts=max_attempts,
- retry_count=retry_count,
- retry_interval=retry_interval,
- ignore_failure=ignore_failure,
- name=name,
- operation_mapping=operation_mapping,
- inputs=inputs,
- plugin_fk=plugin_id,
- ))
- if is_valid:
- assert task.execution == execution_storage.execution.list()[0]
- if task.plugin:
- assert task.plugin == execution_storage.plugin.list()[0]
-
- def test_task_max_attempts_validation(self):
- def create_task(max_attempts):
- Task(execution_fk='eid',
- name='name',
- operation_mapping='',
- inputs={},
- max_attempts=max_attempts)
- create_task(max_attempts=1)
- create_task(max_attempts=2)
- create_task(max_attempts=Task.INFINITE_RETRIES)
- with pytest.raises(ValueError):
- create_task(max_attempts=0)
- with pytest.raises(ValueError):
- create_task(max_attempts=-2)
[2/5] incubator-ariatosca git commit: wip
Posted by mx...@apache.org.
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.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,
status=model.Execution.STARTED,
workflow_name=WORKFLOW_NAME,
started_at=datetime.utcnow(),
@@ -134,19 +127,16 @@ def get_execution(deployment):
def get_deployment(blueprint):
now = datetime.utcnow()
- return model.Deployment(
+ return model.ServiceInstance(
name=DEPLOYMENT_NAME,
- blueprint_fk=blueprint.id,
+ service_template=blueprint,
description='',
created_at=now,
updated_at=now,
workflows={},
- inputs={},
- groups={},
permalink='',
policy_triggers={},
policy_types={},
- outputs={},
scaling_groups={},
)
@@ -165,3 +155,25 @@ def get_plugin(package_name='package', package_version='0.1'):
uploaded_at=datetime.now(),
wheels=[],
)
+
+
+def get_interface_template(operation_name, operation_kwargs=None, interface_kwargs=None):
+ operation_template = model.OperationTemplate(
+ name=operation_name,
+ **(operation_kwargs or {})
+
+ )
+ return model.InterfaceTemplate(
+ operation_templates=[operation_template],
+ name=operation_name.rsplit('.', 1)[0],
+ **(interface_kwargs or {})
+ )
+
+
+def get_interface(operation_name,
+ operation_kwargs=None,
+ interface_kwargs=None,
+ is_relationship=False):
+ operation = model.Operation(name=operation_name, **(operation_kwargs or {}))
+ interface_name = operation_name.rsplit('.', 2 if is_relationship else 1)[0]
+ return model.Interface(operations=[operation], name=interface_name, **(interface_kwargs or {}))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/context/test_operation.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_operation.py b/tests/orchestrator/context/test_operation.py
index b5f52a3..6f7eaee 100644
--- a/tests/orchestrator/context/test_operation.py
+++ b/tests/orchestrator/context/test_operation.py
@@ -52,14 +52,13 @@ def executor():
def test_node_operation_task_execution(ctx, executor):
operation_name = 'aria.interfaces.lifecycle.create'
- node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME)
- node.operations[operation_name] = {
- 'operation': op_path(my_operation, module_path=__name__)
-
- }
+ node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ interface = mock.models.get_interface(
+ operation_name,
+ operation_kwargs=dict(implementation=op_path(my_operation, module_path=__name__))
+ )
+ node.interfaces = [interface]
ctx.model.node.update(node)
- node_instance = ctx.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
-
inputs = {'putput': True}
@workflow
@@ -67,77 +66,78 @@ def test_node_operation_task_execution(ctx, executor):
graph.add_tasks(
api.task.OperationTask.node_instance(
name=operation_name,
- instance=node_instance,
+ instance=node,
inputs=inputs
)
)
execute(workflow_func=basic_workflow, workflow_context=ctx, executor=executor)
- operation_context = global_test_holder[op_name(node_instance, operation_name)]
+ operation_context = global_test_holder[op_name(node, operation_name)]
assert isinstance(operation_context, context.operation.NodeOperationContext)
# Task bases assertions
- assert operation_context.task.actor == node_instance
- assert operation_context.task.name == op_name(node_instance, operation_name)
- assert operation_context.task.operation_mapping == node.operations[operation_name]['operation']
+ assert operation_context.task.actor == node
+ assert operation_context.task.name == op_name(node, operation_name)
+ operations = interface.operations.filter_by(name=operation_name)
+ assert operations.count() == 1
+ assert operation_context.task.implementation == operations[0].implementation
assert operation_context.task.inputs == inputs
# Context based attributes (sugaring)
- assert operation_context.node == node_instance.node
- assert operation_context.node_instance == node_instance
+ assert operation_context.node_template == node.node_template
+ assert operation_context.node == node
def test_relationship_operation_task_execution(ctx, executor):
- operation_name = 'aria.interfaces.relationship_lifecycle.postconfigure'
+ operation_name = 'aria.interfaces.relationship_lifecycle.postconfigure.source'
relationship = ctx.model.relationship.list()[0]
- relationship.source_operations[operation_name] = {
- 'operation': op_path(my_operation, module_path=__name__)
- }
- ctx.model.relationship.update(relationship)
- relationship_instance = ctx.model.relationship_instance.list()[0]
- dependency_node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME)
- dependency_node_instance = \
- ctx.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
- dependent_node = ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_NAME)
- dependent_node_instance = \
- ctx.model.node_instance.get_by_name(mock.models.DEPENDENT_NODE_INSTANCE_NAME)
+ interface = mock.models.get_interface(
+ operation_name=operation_name,
+ operation_kwargs=dict(implementation=op_path(my_operation, module_path=__name__)),
+ is_relationship=True
+ )
+ relationship.source_interfaces = [interface]
+ ctx.model.relationship.update(relationship)
inputs = {'putput': True}
@workflow
def basic_workflow(graph, **_):
graph.add_tasks(
api.task.OperationTask.relationship_instance(
- instance=relationship_instance,
+ instance=relationship,
name=operation_name,
- operation_end=api.task.OperationTask.SOURCE_OPERATION,
inputs=inputs
)
)
execute(workflow_func=basic_workflow, workflow_context=ctx, executor=executor)
- operation_context = global_test_holder[op_name(relationship_instance, operation_name)]
+ operation_context = global_test_holder[op_name(relationship, operation_name)]
assert isinstance(operation_context, context.operation.RelationshipOperationContext)
# Task bases assertions
- assert operation_context.task.actor == relationship_instance
- assert operation_context.task.name == op_name(relationship_instance, operation_name)
- assert operation_context.task.operation_mapping == \
- relationship.source_operations[operation_name]['operation']
+ assert operation_context.task.actor == relationship
+ assert operation_context.task.name == op_name(relationship, operation_name)
+ operation = interface.operations.filter_by(name=operation_name)
+ assert operation_context.task.implementation == operation.all()[0].implementation
assert operation_context.task.inputs == inputs
# Context based attributes (sugaring)
+ dependency_node_template = ctx.model.node_template.get_by_name(mock.models.DEPENDENCY_NODE_NAME)
+ dependency_node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ dependent_node_template = ctx.model.node_template.get_by_name(mock.models.DEPENDENT_NODE_NAME)
+ dependent_node = ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_INSTANCE_NAME)
+
+ assert operation_context.target_node_template == dependency_node_template
assert operation_context.target_node == dependency_node
- assert operation_context.target_node_instance == dependency_node_instance
assert operation_context.relationship == relationship
- assert operation_context.relationship_instance == relationship_instance
+ assert operation_context.source_node_template == dependent_node_template
assert operation_context.source_node == dependent_node
- assert operation_context.source_node_instance == dependent_node_instance
def test_invalid_task_operation_id(ctx, executor):
@@ -149,28 +149,28 @@ def test_invalid_task_operation_id(ctx, executor):
:return:
"""
operation_name = 'aria.interfaces.lifecycle.create'
- other_node_instance, node_instance = ctx.model.node_instance.list()
- assert other_node_instance.id == 1
- assert node_instance.id == 2
-
- node = node_instance.node
- node.operations[operation_name] = {
- 'operation': op_path(get_node_instance_id, module_path=__name__)
-
- }
+ other_node, node = ctx.model.node.list()
+ assert other_node.id == 1
+ assert node.id == 2
+
+ interface = mock.models.get_interface(
+ operation_name=operation_name,
+ operation_kwargs=dict(implementation=op_path(get_node_instance_id, module_path=__name__))
+ )
+ node.interfaces = [interface]
ctx.model.node.update(node)
@workflow
def basic_workflow(graph, **_):
graph.add_tasks(
- api.task.OperationTask.node_instance(name=operation_name, instance=node_instance)
+ api.task.OperationTask.node_instance(name=operation_name, instance=node)
)
execute(workflow_func=basic_workflow, workflow_context=ctx, executor=executor)
- op_node_instance_id = global_test_holder[op_name(node_instance, operation_name)]
- assert op_node_instance_id == node_instance.id
- assert op_node_instance_id != other_node_instance.id
+ op_node_instance_id = global_test_holder[op_name(node, operation_name)]
+ assert op_node_instance_id == node.id
+ assert op_node_instance_id != other_node.id
@operation
@@ -180,7 +180,7 @@ def my_operation(ctx, **_):
@operation
def get_node_instance_id(ctx, **_):
- global_test_holder[ctx.name] = ctx.node_instance.id
+ global_test_holder[ctx.name] = ctx.node.id
@pytest.fixture(autouse=True)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/context/test_resource_render.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_resource_render.py b/tests/orchestrator/context/test_resource_render.py
index ca2ef42..3ba0873 100644
--- a/tests/orchestrator/context/test_resource_render.py
+++ b/tests/orchestrator/context/test_resource_render.py
@@ -17,7 +17,7 @@ import pytest
from tests import mock, storage
-_IMPLICIT_CTX_TEMPLATE = '{{ctx.deployment.name}}'
+_IMPLICIT_CTX_TEMPLATE = '{{ctx.service_instance.name}}'
_IMPLICIT_CTX_TEMPLATE_PATH = 'implicit-ctx.template'
_VARIABLES_TEMPLATE = '{{variable}}'
_VARIABLES_TEMPLATE_PATH = 'variables.template'
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/context/test_serialize.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_serialize.py b/tests/orchestrator/context/test_serialize.py
index ed0afcd..b33f2e7 100644
--- a/tests/orchestrator/context/test_serialize.py
+++ b/tests/orchestrator/context/test_serialize.py
@@ -49,9 +49,12 @@ def test_illegal_serialize_of_memory_model_storage(memory_model_storage):
@workflow
def _mock_workflow(ctx, graph):
- node_instance = ctx.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
- node_instance.node.operations['test.op'] = {'operation': _operation_mapping()}
- task = api.task.OperationTask.node_instance(instance=node_instance, name='test.op')
+ node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ node.interfaces = [mock.models.get_interface(
+ 'test.op',
+ operation_kwargs=dict(implementation=_operation_mapping())
+ )]
+ task = api.task.OperationTask.node_instance(instance=node, name='test.op')
graph.add_tasks(task)
return graph
@@ -61,14 +64,14 @@ def _mock_operation(ctx):
# We test several things in this operation
# ctx.task, ctx.node, etc... tell us that the model storage was properly re-created
# a correct ctx.task.operation_mapping tells us we kept the correct task_id
- assert ctx.task.operation_mapping == _operation_mapping()
+ assert ctx.task.implementation == _operation_mapping()
# a correct ctx.node.name tells us we kept the correct actor_id
- assert ctx.node.name == mock.models.DEPENDENCY_NODE_NAME
+ assert ctx.node.name == mock.models.DEPENDENCY_NODE_INSTANCE_NAME
# a correct ctx.name tells us we kept the correct name
assert ctx.name is not None
assert ctx.name == ctx.task.name
# a correct ctx.deployment.name tells us we kept the correct deployment_id
- assert ctx.deployment.name == mock.models.DEPLOYMENT_NAME
+ assert ctx.service_instance.name == mock.models.DEPLOYMENT_NAME
# Here we test that the resource storage was properly re-created
test_file_content = ctx.resource.blueprint.read(TEST_FILE_ENTRY_ID, TEST_FILE_NAME)
assert test_file_content == TEST_FILE_CONTENT
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/context/test_toolbelt.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_toolbelt.py b/tests/orchestrator/context/test_toolbelt.py
index b63811b..3ad4d40 100644
--- a/tests/orchestrator/context/test_toolbelt.py
+++ b/tests/orchestrator/context/test_toolbelt.py
@@ -48,45 +48,46 @@ def executor():
def _get_elements(workflow_context):
- dependency_node = workflow_context.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME)
- dependency_node.host = dependency_node
- workflow_context.model.node.update(dependency_node)
+ dependency_node_template = workflow_context.model.node_template.get_by_name(
+ mock.models.DEPENDENCY_NODE_NAME)
+ dependency_node_template.host = dependency_node_template
+ workflow_context.model.node.update(dependency_node_template)
- dependency_node_instance = workflow_context.model.node_instance.get_by_name(
+ dependency_node = workflow_context.model.node.get_by_name(
mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
- dependency_node_instance.host_fk = dependency_node_instance.id
- workflow_context.model.node_instance.update(dependency_node_instance)
+ dependency_node.host_fk = dependency_node.id
+ workflow_context.model.node.update(dependency_node)
- dependent_node = workflow_context.model.node.get_by_name(mock.models.DEPENDENT_NODE_NAME)
- dependent_node.host_fk = dependency_node.id
- workflow_context.model.node.update(dependent_node)
+ dependent_node_template = workflow_context.model.node_template.get_by_name(
+ mock.models.DEPENDENT_NODE_NAME)
+ dependent_node_template.host = dependency_node_template
+ workflow_context.model.node_template.update(dependent_node_template)
- dependent_node_instance = workflow_context.model.node_instance.get_by_name(
+ dependent_node = workflow_context.model.node.get_by_name(
mock.models.DEPENDENT_NODE_INSTANCE_NAME)
- dependent_node_instance.host_fk = dependent_node_instance.id
- workflow_context.model.node_instance.update(dependent_node_instance)
+ dependent_node.host = dependent_node
+ workflow_context.model.node.update(dependent_node)
relationship = workflow_context.model.relationship.list()[0]
- relationship_instance = workflow_context.model.relationship_instance.list()[0]
- return dependency_node, dependency_node_instance, dependent_node, dependent_node_instance, \
- relationship, relationship_instance
+ return dependency_node_template, dependency_node, dependent_node_template, dependent_node, \
+ relationship
def test_host_ip(workflow_context, executor):
operation_name = 'aria.interfaces.lifecycle.create'
- dependency_node, dependency_node_instance, _, _, _, _ = _get_elements(workflow_context)
- dependency_node.operations[operation_name] = {
- 'operation': op_path(host_ip, module_path=__name__)
-
- }
- workflow_context.model.node.put(dependency_node)
+ _, dependency_node, _, _, _ = _get_elements(workflow_context)
+ dependency_node.interfaces = [mock.models.get_interface(
+ operation_name,
+ operation_kwargs=dict(implementation=op_path(host_ip, module_path=__name__))
+ )]
+ workflow_context.model.node.update(dependency_node)
inputs = {'putput': True}
@workflow
def basic_workflow(graph, **_):
graph.add_tasks(
api.task.OperationTask.node_instance(
- instance=dependency_node_instance,
+ instance=dependency_node,
name=operation_name,
inputs=inputs
)
@@ -94,18 +95,20 @@ def test_host_ip(workflow_context, executor):
execute(workflow_func=basic_workflow, workflow_context=workflow_context, executor=executor)
- assert global_test_holder.get('host_ip') == \
- dependency_node_instance.runtime_properties.get('ip')
+ assert global_test_holder.get('host_ip') == dependency_node.runtime_properties.get('ip')
def test_relationship_tool_belt(workflow_context, executor):
- operation_name = 'aria.interfaces.relationship_lifecycle.postconfigure'
- _, _, _, _, relationship, relationship_instance = \
- _get_elements(workflow_context)
- relationship.source_operations[operation_name] = {
- 'operation': op_path(relationship_operation, module_path=__name__)
- }
- workflow_context.model.relationship.put(relationship)
+ operation_name = 'aria.interfaces.relationship_lifecycle.postconfigure.source'
+ _, _, _, _, relationship = _get_elements(workflow_context)
+ relationship.source_interfaces = [
+ mock.models.get_interface(
+ operation_name,
+ is_relationship=True,
+ operation_kwargs=dict(
+ implementation=op_path(relationship_operation, module_path=__name__)))
+ ]
+ workflow_context.model.relationship.update(relationship)
inputs = {'putput': True}
@@ -113,16 +116,15 @@ def test_relationship_tool_belt(workflow_context, executor):
def basic_workflow(graph, **_):
graph.add_tasks(
api.task.OperationTask.relationship_instance(
- instance=relationship_instance,
+ instance=relationship,
name=operation_name,
- operation_end=api.task.OperationTask.SOURCE_OPERATION,
inputs=inputs
)
)
execute(workflow_func=basic_workflow, workflow_context=workflow_context, executor=executor)
- assert isinstance(global_test_holder.get(op_name(relationship_instance, operation_name)),
+ assert isinstance(global_test_holder.get(op_name(relationship, operation_name)),
RelationshipToolBelt)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/context/test_workflow.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_workflow.py b/tests/orchestrator/context/test_workflow.py
index 496c1ff..89afb39 100644
--- a/tests/orchestrator/context/test_workflow.py
+++ b/tests/orchestrator/context/test_workflow.py
@@ -29,9 +29,11 @@ class TestWorkflowContext(object):
def test_execution_creation_on_workflow_context_creation(self, storage):
ctx = self._create_ctx(storage)
execution = storage.execution.get(ctx.execution.id) # pylint: disable=no-member
- assert execution.deployment == storage.deployment.get_by_name(models.DEPLOYMENT_NAME)
+ assert execution.service_instance == storage.service_instance.get_by_name(
+ models.DEPLOYMENT_NAME)
assert execution.workflow_name == models.WORKFLOW_NAME
- assert execution.blueprint == storage.blueprint.get_by_name(models.BLUEPRINT_NAME)
+ assert execution.service_template == storage.service_template.get_by_name(
+ models.BLUEPRINT_NAME)
assert execution.status == storage.execution.model_cls.PENDING
assert execution.parameters == {}
assert execution.created_at <= datetime.utcnow()
@@ -51,7 +53,7 @@ class TestWorkflowContext(object):
name='simple_context',
model_storage=storage,
resource_storage=None,
- deployment_id=storage.deployment.get_by_name(models.DEPLOYMENT_NAME).id,
+ service_instance_id=storage.service_instance.get_by_name(models.DEPLOYMENT_NAME).id,
workflow_name=models.WORKFLOW_NAME,
task_max_attempts=models.TASK_MAX_ATTEMPTS,
task_retry_interval=models.TASK_RETRY_INTERVAL
@@ -62,8 +64,8 @@ class TestWorkflowContext(object):
def storage():
api_kwargs = test_storage.get_sqlite_api_kwargs()
workflow_storage = application_model_storage(SQLAlchemyModelAPI, api_kwargs=api_kwargs)
- workflow_storage.blueprint.put(models.get_blueprint())
- blueprint = workflow_storage.blueprint.get_by_name(models.BLUEPRINT_NAME)
- workflow_storage.deployment.put(models.get_deployment(blueprint))
+ workflow_storage.service_template.put(models.get_blueprint())
+ blueprint = workflow_storage.service_template.get_by_name(models.BLUEPRINT_NAME)
+ workflow_storage.service_instance.put(models.get_deployment(blueprint))
yield workflow_storage
test_storage.release_sqlite_storage(workflow_storage)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/__init__.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/__init__.py b/tests/orchestrator/workflows/__init__.py
index fe04b2f..7f0fd56 100644
--- a/tests/orchestrator/workflows/__init__.py
+++ b/tests/orchestrator/workflows/__init__.py
@@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from . import api, builtin, core
+from . import api, core
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/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 58e387f..3d01bd6 100644
--- a/tests/orchestrator/workflows/api/test_task.py
+++ b/tests/orchestrator/workflows/api/test_task.py
@@ -18,7 +18,7 @@ import pytest
from aria.orchestrator import context
from aria.orchestrator.workflows import api
-
+from aria.storage.modeling import model
from tests import mock, storage
@@ -30,7 +30,7 @@ def ctx():
:return:
"""
simple_context = mock.context.simple(storage.get_sqlite_api_kwargs())
- simple_context.model.execution.put(mock.models.get_execution(simple_context.deployment))
+ simple_context.model.execution.put(mock.models.get_execution(simple_context.service_instance))
yield simple_context
storage.release_sqlite_storage(simple_context.model)
@@ -39,16 +39,17 @@ class TestOperationTask(object):
def test_node_operation_task_creation(self, ctx):
operation_name = 'aria.interfaces.lifecycle.create'
- op_details = {'operation': True, 'plugin': 'plugin'}
- node = ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_NAME)
- node.operations[operation_name] = op_details
+ interface = mock.models.get_interface(
+ operation_name,
+ operation_kwargs=dict(plugin='plugin', implementation='op_path'))
+
+ node = ctx.model.node.get_by_name(mock.models.DEPENDENT_NODE_INSTANCE_NAME)
+ node.interfaces = [interface]
node.plugins = [{'name': 'plugin',
'package_name': 'package',
'package_version': '0.1'}]
- ctx.model.node.update(node)
- node_instance = \
- ctx.model.node_instance.get_by_name(mock.models.DEPENDENT_NODE_INSTANCE_NAME)
- inputs = {'inputs': True}
+ ctx.model.node_template.update(node)
+ inputs = [model.Parameter(type_name='Boolean', value=True)]
max_attempts = 10
retry_interval = 10
ignore_failure = True
@@ -56,15 +57,15 @@ class TestOperationTask(object):
with context.workflow.current.push(ctx):
api_task = api.task.OperationTask.node_instance(
name=operation_name,
- instance=node_instance,
+ instance=node,
inputs=inputs,
max_attempts=max_attempts,
retry_interval=retry_interval,
ignore_failure=ignore_failure)
- assert api_task.name == '{0}.{1}'.format(operation_name, node_instance.id)
- assert api_task.operation_mapping is True
- assert api_task.actor == node_instance
+ assert api_task.name == '{0}.{1}'.format(operation_name, node.id)
+ assert api_task.implementation == 'op_path'
+ assert api_task.actor == node
assert api_task.inputs == inputs
assert api_task.retry_interval == retry_interval
assert api_task.max_attempts == max_attempts
@@ -74,31 +75,35 @@ class TestOperationTask(object):
'package_version': '0.1'}
def test_source_relationship_operation_task_creation(self, ctx):
- operation_name = 'aria.interfaces.relationship_lifecycle.preconfigure'
- op_details = {'operation': True, 'plugin': 'plugin'}
+ operation_name = 'aria.interfaces.relationship_lifecycle.preconfigure.source'
+
+ interface = mock.models.get_interface(
+ operation_name,
+ operation_kwargs=dict(implementation='op_path', plugin='plugin'),
+ is_relationship=True
+ )
+
relationship = ctx.model.relationship.list()[0]
- relationship.source_operations[operation_name] = op_details
+ relationship.source_interfaces = [interface]
relationship.source_node.plugins = [{'name': 'plugin',
'package_name': 'package',
'package_version': '0.1'}]
- relationship_instance = ctx.model.relationship_instance.list()[0]
- inputs = {'inputs': True}
+ input = model.Parameter(type_name='Boolean', value=True)
max_attempts = 10
retry_interval = 10
with context.workflow.current.push(ctx):
api_task = api.task.OperationTask.relationship_instance(
name=operation_name,
- instance=relationship_instance,
- operation_end=api.task.OperationTask.SOURCE_OPERATION,
- inputs=inputs,
+ instance=relationship,
+ inputs=[input],
max_attempts=max_attempts,
retry_interval=retry_interval)
- assert api_task.name == '{0}.{1}'.format(operation_name, relationship_instance.id)
- assert api_task.operation_mapping is True
- assert api_task.actor == relationship_instance
- assert api_task.inputs == inputs
+ assert api_task.name == '{0}.{1}'.format(operation_name, relationship.id)
+ assert api_task.implementation == 'op_path'
+ assert api_task.actor == relationship
+ assert api_task.inputs == [input]
assert api_task.retry_interval == retry_interval
assert api_task.max_attempts == max_attempts
assert api_task.plugin == {'name': 'plugin',
@@ -106,31 +111,34 @@ class TestOperationTask(object):
'package_version': '0.1'}
def test_target_relationship_operation_task_creation(self, ctx):
- operation_name = 'aria.interfaces.relationship_lifecycle.preconfigure'
- op_details = {'operation': True, 'plugin': 'plugin'}
+ operation_name = 'aria.interfaces.relationship_lifecycle.preconfigure.target'
+ interface = mock.models.get_interface(
+ operation_name,
+ operation_kwargs=dict(implementation='op_path', plugin='plugin'),
+ is_relationship=True
+ )
+
relationship = ctx.model.relationship.list()[0]
- relationship.target_operations[operation_name] = op_details
+ relationship.target_interfaces = [interface]
relationship.target_node.plugins = [{'name': 'plugin',
'package_name': 'package',
'package_version': '0.1'}]
- relationship_instance = ctx.model.relationship_instance.list()[0]
- inputs = {'inputs': True}
+ input = model.Parameter(type_name='Boolean', value=True)
max_attempts = 10
retry_interval = 10
with context.workflow.current.push(ctx):
api_task = api.task.OperationTask.relationship_instance(
name=operation_name,
- instance=relationship_instance,
- operation_end=api.task.OperationTask.TARGET_OPERATION,
- inputs=inputs,
+ instance=relationship,
+ inputs=[input],
max_attempts=max_attempts,
retry_interval=retry_interval)
- assert api_task.name == '{0}.{1}'.format(operation_name, relationship_instance.id)
- assert api_task.operation_mapping is True
- assert api_task.actor == relationship_instance
- assert api_task.inputs == inputs
+ assert api_task.name == '{0}.{1}'.format(operation_name, relationship.id)
+ assert api_task.implementation == 'op_path'
+ assert api_task.actor == relationship
+ assert api_task.inputs == [input]
assert api_task.retry_interval == retry_interval
assert api_task.max_attempts == max_attempts
assert api_task.plugin == {'name': 'plugin',
@@ -138,12 +146,12 @@ class TestOperationTask(object):
'package_version': '0.1'}
def test_operation_task_default_values(self, ctx):
- dependency_node_instance = ctx.model.node_instance.get_by_name(
+ dependency_node_instance = ctx.model.node.get_by_name(
mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
with context.workflow.current.push(ctx):
task = api.task.OperationTask(
name='stub',
- operation_mapping='',
+ implementation='',
actor=dependency_node_instance)
assert task.inputs == {}
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/builtin/__init__.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/builtin/__init__.py b/tests/orchestrator/workflows/builtin/__init__.py
deleted file mode 100644
index 26ba82f..0000000
--- a/tests/orchestrator/workflows/builtin/__init__.py
+++ /dev/null
@@ -1,53 +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 tests import mock
-
-
-def assert_node_install_operations(operations, with_relationships=False):
- if with_relationships:
- all_operations = [
- 'aria.interfaces.lifecycle.create',
- 'aria.interfaces.relationship_lifecycle.preconfigure',
- 'aria.interfaces.relationship_lifecycle.preconfigure',
- 'aria.interfaces.lifecycle.configure',
- 'aria.interfaces.relationship_lifecycle.postconfigure',
- 'aria.interfaces.relationship_lifecycle.postconfigure',
- 'aria.interfaces.lifecycle.start',
- 'aria.interfaces.relationship_lifecycle.establish',
- 'aria.interfaces.relationship_lifecycle.establish',
- ]
-
- for i, operation in enumerate(operations):
- assert operation.name.startswith(all_operations[i])
- else:
- for i, operation in enumerate(operations):
- assert operation.name.startswith(mock.operations.NODE_OPERATIONS_INSTALL[i])
-
-
-def assert_node_uninstall_operations(operations, with_relationships=False):
- if with_relationships:
- all_operations = [
- 'aria.interfaces.lifecycle.stop',
- 'aria.interfaces.relationship_lifecycle.unlink',
- 'aria.interfaces.relationship_lifecycle.unlink',
- 'aria.interfaces.lifecycle.delete',
- ]
-
- for i, operation in enumerate(operations):
- assert operation.name.startswith(all_operations[i])
- else:
- for i, operation in enumerate(operations):
- assert operation.name.startswith(mock.operations.NODE_OPERATIONS_UNINSTALL[i])
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/builtin/test_execute_operation.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/builtin/test_execute_operation.py b/tests/orchestrator/workflows/builtin/test_execute_operation.py
deleted file mode 100644
index b7e5678..0000000
--- a/tests/orchestrator/workflows/builtin/test_execute_operation.py
+++ /dev/null
@@ -1,56 +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.
-
-import pytest
-
-from aria.orchestrator.workflows.api import task
-from aria.orchestrator.workflows.builtin.execute_operation import execute_operation
-
-from tests import mock
-from tests import storage
-
-
-@pytest.fixture
-def ctx(tmpdir):
- context = mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir)))
- yield context
- storage.release_sqlite_storage(context.model)
-
-
-def test_execute_operation(ctx):
- node_instance = ctx.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
-
- operation_name = mock.operations.NODE_OPERATIONS_INSTALL[0]
-
- execute_tasks = list(
- task.WorkflowTask(
- execute_operation,
- ctx=ctx,
- operation=operation_name,
- operation_kwargs={},
- allow_kwargs_override=False,
- run_by_dependency_order=False,
- type_names=[],
- node_ids=[],
- node_instance_ids=[node_instance.id]
- ).topological_order()
- )
-
- assert len(execute_tasks) == 1
- assert execute_tasks[0].name == '{0}.{1}'.format(operation_name, node_instance.id)
-
-
-
-# TODO: add more scenarios
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/builtin/test_heal.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/builtin/test_heal.py b/tests/orchestrator/workflows/builtin/test_heal.py
deleted file mode 100644
index ad281fd..0000000
--- a/tests/orchestrator/workflows/builtin/test_heal.py
+++ /dev/null
@@ -1,99 +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.
-
-import pytest
-
-from aria.orchestrator.workflows.api import task
-from aria.orchestrator.workflows.builtin.heal import heal
-
-from tests import mock, storage
-
-from . import (assert_node_install_operations,
- assert_node_uninstall_operations)
-
-
-@pytest.fixture
-def ctx(tmpdir):
- context = mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir)))
- yield context
- storage.release_sqlite_storage(context.model)
-
-
-def test_heal_dependent_node(ctx):
- dependent_node_instance = \
- ctx.model.node_instance.get_by_name(mock.models.DEPENDENT_NODE_INSTANCE_NAME)
- dependent_node_instance.host_fk = dependent_node_instance.id
- ctx.model.node_instance.update(dependent_node_instance)
- heal_graph = task.WorkflowTask(heal, ctx=ctx, node_instance_id=dependent_node_instance.id)
-
- assert len(list(heal_graph.tasks)) == 2
- uninstall_subgraph, install_subgraph = list(heal_graph.topological_order(reverse=True))
-
- assert len(list(uninstall_subgraph.tasks)) == 2
- dependent_node_subgraph_uninstall, dependency_node_subgraph_uninstall = \
- list(uninstall_subgraph.topological_order(reverse=True))
-
- assert len(list(install_subgraph.tasks)) == 2
- dependency_node_subgraph_install, dependent_node_subgraph_install = \
- list(install_subgraph.topological_order(reverse=True))
-
- dependent_node_uninstall_tasks = \
- list(dependent_node_subgraph_uninstall.topological_order(reverse=True))
- assert isinstance(dependency_node_subgraph_uninstall, task.StubTask)
- dependent_node_install_tasks = \
- list(dependent_node_subgraph_install.topological_order(reverse=True))
- assert isinstance(dependency_node_subgraph_install, task.StubTask)
-
- assert_node_uninstall_operations(dependent_node_uninstall_tasks, with_relationships=True)
- assert_node_install_operations(dependent_node_install_tasks, with_relationships=True)
-
-
-def test_heal_dependency_node(ctx):
- dependency_node_instance = \
- ctx.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
- dependency_node_instance.host_fk = dependency_node_instance.id
- ctx.model.node_instance.update(dependency_node_instance)
- heal_graph = task.WorkflowTask(heal, ctx=ctx, node_instance_id=dependency_node_instance.id)
- # both subgraphs should contain un\install for both the dependent and the dependency
- assert len(list(heal_graph.tasks)) == 2
- uninstall_subgraph, install_subgraph = list(heal_graph.topological_order(reverse=True))
-
- uninstall_tasks = list(uninstall_subgraph.topological_order(reverse=True))
- assert len(uninstall_tasks) == 4
- unlink_source, unlink_target = uninstall_tasks[:2]
- dependent_node_subgraph_uninstall, dependency_node_subgraph_uninstall = uninstall_tasks[2:]
-
- install_tasks = list(install_subgraph.topological_order(reverse=True))
- assert len(install_tasks) == 4
- dependency_node_subgraph_install, dependent_node_subgraph_install = install_tasks[:2]
- establish_source, establish_target = install_tasks[2:]
-
- assert isinstance(dependent_node_subgraph_uninstall, task.StubTask)
- dependency_node_uninstall_tasks = \
- list(dependency_node_subgraph_uninstall.topological_order(reverse=True))
- assert isinstance(dependent_node_subgraph_install, task.StubTask)
- dependency_node_install_tasks = \
- list(dependency_node_subgraph_install.topological_order(reverse=True))
-
- assert unlink_source.name.startswith('aria.interfaces.relationship_lifecycle.unlink')
- assert unlink_target.name.startswith('aria.interfaces.relationship_lifecycle.unlink')
- assert_node_uninstall_operations(dependency_node_uninstall_tasks)
-
- assert_node_install_operations(dependency_node_install_tasks)
- assert establish_source.name.startswith('aria.interfaces.relationship_lifecycle.establish')
- assert establish_target.name.startswith('aria.interfaces.relationship_lifecycle.establish')
-
-
-# TODO: add tests for contained in scenario
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/builtin/test_install.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/builtin/test_install.py b/tests/orchestrator/workflows/builtin/test_install.py
deleted file mode 100644
index 789a161..0000000
--- a/tests/orchestrator/workflows/builtin/test_install.py
+++ /dev/null
@@ -1,43 +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.
-import pytest
-
-from aria.orchestrator.workflows.api import task
-from aria.orchestrator.workflows.builtin.install import install
-
-from tests import mock
-from tests import storage
-
-from . import assert_node_install_operations
-
-
-@pytest.fixture
-def ctx(tmpdir):
- context = mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir)))
- yield context
- storage.release_sqlite_storage(context.model)
-
-
-def test_install(ctx):
-
- install_tasks = list(task.WorkflowTask(install, ctx=ctx).topological_order(True))
-
- assert len(install_tasks) == 2
- dependency_node_subgraph, dependent_node_subgraph = install_tasks
- dependent_node_tasks = list(dependent_node_subgraph.topological_order(reverse=True))
- dependency_node_tasks = list(dependency_node_subgraph.topological_order(reverse=True))
-
- assert_node_install_operations(dependency_node_tasks)
- assert_node_install_operations(dependent_node_tasks, with_relationships=True)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/builtin/test_uninstall.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/builtin/test_uninstall.py b/tests/orchestrator/workflows/builtin/test_uninstall.py
deleted file mode 100644
index 126c4cf..0000000
--- a/tests/orchestrator/workflows/builtin/test_uninstall.py
+++ /dev/null
@@ -1,44 +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.
-
-import pytest
-
-from aria.orchestrator.workflows.api import task
-from aria.orchestrator.workflows.builtin.uninstall import uninstall
-
-from tests import mock
-from tests import storage
-
-from . import assert_node_uninstall_operations
-
-
-@pytest.fixture
-def ctx(tmpdir):
- context = mock.context.simple(storage.get_sqlite_api_kwargs(str(tmpdir)))
- yield context
- storage.release_sqlite_storage(context.model)
-
-
-def test_uninstall(ctx):
-
- uninstall_tasks = list(task.WorkflowTask(uninstall, ctx=ctx).topological_order(True))
-
- assert len(uninstall_tasks) == 2
- dependent_node_subgraph, dependency_node_subgraph = uninstall_tasks
- dependent_node_tasks = list(dependent_node_subgraph.topological_order(reverse=True))
- dependency_node_tasks = list(dependency_node_subgraph.topological_order(reverse=True))
-
- assert_node_uninstall_operations(operations=dependency_node_tasks)
- assert_node_uninstall_operations(operations=dependent_node_tasks, with_relationships=True)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/core/test_engine.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/core/test_engine.py b/tests/orchestrator/workflows/core/test_engine.py
index d9b50a9..595ed4b 100644
--- a/tests/orchestrator/workflows/core/test_engine.py
+++ b/tests/orchestrator/workflows/core/test_engine.py
@@ -23,7 +23,7 @@ from aria.orchestrator import (
workflow,
operation,
)
-from aria.storage import model
+from aria.storage.modeling import model
from aria.orchestrator.workflows import (
api,
exceptions,
@@ -60,13 +60,14 @@ class BaseTest(object):
max_attempts=None,
retry_interval=None,
ignore_failure=None):
- node_instance = \
- ctx.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
- node_instance.node.operations['aria.interfaces.lifecycle.create'] = {
- 'operation': '{name}.{func.__name__}'.format(name=__name__, func=func)
- }
+ node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ node.interfaces = [mock.models.get_interface(
+ 'aria.interfaces.lifecycle.create',
+ operation_kwargs=dict(implementation='{name}.{func.__name__}'.format(name=__name__,
+ func=func))
+ )]
return api.task.OperationTask.node_instance(
- instance=node_instance,
+ instance=node,
name='aria.interfaces.lifecycle.create',
inputs=inputs,
max_attempts=max_attempts,
@@ -219,8 +220,12 @@ class TestCancel(BaseTest):
@workflow
def mock_workflow(ctx, graph):
- return graph.sequence(*(self._op(mock_sleep_task, ctx, inputs={'seconds': 0.1})
- for _ in range(number_of_tasks)))
+ operations = (
+ self._op(mock_sleep_task, ctx, inputs=dict(seconds=0.1))
+ for _ in range(number_of_tasks)
+ )
+ return graph.sequence(*operations)
+
eng = self._engine(workflow_func=mock_workflow,
workflow_context=workflow_context,
executor=executor)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/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 5381f5d..cde0e99 100644
--- a/tests/orchestrator/workflows/core/test_task.py
+++ b/tests/orchestrator/workflows/core/test_task.py
@@ -51,28 +51,31 @@ class TestOperationTask(object):
storage_plugin_other = mock.models.get_plugin(package_name='p0', package_version='0.0')
ctx.model.plugin.put(storage_plugin_other)
ctx.model.plugin.put(storage_plugin)
- node_instance = \
- ctx.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
- node = node_instance.node
- node.plugins = [{'name': 'plugin1',
- 'package_name': 'p1',
- 'package_version': '0.1'}]
- node.operations['aria.interfaces.lifecycle.create'] = {'plugin': 'plugin1'}
- api_task, core_task = self._create_operation_task(ctx, node_instance)
+ node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ node_template = node.node_template
+ node_template.plugins = [{'name': 'plugin1',
+ 'package_name': 'p1',
+ 'package_version': '0.1'}]
+ node.interfaces = [mock.models.get_interface('aria.interfaces.lifecycle.create',
+ operation_kwargs=dict(plugin='plugin1'))]
+ ctx.model.node_template.update(node_template)
+ ctx.model.node.update(node)
+ api_task, core_task = self._create_operation_task(ctx, node)
storage_task = ctx.model.task.get_by_name(core_task.name)
assert storage_task.execution_name == ctx.execution.name
assert core_task.model_task == storage_task
assert core_task.name == api_task.name
- assert core_task.operation_mapping == api_task.operation_mapping
- assert core_task.actor == api_task.actor == node_instance
+ assert core_task.implementation == api_task.implementation
+ assert core_task.actor == api_task.actor == node
assert core_task.inputs == api_task.inputs == storage_task.inputs
assert core_task.plugin == storage_plugin
def test_operation_task_edit_locked_attribute(self, ctx):
- node_instance = \
- ctx.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ node.interfaces = [mock.models.get_interface('aria.interfaces.lifecycle.create')]
+ ctx.model.node.update(node)
- _, core_task = self._create_operation_task(ctx, node_instance)
+ _, core_task = self._create_operation_task(ctx, node)
now = datetime.utcnow()
with pytest.raises(exceptions.TaskException):
core_task.status = core_task.STARTED
@@ -86,10 +89,11 @@ class TestOperationTask(object):
core_task.due_at = now
def test_operation_task_edit_attributes(self, ctx):
- node_instance = \
- ctx.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ node.interfaces = [mock.models.get_interface('aria.interfaces.lifecycle.create')]
+ ctx.model.node.update(node)
- _, core_task = self._create_operation_task(ctx, node_instance)
+ _, core_task = self._create_operation_task(ctx, node)
future_time = datetime.utcnow() + timedelta(seconds=3)
with core_task._update():
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/core/test_task_graph_into_exececution_graph.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/core/test_task_graph_into_exececution_graph.py b/tests/orchestrator/workflows/core/test_task_graph_into_exececution_graph.py
index 18540f4..a3e216b 100644
--- a/tests/orchestrator/workflows/core/test_task_graph_into_exececution_graph.py
+++ b/tests/orchestrator/workflows/core/test_task_graph_into_exececution_graph.py
@@ -25,20 +25,22 @@ from tests import storage
def test_task_graph_into_execution_graph():
operation_name = 'aria.interfaces.lifecycle.create'
task_context = mock.context.simple(storage.get_sqlite_api_kwargs())
- node_instance = \
- task_context.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ node = task_context.model.node.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ node.interfaces = [mock.models.get_interface(operation_name)]
+ task_context.model.node.update(node)
+
def sub_workflow(name, **_):
return api.task_graph.TaskGraph(name)
with context.workflow.current.push(task_context):
test_task_graph = api.task.WorkflowTask(sub_workflow, name='test_task_graph')
- simple_before_task = api.task.OperationTask.node_instance(instance=node_instance,
+ simple_before_task = api.task.OperationTask.node_instance(instance=node,
name=operation_name)
- simple_after_task = api.task.OperationTask.node_instance(instance=node_instance,
+ simple_after_task = api.task.OperationTask.node_instance(instance=node,
name=operation_name)
inner_task_graph = api.task.WorkflowTask(sub_workflow, name='test_inner_task_graph')
- inner_task = api.task.OperationTask.node_instance(instance=node_instance,
+ inner_task = api.task.OperationTask.node_instance(instance=node,
name=operation_name)
inner_task_graph.add_tasks(inner_task)
@@ -91,7 +93,7 @@ def test_task_graph_into_execution_graph():
def _assert_execution_is_api_task(execution_task, api_task):
assert execution_task.id == api_task.id
assert execution_task.name == api_task.name
- assert execution_task.operation_mapping == api_task.operation_mapping
+ assert execution_task.implementation == api_task.implementation
assert execution_task.actor == api_task.actor
assert execution_task.inputs == api_task.inputs
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/executor/test_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_executor.py b/tests/orchestrator/workflows/executor/test_executor.py
index 2486a1e..97e1393 100644
--- a/tests/orchestrator/workflows/executor/test_executor.py
+++ b/tests/orchestrator/workflows/executor/test_executor.py
@@ -28,7 +28,7 @@ except ImportError:
_celery = None
app = None
-from aria.storage import model
+from aria.storage.modeling import model
from aria.orchestrator import events
from aria.orchestrator.workflows.executor import (
thread,
@@ -43,7 +43,7 @@ def test_execute(executor):
expected_value = 'value'
successful_task = MockTask(mock_successful_task)
failing_task = MockTask(mock_failing_task)
- task_with_inputs = MockTask(mock_task_with_input, inputs={'input': expected_value})
+ task_with_inputs = MockTask(mock_task_with_input, inputs=dict(input='value'))
for task in [successful_task, failing_task, task_with_inputs]:
executor.execute(task)
@@ -98,8 +98,9 @@ class MockTask(object):
self.exception = None
self.id = str(uuid.uuid4())
name = func.__name__
- operation = 'tests.orchestrator.workflows.executor.test_executor.{name}'.format(name=name)
- self.operation_mapping = operation
+ implementation = 'tests.orchestrator.workflows.executor.test_executor.{name}'.format(
+ name=name)
+ self.implementation = implementation
self.logger = logging.getLogger()
self.name = name
self.inputs = inputs or {}
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/executor/test_process_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_process_executor.py b/tests/orchestrator/workflows/executor/test_process_executor.py
index 687e245..ec01d60 100644
--- a/tests/orchestrator/workflows/executor/test_process_executor.py
+++ b/tests/orchestrator/workflows/executor/test_process_executor.py
@@ -22,7 +22,7 @@ from contextlib import contextmanager
import pytest
from aria import application_model_storage
-from aria.storage import model as aria_model
+from aria.storage.modeling import model as aria_model
from aria.utils.plugin import create as create_plugin
from aria.storage.sql_mapi import SQLAlchemyModelAPI
from aria.orchestrator import events
@@ -38,7 +38,7 @@ class TestProcessExecutor(object):
def test_plugin_execution(self, executor, mock_plugin):
task = MockTask(plugin=mock_plugin,
- operation='mock_plugin1.operation')
+ implementation='mock_plugin1.operation')
queue = Queue.Queue()
@@ -119,11 +119,11 @@ class MockTask(object):
INFINITE_RETRIES = aria_model.Task.INFINITE_RETRIES
- def __init__(self, plugin, operation):
+ def __init__(self, plugin, implementation):
self.id = str(uuid.uuid4())
- self.operation_mapping = operation
+ self.implementation = implementation
self.logger = logging.getLogger()
- self.name = operation
+ self.name = implementation
self.inputs = {}
self.context = MockContext()
self.retry_count = 0
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py b/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py
index 1564292..45685f0 100644
--- a/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py
+++ b/tests/orchestrator/workflows/executor/test_process_executor_tracked_changes.py
@@ -43,22 +43,22 @@ def test_track_changes_of_failed_operation(context, executor):
def _assert_tracked_changes_are_applied(context):
- instance = context.model.node_instance.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ instance = context.model.node.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
assert instance.runtime_properties == _TEST_RUNTIME_PROPERTIES
def _update_runtime_properties(context):
- context.node_instance.runtime_properties.clear()
- context.node_instance.runtime_properties.update(_TEST_RUNTIME_PROPERTIES)
+ context.node.runtime_properties.clear()
+ context.node.runtime_properties.update(_TEST_RUNTIME_PROPERTIES)
def _run_workflow(context, executor, op_func):
@workflow
def mock_workflow(ctx, graph):
- node_instance = ctx.model.node_instance.get_by_name(
- mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
- node_instance.node.operations['test.op'] = {'operation': _operation_mapping(op_func)}
- task = api.task.OperationTask.node_instance(instance=node_instance, name='test.op')
+ node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_INSTANCE_NAME)
+ node.interfaces = [mock.models.get_interface(
+ 'test.op', operation_kwargs=dict(implementation=_operation_mapping(op_func)))]
+ task = api.task.OperationTask.node_instance(instance=node, name='test.op')
graph.add_tasks(task)
return graph
graph = mock_workflow(ctx=context) # pylint: disable=no-value-for-parameter
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/storage/__init__.py
----------------------------------------------------------------------
diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py
index 9101fd0..2363957 100644
--- a/tests/storage/__init__.py
+++ b/tests/storage/__init__.py
@@ -14,16 +14,17 @@
# limitations under the License.
import os
import platform
-from tempfile import mkdtemp
from shutil import rmtree
+from tempfile import mkdtemp
-from aria.storage import model
from sqlalchemy import (
create_engine,
orm)
from sqlalchemy.orm import scoped_session
from sqlalchemy.pool import StaticPool
+from aria.storage import modeling
+
class TestFileSystem(object):
@@ -34,7 +35,8 @@ class TestFileSystem(object):
rmtree(self.path, ignore_errors=True)
-def get_sqlite_api_kwargs(base_dir=None, filename='db.sqlite'):
+def get_sqlite_api_kwargs(base_dir=None,
+ filename='db.sqlite'):
"""
Create sql params. works in in-memory and in filesystem mode.
If base_dir is passed, the mode will be filesystem mode. while the default mode is in-memory.
@@ -59,7 +61,7 @@ def get_sqlite_api_kwargs(base_dir=None, filename='db.sqlite'):
session_factory = orm.sessionmaker(bind=engine)
session = scoped_session(session_factory=session_factory) if base_dir else session_factory()
- model.DeclarativeBase.metadata.create_all(bind=engine)
+ modeling.declarative_base.metadata.create_all(bind=engine)
return dict(engine=engine, session=session)
@@ -76,4 +78,4 @@ def release_sqlite_storage(storage):
session.rollback()
session.close()
for engine in set(mapi._engine for mapi in mapis):
- model.DeclarativeBase.metadata.drop_all(engine)
+ modeling.declarative_base.metadata.drop_all(engine)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/tests/storage/test_instrumentation.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_instrumentation.py b/tests/storage/test_instrumentation.py
index 8e7f9aa..ad4f66c 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 = []
@@ -267,9 +266,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/82d9be7d/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.node_template.get_by_name(models.DEPENDENCY_NODE_NAME)
+ target_node_instance = context.model.node.get_by_name(
models.DEPENDENCY_NODE_INSTANCE_NAME)
- new_node = model.Node(
+ new_node = modeling.model.NodeTemplate(
name='new_node',
- type='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=deployment
- )
- source_to_new_relationship = model.Relationship(
- source_node=source_node,
- target_node=new_node,
- 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_name='test_node_type',
type_hierarchy=[],
- properties={},
+ default_instances=1,
+ min_instances=1,
+ max_instances=1,
+ service_template=deployment.service_template
)
- new_node_instance = model.NodeInstance(
+ req, cap = mock_context.models.get_relationship(new_node)
+ context.model.requirement_template.put(req)
+ context.model.capability_template.put(cap)
+
+ source_node.requirement_templates = [req]
+ source_node.capability_templates = [cap]
+ context.model.node_template.update(source_node)
+
+ new_node_instance = modeling.model.Node(
name='new_node_instance',
+ service_instance=deployment,
runtime_properties={},
version=None,
- node=new_node,
+ node_template=new_node,
state='',
scaling_groups=[]
)
- source_to_new_relationship_instance = model.RelationshipInstance(
- relationship=source_to_new_relationship,
- source_node_instance=source_node_instance,
- target_node_instance=new_node_instance,
+ source_to_new_relationship_instance = mock_context.models.get_relationship_instance(
+ target_instance=new_node_instance,
+ source_instance=source_node_instance
)
+ context.model.relationship.put(source_to_new_relationship_instance)
- new_to_target_relationship = model.Relationship(
- source_node=new_node,
- target_node=target_node,
- 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={},
- )
- new_to_target_relationship_instance = model.RelationshipInstance(
- relationship=new_to_target_relationship,
- source_node_instance=new_node_instance,
- target_node_instance=target_node_instance,
- )
+ req, cap = mock_context.models.get_relationship(target_node)
+ context.model.requirement_template.put(req)
+ context.model.capability_template.put(cap)
+ target_node.requirement_templates = [req]
+ target_node.capability_templates = [cap]
+ context.model.node_template.update(target_node)
- context.model.node.put(new_node)
- context.model.node_instance.put(new_node_instance)
- context.model.relationship.put(source_to_new_relationship)
- context.model.relationship.put(new_to_target_relationship)
- context.model.relationship_instance.put(source_to_new_relationship_instance)
- context.model.relationship_instance.put(new_to_target_relationship_instance)
+ new_to_target_relationship_instance = modeling.model.Relationship(
+ source_node=new_node_instance,
+ target_node=target_node_instance,
+ )
+ context.model.relationship.put(new_to_target_relationship_instance)
def flip_and_assert(node_instance, direction):
"""
@@ -234,33 +239,22 @@ def test_relationship_model_ordering(context):
"""
assert direction in ('inbound', 'outbound')
- relationships = getattr(node_instance.node, direction + '_relationships')
- relationship_instances = getattr(node_instance, direction + '_relationship_instances')
- assert len(relationships) == 2
+ relationship_instances = getattr(node_instance, direction + '_relationships')
assert len(relationship_instances) == 2
- first_rel, second_rel = relationships
first_rel_instance, second_rel_instance = relationship_instances
- assert getattr(first_rel, relationships.ordering_attr) == 0
- assert getattr(second_rel, relationships.ordering_attr) == 1
assert getattr(first_rel_instance, relationship_instances.ordering_attr) == 0
assert getattr(second_rel_instance, relationship_instances.ordering_attr) == 1
- reversed_relationships = list(reversed(relationships))
reversed_relationship_instances = list(reversed(relationship_instances))
- assert relationships != reversed_relationships
assert relationship_instances != reversed_relationship_instances
- relationships[:] = reversed_relationships
relationship_instances[:] = reversed_relationship_instances
- context.model.node_instance.update(node_instance)
+ context.model.node.update(node_instance)
- assert relationships == reversed_relationships
assert relationship_instances == reversed_relationship_instances
- assert getattr(first_rel, relationships.ordering_attr) == 1
- assert getattr(second_rel, relationships.ordering_attr) == 0
assert getattr(first_rel_instance, relationship_instances.ordering_attr) == 1
assert getattr(second_rel_instance, relationship_instances.ordering_attr) == 0
[5/5] incubator-ariatosca git commit: wip
Posted by mx...@apache.org.
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 <mx...@gmail.com>
Authored: Thu Jan 19 11:39:36 2017 +0200
Committer: mxmrlv <mx...@gmail.com>
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.ArtifactTemplate,
+ storage.modeling.model.PolicyTemplate,
+ storage.modeling.model.GroupPolicyTemplate,
+ storage.modeling.model.GroupPolicyTriggerTemplate,
+ storage.modeling.model.RequirementTemplate,
+ storage.modeling.model.CapabilityTemplate,
- storage.model.Node,
- storage.model.NodeInstance,
- storage.model.Relationship,
- storage.model.RelationshipInstance,
+ storage.modeling.model.Mapping,
+ storage.modeling.model.Substitution,
+ storage.modeling.model.ServiceInstance,
+ storage.modeling.model.Node,
+ storage.modeling.model.Group,
+ storage.modeling.model.Interface,
+ storage.modeling.model.Operation,
+ storage.modeling.model.Capability,
+ storage.modeling.model.Artifact,
+ storage.modeling.model.Policy,
+ storage.modeling.model.GroupPolicy,
+ storage.modeling.model.GroupPolicyTrigger,
+ storage.modeling.model.Relationship,
- storage.model.Execution,
- storage.model.Task,
+ storage.modeling.model.Execution,
+ storage.modeling.model.ServiceInstanceUpdate,
+ storage.modeling.model.ServiceInstanceUpdateStep,
+ storage.modeling.model.ServiceInstanceModification,
+ storage.modeling.model.Plugin,
+ storage.modeling.model.Task
]
# if api not in _model_storage:
- return storage.ModelStorage(api, items=models, api_kwargs=api_kwargs or {})
+ return storage.ModelStorage(api, items=models_to_register, api_kwargs=api_kwargs or {})
def application_resource_storage(api, api_kwargs=None):
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/cli/commands.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands.py b/aria/cli/commands.py
index 1cd765f..f5edbc4 100644
--- a/aria/cli/commands.py
+++ b/aria/cli/commands.py
@@ -227,7 +227,7 @@ class ExecuteCommand(BaseCommand):
FileSystemResourceDriver(local_resource_storage()))
model_storage = application_model_storage(
FileSystemModelDriver(local_model_storage()))
- deployment = model_storage.deployment.get(args_namespace.deployment_id)
+ deployment = model_storage.service_instance.get(args_namespace.deployment_id)
try:
workflow = deployment.workflows[args_namespace.workflow_id]
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/orchestrator/context/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py
index 53844e8..265901b 100644
--- a/aria/orchestrator/context/common.py
+++ b/aria/orchestrator/context/common.py
@@ -31,7 +31,7 @@ class BaseContext(logger.LoggerMixin):
def __init__(
self,
name,
- deployment_id,
+ service_instance_id,
model_storage,
resource_storage,
**kwargs):
@@ -40,12 +40,12 @@ class BaseContext(logger.LoggerMixin):
self._id = str(uuid4())
self._model = model_storage
self._resource = resource_storage
- self._deployment_id = deployment_id
+ self._service_instance_id = service_instance_id
def __repr__(self):
return (
'{name}(name={self.name}, '
- 'deployment_id={self._deployment_id}, '
+ 'deployment_id={self._service_instance_id}, '
.format(name=self.__class__.__name__, self=self))
@property
@@ -65,18 +65,18 @@ class BaseContext(logger.LoggerMixin):
return self._resource
@property
- def blueprint(self):
+ def service_template(self):
"""
The blueprint model
"""
- return self.deployment.blueprint
+ return self.service_instance.service_template
@property
- def deployment(self):
+ def service_instance(self):
"""
The deployment model
"""
- return self.model.deployment.get(self._deployment_id)
+ return self.model.service_instance.get(self._service_instance_id)
@property
def name(self):
@@ -99,11 +99,11 @@ class BaseContext(logger.LoggerMixin):
Download a blueprint resource from the resource storage
"""
try:
- self.resource.deployment.download(entry_id=str(self.deployment.id),
+ self.resource.deployment.download(entry_id=str(self.service_instance.id),
destination=destination,
path=path)
except exceptions.StorageError:
- self.resource.blueprint.download(entry_id=str(self.blueprint.id),
+ self.resource.blueprint.download(entry_id=str(self.service_template.id),
destination=destination,
path=path)
@@ -126,9 +126,9 @@ class BaseContext(logger.LoggerMixin):
Read a deployment resource as string from the resource storage
"""
try:
- return self.resource.deployment.read(entry_id=str(self.deployment.id), path=path)
+ return self.resource.deployment.read(entry_id=str(self.service_instance.id), path=path)
except exceptions.StorageError:
- return self.resource.blueprint.read(entry_id=str(self.blueprint.id), path=path)
+ return self.resource.deployment.read(entry_id=str(self.service_template.id), path=path)
def get_resource_and_render(self, path=None, variables=None):
"""
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/orchestrator/context/operation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/operation.py b/aria/orchestrator/context/operation.py
index 19bb73a..bba46aa 100644
--- a/aria/orchestrator/context/operation.py
+++ b/aria/orchestrator/context/operation.py
@@ -30,7 +30,7 @@ class BaseOperationContext(BaseContext):
name,
model_storage,
resource_storage,
- deployment_id,
+ service_instance_id,
task_id,
actor_id,
**kwargs):
@@ -38,7 +38,7 @@ class BaseOperationContext(BaseContext):
name=name,
model_storage=model_storage,
resource_storage=resource_storage,
- deployment_id=deployment_id,
+ service_instance_id=service_instance_id,
**kwargs)
self._task_id = task_id
self._actor_id = actor_id
@@ -63,20 +63,20 @@ class NodeOperationContext(BaseOperationContext):
Context for node based operations.
"""
@property
- def node(self):
+ def node_template(self):
"""
the node of the current operation
:return:
"""
- return self.node_instance.node
+ return self.node.node_template
@property
- def node_instance(self):
+ def node(self):
"""
The node instance of the current operation
:return:
"""
- return self.model.node_instance.get(self._actor_id)
+ return self.model.node.get(self._actor_id)
class RelationshipOperationContext(BaseOperationContext):
@@ -84,50 +84,41 @@ class RelationshipOperationContext(BaseOperationContext):
Context for relationship based operations.
"""
@property
- def source_node(self):
+ def source_node_template(self):
"""
The source node
:return:
"""
- return self.relationship.source_node
+ return self.source_node.node_template
@property
- def source_node_instance(self):
+ def source_node(self):
"""
The source node instance
:return:
"""
- return self.relationship_instance.source_node_instance
+ return self.relationship.source_node
@property
- def target_node(self):
+ def target_node_template(self):
"""
The target node
:return:
"""
- return self.relationship.target_node
+ return self.target_node.node_template
@property
- def target_node_instance(self):
+ def target_node(self):
"""
The target node instance
:return:
"""
- return self.relationship_instance.target_node_instance
+ return self.relationship.target_node
@property
def relationship(self):
"""
- The relationship of the current operation
- :return:
- """
-
- return self.relationship_instance.relationship
-
- @property
- def relationship_instance(self):
- """
The relationship instance of the current operation
:return:
"""
- return self.model.relationship_instance.get(self._actor_id)
+ return self.model.relationship.get(self._actor_id)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/orchestrator/context/serialization.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/serialization.py b/aria/orchestrator/context/serialization.py
index 93cb38a..12ae8b3 100644
--- a/aria/orchestrator/context/serialization.py
+++ b/aria/orchestrator/context/serialization.py
@@ -23,7 +23,7 @@ def operation_context_to_dict(context):
context_cls = context.__class__
context_dict = {
'name': context.name,
- 'deployment_id': context._deployment_id,
+ 'service_instance_id': context._service_instance_id,
'task_id': context._task_id,
'actor_id': context._actor_id,
}
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/orchestrator/context/toolbelt.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/toolbelt.py b/aria/orchestrator/context/toolbelt.py
index 301b013..def7d42 100644
--- a/aria/orchestrator/context/toolbelt.py
+++ b/aria/orchestrator/context/toolbelt.py
@@ -33,7 +33,7 @@ class NodeToolBelt(object):
:return:
"""
assert isinstance(self._op_context, operation.NodeOperationContext)
- host = self._op_context.node_instance.host
+ host = self._op_context.node.host
return host.runtime_properties.get('ip')
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/orchestrator/context/workflow.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/workflow.py b/aria/orchestrator/context/workflow.py
index a15790e..4a8d94f 100644
--- a/aria/orchestrator/context/workflow.py
+++ b/aria/orchestrator/context/workflow.py
@@ -49,18 +49,16 @@ class WorkflowContext(BaseContext):
def __repr__(self):
return (
- '{name}(deployment_id={self._deployment_id}, '
+ '{name}(deployment_id={self._service_instance_id}, '
'workflow_name={self._workflow_name}'.format(
name=self.__class__.__name__, self=self))
def _create_execution(self):
- execution_cls = self.model.execution.model_cls
now = datetime.utcnow()
execution = self.model.execution.model_cls(
- deployment=self.deployment,
+ service_instance=self.service_instance,
workflow_name=self._workflow_name,
created_at=now,
- status=execution_cls.PENDING,
parameters=self.parameters,
)
self.model.execution.put(execution)
@@ -81,27 +79,27 @@ class WorkflowContext(BaseContext):
self.model.execution.put(value)
@property
- def nodes(self):
+ def node_templates(self):
"""
Iterator over nodes
"""
- key = 'deployment_{0}'.format(self.model.node.model_cls.name_column_name())
+ key = 'deployment_{0}'.format(self.model.node_template.model_cls.name_column_name())
return self.model.node.iter(
filters={
- key: getattr(self.deployment, self.deployment.name_column_name())
+ key: getattr(self.service_instance, self.service_instance.node_template())
}
)
@property
- def node_instances(self):
+ def nodes(self):
"""
Iterator over node instances
"""
key = 'deployment_{0}'.format(self.model.node_instance.model_cls.name_column_name())
return self.model.node_instance.iter(
filters={
- key: getattr(self.deployment, self.deployment.name_column_name())
+ key: getattr(self.service_instance, self.service_instance.name_column_name())
}
)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/orchestrator/workflows/api/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/api/task.py b/aria/orchestrator/workflows/api/task.py
index 70324a6..b44cfbd 100644
--- a/aria/orchestrator/workflows/api/task.py
+++ b/aria/orchestrator/workflows/api/task.py
@@ -18,7 +18,7 @@ Provides the tasks to be entered into the task graph
"""
from uuid import uuid4
-from aria.storage import model
+from aria.storage.modeling import model
from ... import context
from .. import exceptions
@@ -57,13 +57,13 @@ class OperationTask(BaseTask):
Represents an operation task in the task_graph
"""
- SOURCE_OPERATION = 'source_operations'
- TARGET_OPERATION = 'target_operations'
+ SOURCE_OPERATION = 'source'
+ TARGET_OPERATION = 'target'
def __init__(self,
name,
actor,
- operation_mapping,
+ implementation,
max_attempts=None,
retry_interval=None,
ignore_failure=None,
@@ -75,12 +75,12 @@ class OperationTask(BaseTask):
:param actor: the operation host on which this operation is registered.
:param inputs: operation inputs.
"""
- assert isinstance(actor, (model.NodeInstance,
- model.RelationshipInstance))
+ assert isinstance(actor, (model.Node,
+ model.Relationship))
super(OperationTask, self).__init__()
self.actor = actor
self.name = '{name}.{actor.id}'.format(name=name, actor=actor)
- self.operation_mapping = operation_mapping
+ self.implementation = implementation
self.inputs = inputs or {}
self.plugin = plugin or {}
self.max_attempts = (self.workflow_context._task_max_attempts
@@ -98,58 +98,68 @@ class OperationTask(BaseTask):
:param instance: the node of which this operation belongs to.
:param name: the name of the operation.
"""
- assert isinstance(instance, model.NodeInstance)
- return cls._instance(instance=instance,
- name=name,
- operation_details=instance.node.operations[name],
- inputs=inputs,
- plugins=instance.node.plugins or [],
- *args,
- **kwargs)
+ assert isinstance(instance, model.Node)
+ interfaces = instance.interfaces.filter_by(name=name.rsplit('.', 1)[0])
+ if interfaces.count() != 1:
+ raise exceptions.TaskException(
+ "More than one interface with the same name {0} found".format(name))
+ operation_templates = interfaces[0].operations.filter_by(name=name)
+ if operation_templates.count() != 1:
+ raise exceptions.TaskException(
+ "More than one operation with the same name {0} found".format(name))
+
+ return cls._instance(
+ instance=instance,
+ name=name,
+ operation_template=operation_templates[0],
+ plugins=instance.plugins or [],
+ inputs=inputs,
+ *args,
+ **kwargs)
@classmethod
- def relationship_instance(cls, instance, name, operation_end, inputs=None, *args, **kwargs):
+ def relationship_instance(cls, instance, name, inputs=None, *args, **kwargs):
"""
Represents a relationship based operation
:param instance: the relationship of which this operation belongs to.
:param name: the name of the operation.
- :param operation_end: source or target end of the relationship, this corresponds directly
- with 'source_operations' and 'target_operations'
:param inputs any additional inputs to the operation
"""
- assert isinstance(instance, model.RelationshipInstance)
- if operation_end not in [cls.TARGET_OPERATION, cls.SOURCE_OPERATION]:
- raise exceptions.TaskException('The operation end should be {0} or {1}'.format(
- cls.TARGET_OPERATION, cls.SOURCE_OPERATION
- ))
- operation_details = getattr(instance.relationship, operation_end)[name]
+ assert isinstance(instance, model.Relationship)
+ interface_name, _, operation_end = name.rsplit('.', 2)
+ interfaces = getattr(instance, operation_end + '_interfaces').filter_by(name=interface_name)
+ if interfaces.count() != 1:
+ raise exceptions.TaskException(
+ "More than one interface with the same name {0} found".format(interface_name))
+
+ operations = interfaces.all()[0].operations.filter_by(name=name)
+ if operations.count() > 1:
+ raise exceptions.TaskException(
+ "More than one operation with the same name {0} found".format(name))
+
if operation_end == cls.SOURCE_OPERATION:
- plugins = instance.relationship.source_node.plugins
+ plugins = instance.source_node.plugins
else:
- plugins = instance.relationship.target_node.plugins
+ plugins = instance.target_node.plugins
return cls._instance(instance=instance,
name=name,
- operation_details=operation_details,
- inputs=inputs,
+ operation_template=operations[0],
plugins=plugins or [],
+ inputs=inputs,
*args,
**kwargs)
@classmethod
- def _instance(cls, instance, name, operation_details, inputs, plugins, *args, **kwargs):
- operation_mapping = operation_details.get('operation')
- operation_inputs = operation_details.get('inputs', {})
- operation_inputs.update(inputs or {})
- plugin_name = operation_details.get('plugin')
- matching_plugins = [p for p in plugins if p['name'] == plugin_name]
+ def _instance(cls, instance, name, operation_template, inputs, plugins, *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.
plugin = matching_plugins[0] if matching_plugins else {}
return cls(actor=instance,
name=name,
- operation_mapping=operation_mapping,
- inputs=operation_inputs,
+ implementation=operation_template.implementation,
+ inputs=inputs,
plugin=plugin,
*args,
**kwargs)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/orchestrator/workflows/core/engine.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/engine.py b/aria/orchestrator/workflows/core/engine.py
index 47269a3..4347fde 100644
--- a/aria/orchestrator/workflows/core/engine.py
+++ b/aria/orchestrator/workflows/core/engine.py
@@ -23,7 +23,7 @@ from datetime import datetime
import networkx
from aria import logger
-from aria.storage import model
+from aria.storage.modeling import model
from aria.orchestrator import events
from .. import exceptions
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/orchestrator/workflows/core/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/task.py b/aria/orchestrator/workflows/core/task.py
index 67be2ea..59cdd29 100644
--- a/aria/orchestrator/workflows/core/task.py
+++ b/aria/orchestrator/workflows/core/task.py
@@ -24,7 +24,7 @@ from functools import (
)
from aria import logger
-from aria.storage import model
+from aria.storage.modeling import model
from aria.orchestrator.context import operation as operation_context
from .. import exceptions
@@ -109,11 +109,11 @@ class OperationTask(BaseTask):
model_storage = api_task._workflow_context.model
base_task_model = model_storage.task.model_cls
- if isinstance(api_task.actor, model.NodeInstance):
- context_class = operation_context.NodeOperationContext
+ if isinstance(api_task.actor, model.Node):
+ context_cls = operation_context.NodeOperationContext
task_model_cls = base_task_model.as_node_instance
- elif isinstance(api_task.actor, model.RelationshipInstance):
- context_class = operation_context.RelationshipOperationContext
+ elif isinstance(api_task.actor, model.Relationship):
+ context_cls = operation_context.RelationshipOperationContext
task_model_cls = base_task_model.as_relationship_instance
else:
raise RuntimeError('No operation context could be created for {actor.model_cls}'
@@ -127,7 +127,7 @@ class OperationTask(BaseTask):
# package_name and package_version
operation_task = task_model_cls(
name=api_task.name,
- operation_mapping=api_task.operation_mapping,
+ implementation=api_task.implementation,
instance=api_task.actor,
inputs=api_task.inputs,
status=base_task_model.PENDING,
@@ -139,12 +139,12 @@ class OperationTask(BaseTask):
)
self._workflow_context.model.task.put(operation_task)
- self._ctx = context_class(name=api_task.name,
- model_storage=self._workflow_context.model,
- resource_storage=self._workflow_context.resource,
- deployment_id=self._workflow_context._deployment_id,
- task_id=operation_task.id,
- actor_id=api_task.actor.id)
+ self._ctx = context_cls(name=api_task.name,
+ model_storage=self._workflow_context.model,
+ resource_storage=self._workflow_context.resource,
+ service_instance_id=self._workflow_context._service_instance_id,
+ task_id=operation_task.id,
+ actor_id=api_task.actor.id)
self._task_id = operation_task.id
self._update_fields = None
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/orchestrator/workflows/executor/process.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/process.py b/aria/orchestrator/workflows/executor/process.py
index 51596c3..ea772c8 100644
--- a/aria/orchestrator/workflows/executor/process.py
+++ b/aria/orchestrator/workflows/executor/process.py
@@ -19,8 +19,8 @@ Subprocess based executor
# pylint: disable=wrong-import-position
-import sys
import os
+import sys
# As part of the process executor implementation, subprocess are started with this module as their
# entry point. We thus remove this module's directory from the python path if it happens to be
@@ -43,7 +43,7 @@ from aria.utils import imports
from aria.orchestrator.workflows.executor import base
from aria.orchestrator.context import serialization
from aria.storage import instrumentation
-from aria.storage import type as storage_type
+from aria.storage.modeling import type as storage_type
_IS_WIN = os.name == 'nt'
@@ -184,7 +184,7 @@ class ProcessExecutor(base.BaseExecutor):
def _create_arguments_dict(self, task):
return {
'task_id': task.id,
- 'operation_mapping': task.operation_mapping,
+ 'implementation': task.implementation,
'operation_inputs': task.inputs,
'port': self._server_port,
'context': serialization.operation_context_to_dict(task.context),
@@ -265,6 +265,10 @@ class _Messenger(object):
def _main():
+ # import pydevd
+ # pydevd.settrace('localhost', port=12345, stdoutToServer=True, stderrToServer=True)
+
+
arguments_json_path = sys.argv[1]
with open(arguments_json_path) as f:
arguments = jsonpickle.loads(f.read())
@@ -278,7 +282,7 @@ def _main():
messenger = _Messenger(task_id=task_id, port=port)
messenger.started()
- operation_mapping = arguments['operation_mapping']
+ implementation = arguments['implementation']
operation_inputs = arguments['operation_inputs']
context_dict = arguments['context']
@@ -289,7 +293,7 @@ def _main():
with instrumentation.track_changes() as instrument:
try:
ctx = serialization.operation_context_from_dict(context_dict)
- task_func = imports.load_attribute(operation_mapping)
+ task_func = imports.load_attribute(implementation)
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/82d9be7d/aria/orchestrator/workflows/executor/thread.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/thread.py b/aria/orchestrator/workflows/executor/thread.py
index 1a6ad9f..7ae0217 100644
--- a/aria/orchestrator/workflows/executor/thread.py
+++ b/aria/orchestrator/workflows/executor/thread.py
@@ -57,7 +57,7 @@ class ThreadExecutor(BaseExecutor):
task = self._queue.get(timeout=1)
self._task_started(task)
try:
- task_func = imports.load_attribute(task.operation_mapping)
+ task_func = imports.load_attribute(task.implementation)
task_func(ctx=task.context, **task.inputs)
self._task_succeeded(task)
except BaseException as e:
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/__init__.py
----------------------------------------------------------------------
diff --git a/aria/storage/__init__.py b/aria/storage/__init__.py
index a1c07d7..82bdc7e 100644
--- a/aria/storage/__init__.py
+++ b/aria/storage/__init__.py
@@ -42,14 +42,17 @@ from .core import (
ModelStorage,
ResourceStorage,
)
+from .modeling import (
+ structure,
+ model,
+ model_base
+)
from . import (
exceptions,
api,
- structure,
core,
filesystem_rapi,
sql_mapi,
- model
)
__all__ = (
@@ -60,5 +63,7 @@ __all__ = (
'ResourceStorage',
'filesystem_rapi',
'sql_mapi',
- 'api'
+ 'api',
+ 'model',
+ 'model_base',
)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/base_model.py
----------------------------------------------------------------------
diff --git a/aria/storage/base_model.py b/aria/storage/base_model.py
deleted file mode 100644
index a2bbb60..0000000
--- a/aria/storage/base_model.py
+++ /dev/null
@@ -1,744 +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.
-
-"""
-Aria's storage.models module
-Path: aria.storage.models
-
-models module holds aria's models.
-
-classes:
- * Field - represents a single field.
- * IterField - represents an iterable field.
- * Model - abstract model implementation.
- * Snapshot - snapshots implementation model.
- * Deployment - deployment implementation model.
- * DeploymentUpdateStep - deployment update step implementation model.
- * DeploymentUpdate - deployment update implementation model.
- * DeploymentModification - deployment modification implementation model.
- * Execution - execution implementation model.
- * Node - node implementation model.
- * Relationship - relationship implementation model.
- * NodeInstance - node instance implementation model.
- * RelationshipInstance - relationship instance implementation model.
- * Plugin - plugin implementation model.
-"""
-from collections import namedtuple
-from datetime import datetime
-
-from sqlalchemy.ext.associationproxy import association_proxy
-from sqlalchemy.ext.declarative import declared_attr
-from sqlalchemy import (
- Column,
- Integer,
- Text,
- DateTime,
- Boolean,
- Enum,
- String,
- Float,
- orm,
-)
-from sqlalchemy.ext.orderinglist import ordering_list
-
-from ..orchestrator.exceptions import TaskAbortException, TaskRetryException
-from .structure import ModelMixin
-from .type import (
- List,
- Dict
-)
-
-__all__ = (
- 'BlueprintBase',
- 'DeploymentBase',
- 'DeploymentUpdateStepBase',
- 'DeploymentUpdateBase',
- 'DeploymentModificationBase',
- 'ExecutionBase',
- 'NodeBase',
- 'RelationshipBase',
- 'NodeInstanceBase',
- 'RelationshipInstanceBase',
- 'PluginBase',
- 'TaskBase'
-)
-
-#pylint: disable=no-self-argument, abstract-method
-
-
-class BlueprintBase(ModelMixin):
- """
- Blueprint model representation.
- """
- __tablename__ = 'blueprints'
-
- created_at = Column(DateTime, nullable=False, index=True)
- main_file_name = Column(Text, nullable=False)
- plan = Column(Dict, nullable=False)
- updated_at = Column(DateTime)
- description = Column(Text)
-
-
-class DeploymentBase(ModelMixin):
- """
- Deployment model representation.
- """
- __tablename__ = 'deployments'
-
- _private_fields = ['blueprint_fk']
-
- created_at = Column(DateTime, nullable=False, index=True)
- description = Column(Text)
- inputs = Column(Dict)
- groups = Column(Dict)
- permalink = Column(Text)
- policy_triggers = Column(Dict)
- policy_types = Column(Dict)
- outputs = Column(Dict)
- scaling_groups = Column(Dict)
- updated_at = Column(DateTime)
- workflows = Column(Dict)
-
- @declared_attr
- def blueprint_fk(cls):
- return cls.foreign_key(BlueprintBase, nullable=False)
-
- @declared_attr
- def blueprint(cls):
- return cls.one_to_many_relationship('blueprint_fk')
-
- @declared_attr
- def blueprint_name(cls):
- return association_proxy('blueprint', cls.name_column_name())
-
-
-class ExecutionBase(ModelMixin):
- """
- Execution model representation.
- """
- # Needed only for pylint. the id will be populated by sqlalcehmy and the proper column.
- __tablename__ = 'executions'
- _private_fields = ['deployment_fk']
-
- TERMINATED = 'terminated'
- FAILED = 'failed'
- CANCELLED = 'cancelled'
- PENDING = 'pending'
- STARTED = 'started'
- CANCELLING = 'cancelling'
- FORCE_CANCELLING = 'force_cancelling'
-
- STATES = [TERMINATED, FAILED, CANCELLED, PENDING, STARTED, CANCELLING, FORCE_CANCELLING]
- END_STATES = [TERMINATED, FAILED, CANCELLED]
- ACTIVE_STATES = [state for state in STATES if state not in END_STATES]
-
- VALID_TRANSITIONS = {
- PENDING: [STARTED, CANCELLED],
- STARTED: END_STATES + [CANCELLING],
- CANCELLING: END_STATES + [FORCE_CANCELLING]
- }
-
- @orm.validates('status')
- def validate_status(self, key, value):
- """Validation function that verifies execution status transitions are OK"""
- try:
- current_status = getattr(self, key)
- except AttributeError:
- return
- valid_transitions = self.VALID_TRANSITIONS.get(current_status, [])
- if all([current_status is not None,
- current_status != value,
- value not in valid_transitions]):
- raise ValueError('Cannot change execution status from {current} to {new}'.format(
- current=current_status,
- new=value))
- return value
-
- created_at = Column(DateTime, index=True)
- started_at = Column(DateTime, nullable=True, index=True)
- ended_at = Column(DateTime, nullable=True, index=True)
- error = Column(Text, nullable=True)
- is_system_workflow = Column(Boolean, nullable=False, default=False)
- parameters = Column(Dict)
- status = Column(Enum(*STATES, name='execution_status'), default=PENDING)
- workflow_name = Column(Text)
-
- @declared_attr
- def blueprint(cls):
- return association_proxy('deployment', 'blueprint')
-
- @declared_attr
- def deployment_fk(cls):
- return cls.foreign_key(DeploymentBase, nullable=True)
-
- @declared_attr
- def deployment(cls):
- return cls.one_to_many_relationship('deployment_fk')
-
- @declared_attr
- def deployment_name(cls):
- return association_proxy('deployment', cls.name_column_name())
-
- @declared_attr
- def blueprint_name(cls):
- return association_proxy('deployment', 'blueprint_name')
-
- def __str__(self):
- return '<{0} id=`{1}` (status={2})>'.format(
- self.__class__.__name__,
- getattr(self, self.name_column_name()),
- self.status
- )
-
-
-class DeploymentUpdateBase(ModelMixin):
- """
- Deployment update model representation.
- """
- # Needed only for pylint. the id will be populated by sqlalcehmy and the proper column.
- steps = None
-
- __tablename__ = 'deployment_updates'
-
- _private_fields = ['execution_fk', 'deployment_fk']
-
- created_at = Column(DateTime, nullable=False, index=True)
- deployment_plan = Column(Dict, nullable=False)
- deployment_update_node_instances = Column(Dict)
- deployment_update_deployment = Column(Dict)
- deployment_update_nodes = Column(List)
- modified_entity_ids = Column(Dict)
- state = Column(Text)
-
- @declared_attr
- def execution_fk(cls):
- return cls.foreign_key(ExecutionBase, nullable=True)
-
- @declared_attr
- def execution(cls):
- return cls.one_to_many_relationship('execution_fk')
-
- @declared_attr
- def execution_name(cls):
- return association_proxy('execution', cls.name_column_name())
-
- @declared_attr
- def deployment_fk(cls):
- return cls.foreign_key(DeploymentBase)
-
- @declared_attr
- def deployment(cls):
- return cls.one_to_many_relationship('deployment_fk')
-
- @declared_attr
- def deployment_name(cls):
- return association_proxy('deployment', cls.name_column_name())
-
- def to_dict(self, suppress_error=False, **kwargs):
- dep_update_dict = super(DeploymentUpdateBase, self).to_dict(suppress_error) #pylint: disable=no-member
- # Taking care of the fact the DeploymentSteps are _BaseModels
- dep_update_dict['steps'] = [step.to_dict() for step in self.steps]
- return dep_update_dict
-
-
-class DeploymentUpdateStepBase(ModelMixin):
- """
- Deployment update step model representation.
- """
- # Needed only for pylint. the id will be populated by sqlalcehmy and the proper column.
- __tablename__ = 'deployment_update_steps'
- _private_fields = ['deployment_update_fk']
-
- _action_types = namedtuple('ACTION_TYPES', 'ADD, REMOVE, MODIFY')
- ACTION_TYPES = _action_types(ADD='add', REMOVE='remove', MODIFY='modify')
- _entity_types = namedtuple(
- 'ENTITY_TYPES',
- 'NODE, RELATIONSHIP, PROPERTY, OPERATION, WORKFLOW, OUTPUT, DESCRIPTION, GROUP, '
- 'POLICY_TYPE, POLICY_TRIGGER, PLUGIN')
- ENTITY_TYPES = _entity_types(
- NODE='node',
- RELATIONSHIP='relationship',
- PROPERTY='property',
- OPERATION='operation',
- WORKFLOW='workflow',
- OUTPUT='output',
- DESCRIPTION='description',
- GROUP='group',
- POLICY_TYPE='policy_type',
- POLICY_TRIGGER='policy_trigger',
- PLUGIN='plugin'
- )
-
- action = Column(Enum(*ACTION_TYPES, name='action_type'), nullable=False)
- entity_id = Column(Text, nullable=False)
- entity_type = Column(Enum(*ENTITY_TYPES, name='entity_type'), nullable=False)
-
- @declared_attr
- def deployment_update_fk(cls):
- return cls.foreign_key(DeploymentUpdateBase)
-
- @declared_attr
- def deployment_update(cls):
- return cls.one_to_many_relationship('deployment_update_fk', backreference='steps')
-
- @declared_attr
- def deployment_update_name(cls):
- return association_proxy('deployment_update', cls.name_column_name())
-
- def __hash__(self):
- return hash((getattr(self, self.id_column_name()), self.entity_id))
-
- def __lt__(self, other):
- """
- the order is 'remove' < 'modify' < 'add'
- :param other:
- :return:
- """
- if not isinstance(other, self.__class__):
- return not self >= other
-
- if self.action != other.action:
- if self.action == 'remove':
- return_value = True
- elif self.action == 'add':
- return_value = False
- else:
- return_value = other.action == 'add'
- return return_value
-
- if self.action == 'add':
- return self.entity_type == 'node' and other.entity_type == 'relationship'
- if self.action == 'remove':
- return self.entity_type == 'relationship' and other.entity_type == 'node'
- return False
-
-
-class DeploymentModificationBase(ModelMixin):
- """
- Deployment modification model representation.
- """
- __tablename__ = 'deployment_modifications'
- _private_fields = ['deployment_fk']
-
- STARTED = 'started'
- FINISHED = 'finished'
- ROLLEDBACK = 'rolledback'
-
- STATES = [STARTED, FINISHED, ROLLEDBACK]
- END_STATES = [FINISHED, ROLLEDBACK]
-
- context = Column(Dict)
- created_at = Column(DateTime, nullable=False, index=True)
- ended_at = Column(DateTime, index=True)
- modified_nodes = Column(Dict)
- node_instances = Column(Dict)
- status = Column(Enum(*STATES, name='deployment_modification_status'))
-
- @declared_attr
- def deployment_fk(cls):
- return cls.foreign_key(DeploymentBase)
-
- @declared_attr
- def deployment(cls):
- return cls.one_to_many_relationship('deployment_fk', backreference='modifications')
-
- @declared_attr
- def deployment_name(cls):
- return association_proxy('deployment', cls.name_column_name())
-
-
-class NodeBase(ModelMixin):
- """
- Node model representation.
- """
- __tablename__ = 'nodes'
-
- # See base class for an explanation on these properties
- is_id_unique = False
-
- _private_fields = ['blueprint_fk', 'host_fk']
-
- @declared_attr
- def host_fk(cls):
- return cls.foreign_key(NodeBase, nullable=True)
-
- @declared_attr
- def host(cls):
- return cls.relationship_to_self('host_fk')
-
- @declared_attr
- def host_name(cls):
- return association_proxy('host', cls.name_column_name())
-
- @declared_attr
- def deployment_fk(cls):
- return cls.foreign_key(DeploymentBase)
-
- @declared_attr
- def deployment(cls):
- return cls.one_to_many_relationship('deployment_fk')
-
- @declared_attr
- def deployment_name(cls):
- return association_proxy('deployment', cls.name_column_name())
-
- @declared_attr
- def blueprint_name(cls):
- return association_proxy('deployment', 'blueprint_{0}'.format(cls.name_column_name()))
-
- deploy_number_of_instances = Column(Integer, nullable=False)
- max_number_of_instances = Column(Integer, nullable=False)
- min_number_of_instances = Column(Integer, nullable=False)
- number_of_instances = Column(Integer, nullable=False)
- planned_number_of_instances = Column(Integer, nullable=False)
- plugins = Column(List)
- properties = Column(Dict)
- operations = Column(Dict)
- type = Column(Text, nullable=False, index=True)
- type_hierarchy = Column(List)
-
-
-class RelationshipBase(ModelMixin):
- """
- Relationship model representation.
- """
- __tablename__ = 'relationships'
-
- _private_fields = ['source_node_fk', 'target_node_fk', 'source_position', 'target_position']
-
- source_position = Column(Integer)
- target_position = Column(Integer)
-
- @declared_attr
- def deployment_id(self):
- return association_proxy('source_node', 'deployment_id')
-
- @declared_attr
- def source_node_fk(cls):
- return cls.foreign_key(NodeBase)
-
- @declared_attr
- def source_node(cls):
- return cls.one_to_many_relationship(
- 'source_node_fk',
- backreference='outbound_relationships',
- backref_kwargs=dict(
- order_by=cls.source_position,
- collection_class=ordering_list('source_position', count_from=0)
- )
- )
-
- @declared_attr
- def source_name(cls):
- return association_proxy('source_node', cls.name_column_name())
-
- @declared_attr
- def target_node_fk(cls):
- return cls.foreign_key(NodeBase, nullable=True)
-
- @declared_attr
- def target_node(cls):
- return cls.one_to_many_relationship(
- 'target_node_fk',
- backreference='inbound_relationships',
- backref_kwargs=dict(
- order_by=cls.target_position,
- collection_class=ordering_list('target_position', count_from=0)
- )
- )
-
- @declared_attr
- def target_name(cls):
- return association_proxy('target_node', cls.name_column_name())
-
- source_interfaces = Column(Dict)
- source_operations = Column(Dict, nullable=False)
- target_interfaces = Column(Dict)
- target_operations = Column(Dict, nullable=False)
- type = Column(String, nullable=False)
- type_hierarchy = Column(List)
- properties = Column(Dict)
-
-
-class NodeInstanceBase(ModelMixin):
- """
- Node instance model representation.
- """
- __tablename__ = 'node_instances'
- _private_fields = ['node_fk', 'host_fk']
-
- runtime_properties = Column(Dict)
- scaling_groups = Column(List)
- state = Column(Text, nullable=False)
- version = Column(Integer, default=1)
-
- @declared_attr
- def host_fk(cls):
- return cls.foreign_key(NodeInstanceBase, nullable=True)
-
- @declared_attr
- def host(cls):
- return cls.relationship_to_self('host_fk')
-
- @declared_attr
- def host_name(cls):
- return association_proxy('host', cls.name_column_name())
-
- @declared_attr
- def deployment(cls):
- return association_proxy('node', 'deployment')
-
- @declared_attr
- def deployment_name(cls):
- return association_proxy('node', 'deployment_name')
-
- @declared_attr
- def node_fk(cls):
- return cls.foreign_key(NodeBase, nullable=True)
-
- @declared_attr
- def node(cls):
- return cls.one_to_many_relationship('node_fk')
-
- @declared_attr
- def node_name(cls):
- return association_proxy('node', cls.name_column_name())
-
- @property
- def ip(self):
- if not self.host_fk:
- return None
- host_node_instance = self.host
- if 'ip' in host_node_instance.runtime_properties: # pylint: disable=no-member
- return host_node_instance.runtime_properties['ip'] # pylint: disable=no-member
- host_node = host_node_instance.node # pylint: disable=no-member
- if 'ip' in host_node.properties:
- return host_node.properties['ip']
- return None
-
-
-class RelationshipInstanceBase(ModelMixin):
- """
- Relationship instance model representation.
- """
- __tablename__ = 'relationship_instances'
- _private_fields = ['relationship_storage_fk',
- 'source_node_instance_fk',
- 'target_node_instance_fk',
- 'source_position',
- 'target_position']
-
- source_position = Column(Integer)
- target_position = Column(Integer)
-
- @declared_attr
- def source_node_instance_fk(cls):
- return cls.foreign_key(NodeInstanceBase, nullable=True)
-
- @declared_attr
- def source_node_instance(cls):
- return cls.one_to_many_relationship(
- 'source_node_instance_fk',
- backreference='outbound_relationship_instances',
- backref_kwargs=dict(
- order_by=cls.source_position,
- collection_class=ordering_list('source_position', count_from=0)
- )
- )
-
- @declared_attr
- def source_node_instance_name(cls):
- return association_proxy('source_node_instance', 'node_{0}'.format(cls.name_column_name()))
-
- @declared_attr
- def source_node_name(cls):
- return association_proxy('source_node_instance', cls.name_column_name())
-
- @declared_attr
- def target_node_instance_fk(cls):
- return cls.foreign_key(NodeInstanceBase, nullable=True)
-
- @declared_attr
- def target_node_instance(cls):
- return cls.one_to_many_relationship(
- 'target_node_instance_fk',
- backreference='inbound_relationship_instances',
- backref_kwargs=dict(
- order_by=cls.target_position,
- collection_class=ordering_list('target_position', count_from=0)
- )
- )
-
- @declared_attr
- def target_node_instance_name(cls):
- return association_proxy('target_node_instance', cls.name_column_name())
-
- @declared_attr
- def target_node_name(cls):
- return association_proxy('target_node_instance', 'node_{0}'.format(cls.name_column_name()))
-
- @declared_attr
- def relationship_fk(cls):
- return cls.foreign_key(RelationshipBase)
-
- @declared_attr
- def relationship(cls):
- return cls.one_to_many_relationship('relationship_fk')
-
- @declared_attr
- def relationship_name(cls):
- return association_proxy('relationship', cls.name_column_name())
-
-
-
-class PluginBase(ModelMixin):
- """
- Plugin model representation.
- """
- __tablename__ = 'plugins'
-
- archive_name = Column(Text, nullable=False, index=True)
- distribution = Column(Text)
- distribution_release = Column(Text)
- distribution_version = Column(Text)
- package_name = Column(Text, nullable=False, index=True)
- package_source = Column(Text)
- package_version = Column(Text)
- supported_platform = Column(Text)
- supported_py_versions = Column(List)
- uploaded_at = Column(DateTime, nullable=False, index=True)
- wheels = Column(List, nullable=False)
-
-
-class TaskBase(ModelMixin):
- """
- A Model which represents an task
- """
- __tablename__ = 'tasks'
- _private_fields = ['node_instance_fk', 'relationship_instance_fk', 'execution_fk']
-
- @declared_attr
- def node_instance_fk(cls):
- return cls.foreign_key(NodeInstanceBase, nullable=True)
-
- @declared_attr
- def node_instance_name(cls):
- return association_proxy('node_instance', cls.name_column_name())
-
- @declared_attr
- def node_instance(cls):
- return cls.one_to_many_relationship('node_instance_fk')
-
- @declared_attr
- def relationship_instance_fk(cls):
- return cls.foreign_key(RelationshipInstanceBase, nullable=True)
-
- @declared_attr
- def relationship_instance_name(cls):
- return association_proxy('relationship_instance', cls.name_column_name())
-
- @declared_attr
- def relationship_instance(cls):
- return cls.one_to_many_relationship('relationship_instance_fk')
-
- @declared_attr
- def plugin_fk(cls):
- return cls.foreign_key(PluginBase, nullable=True)
-
- @declared_attr
- def plugin(cls):
- 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)
-
- @declared_attr
- def execution(cls):
- return cls.one_to_many_relationship('execution_fk')
-
- @declared_attr
- def execution_name(cls):
- return association_proxy('execution', cls.name_column_name())
-
- PENDING = 'pending'
- RETRYING = 'retrying'
- SENT = 'sent'
- STARTED = 'started'
- SUCCESS = 'success'
- FAILED = 'failed'
- STATES = (
- PENDING,
- RETRYING,
- SENT,
- STARTED,
- SUCCESS,
- FAILED,
- )
-
- WAIT_STATES = [PENDING, RETRYING]
- END_STATES = [SUCCESS, FAILED]
-
- @orm.validates('max_attempts')
- def validate_max_attempts(self, _, value): # pylint: disable=no-self-use
- """Validates that max attempts is either -1 or a positive number"""
- if value < 1 and value != TaskBase.INFINITE_RETRIES:
- raise ValueError('Max attempts can be either -1 (infinite) or any positive number. '
- 'Got {value}'.format(value=value))
- return value
-
- INFINITE_RETRIES = -1
-
- status = Column(Enum(*STATES, name='status'), default=PENDING)
-
- due_at = Column(DateTime, default=datetime.utcnow)
- started_at = Column(DateTime, default=None)
- ended_at = Column(DateTime, default=None)
- max_attempts = Column(Integer, default=1)
- retry_count = Column(Integer, default=0)
- retry_interval = Column(Float, default=0)
- ignore_failure = Column(Boolean, default=False)
-
- # Operation specific fields
- operation_mapping = Column(String)
- inputs = Column(Dict)
-
- @property
- def actor(self):
- """
- Return the actor of the task
- :return:
- """
- return self.node_instance or self.relationship_instance
-
- @classmethod
- def as_node_instance(cls, instance, **kwargs):
- return cls(node_instance=instance, **kwargs)
-
- @classmethod
- def as_relationship_instance(cls, instance, **kwargs):
- return cls(relationship_instance=instance, **kwargs)
-
- @staticmethod
- def abort(message=None):
- raise TaskAbortException(message)
-
- @staticmethod
- def retry(message=None, retry_interval=None):
- raise TaskRetryException(message, retry_interval=retry_interval)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/instrumentation.py
----------------------------------------------------------------------
diff --git a/aria/storage/instrumentation.py b/aria/storage/instrumentation.py
index d71190d..3a762ba 100644
--- a/aria/storage/instrumentation.py
+++ b/aria/storage/instrumentation.py
@@ -18,11 +18,11 @@ import copy
import sqlalchemy.event
from . import api
-from . import model as _model
+from .modeling import model as _model
_STUB = object()
_INSTRUMENTED = {
- _model.NodeInstance.runtime_properties: dict
+ _model.Node.runtime_properties: dict
}
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/model.py
----------------------------------------------------------------------
diff --git a/aria/storage/model.py b/aria/storage/model.py
deleted file mode 100644
index afca3e4..0000000
--- a/aria/storage/model.py
+++ /dev/null
@@ -1,110 +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.
-
-"""
-Aria's storage.models module
-Path: aria.storage.models
-
-models module holds aria's models.
-
-classes:
- * Field - represents a single field.
- * IterField - represents an iterable field.
- * Model - abstract model implementation.
- * Snapshot - snapshots implementation model.
- * Deployment - deployment implementation model.
- * DeploymentUpdateStep - deployment update step implementation model.
- * DeploymentUpdate - deployment update implementation model.
- * DeploymentModification - deployment modification implementation model.
- * Execution - execution implementation model.
- * Node - node implementation model.
- * Relationship - relationship implementation model.
- * NodeInstance - node instance implementation model.
- * RelationshipInstance - relationship instance implementation model.
- * ProviderContext - provider context implementation model.
- * Plugin - plugin implementation model.
-"""
-from sqlalchemy.ext.declarative import declarative_base
-
-from . import structure
-from . import base_model as base
-
-__all__ = (
- 'Blueprint',
- 'Deployment',
- 'DeploymentUpdateStep',
- 'DeploymentUpdate',
- 'DeploymentModification',
- 'Execution',
- 'Node',
- 'Relationship',
- 'NodeInstance',
- 'RelationshipInstance',
- 'Plugin',
-)
-
-
-#pylint: disable=abstract-method
-# The required abstract method implementation are implemented in the ModelIDMixin, which is used as
-# a base to the DeclerativeBase.
-DeclarativeBase = declarative_base(cls=structure.ModelIDMixin)
-
-
-class Blueprint(DeclarativeBase, base.BlueprintBase):
- pass
-
-
-class Deployment(DeclarativeBase, base.DeploymentBase):
- pass
-
-
-class Execution(DeclarativeBase, base.ExecutionBase):
- pass
-
-
-class DeploymentUpdate(DeclarativeBase, base.DeploymentUpdateBase):
- pass
-
-
-class DeploymentUpdateStep(DeclarativeBase, base.DeploymentUpdateStepBase):
- pass
-
-
-class DeploymentModification(DeclarativeBase, base.DeploymentModificationBase):
- pass
-
-
-class Node(DeclarativeBase, base.NodeBase):
- pass
-
-
-class Relationship(DeclarativeBase, base.RelationshipBase):
- pass
-
-
-class NodeInstance(DeclarativeBase, base.NodeInstanceBase):
- pass
-
-
-class RelationshipInstance(DeclarativeBase, base.RelationshipInstanceBase):
- pass
-
-
-class Plugin(DeclarativeBase, base.PluginBase):
- pass
-
-
-class Task(DeclarativeBase, base.TaskBase):
- pass
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/modeling/__init__.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/__init__.py b/aria/storage/modeling/__init__.py
new file mode 100644
index 0000000..1d5936e
--- /dev/null
+++ b/aria/storage/modeling/__init__.py
@@ -0,0 +1,37 @@
+# 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 collections import namedtuple
+
+from . import (
+ model,
+ instance_elements as _instance_base,
+ orchestrator_elements as _orchestrator_base,
+ template_elements as _template_base,
+)
+from .model import DB as declarative_base
+
+_ModelBaseCls = namedtuple('ModelBase', 'instance_elements,'
+ 'orchestrator_elements,'
+ 'template_elements')
+model_base = _ModelBaseCls(instance_elements=_instance_base,
+ orchestrator_elements=_orchestrator_base,
+ template_elements=_template_base)
+
+__all__ = (
+ 'model',
+ 'model_base',
+ 'declarative_base'
+)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/modeling/elements.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/elements.py b/aria/storage/modeling/elements.py
new file mode 100644
index 0000000..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)))
[3/5] incubator-ariatosca git commit: wip
Posted by mx...@apache.org.
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 0000000..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, self.policy_templates)
+ utils.instantiate_dict(context, self, service_instance.operations, self.operation_templates)
+
+ if self.substitution_template is not None:
+ service_instance.substitution = self.substitution_template.instantiate(context,
+ container)
+
+ utils.instantiate_dict(context, self, service_instance.inputs, self.inputs)
+ utils.instantiate_dict(context, self, service_instance.outputs, self.outputs)
+
+ for name, the_input in context.modeling.inputs.iteritems():
+ if name not in service_instance.inputs:
+ context.validation.report('input "%s" is not supported' % name)
+ else:
+ service_instance.inputs[name].value = the_input
+
+ return service_instance
+
+ def validate(self, context):
+ if self.metadata is not None:
+ self.metadata.validate(context)
+ utils.validate_dict_values(context, self.node_templates)
+ utils.validate_dict_values(context, self.group_templates)
+ utils.validate_dict_values(context, self.policy_templates)
+ if self.substitution_template is not None:
+ self.substitution_template.validate(context)
+ utils.validate_dict_values(context, self.inputs)
+ utils.validate_dict_values(context, self.outputs)
+ utils.validate_dict_values(context, self.operation_templates)
+
+ def coerce_values(self, context, container, report_issues):
+ if self.metadata is not None:
+ self.metadata.coerce_values(context, container, report_issues)
+ utils.coerce_dict_values(context, container, self.node_templates, report_issues)
+ utils.coerce_dict_values(context, container, self.group_templates, report_issues)
+ utils.coerce_dict_values(context, container, self.policy_templates, report_issues)
+ if self.substitution_template is not None:
+ self.substitution_template.coerce_values(context, container, report_issues)
+ utils.coerce_dict_values(context, container, self.inputs, report_issues)
+ utils.coerce_dict_values(context, container, self.outputs, report_issues)
+ utils.coerce_dict_values(context, container, self.operation_templates, report_issues)
+
+ def dump(self, context):
+ if self.description is not None:
+ console.puts(context.style.meta(self.description))
+ if self.metadata is not None:
+ self.metadata.dump(context)
+ for node_template in self.node_templates.itervalues():
+ node_template.dump(context)
+ for group_template in self.group_templates.itervalues():
+ group_template.dump(context)
+ for policy_template in self.policy_templates.itervalues():
+ policy_template.dump(context)
+ if self.substitution_template is not None:
+ self.substitution_template.dump(context)
+ dump_parameters(context, self.inputs, 'Inputs')
+ dump_parameters(context, self.outputs, 'Outputs')
+ utils.dump_dict_values(context, self.operation_templates, 'Operation templates')
+
+
+class InterfaceTemplateBase(structure.ModelMixin):
+ __tablename__ = 'interface_template'
+ # region foreign keys
+
+ @declared_attr
+ def node_template_fk(cls):
+ return cls.foreign_key('node_template', nullable=True)
+
+ @declared_attr
+ def group_template_fk(cls):
+ return cls.foreign_key('group_template', nullable=True)
+
+ # endregion
+
+ description = Column(Text)
+ type_name = Column(Text)
+
+ # region one-to-many relationships
+ @declared_attr
+ def operation_templates(cls):
+ return cls.one_to_many_relationship('operation_template')
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def inputs(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='inputs')
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('type_name', self.type_name),
+ ('inputs', formatting.as_raw_dict(self.properties)), # pylint: disable=no-member
+ # TODO fix self.properties reference
+ ('operation_templates', formatting.as_raw_list(self.operation_templates))))
+
+ def instantiate(self, context, container):
+ interface = instance_elements.InterfaceBase(self.name, self.type_name)
+ interface.description = deepcopy_with_locators(self.description)
+ utils.instantiate_dict(context, container, interface.inputs, self.inputs)
+ utils.instantiate_dict(context, container, interface.operations, self.operation_templates)
+ return interface
+
+ def validate(self, context):
+ if self.type_name:
+ if context.modeling.interface_types.get_descendant(self.type_name) is None:
+ context.validation.report('interface "%s" has an unknown type: %s'
+ % (self.name, formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.inputs)
+ utils.validate_dict_values(context, self.operation_templates)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.inputs, report_issues)
+ utils.coerce_dict_values(context, container, self.operation_templates, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Interface type: %s' % context.style.type(self.type_name))
+ dump_parameters(context, self.inputs, 'Inputs')
+ utils.dump_dict_values(context, self.operation_templates, 'Operation templates')
+
+
+class OperationTemplateBase(structure.ModelMixin):
+ __tablename__ = 'operation_template'
+
+ # region foreign keys
+
+ @declared_attr
+ def service_template_fk(cls):
+ return cls.foreign_key('service_template', nullable=True)
+
+ @declared_attr
+ def interface_template_fk(cls):
+ return cls.foreign_key('interface_template', nullable=True)
+
+ # endregion
+
+ description = Column(Text)
+ implementation = Column(Text)
+ dependencies = Column(aria_type.StrictList(item_cls=basestring))
+ executor = Column(Text)
+ max_retries = Column(Integer)
+ retry_interval = Column(Integer)
+
+ # region orchestrator required columns
+ plugin = Column(Text)
+ operation = Column(Boolean)
+
+ @declared_attr
+ def service_template(cls):
+ return cls.many_to_one_relationship('service_template')
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def inputs(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='inputs')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('implementation', self.implementation),
+ ('dependencies', self.dependencies),
+ ('executor', self.executor),
+ ('max_retries', self.max_retries),
+ ('retry_interval', self.retry_interval),
+ ('inputs', formatting.as_raw_dict(self.inputs))))
+
+ def instantiate(self, context, container):
+ operation = instance_elements.OperationBase(self.name)
+ operation.description = deepcopy_with_locators(self.description)
+ operation.implementation = self.implementation
+ operation.dependencies = self.dependencies
+ operation.executor = self.executor
+ operation.max_retries = self.max_retries
+ operation.retry_interval = self.retry_interval
+ utils.instantiate_dict(context, container, operation.inputs, self.inputs)
+ return operation
+
+ def validate(self, context):
+ utils.validate_dict_values(context, self.inputs)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.inputs, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ if self.implementation is not None:
+ console.puts('Implementation: %s' % context.style.literal(self.implementation))
+ if self.dependencies:
+ console.puts('Dependencies: %s' % ', '.join(
+ (str(context.style.literal(v)) for v in self.dependencies)))
+ if self.executor is not None:
+ console.puts('Executor: %s' % context.style.literal(self.executor))
+ if self.max_retries is not None:
+ console.puts('Max retries: %s' % context.style.literal(self.max_retries))
+ if self.retry_interval is not None:
+ console.puts('Retry interval: %s' % context.style.literal(self.retry_interval))
+ dump_parameters(context, self.inputs, 'Inputs')
+
+
+class ArtifactTemplateBase(structure.ModelMixin):
+ """
+ A file associated with a :class:`NodeTemplate`.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`description`: Description
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`source_path`: Source path (CSAR or repository)
+ * :code:`target_path`: Path at destination machine
+ * :code:`repository_url`: Repository URL
+ * :code:`repository_credential`: Dict of string
+ * :code:`properties`: Dict of :class:`Parameter`
+ """
+ __tablename__ = 'artifact_template'
+ # region foreign keys
+
+ @declared_attr
+ def node_template_fk(cls):
+ return cls.foreign_key('node_template')
+
+ # endregion
+
+ description = Column(Text)
+ type_name = Column(Text)
+ source_path = Column(Text)
+ target_path = Column(Text)
+ repository_url = Column(Text)
+ repository_credential = Column(aria_type.StrictDict(basestring, basestring))
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('type_name', self.type_name),
+ ('source_path', self.source_path),
+ ('target_path', self.target_path),
+ ('repository_url', self.repository_url),
+ ('repository_credential', formatting.as_agnostic(self.repository_credential)),
+ ('properties', formatting.as_raw_dict(self.properties.iteritems()))))
+
+ def instantiate(self, context, container):
+ artifact = instance_elements.ArtifactBase(self.name, self.type_name, self.source_path)
+ artifact.description = deepcopy_with_locators(self.description)
+ artifact.target_path = self.target_path
+ artifact.repository_url = self.repository_url
+ artifact.repository_credential = self.repository_credential
+ utils.instantiate_dict(context, container, artifact.properties, self.properties)
+ return artifact
+
+ def validate(self, context):
+ if context.modeling.artifact_types.get_descendant(self.type_name) is None:
+ context.validation.report('artifact "%s" has an unknown type: %s'
+ % (self.name, formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.properties)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.properties, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Artifact type: %s' % context.style.type(self.type_name))
+ console.puts('Source path: %s' % context.style.literal(self.source_path))
+ if self.target_path is not None:
+ console.puts('Target path: %s' % context.style.literal(self.target_path))
+ if self.repository_url is not None:
+ console.puts('Repository URL: %s' % context.style.literal(self.repository_url))
+ if self.repository_credential:
+ console.puts('Repository credential: %s'
+ % context.style.literal(self.repository_credential))
+ dump_parameters(context, self.properties)
+
+
+class PolicyTemplateBase(structure.ModelMixin):
+ """
+ Policies can be applied to zero or more :class:`NodeTemplate` or :class:`GroupTemplate`
+ instances.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`description`: Description
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`properties`: Dict of :class:`Parameter`
+ * :code:`target_node_template_names`: Must be represented in the :class:`ServiceModel`
+ * :code:`target_group_template_names`: Must be represented in the :class:`ServiceModel`
+ """
+ __tablename__ = 'policy_template'
+ # region foreign keys
+ @declared_attr
+ def service_template_fk(cls):
+ return cls.foreign_key('service_template')
+
+ @declared_attr
+ def group_template_fk(cls):
+ return cls.foreign_key('group_template')
+
+ # endregion
+
+ description = Column(Text)
+ type_name = Column(Text)
+ target_node_template_names = Column(aria_type.StrictList(basestring))
+ target_group_template_names = Column(aria_type.StrictList(basestring))
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('type_name', self.type_name),
+ ('properties', formatting.as_raw_dict(self.properties)),
+ ('target_node_template_names', self.target_node_template_names),
+ ('target_group_template_names', self.target_group_template_names)))
+
+ def instantiate(self, context, *args, **kwargs):
+ policy = instance_elements.PolicyBase(self.name, self.type_name)
+ utils.instantiate_dict(context, self, policy.properties, self.properties)
+ for node_template_name in self.target_node_template_names:
+ policy.target_node_ids.extend(
+ context.modeling.instance.get_node_ids(node_template_name))
+ for group_template_name in self.target_group_template_names:
+ policy.target_group_ids.extend(
+ context.modeling.instance.get_group_ids(group_template_name))
+ return policy
+
+ def validate(self, context):
+ if context.modeling.policy_types.get_descendant(self.type_name) is None:
+ context.validation.report('policy template "%s" has an unknown type: %s'
+ % (self.name, formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.properties)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, self, self.properties, report_issues)
+
+ def dump(self, context):
+ console.puts('Policy template: %s' % context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Type: %s' % context.style.type(self.type_name))
+ dump_parameters(context, self.properties)
+ if self.target_node_template_names:
+ console.puts('Target node templates: %s' % ', '.join(
+ (str(context.style.node(v)) for v in self.target_node_template_names)))
+ if self.target_group_template_names:
+ console.puts('Target group templates: %s' % ', '.join(
+ (str(context.style.node(v)) for v in self.target_group_template_names)))
+
+
+class GroupPolicyTemplateBase(structure.ModelMixin):
+ """
+ Policies applied to groups.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`description`: Description
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`properties`: Dict of :class:`Parameter`
+ * :code:`triggers`: Dict of :class:`GroupPolicyTrigger`
+ """
+
+ __tablename__ = 'group_policy_template'
+ # region foreign keys
+ @declared_attr
+ def group_template_fk(cls):
+ return cls.foreign_key('group_template')
+
+ # endregion
+
+ description = Column(Text)
+ type_name = Column(Text)
+
+ # region one-to-many relationships
+ @declared_attr
+ def triggers(cls):
+ return cls.one_to_many_relationship('group_policy_trigger_template')
+
+ # end region
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('type_name', self.type_name),
+ ('properties', formatting.as_raw_dict(self.properties)),
+ ('triggers', formatting.as_raw_list(self.triggers))))
+
+ def instantiate(self, context, container):
+ group_policy = instance_elements.GroupPolicyBase(self.name, self.type_name)
+ group_policy.description = deepcopy_with_locators(self.description)
+ utils.instantiate_dict(context, container, group_policy.properties, self.properties)
+ utils.instantiate_dict(context, container, group_policy.triggers, self.triggers)
+ return group_policy
+
+ def validate(self, context):
+ if context.modeling.policy_types.get_descendant(self.type_name) is None:
+ context.validation.report('group policy "%s" has an unknown type: %s'
+ % (self.name, formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.properties)
+ utils.validate_dict_values(context, self.triggers)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.properties, report_issues)
+ utils.coerce_dict_values(context, container, self.triggers, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Group policy type: %s' % context.style.type(self.type_name))
+ dump_parameters(context, self.properties)
+ utils.dump_dict_values(context, self.triggers, 'Triggers')
+
+
+class GroupPolicyTriggerTemplateBase(structure.ModelMixin):
+ """
+ Triggers for :class:`GroupPolicyTemplate`.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`description`: Description
+ * :code:`implementation`: Implementation string (interpreted by the orchestrator)
+ * :code:`properties`: Dict of :class:`Parameter`
+ """
+ __tablename__ = 'group_policy_trigger_template'
+ # region foreign keys
+ @declared_attr
+ def group_policy_template_fk(cls):
+ return cls.foreign_key('group_policy_template')
+
+ # endregion
+
+ description = Column(Text)
+ implementation = Column(Text)
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('implementation', self.implementation),
+ ('properties', formatting.as_raw_dict(self.properties))))
+
+ def instantiate(self, context, container):
+ group_policy_trigger = instance_elements.GroupPolicyTriggerBase(self.name,
+ self.implementation)
+ group_policy_trigger.description = deepcopy_with_locators(self.description)
+ utils.instantiate_dict(context, container, group_policy_trigger.properties,
+ self.properties)
+ return group_policy_trigger
+
+ def validate(self, context):
+ utils.validate_dict_values(context, self.properties)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.properties, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Implementation: %s' % context.style.literal(self.implementation))
+ dump_parameters(context, self.properties)
+
+
+class MappingTemplateBase(structure.ModelMixin):
+ """
+ Used by :class:`SubstitutionTemplate` to map a capability or a requirement to a node.
+
+ Properties:
+
+ * :code:`mapped_name`: Exposed capability or requirement name
+ * :code:`node_template_name`: Must be represented in the :class:`ServiceModel`
+ * :code:`name`: Name of capability or requirement at the node template
+ """
+ __tablename__ = 'mapping_template'
+
+ mapped_name = Column(Text)
+ node_template_name = Column(Text)
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('mapped_name', self.mapped_name),
+ ('node_template_name', self.node_template_name),
+ ('name', self.name)))
+
+ def instantiate(self, context, *args, **kwargs):
+ nodes = context.modeling.instance.find_nodes(self.node_template_name)
+ if len(nodes) == 0:
+ context.validation.report(
+ 'mapping "%s" refer to node template "%s" but there are no '
+ 'node instances' % (self.mapped_name,
+ self.node_template_name),
+ level=validation.Issue.BETWEEN_INSTANCES)
+ return None
+ return instance_elements.MappingBase(self.mapped_name, nodes[0].id, self.name)
+
+ def validate(self, context):
+ if self.node_template_name not in context.modeling.model.node_templates:
+ context.validation.report('mapping "%s" refers to an unknown node template: %s'
+ % (
+ self.mapped_name,
+ formatting.safe_repr(self.node_template_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ def dump(self, context):
+ console.puts('%s -> %s.%s' % (context.style.node(self.mapped_name),
+ context.style.node(self.node_template_name),
+ context.style.node(self.name)))
+
+
+class SubstitutionTemplateBase(structure.ModelMixin):
+ """
+ Used to substitute a single node for the entire deployment.
+
+ Properties:
+
+ * :code:`node_type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`capability_templates`: Dict of :class:`MappingTemplate`
+ * :code:`requirement_templates`: Dict of :class:`MappingTemplate`
+ """
+ __tablename__ = 'substitution_template'
+ node_type_name = Column(Text)
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def capability_templates(cls):
+ return cls.many_to_many_relationship('mapping_template',
+ table_prefix='capability_templates',
+ relationship_kwargs=dict(lazy='dynamic'))
+
+ @declared_attr
+ def requirement_templates(cls):
+ return cls.many_to_many_relationship('mapping_template',
+ table_prefix='requirement_templates',
+ relationship_kwargs=dict(lazy='dynamic'))
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('node_type_name', self.node_type_name),
+ ('capability_templates', formatting.as_raw_list(self.capability_templates)),
+ ('requirement_templates', formatting.as_raw_list(self.requirement_templates))))
+
+ def instantiate(self, context, container):
+ substitution = instance_elements.SubstitutionBase(self.node_type_name)
+ utils.instantiate_dict(context, container, substitution.capabilities,
+ self.capability_templates)
+ utils.instantiate_dict(context, container, substitution.requirements,
+ self.requirement_templates)
+ return substitution
+
+ def validate(self, context):
+ if context.modeling.node_types.get_descendant(self.node_type_name) is None:
+ context.validation.report('substitution template has an unknown type: %s'
+ % formatting.safe_repr(self.node_type_name),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.capability_templates)
+ utils.validate_dict_values(context, self.requirement_templates)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, self, self.capability_templates, report_issues)
+ utils.coerce_dict_values(context, self, self.requirement_templates, report_issues)
+
+ def dump(self, context):
+ console.puts('Substitution template:')
+ with context.style.indent:
+ console.puts('Node type: %s' % context.style.type(self.node_type_name))
+ utils.dump_dict_values(context, self.capability_templates,
+ 'Capability template mappings')
+ utils.dump_dict_values(context, self.requirement_templates,
+ 'Requirement template mappings')
+
+
+# endregion
+
+# region Node templates
+
+class NodeTemplateBase(structure.ModelMixin):
+ __tablename__ = 'node_template'
+
+ # region foreign_keys
+ @declared_attr
+ def service_template_fk(cls):
+ return cls.foreign_key('service_template')
+
+ @declared_attr
+ def host_fk(cls):
+ return cls.foreign_key('node_template', nullable=True)
+
+ # endregion
+
+ description = Column(Text)
+ type_name = Column(Text)
+ default_instances = Column(Integer, default=1)
+ min_instances = Column(Integer, default=0)
+ max_instances = Column(Integer, default=None)
+ target_node_template_constraints = Column(aria_type.StrictList(FunctionType))
+
+ # region orchestrator required columns
+
+ plugins = Column(aria_type.List)
+ type_hierarchy = Column(aria_type.List)
+
+ @declared_attr
+ def host(cls):
+ return cls.relationship_to_self('host_fk')
+
+ @declared_attr
+ def service_template_name(cls):
+ return association_proxy('service_template', cls.name_column_name())
+
+ # endregion
+
+ # region one-to-many relationships
+ @declared_attr
+ def interface_templates(cls):
+ return cls.one_to_many_relationship('interface_template')
+
+ @declared_attr
+ def artifact_templates(cls):
+ return cls.one_to_many_relationship('artifact_template')
+
+ @declared_attr
+ def capability_templates(cls):
+ return cls.one_to_many_relationship('capability_template')
+
+ @declared_attr
+ def requirement_templates(cls):
+ return cls.one_to_many_relationship('requirement_template')
+
+ # endregion
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def service_template(cls):
+ return cls.many_to_one_relationship('service_template')
+
+ # endregion
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ def is_target_node_valid(self, target_node_template):
+ if self.target_node_template_constraints:
+ for node_type_constraint in self.target_node_template_constraints:
+ if not node_type_constraint(target_node_template, self):
+ return False
+ return True
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('type_name', self.type_name),
+ ('default_instances', self.default_instances),
+ ('min_instances', self.min_instances),
+ ('max_instances', self.max_instances),
+ ('properties', formatting.as_raw_dict(self.properties)),
+ ('interface_templates', formatting.as_raw_list(self.interface_templates)),
+ ('artifact_templates', formatting.as_raw_list(self.artifact_templates)),
+ ('capability_templates', formatting.as_raw_list(self.capability_templates)),
+ ('requirement_templates', formatting.as_raw_list(self.requirement_templates))))
+
+ def instantiate(self, context, *args, **kwargs):
+ node = instance_elements.NodeBase(context, self.type_name, self.name)
+ utils.instantiate_dict(context, node, node.properties, self.properties)
+ utils.instantiate_dict(context, node, node.interfaces, self.interface_templates)
+ utils.instantiate_dict(context, node, node.artifacts, self.artifact_templates)
+ utils.instantiate_dict(context, node, node.capabilities, self.capability_templates)
+ return node
+
+ def validate(self, context):
+ if context.modeling.node_types.get_descendant(self.type_name) is None:
+ context.validation.report('node template "%s" has an unknown type: %s'
+ % (self.name,
+ formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.properties)
+ utils.validate_dict_values(context, self.interface_templates)
+ utils.validate_dict_values(context, self.artifact_templates)
+ utils.validate_dict_values(context, self.capability_templates)
+ utils.validate_list_values(context, self.requirement_templates)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, self, self.properties, report_issues)
+ utils.coerce_dict_values(context, self, self.interface_templates, report_issues)
+ utils.coerce_dict_values(context, self, self.artifact_templates, report_issues)
+ utils.coerce_dict_values(context, self, self.capability_templates, report_issues)
+ utils.coerce_list_values(context, self, self.requirement_templates, report_issues)
+
+ def dump(self, context):
+ console.puts('Node template: %s' % context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Type: %s' % context.style.type(self.type_name))
+ console.puts('Instances: %d (%d%s)'
+ % (self.default_instances,
+ self.min_instances,
+ (' to %d' % self.max_instances
+ if self.max_instances is not None
+ else ' or more')))
+ dump_parameters(context, self.properties)
+ utils.dump_interfaces(context, self.interface_templates)
+ utils.dump_dict_values(context, self.artifact_templates, 'Artifact tempaltes')
+ utils.dump_dict_values(context, self.capability_templates, 'Capability templates')
+ utils.dump_list_values(context, self.requirement_templates, 'Requirement templates')
+
+
+class GroupTemplateBase(structure.ModelMixin):
+ """
+ A template for creating zero or more :class:`Group` instances.
+
+ Groups are logical containers for zero or more nodes that allow applying zero or more
+ :class:`GroupPolicy` instances to the nodes together.
+
+ Properties:
+
+ * :code:`name`: Name (will be used as a prefix for group IDs)
+ * :code:`description`: Description
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`properties`: Dict of :class:`Parameter`
+ * :code:`interface_templates`: Dict of :class:`InterfaceTemplate`
+ * :code:`policy_templates`: Dict of :class:`GroupPolicyTemplate`
+ * :code:`member_node_template_names`: Must be represented in the :class:`ServiceModel`
+ * :code:`member_group_template_names`: Must be represented in the :class:`ServiceModel`
+ """
+ __tablename__ = 'group_template'
+ # region foreign keys
+
+ @declared_attr
+ def service_template_fk(cls):
+ return cls.foreign_key('service_template')
+
+ # endregion
+
+ description = Column(Text)
+ type_name = Column(Text)
+ member_node_template_names = Column(aria_type.StrictList(basestring))
+ member_group_template_names = Column(aria_type.StrictList(basestring))
+
+ # region one-to-many relationships
+ @declared_attr
+ def interface_templates(cls):
+ return cls.one_to_many_relationship('interface_template')
+
+ @declared_attr
+ def policy_templates(cls):
+ return cls.one_to_many_relationship('policy_template')
+
+ # endregion
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('type_name', self.type_name),
+ ('properties', formatting.as_raw_dict(self.properties)),
+ ('interface_templates', formatting.as_raw_list(self.interface_templates)),
+ ('policy_templates', formatting.as_raw_list(self.policy_templates)),
+ ('member_node_template_names', self.member_node_template_names),
+ ('member_group_template_names', self.member_group_template_names)))
+
+ def instantiate(self, context, *args, **kwargs):
+ group = instance_elements.GroupBase(context, self.type_name, self.name)
+ utils.instantiate_dict(context, self, group.properties, self.properties)
+ utils.instantiate_dict(context, self, group.interfaces, self.interface_templates)
+ utils.instantiate_dict(context, self, group.policies, self.policy_templates)
+ for member_node_template_name in self.member_node_template_names:
+ group.member_node_ids += \
+ context.modeling.instance.get_node_ids(member_node_template_name)
+ for member_group_template_name in self.member_group_template_names:
+ group.member_group_ids += \
+ context.modeling.instance.get_group_ids(member_group_template_name)
+ return group
+
+ def validate(self, context):
+ if context.modeling.group_types.get_descendant(self.type_name) is None:
+ context.validation.report('group template "%s" has an unknown type: %s'
+ % (self.name, formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.properties)
+ utils.validate_dict_values(context, self.interface_templates)
+ utils.validate_dict_values(context, self.policy_templates)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, self, self.properties, report_issues)
+ utils.coerce_dict_values(context, self, self.interface_templates, report_issues)
+ utils.coerce_dict_values(context, self, self.policy_templates, report_issues)
+
+ def dump(self, context):
+ console.puts('Group template: %s' % context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ if self.type_name:
+ console.puts('Type: %s' % context.style.type(self.type_name))
+ dump_parameters(context, self.properties)
+ utils.dump_interfaces(context, self.interface_templates)
+ utils.dump_dict_values(context, self.policy_templates, 'Policy templates')
+ if self.member_node_template_names:
+ console.puts('Member node templates: %s' % ', '.join(
+ (str(context.style.node(v)) for v in self.member_node_template_names)))
+
+
+# endregion
+
+# region Relationship templates
+
+class RequirementTemplateBase(structure.ModelMixin):
+ """
+ A requirement for a :class:`NodeTemplate`. During instantiation will be matched with a
+ capability of another
+ node.
+
+ Requirements may optionally contain a :class:`RelationshipTemplate` that will be created between
+ the nodes.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`target_node_type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`target_node_template_name`: Must be represented in the :class:`ServiceModel`
+ * :code:`target_node_template_constraints`: List of :class:`FunctionType`
+ * :code:`target_capability_type_name`: Type of capability in target node
+ * :code:`target_capability_name`: Name of capability in target node
+ * :code:`relationship_template`: :class:`RelationshipTemplate`
+ """
+ __tablename__ = 'requirement_template'
+ # region foreign keys
+ @declared_attr
+ def node_template_fk(cls):
+ return cls.foreign_key('node_template', nullable=True)
+
+ # endregion
+
+ target_node_type_name = Column(Text)
+ target_node_template_name = Column(Text)
+ target_node_template_constraints = Column(aria_type.StrictList(FunctionType))
+ target_capability_type_name = Column(Text)
+ target_capability_name = Column(Text)
+ # CHECK: ???
+ relationship_template = Column(Text) # optional
+
+ def instantiate(self, context, container):
+ raise NotImplementedError
+
+ def find_target(self, context, source_node_template):
+ # We might already have a specific node template, so we'll just verify it
+ if self.target_node_template_name is not None:
+ target_node_template = \
+ context.modeling.model.node_templates.get(self.target_node_template_name)
+
+ if not source_node_template.is_target_node_valid(target_node_template):
+ context.validation.report('requirement "%s" of node template "%s" is for node '
+ 'template "%s" but it does not match constraints'
+ % (self.name,
+ self.target_node_template_name,
+ source_node_template.name),
+ level=validation.Issue.BETWEEN_TYPES)
+ return None, None
+
+ if self.target_capability_type_name is not None \
+ or self.target_capability_name is not None:
+ target_node_capability = self.find_target_capability(context,
+ source_node_template,
+ target_node_template)
+ if target_node_capability is None:
+ return None, None
+ else:
+ target_node_capability = None
+
+ return target_node_template, target_node_capability
+
+ # Find first node that matches the type
+ elif self.target_node_type_name is not None:
+ for target_node_template in context.modeling.model.node_templates.itervalues():
+ if not context.modeling.node_types.is_descendant(self.target_node_type_name,
+ target_node_template.type_name):
+ continue
+
+ if not source_node_template.is_target_node_valid(target_node_template):
+ continue
+
+ target_node_capability = self.find_target_capability(context,
+ source_node_template,
+ target_node_template)
+ if target_node_capability is None:
+ continue
+
+ return target_node_template, target_node_capability
+
+ return None, None
+
+ def find_target_capability(self, context, source_node_template, target_node_template):
+ for capability_template in target_node_template.capability_templates.itervalues():
+ if capability_template.satisfies_requirement(context,
+ source_node_template,
+ self,
+ target_node_template):
+ return capability_template
+ return None
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('target_node_type_name', self.target_node_type_name),
+ ('target_node_template_name', self.target_node_template_name),
+ ('target_capability_type_name', self.target_capability_type_name),
+ ('target_capability_name', self.target_capability_name),
+ ('relationship_template', formatting.as_raw(self.relationship_template))))
+
+ def validate(self, context):
+ node_types = context.modeling.node_types
+ capability_types = context.modeling.capability_types
+ if self.target_node_type_name \
+ and node_types.get_descendant(self.target_node_type_name) is None:
+ context.validation.report('requirement "%s" refers to an unknown node type: %s'
+ % (self.name,
+ formatting.safe_repr(self.target_node_type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+ if self.target_capability_type_name and \
+ capability_types.get_descendant(self.target_capability_type_name is None):
+ context.validation.report('requirement "%s" refers to an unknown capability type: %s'
+ % (self.name,
+ formatting.safe_repr(self.target_capability_type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+ if self.relationship_template:
+ self.relationship_template.validate(context)
+
+ def coerce_values(self, context, container, report_issues):
+ if self.relationship_template is not None:
+ self.relationship_template.coerce_values(context, container, report_issues)
+
+ def dump(self, context):
+ if self.name:
+ console.puts(context.style.node(self.name))
+ else:
+ console.puts('Requirement:')
+ with context.style.indent:
+ if self.target_node_type_name is not None:
+ console.puts('Target node type: %s'
+ % context.style.type(self.target_node_type_name))
+ elif self.target_node_template_name is not None:
+ console.puts('Target node template: %s'
+ % context.style.node(self.target_node_template_name))
+ if self.target_capability_type_name is not None:
+ console.puts('Target capability type: %s'
+ % context.style.type(self.target_capability_type_name))
+ elif self.target_capability_name is not None:
+ console.puts('Target capability name: %s'
+ % context.style.node(self.target_capability_name))
+ if self.target_node_template_constraints:
+ console.puts('Target node template constraints:')
+ with context.style.indent:
+ for constraint in self.target_node_template_constraints:
+ console.puts(context.style.literal(constraint))
+ if self.relationship_template:
+ console.puts('Relationship:')
+ with context.style.indent:
+ self.relationship_template.dump(context)
+
+
+class CapabilityTemplateBase(structure.ModelMixin):
+ """
+ A capability of a :class:`NodeTemplate`. Nodes expose zero or more capabilities that can be
+ matched with :class:`Requirement` instances of other nodes.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`description`: Description
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`min_occurrences`: Minimum number of requirement matches required
+ * :code:`max_occurrences`: Maximum number of requirement matches allowed
+ * :code:`valid_source_node_type_names`: Must be represented in the :class:`ModelingContext`
+ * :code:`properties`: Dict of :class:`Parameter`
+ """
+ __tablename__ = 'capability_template'
+ # region foreign keys
+ @declared_attr
+ def node_template_fk(cls):
+ return cls.foreign_key('node_template', nullable=True)
+
+ # endregion
+
+ description = Column(Text)
+ type_name = Column(Text)
+ min_occurrences = Column(Integer, default=None) # optional
+ max_occurrences = Column(Integer, default=None) # optional
+ # CHECK: type?
+ valid_source_node_type_names = Column(Text)
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ def satisfies_requirement(self,
+ context,
+ source_node_template,
+ requirement,
+ target_node_template):
+ # Do we match the required capability type?
+ capability_types = context.modeling.capability_types
+ if not capability_types.is_descendant(requirement.target_capability_type_name,
+ self.type_name):
+ return False
+
+ # Are we in valid_source_node_type_names?
+ if self.valid_source_node_type_names:
+ for valid_source_node_type_name in self.valid_source_node_type_names:
+ if not context.modeling.node_types.is_descendant(valid_source_node_type_name,
+ source_node_template.type_name):
+ return False
+
+ # Apply requirement constraints
+ if requirement.target_node_template_constraints:
+ for node_type_constraint in requirement.target_node_template_constraints:
+ if not node_type_constraint(target_node_template, source_node_template):
+ return False
+
+ return True
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('type_name', self.type_name),
+ ('min_occurrences', self.min_occurrences),
+ ('max_occurrences', self.max_occurrences),
+ ('valid_source_node_type_names', self.valid_source_node_type_names),
+ ('properties', formatting.as_raw_dict(self.properties))))
+
+ def instantiate(self, context, container):
+ capability = instance_elements.CapabilityBase(self.name, self.type_name)
+ capability.min_occurrences = self.min_occurrences
+ capability.max_occurrences = self.max_occurrences
+ utils.instantiate_dict(context, container, capability.properties, self.properties)
+ return capability
+
+ def validate(self, context):
+ if context.modeling.capability_types.get_descendant(self.type_name) is None:
+ context.validation.report('capability "%s" refers to an unknown type: %s'
+ % (self.name, formatting.safe_repr(self.type)), # pylint: disable=no-member
+ # TODO fix self.type reference
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.properties)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, self, self.properties, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Type: %s' % context.style.type(self.type_name))
+ console.puts(
+ 'Occurrences: %d%s'
+ % (self.min_occurrences or 0, (' to %d' % self.max_occurrences)
+ if self.max_occurrences is not None else ' or more'))
+ if self.valid_source_node_type_names:
+ console.puts('Valid source node types: %s'
+ % ', '.join((str(context.style.type(v))
+ for v in self.valid_source_node_type_names)))
+ dump_parameters(context, self.properties)
+
+# endregion
+
+
+def dump_parameters(context, parameters, name='Properties'):
+ if not parameters:
+ return
+ console.puts('%s:' % name)
+ with context.style.indent:
+ for parameter_name, parameter in parameters.items():
+ if parameter.type_name is not None:
+ console.puts('%s = %s (%s)' % (context.style.property(parameter_name),
+ context.style.literal(parameter.value),
+ context.style.type(parameter.type_name)))
+ else:
+ console.puts('%s = %s' % (context.style.property(parameter_name),
+ context.style.literal(parameter.value)))
+ if parameter.description:
+ console.puts(context.style.meta(parameter.description))
+
+
+# TODO (left for tal): Move following two methods to some place parser specific
+def deepcopy_with_locators(value):
+ """
+ Like :code:`deepcopy`, but also copies over locators.
+ """
+
+ res = deepcopy(value)
+ copy_locators(res, value)
+ return res
+
+
+def copy_locators(target, source):
+ """
+ Copies over :code:`_locator` for all elements, recursively.
+
+ Assumes that target and source have exactly the same list/dict structure.
+ """
+
+ locator = getattr(source, '_locator', None)
+ if locator is not None:
+ try:
+ setattr(target, '_locator', locator)
+ except AttributeError:
+ pass
+
+ if isinstance(target, list) and isinstance(source, list):
+ for i, _ in enumerate(target):
+ copy_locators(target[i], source[i])
+ elif isinstance(target, dict) and isinstance(source, dict):
+ for k, v in target.items():
+ copy_locators(v, source[k])
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/modeling/type.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/type.py b/aria/storage/modeling/type.py
new file mode 100644
index 0000000..0b6c58f
--- /dev/null
+++ b/aria/storage/modeling/type.py
@@ -0,0 +1,275 @@
+# 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 json
+from collections import namedtuple
+from types import NoneType
+
+from sqlalchemy import (
+ TypeDecorator,
+ VARCHAR,
+ event
+)
+from sqlalchemy.ext import mutable
+
+from aria.storage import exceptions
+
+
+class _MutableType(TypeDecorator):
+ """
+ Dict representation of type.
+ """
+ @property
+ def python_type(self):
+ raise NotImplementedError
+
+ def process_literal_param(self, value, dialect):
+ pass
+
+ impl = VARCHAR
+
+ def process_bind_param(self, value, dialect):
+ if value is not None:
+ value = json.dumps(value)
+ return value
+
+ def process_result_value(self, value, dialect):
+ if value is not None:
+ value = json.loads(value)
+ return value
+
+
+class Dict(_MutableType):
+ @property
+ def python_type(self):
+ return dict
+
+
+class List(_MutableType):
+ @property
+ def python_type(self):
+ return list
+
+
+class _StrictDictMixin(object):
+ ANY_TYPE = 'any_type'
+
+ _key_cls = ANY_TYPE
+ _value_cls = ANY_TYPE
+
+ @classmethod
+ def coerce(cls, key, value):
+ "Convert plain dictionaries to MutableDict."
+ try:
+ if not isinstance(value, cls):
+ if isinstance(value, dict):
+ for k, v in value.items():
+ cls._assert_strict_key(k)
+ cls._assert_strict_value(v)
+ return cls(value)
+ return mutable.MutableDict.coerce(key, value)
+ else:
+ return value
+ except ValueError as e:
+ raise exceptions.StorageError('SQL Storage error: {0}'.format(str(e)))
+
+ def __setitem__(self, key, value):
+ self._assert_strict_key(key)
+ self._assert_strict_value(value)
+ super(_StrictDictMixin, self).__setitem__(key, value)
+
+ def setdefault(self, key, value):
+ self._assert_strict_key(key)
+ self._assert_strict_value(value)
+ super(_StrictDictMixin, self).setdefault(key, value)
+
+ def update(self, *args, **kwargs):
+ for k, v in kwargs.items():
+ self._assert_strict_key(k)
+ self._assert_strict_value(v)
+ super(_StrictDictMixin, self).update(*args, **kwargs)
+
+ @classmethod
+ def _assert_strict_key(cls, key):
+ if not isinstance(key, (cls._key_cls, NoneType)):
+ raise exceptions.StorageError("Key type was set strictly to {0}, but was {1}".format(
+ cls._key_cls, type(key)
+ ))
+
+ @classmethod
+ def _assert_strict_value(cls, value):
+ if not isinstance(value, (cls._value_cls, NoneType)):
+ raise exceptions.StorageError("Value type was set strictly to {0}, but was {1}".format(
+ cls._value_cls, type(value)
+ ))
+
+
+class _MutableDict(mutable.MutableDict):
+ """
+ Enables tracking for dict values.
+ """
+
+ @classmethod
+ def coerce(cls, key, value):
+ "Convert plain dictionaries to MutableDict."
+ try:
+ return mutable.MutableDict.coerce(key, value)
+ except ValueError as e:
+ raise exceptions.StorageError('SQL Storage error: {0}'.format(str(e)))
+
+
+class _StrictListMixin(object):
+ ANY_TYPE = 'any_type'
+
+ _item_cls = ANY_TYPE
+
+ @classmethod
+ def coerce(cls, key, value):
+ "Convert plain dictionaries to MutableDict."
+ try:
+ if not isinstance(value, cls):
+ if isinstance(value, list):
+ for item in value:
+ cls._assert_item(item)
+ return cls(value)
+ return mutable.MutableList.coerce(key, value)
+ else:
+ return value
+ except ValueError as e:
+ raise exceptions.StorageError('SQL Storage error: {0}'.format(str(e)))
+
+ def __setitem__(self, index, value):
+ """Detect list set events and emit change events."""
+ self._assert_item(value)
+ super(_StrictListMixin, self).__setitem__(index, value)
+
+ def append(self, item):
+ self._assert_item(item)
+ super(_StrictListMixin, self).append(item)
+
+ def extend(self, item):
+ self._assert_item(item)
+ super(_StrictListMixin, self).extend(item)
+
+ def insert(self, index, item):
+ self._assert_item(item)
+ super(_StrictListMixin, self).insert(index, item)
+
+ @classmethod
+ def _assert_item(cls, item):
+ if not isinstance(item, (cls._item_cls, NoneType)):
+ raise exceptions.StorageError("Key type was set strictly to {0}, but was {1}".format(
+ cls._item_cls, type(item)
+ ))
+
+
+class _MutableList(mutable.MutableList):
+
+ @classmethod
+ def coerce(cls, key, value):
+ "Convert plain dictionaries to MutableDict."
+
+ try:
+ if not isinstance(value, cls):
+ if isinstance(value, list):
+ return cls(value)
+
+ return mutable.Mutable.coerce(key, value)
+ else:
+ return value
+
+ except ValueError as e:
+ raise exceptions.StorageError('SQL Storage error: {0}'.format(str(e)))
+
+StrictDictID = namedtuple('strict_dict_id', 'key_cls, value_cls')
+
+
+class _StrictDict(object):
+ _strict_map = {}
+
+ def __call__(self, key_cls=NoneType, value_cls=NoneType, *args, **kwargs):
+ strict_dict_map_key = StrictDictID(key_cls=key_cls, value_cls=value_cls)
+ if strict_dict_map_key not in self._strict_map:
+ strict_dict_cls = type(
+ 'StrictDict_{0}_{1}'.format(key_cls.__name__, value_cls.__name__),
+ (Dict, ),
+ {}
+ )
+ type(
+ 'StrictMutableDict_{0}_{1}'.format(key_cls.__name__, value_cls.__name__),
+ (_StrictDictMixin, _MutableDict),
+ {'_key_cls': key_cls, '_value_cls': value_cls}
+ ).associate_with(strict_dict_cls)
+ self._strict_map[strict_dict_map_key] = strict_dict_cls
+
+ return self._strict_map[strict_dict_map_key]
+
+StrictDict = _StrictDict()
+
+
+class _StrictList(object):
+ _strict_map = {}
+
+ def __call__(self, item_cls):
+ if item_cls not in self._strict_map:
+ strict_list_cls = type(
+ 'StrictList_{0}'.format(item_cls.__name__),
+ (List, ),
+ {}
+ )
+ type(
+ 'StrictMutableList_{0}'.format(item_cls.__name__),
+ (_StrictListMixin, _MutableList),
+ {'_item_cls': item_cls}
+ ).associate_with(strict_list_cls)
+ self._strict_map[item_cls] = strict_list_cls
+
+ return self._strict_map[item_cls]
+
+StrictList = _StrictList()
+
+def _mutable_association_listener(mapper, cls):
+ for prop in mapper.column_attrs:
+ column_type = prop.columns[0].type
+ if isinstance(column_type, Dict):
+ _MutableDict.associate_with_attribute(getattr(cls, prop.key))
+ if isinstance(column_type, List):
+ _MutableList.associate_with_attribute(getattr(cls, prop.key))
+_LISTENER_ARGS = (mutable.mapper, 'mapper_configured', _mutable_association_listener)
+
+
+def _register_mutable_association_listener():
+ event.listen(*_LISTENER_ARGS)
+
+
+def remove_mutable_association_listener():
+ """
+ Remove the event listener that associates ``Dict`` and ``List`` column types with
+ ``MutableDict`` and ``MutableList``, respectively.
+
+ This call must happen before any model instance is instantiated.
+ This is because once it does, that would trigger the listener we are trying to remove.
+ Once it is triggered, many other listeners will then be registered.
+ At that point, it is too late.
+
+ The reason this function exists is that the association listener, interferes with ARIA change
+ tracking instrumentation, so a way to disable it is required.
+
+ Note that the event listener this call removes is registered by default.
+ """
+ if event.contains(*_LISTENER_ARGS):
+ event.remove(*_LISTENER_ARGS)
+
+_register_mutable_association_listener()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/utils.py b/aria/storage/modeling/utils.py
new file mode 100644
index 0000000..f4c97c4
--- /dev/null
+++ b/aria/storage/modeling/utils.py
@@ -0,0 +1,146 @@
+# 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 random import randrange
+
+from shortuuid import ShortUUID
+
+from aria.utils.collections import OrderedDict
+from aria.utils.console import puts
+from aria.parser.exceptions import InvalidValueError
+from aria.parser.presentation import Value
+from aria.parser.modeling.exceptions import CannotEvaluateFunctionException
+
+# UUID = ShortUUID() # default alphabet is base57, which is alphanumeric without visually ambiguous
+# characters; ID length is 22
+UUID = ShortUUID(alphabet='abcdefghijklmnopqrstuvwxyz0123456789') # alphanumeric; ID length is 25
+
+
+def generate_id_string(length=None):
+ """
+ A random string with a strong guarantee of universal uniqueness (uses UUID).
+
+ The default length is 25 characters.
+ """
+
+ the_id = UUID.uuid()
+ if length is not None:
+ the_id = the_id[:length]
+ return the_id
+
+
+def generate_hex_string():
+ """
+ A random string of 5 hex digits with no guarantee of universal uniqueness.
+ """
+
+ return '%05x' % randrange(16 ** 5)
+
+
+def coerce_value(context, container, value, report_issues=False):
+ if isinstance(value, Value):
+ value = value.value
+
+ if isinstance(value, list):
+ return [coerce_value(context, container, v, report_issues) for v in value]
+ elif isinstance(value, dict):
+ return OrderedDict((k, coerce_value(context, container, v, report_issues))
+ for k, v in value.iteritems())
+ elif hasattr(value, '_evaluate'):
+ try:
+ value = value._evaluate(context, container)
+ value = coerce_value(context, container, value, report_issues)
+ except CannotEvaluateFunctionException:
+ pass
+ except InvalidValueError as e:
+ if report_issues:
+ context.validation.report(e.issue)
+ return value
+
+
+def validate_dict_values(context, the_dict):
+ if not the_dict:
+ return
+ validate_list_values(context, the_dict.itervalues())
+
+
+def validate_list_values(context, the_list):
+ if not the_list:
+ return
+ for value in the_list:
+ value.validate(context)
+
+
+def coerce_dict_values(context, container, the_dict, report_issues=False):
+ if not the_dict:
+ return
+ coerce_list_values(context, container, the_dict.itervalues(), report_issues)
+
+
+def coerce_list_values(context, container, the_list, report_issues=False):
+ if not the_list:
+ return
+ for value in the_list:
+ value.coerce_values(context, container, report_issues)
+
+
+def instantiate_dict(context, container, the_dict, from_dict):
+ if not from_dict:
+ return
+ for name, value in from_dict.iteritems():
+ value = value.instantiate(context, container)
+ if value is not None:
+ the_dict[name] = value
+
+
+def dump_list_values(context, the_list, name):
+ if not the_list:
+ return
+ puts('%s:' % name)
+ with context.style.indent:
+ for value in the_list:
+ value.dump(context)
+
+
+def dump_dict_values(context, the_dict, name):
+ if not the_dict:
+ return
+ dump_list_values(context, the_dict.itervalues(), name)
+
+
+def dump_parameters(context, parameters, name='Properties'):
+ if not parameters:
+ return
+ puts('%s:' % name)
+ with context.style.indent:
+ for parameter_name, parameter in parameters.iteritems():
+ if parameter.type_name is not None:
+ puts('%s = %s (%s)' % (context.style.property(parameter_name),
+ context.style.literal(parameter.value),
+ context.style.type(parameter.type_name)))
+ else:
+ puts('%s = %s' % (context.style.property(parameter_name),
+ context.style.literal(parameter.value)))
+ if parameter.description:
+ puts(context.style.meta(parameter.description))
+
+
+def dump_interfaces(context, interfaces, name='Interfaces'):
+ if not interfaces:
+ return
+ puts('%s:' % name)
+ with context.style.indent:
+ for interface in interfaces.itervalues():
+ interface.dump(context)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/structure.py
----------------------------------------------------------------------
diff --git a/aria/storage/structure.py b/aria/storage/structure.py
deleted file mode 100644
index fa592ac..0000000
--- a/aria/storage/structure.py
+++ /dev/null
@@ -1,190 +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.
-
-"""
-Aria's storage.structures module
-Path: aria.storage.structures
-
-models module holds aria's models.
-
-classes:
- * Field - represents a single field.
- * IterField - represents an iterable field.
- * PointerField - represents a single pointer field.
- * IterPointerField - represents an iterable pointers field.
- * Model - abstract model implementation.
-"""
-
-from sqlalchemy.orm import relationship, backref
-from sqlalchemy.ext import associationproxy
-from sqlalchemy import (
- Column,
- ForeignKey,
- Integer,
- Text
-)
-
-
-class ModelMixin(object):
-
- @classmethod
- def id_column_name(cls):
- raise NotImplementedError
-
- @classmethod
- def name_column_name(cls):
- raise NotImplementedError
-
- @classmethod
- def _get_cls_by_tablename(cls, tablename):
- """Return class reference mapped to table.
-
- :param tablename: String with name of table.
- :return: Class reference or None.
- """
- if tablename in (cls.__name__, cls.__tablename__):
- return cls
-
- for table_cls in cls._decl_class_registry.values():
- if tablename in (getattr(table_cls, '__name__', None),
- getattr(table_cls, '__tablename__', None)):
- return table_cls
-
- @classmethod
- def foreign_key(cls, table, nullable=False):
- """Return a ForeignKey object with the relevant
-
- :param table: Unique id column in the parent table
- :param nullable: Should the column be allowed to remain empty
- """
- table_cls = cls._get_cls_by_tablename(table.__tablename__)
- foreign_key_str = '{tablename}.{unique_id}'.format(tablename=table_cls.__tablename__,
- unique_id=table_cls.id_column_name())
- column = Column(ForeignKey(foreign_key_str, ondelete='CASCADE'),
- nullable=nullable)
- column.__remote_table_name = table_cls.__name__
- return column
-
- @classmethod
- def one_to_many_relationship(cls,
- foreign_key_column,
- backreference=None,
- backref_kwargs=None,
- **kwargs):
- """Return a one-to-many SQL relationship object
- Meant to be used from inside the *child* object
-
- :param parent_class: Class of the parent table
- :param cls: Class of the child table
- :param foreign_key_column: The column of the foreign key (from the child table)
- :param backreference: The name to give to the reference to the child (on the parent table)
- """
- backref_kwargs = backref_kwargs or {}
- parent_table = cls._get_cls_by_tablename(
- getattr(cls, foreign_key_column).__remote_table_name)
- primaryjoin_str = '{parent_class_name}.{parent_unique_id} == ' \
- '{child_class.__name__}.{foreign_key_column}'\
- .format(
- parent_class_name=parent_table.__name__,
- parent_unique_id=parent_table.id_column_name(),
- child_class=cls,
- foreign_key_column=foreign_key_column
- )
- return relationship(
- parent_table.__name__,
- primaryjoin=primaryjoin_str,
- foreign_keys=[getattr(cls, foreign_key_column)],
- # The following line make sure that when the *parent* is
- # deleted, all its connected children are deleted as well
- backref=backref(backreference or cls.__tablename__, cascade='all', **backref_kwargs),
- **kwargs
- )
-
- @classmethod
- def relationship_to_self(cls, local_column):
-
- remote_side_str = '{cls.__name__}.{remote_column}'.format(
- cls=cls,
- remote_column=cls.id_column_name()
- )
- primaryjoin_str = '{remote_side_str} == {cls.__name__}.{local_column}'.format(
- remote_side_str=remote_side_str,
- cls=cls,
- local_column=local_column)
- return relationship(cls.__name__,
- primaryjoin=primaryjoin_str,
- remote_side=remote_side_str,
- post_update=True)
-
- def to_dict(self, fields=None, suppress_error=False):
- """Return a dict representation of the model
-
- :param suppress_error: If set to True, sets `None` to attributes that
- it's unable to retrieve (e.g., if a relationship wasn't established
- yet, and so it's impossible to access a property through it)
- """
- res = dict()
- fields = fields or self.fields()
- for field in fields:
- try:
- field_value = getattr(self, field)
- except AttributeError:
- if suppress_error:
- field_value = None
- else:
- raise
- if isinstance(field_value, list):
- field_value = list(field_value)
- elif isinstance(field_value, dict):
- field_value = dict(field_value)
- elif isinstance(field_value, ModelMixin):
- field_value = field_value.to_dict()
- res[field] = field_value
-
- return res
-
- @classmethod
- def _association_proxies(cls):
- for col, value in vars(cls).items():
- if isinstance(value, associationproxy.AssociationProxy):
- yield col
-
- @classmethod
- def fields(cls):
- """Return the list of field names for this table
-
- Mostly for backwards compatibility in the code (that uses `fields`)
- """
- fields = set(cls._association_proxies())
- fields.update(cls.__table__.columns.keys())
- return fields - set(getattr(cls, '_private_fields', []))
-
- def __repr__(self):
- return '<{__class__.__name__} id=`{id}`>'.format(
- __class__=self.__class__,
- id=getattr(self, self.name_column_name()))
-
-
-class ModelIDMixin(object):
- id = Column(Integer, primary_key=True, autoincrement=True)
- name = Column(Text, nullable=True, index=True)
-
- @classmethod
- def id_column_name(cls):
- return 'id'
-
- @classmethod
- def name_column_name(cls):
- return 'name'
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/type.py
----------------------------------------------------------------------
diff --git a/aria/storage/type.py b/aria/storage/type.py
deleted file mode 100644
index dd2a5ce..0000000
--- a/aria/storage/type.py
+++ /dev/null
@@ -1,120 +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.
-import json
-
-from sqlalchemy import (
- TypeDecorator,
- VARCHAR,
- event
-)
-
-from sqlalchemy.ext import mutable
-
-from . import exceptions
-
-
-class _MutableType(TypeDecorator):
- """
- Dict representation of type.
- """
- @property
- def python_type(self):
- raise NotImplementedError
-
- def process_literal_param(self, value, dialect):
- pass
-
- impl = VARCHAR
-
- def process_bind_param(self, value, dialect):
- if value is not None:
- value = json.dumps(value)
- return value
-
- def process_result_value(self, value, dialect):
- if value is not None:
- value = json.loads(value)
- return value
-
-
-class Dict(_MutableType):
- @property
- def python_type(self):
- return dict
-
-
-class List(_MutableType):
- @property
- def python_type(self):
- return list
-
-
-class _MutableDict(mutable.MutableDict):
- """
- Enables tracking for dict values.
- """
- @classmethod
- def coerce(cls, key, value):
- "Convert plain dictionaries to MutableDict."
- try:
- return mutable.MutableDict.coerce(key, value)
- except ValueError as e:
- raise exceptions.StorageError('SQL Storage error: {0}'.format(str(e)))
-
-
-class _MutableList(mutable.MutableList):
-
- @classmethod
- def coerce(cls, key, value):
- "Convert plain dictionaries to MutableDict."
- try:
- return mutable.MutableList.coerce(key, value)
- except ValueError as e:
- raise exceptions.StorageError('SQL Storage error: {0}'.format(str(e)))
-
-
-def _mutable_association_listener(mapper, cls):
- for prop in mapper.column_attrs:
- column_type = prop.columns[0].type
- if isinstance(column_type, Dict):
- _MutableDict.associate_with_attribute(getattr(cls, prop.key))
- if isinstance(column_type, List):
- _MutableList.associate_with_attribute(getattr(cls, prop.key))
-_LISTENER_ARGS = (mutable.mapper, 'mapper_configured', _mutable_association_listener)
-
-
-def _register_mutable_association_listener():
- event.listen(*_LISTENER_ARGS)
-
-
-def remove_mutable_association_listener():
- """
- Remove the event listener that associates ``Dict`` and ``List`` column types with
- ``MutableDict`` and ``MutableList``, respectively.
-
- This call must happen before any model instance is instantiated.
- This is because once it does, that would trigger the listener we are trying to remove.
- Once it is triggered, many other listeners will then be registered.
- At that point, it is too late.
-
- The reason this function exists is that the association listener, interferes with ARIA change
- tracking instrumentation, so a way to disable it is required.
-
- Note that the event listener this call removes is registered by default.
- """
- if event.contains(*_LISTENER_ARGS):
- event.remove(*_LISTENER_ARGS)
-
-_register_mutable_association_listener()
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/utils/application.py
----------------------------------------------------------------------
diff --git a/aria/utils/application.py b/aria/utils/application.py
index 113e054..161a9cb 100644
--- a/aria/utils/application.py
+++ b/aria/utils/application.py
@@ -102,14 +102,14 @@ class StorageManager(LoggerMixin):
assert hasattr(self.model_storage, 'blueprint')
self.logger.debug('creating blueprint resource storage entry')
- self.resource_storage.blueprint.upload(
+ self.resource_storage.service_template.upload(
entry_id=self.blueprint_id,
source=os.path.dirname(source))
self.logger.debug('created blueprint resource storage entry')
self.logger.debug('creating blueprint model storage entry')
now = datetime.utcnow()
- blueprint = self.model_storage.blueprint.model_cls(
+ blueprint = self.model_storage.service_template.model_cls(
plan=self.blueprint_plan,
id=self.blueprint_id,
description=self.blueprint_plan.get('description'),
@@ -117,7 +117,7 @@ class StorageManager(LoggerMixin):
updated_at=now,
main_file_name=main_file_name,
)
- self.model_storage.blueprint.put(blueprint)
+ self.model_storage.service_template.put(blueprint)
self.logger.debug('created blueprint model storage entry')
def create_nodes_storage(self):
@@ -164,10 +164,10 @@ class StorageManager(LoggerMixin):
self.logger.debug('creating deployment resource storage entry')
temp_dir = tempfile.mkdtemp()
try:
- self.resource_storage.blueprint.download(
+ self.resource_storage.service_template.download(
entry_id=self.blueprint_id,
destination=temp_dir)
- self.resource_storage.deployment.upload(
+ self.resource_storage.service_instance.upload(
entry_id=self.deployment_id,
source=temp_dir)
finally:
@@ -176,7 +176,7 @@ class StorageManager(LoggerMixin):
self.logger.debug('creating deployment model storage entry')
now = datetime.utcnow()
- deployment = self.model_storage.deployment.model_cls(
+ deployment = self.model_storage.service_instance.model_cls(
id=self.deployment_id,
blueprint_id=self.blueprint_id,
description=self.deployment_plan['description'],
@@ -190,7 +190,7 @@ class StorageManager(LoggerMixin):
created_at=now,
updated_at=now
)
- self.model_storage.deployment.put(deployment)
+ self.model_storage.service_instance.put(deployment)
self.logger.debug('created deployment model storage entry')
def create_node_instances_storage(self):
[4/5] incubator-ariatosca git commit: wip
Posted by mx...@apache.org.
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 0000000..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_name):
+ return collections.FrozenList((group.id for group in self.find_groups(group_template_name)))
+
+ def is_node_a_target(self, context, target_node):
+ for node in self.nodes.all():
+ if self._is_node_a_target(context, node, target_node):
+ return True
+ return False
+
+ def _is_node_a_target(self, context, source_node, target_node):
+ if source_node.relationships:
+ for relationship in source_node.relationships:
+ if relationship.target_node_id == target_node.id:
+ return True
+ else:
+ node = context.modeling.instance.nodes.get(relationship.target_node_id)
+ if node is not None:
+ if self._is_node_a_target(context, node, target_node):
+ return True
+ return False
+
+
+class OperationBase(structure.ModelMixin):
+ """
+ An operation in a :class:`Interface`.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`description`: Description
+ * :code:`implementation`: Implementation string (interpreted by the orchestrator)
+ * :code:`dependencies`: List of strings (interpreted by the orchestrator)
+ * :code:`executor`: Executor string (interpreted by the orchestrator)
+ * :code:`max_retries`: Maximum number of retries allowed in case of failure
+ * :code:`retry_interval`: Interval between retries
+ * :code:`inputs`: Dict of :class:`Parameter`
+ """
+ __tablename__ = 'operation'
+ # region foreign_keys
+ @declared_attr
+ def service_instance_fk(cls):
+ return cls.foreign_key('service_instance', nullable=True)
+
+ @declared_attr
+ def interface_instance_fk(cls):
+ return cls.foreign_key('interface', nullable=True)
+
+ # endregion
+ description = Column(Text)
+ implementation = Column(Text)
+ dependencies = Column(aria_types.StrictList(item_cls=basestring))
+
+ executor = Column(Text)
+ max_retries = Column(Integer, default=None)
+ retry_interval = Column(Integer, default=None)
+ plugin = Column(Text)
+ operation = Column(Boolean)
+ # region many-to-many relationships
+
+ @declared_attr
+ def inputs(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='inputs')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('implementation', self.implementation),
+ ('dependencies', self.dependencies),
+ ('executor', self.executor),
+ ('max_retries', self.max_retries),
+ ('retry_interval', self.retry_interval),
+ ('inputs', formatting.as_raw_dict(self.inputs))))
+
+ def validate(self, context):
+ utils.validate_dict_values(context, self.inputs)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.inputs, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ if self.implementation is not None:
+ console.puts('Implementation: %s' % context.style.literal(self.implementation))
+ if self.dependencies:
+ console.puts(
+ 'Dependencies: %s'
+ % ', '.join((str(context.style.literal(v)) for v in self.dependencies)))
+ if self.executor is not None:
+ console.puts('Executor: %s' % context.style.literal(self.executor))
+ if self.max_retries is not None:
+ console.puts('Max retries: %s' % context.style.literal(self.max_retries))
+ if self.retry_interval is not None:
+ console.puts('Retry interval: %s' % context.style.literal(self.retry_interval))
+ utils.dump_parameters(context, self.inputs, 'Inputs')
+
+
+class InterfaceBase(structure.ModelMixin):
+ """
+ A typed set of :class:`Operation`.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`description`: Description
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`inputs`: Dict of :class:`Parameter`
+ * :code:`operations`: Dict of :class:`Operation`
+ """
+ __tablename__ = 'interface'
+ # region foreign_keys
+ @declared_attr
+ def group_fk(cls):
+ return cls.foreign_key('group', nullable=True)
+
+ @declared_attr
+ def node_fk(cls):
+ return cls.foreign_key('node', nullable=True)
+
+ @declared_attr
+ def relationship_fk(cls):
+ return cls.foreign_key('relationship', nullable=True)
+
+ # endregion
+
+ description = Column(Text)
+ type_name = Column(Text)
+
+ # region one-to-many relationships
+ @declared_attr
+ def operations(cls):
+ return cls.one_to_many_relationship('operation')
+
+ # endregion
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def inputs(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='inputs')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('type_name', self.type_name),
+ ('inputs', formatting.as_raw_dict(self.inputs)),
+ ('operations', formatting.as_raw_list(self.operations))))
+
+ def validate(self, context):
+ if self.type_name:
+ if context.modeling.interface_types.get_descendant(self.type_name) is None:
+ context.validation.report('interface "%s" has an unknown type: %s'
+ % (self.name,
+ formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.inputs)
+ utils.validate_dict_values(context, self.operations)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.inputs, report_issues)
+ utils.coerce_dict_values(context, container, self.operations, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Interface type: %s' % context.style.type(self.type_name))
+ utils.dump_parameters(context, self.inputs, 'Inputs')
+ utils.dump_dict_values(context, self.operations, 'Operations')
+
+
+class CapabilityBase(structure.ModelMixin):
+ """
+ A capability of a :class:`Node`.
+
+ An instance of a :class:`CapabilityTemplate`.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`min_occurrences`: Minimum number of requirement matches required
+ * :code:`max_occurrences`: Maximum number of requirement matches allowed
+ * :code:`properties`: Dict of :class:`Parameter`
+ """
+ __tablename__ = 'capability'
+ # region foreign_keys
+ @declared_attr
+ def node_fk(cls):
+ return cls.foreign_key('node')
+
+ # endregion
+ type_name = Column(Text)
+
+ min_occurrences = Column(Integer, default=None) # optional
+ max_occurrences = Column(Integer, default=None) # optional
+ occurrences = Column(Integer, default=0)
+
+ # region many-to-many relationships
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ @property
+ def has_enough_relationships(self):
+ if self.min_occurrences is not None:
+ return self.occurrences >= self.min_occurrences
+ return True
+
+ def relate(self):
+ if self.max_occurrences is not None:
+ if self.occurrences == self.max_occurrences:
+ return False
+ self.occurrences += 1
+ return True
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('type_name', self.type_name),
+ ('properties', formatting.as_raw_dict(self.properties))))
+
+ def validate(self, context):
+ if context.modeling.capability_types.get_descendant(self.type_name) is None:
+ context.validation.report('capability "%s" has an unknown type: %s'
+ % (self.name,
+ formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.properties)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.properties, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ with context.style.indent:
+ console.puts('Type: %s' % context.style.type(self.type_name))
+ console.puts('Occurrences: %s (%s%s)'
+ % (self.occurrences,
+ self.min_occurrences or 0,
+ (' to %d' % self.max_occurrences)
+ if self.max_occurrences is not None
+ else ' or more'))
+ utils.dump_parameters(context, self.properties)
+
+
+class ArtifactBase(structure.ModelMixin):
+ """
+ A file associated with a :class:`Node`.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`description`: Description
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`source_path`: Source path (CSAR or repository)
+ * :code:`target_path`: Path at destination machine
+ * :code:`repository_url`: Repository URL
+ * :code:`repository_credential`: Dict of string
+ * :code:`properties`: Dict of :class:`Parameter`
+ """
+ __tablename__ = 'artifact'
+ # region foreign_keys
+
+ @declared_attr
+ def node_fk(cls):
+ return cls.foreign_key('node')
+
+ # endregion
+
+ description = Column(Text)
+ type_name = Column(Text)
+ source_path = Column(Text)
+ target_path = Column(Text)
+ repository_url = Column(Text)
+ repository_credential = Column(aria_types.StrictDict(basestring, basestring))
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('type_name', self.type_name),
+ ('source_path', self.source_path),
+ ('target_path', self.target_path),
+ ('repository_url', self.repository_url),
+ ('repository_credential', formatting.as_agnostic(self.repository_credential)),
+ ('properties', formatting.as_raw_dict(self.properties))))
+
+ def validate(self, context):
+ if context.modeling.artifact_types.get_descendant(self.type_name) is None:
+ context.validation.report('artifact "%s" has an unknown type: %s'
+ % (self.name,
+ formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+ utils.validate_dict_values(context, self.properties)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.properties, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Artifact type: %s' % context.style.type(self.type_name))
+ console.puts('Source path: %s' % context.style.literal(self.source_path))
+ if self.target_path is not None:
+ console.puts('Target path: %s' % context.style.literal(self.target_path))
+ if self.repository_url is not None:
+ console.puts('Repository URL: %s' % context.style.literal(self.repository_url))
+ if self.repository_credential:
+ console.puts('Repository credential: %s'
+ % context.style.literal(self.repository_credential))
+ utils.dump_parameters(context, self.properties)
+
+
+class PolicyBase(structure.ModelMixin):
+ """
+ An instance of a :class:`PolicyTemplate`.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`properties`: Dict of :class:`Parameter`
+ * :code:`target_node_ids`: Must be represented in the :class:`ServiceInstance`
+ * :code:`target_group_ids`: Must be represented in the :class:`ServiceInstance`
+ """
+ __tablename__ = 'policy'
+ # region foreign_keys
+ @declared_attr
+ def service_instance_fk(cls):
+ return cls.foreign_key('service_instance')
+
+ # endregion
+ type_name = Column(Text)
+ target_node_ids = Column(aria_types.StrictList(basestring))
+ target_group_ids = Column(aria_types.StrictList(basestring))
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('type_name', self.type_name),
+ ('properties', formatting.as_raw_dict(self.properties)),
+ ('target_node_ids', self.target_node_ids),
+ ('target_group_ids', self.target_group_ids)))
+
+ def validate(self, context):
+ if context.modeling.policy_types.get_descendant(self.type_name) is None:
+ context.validation.report('policy "%s" has an unknown type: %s'
+ % (self.name, utils.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.properties)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.properties, report_issues)
+
+ def dump(self, context):
+ console.puts('Policy: %s' % context.style.node(self.name))
+ with context.style.indent:
+ console.puts('Type: %s' % context.style.type(self.type_name))
+ utils.dump_parameters(context, self.properties)
+ if self.target_node_ids:
+ console.puts('Target nodes:')
+ with context.style.indent:
+ for node_id in self.target_node_ids:
+ console.puts(context.style.node(node_id))
+ if self.target_group_ids:
+ console.puts('Target groups:')
+ with context.style.indent:
+ for group_id in self.target_group_ids:
+ console.puts(context.style.node(group_id))
+
+
+class GroupPolicyBase(structure.ModelMixin):
+ """
+ Policies applied to groups.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`description`: Description
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`properties`: Dict of :class:`Parameter`
+ * :code:`triggers`: Dict of :class:`GroupPolicyTrigger`
+ """
+ __tablename__ = 'group_policy'
+ # region foreign_keys
+ @declared_attr
+ def group_fk(cls):
+ return cls.foreign_key('group')
+
+ # endregion
+
+ description = Column(Text)
+ type_name = Column(Text)
+
+ # region one-to-many relationships
+
+ @declared_attr
+ def triggers(cls):
+ return cls.one_to_many_relationship('group_policy_trigger')
+
+ # endregion
+
+ # region many-to-many relationships
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # relationships
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('type_name', self.type_name),
+ ('properties', formatting.as_raw_dict(self.properties)),
+ ('triggers', formatting.as_raw_list(self.triggers))))
+
+ def validate(self, context):
+ if context.modeling.policy_types.get_descendant(self.type_name) is None:
+ context.validation.report(
+ 'group policy "%s" has an unknown type: %s'
+ % (self.name,
+ formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.properties)
+ utils.validate_dict_values(context, self.triggers)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.properties, report_issues)
+ utils.coerce_dict_values(context, container, self.triggers, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Group policy type: %s' % context.style.type(self.type_name))
+ utils.dump_parameters(context, self.properties)
+ utils.dump_dict_values(context, self.triggers, 'Triggers')
+
+
+class GroupPolicyTriggerBase(structure.ModelMixin):
+ """
+ Triggers for :class:`GroupPolicy`.
+
+ Properties:
+
+ * :code:`name`: Name
+ * :code:`description`: Description
+ * :code:`implementation`: Implementation string (interpreted by the orchestrator)
+ * :code:`properties`: Dict of :class:`Parameter`
+ """
+ __tablename__ = 'group_policy_trigger'
+ # region foreign keys
+
+ @declared_attr
+ def group_policy_fk(cls):
+ return cls.foreign_key('group_policy')
+
+ # endregion
+
+ description = Column(Text)
+ implementation = Column(Text)
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('description', self.description),
+ ('implementation', self.implementation),
+ ('properties', formatting.as_raw_dict(self.properties))))
+
+ def validate(self, context):
+ utils.validate_dict_values(context, self.properties)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.properties, report_issues)
+
+ def dump(self, context):
+ console.puts(context.style.node(self.name))
+ if self.description:
+ console.puts(context.style.meta(self.description))
+ with context.style.indent:
+ console.puts('Implementation: %s' % context.style.literal(self.implementation))
+ utils.dump_parameters(context, self.properties)
+
+
+class MappingBase(structure.ModelMixin):
+ """
+ An instance of a :class:`MappingTemplate`.
+
+ Properties:
+
+ * :code:`mapped_name`: Exposed capability or requirement name
+ * :code:`node_id`: Must be represented in the :class:`ServiceInstance`
+ * :code:`name`: Name of capability or requirement at the node
+ """
+ __tablename__ = 'mapping'
+
+ mapped_name = Column(Text)
+ node_id = Column(Text)
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('mapped_name', self.mapped_name),
+ ('node_id', self.node_id),
+ ('name', self.name)))
+
+ def dump(self, context):
+ console.puts('%s -> %s.%s'
+ % (context.style.node(self.mapped_name),
+ context.style.node(self.node_id),
+ context.style.node(self.name)))
+
+
+class SubstitutionBase(structure.ModelMixin):
+ """
+ An instance of a :class:`SubstitutionTemplate`.
+
+ Properties:
+
+ * :code:`node_type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`capabilities`: Dict of :class:`Mapping`
+ * :code:`requirements`: Dict of :class:`Mapping`
+ """
+ __tablename__ = 'substitution'
+ node_type_name = Column(Text)
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def capabilities(cls):
+ return cls.many_to_many_relationship('mapping', table_prefix='capabilities')
+
+ @declared_attr
+ def requirements(cls):
+ return cls.many_to_many_relationship('mapping',
+ table_prefix='requirements',
+ relationship_kwargs=dict(lazy='dynamic'))
+
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('node_type_name', self.node_type_name),
+ ('capabilities', formatting.as_raw_list(self.capabilities)),
+ ('requirements', formatting.as_raw_list(self.requirements))))
+
+ def validate(self, context):
+ if context.modeling.node_types.get_descendant(self.node_type_name) is None:
+ context.validation.report('substitution "%s" has an unknown type: %s'
+ % (self.name, # pylint: disable=no-member
+ # TODO fix self.name reference
+ formatting.safe_repr(self.node_type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.capabilities)
+ utils.validate_dict_values(context, self.requirements)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.capabilities, report_issues)
+ utils.coerce_dict_values(context, container, self.requirements, report_issues)
+
+ def dump(self, context):
+ console.puts('Substitution:')
+ with context.style.indent:
+ console.puts('Node type: %s' % context.style.type(self.node_type_name))
+ utils.dump_dict_values(context, self.capabilities, 'Capability mappings')
+ utils.dump_dict_values(context, self.requirements, 'Requirement mappings')
+
+
+# endregion
+
+# region Node instances
+
+class NodeBase(structure.ModelMixin):
+ """
+ An instance of a :class:`NodeTemplate`.
+
+ Nodes may have zero or more :class:`Relationship` instances to other nodes.
+
+ Properties:
+
+ * :code:`id`: Unique ID (prefixed with the template name)
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`template_name`: Must be represented in the :class:`ServiceModel`
+ * :code:`properties`: Dict of :class:`Parameter`
+ * :code:`interfaces`: Dict of :class:`Interface`
+ * :code:`artifacts`: Dict of :class:`Artifact`
+ * :code:`capabilities`: Dict of :class:`CapabilityTemplate`
+ * :code:`relationship`: List of :class:`Relationship`
+ """
+ __tablename__ = 'node'
+
+ # region foreign_keys
+ @declared_attr
+ def service_instance_fk(cls):
+ return cls.foreign_key('service_instance')
+
+ @declared_attr
+ def host_fk(cls):
+ return cls.foreign_key('node', nullable=True)
+
+ @declared_attr
+ def node_template_fk(cls):
+ return cls.foreign_key('node_template')
+
+ # endregion
+
+ type_name = Column(Text)
+ template_name = Column(Text)
+
+ # region orchestrator required columns
+ runtime_properties = Column(aria_types.Dict)
+ scaling_groups = Column(aria_types.List)
+ state = Column(Text, nullable=False)
+ version = Column(Integer, default=1)
+
+ @declared_attr
+ def plugins(cls):
+ return association_proxy('node_template', 'plugins')
+
+ @declared_attr
+ def host(cls):
+ return cls.relationship_to_self('host_fk')
+
+ @property
+ def ip(self):
+ if not self.host_fk:
+ return None
+ host_node_instance = self.host
+ if 'ip' in host_node_instance.runtime_properties: # pylint: disable=no-member
+ return host_node_instance.runtime_properties['ip'] # pylint: disable=no-member
+ host_node = host_node_instance.node # pylint: disable=no-member
+ if 'ip' in host_node.properties:
+ return host_node.properties['ip']
+ return None
+
+ @declared_attr
+ def node_template(cls):
+ return cls.many_to_one_relationship('node_template')
+
+ @declared_attr
+ def service_template(cls):
+ return association_proxy('service_instance', 'service_template')
+ # endregion
+
+ # region one-to-many relationships
+ @declared_attr
+ def interfaces(cls):
+ return cls.one_to_many_relationship('interface')
+
+ @declared_attr
+ def artifacts(cls):
+ return cls.one_to_many_relationship('artifact')
+
+ @declared_attr
+ def capabilities(cls):
+ return cls.one_to_many_relationship('capability')
+
+ # endregion
+
+ # region many-to-one relationships
+ @declared_attr
+ def service_instance(cls):
+ return cls.many_to_one_relationship('service_instance')
+
+ # endregion
+
+ # region many-to-many relationships
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ def satisfy_requirements(self, context):
+ node_template = context.modeling.model.node_templates.get(self.template_name)
+ satisfied = True
+ for i in range(len(node_template.requirement_templates)):
+ requirement_template = node_template.requirement_templates[i]
+
+ # Find target template
+ target_node_template, target_node_capability = \
+ requirement_template.find_target(context, node_template)
+ if target_node_template is not None:
+ satisfied = self._satisfy_capability(context,
+ target_node_capability,
+ target_node_template,
+ requirement_template,
+ requirement_template_index=i)
+ else:
+ context.validation.report('requirement "%s" of node "%s" has no target node '
+ 'template' % (requirement_template.name,
+ self.id),
+ level=validation.Issue.BETWEEN_INSTANCES)
+ satisfied = False
+ return satisfied
+
+ def _satisfy_capability(self, context, target_node_capability, target_node_template,
+ requirement_template, requirement_template_index):
+ # Find target nodes
+ target_nodes = context.modeling.instance.find_nodes(target_node_template.name)
+ if target_nodes:
+ target_node = None
+ target_capability = None
+
+ if target_node_capability is not None:
+ # Relate to the first target node that has capacity
+ for node in target_nodes:
+ target_capability = node.capabilities.get(target_node_capability.name)
+ if target_capability.relate():
+ target_node = node
+ break
+ else:
+ # Use first target node
+ target_node = target_nodes[0]
+
+ if target_node is not None:
+ if requirement_template.relationship_template is not None:
+ relationship = \
+ requirement_template.relationship_template.instantiate(context, self)
+ else:
+ relationship = RelationshipBase()
+ relationship.name = requirement_template.name
+ relationship.source_requirement_index = requirement_template_index
+ relationship.target_node_id = target_node.id
+ if target_capability is not None:
+ relationship.target_capability_name = target_capability.name
+ self.relationships.append(relationship)
+ else:
+ context.validation.report('requirement "%s" of node "%s" targets node '
+ 'template "%s" but its instantiated nodes do not '
+ 'have enough capacity'
+ % (requirement_template.name,
+ self.id,
+ target_node_template.name),
+ level=validation.Issue.BETWEEN_INSTANCES)
+ return False
+ else:
+ context.validation.report('requirement "%s" of node "%s" targets node template '
+ '"%s" but it has no instantiated nodes'
+ % (requirement_template.name,
+ self.id,
+ target_node_template.name),
+ level=validation.Issue.BETWEEN_INSTANCES)
+ return False
+
+ def validate_capabilities(self, context):
+ satisfied = False
+ for capability in self.capabilities.itervalues():
+ if not capability.has_enough_relationships:
+ context.validation.report('capability "%s" of node "%s" requires at least %d '
+ 'relationships but has %d'
+ % (capability.name,
+ self.id,
+ capability.min_occurrences,
+ capability.occurrences),
+ level=validation.Issue.BETWEEN_INSTANCES)
+ satisfied = False
+ return satisfied
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('id', self.id),
+ ('type_name', self.type_name),
+ ('template_name', self.template_name),
+ ('properties', formatting.as_raw_dict(self.properties)),
+ ('interfaces', formatting.as_raw_list(self.interfaces)),
+ ('artifacts', formatting.as_raw_list(self.artifacts)),
+ ('capabilities', formatting.as_raw_list(self.capabilities)),
+ ('relationships', formatting.as_raw_list(self.relationships))))
+
+ def validate(self, context):
+ if len(self.id) > context.modeling.id_max_length:
+ context.validation.report('"%s" has an ID longer than the limit of %d characters: %d'
+ % (self.id,
+ context.modeling.id_max_length,
+ len(self.id)),
+ level=validation.Issue.BETWEEN_INSTANCES)
+
+ # TODO: validate that node template is of type?
+
+ utils.validate_dict_values(context, self.properties)
+ utils.validate_dict_values(context, self.interfaces)
+ utils.validate_dict_values(context, self.artifacts)
+ utils.validate_dict_values(context, self.capabilities)
+ utils.validate_list_values(context, self.relationships)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, self, self.properties, report_issues)
+ utils.coerce_dict_values(context, self, self.interfaces, report_issues)
+ utils.coerce_dict_values(context, self, self.artifacts, report_issues)
+ utils.coerce_dict_values(context, self, self.capabilities, report_issues)
+ utils.coerce_list_values(context, self, self.relationships, report_issues)
+
+ def dump(self, context):
+ console.puts('Node: %s' % context.style.node(self.id))
+ with context.style.indent:
+ console.puts('Template: %s' % context.style.node(self.template_name))
+ console.puts('Type: %s' % context.style.type(self.type_name))
+ utils.dump_parameters(context, self.properties)
+ utils.dump_interfaces(context, self.interfaces)
+ utils.dump_dict_values(context, self.artifacts, 'Artifacts')
+ utils.dump_dict_values(context, self.capabilities, 'Capabilities')
+ utils.dump_list_values(context, self.relationships, 'Relationships')
+
+
+class GroupBase(structure.ModelMixin):
+ """
+ An instance of a :class:`GroupTemplate`.
+
+ Properties:
+
+ * :code:`id`: Unique ID (prefixed with the template name)
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`template_name`: Must be represented in the :class:`ServiceModel`
+ * :code:`properties`: Dict of :class:`Parameter`
+ * :code:`interfaces`: Dict of :class:`Interface`
+ * :code:`policies`: Dict of :class:`GroupPolicy`
+ * :code:`member_node_ids`: Must be represented in the :class:`ServiceInstance`
+ * :code:`member_group_ids`: Must be represented in the :class:`ServiceInstance`
+ """
+ __tablename__ = 'group'
+ # region foreign_keys
+
+ @declared_attr
+ def service_instance_fk(cls):
+ return cls.foreign_key('service_instance')
+
+ # endregion
+
+ type_name = Column(Text)
+ template_name = Column(Text)
+ member_node_ids = Column(aria_types.StrictList(basestring))
+ member_group_ids = Column(aria_types.StrictList(basestring))
+
+ # region one-to-many relationships
+ @declared_attr
+ def interfaces(cls):
+ return cls.one_to_many_relationship('interface')
+
+ @declared_attr
+ def policies(cls):
+ return cls.one_to_many_relationship('group_policy')
+
+ # endregion
+
+ # region many-to-many relationships
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ # endregion
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('id', self.id),
+ ('type_name', self.type_name),
+ ('template_name', self.template_name),
+ ('properties', formatting.as_raw_dict(self.properties)),
+ ('interfaces', formatting.as_raw_list(self.interfaces)),
+ ('policies', formatting.as_raw_list(self.policies)),
+ ('member_node_ids', self.member_node_ids),
+ ('member_group_ids', self.member_group_ids)))
+
+ def validate(self, context):
+ if context.modeling.group_types.get_descendant(self.type_name) is None:
+ context.validation.report('group "%s" has an unknown type: %s'
+ % (self.name, # pylint: disable=no-member
+ # TODO fix self.name reference
+ formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+
+ utils.validate_dict_values(context, self.properties)
+ utils.validate_dict_values(context, self.interfaces)
+ utils.validate_dict_values(context, self.policies)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.properties, report_issues)
+ utils.coerce_dict_values(context, container, self.interfaces, report_issues)
+ utils.coerce_dict_values(context, container, self.policies, report_issues)
+
+ def dump(self, context):
+ console.puts('Group: %s' % context.style.node(self.id))
+ with context.style.indent:
+ console.puts('Type: %s' % context.style.type(self.type_name))
+ console.puts('Template: %s' % context.style.type(self.template_name))
+ utils.dump_parameters(context, self.properties)
+ utils.dump_interfaces(context, self.interfaces)
+ utils.dump_dict_values(context, self.policies, 'Policies')
+ if self.member_node_ids:
+ console.puts('Member nodes:')
+ with context.style.indent:
+ for node_id in self.member_node_ids:
+ console.puts(context.style.node(node_id))
+
+# endregion
+
+# region Relationship instances
+
+
+class RelationshipBase(structure.ModelMixin):
+ """
+ Connects :class:`Node` to another node.
+
+ An instance of a :class:`RelationshipTemplate`.
+
+ Properties:
+
+ * :code:`name`: Name (usually the name of the requirement at the source node template)
+ * :code:`source_requirement_index`: Must be represented in the source node template
+ * :code:`target_node_id`: Must be represented in the :class:`ServiceInstance`
+ * :code:`target_capability_name`: Matches the capability at the target node
+ * :code:`type_name`: Must be represented in the :class:`ModelingContext`
+ * :code:`template_name`: Must be represented in the :class:`ServiceModel`
+ * :code:`properties`: Dict of :class:`Parameter`
+ * :code:`source_interfaces`: Dict of :class:`Interface`
+ * :code:`target_interfaces`: Dict of :class:`Interface`
+ """
+ __tablename__ = 'relationship'
+
+ source_requirement_index = Column(Integer)
+ target_node_id = Column(Text)
+ target_capability_name = Column(Text)
+ type_name = Column(Text)
+ template_name = Column(Text)
+
+ # # region orchestrator required columns
+ source_position = Column(Integer)
+ target_position = Column(Integer)
+
+ @declared_attr
+ def source_node_fk(cls):
+ return cls.foreign_key('node', nullable=True)
+
+ @declared_attr
+ def source_node(cls):
+ return cls.many_to_one_relationship(
+ 'node',
+ 'source_node_fk',
+ backreference='outbound_relationships',
+ backref_kwargs=dict(
+ order_by=cls.source_position,
+ collection_class=ordering_list('source_position', count_from=0),
+ lazy='select'
+ )
+ )
+
+ @declared_attr
+ def source_node_name(cls):
+ return association_proxy('source_node', cls.name_column_name())
+
+ @declared_attr
+ def target_node_fk(cls):
+ return cls.foreign_key('node', nullable=True)
+
+ @declared_attr
+ def target_node(cls):
+ return cls.many_to_one_relationship(
+ 'node',
+ 'target_node_fk',
+ backreference='inbound_relationships',
+ backref_kwargs=dict(
+ order_by=cls.target_position,
+ collection_class=ordering_list('target_position', count_from=0),
+ lazy='select'
+ )
+ )
+
+ @declared_attr
+ def target_node_name(cls):
+ return association_proxy('target_node', cls.name_column_name())
+ # endregion
+
+ # region many-to-many relationship
+
+ @declared_attr
+ def properties(cls):
+ return cls.many_to_many_relationship('parameter', table_prefix='properties')
+
+ @declared_attr
+ def source_interfaces(cls):
+ return cls.many_to_many_relationship('interface',
+ table_prefix='source_interfaces',
+ relationship_kwargs=dict(lazy='dynamic'))
+
+ @declared_attr
+ def target_interfaces(cls):
+ return cls.many_to_many_relationship('interface',
+ table_prefix='target_interfaces',
+ relationship_kwargs=dict(lazy='dynamic'))
+
+ @property
+ def as_raw(self):
+ return collections.OrderedDict((
+ ('name', self.name),
+ ('source_requirement_index', self.source_requirement_index),
+ ('target_node_id', self.target_node_id),
+ ('target_capability_name', self.target_capability_name),
+ ('type_name', self.type_name),
+ ('template_name', self.template_name),
+ ('properties', formatting.as_raw_dict(self.properties)),
+ ('source_interfaces', formatting.as_raw_list(self.source_interfaces)),
+ ('target_interfaces', formatting.as_raw_list(self.target_interfaces))))
+
+ def validate(self, context):
+ if self.type_name:
+ if context.modeling.relationship_types.get_descendant(self.type_name) is None:
+ context.validation.report('relationship "%s" has an unknown type: %s'
+ % (self.name,
+ formatting.safe_repr(self.type_name)),
+ level=validation.Issue.BETWEEN_TYPES)
+ utils.validate_dict_values(context, self.properties)
+ utils.validate_dict_values(context, self.source_interfaces)
+ utils.validate_dict_values(context, self.target_interfaces)
+
+ def coerce_values(self, context, container, report_issues):
+ utils.coerce_dict_values(context, container, self.properties, report_issues)
+ utils.coerce_dict_values(context, container, self.source_interfaces, report_issues)
+ utils.coerce_dict_values(context, container, self.target_interfaces, report_issues)
+
+ def dump(self, context):
+ if self.name:
+ if self.source_requirement_index is not None:
+ console.puts('%s (%d) ->' % (
+ context.style.node(self.name),
+ self.source_requirement_index))
+ else:
+ console.puts('%s ->' % context.style.node(self.name))
+ else:
+ console.puts('->')
+ with context.style.indent:
+ console.puts('Node: %s' % context.style.node(self.target_node_id))
+ if self.target_capability_name is not None:
+ console.puts('Capability: %s' % context.style.node(self.target_capability_name))
+ if self.type_name is not None:
+ console.puts('Relationship type: %s' % context.style.type(self.type_name))
+ if self.template_name is not None:
+ console.puts('Relationship template: %s' % context.style.node(self.template_name))
+ utils.dump_parameters(context, self.properties)
+ utils.dump_interfaces(context, self.source_interfaces, 'Source interfaces')
+ utils.dump_interfaces(context, self.target_interfaces, 'Target interfaces')
+
+# endregion
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/modeling/model.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/model.py b/aria/storage/modeling/model.py
new file mode 100644
index 0000000..227e5b5
--- /dev/null
+++ b/aria/storage/modeling/model.py
@@ -0,0 +1,175 @@
+# 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.ext.declarative import declarative_base
+
+from . import (
+ elements,
+ template_elements,
+ instance_elements,
+ orchestrator_elements,
+ structure,
+)
+
+DB = declarative_base(cls=structure.ModelIDMixin)
+
+# pylint: disable=abstract-method
+
+# region elements
+
+
+class Parameter(elements.ParameterBase, DB):
+ pass
+
+# endregion
+
+# region template models
+
+
+class MappingTemplate(DB, template_elements.MappingTemplateBase):
+ pass
+
+
+class SubstitutionTemplate(DB, template_elements.SubstitutionTemplateBase):
+ pass
+
+
+class InterfaceTemplate(DB, template_elements.InterfaceTemplateBase):
+ pass
+
+
+class OperationTemplate(DB, template_elements.OperationTemplateBase):
+ pass
+
+
+class ServiceTemplate(DB, template_elements.ServiceTemplateBase):
+ pass
+
+
+class NodeTemplate(DB, template_elements.NodeTemplateBase):
+ pass
+
+
+class GroupTemplate(DB, template_elements.GroupTemplateBase):
+ pass
+
+
+class ArtifactTemplate(DB, template_elements.ArtifactTemplateBase):
+ pass
+
+
+class PolicyTemplate(DB, template_elements.PolicyTemplateBase):
+ pass
+
+
+class GroupPolicyTemplate(DB, template_elements.GroupPolicyTemplateBase):
+ pass
+
+
+class GroupPolicyTriggerTemplate(DB, template_elements.GroupPolicyTriggerTemplateBase):
+ pass
+
+
+class RequirementTemplate(DB, template_elements.RequirementTemplateBase):
+ pass
+
+
+class CapabilityTemplate(DB, template_elements.CapabilityTemplateBase):
+ pass
+
+
+# endregion
+
+# region instance models
+
+class Mapping(DB, instance_elements.MappingBase):
+ pass
+
+
+class Substitution(DB, instance_elements.SubstitutionBase):
+ pass
+
+
+class ServiceInstance(DB, instance_elements.ServiceInstanceBase):
+ pass
+
+
+class Node(DB, instance_elements.NodeBase):
+ pass
+
+
+class Relationship(DB, instance_elements.RelationshipBase):
+ pass
+
+
+class Artifact(DB, instance_elements.ArtifactBase):
+ pass
+
+
+class Group(DB, instance_elements.GroupBase):
+ pass
+
+
+class Interface(DB, instance_elements.InterfaceBase):
+ pass
+
+
+class Operation(DB, instance_elements.OperationBase):
+ pass
+
+
+class Capability(DB, instance_elements.CapabilityBase):
+ pass
+
+
+class Policy(DB, instance_elements.PolicyBase):
+ pass
+
+
+class GroupPolicy(DB, instance_elements.GroupPolicyBase):
+ pass
+
+
+class GroupPolicyTrigger(DB, instance_elements.GroupPolicyTriggerBase):
+ pass
+
+
+# endregion
+
+# region orchestrator models
+
+class Execution(DB, orchestrator_elements.Execution):
+ pass
+
+
+class ServiceInstanceUpdate(DB, orchestrator_elements.ServiceInstanceUpdateBase):
+ pass
+
+
+class ServiceInstanceUpdateStep(DB, orchestrator_elements.ServiceInstanceUpdateStepBase):
+ pass
+
+
+class ServiceInstanceModification(DB, orchestrator_elements.ServiceInstanceModificationBase):
+ pass
+
+
+class Plugin(DB, orchestrator_elements.PluginBase):
+ pass
+
+
+class Task(DB, orchestrator_elements.TaskBase):
+ pass
+# endregion
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/modeling/orchestrator_elements.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/orchestrator_elements.py b/aria/storage/modeling/orchestrator_elements.py
new file mode 100644
index 0000000..6966322
--- /dev/null
+++ b/aria/storage/modeling/orchestrator_elements.py
@@ -0,0 +1,446 @@
+# 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.
+
+"""
+Aria's storage.models module
+Path: aria.storage.models
+
+models module holds aria's models.
+
+classes:
+ * Field - represents a single field.
+ * IterField - represents an iterable field.
+ * Model - abstract model implementation.
+ * Snapshot - snapshots implementation model.
+ * Deployment - deployment implementation model.
+ * DeploymentUpdateStep - deployment update step implementation model.
+ * DeploymentUpdate - deployment update implementation model.
+ * DeploymentModification - deployment modification implementation model.
+ * Execution - execution implementation model.
+ * Node - node implementation model.
+ * Relationship - relationship implementation model.
+ * NodeInstance - node instance implementation model.
+ * RelationshipInstance - relationship instance implementation model.
+ * Plugin - plugin implementation model.
+"""
+from collections import namedtuple
+from datetime import datetime
+
+from sqlalchemy import (
+ Column,
+ Integer,
+ Text,
+ DateTime,
+ Boolean,
+ Enum,
+ String,
+ Float,
+ orm,
+)
+from sqlalchemy.ext.associationproxy import association_proxy
+from sqlalchemy.ext.declarative import declared_attr
+
+from aria.orchestrator.exceptions import TaskAbortException, TaskRetryException
+
+from .type import List, Dict
+from .structure import ModelMixin
+
+__all__ = (
+ 'ServiceInstanceUpdateStepBase',
+ 'ServiceInstanceUpdateBase',
+ 'ServiceInstanceModificationBase',
+ 'Execution',
+ 'PluginBase',
+ 'TaskBase'
+)
+
+# pylint: disable=no-self-argument, no-member, abstract-method
+
+
+class Execution(ModelMixin):
+ """
+ Execution model representation.
+ """
+ # Needed only for pylint. the id will be populated by sqlalcehmy and the proper column.
+ __tablename__ = 'execution'
+
+ TERMINATED = 'terminated'
+ FAILED = 'failed'
+ CANCELLED = 'cancelled'
+ PENDING = 'pending'
+ STARTED = 'started'
+ CANCELLING = 'cancelling'
+ FORCE_CANCELLING = 'force_cancelling'
+
+ STATES = [TERMINATED, FAILED, CANCELLED, PENDING, STARTED, CANCELLING, FORCE_CANCELLING]
+ END_STATES = [TERMINATED, FAILED, CANCELLED]
+ ACTIVE_STATES = [state for state in STATES if state not in END_STATES]
+
+ VALID_TRANSITIONS = {
+ PENDING: [STARTED, CANCELLED],
+ STARTED: END_STATES + [CANCELLING],
+ CANCELLING: END_STATES + [FORCE_CANCELLING]
+ }
+
+ @orm.validates('status')
+ def validate_status(self, key, value):
+ """Validation function that verifies execution status transitions are OK"""
+ try:
+ current_status = getattr(self, key)
+ except AttributeError:
+ return
+ valid_transitions = self.VALID_TRANSITIONS.get(current_status, [])
+ if all([current_status is not None,
+ current_status != value,
+ value not in valid_transitions]):
+ raise ValueError('Cannot change execution status from {current} to {new}'.format(
+ current=current_status,
+ new=value))
+ return value
+
+ created_at = Column(DateTime, index=True)
+ started_at = Column(DateTime, nullable=True, index=True)
+ ended_at = Column(DateTime, nullable=True, index=True)
+ error = Column(Text, nullable=True)
+ is_system_workflow = Column(Boolean, nullable=False, default=False)
+ parameters = Column(Dict)
+ status = Column(Enum(*STATES, name='execution_status'), default=PENDING)
+ workflow_name = Column(Text)
+
+ @declared_attr
+ def service_template(cls):
+ return association_proxy('service_instance', 'service_template')
+
+ @declared_attr
+ def service_instance_fk(cls):
+ return cls.foreign_key('service_instance')
+
+ @declared_attr
+ def service_instance(cls):
+ return cls.many_to_one_relationship('service_instance')
+
+ @declared_attr
+ def service_instance_name(cls):
+ return association_proxy('service_instance', cls.name_column_name())
+
+ @declared_attr
+ def service_template_name(cls):
+ return association_proxy('service_instance', 'service_template_name')
+
+ def __str__(self):
+ return '<{0} id=`{1}` (status={2})>'.format(
+ self.__class__.__name__,
+ getattr(self, self.name_column_name()),
+ self.status
+ )
+
+
+class ServiceInstanceUpdateBase(ModelMixin):
+ """
+ Deployment update model representation.
+ """
+ # Needed only for pylint. the id will be populated by sqlalcehmy and the proper column.
+ steps = None
+
+ __tablename__ = 'service_instance_update'
+
+ _private_fields = ['execution_fk', 'deployment_fk']
+
+ created_at = Column(DateTime, nullable=False, index=True)
+ deployment_plan = Column(Dict, nullable=False)
+ deployment_update_node_instances = Column(Dict)
+ deployment_update_deployment = Column(Dict)
+ deployment_update_nodes = Column(List)
+ modified_entity_ids = Column(Dict)
+ state = Column(Text)
+
+ @declared_attr
+ def execution_fk(cls):
+ return cls.foreign_key('execution', nullable=True)
+
+ @declared_attr
+ def execution(cls):
+ return cls.many_to_one_relationship('execution')
+
+ @declared_attr
+ def execution_name(cls):
+ return association_proxy('execution', cls.name_column_name())
+
+ @declared_attr
+ def service_instance_fk(cls):
+ return cls.foreign_key('service_instance')
+
+ @declared_attr
+ def service_instance(cls):
+ return cls.many_to_one_relationship('service_instance')
+
+ @declared_attr
+ def service_instance_name(cls):
+ return association_proxy('service_instance', cls.name_column_name())
+
+ def to_dict(self, suppress_error=False, **kwargs):
+ dep_update_dict = super(ServiceInstanceUpdateBase, self).to_dict(suppress_error) #pylint: disable=no-member
+ # Taking care of the fact the DeploymentSteps are _BaseModels
+ dep_update_dict['steps'] = [step.to_dict() for step in self.steps]
+ return dep_update_dict
+
+
+class ServiceInstanceUpdateStepBase(ModelMixin):
+ """
+ Deployment update step model representation.
+ """
+ # Needed only for pylint. the id will be populated by sqlalcehmy and the proper column.
+ __tablename__ = 'service_instance_update_step'
+ _private_fields = ['deployment_update_fk']
+
+ _action_types = namedtuple('ACTION_TYPES', 'ADD, REMOVE, MODIFY')
+ ACTION_TYPES = _action_types(ADD='add', REMOVE='remove', MODIFY='modify')
+ _entity_types = namedtuple(
+ 'ENTITY_TYPES',
+ 'NODE, RELATIONSHIP, PROPERTY, OPERATION, WORKFLOW, OUTPUT, DESCRIPTION, GROUP, '
+ 'POLICY_TYPE, POLICY_TRIGGER, PLUGIN')
+ ENTITY_TYPES = _entity_types(
+ NODE='node',
+ RELATIONSHIP='relationship',
+ PROPERTY='property',
+ OPERATION='operation',
+ WORKFLOW='workflow',
+ OUTPUT='output',
+ DESCRIPTION='description',
+ GROUP='group',
+ POLICY_TYPE='policy_type',
+ POLICY_TRIGGER='policy_trigger',
+ PLUGIN='plugin'
+ )
+
+ action = Column(Enum(*ACTION_TYPES, name='action_type'), nullable=False)
+ entity_id = Column(Text, nullable=False)
+ entity_type = Column(Enum(*ENTITY_TYPES, name='entity_type'), nullable=False)
+
+ @declared_attr
+ def service_instance_update_fk(cls):
+ return cls.foreign_key('service_instance_update')
+
+ @declared_attr
+ def deployment_update(cls):
+ return cls.many_to_one_relationship('service_instance_update',
+ backreference='steps')
+
+ @declared_attr
+ def deployment_update_name(cls):
+ return association_proxy('deployment_update', cls.name_column_name())
+
+ def __hash__(self):
+ return hash((getattr(self, self.id_column_name()), self.entity_id))
+
+ def __lt__(self, other):
+ """
+ the order is 'remove' < 'modify' < 'add'
+ :param other:
+ :return:
+ """
+ if not isinstance(other, self.__class__):
+ return not self >= other
+
+ if self.action != other.action:
+ if self.action == 'remove':
+ return_value = True
+ elif self.action == 'add':
+ return_value = False
+ else:
+ return_value = other.action == 'add'
+ return return_value
+
+ if self.action == 'add':
+ return self.entity_type == 'node' and other.entity_type == 'relationship'
+ if self.action == 'remove':
+ return self.entity_type == 'relationship' and other.entity_type == 'node'
+ return False
+
+
+class ServiceInstanceModificationBase(ModelMixin):
+ """
+ Deployment modification model representation.
+ """
+ __tablename__ = 'deployment_modifications'
+ _private_fields = ['deployment_fk']
+
+ STARTED = 'started'
+ FINISHED = 'finished'
+ ROLLEDBACK = 'rolledback'
+
+ STATES = [STARTED, FINISHED, ROLLEDBACK]
+ END_STATES = [FINISHED, ROLLEDBACK]
+
+ context = Column(Dict)
+ created_at = Column(DateTime, nullable=False, index=True)
+ ended_at = Column(DateTime, index=True)
+ modified_nodes = Column(Dict)
+ node_instances = Column(Dict)
+ status = Column(Enum(*STATES, name='deployment_modification_status'))
+
+ @declared_attr
+ def service_instance_fk(cls):
+ return cls.foreign_key('service_instance')
+
+ @declared_attr
+ def service_instance(cls):
+ return cls.many_to_one_relationship('service_instance',
+ backreference='modifications')
+
+ @declared_attr
+ def deployment_name(cls):
+ return association_proxy('service_instance', cls.name_column_name())
+
+
+class PluginBase(ModelMixin):
+ """
+ Plugin model representation.
+ """
+ __tablename__ = 'plugin'
+
+ archive_name = Column(Text, nullable=False, index=True)
+ distribution = Column(Text)
+ distribution_release = Column(Text)
+ distribution_version = Column(Text)
+ package_name = Column(Text, nullable=False, index=True)
+ package_source = Column(Text)
+ package_version = Column(Text)
+ supported_platform = Column(Text)
+ supported_py_versions = Column(List)
+ uploaded_at = Column(DateTime, nullable=False, index=True)
+ wheels = Column(List, nullable=False)
+
+
+class TaskBase(ModelMixin):
+ """
+ A Model which represents an task
+ """
+ __tablename__ = 'tasks'
+ _private_fields = ['node_instance_fk', 'relationship_instance_fk', 'execution_fk']
+
+ @declared_attr
+ def node_fk(cls):
+ return cls.foreign_key('node', nullable=True)
+
+ @declared_attr
+ def node_name(cls):
+ return association_proxy('node', cls.name_column_name())
+
+ @declared_attr
+ def node(cls):
+ return cls.many_to_one_relationship('node')
+
+ @declared_attr
+ def relationship_fk(cls):
+ return cls.foreign_key('relationship', nullable=True)
+
+ @declared_attr
+ def relationship_name(cls):
+ return association_proxy('relationships', cls.name_column_name())
+
+ @declared_attr
+ def relationship(cls):
+ return cls.many_to_one_relationship('relationship')
+
+ @declared_attr
+ def plugin_fk(cls):
+ return cls.foreign_key('plugin', nullable=True)
+
+ @declared_attr
+ def plugin(cls):
+ return cls.many_to_one_relationship('plugin')
+
+ @declared_attr
+ def plugin_name(cls):
+ return association_proxy('plugin', 'name')
+
+ @declared_attr
+ def execution_fk(cls):
+ return cls.foreign_key('execution', nullable=True)
+
+ @declared_attr
+ def execution(cls):
+ return cls.many_to_one_relationship('execution')
+
+ @declared_attr
+ def execution_name(cls):
+ return association_proxy('execution', cls.name_column_name())
+
+ PENDING = 'pending'
+ RETRYING = 'retrying'
+ SENT = 'sent'
+ STARTED = 'started'
+ SUCCESS = 'success'
+ FAILED = 'failed'
+ STATES = (
+ PENDING,
+ RETRYING,
+ SENT,
+ STARTED,
+ SUCCESS,
+ FAILED,
+ )
+
+ WAIT_STATES = [PENDING, RETRYING]
+ END_STATES = [SUCCESS, FAILED]
+
+ @orm.validates('max_attempts')
+ def validate_max_attempts(self, _, value): # pylint: disable=no-self-use
+ """Validates that max attempts is either -1 or a positive number"""
+ if value < 1 and value != TaskBase.INFINITE_RETRIES:
+ raise ValueError('Max attempts can be either -1 (infinite) or any positive number. '
+ 'Got {value}'.format(value=value))
+ return value
+
+ INFINITE_RETRIES = -1
+
+ status = Column(Enum(*STATES, name='status'), default=PENDING)
+
+ due_at = Column(DateTime, default=datetime.utcnow)
+ started_at = Column(DateTime, default=None)
+ ended_at = Column(DateTime, default=None)
+ max_attempts = Column(Integer, default=1)
+ retry_count = Column(Integer, default=0)
+ retry_interval = Column(Float, default=0)
+ ignore_failure = Column(Boolean, default=False)
+
+ # Operation specific fields
+ implementation = Column(String)
+ inputs = Column(Dict)
+
+ @property
+ def actor(self):
+ """
+ Return the actor of the task
+ :return:
+ """
+ return self.node or self.relationship
+
+ @classmethod
+ def as_node_instance(cls, instance, **kwargs):
+ return cls(node=instance, **kwargs)
+
+ @classmethod
+ def as_relationship_instance(cls, instance, **kwargs):
+ return cls(relationship=instance, **kwargs)
+
+ @staticmethod
+ def abort(message=None):
+ raise TaskAbortException(message)
+
+ @staticmethod
+ def retry(message=None, retry_interval=None):
+ raise TaskRetryException(message, retry_interval=retry_interval)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/82d9be7d/aria/storage/modeling/structure.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/structure.py b/aria/storage/modeling/structure.py
new file mode 100644
index 0000000..86d3365
--- /dev/null
+++ b/aria/storage/modeling/structure.py
@@ -0,0 +1,270 @@
+# 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.
+
+"""
+Aria's storage.structures module
+Path: aria.storage.structures
+
+models module holds aria's models.
+
+classes:
+ * Field - represents a single field.
+ * IterField - represents an iterable field.
+ * PointerField - represents a single pointer field.
+ * IterPointerField - represents an iterable pointers field.
+ * Model - abstract model implementation.
+"""
+
+from sqlalchemy.orm import relationship, backref
+from sqlalchemy.ext import associationproxy
+from sqlalchemy import (
+ Column,
+ ForeignKey,
+ Integer,
+ Text,
+ Table
+)
+
+from aria.parser.modeling.elements import Element
+
+
+# TODO: models should inherit for model_element
+class ModelMixin(Element):
+
+ @classmethod
+ def id_column_name(cls):
+ raise NotImplementedError
+
+ @classmethod
+ def name_column_name(cls):
+ raise NotImplementedError
+
+ @classmethod
+ def _get_cls_by_tablename(cls, tablename):
+ """Return class reference mapped to table.
+
+ :param tablename: String with name of table.
+ :return: Class reference or None.
+ """
+ if tablename in (cls.__name__, cls.__tablename__):
+ return cls
+
+ for table_cls in cls._decl_class_registry.values():
+ if tablename == getattr(table_cls, '__tablename__', None):
+ return table_cls
+
+ @classmethod
+ def foreign_key(cls, table_name, nullable=False):
+ """Return a ForeignKey object with the relevant
+
+ :param table: Unique id column in the parent table
+ :param nullable: Should the column be allowed to remain empty
+ """
+ return Column(Integer,
+ ForeignKey('{tablename}.id'.format(tablename=table_name), ondelete='CASCADE'),
+ nullable=nullable)
+
+ @classmethod
+ def one_to_one_relationship(cls, table_name, backreference=None):
+ return relationship(lambda: cls._get_cls_by_tablename(table_name),
+ backref=backref(backreference or cls.__tablename__, uselist=False))
+
+ @classmethod
+ def many_to_one_relationship(cls,
+ parent_table_name,
+ foreign_key_column=None,
+ backreference=None,
+ backref_kwargs=None,
+ **kwargs):
+ """Return a one-to-many SQL relationship object
+ Meant to be used from inside the *child* object
+
+ :param parent_class: Class of the parent table
+ :param cls: Class of the child table
+ :param foreign_key_column: The column of the foreign key (from the child table)
+ :param backreference: The name to give to the reference to the child (on the parent table)
+ """
+ relationship_kwargs = kwargs
+ if foreign_key_column:
+ relationship_kwargs.setdefault('foreign_keys', getattr(cls, foreign_key_column))
+
+ backref_kwargs = backref_kwargs or {}
+ backref_kwargs.setdefault('lazy', 'dynamic')
+ # The following line make sure that when the *parent* is
+ # deleted, all its connected children are deleted as well
+ backref_kwargs.setdefault('cascade', 'all')
+
+ return relationship(lambda: cls._get_cls_by_tablename(parent_table_name),
+ backref=backref(backreference or cls.__tablename__,
+ **backref_kwargs or {}),
+ **relationship_kwargs)
+
+ @classmethod
+ def one_to_many_relationship(cls, child_table_name, backrefernce=None):
+ return relationship(lambda: cls._get_cls_by_tablename(child_table_name),
+ backref=backrefernce or '{0}s'.format(cls.__tablename__),
+ lazy='dynamic')
+
+ @classmethod
+ def relationship_to_self(cls, local_column):
+
+ remote_side_str = '{cls.__name__}.{remote_column}'.format(
+ cls=cls,
+ remote_column=cls.id_column_name()
+ )
+ primaryjoin_str = '{remote_side_str} == {cls.__name__}.{local_column}'.format(
+ remote_side_str=remote_side_str,
+ cls=cls,
+ local_column=local_column)
+ return relationship(cls._get_cls_by_tablename(cls.__tablename__).__name__,
+ primaryjoin=primaryjoin_str,
+ remote_side=remote_side_str,
+ post_update=True)
+
+ @classmethod
+ def many_to_many_relationship(cls, other_table_name, table_prefix, relationship_kwargs=None):
+ """Return a many-to-many SQL relationship object
+
+ Notes:
+ 1. The backreference name is the current table's table name
+ 2. This method creates a new helper table in the DB
+
+ :param cls: The class of the table we're connecting from
+ :param other_table_name: The class of the table we're connecting to
+ :param table_prefix: Custom prefix for the helper table name and the
+ backreference name
+ """
+ current_table_name = cls.__tablename__
+ current_column_name = '{0}_id'.format(current_table_name)
+ current_foreign_key = '{0}.id'.format(current_table_name)
+
+ other_column_name = '{0}_id'.format(other_table_name)
+ other_foreign_key = '{0}.id'.format(other_table_name)
+
+ helper_table_name = '{0}_{1}'.format(current_table_name, other_table_name)
+
+ backref_name = current_table_name
+ if table_prefix:
+ helper_table_name = '{0}_{1}'.format(table_prefix, helper_table_name)
+ backref_name = '{0}_{1}'.format(table_prefix, backref_name)
+
+ secondary_table = cls.get_secondary_table(
+ cls.metadata,
+ helper_table_name,
+ current_column_name,
+ other_column_name,
+ current_foreign_key,
+ other_foreign_key
+ )
+
+ return relationship(
+ lambda: cls._get_cls_by_tablename(other_table_name),
+ secondary=secondary_table,
+ backref=backref(backref_name),
+ **(relationship_kwargs or {})
+ )
+
+ @staticmethod
+ def get_secondary_table(metadata,
+ helper_table_name,
+ first_column_name,
+ second_column_name,
+ first_foreign_key,
+ second_foreign_key):
+ """Create a helper table for a many-to-many relationship
+
+ :param helper_table_name: The name of the table
+ :param first_column_name: The name of the first column in the table
+ :param second_column_name: The name of the second column in the table
+ :param first_foreign_key: The string representing the first foreign key,
+ for example `blueprint.storage_id`, or `tenants.id`
+ :param second_foreign_key: The string representing the second foreign key
+ :return: A Table object
+ """
+ return Table(
+ helper_table_name,
+ metadata,
+ Column(
+ first_column_name,
+ Integer,
+ ForeignKey(first_foreign_key)
+ ),
+ Column(
+ second_column_name,
+ Integer,
+ ForeignKey(second_foreign_key)
+ )
+ )
+
+ def to_dict(self, fields=None, suppress_error=False):
+ """Return a dict representation of the model
+
+ :param suppress_error: If set to True, sets `None` to attributes that
+ it's unable to retrieve (e.g., if a relationship wasn't established
+ yet, and so it's impossible to access a property through it)
+ """
+ res = dict()
+ fields = fields or self.fields()
+ for field in fields:
+ try:
+ field_value = getattr(self, field)
+ except AttributeError:
+ if suppress_error:
+ field_value = None
+ else:
+ raise
+ if isinstance(field_value, list):
+ field_value = list(field_value)
+ elif isinstance(field_value, dict):
+ field_value = dict(field_value)
+ elif isinstance(field_value, ModelMixin):
+ field_value = field_value.to_dict()
+ res[field] = field_value
+
+ return res
+
+ @classmethod
+ def _association_proxies(cls):
+ for col, value in vars(cls).items():
+ if isinstance(value, associationproxy.AssociationProxy):
+ yield col
+
+ @classmethod
+ def fields(cls):
+ """Return the list of field names for this table
+
+ Mostly for backwards compatibility in the code (that uses `fields`)
+ """
+ fields = set(cls._association_proxies())
+ fields.update(cls.__table__.columns.keys())
+ return fields - set(getattr(cls, '_private_fields', []))
+
+ def __repr__(self):
+ return '<{__class__.__name__} id=`{id}`>'.format(
+ __class__=self.__class__,
+ id=getattr(self, self.name_column_name()))
+
+
+class ModelIDMixin(object):
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ name = Column(Text, nullable=True, index=True)
+
+ @classmethod
+ def id_column_name(cls):
+ return 'id'
+
+ @classmethod
+ def name_column_name(cls):
+ return 'name'