incubator-ariatosca git commit: wip
Repository: incubator-ariatosca Updated Branches: refs/heads/operation_graph b53aa1f3b -> 8f83ce939 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/8f83ce93 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/8f83ce93 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/8f83ce93 Branch: refs/heads/operation_graph Commit: 8f83ce9393ca5d57c719986ef78efc36031b1116 Parents: b53aa1f Author: mxmrlvAuthored: Thu Oct 13 19:52:35 2016 +0300 Committer: mxmrlv Committed: Thu Oct 13 19:52:35 2016 +0300 -- aria/workflows/engine/engine.py | 99 ++-- aria/workflows/engine/tasks.py | 72 ++ 2 files changed, 144 insertions(+), 27 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8f83ce93/aria/workflows/engine/engine.py -- diff --git a/aria/workflows/engine/engine.py b/aria/workflows/engine/engine.py index 7b86fb5..34aee58 100644 --- a/aria/workflows/engine/engine.py +++ b/aria/workflows/engine/engine.py @@ -28,6 +28,16 @@ from aria.events import ( on_failure_task_signal, ) from aria.logger import LoggerMixin +from aria.contexts import OperationContext + + +from .tasks import ( +StartWorkflowTask, +EndWorkflowTask, +StartSubWorkflowTask, +EndSubWorkflowTask, +OperationTask, +) class Engine(LoggerMixin): @@ -38,10 +48,68 @@ class Engine(LoggerMixin): self._tasks_graph = tasks_graph self._execution_graph = DiGraph() self._executor = executor -self._build_execution_graph(self._workflow_context, self._tasks_graph) - -def _build_execution_graph(self, workflow_context, graph): -pass +self._start_task_name = 'Starting.{0}'.format +self._end_task_name = 'Ending.{0}'.format +self._build_execution_graph(self._tasks_graph) + +def _build_execution_graph( +self, +graph, +StartClass=StartWorkflowTask, +EndClass=EndWorkflowTask, +depends_on=()): + +# Insert start marker +start_task = StartClass(task_name=self._start_task_name(graph.name), context=self._workflow_context) +self._add_task_and_dependencies(start_task, depends_on) + +for operation_or_workflow, dependencies in graph.task_tree(reverse=True): +operation_dependencies = self._get_tasks_from_dependencies(dependencies, default=[start_task]) + +if self._is_operation(operation_or_workflow): +# Add the task an the dependencies +operation_task = OperationTask( +task_name=operation_or_workflow.name, +context=operation_or_workflow, +**operation_or_workflow.engine_options +) +self._add_task_and_dependencies(operation_task, operation_dependencies) +else: +# Built the graph recursively while adding start and end markers +self._build_execution_graph( +graph=operation_or_workflow, +StartClass=StartSubWorkflowTask, +EndClass=EndSubWorkflowTask, +depends_on=operation_dependencies +) + +# Insert end marker +workflow_dependencies = self._get_tasks_from_dependencies(graph.leaf_tasks, default=[start_task]) +end_task = EndClass(task_name=self._end_task_name(graph.name), context=self._workflow_context) +self._add_task_and_dependencies(end_task, workflow_dependencies) + +def _add_task_and_dependencies(self, operation_task, operation_dependencies=()): +self._execution_graph.add_node(operation_task) +for dependency in operation_dependencies: + self._execution_graph.add_edge(self._execution_graph[dependency.task_name], + self._execution_graph[operation_task.task_name]) + +def _get_tasks_from_dependencies(self, dependencies, default=()): +""" +Returns task list from dependencies. +""" +return [ +self._workflow_tasks[ +context.name +if self._is_operation(context) else +self._end_task_name(context.name) +] +for context in dependencies +] or default + +@staticmethod +def _is_operation(task): +return isinstance(task, OperationContext) def execute(self): execution_id = self._workflow_context.execution_id @@ -160,26 +228,3 @@ class Engine(LoggerMixin):
[5/6] incubator-ariatosca git commit: move everything and more to ariatosca
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c52f949e/aria/from_cloudify/workflows/events.py -- diff --git a/aria/from_cloudify/workflows/events.py b/aria/from_cloudify/workflows/events.py new file mode 100644 index 000..b8faa1b --- /dev/null +++ b/aria/from_cloudify/workflows/events.py @@ -0,0 +1,197 @@ + +# Copyright (c) 2014 GigaSpaces Technologies Ltd. All rights reserved +# +# Licensed 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 cloudify import logs +from cloudify.exceptions import OperationRetry +from cloudify.workflows import tasks as tasks_api + + +class Monitor(object): +"""Monitor with handlers for different celery events""" + +def __init__(self, tasks_graph): +""" +:param tasks_graph: The task graph. Used to extract tasks based on the +events task id. +""" +self.tasks_graph = tasks_graph +self._receiver = None +self._should_stop = False + +def task_sent(self, event): +pass + +def task_received(self, event): +pass + +def task_started(self, event): +self._handle(tasks_api.TASK_STARTED, event, send_event=True) + +def task_succeeded(self, event): +self._handle(tasks_api.TASK_SUCCEEDED, event, send_event=True) + +def task_failed(self, event): +if event.get('exception', '').startswith(OperationRetry.__name__): +state = tasks_api.TASK_RESCHEDULED +else: +state = tasks_api.TASK_FAILED +self._handle(state, event, send_event=False) + +def task_revoked(self, event): +pass + +def task_retried(self, event): +pass + +def _handle(self, state, event, send_event): +task_id = event['uuid'] +task = self.tasks_graph.get_task(task_id) +if task is not None: +if send_event: +send_task_event(state, task, send_task_event_func_remote, +event) +task.set_state(state) + +def capture(self): +# Only called when running within an agent, so import here +from cloudify_agent.app import app +with app.connection() as connection: +self._receiver = app.events.Receiver(connection, handlers={ +'task-sent': self.task_sent, +'task-received': self.task_received, +'task-started': self.task_started, +'task-succeeded': self.task_succeeded, +'task-failed': self.task_failed, +'task-revoked': self.task_revoked, +'task-retried': self.task_retried +}) +for _ in self._receiver.itercapture(limit=None, +timeout=None, +wakeup=True): +if self._should_stop: +return + +def stop(self): +self._should_stop = True +self._receiver.should_stop = True + + +def send_task_event_func_remote(task, event_type, message, +additional_context=None): +_send_task_event_func(task, event_type, message, + out_func=logs.amqp_event_out, + additional_context=additional_context) + + +def send_task_event_func_local(task, event_type, message, + additional_context=None): +_send_task_event_func(task, event_type, message, + out_func=logs.stdout_event_out, + additional_context=additional_context) + + +def _send_task_event_func(task, event_type, message, out_func, + additional_context): +if task.cloudify_context is None: +logs.send_workflow_event(ctx=task.workflow_context, + event_type=event_type, + message=message, + out_func=out_func, + additional_context=additional_context) +else: +logs.send_task_event(cloudify_context=task.cloudify_context, + event_type=event_type, + message=message, + out_func=out_func, + additional_context=additional_context) + + +def _filter_task(task, state): +return
[6/6] incubator-ariatosca git commit: move everything and more to ariatosca
move everything and more to ariatosca Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/c52f949e Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/c52f949e Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/c52f949e Branch: refs/heads/wf-wip Commit: c52f949e98e33c06de15a900dd922734585f5165 Parents: Author: Dan KilmanAuthored: Thu Oct 13 12:35:17 2016 +0300 Committer: Dan Kilman Committed: Thu Oct 13 12:35:17 2016 +0300 -- .gitignore | 64 + .pylintrc | 389 + .travis.yml | 14 + LICENSE | 191 +++ MANIFEST.in |1 + README.md | 10 + TODO.md |8 + aria/VERSION.py | 21 + aria/__init__.py| 76 + aria/cli/__init__.py| 14 + aria/cli/args_parser.py | 115 ++ aria/cli/cli.py | 80 + aria/cli/commands.py| 280 aria/cli/config.py | 37 + aria/cli/exceptions.py | 47 + aria/cli/storage.py | 70 + aria/contexts.py| 155 ++ aria/decorators.py | 85 + aria/events/__init__.py | 46 + aria/events/builtin_event_handlers.py | 44 + aria/events/workflow_engine_event_handler.py| 74 + aria/exceptions.py | 30 + aria/from_cloudify/__init__.py |0 aria/from_cloudify/workflows/__init__.py| 20 + aria/from_cloudify/workflows/events.py | 197 +++ aria/from_cloudify/workflows/local.py | 598 +++ aria/from_cloudify/workflows/tasks.py | 767 + aria/from_cloudify/workflows/tasks_graph.py | 372 + aria/from_cloudify/workflows/workflow_api.py| 47 + .../from_cloudify/workflows/workflow_context.py | 1525 ++ aria/logger.py | 130 ++ aria/storage/__init__.py| 371 + aria/storage/drivers.py | 407 + aria/storage/models.py | 344 aria/storage/structures.py | 286 aria/tools/__init__.py | 14 + aria/tools/application.py | 279 aria/tools/lru_cache.py | 127 ++ aria/tools/plugin.py| 38 + aria/tools/process.py | 153 ++ aria/tools/validation.py| 78 + aria/workflows/__init__.py | 54 + aria/workflows/api/__init__.py | 14 + aria/workflows/api/tasks_graph.py | 203 +++ aria/workflows/builtin/__init__.py | 32 + .../builtin/deployment_modification.py | 221 +++ aria/workflows/builtin/execute_operation.py | 77 + aria/workflows/builtin/heal.py | 147 ++ aria/workflows/builtin/install.py | 42 + aria/workflows/builtin/scale.py | 416 + aria/workflows/builtin/uninstall.py | 41 + aria/workflows/builtin/update.py| 21 + aria/workflows/builtin/workflows.py | 194 +++ aria/workflows/engine/__init__.py | 14 + aria/workflows/engine/engine.py | 185 +++ aria/workflows/engine/executor.py | 41 + aria/workflows/exceptions.py| 47 + ctx_api | 113 ++ requirements.txt|6 + setup.py| 59 + tests/__init__.py | 14 + tests/events/__init__.py| 14 + tests/events/test_builtin_event_handlers.py | 58 + .../test_workflow_enginge_event_handlers.py |0 tests/requirements.txt |6 + tests/storage/__init__.py | 53 + tests/storage/test_drivers.py | 136 ++ tests/storage/test_field.py | 108 ++ tests/storage/test_model_storage.py | 162 ++ tests/storage/test_models.py| 289 tests/storage/test_models_api.py| 70 + tests/storage/test_resource_storage.py | 175 ++ tests/test_logger.py| 126