Search in sources :

Example 1 with YFlowValidationResponse

use of org.openkilda.messaging.command.yflow.YFlowValidationResponse in project open-kilda by telstra.

the class YFlowValidationHubServiceTest method verifyNorthboundSuccessResponse.

private void verifyNorthboundSuccessResponse(YFlowValidationHubCarrier carrierMock) {
    YFlowValidationResponse response = getNorthboundResponse(carrierMock);
    assertTrue(response.isAsExpected());
    assertTrue(response.getYFlowValidationResult().isAsExpected());
    response.getSubFlowValidationResults().forEach(result -> assertTrue(result.getAsExpected()));
}
Also used : YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse)

Example 2 with YFlowValidationResponse

use of org.openkilda.messaging.command.yflow.YFlowValidationResponse in project open-kilda by telstra.

the class CompleteYFlowValidationAction method performWithResponse.

@Override
public Optional<Message> performWithResponse(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) throws FlowNotFoundException, SwitchNotFoundException {
    YFlowDiscrepancyDto resourcesValidationResult = validationService.validateYFlowResources(stateMachine.getYFlowId(), stateMachine.getReceivedRules(), stateMachine.getReceivedMeters());
    YFlowValidationResponse result = new YFlowValidationResponse();
    result.setYFlowValidationResult(resourcesValidationResult);
    result.setSubFlowValidationResults(stateMachine.getSubFlowValidationResults());
    boolean notAsExpected = !resourcesValidationResult.isAsExpected() || stateMachine.getSubFlowValidationResults().stream().map(FlowValidationResponse::getAsExpected).anyMatch(n -> !n);
    result.setAsExpected(!notAsExpected);
    CommandContext commandContext = stateMachine.getCommandContext();
    InfoMessage message = new InfoMessage(result, commandContext.getCreateTime(), commandContext.getCorrelationId());
    return Optional.of(message);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) YFlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm) CommandContext(org.openkilda.wfm.CommandContext) YFlowValidationContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationContext) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) NbTrackableAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.NbTrackableAction) YFlowDiscrepancyDto(org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.Event) Optional(java.util.Optional) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) YFlowValidationService(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationService) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.State) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) CommandContext(org.openkilda.wfm.CommandContext) InfoMessage(org.openkilda.messaging.info.InfoMessage) YFlowDiscrepancyDto(org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse)

Example 3 with YFlowValidationResponse

use of org.openkilda.messaging.command.yflow.YFlowValidationResponse in project open-kilda by telstra.

the class YFlowValidationHubServiceTest method getNorthboundResponse.

private YFlowValidationResponse getNorthboundResponse(YFlowValidationHubCarrier carrierMock) {
    ArgumentCaptor<Message> responseCaptor = ArgumentCaptor.forClass(Message.class);
    verify(carrierMock, times(1)).sendNorthboundResponse(responseCaptor.capture());
    Message rawResponse = responseCaptor.getValue();
    assertNotNull(rawResponse);
    assertTrue(rawResponse instanceof InfoMessage);
    InfoData rawPayload = ((InfoMessage) rawResponse).getData();
    assertTrue(rawPayload instanceof YFlowValidationResponse);
    return (YFlowValidationResponse) rawPayload;
}
Also used : YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) InfoMessage(org.openkilda.messaging.info.InfoMessage) InfoData(org.openkilda.messaging.info.InfoData)

Example 4 with YFlowValidationResponse

use of org.openkilda.messaging.command.yflow.YFlowValidationResponse 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

YFlowValidationResponse (org.openkilda.messaging.command.yflow.YFlowValidationResponse)4 Message (org.openkilda.messaging.Message)3 InfoMessage (org.openkilda.messaging.info.InfoMessage)3 InfoData (org.openkilda.messaging.info.InfoData)2 CommandContext (org.openkilda.wfm.CommandContext)2 YFlowValidationService (org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationService)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1