use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.
the class FlowServiceImplTest method updateFlow.
@Test
public void updateFlow() throws Exception {
long updatedBandwidth = 20000L;
FlowEndpointPayload firstEndpoint = new FlowEndpointPayload(srcSwitchId, 10, 100);
FlowEndpointPayload secondEndpoint = new FlowEndpointPayload(dstSwitchId, 20, 100);
FlowPayload flowPayload = new FlowPayload(flowId, 0L, secondEndpoint, firstEndpoint, 10000L, "", "", OutputVlanType.NONE);
FlowPayload newFlowPayload = new FlowPayload(flowId, 0L, secondEndpoint, firstEndpoint, updatedBandwidth, "", "", OutputVlanType.NONE);
flowService.createFlow(flowPayload, DEFAULT_CORRELATION_ID);
flowService.updateFlow(newFlowPayload, DEFAULT_CORRELATION_ID);
Set<Flow> flows = flowRepository.findByFlowId(flowId);
assertNotNull(flows);
assertFalse(flows.isEmpty());
assertEquals(2, flows.size());
for (Flow flow : flowRepository.findAll()) {
assertEquals(flowId, flow.getFlowId());
assertEquals(updatedBandwidth, flow.getBandwidth());
}
}
use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.
the class FlowUtils method getFlow.
/**
* Gets flow through Northbound service.
*
* @param flowId flow id
* @return The JSON document of the specified flow
*/
public static FlowPayload getFlow(final String flowId) {
System.out.println("\n==> Northbound Get Flow");
long current = System.currentTimeMillis();
Client client = clientFactory();
Response response = client.target(northboundEndpoint).path("/api/v1/flows").path("{flowid}").resolveTemplate("flowid", flowId).request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, authHeaderValue).header(Utils.CORRELATION_ID, String.valueOf(System.currentTimeMillis())).get();
System.out.println(format("===> Response = %s", response.toString()));
System.out.println(format("===> Northbound Get Flow Time: %,.3f", getTimeDuration(current)));
int responseCode = response.getStatus();
if (responseCode == 200) {
FlowPayload flow = response.readEntity(FlowPayload.class);
System.out.println(format("====> Northbound Get Flow = %s", flow));
return flow;
} else {
System.out.println(format("====> Error: Northbound Get Flow = %s", response.readEntity(MessageError.class)));
return null;
}
}
use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.
the class FlowUtils method cleanupFlows.
/**
* Cleanups all flows.
*/
public static void cleanupFlows() {
try {
Set<String> flows = new HashSet<>();
// TODO: This method started with getting counts and compariing, but that shouldn't be
// the responsibility of this method given its name - cleanupFlows.
// So, the TODO is to determine whether this code exists elsewhere in tests,
// and if not, move it somewhere after, or part of, create test.
// Get the flows through the NB API
List<FlowPayload> nbFlows = getFlowDump();
System.out.println(format("=====> Cleanup Flows, nbflow count = %d", nbFlows.size()));
nbFlows.forEach(flow -> flows.add(flow.getId()));
// Get the flows through the TE Rest API ... loop until the math works out.
List<Flow> tpeFlows = new ArrayList<>();
for (int i = 0; i < 10; ++i) {
tpeFlows = dumpFlows();
if (tpeFlows.size() == nbFlows.size() * 2) {
tpeFlows.forEach(flow -> flows.add(flow.getFlowId()));
break;
}
TimeUnit.SECONDS.sleep(2);
}
System.out.println(format("=====> Cleanup Flows, tpeFlows count = %d", tpeFlows.size()));
// Delete all the flows
flows.forEach(FlowUtils::deleteFlow);
// Wait for them to become zero
int nb_count = -1;
int ter_count = -1;
for (int i = 0; i < 10; ++i) {
TimeUnit.SECONDS.sleep(2);
nb_count = dumpFlows().size();
ter_count = getFlowDump().size();
if (nb_count == 0 && ter_count == 0) {
break;
}
}
assertEquals(0, nb_count);
assertEquals(0, ter_count);
// (crimi) - it is unclear why we are doing a count validation here .. it makes sense to do this
// in the creation. But on cleanup, we just want things to be zero.
// assertEquals(nbFlows.size() * 2, tpeFlows.size());
// assertEquals(nbFlows.size(), flows.size());
} catch (Exception exception) {
System.out.println(format("Error during flow deletion: %s", exception.getMessage()));
exception.printStackTrace();
}
}
use of org.openkilda.messaging.payload.flow.FlowPayload in project open-kilda by telstra.
the class FlowUtils method updateFlow.
/**
* Updates flow through Northbound service.
*
* @param flowId flow id
* @param payload flow JSON data
* @return The JSON document of the created flow
*/
public static FlowPayload updateFlow(final String flowId, final FlowPayload payload) {
System.out.println("\n==> Northbound Update Flow");
long current = System.currentTimeMillis();
Client client = clientFactory();
Response response = client.target(northboundEndpoint).path("/api/v1/flows").path("{flowid}").resolveTemplate("flowid", flowId).request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, authHeaderValue).header(Utils.CORRELATION_ID, String.valueOf(System.currentTimeMillis())).put(Entity.json(payload));
System.out.println(format("===> Request Payload = %s", Entity.json(payload).getEntity()));
System.out.println(format("===> Response = %s", response.toString()));
System.out.println(format("===> Northbound Update Flow Time: %,.3f", getTimeDuration(current)));
int responseCode = response.getStatus();
if (responseCode == 200) {
FlowPayload flow = response.readEntity(FlowPayload.class);
System.out.println(format("====> Northbound Update Flow = %s", flow));
return flow;
} else {
System.out.println(format("====> Error: Northbound Update Flow = %s", response.readEntity(MessageError.class)));
return null;
}
}
use of org.openkilda.messaging.payload.flow.FlowPayload 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);
}
}
Aggregations