Search in sources :

Example 26 with CommandData

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

the class YFlowReadBolt method handleInput.

protected void handleInput(Tuple input) throws Exception {
    String requestId = getCommandContext().getCorrelationId();
    CommandData request = pullValue(input, FIELD_ID_PAYLOAD, CommandData.class);
    try {
        if (request instanceof YFlowsDumpRequest) {
            List<YFlowResponse> result = processYFlowDumpRequest();
            emitMessages(input, requestId, result);
        } else if (request instanceof YFlowReadRequest) {
            YFlowResponse result = processYFlowReadRequest((YFlowReadRequest) request);
            emitMessage(input, requestId, result);
        } else if (request instanceof YFlowPathsReadRequest) {
            YFlowPathsResponse result = processYFlowPathsReadRequest((YFlowPathsReadRequest) request);
            emitMessage(input, requestId, result);
        } else if (request instanceof SubFlowsReadRequest) {
            SubFlowsResponse result = processSubFlowsReadRequest((SubFlowsReadRequest) request);
            emitMessage(input, requestId, result);
        } else {
            unhandledInput(input);
        }
    } catch (MessageException e) {
        ErrorData errorData = new ErrorData(e.getErrorType(), e.getMessage(), e.getErrorDescription());
        Message message = new ErrorMessage(errorData, System.currentTimeMillis(), requestId);
        emit(input, new Values(requestId, message));
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) ChunkedInfoMessage(org.openkilda.messaging.info.ChunkedInfoMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) Values(org.apache.storm.tuple.Values) YFlowsDumpRequest(org.openkilda.messaging.command.yflow.YFlowsDumpRequest) MessageException(org.openkilda.messaging.error.MessageException) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) YFlowReadRequest(org.openkilda.messaging.command.yflow.YFlowReadRequest) SubFlowsResponse(org.openkilda.messaging.command.yflow.SubFlowsResponse) ErrorData(org.openkilda.messaging.error.ErrorData) YFlowPathsReadRequest(org.openkilda.messaging.command.yflow.YFlowPathsReadRequest) SubFlowsReadRequest(org.openkilda.messaging.command.yflow.SubFlowsReadRequest) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse)

Example 27 with CommandData

use of org.openkilda.messaging.command.CommandData 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 28 with CommandData

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

the class FlowValidationHubServiceTest method testTimeout.

@Test
public void testTimeout() throws DuplicateKeyException, UnknownKeyException {
    FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {

        @Override
        public void sendSpeakerRequest(String flowId, CommandData commandData) {
            assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
            List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
            if (commandData instanceof DumpRulesForFlowHsRequest) {
                assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
            } else if (commandData instanceof DumpMetersForFlowHsRequest) {
                assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
            } else {
                assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
            }
        }

        @Override
        public void sendNorthboundResponse(List<? extends InfoData> message) {
            fail();
        }

        @Override
        public void sendNorthboundResponse(Message message) {
            assertEquals(ErrorType.OPERATION_TIMED_OUT, ((ErrorMessage) message).getData().getErrorType());
        }

        @Override
        public void cancelTimeoutCallback(String key) {
            assertEquals(TEST_KEY, key);
        }

        @Override
        public void sendInactive() {
        }
    };
    flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
    buildTransitVlanFlow("");
    flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
    flowValidationHubService.handleTimeout(TEST_KEY);
}
Also used : DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) Message(org.openkilda.messaging.Message) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandContext(org.openkilda.wfm.CommandContext) SwitchId(org.openkilda.model.SwitchId) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) FlowValidationRequest(org.openkilda.messaging.command.flow.FlowValidationRequest) InfoData(org.openkilda.messaging.info.InfoData) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) List(java.util.List) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) Test(org.junit.Test)

Example 29 with CommandData

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

the class FlowValidationHubServiceTest method testFlowNotFoundError.

