use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.
the class NetworkCacheTest method updateSwitch.
@Test
public void updateSwitch() throws Exception {
String swId = "sw7";
SwitchInfoData sw7 = new SwitchInfoData(swId, SwitchState.ACTIVATED, "", "", "", "");
networkCache.createSwitch(sw7);
assertEquals(sw7, networkCache.getSwitch(swId));
SwitchInfoData sw7updated = new SwitchInfoData(swId, SwitchState.ACTIVATED, "", "", "", "");
networkCache.updateSwitch(sw7updated);
assertEquals(sw7updated, networkCache.getSwitch(swId));
networkCache.deleteSwitch(swId);
Set<SwitchInfoData> switches = networkCache.dumpSwitches();
assertEquals(Collections.emptySet(), switches);
}
use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.
the class KafkaMessageConsumer method receive.
/**
* Receives messages from WorkFlowManager queue.
*
* @param record the message object instance
*/
@KafkaListener(topics = "kilda-test")
public void receive(final String record) {
logger.debug("message received: {}", record);
try {
Message message = MAPPER.readValue(record, Message.class);
if (message.getDestination() == null || Destination.TOPOLOGY_ENGINE.equals(message.getDestination())) {
if (message instanceof CommandMessage) {
CommandData data = ((CommandMessage) message).getData();
if (data instanceof FlowCreateRequest) {
FlowPayload payload = ((FlowCreateRequest) data).getPayload();
logger.debug("FlowCreateRequest: {}", payload);
Set<CommandMessage> commands = flowService.createFlow(payload, message.getCorrelationId());
for (CommandMessage response : commands) {
kafkaMessageProducer.send(topic, response);
}
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowDeleteRequest) {
FlowIdStatusPayload payload = ((FlowDeleteRequest) data).getPayload();
logger.debug("FlowDeleteRequest: {}", payload);
Set<CommandMessage> commands = flowService.deleteFlow(payload, message.getCorrelationId());
for (CommandMessage response : commands) {
kafkaMessageProducer.send(topic, response);
}
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowUpdateRequest) {
FlowPayload payload = ((FlowUpdateRequest) data).getPayload();
logger.debug("FlowUpdateRequest: {}", payload);
Set<CommandMessage> commands = flowService.updateFlow(payload, message.getCorrelationId());
for (CommandMessage response : commands) {
kafkaMessageProducer.send(topic, response);
}
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowGetRequest) {
FlowIdStatusPayload payload = ((FlowGetRequest) data).getPayload();
logger.debug("FlowGetRequest: {}", payload);
InfoMessage response = flowService.getFlow(payload, message.getCorrelationId());
kafkaMessageProducer.send(topic, response);
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowsGetRequest) {
FlowIdStatusPayload payload = ((FlowsGetRequest) data).getPayload();
logger.debug("FlowsGetRequest: {}", payload);
InfoMessage response = flowService.getFlows(payload, message.getCorrelationId());
kafkaMessageProducer.send(topic, response);
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else if (data instanceof FlowPathRequest) {
FlowIdStatusPayload payload = ((FlowPathRequest) data).getPayload();
logger.debug("FlowPathRequest: {}", payload);
InfoMessage response = flowService.pathFlow(payload, message.getCorrelationId());
kafkaMessageProducer.send(topic, response);
logger.debug("Response send, {}={}", CORRELATION_ID, message.getCorrelationId());
} else {
logger.error("Unexpected command message data type: {}", data);
}
} else if (message instanceof InfoMessage) {
InfoData data = ((InfoMessage) message).getData();
if (data instanceof SwitchInfoData) {
SwitchInfoData payload = (SwitchInfoData) data;
switch(payload.getState()) {
case ADDED:
switchService.add(payload);
break;
case ACTIVATED:
switchService.activate(payload);
break;
case DEACTIVATED:
switchService.deactivate(payload);
break;
case REMOVED:
switchService.remove(payload);
break;
case CHANGED:
default:
break;
}
} else if (data instanceof IslInfoData) {
IslInfoData payload = (IslInfoData) data;
islService.discoverLink(payload);
} else {
logger.debug("Unexpected info message data type: {}", data);
}
}
} else {
logger.debug("Skip message: {}", message);
}
} catch (IOException exception) {
logger.error("Could not deserialize message: {}", record, exception);
}
}
use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.
the class SwitchesUtils method dumpSwitches.
/**
* Returns Switches through Topology-Engine-Rest service.
*
* @return The JSON document of all flows
*/
public static List<SwitchInfoData> dumpSwitches() {
System.out.println("\n==> Topology-Engine Dump Switches");
Client client = ClientBuilder.newClient(new ClientConfig());
Response response = client.target(topologyEndpoint).path("/api/v1/topology/switches").request().header(HttpHeaders.AUTHORIZATION, authHeaderValue).get();
System.out.println(format("===> Response = %s", response.toString()));
try {
List<SwitchInfoData> switches = new ObjectMapper().readValue(response.readEntity(String.class), new TypeReference<List<SwitchInfoData>>() {
});
return switches;
} catch (IOException ex) {
throw new TopologyProcessingException(format("Unable to parse the switches '%s'.", response.toString()), ex);
}
}
use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.
the class TopologyEventsBasicTest method the_switch_disappears_from_the_topology_engine.
@Then("^the switch disappears from the topology engine\\.$")
public void the_switch_disappears_from_the_topology_engine() throws Exception {
List<SwitchInfoData> switches = SwitchesUtils.dumpSwitches();
SwitchInfoData middleSwitch = getMiddleSwitch(switches);
// right now switch doesn't disappear in neo4j - we just update status
assertThat(middleSwitch.getState(), is(SwitchState.DEACTIVATED));
}
use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.
the class TopologyEventsBasicTest method a_switch_is_dropped_in_the_middle.
@When("^a switch is dropped in the middle$")
public void a_switch_is_dropped_in_the_middle() throws Exception {
List<SwitchInfoData> switches = SwitchesUtils.dumpSwitches();
SwitchInfoData middleSwitch = getMiddleSwitch(switches);
assertTrue("Should successfully knockout switch", SwitchesUtils.knockoutSwitch(getSwitchName(middleSwitch.getSwitchId())));
TimeUnit.SECONDS.sleep(1);
List<SwitchInfoData> updatedSwitches = SwitchesUtils.dumpSwitches();
SwitchInfoData deactivatedSwitch = updatedSwitches.stream().filter(sw -> sw.getSwitchId().equalsIgnoreCase(middleSwitch.getSwitchId())).findFirst().orElseThrow(() -> new IllegalStateException("Switch should exist"));
assertThat(deactivatedSwitch.getState(), is(SwitchState.DEACTIVATED));
}
Aggregations