Open Kilda Java Documentation
message.py
Go to the documentation of this file.
1 # Copyright 2017 Telstra Open Source
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 
16 import time
17 import json
18 
19 
20 class Message(object):
21 
22  JAVA_CTRL_REQUEST = 'org.openkilda.messaging.ctrl.CtrlRequest'
23 
24  def __init__(self, destination, payload, correlation_id=None,
25  _clazz=JAVA_CTRL_REQUEST):
26  self._payload = payload
27  self._destination = destination
28  self._timestamp = int(round(time.time() * 1000))
29  self._correlation_id = correlation_id
30  self._clazz = _clazz
31 
32  def serialize(self):
33  value = {
34  'payload': self._payload,
35  'destination': 'WFM_CTRL',
36  'timestamp': self._timestamp,
37  'correlation_id': self._correlation_id,
38  'route': self._destination,
39  'clazz': self._clazz
40  }
41 
42  return bytes(json.dumps(value).encode('utf-8'))
43 
44 
46 
47  JAVA_REQUEST_DATA = 'org.openkilda.messaging.ctrl.RequestData'
48 
49  def __init__(self, destination, correlation_id, action):
50  payload = {
51  'clazz': self.JAVA_REQUEST_DATA,
52  'action': action
53  }
54 
55  super(CtrlCommandMessage, self).__init__(destination,
56  payload, correlation_id)
57 
58 
60 
61  JAVA_REQUEST_DATA = \
62  'org.openkilda.messaging.ctrl.DumpStateBySwitchRequestData'
63 
64  def __init__(self, destination, correlation_id, switch_id):
65  payload = {
66  'clazz': self.JAVA_REQUEST_DATA,
67  'action': 'dumpBySwitch',
68  'switch_id': switch_id
69  }
70 
71  super(DumpBySwitchCtrlCommandMessage, self).__init__(destination,
72  payload, correlation_id)
73 
74 
75 def create_list(correlation_id):
76  return CtrlCommandMessage('*', correlation_id, 'list')
77 
78 
79 def create_dump_state(correlation_id, destination):
80  return CtrlCommandMessage(destination, correlation_id, 'dump')
81 
82 
83 def create_dump_state_by_switch(correlation_id, destination, switch):
84  return DumpBySwitchCtrlCommandMessage(destination, correlation_id, switch)
85 
86 
87 def create_resource_dump_state(correlation_id, destination):
88  return CtrlCommandMessage(destination, correlation_id, 'dumpResorceCache')
def __init__(self, destination, payload, correlation_id=None, _clazz=JAVA_CTRL_REQUEST)
Definition: message.py:25
def create_dump_state_by_switch(correlation_id, destination, switch)
Definition: message.py:83
def create_dump_state(correlation_id, destination)
Definition: message.py:79
def create_resource_dump_state(correlation_id, destination)
Definition: message.py:87
def __init__(self, destination, correlation_id, action)
Definition: message.py:49
def create_list(correlation_id)
Definition: message.py:75
def __init__(self, destination, correlation_id, switch_id)
Definition: message.py:64