Search in sources :

Example 1 with FlowResponse

use of org.openkilda.messaging.info.flow.FlowResponse in project open-kilda by telstra.

the class FlowTopologyTest method getFlowCommand.

private Flow getFlowCommand(final String flowId) throws IOException {
    System.out.println("TOPOLOGY: Get flow");
    Flow flowPayload = new Flow(flowId, 10000, false, "", "test-switch", 1, 2, "test-switch", 1, 2);
    FlowResponse infoData = new FlowResponse(flowPayload);
    InfoMessage infoMessage = new InfoMessage(infoData, 0, "get-flow", Destination.WFM);
    sendTopologyEngineMessage(infoMessage);
    return flowPayload;
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) Flow(org.openkilda.messaging.model.Flow) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow)

Example 2 with FlowResponse

use of org.openkilda.messaging.info.flow.FlowResponse in project open-kilda by telstra.

the class FlowTopologyTest method getFlowTest.

@Test
public void getFlowTest() throws Exception {
    String flowId = UUID.randomUUID().toString();
    ConsumerRecord<String, String> record;
    Flow flow = createFlow(flowId);
    flow.setCookie(1);
    flow.setFlowPath(new PathInfoData(0L, Collections.emptyList()));
    flow.setMeterId(1);
    flow.setTransitVlan(2);
    flow.setState(FlowState.ALLOCATED);
    record = cacheConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    getFlow(flowId);
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    InfoMessage infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    FlowResponse infoData = (FlowResponse) infoMessage.getData();
    assertNotNull(infoData);
    Flow flowTePayload = infoData.getPayload();
    assertEquals(flow, flowTePayload);
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) Flow(org.openkilda.messaging.model.Flow) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 3 with FlowResponse

use of org.openkilda.messaging.info.flow.FlowResponse in project open-kilda by telstra.

the class FlowTopologyTest method updateFlowCommandBoltTest.

@Test
public void updateFlowCommandBoltTest() throws Exception {
    String flowId = UUID.randomUUID().toString();
    ConsumerRecord<String, String> record;
    createFlow(flowId);
    record = cacheConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    updateFlow(flowId);
    record = cacheConsumer.pollMessage();
    assertNotNull(record);
    InfoMessage message = objectMapper.readValue(record.value(), InfoMessage.class);
    assertNotNull(message);
    ImmutablePair<Flow, Flow> flow = getFlowPayload(message);
    assertNotNull(flow);
    Flow flowTePayload = flow.getLeft();
    record = nbConsumer.pollMessage();
    assertNotNull(record);
    assertNotNull(record.value());
    InfoMessage infoMessage = objectMapper.readValue(record.value(), InfoMessage.class);
    FlowResponse payload = (FlowResponse) infoMessage.getData();
    assertNotNull(payload);
    Flow flowNbPayload = payload.getPayload();
    assertEquals(flowNbPayload, flowTePayload);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) Flow(org.openkilda.messaging.model.Flow) InstallOneSwitchFlow(org.openkilda.messaging.command.flow.InstallOneSwitchFlow) AbstractStormTest(org.openkilda.wfm.AbstractStormTest) Test(org.junit.Test)

Example 4 with FlowResponse

use of org.openkilda.messaging.info.flow.FlowResponse in project open-kilda by telstra.

the class FlowServiceImpl method getFlow.

/**
 * {@inheritDoc}
 */
@Override
public InfoMessage getFlow(final FlowIdStatusPayload payload, final String correlationId) {
    Set<Flow> flows = flowRepository.findByFlowId(payload.getId());
    if (flows == null || flows.isEmpty()) {
        logger.error("Flow with id={} not found", payload.getId());
        throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
    }
    FlowResponse response = null;
    for (Flow flow : flows) {
        if ((flow.getCookie() & DIRECT_FLOW_COOKIE) == DIRECT_FLOW_COOKIE) {
            response = new FlowResponse(getFlowPayloadByFlow(flow));
        }
    }
    logger.debug("Flow with id={} get: {}", payload.getId(), response);
    return new InfoMessage(response, System.currentTimeMillis(), correlationId, Destination.WFM);
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) Flow(org.openkilda.topology.domain.Flow)

Example 5 with FlowResponse

use of org.openkilda.messaging.info.flow.FlowResponse in project open-kilda by telstra.

the class FlowServiceImpl method updateFlow.

/**
 * {@inheritDoc}
 */
@Override
public FlowPayload updateFlow(final FlowPayload flow, final String correlationId) {
    LOGGER.debug("Update flow: {}={}", CORRELATION_ID, correlationId);
    FlowUpdateRequest data = new FlowUpdateRequest(Converter.buildFlowByFlowPayload(flow));
    CommandMessage request = new CommandMessage(data, System.currentTimeMillis(), correlationId, Destination.WFM);
    messageConsumer.clear();
    messageProducer.send(topic, request);
    Message message = (Message) messageConsumer.poll(correlationId);
    FlowResponse response = (FlowResponse) validateInfoMessage(request, message, correlationId);
    return Converter.buildFlowPayloadByFlow(response.getPayload());
}
Also used : FlowUpdateRequest(org.openkilda.messaging.command.flow.FlowUpdateRequest) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Aggregations

InfoMessage (org.openkilda.messaging.info.InfoMessage)12 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)12 Test (org.junit.Test)6 InstallOneSwitchFlow (org.openkilda.messaging.command.flow.InstallOneSwitchFlow)6 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)6 Flow (org.openkilda.messaging.model.Flow)6 Message (org.openkilda.messaging.Message)5 CommandMessage (org.openkilda.messaging.command.CommandMessage)5 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)5 Ignore (org.junit.Ignore)1 FlowCreateRequest (org.openkilda.messaging.command.flow.FlowCreateRequest)1 FlowGetRequest (org.openkilda.messaging.command.flow.FlowGetRequest)1 FlowUpdateRequest (org.openkilda.messaging.command.flow.FlowUpdateRequest)1 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)1 MessageException (org.openkilda.messaging.error.MessageException)1 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)1 FlowIdStatusPayload (org.openkilda.messaging.payload.flow.FlowIdStatusPayload)1 Flow (org.openkilda.topology.domain.Flow)1