summaryrefslogtreecommitdiffstats
path: root/azure/aria/aria-extension-cloudify/src/aria/aria/orchestrator/workflows/events_logging.py
blob: 9eee1e10bb33c76fadb167707f31b1ef6b83492d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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.


"""
Workflow event logging.
"""

from .. import events
from ... import modeling


def _get_task_name(task):
    if isinstance(task.actor, modeling.model_bases.service_instance.RelationshipBase):
        return '{source_node.name}->{target_node.name}'.format(
            source_node=task.actor.source_node, target_node=task.actor.target_node)
    else:
        return task.actor.name


@events.start_task_signal.connect
def _start_task_handler(ctx, **kwargs):
    # If the task has no function this is an empty task.
    if ctx.task.function:
        suffix = 'started...'
        logger = ctx.logger.info
    else:
        suffix = 'has no implementation'
        logger = ctx.logger.debug

    logger('{name} {task.interface_name}.{task.operation_name} {suffix}'.format(
        name=_get_task_name(ctx.task), task=ctx.task, suffix=suffix))


@events.on_success_task_signal.connect
def _success_task_handler(ctx, **kwargs):
    if not ctx.task.function:
        return
    ctx.logger.info('{name} {task.interface_name}.{task.operation_name} successful'
                    .format(name=_get_task_name(ctx.task), task=ctx.task))


@events.on_failure_task_signal.connect
def _failure_operation_handler(ctx, traceback, **kwargs):
    ctx.logger.error(
        '{name} {task.interface_name}.{task.operation_name} failed'
        .format(name=_get_task_name(ctx.task), task=ctx.task), extra=dict(traceback=traceback)
    )


@events.start_workflow_signal.connect
def _start_workflow_handler(context, **kwargs):
    context.logger.info("Starting '{ctx.workflow_name}' workflow execution".format(ctx=context))


@events.on_failure_workflow_signal.connect
def _failure_workflow_handler(context, **kwargs):
    context.logger.info("'{ctx.workflow_name}' workflow execution failed".format(ctx=context))


@events.on_success_workflow_signal.connect
def _success_workflow_handler(context, **kwargs):
    context.logger.info("'{ctx.workflow_name}' workflow execution succeeded".format(ctx=context))


@events.on_cancelled_workflow_signal.connect
def _cancel_workflow_handler(context, **kwargs):
    context.logger.info("'{ctx.workflow_name}' workflow execution canceled".format(ctx=context))


@events.on_cancelling_workflow_signal.connect
def _cancelling_workflow_handler(context, **kwargs):
    context.logger.info("Cancelling '{ctx.workflow_name}' workflow execution".format(ctx=context))