You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by em...@apache.org on 2017/04/05 15:58:21 UTC

[1/6] incubator-ariatosca git commit: ARIA-86-Create-a-basic-Hello-World-blueprint-example [Forced Update!]

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-134-populate-workflows 5edbf938d -> 3a56f122b (forced update)


ARIA-86-Create-a-basic-Hello-World-blueprint-example


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/16ae46a6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/16ae46a6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/16ae46a6

Branch: refs/heads/ARIA-134-populate-workflows
Commit: 16ae46a61b01acd2b654acc301e40cc29c683e9a
Parents: 4400e30
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Mar 30 17:29:17 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Thu Mar 30 17:59:55 2017 +0300

----------------------------------------------------------------------
 examples/hello-world/helloworld.yaml      |  27 +++++++++++++
 examples/hello-world/images/aria-logo.png | Bin 0 -> 23601 bytes
 examples/hello-world/index.html           |  14 +++++++
 examples/hello-world/scripts/configure.sh |  23 +++++++++++
 examples/hello-world/scripts/start.sh     |  52 +++++++++++++++++++++++++
 examples/hello-world/scripts/stop.sh      |  15 +++++++
 6 files changed, 131 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/16ae46a6/examples/hello-world/helloworld.yaml
----------------------------------------------------------------------
diff --git a/examples/hello-world/helloworld.yaml b/examples/hello-world/helloworld.yaml
new file mode 100644
index 0000000..b6efaca
--- /dev/null
+++ b/examples/hello-world/helloworld.yaml
@@ -0,0 +1,27 @@
+tosca_definitions_version: tosca_simple_profile_for_nfv_1_0
+
+node_types:
+  web_app:
+    derived_from: tosca.nodes.WebApplication
+    properties:
+      port:
+        type: integer
+        default: 8080
+
+topology_template:
+
+  node_templates:
+    web_server:
+      type: tosca.nodes.WebServer
+
+    web_app:
+      type: web_app
+      properties:
+        port: 9090
+      requirements:
+        - host: web_server
+      interfaces:
+        Standard:
+          configure: scripts/configure.sh
+          start: scripts/start.sh
+          stop: scripts/stop.sh

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/16ae46a6/examples/hello-world/images/aria-logo.png
----------------------------------------------------------------------
diff --git a/examples/hello-world/images/aria-logo.png b/examples/hello-world/images/aria-logo.png
new file mode 100644
index 0000000..3505844
Binary files /dev/null and b/examples/hello-world/images/aria-logo.png differ

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/16ae46a6/examples/hello-world/index.html
----------------------------------------------------------------------
diff --git a/examples/hello-world/index.html b/examples/hello-world/index.html
new file mode 100644
index 0000000..8d21c3a
--- /dev/null
+++ b/examples/hello-world/index.html
@@ -0,0 +1,14 @@
+<html>
+    <header>
+        <title>ARIA Hello World</title>
+    </header>
+<body>
+    <h1>Hello, World!</h1>
+    <p>
+        blueprint_id = {{ ctx.service_template.name }}<br/>
+        deployment_id = {{ ctx.service.name }}<br/>
+        node_id = {{ ctx.node.name }}
+    </p>
+    <img src="aria-logo.png">
+</body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/16ae46a6/examples/hello-world/scripts/configure.sh
----------------------------------------------------------------------
diff --git a/examples/hello-world/scripts/configure.sh b/examples/hello-world/scripts/configure.sh
new file mode 100755
index 0000000..b55ec17
--- /dev/null
+++ b/examples/hello-world/scripts/configure.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+set -e
+
+TEMP_DIR="/tmp"
+PYTHON_FILE_SERVER_ROOT=${TEMP_DIR}/python-simple-http-webserver
+if [ -d ${PYTHON_FILE_SERVER_ROOT} ]; then
+	echo "Removing file server root folder ${PYTHON_FILE_SERVER_ROOT}"
+	rm -rf ${PYTHON_FILE_SERVER_ROOT}
+fi
+ctx logger info "Creating HTTP server root directory at ${PYTHON_FILE_SERVER_ROOT}"
+
+mkdir -p ${PYTHON_FILE_SERVER_ROOT}
+
+cd ${PYTHON_FILE_SERVER_ROOT}
+
+index_path="index.html"
+image_path="images/aria-logo.png"
+
+ctx logger info "Downloading blueprint resources..."
+ctx download-resource-and-render ${PYTHON_FILE_SERVER_ROOT}/index.html ${index_path}
+ctx download-resource ${PYTHON_FILE_SERVER_ROOT}/aria-logo.png ${image_path}
+

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/16ae46a6/examples/hello-world/scripts/start.sh
----------------------------------------------------------------------
diff --git a/examples/hello-world/scripts/start.sh b/examples/hello-world/scripts/start.sh
new file mode 100755
index 0000000..96298c5
--- /dev/null
+++ b/examples/hello-world/scripts/start.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+set -e
+
+TEMP_DIR="/tmp"
+PYTHON_FILE_SERVER_ROOT=${TEMP_DIR}/python-simple-http-webserver
+PID_FILE="server.pid"
+
+ctx logger info "Starting HTTP server from ${PYTHON_FILE_SERVER_ROOT}"
+
+port=$(ctx node properties port)
+
+cd ${PYTHON_FILE_SERVER_ROOT}
+ctx logger info "Starting SimpleHTTPServer"
+nohup python -m SimpleHTTPServer ${port} > /dev/null 2>&1 &
+echo $! > ${PID_FILE}
+
+ctx logger info "Waiting for server to launch on port ${port}"
+url="http://localhost:${port}"
+
+server_is_up() {
+	if which wget >/dev/null; then
+		if wget $url >/dev/null; then
+			return 0
+		fi
+	elif which curl >/dev/null; then
+		if curl $url >/dev/null; then
+			return 0
+		fi
+	else
+		ctx logger error "Both curl, wget were not found in path"
+		exit 1
+	fi
+	return 1
+}
+
+STARTED=false
+for i in $(seq 1 15)
+do
+	if server_is_up; then
+		ctx logger info "Server is up."
+		STARTED=true
+    	break
+	else
+		ctx logger info "Server not up. waiting 1 second."
+		sleep 1
+	fi
+done
+if [ ${STARTED} = false ]; then
+	ctx logger error "Failed starting web server in 15 seconds."
+	exit 1
+fi

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/16ae46a6/examples/hello-world/scripts/stop.sh
----------------------------------------------------------------------
diff --git a/examples/hello-world/scripts/stop.sh b/examples/hello-world/scripts/stop.sh
new file mode 100755
index 0000000..5461caf
--- /dev/null
+++ b/examples/hello-world/scripts/stop.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+set -e
+
+TEMP_DIR="/tmp"
+PYTHON_FILE_SERVER_ROOT=${TEMP_DIR}/python-simple-http-webserver
+PID_FILE="server.pid"
+
+PID=`cat ${PYTHON_FILE_SERVER_ROOT}/${PID_FILE}`
+
+ctx logger info "Shutting down file server. pid = ${PID}"
+kill -9 ${PID} || exit $?
+
+ctx logger info "Deleting file server root directory (${PYTHON_FILE_SERVER_ROOT})"
+rm -rf ${PYTHON_FILE_SERVER_ROOT}


