Search in sources :

Example 16 with DuplicateKeyException

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

the class FlowValidationHubBolt method onRequest.

@Override
protected void onRequest(Tuple input) throws PipelineException {
    currentKey = pullKey(input);
    FlowValidationRequest payload = pullValue(input, FIELD_ID_PAYLOAD, FlowValidationRequest.class);
    try {
        service.handleFlowValidationRequest(currentKey, getCommandContext(), payload);
    } catch (DuplicateKeyException e) {
        log.error("Failed to handle a request with key {}. {}", currentKey, e.getMessage());
    }
}
Also used : FlowValidationRequest(org.openkilda.messaging.command.flow.FlowValidationRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 17 with DuplicateKeyException

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

the class YFlowCreateHubBolt method onRequest.

@Override
protected void onRequest(Tuple input) throws PipelineException {
    currentKey = pullKey(input);
    YFlowRequest payload = pullValue(input, FIELD_ID_PAYLOAD, YFlowRequest.class);
    try {
        yFlowCreateService.handleRequest(currentKey, getCommandContext(), payload);
    } catch (DuplicateKeyException e) {
        log.error("Failed to handle a request with key {}. {}", currentKey, e.getMessage());
    }
}
Also used : YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 18 with DuplicateKeyException

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

the class YFlowUpdateHubBolt method onRequest.

@Override
protected void onRequest(Tuple input) throws PipelineException {
    currentKey = pullKey(input);
    CommandData payload = pullValue(input, FIELD_ID_PAYLOAD, CommandData.class);
    try {
        if (payload instanceof YFlowRequest) {
            yflowUpdateService.handleRequest(currentKey, pullContext(input), (YFlowRequest) payload);
        } else if (payload instanceof YFlowPartialUpdateRequest) {
            yflowUpdateService.handlePartialUpdateRequest(currentKey, pullContext(input), (YFlowPartialUpdateRequest) payload);
        } else {
            unhandledInput(input);
        }
    } catch (DuplicateKeyException e) {
        log.error("Failed to handle a request with key {}. {}", currentKey, e.getMessage());
    } catch (FlowProcessingException e) {
        ErrorData errorData = new ErrorData(e.getErrorType(), "Y-flow update error", e.getMessage());
        CommandContext commandContext = getCommandContext();
        ErrorMessage errorMessage = new ErrorMessage(errorData, commandContext.getCreateTime(), commandContext.getCorrelationId());
        sendNorthboundResponse(errorMessage);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) YFlowPartialUpdateRequest(org.openkilda.messaging.command.yflow.YFlowPartialUpdateRequest) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ErrorData(org.openkilda.messaging.error.ErrorData) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 19 with DuplicateKeyException

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

the class FlowCreateHubBolt method onRequest.

@Override
protected void onRequest(Tuple input) throws PipelineException {
    currentKey = pullKey(input);
    FlowRequest payload = pullValue(input, FIELD_ID_PAYLOAD, FlowRequest.class);
    try {
        service.handleRequest(currentKey, getCommandContext(), payload);
    } catch (DuplicateKeyException e) {
        log.error("Failed to handle a request with key {}. {}", currentKey, e.getMessage());
    }
}
Also used : FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)

Example 20 with DuplicateKeyException

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

the class YFlowValidationHubServiceTest method shouldValidateAndFailIfSubFlowHasMissingRule.

@Test
public void shouldValidateAndFailIfSubFlowHasMissingRule() throws DuplicateKeyException {
    // given
    String yFlowId = "test_y_flow_1";
    YFlow yFlow = createYFlowViaTransit(yFlowId);
    YSubFlow failedSubFlow = yFlow.getSubFlows().stream().findFirst().orElseThrow(IllegalStateException::new);
    Flow failedFlow = failedSubFlow.getFlow();
    YFlowSwitchFlowEntriesBuilder flowEntriesBuilder = new YFlowSwitchFlowEntriesBuilder(yFlow, persistenceManager.getRepositoryFactory().createTransitVlanRepository(), persistenceManager.getRepositoryFactory().createVxlanRepository());
    Map<SwitchId, Collection<FlowEntry>> flowEntries = flowEntriesBuilder.getFlowEntries();
    flowEntries.forEach((s, f) -> f.removeIf(entry -> entry.getCookie() == failedFlow.getForwardPath().getCookie().getValue()));
    Map<SwitchId, Collection<MeterEntry>> meterEntries = flowEntriesBuilder.getMeterEntries();
    Map<SwitchId, Collection<GroupEntry>> groupEntries = flowEntriesBuilder.getGroupEntries();
    YFlowValidationHubService service = makeYFlowValidationHubService();
    service.handleRequest(yFlow.getYFlowId(), new CommandContext(), yFlow.getYFlowId());
    // when
    handleSpeakerRequests(service, yFlowId, flowEntries, meterEntries, groupEntries);
    // then
    YFlowValidationResponse response = getNorthboundResponse(yFlowValidationHubCarrier);
    assertFalse(response.isAsExpected());
    assertFalse(response.getYFlowValidationResult().isAsExpected());
    response.getSubFlowValidationResults().forEach(result -> assertTrue(result.getFlowId().equals(failedFlow.getFlowId()) || result.getAsExpected()));
    assertEquals(1, response.getSubFlowValidationResults().stream().filter(r -> !r.getAsExpected()).count());
}
Also used : YFlow(org.openkilda.model.YFlow) InfoMessage(org.openkilda.messaging.info.InfoMessage) Flow(org.openkilda.model.Flow) Pair(org.apache.commons.lang3.tuple.Pair) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) FlowValidationHubCarrier(org.openkilda.wfm.topology.flowhs.service.FlowValidationHubCarrier) Assert.fail(org.junit.Assert.fail) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) YFlowSwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowSwitchFlowEntriesBuilder) YSubFlow(org.openkilda.model.YSubFlow) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) InfoData(org.openkilda.messaging.info.InfoData) CommandContext(org.openkilda.wfm.CommandContext) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) BURST_COEFFICIENT(org.openkilda.wfm.topology.flowhs.fsm.validation.SwitchFlowEntriesBuilder.BURST_COEFFICIENT) Assert.assertFalse(org.junit.Assert.assertFalse) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CommandData(org.openkilda.messaging.command.CommandData) Message(org.openkilda.messaging.Message) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) MeterEntry(org.openkilda.messaging.info.meter.MeterEntry) ArrayList(java.util.ArrayList) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) ArgumentCaptor(org.mockito.ArgumentCaptor) YFlow(org.openkilda.model.YFlow) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException) Assert.assertNotNull(org.junit.Assert.assertNotNull) ErrorType(org.openkilda.messaging.error.ErrorType) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) FlowValidationHubService(org.openkilda.wfm.topology.flowhs.service.FlowValidationHubService) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) SwitchId(org.openkilda.model.SwitchId) MIN_BURST_SIZE_IN_KBITS(org.openkilda.wfm.topology.flowhs.fsm.validation.SwitchFlowEntriesBuilder.MIN_BURST_SIZE_IN_KBITS) YFlowValidationService(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationService) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest) Assert.assertEquals(org.junit.Assert.assertEquals) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) CommandContext(org.openkilda.wfm.CommandContext) SwitchId(org.openkilda.model.SwitchId) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) YFlow(org.openkilda.model.YFlow) Collection(java.util.Collection) YFlowSwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowSwitchFlowEntriesBuilder) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Aggregations

DuplicateKeyException (org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException)21 Before (org.junit.Before)3 Test (org.junit.Test)3 RunWith (org.junit.runner.RunWith)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 Mock (org.mockito.Mock)3 Mockito.doAnswer (org.mockito.Mockito.doAnswer)3 Mockito.times (org.mockito.Mockito.times)3 Mockito.verify (org.mockito.Mockito.verify)3 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)3 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)3 CommandContext (org.openkilda.wfm.CommandContext)3 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Ignore (org.junit.Ignore)2 ArgumentMatchers (org.mockito.ArgumentMatchers)2 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)2 Mockito.doThrow (org.mockito.Mockito.doThrow)2 Mockito.when (org.mockito.Mockito.when)2