Search in sources :

Example 1 with FlowValidator

use of org.openkilda.wfm.topology.flow.validation.FlowValidator in project open-kilda by telstra.

the class CrudBolt method handleUpdateRequest.

private void handleUpdateRequest(CommandMessage message, Tuple tuple) throws IOException {
    Flow requestedFlow = ((FlowUpdateRequest) message.getData()).getPayload();
    ImmutablePair<PathInfoData, PathInfoData> path;
    try {
        new FlowValidator(flowCache).checkFlowForEndpointConflicts(requestedFlow);
        path = pathComputer.getPath(requestedFlow, Strategy.COST);
        logger.info("Updated flow path: {}", path);
    } catch (FlowValidationException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.UPDATE_FAILURE, "Could not update flow", e.getMessage());
    } catch (UnroutablePathException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.UPDATE_FAILURE, "Could not update flow", "Path was not found");
    }
    ImmutablePair<Flow, Flow> flow = flowCache.updateFlow(requestedFlow, path);
    logger.info("Updated flow: {}", flow);
    FlowInfoData data = new FlowInfoData(requestedFlow.getFlowId(), flow, FlowOperation.UPDATE, message.getCorrelationId());
    InfoMessage infoMessage = new InfoMessage(data, System.currentTimeMillis(), message.getCorrelationId());
    Values topology = new Values(MAPPER.writeValueAsString(infoMessage));
    outputCollector.emit(StreamType.UPDATE.toString(), tuple, topology);
    Values northbound = new Values(new InfoMessage(new FlowResponse(buildFlowResponse(flow)), message.getTimestamp(), message.getCorrelationId(), Destination.NORTHBOUND));
    outputCollector.emit(StreamType.RESPONSE.toString(), tuple, northbound);
}
Also used : FlowUpdateRequest(org.openkilda.messaging.command.flow.FlowUpdateRequest) Values(org.apache.storm.tuple.Values) UnroutablePathException(org.openkilda.pce.provider.UnroutablePathException) Flow(org.openkilda.messaging.model.Flow) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowValidationException(org.openkilda.wfm.topology.flow.validation.FlowValidationException) MessageException(org.openkilda.messaging.error.MessageException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowValidator(org.openkilda.wfm.topology.flow.validation.FlowValidator)

Example 2 with FlowValidator

use of org.openkilda.wfm.topology.flow.validation.FlowValidator in project open-kilda by telstra.

the class CrudBolt method handleCreateRequest.

private void handleCreateRequest(CommandMessage message, Tuple tuple) throws IOException {
    Flow requestedFlow = ((FlowCreateRequest) message.getData()).getPayload();
    ImmutablePair<PathInfoData, PathInfoData> path;
    try {
        new FlowValidator(flowCache).checkFlowForEndpointConflicts(requestedFlow);
        path = pathComputer.getPath(requestedFlow, Strategy.COST);
        logger.info("Created flow path: {}", path);
    } catch (FlowValidationException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.CREATION_FAILURE, "Could not create flow", e.getMessage());
    } catch (UnroutablePathException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.CREATION_FAILURE, "Could not create flow", "Path was not found");
    }
    ImmutablePair<Flow, Flow> flow = flowCache.createFlow(requestedFlow, path);
    logger.info("Created flow: {}", flow);
    FlowInfoData data = new FlowInfoData(requestedFlow.getFlowId(), flow, FlowOperation.CREATE, message.getCorrelationId());
    InfoMessage infoMessage = new InfoMessage(data, System.currentTimeMillis(), message.getCorrelationId());
    Values topology = new Values(MAPPER.writeValueAsString(infoMessage));
    outputCollector.emit(StreamType.CREATE.toString(), tuple, topology);
    Values northbound = new Values(new InfoMessage(new FlowResponse(buildFlowResponse(flow)), message.getTimestamp(), message.getCorrelationId(), Destination.NORTHBOUND));
    outputCollector.emit(StreamType.RESPONSE.toString(), tuple, northbound);
}
Also used : FlowCreateRequest(org.openkilda.messaging.command.flow.FlowCreateRequest) Values(org.apache.storm.tuple.Values) UnroutablePathException(org.openkilda.pce.provider.UnroutablePathException) Flow(org.openkilda.messaging.model.Flow) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) FlowValidationException(org.openkilda.wfm.topology.flow.validation.FlowValidationException) MessageException(org.openkilda.messaging.error.MessageException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowValidator(org.openkilda.wfm.topology.flow.validation.FlowValidator)

Aggregations

Values (org.apache.storm.tuple.Values)2 MessageException (org.openkilda.messaging.error.MessageException)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)2 Flow (org.openkilda.messaging.model.Flow)2 UnroutablePathException (org.openkilda.pce.provider.UnroutablePathException)2 FlowValidationException (org.openkilda.wfm.topology.flow.validation.FlowValidationException)2 FlowValidator (org.openkilda.wfm.topology.flow.validation.FlowValidator)2 FlowCreateRequest (org.openkilda.messaging.command.flow.FlowCreateRequest)1 FlowUpdateRequest (org.openkilda.messaging.command.flow.FlowUpdateRequest)1