[2/6] incubator-ariatosca git commit: ARIA-125-Filtering-returns-the-wrong-models

Posted by em...@apache.org.
ARIA-125-Filtering-returns-the-wrong-models


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/2d834753
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/2d834753
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/2d834753

Branch: refs/heads/ARIA-134-populate-workflows
Commit: 2d834753a03564d1cd1f413268b5d769d3144845
Parents: 16ae46a
Author: max-orlov <ma...@gigaspaces.com>
Authored: Sun Apr 2 14:53:46 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Sun Apr 2 15:35:13 2017 +0300

----------------------------------------------------------------------
 aria/storage/sql_mapi.py             |  50 +++--------
 tests/mock/models.py                 |  13 +--
 tests/mock/topology.py               |  15 ++--
 tests/modeling/test_model_storage.py | 102 ----------------------
 tests/modeling/test_models.py        |  12 +--
 tests/storage/test_model_storage.py  | 139 ++++++++++++++++++++++++++++++
 6 files changed, 169 insertions(+), 162 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2d834753/aria/storage/sql_mapi.py
----------------------------------------------------------------------
diff --git a/aria/storage/sql_mapi.py b/aria/storage/sql_mapi.py
index 8bbec54..59e1896 100644
--- a/aria/storage/sql_mapi.py
+++ b/aria/storage/sql_mapi.py
@@ -187,55 +187,31 @@ class SQLAlchemyModelAPI(api.ModelAPI):
             # If all columns should be returned, query directly from the model
             query = self._session.query(self.model_cls)
 
-        if not self._skip_joining(joins, include):
-            for join_table in joins:
-                query = query.join(join_table)
-
+        query = query.join(*joins)
         return query
 
     @staticmethod
     def _get_joins(model_class, columns):
         """Get a list of all the tables on which we need to join
 
-        :param columns: A set of all columns involved in the query
+        :param columns: A set of all attributes involved in the query
         """
-        joins = []  # Using a list instead of a set because order is important
+
+        # Using a list instead of a set because order is important
+        joins = OrderedDict()
         for column_name in columns:
             column = getattr(model_class, column_name)
             while not column.is_attribute:
