use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.
the class MeterInstallCommand method handleOfError.
@Override
public CompletableFuture<Optional<OFMessage>> handleOfError(OFErrorMsg response) {
CompletableFuture<Optional<OFMessage>> future = new CompletableFuture<>();
if (!isInstallConflict(response)) {
future.completeExceptionally(new SwitchErrorResponseException(getSw().getId(), String.format("Can't install meter %s - %s", meterConfig.getId(), response)));
return future;
}
log.info("Meter conflict detected sw:{} meter:{}", getSw().getId(), meterConfig.getId());
MeterVerifyCommand verifyCommand = new MeterVerifyCommand(messageContext, switchId, meterConfig);
propagateFutureResponse(future, commandProcessor.chain(verifyCommand).thenAccept(this::handleMeterVerify).thenApply(ignore -> Optional.empty()));
return future;
}
use of org.openkilda.messaging.MessageContext 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.messaging.MessageContext in project open-kilda by telstra.
the class MeterVerifyCommandTest method shouldVerifyInaccurateMeterBurst.
@Test
public void shouldVerifyInaccurateMeterBurst() throws Exception {
MeterConfig validConfig = new MeterConfig(new MeterId(1), (long) (100 / 1.05));
MeterVerifyCommand command1 = new MeterVerifyCommand(new MessageContext(), mapSwitchId(dpId), validConfig);
switchFeaturesSetup(sw, SwitchFeature.METERS, SwitchFeature.INACCURATE_METER);
SettableFuture<List<OFMeterConfigStatsReply>> statsReplyProxy = setupMeterConfigStatsReply();
// for command2
setupMeterConfigStatsReply();
replayAll();
CompletableFuture<MeterVerifyReport> result = command1.execute(commandProcessor);
// make one more command with altered config, to produce meter config flags/bands
MeterConfig invalidConfig = new MeterConfig(validConfig.getId(), validConfig.getBandwidth() + 1);
MeterVerifyCommand command2 = new MeterVerifyCommand(command1.getMessageContext(), command1.getSwitchId(), invalidConfig);
// must be executed, for let .setup() method to initialize all dependencies
command2.execute(commandProcessor);
OFMeterConfig reply = sw.getOFFactory().buildMeterConfig().setMeterId(validConfig.getId().getValue()).setFlags(command2.makeMeterFlags()).setEntries(command2.makeMeterBands()).build();
statsReplyProxy.set(wrapMeterStatsReply(reply));
verifySuccessCompletion(result);
}
use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.
the class RecordHandler method doInstallGroupRequest.
private void doInstallGroupRequest(CommandMessage message) {
SwitchId switchId = ((InstallGroupRequest) message.getData()).getSwitchId();
MirrorConfig mirrorConfig = ((InstallGroupRequest) message.getData()).getMirrorConfig();
FlowTransitEncapsulation encapsulation = ((InstallGroupRequest) message.getData()).getEncapsulation();
SwitchId egressSwitchId = ((InstallGroupRequest) message.getData()).getEgressSwitchId();
FlowTransitData flowTransitData = null;
if (encapsulation != null) {
flowTransitData = FlowTransitData.builder().ingressSwitchId(switchId).egressSwitchId(egressSwitchId).encapsulation(encapsulation).build();
}
logger.debug("Install group '{}' for switch '{}'", mirrorConfig.getGroupId().intValue(), switchId);
handleSpeakerCommand(new GroupInstallCommand(new MessageContext(message), switchId, mirrorConfig, flowTransitData));
InstallGroupResponse response = new InstallGroupResponse(switchId, mirrorConfig.getGroupId().intValue());
String correlationId = message.getCorrelationId();
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), correlationId, infoMessage);
}
use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.
the class RecordHandler method doModifyGroupRequest.
private void doModifyGroupRequest(CommandMessage message) {
SwitchId switchId = ((ModifyGroupRequest) message.getData()).getSwitchId();
MirrorConfig mirrorConfig = ((ModifyGroupRequest) message.getData()).getMirrorConfig();
FlowTransitEncapsulation encapsulation = ((ModifyGroupRequest) message.getData()).getEncapsulation();
SwitchId egressSwitchId = ((ModifyGroupRequest) message.getData()).getEgressSwitchId();
FlowTransitData flowTransitData = null;
if (encapsulation != null) {
flowTransitData = FlowTransitData.builder().ingressSwitchId(switchId).egressSwitchId(egressSwitchId).encapsulation(encapsulation).build();
}
logger.debug("Modify group '{}' for switch '{}'", mirrorConfig.getGroupId().intValue(), switchId);
handleSpeakerCommand(new GroupModifyCommand(new MessageContext(message), switchId, mirrorConfig, flowTransitData));
ModifyGroupResponse response = new ModifyGroupResponse(switchId, mirrorConfig.getGroupId().intValue());
String correlationId = message.getCorrelationId();
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), correlationId, infoMessage);
}
Aggregations