Github user ran-z commented on a diff in the pull request:
https://github.com/apache/incubator-ariatosca/pull/97#discussion_r111401230
--- Diff: aria/cli/commands/executions.py ---
@@ -0,0 +1,170 @@
+# 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 .. import utils
+from ..table import print_data
+from ..cli import aria
+from ...modeling.models import Execution
+from ...orchestrator.workflow_runner import WorkflowRunner
+from ...orchestrator.workflows.executor.dry import DryExecutor
+from ...utils import formatting
+from ...utils import threading
+
+EXECUTION_COLUMNS = ['id', 'workflow_name', 'status', 'service_name',
+ 'created_at', 'error']
+
+
[email protected](name='executions')
[email protected]()
+def executions():
+ """Handle workflow executions
+ """
+ pass
+
+
[email protected](name='show',
+ short_help='Show execution information')
[email protected]('execution-id')
[email protected]()
[email protected]_model_storage
[email protected]_logger
+def show(execution_id, model_storage, logger):
+ """Show information for a specific execution
+
+ `EXECUTION_ID` is the execution to get information on.
+ """
+ logger.info('Showing execution {0}'.format(execution_id))
+ execution = model_storage.execution.get(execution_id)
+
+ print_data(EXECUTION_COLUMNS, execution.to_dict(), 'Execution:',
max_width=50)
+
+ # print execution parameters
+ logger.info('Execution Inputs:')
+ if execution.inputs:
+ #TODO check this section, havent tested it
+ execution_inputs = [ei.to_dict() for ei in execution.inputs]
+ for input_name, input_value in formatting.decode_dict(
+ execution_inputs).iteritems():
+ logger.info('\t{0}: \t{1}'.format(input_name, input_value))
+ else:
+ logger.info('\tNo inputs')
+ logger.info('')
+
+
[email protected](name='list',
+ short_help='List service executions')
[email protected]_name(required=False)
[email protected]_by()
[email protected]
[email protected]()
[email protected]_model_storage
[email protected]_logger
+def list(service_name,
+ sort_by,
+ descending,
+ model_storage,
+ logger):
+ """List executions
+
+ If `SERVICE_NAME` is provided, list executions for that service.
+ Otherwise, list executions for all services.
+ """
+ if service_name:
+ logger.info('Listing executions for service {0}...'.format(
+ service_name))
+ service = model_storage.service.get_by_name(service_name)
+ filters = dict(service=service)
+ else:
+ logger.info('Listing all executions...')
+ filters = {}
+
+ executions_list = [e.to_dict() for e in model_storage.execution.list(
+ filters=filters,
+ sort=utils.storage_sort_param(sort_by, descending))]
+
+ print_data(EXECUTION_COLUMNS, executions_list, 'Executions:')
+
+
[email protected](name='start',
+ short_help='Execute a workflow')
[email protected]('workflow-name')
[email protected]_name(required=True)
[email protected]
[email protected]_execution
[email protected]_max_attempts()
[email protected]_retry_interval()
[email protected]()
[email protected]_model_storage
[email protected]_resource_storage
[email protected]_plugin_manager
[email protected]_logger
+def start(workflow_name,
+ service_name,
+ inputs,
+ dry,
+ task_max_attempts,
+ task_retry_interval,
+ model_storage,
+ resource_storage,
+ plugin_manager,
+ logger):
+ """Execute a workflow
+
+ `WORKFLOW_NAME` is the name of the workflow to execute (e.g.
`uninstall`)
+ """
+ service = model_storage.service.get_by_name(service_name)
+ executor = DryExecutor() if dry else None # use WorkflowRunner's
default executor
+
+ workflow_runner = \
+ WorkflowRunner(workflow_name, service.id, inputs,
+ model_storage, resource_storage, plugin_manager,
+ executor, task_max_attempts, task_retry_interval)
+
+ execution_thread_name = '{0}_{1}'.format(service_name, workflow_name)
+ execution_thread =
threading.ExceptionThread(target=workflow_runner.execute,
+
name=execution_thread_name)
+ execution_thread.daemon = True # allows force-cancel to exit
immediately
+
+ logger.info('Starting {0}execution. Press Ctrl+C cancel'.format('dry '
if dry else ''))
+ execution_thread.start()
+ try:
+ while execution_thread.is_alive():
+ # using join without a timeout blocks and ignores
KeyboardInterrupt
+ execution_thread.join(1)
+ except KeyboardInterrupt:
+ _cancel_execution(workflow_runner, execution_thread, logger)
+
+ # raise any errors from the execution thread (note these are not
workflow execution errors)
+ execution_thread.raise_error_if_exists()
+
+ execution = workflow_runner.execution
+ logger.info('Execution has ended with "{0}"
status'.format(execution.status))
+ if execution.status == Execution.FAILED and execution.error:
+ logger.info('Execution error:\n{0}'.format(execution.error))
--- End diff --
:+1:
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---