+                join_attr = column.local_attr
+                # This is a hack, to deal with the fact that SQLA doesn't
+                # fully support doing something like: `if join_attr in joins`,
+                # because some SQLA elements have their own comparators
+                join_attr_name = str(join_attr)
+                if join_attr_name not in joins:
+                    joins[join_attr_name] = join_attr
                 column = column.remote_attr
-                if column.is_attribute:
-                    join_class = column.class_
-                else:
-                    join_class = column.local_attr.class_
-
-                # Don't add the same class more than once
-                if join_class not in joins:
-                    joins.append(join_class)
-        return joins
-
-    @staticmethod
-    def _skip_joining(joins, include):
-        """Dealing with an edge case where the only included column comes from
-        an other table. In this case, we mustn't join on the same table again
 
-        :param joins: A list of tables on which we're trying to join
-        :param include: The list of
-        :return: True if we need to skip joining
-        """
-        if not joins:
-            return True
-        join_table_names = [t.__tablename__ for t in joins]
-
-        if len(include) != 1:
-            return False
-
-        column = include[0]
-        if column.is_clause_element:
-            table_name = column.element.table.name
-        else:
-            table_name = column.class_.__tablename__
-        return table_name in join_table_names
+        return joins.values()
 
     @staticmethod
     def _sort_query(query, sort=None):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2d834753/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 457e7cb..1d29e2d 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -50,10 +50,10 @@ DEPENDENT_NODE_TEMPLATE_NAME = 'dependent_node_template'
 DEPENDENT_NODE_NAME = 'dependent_node'
 
 
-def create_service_template():
+def create_service_template(name=SERVICE_TEMPLATE_NAME):
     now = datetime.now()
     return models.ServiceTemplate(
-        name=SERVICE_TEMPLATE_NAME,
+        name=name,
         description=None,
         created_at=now,
         updated_at=now,
@@ -68,10 +68,10 @@ def create_service_template():
     )
 
 
-def create_service(service_template):
+def create_service(service_template, name=SERVICE_NAME):
     now = datetime.utcnow()
     return models.Service(
-        name=SERVICE_NAME,
+        name=name,
         service_template=service_template,
         description='',
         created_at=now,
@@ -81,7 +81,7 @@ def create_service(service_template):
     )
 
 
-def create_dependency_node_template(name, service_template):
+def create_dependency_node_template(service_template, name=DEPENDENCY_NODE_TEMPLATE_NAME):
     node_type = service_template.node_types.get_descendant('test_node_type')
     capability_type = service_template.capability_types.get_descendant('test_capability_type')
 
@@ -103,7 +103,8 @@ def create_dependency_node_template(name, service_template):
     return node_template
 
 
