use of org.openkilda.model.PortProperties in project open-kilda by telstra.
the class FermaPortPropertiesRepositoryTest method shouldCreatePortPropertiesWithRelation.
@Test
public void shouldCreatePortPropertiesWithRelation() {
Switch origSwitch = createTestSwitch(TEST_SWITCH_ID.getId());
PortProperties portProperties = PortProperties.builder().switchObj(origSwitch).discoveryEnabled(false).build();
portPropertiesRepository.add(portProperties);
Collection<PortProperties> portPropertiesResult = portPropertiesRepository.findAll();
assertEquals(1, portPropertiesResult.size());
assertNotNull(portPropertiesResult.iterator().next().getSwitchObj());
}
use of org.openkilda.model.PortProperties in project open-kilda by telstra.
the class SwitchOperationsServiceTest method shouldDeletePortPropertiesWhenDeletingSwitch.
@Test
public void shouldDeletePortPropertiesWhenDeletingSwitch() throws SwitchNotFoundException {
Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
switchRepository.add(sw);
PortProperties portProperties = PortProperties.builder().switchObj(sw).port(7).discoveryEnabled(false).build();
portPropertiesRepository.add(portProperties);
switchOperationsService.deleteSwitch(TEST_SWITCH_ID, false);
assertFalse(switchRepository.findById(TEST_SWITCH_ID).isPresent());
assertTrue(portPropertiesRepository.findAll().isEmpty());
}
use of org.openkilda.model.PortProperties in project open-kilda by telstra.
the class NetworkPortService method updatePortProperties.
/**
* Update port properties.
*/
public void updatePortProperties(Endpoint endpoint, boolean discoveryEnabled) {
try {
transactionManager.doInTransaction(() -> {
PortProperties portProperties = savePortProperties(endpoint, discoveryEnabled);
PortFsm portFsm = locateController(endpoint);
PortFsmContext context = PortFsmContext.builder(carrier).build();
PortFsmEvent event = discoveryEnabled ? PortFsmEvent.ENABLE_DISCOVERY : PortFsmEvent.DISABLE_DISCOVERY;
controllerExecutor.fire(portFsm, event, context);
carrier.notifyPortPropertiesChanged(portProperties);
});
} catch (PersistenceException e) {
String message = format("Could not update port properties for '%s': %s", endpoint, e.getMessage());
throw new MessageException(NOT_FOUND, message, "Persistence exception");
} catch (IllegalStateException e) {
// Rollback if port is not found. It's allowed to change port properties for already existing ports only.
String message = format("Port not found: '%s'", e.getMessage());
throw new MessageException(NOT_FOUND, message, "Port not found exception");
}
}
use of org.openkilda.model.PortProperties in project open-kilda by telstra.
the class NetworkPortService method savePortProperties.
private PortProperties savePortProperties(Endpoint endpoint, boolean discoveryEnabled) {
Switch sw = switchRepository.findById(endpoint.getDatapath()).orElseThrow(() -> new PersistenceException(format("Switch %s not found.", endpoint.getDatapath())));
PortProperties portProperties = portPropertiesRepository.getBySwitchIdAndPort(endpoint.getDatapath(), endpoint.getPortNumber()).orElseGet(() -> {
PortProperties newProps = PortProperties.builder().switchObj(sw).port(endpoint.getPortNumber()).build();
portPropertiesRepository.add(newProps);
return newProps;
});
portProperties.setDiscoveryEnabled(discoveryEnabled);
return portProperties;
}
use of org.openkilda.model.PortProperties in project open-kilda by telstra.
the class FermaPortPropertiesRepositoryTest method shouldGetPortPropertiesBySwitchIdAndPort.
@Test
public void shouldGetPortPropertiesBySwitchIdAndPort() {
Switch origSwitch = createTestSwitch(TEST_SWITCH_ID.getId());
int port = 7;
PortProperties portProperties = PortProperties.builder().switchObj(origSwitch).port(port).discoveryEnabled(false).build();
portPropertiesRepository.add(portProperties);
Optional<PortProperties> portPropertiesResult = portPropertiesRepository.getBySwitchIdAndPort(origSwitch.getSwitchId(), port);
assertTrue(portPropertiesResult.isPresent());
assertEquals(origSwitch.getSwitchId(), portPropertiesResult.get().getSwitchObj().getSwitchId());
assertEquals(port, portPropertiesResult.get().getPort());
assertFalse(portPropertiesResult.get().isDiscoveryEnabled());
}
Aggregations