use of org.openkilda.messaging.model.ImmutablePair 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);
}
}
}
}
use of org.openkilda.messaging.model.ImmutablePair in project open-kilda by telstra.
the class CacheTopologyTest method buildFlowInfoData.
private FlowInfoData buildFlowInfoData(String flowId, String srcSwitch, String dstSwitch, List<PathNode> path) {
Flow flow = new Flow();
flow.setFlowId(flowId);
flow.setSourceSwitch(srcSwitch);
flow.setDestinationSwitch(dstSwitch);
flow.setState(FlowState.UP);
PathInfoData pathInfoData = new PathInfoData(0L, path);
flow.setFlowPath(pathInfoData);
ImmutablePair<Flow, Flow> immutablePair = new ImmutablePair<>(flow, flow);
return new FlowInfoData(flowId, immutablePair, FlowOperation.CREATE, UUID.randomUUID().toString());
}
use of org.openkilda.messaging.model.ImmutablePair in project open-kilda by telstra.
the class FlowCrudSteps method eachFlowIsCreatedAndStoredInTopologyEngine.
@Then("^each flow is created and stored in TopologyEngine$")
public void eachFlowIsCreatedAndStoredInTopologyEngine() {
List<Flow> expextedFlows = flows.stream().map(flow -> new Flow(flow.getId(), flow.getMaximumBandwidth(), flow.isIgnoreBandwidth(), 0, flow.getId(), null, flow.getSource().getSwitchId(), flow.getDestination().getSwitchId(), flow.getSource().getPortId(), flow.getDestination().getPortId(), flow.getSource().getVlanId(), flow.getDestination().getVlanId(), 0, 0, null, null)).collect(toList());
for (Flow expectedFlow : expextedFlows) {
ImmutablePair<Flow, Flow> flowPair = Failsafe.with(retryPolicy.abortIf(Objects::nonNull)).get(() -> topologyEngineService.getFlow(expectedFlow.getFlowId()));
assertNotNull(format("The flow '%s' is missing.", expectedFlow.getFlowId()), flowPair);
assertThat(format("The flow '%s' is different.", expectedFlow.getFlowId()), flowPair.getLeft(), is(equalTo(expectedFlow)));
}
}
use of org.openkilda.messaging.model.ImmutablePair in project open-kilda by telstra.
the class StormTopologyLCM method allStormTopologiesInTheSameState.
/**
* We compare old inner state of cache bolt and OFELinkBolt with new state after reload
* topologies.
*/
@And("^all storm topologies in the same state$")
public void allStormTopologiesInTheSameState() throws Throwable {
DumpStateManager actualSateDumpsFromBolts = kafkaUtils.getStateDumpsFromBolts();
// CacheBolt part
Set<ImmutablePair<Flow, Flow>> actualCacheBoltFlows = actualSateDumpsFromBolts.getCacheBoltState().getFlowDump().getFlows();
Set<ImmutablePair<Flow, Flow>> expectedCacheBoltFlows = expectedStateDumpsFromBolts.getCacheBoltState().getFlowDump().getFlows();
assertTrue(CollectionUtils.isEqualCollection(actualCacheBoltFlows, expectedCacheBoltFlows));
// OFELinkBolt
OFELinkBoltState actualOfeLinkBoltState = actualSateDumpsFromBolts.getOfeLinkBoltState();
OFELinkBoltState expectedOfeLinkBoltState = expectedStateDumpsFromBolts.getOfeLinkBoltState();
assertTrue(CollectionUtils.isEqualCollection(expectedOfeLinkBoltState.getDiscovery(), actualOfeLinkBoltState.getDiscovery()));
}
use of org.openkilda.messaging.model.ImmutablePair in project open-kilda by telstra.
the class FlowCache method buildFlow.
/**
* Builds new forward and reverse flow pair.
*
* @param flow source flow
* @param path flow path
* @param cache resource cache
* @return new forward and reverse flow pair
*/
public ImmutablePair<Flow, Flow> buildFlow(final ImmutablePair<Flow, Flow> flow, ImmutablePair<PathInfoData, PathInfoData> path, ResourceCache cache) {
String timestamp = Utils.getIsoTimestamp();
int cookie = cache.allocateCookie((int) flow.getLeft().getCookie());
Flow forward = new Flow(flow.getLeft().getFlowId(), flow.getLeft().getBandwidth(), false, cookie | ResourceCache.FORWARD_FLOW_COOKIE_MASK, flow.getLeft().getDescription(), timestamp, flow.getLeft().getSourceSwitch(), flow.getLeft().getDestinationSwitch(), flow.getLeft().getSourcePort(), flow.getLeft().getDestinationPort(), flow.getLeft().getSourceVlan(), flow.getLeft().getDestinationVlan(), cache.allocateMeterId(flow.getLeft().getSourceSwitch(), flow.getLeft().getMeterId()), cache.allocateVlanId(flow.getLeft().getTransitVlan()), path.getLeft(), FlowState.ALLOCATED);
Flow reverse = new Flow(flow.getRight().getFlowId(), flow.getRight().getBandwidth(), false, cookie | ResourceCache.REVERSE_FLOW_COOKIE_MASK, flow.getRight().getDescription(), timestamp, flow.getRight().getSourceSwitch(), flow.getRight().getDestinationSwitch(), flow.getRight().getSourcePort(), flow.getRight().getDestinationPort(), flow.getRight().getSourceVlan(), flow.getRight().getDestinationVlan(), cache.allocateMeterId(flow.getRight().getSourceSwitch(), flow.getRight().getMeterId()), cache.allocateVlanId(flow.getRight().getTransitVlan()), path.getRight(), FlowState.ALLOCATED);
return new ImmutablePair<>(forward, reverse);
}
Aggregations