Search in sources :

Example 1 with FlowRestoreRequest

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

the class CacheBolt method emitRestoreCommands.

private void emitRestoreCommands(Set<ImmutablePair<Flow, Flow>> flows, Tuple tuple) {
    if (flows != null) {
        ResourceCache resourceCache = new ResourceCache();
        for (ImmutablePair<Flow, Flow> flow : flows) {
            resourceCache.allocateFlow(flow);
        }
        for (ImmutablePair<Flow, Flow> flow : flows) {
            try {
                FlowRestoreRequest request = new FlowRestoreRequest(flowCache.buildFlow(flow.getLeft(), new ImmutablePair<>(null, null), resourceCache));
                resourceCache.deallocateFlow(flow);
                Values values = new Values(Utils.MAPPER.writeValueAsString(new CommandMessage(request, System.currentTimeMillis(), UUID.randomUUID().toString(), Destination.WFM)));
                outputCollector.emit(StreamType.WFM_DUMP.toString(), tuple, values);
                logger.info("Flow {} restore command message sent", flow.getLeft().getFlowId());
            } catch (JsonProcessingException exception) {
                logger.error("Could not format flow restore request by flow={}", flow, exception);
            }
        }
    }
}
Also used : ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Values(org.apache.storm.tuple.Values) FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) ResourceCache(org.openkilda.pce.cache.ResourceCache) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Flow(org.openkilda.messaging.model.Flow) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with FlowRestoreRequest

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

the class CrudBolt method handleRestoreRequest.

private void handleRestoreRequest(CommandMessage message, Tuple tuple) throws IOException {
    ImmutablePair<Flow, Flow> requestedFlow = ((FlowRestoreRequest) message.getData()).getPayload();
    try {
        ImmutablePair<PathInfoData, PathInfoData> path = pathComputer.getPath(requestedFlow.getLeft(), Strategy.COST);
        logger.info("Restored flow path: {}", path);
        ImmutablePair<Flow, Flow> flow;
        if (flowCache.cacheContainsFlow(requestedFlow.getLeft().getFlowId())) {
            flow = flowCache.updateFlow(requestedFlow, path);
        } else {
            flow = flowCache.createFlow(requestedFlow, path);
        }
        logger.info("Restored flow: {}", flow);
        Values topology = new Values(Utils.MAPPER.writeValueAsString(new FlowInfoData(requestedFlow.getLeft().getFlowId(), flow, FlowOperation.UPDATE, message.getCorrelationId())));
        outputCollector.emit(StreamType.UPDATE.toString(), tuple, topology);
    } catch (UnroutablePathException e) {
        throw new MessageException(message.getCorrelationId(), System.currentTimeMillis(), ErrorType.CREATION_FAILURE, "Could not restore flow", "Path was not found");
    }
}
Also used : PathInfoData(org.openkilda.messaging.info.event.PathInfoData) MessageException(org.openkilda.messaging.error.MessageException) Values(org.apache.storm.tuple.Values) FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) UnroutablePathException(org.openkilda.pce.provider.UnroutablePathException) Flow(org.openkilda.messaging.model.Flow)

Example 3 with FlowRestoreRequest

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

