Search in sources :

Example 46 with Switch

use of org.openkilda.model.Switch 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());
}
Also used : Switch(org.openkilda.model.Switch) SwitchAvailabilityData(org.openkilda.messaging.model.SwitchAvailabilityData) SwitchConnect(org.openkilda.model.SwitchConnect) SwitchConnectionsResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectionsResponse) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 47 with Switch

use of org.openkilda.model.Switch 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);
}
Also used : Switch(org.openkilda.model.Switch) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 48 with Switch

use of org.openkilda.model.Switch 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);
}
Also used : GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) Switch(org.openkilda.model.Switch) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 49 with Switch

use of org.openkilda.model.Switch in project open-kilda by telstra.

the class LinkOperationsServiceTest method createSwitchIfNotExist.

private Switch createSwitchIfNotExist(SwitchId switchId) {
    return switchRepository.findById(switchId).orElseGet(() -> {
        Switch sw = Switch.builder().switchId(switchId).status(SwitchStatus.ACTIVE).build();
        switchRepository.add(sw);
        return sw;
    });
}
Also used : Switch(org.openkilda.model.Switch)

Example 50 with Switch

use of org.openkilda.model.Switch in project open-kilda by telstra.

the class SwitchOperationsServiceTest method shouldValidateSupportedEncapsulationTypeWhenUpdatingSwitchProperties.

@Test(expected = IllegalSwitchPropertiesException.class)
public void shouldValidateSupportedEncapsulationTypeWhenUpdatingSwitchProperties() {
    Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
    switchRepository.add(sw);
    createSwitchProperties(sw, Collections.singleton(FlowEncapsulationType.TRANSIT_VLAN), false, false, false);
    switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, new SwitchPropertiesDto());
}
Also used : SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) Switch(org.openkilda.model.Switch) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

Switch (org.openkilda.model.Switch)230 Test (org.junit.Test)126 Flow (org.openkilda.model.Flow)68 SwitchId (org.openkilda.model.SwitchId)67 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)46 FlowPath (org.openkilda.model.FlowPath)34 PathId (org.openkilda.model.PathId)32 Utils.buildSwitch (org.openkilda.rulemanager.Utils.buildSwitch)32 PathComputer (org.openkilda.pce.PathComputer)28 GetPathsResult (org.openkilda.pce.GetPathsResult)23 List (java.util.List)22 SwitchProperties (org.openkilda.model.SwitchProperties)21 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)20 SpeakerData (org.openkilda.rulemanager.SpeakerData)19 String.format (java.lang.String.format)17 Set (java.util.Set)17 Isl (org.openkilda.model.Isl)15 HashSet (java.util.HashSet)14 ArrayList (java.util.ArrayList)13 Collections (java.util.Collections)13