-def create_dependent_node_template(name, service_template, dependency_node_template):
+def create_dependent_node_template(
+        service_template, dependency_node_template, name=DEPENDENT_NODE_TEMPLATE_NAME):
     the_type = service_template.node_types.get_descendant('test_node_type')
 
     requirement_template = models.RequirementTemplate(

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2d834753/tests/mock/topology.py
----------------------------------------------------------------------
diff --git a/tests/mock/topology.py b/tests/mock/topology.py
index edf6b7d..e5b4e01 100644
--- a/tests/mock/topology.py
+++ b/tests/mock/topology.py
@@ -22,8 +22,7 @@ def create_simple_topology_single_node(model_storage, create_operation):
     service_template = models.create_service_template()
     service = models.create_service(service_template)
 
-    node_template = models.create_dependency_node_template(
-        models.DEPENDENCY_NODE_TEMPLATE_NAME, service_template)
+    node_template = models.create_dependency_node_template(service_template)
     interface_template = models.create_interface_template(
         service_template,
         'Standard', 'create',
@@ -55,10 +54,9 @@ def create_simple_topology_two_nodes(model_storage):
 
     # Creating a simple service with node -> node as a graph
 
-    dependency_node_template = models.create_dependency_node_template(
-        models.DEPENDENCY_NODE_TEMPLATE_NAME, service_template)
-    dependent_node_template = models.create_dependent_node_template(
-        models.DEPENDENT_NODE_TEMPLATE_NAME, service_template, dependency_node_template)
+    dependency_node_template = models.create_dependency_node_template(service_template)
+    dependent_node_template = models.create_dependent_node_template(service_template,
+                                                                    dependency_node_template)
 
     dependency_node = models.create_node(
         models.DEPENDENCY_NODE_NAME, dependency_node_template, service)
@@ -87,9 +85,8 @@ def create_simple_topology_three_nodes(model_storage):
     service_id = create_simple_topology_two_nodes(model_storage)
     service = model_storage.service.get(service_id)
     third_node_template = models.create_dependency_node_template(
-        'another_dependency_node_template', service.service_template)
-    third_node = models.create_node(
-        'another_dependency_node', third_node_template, service)
+        service.service_template, name='another_dependency_node_template')
+    third_node = models.create_node('another_dependency_node', third_node_template, service)
     new_relationship = models.create_relationship(
         source=model_storage.node.get_by_name(models.DEPENDENT_NODE_NAME),
         target=third_node,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2d834753/tests/modeling/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/modeling/test_model_storage.py b/tests/modeling/test_model_storage.py
deleted file mode 100644
index bb778d4..0000000
--- a/tests/modeling/test_model_storage.py
+++ /dev/null
@@ -1,102 +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.storage import (
-    ModelStorage,
-    exceptions,
-    sql_mapi
-)
-from aria import (application_model_storage, modeling)
-from ..storage import (release_sqlite_storage, init_inmemory_model_storage)
-
-from . import MockModel
-
-
-@pytest.fixture
-def storage():
-    base_storage = ModelStorage(sql_mapi.SQLAlchemyModelAPI,
-                                initiator=init_inmemory_model_storage)
-    base_storage.register(MockModel)
-    yield base_storage
-    release_sqlite_storage(base_storage)
-
-
-@pytest.fixture(scope='module', autouse=True)
-def module_cleanup():
-    modeling.models.aria_declarative_base.metadata.remove(MockModel.__table__)  #pylint: disable=no-member
-
-
-def test_storage_base(storage):
-    with pytest.raises(AttributeError):
-        storage.non_existent_attribute()
-
-
-def test_model_storage(storage):
-    mock_model = MockModel(value=0, name='model_name')
-    storage.mock_model.put(mock_model)
-
-    assert storage.mock_model.get_by_name('model_name') == mock_model
-
-    assert [mm_from_storage for mm_from_storage in storage.mock_model.iter()] == [mock_model]
-    assert [mm_from_storage for mm_from_storage in storage.mock_model] == [mock_model]
-
-    storage.mock_model.delete(mock_model)
-    with pytest.raises(exceptions.StorageError):
-        storage.mock_model.get(mock_model.id)
-
-
-def test_application_storage_factory():
-    storage = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
-                                        initiator=init_inmemory_model_storage)
-
-    assert storage.service_template
-    assert storage.node_template
-    assert storage.group_template
-    assert storage.policy_template
-    assert storage.substitution_template
-    assert storage.substitution_template_mapping
-    assert storage.requirement_template
-    assert storage.relationship_template
-    assert storage.capability_template
-    assert storage.interface_template
-    assert storage.operation_template
-    assert storage.artifact_template
-
-    assert storage.service
-    assert storage.node
-    assert storage.group
-    assert storage.policy
-    assert storage.substitution
-    assert storage.substitution_mapping
-    assert storage.relationship
-    assert storage.capability
-    assert storage.interface
-    assert storage.operation
-    assert storage.artifact
-
-    assert storage.execution
-    assert storage.service_update
-    assert storage.service_update_step
-    assert storage.service_modification
-    assert storage.plugin
-    assert storage.task
-
-    assert storage.parameter
-    assert storage.type
-    assert storage.metadata
-
-    release_sqlite_storage(storage)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2d834753/tests/modeling/test_models.py
----------------------------------------------------------------------
diff --git a/tests/modeling/test_models.py b/tests/modeling/test_models.py
index 35ae09f..8cd00f8 100644
--- a/tests/modeling/test_models.py
+++ b/tests/modeling/test_models.py
@@ -89,10 +89,8 @@ def _service_update_storage():
 def _node_template_storage():
     storage = _service_storage()
     service_template = storage.service_template.list()[0]
-    dependency_node_template = mock.models.create_dependency_node_template(
-        mock.models.DEPENDENCY_NODE_TEMPLATE_NAME, service_template)
-    mock.models.create_dependent_node_template(
-        mock.models.DEPENDENCY_NODE_NAME, service_template, dependency_node_template)
+    dependency_node_template = mock.models.create_dependency_node_template(service_template)
+    mock.models.create_dependent_node_template(service_template, dependency_node_template)
     storage.service_template.update(service_template)
     return storage
 
@@ -104,10 +102,8 @@ def _nodes_storage():
         mock.models.DEPENDENCY_NODE_TEMPLATE_NAME)
     mock.models.create_node(mock.models.DEPENDENCY_NODE_NAME, dependency_node_template, service)
 
-    dependent_node_template = \
-        mock.models.create_dependent_node_template(mock.models.DEPENDENT_NODE_TEMPLATE_NAME,
-                                                   service.service_template,
-                                                   dependency_node_template)
+    dependent_node_template = mock.models.create_dependent_node_template(service.service_template,
+                                                                         dependency_node_template)
 
     mock.models.create_node(mock.models.DEPENDENT_NODE_NAME, dependent_node_template, service)
     storage.service.update(service)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2d834753/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