the class SplitterBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    String request = tuple.getString(0);
    Values values = new Values(request);
    try {
        Message message = tryMessage(request);
        if (message == null || !Destination.WFM.equals(message.getDestination()) || !(message instanceof CommandMessage || message instanceof InfoMessage)) {
            return;
        }
        logger.debug("Request tuple={}", tuple);
        /*
             * First, try to see if this is a PUSH / UNPUSH (smaller code base vs other).
             * NB: InfoMessage was used since it has the relevant attributes/properties for
             * pushing the flow.
             */
        if (message instanceof InfoMessage) {
            InfoData data = ((InfoMessage) message).getData();
            if (data instanceof FlowInfoData) {
                FlowInfoData fid = (FlowInfoData) data;
                String flowId = fid.getFlowId();
                values = new Values(message, flowId);
                logger.info("Flow {} message: operation={} values={}", flowId, fid.getOperation(), values);
                if (fid.getOperation() == FlowOperation.PUSH) {
                    outputCollector.emit(StreamType.PUSH.toString(), tuple, values);
                } else if (fid.getOperation() == FlowOperation.UNPUSH) {
                    outputCollector.emit(StreamType.UNPUSH.toString(), tuple, values);
                } else {
                    logger.warn("Skip undefined FlowInfoData Operation {}: {}={}", fid.getOperation(), Utils.CORRELATION_ID, message.getCorrelationId());
                }
            } else {
                logger.warn("Skip undefined InfoMessage: {}={}", Utils.CORRELATION_ID, message.getCorrelationId());
            }
            return;
        }
        /*
             * Second, it isn't an InfoMessage, so it must be a CommandMessage.
             */
        CommandData data = ((CommandMessage) message).getData();
        if (data instanceof FlowCreateRequest) {
            String flowId = ((FlowCreateRequest) data).getPayload().getFlowId();
            logger.info("Flow {} create message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.CREATE.toString(), tuple, values);
        } else if (data instanceof FlowDeleteRequest) {
            String flowId = ((FlowDeleteRequest) data).getPayload().getFlowId();
            logger.info("Flow {} delete message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.DELETE.toString(), tuple, values);
        } else if (data instanceof FlowUpdateRequest) {
            String flowId = ((FlowUpdateRequest) data).getPayload().getFlowId();
            logger.info("Flow {} update message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.UPDATE.toString(), tuple, values);
        } else if (data instanceof FlowRestoreRequest) {
            String flowId = ((FlowRestoreRequest) data).getPayload().getLeft().getFlowId();
            logger.info("Flow {} restore message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.RESTORE.toString(), tuple, values);
        } else if (data instanceof FlowRerouteRequest) {
            String flowId = ((FlowRerouteRequest) data).getPayload().getFlowId();
            logger.info("Flow {} reroute message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.REROUTE.toString(), tuple, values);
        } else if (data instanceof FlowStatusRequest) {
            String flowId = ((FlowStatusRequest) data).getPayload().getId();
            logger.info("Flow {} status message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.STATUS.toString(), tuple, values);
        } else if (data instanceof FlowGetRequest) {
            String flowId = ((FlowGetRequest) data).getPayload().getId();
            logger.info("Flow {} get message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.READ.toString(), tuple, values);
        } else if (data instanceof FlowsGetRequest) {
            logger.info("Flows get message: values={}", values);
            values = new Values(message, null);
            outputCollector.emit(StreamType.READ.toString(), tuple, values);
        } else if (data instanceof FlowPathRequest) {
            String flowId = ((FlowPathRequest) data).getPayload().getId();
            logger.info("Flow {} path message: values={}", flowId, values);
            values = new Values(message, flowId);
            outputCollector.emit(StreamType.PATH.toString(), tuple, values);
        } else if (data instanceof FlowCacheSyncRequest) {
            logger.info("FlowCacheSyncRequest: values={}", values);
            values = new Values(message, null);
            outputCollector.emit(StreamType.CACHE_SYNC.toString(), tuple, values);
        } else {
            logger.debug("Skip undefined CommandMessage: {}={}", Utils.CORRELATION_ID, message.getCorrelationId());
        }
    /*
 * (crimi) This was commented out since the parsing of the message is handled in tryMessage.
 * Due to refactoring the kafka topics, it appears more messages are coming to the splitter than
 * originally desinged for.
 *
 * TODO: Fix the cause of excess messages coming to the splitter.
 */
    // 
    // } catch (IOException exception) {
    // String message = String.format("Could not deserialize message: %s", request);
    // logger.error("{}", message, exception);
    // 
    // ErrorMessage errorMessage = new ErrorMessage(
    // new ErrorData(ErrorType.REQUEST_INVALID, message, exception.getMessage()),
    // System.currentTimeMillis(), Utils.SYSTEM_CORRELATION_ID, Destination.NORTHBOUND);
    // 
    // values = new Values(errorMessage, ErrorType.INTERNAL_ERROR);
    // outputCollector.emit(StreamType.ERROR.toString(), tuple, values);
    } finally {
        logger.debug("Splitter message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
        outputCollector.ack(tuple);
    }
}
Also used : FlowsGetRequest(org.openkilda.messaging.command.flow.FlowsGetRequest) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) FlowUpdateRequest(org.openkilda.messaging.command.flow.FlowUpdateRequest) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowDeleteRequest(org.openkilda.messaging.command.flow.FlowDeleteRequest) Values(org.apache.storm.tuple.Values) FlowCreateRequest(org.openkilda.messaging.command.flow.FlowCreateRequest) FlowGetRequest(org.openkilda.messaging.command.flow.FlowGetRequest) FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) CommandMessage(org.openkilda.messaging.command.CommandMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) InfoData(org.openkilda.messaging.info.InfoData) FlowInfoData(org.openkilda.messaging.info.flow.FlowInfoData) FlowStatusRequest(org.openkilda.messaging.command.flow.FlowStatusRequest) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) CommandData(org.openkilda.messaging.command.CommandData) FlowPathRequest(org.openkilda.messaging.command.flow.FlowPathRequest) FlowCacheSyncRequest(org.openkilda.messaging.command.flow.FlowCacheSyncRequest)

Example 4 with FlowRestoreRequest

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

the class CacheTopologyTest method cacheReceivesInfoDataBeforeNetworkDump.

@Test
public void cacheReceivesInfoDataBeforeNetworkDump() throws Exception {
    System.out.println("Cache receives InfoData before NetworkDump Test");
    sendClearState();
    waitDumpRequest();
    // Send switchUpdate info to not initialized bolt
    sendData(sw);
    // Bolt must fail that tuple
    sendNetworkDumpRequest();
    NetworkDump networkDump = getNetworkDump(ctrlConsumer.pollMessage());
    assertTrue(CollectionUtils.isEmpty(networkDump.getSwitches()));
    // Init bolt with dump from TE
    sendNetworkDump(dump);
    // Check if SwitchInfoData is ok
    sendNetworkDumpRequest();
    networkDump = getNetworkDump(ctrlConsumer.pollMessage());
    assertFalse(CollectionUtils.isEmpty(networkDump.getSwitches()));
    Set<String> flowIds = new HashSet<>(Arrays.asList(firstFlowId, secondFlowId));
    ConsumerRecord<String, String> firstRecord = flowConsumer.pollMessage();
    assertNotNull(firstRecord);
    assertNotNull(firstRecord.value());
    CommandMessage commandMessage = objectMapper.readValue(firstRecord.value(), CommandMessage.class);
    FlowRestoreRequest commandData = (FlowRestoreRequest) commandMessage.getData();
    assertNotNull(commandData);
    assertTrue(flowIds.contains(commandData.getPayload().getLeft().getFlowId()));
    ConsumerRecord<String, String> secondRecord = flowConsumer.pollMessage();
    assertNotNull(secondRecord);
    assertNotNull(secondRecord.value());
    commandMessage = objectMapper.readValue(secondRecord.value(), CommandMessage.class);
    commandData = (FlowRestoreRequest) commandMessage.getData();
    assertNotNull(commandData);
    assertTrue(flowIds.contains(commandData.getPayload().getLeft().getFlowId()));
}
Also used : NetworkDump(org.openkilda.messaging.ctrl.state.NetworkDump) FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) HashSet(java.util.HashSet) CommandMessage(org.openkilda.messaging.command.CommandMessage) AbstractStormTest(org.openkilda.wfm.AbstractStormTest)

Example 5 with FlowRestoreRequest

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

the class CacheTopologyTest method cacheReceivesNetworkDumpAndSendsToFlowTopology.

@Test
public void cacheReceivesNetworkDumpAndSendsToFlowTopology() throws Exception {
    System.out.println("Dump Test");
    ConsumerRecord<String, String> firstRecord = flowConsumer.pollMessage();
    assertNotNull(firstRecord);
    assertNotNull(firstRecord.value());
    Set<String> flowIds = new HashSet<>(Arrays.asList(firstFlowId, secondFlowId));
    CommandMessage commandMessage = objectMapper.readValue(firstRecord.value(), CommandMessage.class);
    FlowRestoreRequest commandData = (FlowRestoreRequest) commandMessage.getData();
    assertNotNull(commandData);
    assertTrue(flowIds.contains(commandData.getPayload().getLeft().getFlowId()));
    ConsumerRecord<String, String> secondRecord = flowConsumer.pollMessage();
    assertNotNull(secondRecord);
    assertNotNull(secondRecord.value());
    commandMessage = objectMapper.readValue(secondRecord.value(), CommandMessage.class);
    commandData = (FlowRestoreRequest) commandMessage.getData();
    assertNotNull(commandData);
    assertTrue(flowIds.contains(commandData.getPayload().getLeft().getFlowId()));
}
Also used : FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) HashSet(java.util.HashSet) CommandMessage(org.openkilda.messaging.command.CommandMessage) AbstractStormTest(org.openkilda.wfm.AbstractStormTest)

Aggregations

FlowRestoreRequest (org.openkilda.messaging.command.flow.FlowRestoreRequest)5 CommandMessage (org.openkilda.messaging.command.CommandMessage)4 Values (org.apache.storm.tuple.Values)3 HashSet (java.util.HashSet)2 Flow (org.openkilda.messaging.model.Flow)2 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Message (org.openkilda.messaging.Message)1 CommandData (org.openkilda.messaging.command.CommandData)1 FlowCacheSyncRequest (org.openkilda.messaging.command.flow.FlowCacheSyncRequest)1 FlowCreateRequest (org.openkilda.messaging.command.flow.FlowCreateRequest)1 FlowDeleteRequest (org.openkilda.messaging.command.flow.FlowDeleteRequest)1 FlowGetRequest (org.openkilda.messaging.command.flow.FlowGetRequest)1 FlowPathRequest (org.openkilda.messaging.command.flow.FlowPathRequest)1 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)1 FlowStatusRequest (org.openkilda.messaging.command.flow.FlowStatusRequest)1 FlowUpdateRequest (org.openkilda.messaging.command.flow.FlowUpdateRequest)1 FlowsGetRequest (org.openkilda.messaging.command.flow.FlowsGetRequest)1 NetworkDump (org.openkilda.messaging.ctrl.state.NetworkDump)1 MessageException (org.openkilda.messaging.error.MessageException)1