Search in sources :

Example 21 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException in project open-kilda by telstra.

the class YFlowDeleteHubBolt method onWorkerResponse.

@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
    String operationKey = pullKey(input);
    currentKey = KeyProvider.getParentKey(operationKey);
    SpeakerResponse speakerResponse = pullValue(input, FIELD_ID_PAYLOAD, SpeakerResponse.class);
    try {
        yFlowDeleteService.handleAsyncResponse(currentKey, speakerResponse);
    } catch (UnknownKeyException e) {
        log.error("Received a response with unknown key {}.", currentKey);
    }
}
Also used : SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 22 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException in project open-kilda by telstra.

the class YFlowValidationHubBolt method onWorkerResponse.

@Override
protected void onWorkerResponse(Tuple input) throws PipelineException {
    String operationKey = pullKey(input);
    String flowKey = KeyProvider.getParentKey(operationKey);
    String flowId = KeyProvider.getChildKey(flowKey);
    currentKey = KeyProvider.getParentKey(flowKey);
    MessageData messageData = pullValue(input, FIELD_ID_PAYLOAD, MessageData.class);
    try {
        yFlowValidationHubService.handleAsyncResponse(currentKey, flowId, messageData);
    } catch (UnknownKeyException e) {
        log.warn("Received a response with unknown key {}.", currentKey);
    }
}
Also used : MessageData(org.openkilda.messaging.MessageData) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 23 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException in project open-kilda by telstra.

the class FlowCreateServiceTest method shouldRollbackIfEgressRuleNotInstalled.

@Test
public void shouldRollbackIfEgressRuleNotInstalled() throws Exception {
    when(pathComputer.getPath(any(Flow.class))).thenReturn(make3SwitchesPathPair());
    String key = "failed_flow_create";
    FlowRequest flowRequest = makeRequest().flowId("failed_flow_id").build();
    FlowCreateService service = makeService();
    service.handleRequest(key, new CommandContext(), flowRequest);
    Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
    verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest request;
    int installCommands = 0;
    int deleteCommands = 0;
    while ((request = requests.poll()) != null) {
        try {
            if (request.isVerifyRequest()) {
                service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
            } else if (request.isInstallRequest()) {
                installCommands++;
                if (requests.size() > 1) {
                    handleResponse(service, key, request);
                } else {
                    handleErrorResponse(service, key, request, ErrorCode.UNKNOWN);
                }
            } else if (request.isRemoveRequest()) {
                deleteCommands++;
                handleResponse(service, key, request);
            }
        } catch (UnknownKeyException ex) {
        // skip
        }
    }
    assertEquals("All installed rules should be deleted", installCommands, deleteCommands);
    Flow result = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
    // TODO(surabujin): do we really want to create flow without paths?
    Assert.assertNull(result.getForwardPath());
    Assert.assertNull(result.getReversePath());
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) Test(org.junit.Test)

Example 24 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException in project open-kilda by telstra.

the class FlowCreateServiceTest method testSpeakerCommandRetry.

private void testSpeakerCommandRetry(Class<?> failRequest, ErrorCode error, boolean mustRetry) throws Exception {
    String key = "retries_non_ingress_installation";
    FlowRequest flowRequest = makeRequest().flowId("dummy_flow_id").build();
    int retriesLimit = 10;
    FlowCreateService service = makeService(retriesLimit);
    preparePathComputation(flowRequest.getFlowId(), make2SwitchesPathPair());
    service.handleRequest(key, new CommandContext(), flowRequest);
    Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
    verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
    verifyNorthboundSuccessResponse(carrier);
    Set<UUID> producedErrors = new HashSet<>();
    Map<UUID, Integer> remainingRetries = new HashMap<>();
    Map<UUID, Integer> seenCounter = new HashMap<>();
    FlowSegmentRequest request;
    while ((request = requests.poll()) != null) {
        UUID commandId = request.getCommandId();
        seenCounter.put(commandId, seenCounter.getOrDefault(commandId, 0) + 1);
        Integer remaining = remainingRetries.getOrDefault(commandId, retriesLimit);
        try {
            if (failRequest.isInstance(request) && remaining > 0) {
                producedErrors.add(commandId);
                remainingRetries.put(commandId, remaining - 1);
                handleErrorResponse(service, key, request, error);
            } else if (request.isVerifyRequest()) {
                service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
            } else {
                handleResponse(service, key, request);
            }
        } catch (UnknownKeyException ex) {
        // skip
        }
    }
    Assert.assertFalse(producedErrors.isEmpty());
    for (Map.Entry<UUID, Integer> entry : seenCounter.entrySet()) {
        if (!producedErrors.contains(entry.getKey())) {
            continue;
        }
        Integer counter = entry.getValue();
        if (mustRetry) {
            Assert.assertEquals(retriesLimit + 1, (int) counter);
        } else {
            Assert.assertEquals(1, (int) counter);
        }
    }
    if (mustRetry) {
        Flow result = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.UP);
        verifyFlowPathStatus(result.getForwardPath(), FlowPathStatus.ACTIVE, "forward");
        verifyFlowPathStatus(result.getReversePath(), FlowPathStatus.ACTIVE, "reverse");
    } else {
        verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) HashMap(java.util.HashMap) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 25 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException in project open-kilda by telstra.

the class FlowCreateServiceTest method shouldRollbackIfIngressRuleNotInstalled.

@Test
public void shouldRollbackIfIngressRuleNotInstalled() throws Exception {
    when(pathComputer.getPath(any(Flow.class))).thenReturn(make3SwitchesPathPair());
    String key = "failed_flow_create";
    FlowRequest flowRequest = makeRequest().flowId("failed_flow_id").build();
    FlowCreateService service = makeService();
    service.handleRequest(key, new CommandContext(), flowRequest);
    Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
    verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest request;
    int installCommands = 0;
    int deleteCommands = 0;
    while ((request = requests.poll()) != null) {
        try {
            if (request.isVerifyRequest()) {
                service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
            } else if (request.isInstallRequest()) {
                installCommands++;
                if (requests.size() > 1 || request instanceof EgressFlowSegmentInstallRequest) {
                    handleResponse(service, key, request);
                } else {
                    handleErrorResponse(service, key, request, ErrorCode.UNKNOWN);
                }
            } else if (request.isRemoveRequest()) {
                deleteCommands++;
                handleResponse(service, key, request);
            }
        } catch (UnknownKeyException ex) {
        // skip
        }
    }
    assertEquals("All installed rules should be deleted", installCommands, deleteCommands);
    Flow result = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
    Assert.assertNull(result.getForwardPath());
    Assert.assertNull(result.getReversePath());
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) EgressFlowSegmentInstallRequest(org.openkilda.floodlight.api.request.EgressFlowSegmentInstallRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) Test(org.junit.Test)

Aggregations

UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)49 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)9 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)9 Flow (org.openkilda.model.Flow)7 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)6 Test (org.junit.Test)5 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)5 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)4 FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)4 FlowEndpoint (org.openkilda.model.FlowEndpoint)4 CommandContext (org.openkilda.wfm.CommandContext)4 ErrorData (org.openkilda.messaging.error.ErrorData)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 UUID (java.util.UUID)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)2 Assert (org.junit.Assert)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2