new file mode 100644
index 0000000..fa57e6f
--- /dev/null
+++ b/tests/storage/test_model_storage.py
@@ -0,0 +1,139 @@
+# 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 import (
+    application_model_storage,
+    modeling
+)
+from aria.storage import (
+    ModelStorage,
+    exceptions,
+    sql_mapi,
+)
+
+from tests import (
+    mock,
+    storage as tests_storage,
+    modeling as tests_modeling
+)
+
+
+@pytest.fixture
+def storage():
+    base_storage = ModelStorage(sql_mapi.SQLAlchemyModelAPI,
+                                initiator=tests_storage.init_inmemory_model_storage)
+    base_storage.register(tests_modeling.MockModel)
+    yield base_storage
+    tests_storage.release_sqlite_storage(base_storage)
+
+
+@pytest.fixture(scope='module', autouse=True)
+def module_cleanup():
+    modeling.models.aria_declarative_base.metadata.remove(tests_modeling.MockModel.__table__)  #pylint: disable=no-member
+
+
+def test_storage_base(storage):
+    with pytest.raises(AttributeError):
+        storage.non_existent_attribute()
+
+
+def test_model_storage(storage):
+    mock_model = tests_modeling.MockModel(value=0, name='model_name')
+    storage.mock_model.put(mock_model)
+
+    assert storage.mock_model.get_by_name('model_name') == mock_model
+
+    assert [mm_from_storage for mm_from_storage in storage.mock_model.iter()] == [mock_model]
+    assert [mm_from_storage for mm_from_storage in storage.mock_model] == [mock_model]
+
+    storage.mock_model.delete(mock_model)
+    with pytest.raises(exceptions.StorageError):
+        storage.mock_model.get(mock_model.id)
+
+
+def test_application_storage_factory():
+    storage = application_model_storage(sql_mapi.SQLAlchemyModelAPI,
+                                        initiator=tests_storage.init_inmemory_model_storage)
+
+    assert storage.service_template
+    assert storage.node_template
+    assert storage.group_template
+    assert storage.policy_template
+    assert storage.substitution_template
+    assert storage.substitution_template_mapping
+    assert storage.requirement_template
+    assert storage.relationship_template
+    assert storage.capability_template
+    assert storage.interface_template
+    assert storage.operation_template
+    assert storage.artifact_template
+
+    assert storage.service
+    assert storage.node
+    assert storage.group
+    assert storage.policy
+    assert storage.substitution
+    assert storage.substitution_mapping
+    assert storage.relationship
+    assert storage.capability
+    assert storage.interface
+    assert storage.operation
+    assert storage.artifact
+
+    assert storage.execution
+    assert storage.service_update
+    assert storage.service_update_step
+    assert storage.service_modification
+    assert storage.plugin
+    assert storage.task
+
+    assert storage.parameter
+    assert storage.type
+    assert storage.metadata
+
+    tests_storage.release_sqlite_storage(storage)
+
+
+@pytest.fixture
+def context(tmpdir):
+    result = mock.context.simple(str(tmpdir))
+    yield result
+    tests_storage.release_sqlite_storage(result.model)
+
+
+def test_mapi_include(context):
+    service1 = context.model.service.list()[0]
+    service1.name = 'service1'
+    service1.service_template.name = 'service_template1'
+    context.model.service.update(service1)
+
+    service_template2 = mock.models.create_service_template('service_template2')
+    service2 = mock.models.create_service(service_template2, 'service2')
+    context.model.service.put(service2)
+
+    assert service1 != service2
+    assert service1.service_template != service2.service_template
+
+    def assert_include(service):
+        st_name = context.model.service.get(service.id, include=('service_template_name',))
+        st_name_list = context.model.service.list(filters={'id': service.id},
+                                                  include=('service_template_name', ))
+        assert len(st_name) == len(st_name_list) == 1
+        assert st_name[0] == st_name_list[0][0] == service.service_template.name
+
+    assert_include(service1)
+    assert_include(service2)


[3/6] incubator-ariatosca git commit: ARIA-136-ctx-binary-doesnt-get-installed-via-pip-install

Posted by em...@apache.org.
ARIA-136-ctx-binary-doesnt-get-installed-via-pip-install


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/369323b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/369323b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/369323b6

Branch: refs/heads/ARIA-134-populate-workflows
Commit: 369323b66cdd02ccfba6cc3e3c547ac4694fc2fd
Parents: 2d83475
Author: max-orlov <ma...@gigaspaces.com>
Authored: Sun Apr 2 19:24:20 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Tue Apr 4 11:48:08 2017 +0300

