1
|
|
|
""" |
2
|
|
|
Enarksh |
3
|
|
|
|
4
|
|
|
Copyright 2013-2016 Set Based IT Consultancy |
5
|
|
|
|
6
|
|
|
Licence MIT |
7
|
|
|
""" |
8
|
|
|
from enarksh.message.Message import Message |
|
|
|
|
9
|
|
|
from enarksh.message.MessageController import MessageController |
|
|
|
|
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class RequestNodeActionMessage(Message): |
13
|
|
|
""" |
14
|
|
|
Message type for requesting a node action. |
15
|
|
|
""" |
16
|
|
|
MESSAGE_TYPE = 'controller:RequestNodeActionMessage' |
17
|
|
|
""" |
18
|
|
|
The message type. |
19
|
|
|
|
20
|
|
|
:type: str |
21
|
|
|
""" |
22
|
|
|
|
23
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
24
|
|
|
def __init__(self, sch_id, rnd_id, act_id, usr_login, mail_on_completion, mail_on_error): |
25
|
|
|
""" |
26
|
|
|
Object constructor. |
27
|
|
|
|
28
|
|
|
:param int sch_id: The ID of the schedule. |
29
|
|
|
:param int rnd_id: The ID of the run node. |
30
|
|
|
:param int act_id: The ID of the requested action. |
31
|
|
|
:param str usr_login: The name of the user who has requested the node action. |
32
|
|
|
:param bool mail_on_completion: If True the user wants to receive a mail when the schedule has completed. |
33
|
|
|
:param bool mail_on_error: If True the user wants to receive a mail when an error occurs. |
34
|
|
|
""" |
35
|
|
|
Message.__init__(self, RequestNodeActionMessage.MESSAGE_TYPE) |
36
|
|
|
|
37
|
|
|
self.sch_id = sch_id |
38
|
|
|
""" |
39
|
|
|
The ID of the schedule. |
40
|
|
|
|
41
|
|
|
:type: int |
42
|
|
|
""" |
43
|
|
|
|
44
|
|
|
self.rnd_id = rnd_id |
45
|
|
|
""" |
46
|
|
|
The ID of the run node. |
47
|
|
|
|
48
|
|
|
:type: int |
49
|
|
|
""" |
50
|
|
|
|
51
|
|
|
self.act_id = act_id |
52
|
|
|
""" |
53
|
|
|
The ID of the requested action. |
54
|
|
|
|
55
|
|
|
:type: int |
56
|
|
|
""" |
57
|
|
|
|
58
|
|
|
self.usr_login = usr_login |
59
|
|
|
""" |
60
|
|
|
The name of the user who has requested the node action. |
61
|
|
|
|
62
|
|
|
:type: int |
63
|
|
|
""" |
64
|
|
|
|
65
|
|
|
self.mail_on_completion = mail_on_completion |
66
|
|
|
""" |
67
|
|
|
If True the user wants to receive a mail when the schedule has completed. |
68
|
|
|
|
69
|
|
|
:type: bool |
70
|
|
|
""" |
71
|
|
|
|
72
|
|
|
self.mail_on_error = mail_on_error |
73
|
|
|
""" |
74
|
|
|
If True the user wants to receive a mail when an error occurs. |
75
|
|
|
|
76
|
|
|
:type: bool |
77
|
|
|
""" |
78
|
|
|
|
79
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
80
|
|
|
@staticmethod |
81
|
|
|
def create_from_json(message): |
82
|
|
|
""" |
83
|
|
|
Object constructor using JSON encoded message. |
84
|
|
|
|
85
|
|
|
:param * message: The message. |
86
|
|
|
|
87
|
|
|
:rtype: enarksh.controller.message.RequestPossibleNodeActionsMessage.RequestPossibleNodeActionsMessage |
88
|
|
|
""" |
89
|
|
|
return RequestNodeActionMessage(int(message['sch_id']), |
90
|
|
|
int(message['rnd_id']), |
91
|
|
|
int(message['act_id']), |
92
|
|
|
message['usr_login'], |
93
|
|
|
bool(message['mail_on_completion']), |
94
|
|
|
bool(message['mail_on_error'])) |
95
|
|
|
|
96
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
97
|
|
|
def send_message(self, end_point): |
98
|
|
|
""" |
99
|
|
|
Sends the message to an end point. |
100
|
|
|
|
101
|
|
|
:param str end_point: The end point. |
102
|
|
|
|
103
|
|
|
:rtype: None |
104
|
|
|
""" |
105
|
|
|
self.message_controller.send_message(end_point, self) |
|
|
|
|
106
|
|
|
|
107
|
|
|
|
108
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
109
|
|
|
MessageController.register_json_message_creator(RequestNodeActionMessage.MESSAGE_TYPE, |
110
|
|
|
RequestNodeActionMessage.create_from_json) |
111
|
|
|
|