Search in sources :

Example 1 with ResourceCache

use of org.openkilda.pce.cache.ResourceCache 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)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Values (org.apache.storm.tuple.Values)1 CommandMessage (org.openkilda.messaging.command.CommandMessage)1 FlowRestoreRequest (org.openkilda.messaging.command.flow.FlowRestoreRequest)1 Flow (org.openkilda.messaging.model.Flow)1 ImmutablePair (org.openkilda.messaging.model.ImmutablePair)1 ResourceCache (org.openkilda.pce.cache.ResourceCache)1