16 package org.openkilda.wfm;
31 import com.fasterxml.jackson.databind.ObjectMapper;
33 import java.io.IOException;
34 import java.util.Collections;
79 public static final String
PORT_UP =
"UP";
82 public static final String
LINK_UP =
"DISCOVERED";
86 public static final String
MT_SWITCH =
"org.openkilda.messaging.info.event.SwitchInfoData";
87 public static final String
MT_PORT =
"org.openkilda.messaging.info.event.PortInfoData";
92 private static final ObjectMapper _mapper =
new ObjectMapper();
95 throw new UnsupportedOperationException();
133 StringBuffer sb =
new StringBuffer(
"{'type': 'INFO', ");
134 sb.append(
"'timestamp': ").append(System.currentTimeMillis()).append(
", ");
138 return sb.toString().replace(
"'",
"\"");
156 StringBuffer sb =
new StringBuffer();
157 sb.append(
"{'clazz': '").append(
type).append(
"', ");
158 sb.append(
"'switch_id': '").append(switchId).append(
"', ");
159 if (portId != null && portId.length() > 0) {
160 sb.append(
"'port_no': ").append(portId).append(
", ");
162 sb.append(
"'state': '").append(state).append(
"'}");
164 return sb.toString().replace(
"'",
"\"");
167 public static Map<String, ?>
fromJson(String json)
throws IOException {
168 return _mapper.readValue(json, Map.class);
171 public static String
toJson(Map<String, ?> map)
throws IOException {
172 return _mapper.writeValueAsString(map);
182 public static Map<String, ?>
getData(String json)
throws IOException {
184 if (
root.containsKey(
"type")) {
185 root = (Map<String, ?>)
root.get(PAYLOAD);
203 return MAPPER.writeValueAsString(message);
218 System.currentTimeMillis(),
221 return MAPPER.writeValueAsString(message);
static final String PAYLOAD
static final ObjectMapper MAPPER
static String createSwitchDataMessage(String state, String switchId)
static final String MT_SWITCH
static String createPortDataMessage(String state, String switchId, String portId)
static String createDataMessage(String type, String state, String switchId, String portId)
static final String SWITCH_UP
static final String FIELD_PORT_ID
static String createIslFail(SwitchId switchId, int portId, String correlationId)
static final String PORT_UP
static final String LINK_UP
static final String MT_PORT
static final String SWITCH_DOWN
static String createInfoMessage(boolean isSwitch, String switchId, String portId, String state)
static String toJson(Map< String, ?> map)
static final String FIELD_STATE
static final String FIELD_SWITCH_ID
static String createSwitchInfoMessage(String switchId, String state)
static Map< String, ?> getData(String json)
static final String LINK_DOWN
static Map< String, ?> fromJson(String json)
static final String PORT_ADD
static String createIslDiscovery(SwitchId switchId, int portId, String correlationId)
static final String PORT_DOWN
static String createPortInfoMessage(String switchId, String portId, String state)