use of org.openkilda.floodlight.service.session.Session in project open-kilda by telstra.
the class OfBatchExecutor method executeBatch.
/**
* Execute current batch of commands.
*/
public void executeBatch() {
log.debug("Execute batch start (key={})", kafkaKey);
List<UUID> stageCommandsUuids = holder.getCurrentStage();
List<OFMessage> ofMessages = new ArrayList<>();
for (UUID uuid : stageCommandsUuids) {
log.debug("Start processing UUID: {} (key={})", uuid, kafkaKey);
if (holder.canExecute(uuid)) {
BatchData batchData = holder.getByUUid(uuid);
hasFlows |= batchData.isFlow();
hasMeters |= batchData.isMeter();
hasGroups |= batchData.isGroup();
ofMessages.add(batchData.getMessage());
} else {
Map<UUID, String> blockingDependencies = holder.getBlockingDependencies(uuid);
holder.recordFailedUuid(uuid, "Not all dependencies are satisfied: " + (blockingDependencies.isEmpty() ? "can't execute" : Joiner.on(",").withKeyValueSeparator("=").join(blockingDependencies)));
}
}
List<CompletableFuture<Optional<OFMessage>>> requests = new ArrayList<>();
try (Session session = sessionService.open(messageContext, iofSwitch)) {
for (OFMessage message : ofMessages) {
requests.add(session.write(message).whenComplete((res, ex) -> {
log.debug("Check responses (key={})", kafkaKey);
if (ex == null) {
res.ifPresent(ofMessage -> {
UUID uuid = holder.popAwaitingXid(ofMessage.getXid());
if (ofMessage instanceof OFErrorMsg) {
OFErrorMsg errorMsg = (OFErrorMsg) ofMessage;
holder.recordFailedUuid(uuid, errorMsg.getErrType().toString());
}
});
} else {
log.error("Received error {}", ex.getMessage(), ex);
}
}));
}
}
CompletableFuture.allOf(requests.toArray(new CompletableFuture<?>[0])).thenAccept(ignore -> checkOfResponses());
}
use of org.openkilda.floodlight.service.session.Session in project open-kilda by telstra.
the class MeterRemoveCommand method makeExecutePlan.
@Override
protected CompletableFuture<MeterRemoveReport> makeExecutePlan(SpeakerCommandProcessor commandProcessor) throws Exception {
ensureSwitchSupportMeters();
IOFSwitch sw = getSw();
OFMeterMod meterDeleteMessage = sw.getOFFactory().buildMeterMod().setMeterId(meterId.getValue()).setCommand(OFMeterModCommand.DELETE).build();
try (Session session = getSessionService().open(messageContext, sw)) {
return session.write(meterDeleteMessage).thenApply(ignore -> makeSuccessReport());
}
}
use of org.openkilda.floodlight.service.session.Session in project open-kilda by telstra.
the class IngressFlowSegmentBase method planOfFlowsInstall.
private CompletableFuture<FlowSegmentReport> planOfFlowsInstall(EffectiveIds effectiveIds) {
MeterId effectiveMeterId = effectiveIds.getMeterId();
MeterConfig meterConfig = getMeterConfig();
if (effectiveMeterId == null && rulesContext != null && !rulesContext.isUpdateMeter() && meterConfig != null) {
effectiveIds.setMeterId(meterConfig.getId());
}
List<OFFlowMod> ofMessages = makeFlowModMessages(effectiveIds);
List<CompletableFuture<Optional<OFMessage>>> writeResults = new ArrayList<>(ofMessages.size());
try (Session session = getSessionService().open(messageContext, getSw())) {
for (OFFlowMod message : ofMessages) {
writeResults.add(session.write(message));
}
}
return CompletableFuture.allOf(writeResults.toArray(new CompletableFuture[0])).thenApply(ignore -> makeSuccessReport());
}
use of org.openkilda.floodlight.service.session.Session in project open-kilda by telstra.
the class IngressFlowSegmentBase method planOfFlowsRemove.
private CompletableFuture<EffectiveIds> planOfFlowsRemove(EffectiveIds effectiveIds) {
List<OFFlowMod> ofMessages = new ArrayList<>(makeFlowModMessages(effectiveIds));
List<CompletableFuture<?>> requests = new ArrayList<>(ofMessages.size());
try (Session session = getSessionService().open(messageContext, getSw())) {
for (OFFlowMod message : ofMessages) {
requests.add(session.write(message));
}
}
return CompletableFuture.allOf(requests.toArray(new CompletableFuture<?>[0])).thenApply(ignore -> effectiveIds);
}
use of org.openkilda.floodlight.service.session.Session in project open-kilda by telstra.
the class GroupRemoveCommand method makeExecutePlan.
@Override
protected CompletableFuture<GroupRemoveReport> makeExecutePlan(SpeakerCommandProcessor commandProcessor) throws Exception {
ensureSwitchSupportGroups();
IOFSwitch sw = getSw();
OFGroupDelete groupDelete = sw.getOFFactory().buildGroupDelete().setGroup(OFGroup.of(groupId.intValue())).setGroupType(OFGroupType.ALL).build();
try (Session session = getSessionService().open(messageContext, sw)) {
return session.write(groupDelete).thenApply(ignore -> makeSuccessReport());
}
}
Aggregations