----------------------------------------------------------------------
 setup.py | 47 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 36 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/369323b6/setup.py
----------------------------------------------------------------------
diff --git a/setup.py b/setup.py
index 7be5275..3d72ebc 100644
--- a/setup.py
+++ b/setup.py
@@ -19,6 +19,7 @@ import sys
 
 from setuptools import setup, find_packages
 from setuptools.command.install import install
+from setuptools.command.develop import develop
 
 _PACKAGE_NAME = 'aria'
 _PYTHON_SUPPORTED_VERSIONS = [(2, 6), (2, 7)]
@@ -63,20 +64,43 @@ except IOError:
 console_scripts = ['aria = aria.cli.cli:main']
 
 
-class InstallCommand(install):
-    user_options = install.user_options + [
+def _generate_user_options(command):
+    return command.user_options + [
         ('skip-ctx', None, 'Install with or without the ctx (Defaults to False)')
     ]
-    boolean_options = install.boolean_options + ['skip-ctx']
 
-    def initialize_options(self):
-        install.initialize_options(self)
-        self.skip_ctx = False
 
-    def run(self):
-        if self.skip_ctx is False:
-            console_scripts.append('ctx = aria.orchestrator.execution_plugin.ctx_proxy.client:main')
-        install.run(self)
+def _generate_boolean_options(command):
+    return command.boolean_options + ['skip-ctx']
+
+
+def _initialize_options(custom_cmd):
+    custom_cmd.command.initialize_options(custom_cmd)
+    custom_cmd.skip_ctx = False
+
+
+def _run(custom_cmd):
+    if custom_cmd.skip_ctx is False:
+        console_scripts.append('ctx = aria.orchestrator.execution_plugin.ctx_proxy.client:main')
+    custom_cmd.command.run(custom_cmd)
+
+
+class InstallCommand(install):
+    command = install
+
+    user_options = _generate_user_options(install)
+    boolean_options = _generate_boolean_options(install)
+    initialize_options = _initialize_options
+    run = _run
+
+
+class DevelopCommand(develop):
+    command = develop
+
+    user_options = _generate_user_options(develop)
+    boolean_options = _generate_boolean_options(develop)
+    initialize_options = _initialize_options
+    run = _run
 
 setup(
     name=_PACKAGE_NAME,
@@ -116,6 +140,7 @@ setup(
         'console_scripts': console_scripts
     },
     cmdclass={
-        'install': InstallCommand
+        'install': InstallCommand,      # used in pip install ...
+        'develop': DevelopCommand       # used in pip install -e ...
     }
 )


[5/6] incubator-ariatosca git commit: ARIA-137-Support-for-predicate-based-queries-in-the-SQL-mapi

Posted by em...@apache.org.
ARIA-137-Support-for-predicate-based-queries-in-the-SQL-mapi


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/422574e0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/422574e0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/422574e0

Branch: refs/heads/ARIA-134-populate-workflows
Commit: 422574e03174e5dff57888af2519ed62048ce3fa
Parents: e7ffc73
Author: max-orlov <ma...@gigaspaces.com>
Authored: Tue Apr 4 20:41:59 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Wed Apr 5 16:02:04 2017 +0300

----------------------------------------------------------------------
 aria/storage/sql_mapi.py            | 28 +++++++++++++++-
 tests/storage/test_model_storage.py | 57 ++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/422574e0/aria/storage/sql_mapi.py
----------------------------------------------------------------------
diff --git a/aria/storage/sql_mapi.py b/aria/storage/sql_mapi.py
index 59e1896..8d34bb4 100644
--- a/aria/storage/sql_mapi.py
+++ b/aria/storage/sql_mapi.py
@@ -31,6 +31,13 @@ from . import (
     exceptions,
 )
 
+_predicates = {'ge': '__ge__',
+               'gt': '__gt__',
+               'lt': '__lt__',
+               'le': '__le__',
+               'eq': '__eq__',
+               'ne': '__ne__'}
+
 
 class SQLAlchemyModelAPI(api.ModelAPI):
     """
@@ -243,7 +250,10 @@ class SQLAlchemyModelAPI(api.ModelAPI):
     @staticmethod
     def _add_value_filter(query, filters):
         for column, value in filters.items():
-            if isinstance(value, (list, tuple)):
+            if isinstance(value, dict):
+                for predicate, operand in value.items():
+                    query = query.filter(getattr(column, predicate)(operand))
+            elif isinstance(value, (list, tuple)):
                 query = query.filter(column.in_(value))
             else:
                 query = query.filter(column == value)
@@ -269,12 +279,28 @@ class SQLAlchemyModelAPI(api.ModelAPI):
         include, filters, sort, joins = self._get_joins_and_converted_columns(
             include, filters, sort
         )
+        filters = self._convert_operands(filters)
 
         query = self._get_base_query(include, joins)
         query = self._filter_query(query, filters)
         query = self._sort_query(query, sort)
         return query
 
+    @staticmethod
+    def _convert_operands(filters):
+        for column, conditions in filters.items():
+            if isinstance(conditions, dict):
+                for predicate, operand in conditions.items():
+                    if predicate not in _predicates:
+                        raise exceptions.StorageError(
+                            "{0} is not a valid predicate for filtering. Valid predicates are {1}"
+                            .format(predicate, ', '.join(_predicates.keys())))
+                    del filters[column][predicate]
+                    filters[column][_predicates[predicate]] = operand
+
+
+        return filters
+
     def _get_joins_and_converted_columns(self,
                                          include,
                                          filters,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/422574e0/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index e4f3eba..4dabfaf 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -15,6 +15,12 @@
 
 import pytest
 
+from sqlalchemy import (
+    Column,
+    Integer,
+    Text
+)
+
 from aria import (
     application_model_storage,
     modeling
@@ -150,3 +156,54 @@ def test_mapi_include(context):
 
     assert_include(service1)
     assert_include(service2)
+
+
+class MockModel(modeling.models.aria_declarative_base, modeling.mixins.ModelMixin): #pylint: disable=abstract-method
+    __tablename__ = 'op_mock_model'
+
+    name = Column(Text)
+    value = Column(Integer)
+
+
+class TestFilterOperands(object):
+
+    @pytest.fixture()
+    def storage(self):
+        model_storage = application_model_storage(
+            sql_mapi.SQLAlchemyModelAPI, initiator=tests_storage.init_inmemory_model_storage)
+        model_storage.register(MockModel)
+        for value in (1, 2, 3, 4):
+            model_storage.op_mock_model.put(MockModel(value=value))
+        yield model_storage
+        tests_storage.release_sqlite_storage(model_storage)
+
+    def test_gt(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(gt=3)))) == 1
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(gt=4)))) == 0
+
+    def test_ge(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(ge=3)))) == 2
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(ge=5)))) == 0
+
+    def test_lt(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(lt=2)))) == 1
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(lt=1)))) == 0
+
+    def test_le(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(le=2)))) == 2
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(le=0)))) == 0
+
+    def test_eq(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(eq=2)))) == 1
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(eq=0)))) == 0
+
+    def test_neq(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(ne=2)))) == 3
+
+    def test_gt_and_lt(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(gt=1, lt=3)))) == 1
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(gt=2, lt=2)))) == 0
+
+    def test_eq_and_ne(self, storage):
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(eq=1, ne=3)))) == 1
+        assert len(storage.op_mock_model.list(filters=dict(value=dict(eq=1, ne=1)))) == 0


[4/6] incubator-ariatosca git commit: ARIA-132-fixed-support-for-cascading-deletion

Posted by em...@apache.org.
ARIA-132-fixed-support-for-cascading-deletion


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e7ffc735
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e7ffc735
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e7ffc735

Branch: refs/heads/ARIA-134-populate-workflows
Commit: e7ffc7353dd2f23fdffde22bdb2ffac20542d601
Parents: 369323b
Author: max-orlov <ma...@gigaspaces.com>
Authored: Tue Apr 4 12:22:12 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Tue Apr 4 12:22:12 2017 +0300

----------------------------------------------------------------------
 aria/modeling/relationship.py       |  3 ++-
 tests/storage/test_model_storage.py | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e7ffc735/aria/modeling/relationship.py
----------------------------------------------------------------------
diff --git a/aria/modeling/relationship.py b/aria/modeling/relationship.py
index ac1de28..e6830b8 100644
--- a/aria/modeling/relationship.py
+++ b/aria/modeling/relationship.py
@@ -193,7 +193,8 @@ def one_to_many(model_class,
         child_table,
         back_populates=back_populates,
         other_fk=child_fk,
-        dict_key=dict_key)
+        dict_key=dict_key,
+        relationship_kwargs=dict(cascade='all'))
 
 
 def many_to_one(model_class,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e7ffc735/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index fa57e6f..e4f3eba 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -108,6 +108,19 @@ def test_application_storage_factory():
     tests_storage.release_sqlite_storage(storage)
 
 
+def test_cascade_deletion(context):
+    service = context.model.service.list()[0]
+
+    assert len(context.model.service_template.list()) == 1
+    assert len(service.nodes) == len(context.model.node.list()) == 2
+
+    context.model.service.delete(service)
+
+    assert len(context.model.service_template.list()) == 1
+    assert len(context.model.service.list()) == 0
+    assert len(context.model.node.list()) == 0
+
+
 @pytest.fixture
 def context(tmpdir):
     result = mock.context.simple(str(tmpdir))


[6/6] incubator-ariatosca git commit: ARIA-134 Parser populates service workflows

Posted by em...@apache.org.
ARIA-134 Parser populates service workflows


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/3a56f122
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/3a56f122
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/3a56f122

Branch: refs/heads/ARIA-134-populate-workflows
Commit: 3a56f122b9adc591a790d76d38edef269b503fc8
Parents: 422574e
Author: Tal Liron <ta...@gmail.com>
Authored: Fri Mar 31 14:34:41 2017 -0500
Committer: Tal Liron <ta...@gmail.com>
Committed: Wed Apr 5 10:58:06 2017 -0500

----------------------------------------------------------------------
 aria/cli/dry.py                                 |  2 +-
 aria/modeling/service_instance.py               | 10 ++-----
 .../simple_v1_0/modeling/__init__.py            | 30 +++++++++++++++++++-
 3 files changed, 33 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a56f122/aria/cli/dry.py
----------------------------------------------------------------------
diff --git a/aria/cli/dry.py b/aria/cli/dry.py
index 82faf42..098638f 100644
--- a/aria/cli/dry.py
+++ b/aria/cli/dry.py
@@ -31,7 +31,7 @@ def convert_to_dry(service):
     interfaces) to run dryly.
     """
 
-    for workflow in service.workflows:
+    for workflow in service.workflows.itervalues():
         convert_operation_to_dry(workflow)
 
     for node in service.nodes.itervalues():

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a56f122/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index e6c2b12..d15aa7e 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -121,6 +121,7 @@ class ServiceBase(InstanceModelMixin):
     # endregion
 
     # region one_to_many relationships
+
     @declared_attr
     def updates(cls):
         return relationship.one_to_many(cls, 'service_update')
@@ -134,10 +135,6 @@ class ServiceBase(InstanceModelMixin):
         return relationship.one_to_many(cls, 'execution')
 
     @declared_attr
-    def operations(cls):
-        return relationship.one_to_many(cls, 'operation')
-
-    @declared_attr
     def nodes(cls):
         return relationship.one_to_many(cls, 'node', dict_key='name')
 
@@ -164,6 +161,7 @@ class ServiceBase(InstanceModelMixin):
     # endregion
 
     # region many_to_many relationships
+
     @declared_attr
     def meta_data(cls):
         # Warning! We cannot use the attr name "metadata" because it's used by SQLAlchemy!
@@ -1666,7 +1664,7 @@ class OperationBase(InstanceModelMixin):
 
     @declared_attr
     def service(cls):
-        return relationship.many_to_one(cls, 'service')
+        return relationship.many_to_one(cls, 'service', back_populates='workflows')
 
     @declared_attr
     def interface(cls):
@@ -1693,8 +1691,6 @@ class OperationBase(InstanceModelMixin):
     max_retries = Column(Integer)
     retry_interval = Column(Integer)
 
-
-
     @property
     def as_raw(self):
         return collections.OrderedDict((

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a56f122/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
index d0a39e6..267f6de 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/__init__.py
@@ -85,9 +85,14 @@ def create_service_template_model(context): # pylint: disable=too-many-locals,to
     policies = context.presentation.get('service_template', 'topology_template', 'policies')
     if policies:
         for policy in policies.itervalues():
-            if model.policy_types.get_descendant(policy.type).role == 'plugin':
+            role = model.policy_types.get_descendant(policy.type).role
+            if role == 'plugin':
                 plugin_specification = create_plugin_specification_model(context, policy)
                 model.plugin_specifications[plugin_specification.name] = plugin_specification
+            elif role == 'workflow':
+                operation_template = create_workflow_operation_template_model(context,
+                                                                              model, policy)
+                model.workflow_templates[operation_template.name] = operation_template
 
     # Node templates
     node_templates = context.presentation.get('service_template', 'topology_template',
@@ -446,6 +451,29 @@ def create_plugin_specification_model(context, policy):
     return model
 
 
+def create_workflow_operation_template_model(context, service_template, policy):
+    model = OperationTemplate(name=policy._name,
+                              service_template=service_template)
+
+    if policy.description:
+        model.description = policy.description.value
+
+    properties = policy._get_property_values(context)
+    for prop_name, prop in properties.iteritems():
+        if prop_name == 'implementation':
+            model.plugin_specification, model.implementation = \
+                parse_implementation_string(context, service_template, prop.value)
+        elif prop_name == 'dependencies':
+            model.dependencies = prop.value
+        else:
+            model.inputs[prop_name] = Parameter(name=prop_name,
+                                                type_name=prop.type,
+                                                value=prop.value,
+                                                description=prop.description)
+
+    return model
+
+
 #
 # Utils
 #