use of org.openkilda.messaging.command.flow.RemoveFlow in project open-kilda by telstra.
the class SwitchSyncServiceImplTest method handleSyncExcess.
@Test
public void handleSyncExcess() {
request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).removeExcess(true).build();
excessRules = singletonList(EXCESS_COOKIE);
excessMeters = singletonList(new MeterInfoEntry(EXCESS_COOKIE, EXCESS_COOKIE, FLOW_ID, 0L, 0L, new String[] {}, null, null));
RemoveFlow removeFlow = RemoveFlow.builder().transactionId(UUID.randomUUID()).flowId(FLOW_ID).cookie(EXCESS_COOKIE).switchId(SWITCH_ID).meterId(EXCESS_COOKIE).build();
when(commandBuilder.buildCommandsToRemoveExcessRules(eq(SWITCH_ID), any(), any())).thenReturn(singletonList(removeFlow));
service.handleSwitchSync(KEY, request, makeValidationResult());
verify(commandBuilder).buildCommandsToSyncMissingRules(eq(SWITCH_ID), eq(missingRules));
verify(commandBuilder).buildCommandsToRemoveExcessRules(eq(SWITCH_ID), eq(singletonList(flowEntry)), eq(excessRules));
verify(carrier).sendCommandToSpeaker(eq(KEY), any(DeleterMeterForSwitchManagerRequest.class));
service.handleRemoveMetersResponse(KEY);
verify(carrier).sendCommandToSpeaker(eq(KEY), any(InstallFlowForSwitchManagerRequest.class));
verify(carrier).sendCommandToSpeaker(eq(KEY), any(RemoveFlowForSwitchManagerRequest.class));
service.handleInstallRulesResponse(KEY);
service.handleRemoveRulesResponse(KEY);
verify(carrier, times(3)).sendCommandToSpeaker(eq(KEY), any(CommandData.class));
verify(carrier).cancelTimeoutCallback(eq(KEY));
verify(carrier).response(eq(KEY), any(InfoMessage.class));
verifyNoMoreInteractions(commandBuilder);
verifyNoMoreInteractions(carrier);
}
use of org.openkilda.messaging.command.flow.RemoveFlow in project open-kilda by telstra.
the class RecordHandler method doReinstallDefaultFlowForSwitchManager.
/**
* Reinstall default flow.
*
* @param message command message for flow deletion
*/
private void doReinstallDefaultFlowForSwitchManager(CommandMessage message) {
ReinstallDefaultFlowForSwitchManagerRequest request = (ReinstallDefaultFlowForSwitchManagerRequest) message.getData();
IKafkaProducerService producerService = getKafkaProducer();
String replyToTopic = context.getKafkaSwitchManagerTopic();
long cookie = request.getCookie();
if (!Cookie.isDefaultRule(cookie)) {
logger.warn("Failed to reinstall default switch rule for switch: '{}'. Rule {} is not default.", request.getSwitchId(), Long.toHexString(cookie));
anError(ErrorType.DATA_INVALID).withMessage(format("Failed to reinstall default switch rule for switch %s. Rule %s is not default", request.getSwitchId(), Long.toHexString(cookie))).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
SwitchId switchId = request.getSwitchId();
DatapathId dpid = DatapathId.of(switchId.toLong());
try {
RemoveFlow command = RemoveFlow.builder().flowId("REMOVE_DEFAULT_FLOW").cookie(cookie).switchId(switchId).build();
Set<Long> removedFlows = new HashSet<>(processDeleteFlow(command, dpid));
for (Long removedFlow : removedFlows) {
Long installedFlow;
if (request instanceof ReinstallServer42FlowForSwitchManagerRequest) {
installedFlow = processInstallServer42Rule((ReinstallServer42FlowForSwitchManagerRequest) request);
} else {
installedFlow = processInstallDefaultFlowByCookie(switchId, removedFlow);
}
InfoMessage response = new InfoMessage(new FlowReinstallResponse(removedFlow, installedFlow), System.currentTimeMillis(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
}
} catch (SwitchOperationException e) {
logger.error("Failed to reinstall switch rule for switch: '{}'", request.getSwitchId(), e);
anError(ErrorType.INTERNAL_ERROR).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
Aggregations