@Test
public void testFlowNotFoundError() throws DuplicateKeyException, UnknownKeyException {
    FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {

        @Override
        public void sendSpeakerRequest(String flowId, CommandData commandData) {
            assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
            List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
            if (commandData instanceof DumpRulesForFlowHsRequest) {
                assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
            } else if (commandData instanceof DumpMetersForFlowHsRequest) {
                assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
            } else {
                assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
            }
        }

        @Override
        public void sendNorthboundResponse(List<? extends InfoData> message) {
            fail();
        }

        @Override
        public void sendNorthboundResponse(Message message) {
            assertEquals(ErrorType.NOT_FOUND, ((ErrorMessage) message).getData().getErrorType());
        }

        @Override
        public void cancelTimeoutCallback(String key) {
            assertEquals(TEST_KEY, key);
        }

        @Override
        public void sendInactive() {
        }
    };
    flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
    buildTransitVlanFlow("");
    flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest("test"));
    flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
    transactionManager.doInTransaction(() -> flowRepository.remove(flowRepository.findById(TEST_FLOW_ID_A).get()));
    for (SwitchFlowEntries switchFlowEntries : getSwitchFlowEntriesWithTransitVlan()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchFlowEntries);
    }
    for (SwitchMeterEntries switchMeterEntries : getSwitchMeterEntries()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchMeterEntries);
    }
    for (SwitchGroupEntries switchGroupEntries : getSwitchGroupEntries()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchGroupEntries);
    }
}
Also used : DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) Message(org.openkilda.messaging.Message) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandContext(org.openkilda.wfm.CommandContext) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) SwitchId(org.openkilda.model.SwitchId) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) FlowValidationRequest(org.openkilda.messaging.command.flow.FlowValidationRequest) InfoData(org.openkilda.messaging.info.InfoData) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) List(java.util.List) CommandData(org.openkilda.messaging.command.CommandData) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) Test(org.junit.Test)

Example 30 with CommandData

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

the class FlowStateCacheBolt method handleInput.

@Override
protected void handleInput(Tuple input) throws PipelineException {
    if (active) {
        if (ComponentId.TICK_BOLT.name().equals(input.getSourceComponent())) {
            flowStateCacheService.getFlows().forEach(flowId -> emit(input, new Values(flowId, getCommandContext())));
            return;
        }
        if (FLOW_UPDATE_STREAM_ID.name().equals(input.getSourceStreamId())) {
            CommandData payload = pullValue(input, COMMAND_DATA_FIELD, CommandData.class);
            if (payload instanceof UpdateFlowCommand) {
                UpdateFlowCommand updateFlowCommand = (UpdateFlowCommand) payload;
                flowStateCacheService.updateFlow(updateFlowCommand);
                emit(FLOW_UPDATE_STREAM_ID.name(), input, new Values(updateFlowCommand.getFlowId(), updateFlowCommand, getCommandContext()));
            } else {
                unhandledInput(input);
            }
            return;
        }
        if (FLOW_REMOVE_STREAM_ID.name().equals(input.getSourceStreamId())) {
            String flowId = pullValue(input, FLOW_ID_FIELD, String.class);
            flowStateCacheService.removeFlow(flowId);
            emit(FLOW_REMOVE_STREAM_ID.name(), input, new Values(flowId, getCommandContext()));
        } else {
            unhandledInput(input);
        }
    }
}
Also used : UpdateFlowCommand(org.openkilda.messaging.info.flow.UpdateFlowCommand) Values(org.apache.storm.tuple.Values) CommandData(org.openkilda.messaging.command.CommandData)

Aggregations

CommandData (org.openkilda.messaging.command.CommandData)35 CommandMessage (org.openkilda.messaging.command.CommandMessage)14 Values (org.apache.storm.tuple.Values)12 Message (org.openkilda.messaging.Message)11 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)11 InfoData (org.openkilda.messaging.info.InfoData)7 Test (org.junit.Test)6 InfoMessage (org.openkilda.messaging.info.InfoMessage)6 DiscoverIslCommandData (org.openkilda.messaging.command.discovery.DiscoverIslCommandData)5 DumpGroupsForFlowHsRequest (org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest)5 DumpMetersForFlowHsRequest (org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest)5 DumpRulesForFlowHsRequest (org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest)5 SwitchId (org.openkilda.model.SwitchId)5 IOException (java.io.IOException)4 List (java.util.List)4 DiscoverPathCommandData (org.openkilda.messaging.command.discovery.DiscoverPathCommandData)4 FlowCreateRequest (org.openkilda.messaging.command.flow.FlowCreateRequest)4 ErrorData (org.openkilda.messaging.error.ErrorData)4 NetworkCommandData (org.openkilda.messaging.command.discovery.NetworkCommandData)3 BaseInstallFlow (org.openkilda.messaging.command.flow.BaseInstallFlow)3