use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchOperationsBolt method deleteSwitch.
private DeleteSwitchResponse deleteSwitch(DeleteSwitchRequest request) {
SwitchId switchId = request.getSwitchId();
boolean force = request.isForce();
boolean deleted = transactionManager.doInTransaction(() -> {
try {
if (!force) {
switchOperationsService.checkSwitchIsDeactivated(switchId);
switchOperationsService.checkSwitchHasNoFlows(switchId);
switchOperationsService.checkSwitchHasNoFlowSegments(switchId);
switchOperationsService.checkSwitchHasNoIsls(switchId);
}
return switchOperationsService.deleteSwitch(switchId, force);
} catch (SwitchNotFoundException e) {
String message = format("Could not delete switch '%s': '%s'", switchId, e.getMessage());
throw new MessageException(ErrorType.NOT_FOUND, message, "Switch is not found.");
} catch (IllegalSwitchStateException e) {
String message = format("Could not delete switch '%s': '%s'", switchId, e.getMessage());
throw new MessageException(ErrorType.REQUEST_INVALID, message, "Switch is in illegal state");
}
});
if (deleted) {
DeactivateSwitchInfoData data = new DeactivateSwitchInfoData(switchId);
getOutput().emit(StreamType.DISCO.toString(), getCurrentTuple(), new Values(data, getCorrelationId()));
}
log.info("{} deletion of switch '{}'", deleted ? "Successful" : "Unsuccessful", switchId);
return new DeleteSwitchResponse(deleted);
}
use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchOperationsService method getSwitchConnections.
/**
* Find and return the set of connections to the speakers for specific switch.
*/
public SwitchConnectionsResponse getSwitchConnections(SwitchId switchId) throws SwitchNotFoundException {
Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
SwitchAvailabilityData.SwitchAvailabilityDataBuilder payload = SwitchAvailabilityData.builder();
for (SwitchConnect entry : switchConnectRepository.findBySwitchId(switchId)) {
payload.connection(SwitchMapper.INSTANCE.map(entry));
}
return new SwitchConnectionsResponse(sw.getSwitchId(), sw.getStatus(), payload.build());
}
use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchOperationsService method deleteSwitch.
/**
* Delete switch.
*
* @param switchId ID of switch to be deleted
* @param force if True all switch relationships will be deleted too.
* If False switch will be deleted only if it has no relations.
* @return True if switch was deleted, False otherwise
* @throws SwitchNotFoundException if switch is not found
*/
public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException {
transactionManager.doInTransaction(() -> {
Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
switchPropertiesRepository.findBySwitchId(sw.getSwitchId()).ifPresent(sp -> switchPropertiesRepository.remove(sp));
portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()).forEach(portPropertiesRepository::remove);
if (force) {
// remove() removes switch along with all relationships.
switchRepository.remove(sw);
} else {
// removeIfNoDependant() is used to be sure that we wouldn't delete switch
// if it has even one relationship.
switchRepository.removeIfNoDependant(sw);
}
});
return !switchRepository.exists(switchId);
}
use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchOperationsService method getSwitch.
/**
* Get switch by switch id.
*
* @param switchId switch id.
*/
public GetSwitchResponse getSwitch(SwitchId switchId) throws SwitchNotFoundException {
Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
switchRepository.detach(sw);
return new GetSwitchResponse(sw);
}
use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.
the class FlowValidationHubServiceTest method testMainPath.
@Test
public void testMainPath() throws DuplicateKeyException, UnknownKeyException {
FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {
@Override
public void sendSpeakerRequest(String flowId, CommandData commandData) {
assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
if (commandData instanceof DumpRulesForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
} else if (commandData instanceof DumpMetersForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
} else {
assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
}
}
@Override
public void sendNorthboundResponse(List<? extends InfoData> message) {
assertEquals(4, message.size());
try {
assertEquals(flowValidationService.validateFlow(TEST_FLOW_ID_A, getSwitchFlowEntriesWithTransitVlan(), getSwitchMeterEntries(), getSwitchGroupEntries()), message);
} catch (FlowNotFoundException | SwitchNotFoundException e) {
// tested in the FlowValidationServiceTest
}
}
@Override
public void sendNorthboundResponse(Message message) {
fail();
}
@Override
public void cancelTimeoutCallback(String key) {
assertEquals(TEST_KEY, key);
}
@Override
public void sendInactive() {
}
};
flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
buildTransitVlanFlow("");
flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
for (SwitchFlowEntries switchFlowEntries : getSwitchFlowEntriesWithTransitVlan()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchFlowEntries);
}
for (SwitchMeterEntries switchMeterEntries : getSwitchMeterEntries()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchMeterEntries);
}
for (SwitchGroupEntries switchGroupEntries : getSwitchGroupEntries()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchGroupEntries);
}
}
Aggregations