You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by ra...@apache.org on 2017/03/29 15:26:48 UTC
incubator-ariatosca git commit: used stubtask for empty
implementations, fixes to resource storage usage
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-48-aria-cli 47fc1eaa3 -> 46c70a43f
used stubtask for empty implementations, fixes to resource storage usage
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/46c70a43
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/46c70a43
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/46c70a43
Branch: refs/heads/ARIA-48-aria-cli
Commit: 46c70a43fd65a9ccb00d907ee294fd61a1e88b04
Parents: 47fc1ea
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Wed Mar 29 18:26:44 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Wed Mar 29 18:26:44 2017 +0300
----------------------------------------------------------------------
aria/core.py | 4 +-
aria/orchestrator/context/common.py | 16 ++--
aria/orchestrator/workflows/api/task.py | 19 +----
.../workflows/builtin/execute_operation.py | 3 +-
aria/orchestrator/workflows/builtin/utils.py | 86 +++++++++++++-------
.../context/test_resource_render.py | 4 +-
tests/orchestrator/context/test_serialize.py | 4 +-
.../orchestrator/execution_plugin/test_local.py | 2 +-
tests/orchestrator/execution_plugin/test_ssh.py | 2 +-
9 files changed, 78 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/46c70a43/aria/core.py
----------------------------------------------------------------------
diff --git a/aria/core.py b/aria/core.py
index 3b1df80..99b209d 100644
--- a/aria/core.py
+++ b/aria/core.py
@@ -57,7 +57,7 @@ class Core(object):
service_template.name = service_template_name
self.model_storage.service_template.put(service_template)
self.resource_storage.service_template.upload(
- entry_id=service_template.name, source=service_template_dir)
+ entry_id=str(service_template.id), source=service_template_dir)
def delete_service_template(self, service_template_id):
service_template = self.model_storage.service_template.get(service_template_id)
@@ -66,7 +66,7 @@ class Core(object):
"existing services")
self.model_storage.service_template.delete(service_template)
- self.resource_storage.service_template.delete(entry_id=service_template.name)
+ self.resource_storage.service_template.delete(entry_id=str(service_template.name))
def create_service(self, service_template_name, inputs, service_name):
service_template = self.model_storage.service_template.get_by_name(service_template_name)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/46c70a43/aria/orchestrator/context/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py
index 127641f..06e283c 100644
--- a/aria/orchestrator/context/common.py
+++ b/aria/orchestrator/context/common.py
@@ -168,13 +168,13 @@ class BaseContext(object):
Download a blueprint resource from the resource storage
"""
try:
- self.resource.deployment.download(entry_id=str(self.service.id),
- destination=destination,
- path=path)
+ self.resource.service.download(entry_id=str(self.service.id),
+ destination=destination,
+ path=path)
except exceptions.StorageError:
- self.resource.blueprint.download(entry_id=str(self.service_template.id),
- destination=destination,
- path=path)
+ self.resource.service_template.download(entry_id=str(self.service_template.id),
+ destination=destination,
+ path=path)
def download_resource_and_render(self, destination, path=None, variables=None):
"""
@@ -193,9 +193,9 @@ class BaseContext(object):
Read a deployment resource as string from the resource storage
"""
try:
- return self.resource.deployment.read(entry_id=str(self.service.id), path=path)
+ return self.resource.service.read(entry_id=str(self.service.id), path=path)
except exceptions.StorageError:
- return self.resource.deployment.read(entry_id=str(self.service_template.id), path=path)
+ return self.resource.service.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/46c70a43/aria/orchestrator/workflows/api/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/api/task.py b/aria/orchestrator/workflows/api/task.py
index f49ec2e..2691190 100644
--- a/aria/orchestrator/workflows/api/task.py
+++ b/aria/orchestrator/workflows/api/task.py
@@ -63,7 +63,6 @@ class OperationTask(BaseTask):
def __init__(self,
actor,
- actor_type,
interface_name,
operation_name,
runs_on=None,
@@ -76,6 +75,7 @@ class OperationTask(BaseTask):
:meth:`for_relationship`.
"""
+ actor_type = type(actor).__name__.lower()
assert isinstance(actor, (models.Node, models.Relationship))
assert actor_type in ('node', 'relationship')
assert interface_name and operation_name
@@ -103,12 +103,7 @@ class OperationTask(BaseTask):
# model, because they are different from the operation inputs. If we do this, then the two
# kinds of inputs should *not* be merged here.
- operation = self._get_operation()
- if operation is None:
- raise exceptions.OperationNotFoundException(
- 'Could not find operation "{0}" on interface "{1}" for {2} "{3}"'
- .format(self.operation_name, self.interface_name, actor_type, actor.name))
-
+ operation = self.actor.interfaces[self.interface_name].operations[self.operation_name]
self.plugin = None
if operation.plugin_specification:
self.plugin = OperationTask._find_plugin(operation.plugin_specification)
@@ -128,14 +123,6 @@ class OperationTask(BaseTask):
def __repr__(self):
return self.name
- def _get_operation(self):
- interface = self.actor.interfaces.get(self.interface_name)
- if interface:
- return interface.operations.get(self.operation_name)
- return None
-
-
-
@classmethod
def for_node(cls,
node,
@@ -163,7 +150,6 @@ class OperationTask(BaseTask):
assert isinstance(node, models.Node)
return cls(
actor=node,
- actor_type='node',
interface_name=interface_name,
operation_name=operation_name,
max_attempts=max_attempts,
@@ -202,7 +188,6 @@ class OperationTask(BaseTask):
assert runs_on in models.Task.RUNS_ON
return cls(
actor=relationship,
- actor_type='relationship',
interface_name=interface_name,
operation_name=operation_name,
runs_on=runs_on,
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/46c70a43/aria/orchestrator/workflows/builtin/execute_operation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/execute_operation.py b/aria/orchestrator/workflows/builtin/execute_operation.py
index 348f47a..fef56f0 100644
--- a/aria/orchestrator/workflows/builtin/execute_operation.py
+++ b/aria/orchestrator/workflows/builtin/execute_operation.py
@@ -17,6 +17,7 @@
Builtin execute_operation workflow
"""
+from . import utils
from ..api.task import OperationTask
from ... import workflow
@@ -122,7 +123,7 @@ def _create_node_task(
if allow_kwargs_override is not None:
operation_kwargs['allow_kwargs_override'] = allow_kwargs_override
- return OperationTask.for_node(
+ return utils.create_node_task(
node=node,
interface_name=interface_name,
operation_name=operation_name,
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/46c70a43/aria/orchestrator/workflows/builtin/utils.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/utils.py b/aria/orchestrator/workflows/builtin/utils.py
index d79318f..8890084 100644
--- a/aria/orchestrator/workflows/builtin/utils.py
+++ b/aria/orchestrator/workflows/builtin/utils.py
@@ -12,26 +12,31 @@
# 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 ..api.task import OperationTask
+
+from ..api.task import OperationTask, StubTask
from .. import exceptions
-def create_node_task(node, interface_name, operation_name):
+def create_node_task(node, interface_name, operation_name, **kwargs):
"""
Returns a new operation task if the operation exists in the node, otherwise returns None.
"""
try:
+ if _is_empty_task(node, interface_name, operation_name):
+ return StubTask()
+
return OperationTask.for_node(node=node,
interface_name=interface_name,
- operation_name=operation_name)
+ operation_name=operation_name,
+ **kwargs)
except exceptions.OperationNotFoundException:
# We will skip nodes which do not have the operation
return None
def create_relationships_tasks(
- node, interface_name, source_operation_name=None, target_operation_name=None):
+ node, interface_name, source_operation_name=None, target_operation_name=None, **kwargs):
"""
Creates a relationship task (source and target) for all of a node_instance relationships.
:param basestring source_operation_name: the relationship operation name.
@@ -43,21 +48,18 @@ def create_relationships_tasks(
"""
sub_tasks = []
for relationship in node.outbound_relationships:
- try:
- relationship_operations = relationship_tasks(
- relationship,
- interface_name,
- source_operation_name=source_operation_name,
- target_operation_name=target_operation_name)
- sub_tasks.append(relationship_operations)
- except exceptions.OperationNotFoundException:
- # We will skip relationships which do not have the operation
- pass
+ relationship_operations = relationship_tasks(
+ relationship,
+ interface_name,
+ source_operation_name=source_operation_name,
+ target_operation_name=target_operation_name,
+ **kwargs)
+ sub_tasks.append(relationship_operations)
return sub_tasks
-def relationship_tasks(
- relationship, interface_name, source_operation_name=None, target_operation_name=None):
+def relationship_tasks(relationship, interface_name, source_operation_name=None,
+ target_operation_name=None, **kwargs):
"""
Creates a relationship task source and target.
:param Relationship relationship: the relationship instance itself
@@ -68,19 +70,35 @@ def relationship_tasks(
"""
operations = []
if source_operation_name:
- operations.append(
- OperationTask.for_relationship(relationship=relationship,
- interface_name=interface_name,
- operation_name=source_operation_name,
- runs_on='source')
- )
+ try:
+ if _is_empty_task(relationship, interface_name, source_operation_name):
+ operations.append(StubTask())
+
+ operations.append(
+ OperationTask.for_relationship(relationship=relationship,
+ interface_name=interface_name,
+ operation_name=source_operation_name,
+ runs_on='source',
+ **kwargs)
+ )
+ except exceptions.OperationNotFoundException:
+ # We will skip relationships which do not have the operation
+ pass
if target_operation_name:
- operations.append(
- OperationTask.for_relationship(relationship=relationship,
- interface_name=interface_name,
- operation_name=target_operation_name,
- runs_on='target')
- )
+ try:
+ if _is_empty_task(relationship, interface_name, target_operation_name):
+ operations.append(StubTask())
+
+ operations.append(
+ OperationTask.for_relationship(relationship=relationship,
+ interface_name=interface_name,
+ operation_name=target_operation_name,
+ runs_on='target',
+ **kwargs)
+ )
+ except exceptions.OperationNotFoundException:
+ # We will skip relationships which do not have the operation
+ pass
return operations
@@ -108,3 +126,15 @@ def create_node_task_dependencies(graph, tasks_and_nodes, reverse=False):
graph.add_dependency(dependency, task)
else:
graph.add_dependency(task, dependencies)
+
+
+def _is_empty_task(actor, interface_name, operation_name):
+ interface = actor.interfaces.get(interface_name)
+ if interface:
+ operation = interface.operations.get(operation_name)
+ if operation:
+ return operation.implementation is None
+
+ raise exceptions.OperationNotFoundException(
+ 'Could not find operation "{0}" on interface "{1}" for {2} "{3}"'
+ .format(operation_name, interface_name, type(actor).__name__.lower(), actor.name))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/46c70a43/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 696e9b3..8113746 100644
--- a/tests/orchestrator/context/test_resource_render.py
+++ b/tests/orchestrator/context/test_resource_render.py
@@ -64,9 +64,9 @@ def resources(tmpdir, ctx):
implicit_ctx_template_path.write(_IMPLICIT_CTX_TEMPLATE)
variables_template_path = tmpdir.join(_VARIABLES_TEMPLATE_PATH)
variables_template_path.write(_VARIABLES_TEMPLATE)
- ctx.resource.deployment.upload(entry_id='1',
+ ctx.resource.service.upload(entry_id='1',
source=str(implicit_ctx_template_path),
path=_IMPLICIT_CTX_TEMPLATE_PATH)
- ctx.resource.deployment.upload(entry_id='1',
+ ctx.resource.service.upload(entry_id='1',
source=str(variables_template_path),
path=_VARIABLES_TEMPLATE_PATH)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/46c70a43/tests/orchestrator/context/test_serialize.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_serialize.py b/tests/orchestrator/context/test_serialize.py
index db45e8e..5fdb674 100644
--- a/tests/orchestrator/context/test_serialize.py
+++ b/tests/orchestrator/context/test_serialize.py
@@ -34,7 +34,7 @@ def test_serialize_operation_context(context, executor, tmpdir):
test_file = tmpdir.join(TEST_FILE_NAME)
test_file.write(TEST_FILE_CONTENT)
resource = context.resource
- resource.blueprint.upload(TEST_FILE_ENTRY_ID, str(test_file))
+ resource.service_template.upload(TEST_FILE_ENTRY_ID, str(test_file))
graph = _mock_workflow(ctx=context) # pylint: disable=no-value-for-parameter
eng = engine.Engine(executor=executor, workflow_context=context, tasks_graph=graph)
eng.execute()
@@ -73,7 +73,7 @@ def _mock_operation(ctx):
# a correct ctx.deployment.name tells us we kept the correct deployment_id
assert ctx.service.name == mock.models.SERVICE_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)
+ test_file_content = ctx.resource.service_template.read(TEST_FILE_ENTRY_ID, TEST_FILE_NAME)
assert test_file_content == TEST_FILE_CONTENT
# a non empty plugin workdir tells us that we kept the correct base_workdir
assert ctx.plugin_workdir is not None
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/46c70a43/tests/orchestrator/execution_plugin/test_local.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/execution_plugin/test_local.py b/tests/orchestrator/execution_plugin/test_local.py
index e3612cf..08408bb 100644
--- a/tests/orchestrator/execution_plugin/test_local.py
+++ b/tests/orchestrator/execution_plugin/test_local.py
@@ -462,7 +462,7 @@ if __name__ == '__main__':
local_script_path = script_path
script_path = os.path.basename(local_script_path) if local_script_path else None
if script_path:
- workflow_context.resource.deployment.upload(
+ workflow_context.resource.service.upload(
entry_id=str(workflow_context.service.id),
source=local_script_path,
path=script_path)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/46c70a43/tests/orchestrator/execution_plugin/test_ssh.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/execution_plugin/test_ssh.py b/tests/orchestrator/execution_plugin/test_ssh.py
index dd36466..d17def1 100644
--- a/tests/orchestrator/execution_plugin/test_ssh.py
+++ b/tests/orchestrator/execution_plugin/test_ssh.py
@@ -258,7 +258,7 @@ class TestWithActualSSHServer(object):
return collected[signal][0]['kwargs']['exception']
def _upload(self, source, path):
- self._workflow_context.resource.deployment.upload(
+ self._workflow_context.resource.service.upload(
entry_id=str(self._workflow_context.service.id),
source=source,
path=path)