Search in sources :

Example 1 with FlowMirrorPointResponse

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

the class FlowMapperTest method testFlowMirrorPointResponseToFlowMirrorPointCreatePayload.

@Test
public void testFlowMirrorPointResponseToFlowMirrorPointCreatePayload() {
    FlowMirrorPointResponse response = FlowMirrorPointResponse.builder().flowId(FLOW_ID).mirrorPointId(MIRROR_POINT_ID_A).mirrorPointDirection(MIRROR_POINT_DIRECTION_A).mirrorPointSwitchId(SRC_SWITCH_ID).sinkEndpoint(FlowEndpoint.builder().switchId(DST_SWITCH_ID).portNumber(DST_PORT).outerVlanId(DST_VLAN).innerVlanId(DST_INNER_VLAN).build()).build();
    FlowMirrorPointResponseV2 apiResponse = flowMapper.toFlowMirrorPointResponseV2(response);
    assertEquals(response.getFlowId(), apiResponse.getFlowId());
    assertEquals(response.getMirrorPointId(), apiResponse.getMirrorPointId());
    assertEquals(response.getMirrorPointDirection(), apiResponse.getMirrorPointDirection());
    assertEquals(response.getMirrorPointSwitchId(), apiResponse.getMirrorPointSwitchId());
    assertEquals(response.getSinkEndpoint().getSwitchId(), apiResponse.getSinkEndpoint().getSwitchId());
    assertEquals(response.getSinkEndpoint().getPortNumber(), apiResponse.getSinkEndpoint().getPortNumber());
    assertEquals(response.getSinkEndpoint().getOuterVlanId(), apiResponse.getSinkEndpoint().getVlanId());
    assertEquals(response.getSinkEndpoint().getInnerVlanId(), apiResponse.getSinkEndpoint().getInnerVlanId());
}
Also used : FlowMirrorPointResponse(org.openkilda.messaging.info.flow.FlowMirrorPointResponse) FlowMirrorPointResponseV2(org.openkilda.northbound.dto.v2.flows.FlowMirrorPointResponseV2) Test(org.junit.Test)

Example 2 with FlowMirrorPointResponse

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

the class ValidateRequestAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    PathId mirrorPathId = new PathId(context.getFlowMirrorPointId());
    stateMachine.setMirrorPathId(mirrorPathId);
    dashboardLogger.onFlowMirrorPointDelete(flowId, context.getFlowMirrorPointId());
    FlowMirrorPointResponse response = transactionManager.doInTransaction(() -> {
        Flow foundFlow = getFlow(flowId);
        if (foundFlow.getStatus() == FlowStatus.IN_PROGRESS) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is in progress now", flowId));
        }
        stateMachine.setFlowStatus(foundFlow.getStatus());
        flowRepository.updateStatus(flowId, FlowStatus.IN_PROGRESS);
        FlowMirrorPath flowMirrorPath = flowMirrorPathRepository.findById(mirrorPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror point %s not found", mirrorPathId)));
        if (flowMirrorPath.getStatus() == FlowPathStatus.IN_PROGRESS) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow mirror point %s is in progress now", mirrorPathId));
        }
        stateMachine.setOriginalFlowMirrorPathStatus(flowMirrorPath.getStatus());
        flowMirrorPathRepository.updateStatus(mirrorPathId, FlowPathStatus.IN_PROGRESS);
        String direction = flowMirrorPath.getFlowMirrorPoints().getFlowPath().isForward() ? "forward" : "reverse";
        return FlowMirrorPointResponse.builder().flowId(foundFlow.getFlowId()).mirrorPointId(flowMirrorPath.getPathId().getId()).mirrorPointDirection(direction).mirrorPointSwitchId(flowMirrorPath.getMirrorSwitchId()).sinkEndpoint(FlowEndpoint.builder().switchId(flowMirrorPath.getEgressSwitchId()).portNumber(flowMirrorPath.getEgressPort()).innerVlanId(flowMirrorPath.getEgressInnerVlan()).outerVlanId(flowMirrorPath.getEgressOuterVlan()).build()).build();
    });
    stateMachine.saveNewEventToHistory("Flow was validated successfully", FlowEventData.Event.FLOW_MIRROR_POINT_DELETE);
    CommandContext commandContext = stateMachine.getCommandContext();
    return Optional.of(new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
Also used : PathId(org.openkilda.model.PathId) FlowMirrorPointResponse(org.openkilda.messaging.info.flow.FlowMirrorPointResponse) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow)

Example 3 with FlowMirrorPointResponse

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

the class PostResourceAllocationAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    PathId flowMirrorPathId = stateMachine.getMirrorPathId();
    FlowMirrorPath flowMirrorPath = flowMirrorPathRepository.findById(flowMirrorPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror path %s not found", flowMirrorPathId)));
    String direction = flowMirrorPath.getFlowMirrorPoints().getFlowPath().isForward() ? "forward" : "reverse";
    FlowMirrorPointResponse response = FlowMirrorPointResponse.builder().flowId(flow.getFlowId()).mirrorPointId(flowMirrorPath.getPathId().getId()).mirrorPointDirection(direction).mirrorPointSwitchId(flowMirrorPath.getMirrorSwitchId()).sinkEndpoint(FlowEndpoint.builder().switchId(flowMirrorPath.getEgressSwitchId()).portNumber(flowMirrorPath.getEgressPort()).outerVlanId(flowMirrorPath.getEgressOuterVlan()).innerVlanId(flowMirrorPath.getEgressInnerVlan()).build()).build();
    CommandContext commandContext = stateMachine.getCommandContext();
    return Optional.of(new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
Also used : PathId(org.openkilda.model.PathId) FlowMirrorPointResponse(org.openkilda.messaging.info.flow.FlowMirrorPointResponse) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow)

Aggregations

FlowMirrorPointResponse (org.openkilda.messaging.info.flow.FlowMirrorPointResponse)3 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 Flow (org.openkilda.model.Flow)2 FlowMirrorPath (org.openkilda.model.FlowMirrorPath)2 PathId (org.openkilda.model.PathId)2 CommandContext (org.openkilda.wfm.CommandContext)2 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)2 Test (org.junit.Test)1 FlowMirrorPointResponseV2 (org.openkilda.northbound.dto.v2.flows.FlowMirrorPointResponseV2)1