Search in sources :

Example 6 with FlowDto

use of org.openkilda.messaging.model.FlowDto in project open-kilda by telstra.

the class OnFinishedWithErrorAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowSwapEndpointsContext context, FlowSwapEndpointsFsm stateMachine) {
    ErrorData data;
    if (Event.TIMEOUT.equals(event)) {
        data = new ErrorData(ErrorType.OPERATION_TIMED_OUT, getGenericErrorMessage(), "Flow swap endpoints failed by timeout");
    } else if (Event.NEXT.equals(event)) {
        List<String> flows = stateMachine.getFlowResponses().stream().map(FlowResponse::getPayload).map(FlowDto::getFlowId).collect(Collectors.toList());
        data = new ErrorData(ErrorType.UPDATE_FAILURE, getGenericErrorMessage(), format("Reverted flows: %s", flows));
    } else {
        data = (ErrorData) context.getResponse();
    }
    if (!Event.VALIDATION_ERROR.equals(event)) {
        saveActionToHistory(stateMachine, stateMachine.getFirstFlowId(), stateMachine.getSecondFlowId(), data.getErrorDescription());
        saveActionToHistory(stateMachine, stateMachine.getSecondFlowId(), stateMachine.getFirstFlowId(), data.getErrorDescription());
    }
    updateFlowsStatuses(stateMachine);
    CommandContext commandContext = stateMachine.getCommandContext();
    return Optional.of(new ErrorMessage(data, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
Also used : FlowDto(org.openkilda.messaging.model.FlowDto) CommandContext(org.openkilda.wfm.CommandContext) List(java.util.List) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 7 with FlowDto

use of org.openkilda.messaging.model.FlowDto in project open-kilda by telstra.

the class StubServiceFactory method putFlow.

private void putFlow(String flowId, FlowPayload flowPayload) {
    flowPayloads.put(flowId, flowPayload);
    FlowDto forwardFlow = new FlowDto(flowPayload);
    forwardFlow.setMeterId(meterCounter++);
    FlowDto reverseFlow = forwardFlow.toBuilder().sourceSwitch(forwardFlow.getDestinationSwitch()).sourcePort(forwardFlow.getDestinationPort()).sourceVlan(forwardFlow.getDestinationVlan()).destinationSwitch(forwardFlow.getSourceSwitch()).destinationPort(forwardFlow.getSourcePort()).destinationVlan(forwardFlow.getSourceVlan()).build();
    flows.put(flowId, new FlowPairDto<>(forwardFlow, reverseFlow));
}
Also used : FlowDto(org.openkilda.messaging.model.FlowDto)

Example 8 with FlowDto

use of org.openkilda.messaging.model.FlowDto in project open-kilda by telstra.

the class FlowMapperTest method testStatusDetailsMapping.

@Test
public void testStatusDetailsMapping() {
    Flow flow = buildFlow();
    FlowDto flowDto = FlowMapper.INSTANCE.map(flow);
    assertNotNull(flowDto.getFlowStatusDetails());
    assertEquals(FlowPathStatus.ACTIVE, flowDto.getFlowStatusDetails().getMainFlowPathStatus());
    assertEquals(FlowPathStatus.INACTIVE, flowDto.getFlowStatusDetails().getProtectedFlowPathStatus());
    assertDetectConnectedDevices(flowDto.getDetectConnectedDevices(), flow.getDetectConnectedDevices());
}
Also used : FlowDto(org.openkilda.messaging.model.FlowDto) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 9 with FlowDto

use of org.openkilda.messaging.model.FlowDto in project open-kilda by telstra.

the class FlowServiceTest method createFlowLoop.

@Test
public void createFlowLoop() throws Exception {
    String correlationId = "correlation-id";
    RequestCorrelationId.create(correlationId);
    String flowId = "flow-id";
    SwitchId switchId = new SwitchId("1");
    FlowDto dto = FlowDto.builder().flowId(flowId).loopSwitchId(switchId).build();
    FlowResponse response = new FlowResponse(dto);
    messageExchanger.mockResponse(correlationId, response);
    FlowLoopResponse result = flowService.createFlowLoop(flowId, switchId).get();
    assertEquals(flowId, result.getFlowId());
    assertEquals(switchId, result.getSwitchId());
}
Also used : FlowDto(org.openkilda.messaging.model.FlowDto) FlowLoopResponse(org.openkilda.northbound.dto.v2.flows.FlowLoopResponse) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) SwitchId(org.openkilda.model.SwitchId) Test(org.junit.Test)

Aggregations

FlowDto (org.openkilda.messaging.model.FlowDto)9 Test (org.junit.Test)5 Flow (org.openkilda.model.Flow)4 SwitchId (org.openkilda.model.SwitchId)3 List (java.util.List)2 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)2 SwapFlowResponse (org.openkilda.messaging.info.flow.SwapFlowResponse)2 FlowPairDto (org.openkilda.messaging.model.FlowPairDto)2 SwapFlowDto (org.openkilda.messaging.model.SwapFlowDto)2 Instant (java.time.Instant)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Supplier (java.util.function.Supplier)1 Mapper (org.mapstruct.Mapper)1 Mapping (org.mapstruct.Mapping)1 Mappers (org.mapstruct.factory.Mappers)1 ErrorData (org.openkilda.messaging.error.ErrorData)1 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)1 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)1