vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / aria / orchestrator / workflows / events_logging.py
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements.  See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License.  You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16
17 """
18 Workflow event logging.
19 """
20
21 from .. import events
22 from ... import modeling
23
24
25 def _get_task_name(task):
26     if isinstance(task.actor, modeling.model_bases.service_instance.RelationshipBase):
27         return '{source_node.name}->{target_node.name}'.format(
28             source_node=task.actor.source_node, target_node=task.actor.target_node)
29     else:
30         return task.actor.name
31
32
33 @events.start_task_signal.connect
34 def _start_task_handler(ctx, **kwargs):
35     # If the task has no function this is an empty task.
36     if ctx.task.function:
37         suffix = 'started...'
38         logger = ctx.logger.info
39     else:
40         suffix = 'has no implementation'
41         logger = ctx.logger.debug
42
43     logger('{name} {task.interface_name}.{task.operation_name} {suffix}'.format(
44         name=_get_task_name(ctx.task), task=ctx.task, suffix=suffix))
45
46
47 @events.on_success_task_signal.connect
48 def _success_task_handler(ctx, **kwargs):
49     if not ctx.task.function:
50         return
51     ctx.logger.info('{name} {task.interface_name}.{task.operation_name} successful'
52                     .format(name=_get_task_name(ctx.task), task=ctx.task))
53
54
55 @events.on_failure_task_signal.connect
56 def _failure_operation_handler(ctx, traceback, **kwargs):
57     ctx.logger.error(
58         '{name} {task.interface_name}.{task.operation_name} failed'
59         .format(name=_get_task_name(ctx.task), task=ctx.task), extra=dict(traceback=traceback)
60     )
61
62
63 @events.start_workflow_signal.connect
64 def _start_workflow_handler(context, **kwargs):
65     context.logger.info("Starting '{ctx.workflow_name}' workflow execution".format(ctx=context))
66
67
68 @events.on_failure_workflow_signal.connect
69 def _failure_workflow_handler(context, **kwargs):
70     context.logger.info("'{ctx.workflow_name}' workflow execution failed".format(ctx=context))
71
72
73 @events.on_success_workflow_signal.connect
74 def _success_workflow_handler(context, **kwargs):
75     context.logger.info("'{ctx.workflow_name}' workflow execution succeeded".format(ctx=context))
76
77
78 @events.on_cancelled_workflow_signal.connect
79 def _cancel_workflow_handler(context, **kwargs):
80     context.logger.info("'{ctx.workflow_name}' workflow execution canceled".format(ctx=context))
81
82
83 @events.on_cancelling_workflow_signal.connect
84 def _cancelling_workflow_handler(context, **kwargs):
85     context.logger.info("Cancelling '{ctx.workflow_name}' workflow execution".format(ctx=context))