Search in sources :

Example 1 with YFlowPingResponse

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

the class YFlowMapperTest method pingResultTest.

@Test
public void pingResultTest() {
    YFlowPingResponse response = new YFlowPingResponse(Y_FLOW_ID, false, ERROR_MESSAGE, Lists.newArrayList(new SubFlowPingPayload(SUB_FLOW_1, new UniSubFlowPingPayload(true, null, 1), new UniSubFlowPingPayload(false, Errors.TIMEOUT, 2)), new SubFlowPingPayload(SUB_FLOW_2, new UniSubFlowPingPayload(false, Errors.DEST_NOT_AVAILABLE, 3), new UniSubFlowPingPayload(true, null, 4))));
    YFlowPingResult result = mapper.toPingResult(response);
    assertEquals(response.getYFlowId(), result.getYFlowId());
    assertEquals(response.isPingSuccess(), result.isPingSuccess());
    assertEquals(response.getError(), result.getError());
    assertEquals(response.getSubFlows().size(), result.getSubFlows().size());
    assertSubFlowPingPayload(response.getSubFlows().get(0), result.getSubFlows().get(0));
}
Also used : YFlowPingResult(org.openkilda.northbound.dto.v2.yflows.YFlowPingResult) UniSubFlowPingPayload(org.openkilda.messaging.info.flow.UniSubFlowPingPayload) YFlowPingResponse(org.openkilda.messaging.info.flow.YFlowPingResponse) UniSubFlowPingPayload(org.openkilda.messaging.info.flow.UniSubFlowPingPayload) SubFlowPingPayload(org.openkilda.messaging.info.flow.SubFlowPingPayload) Test(org.junit.Test)

Example 2 with YFlowPingResponse

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

the class OnDemandResultManager method buildYFlowPingResponse.

private YFlowPingResponse buildYFlowPingResponse(Group group) {
    Map<String, SubFlowPingPayload> subFlowMap = new HashMap<>();
    Set<String> yFlowIdSet = new HashSet<>();
    for (PingContext record : group.getRecords()) {
        if (record.getYFlowId() == null) {
            throw new IllegalArgumentException(format("Ping report %s has no yFlowId", record));
        }
        yFlowIdSet.add(record.getYFlowId());
        SubFlowPingPayload subFlow = subFlowMap.computeIfAbsent(record.getFlowId(), mappingFunction -> new SubFlowPingPayload(record.getFlowId(), null, null));
        switch(record.getDirection()) {
            case FORWARD:
                validateSubFlow(subFlow.getForward(), FORWARD, group, record, subFlow.getFlowId());
                subFlow.setForward(makeSubFlowPayload(record));
                break;
            case REVERSE:
                validateSubFlow(subFlow.getReverse(), REVERSE, group, record, subFlow.getFlowId());
                subFlow.setReverse(makeSubFlowPayload(record));
                break;
            default:
                throw new IllegalArgumentException(format("Unsupported %s.%s value", record.getDirection().getClass().getName(), record.getDirection()));
        }
    }
    if (subFlowMap.size() * 2 != group.getRecords().size()) {
        throw new IllegalArgumentException(format("Expect %d unique Flow IDs in ping group responses, but got responses about %d Flows: %s", group.getRecords().size() / 2, subFlowMap.size(), subFlowMap.keySet()));
    }
    if (yFlowIdSet.size() != 1) {
        throw new IllegalArgumentException(format("Expect exact one Y Flow id in pings group response, got - %s", yFlowIdSet));
    }
    return new YFlowPingResponse(yFlowIdSet.iterator().next(), null, new ArrayList<>(subFlowMap.values()));
}
Also used : HashMap(java.util.HashMap) YFlowPingResponse(org.openkilda.messaging.info.flow.YFlowPingResponse) PingContext(org.openkilda.wfm.topology.ping.model.PingContext) UniSubFlowPingPayload(org.openkilda.messaging.info.flow.UniSubFlowPingPayload) SubFlowPingPayload(org.openkilda.messaging.info.flow.SubFlowPingPayload) HashSet(java.util.HashSet)

Example 3 with YFlowPingResponse

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

the class FlowFetcher method emitOnDemandYFlowResponse.

private void emitOnDemandYFlowResponse(Tuple input, YFlowPingRequest request, String errorMessage) throws PipelineException {
    YFlowPingResponse response = new YFlowPingResponse(request.getYFlowId(), false, errorMessage, null);
    getOutput().emit(STREAM_ON_DEMAND_Y_FLOW_RESPONSE_ID, input, new Values(response, pullContext(input)));
}
Also used : YFlowPingResponse(org.openkilda.messaging.info.flow.YFlowPingResponse) Values(org.apache.storm.tuple.Values)

Example 4 with YFlowPingResponse

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

the class OnDemandResultManager method handleYFlowResponse.

private void handleYFlowResponse(Tuple input, Group group) throws PipelineException {
    try {
        YFlowPingResponse response = buildYFlowPingResponse(group);
        emit(input, response);
    } catch (IllegalArgumentException e) {
        String yFlowId = group.getRecords().stream().map(PingContext::getYFlowId).filter(Objects::nonNull).findFirst().orElse(null);
        YFlowPingResponse errorResponse = new YFlowPingResponse(yFlowId, e.getMessage(), null);
        emit(input, errorResponse);
    }
}
Also used : YFlowPingResponse(org.openkilda.messaging.info.flow.YFlowPingResponse) PingContext(org.openkilda.wfm.topology.ping.model.PingContext)

Aggregations

YFlowPingResponse (org.openkilda.messaging.info.flow.YFlowPingResponse)4 SubFlowPingPayload (org.openkilda.messaging.info.flow.SubFlowPingPayload)2 UniSubFlowPingPayload (org.openkilda.messaging.info.flow.UniSubFlowPingPayload)2 PingContext (org.openkilda.wfm.topology.ping.model.PingContext)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Values (org.apache.storm.tuple.Values)1 Test (org.junit.Test)1 YFlowPingResult (org.openkilda.northbound.dto.v2.yflows.YFlowPingResult)1