Search in sources :

Example 1 with PortProperties

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());
}
Also used : Switch(org.openkilda.model.Switch) PortProperties(org.openkilda.model.PortProperties) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 2 with PortProperties

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());
}
Also used : Switch(org.openkilda.model.Switch) PortProperties(org.openkilda.model.PortProperties) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 3 with PortProperties

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");
    }
}
Also used : MessageException(org.openkilda.messaging.error.MessageException) PortFsm(org.openkilda.wfm.topology.network.controller.port.PortFsm) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PortFsmEvent(org.openkilda.wfm.topology.network.controller.port.PortFsm.PortFsmEvent) PortProperties(org.openkilda.model.PortProperties) PortFsmContext(org.openkilda.wfm.topology.network.controller.port.PortFsm.PortFsmContext)

Example 4 with PortProperties

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;
}
Also used : Switch(org.openkilda.model.Switch) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) PortProperties(org.openkilda.model.PortProperties)

Example 5 with 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());
}
Also used : Switch(org.openkilda.model.Switch) PortProperties(org.openkilda.model.PortProperties) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

PortProperties (org.openkilda.model.PortProperties)5 Switch (org.openkilda.model.Switch)4 Test (org.junit.Test)3 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)3 PersistenceException (org.openkilda.persistence.exceptions.PersistenceException)2 MessageException (org.openkilda.messaging.error.MessageException)1 PortFsm (org.openkilda.wfm.topology.network.controller.port.PortFsm)1 PortFsmContext (org.openkilda.wfm.topology.network.controller.port.PortFsm.PortFsmContext)1 PortFsmEvent (org.openkilda.wfm.topology.network.controller.port.PortFsm.PortFsmEvent)1