Search in sources :

Example 1 with IslRepository

use of org.openkilda.persistence.repositories.IslRepository in project open-kilda by telstra.

the class NetworkHistoryService method loadNetworkHistory.

// -- private --
private Collection<HistoryFacts> loadNetworkHistory() {
    RepositoryFactory repositoryFactory = persistenceManager.getRepositoryFactory();
    SwitchRepository switchRepository = repositoryFactory.createSwitchRepository();
    HashMap<SwitchId, HistoryFacts> switchById = new HashMap<>();
    for (Switch switchEntry : switchRepository.findAll()) {
        SwitchId switchId = switchEntry.getSwitchId();
        SwitchStatus switchStatus = switchEntry.getStatus();
        switchById.put(switchId, new HistoryFacts(switchId, switchStatus));
    }
    IslRepository islRepository = repositoryFactory.createIslRepository();
    for (Isl islEntry : islRepository.findAll()) {
        HistoryFacts history = switchById.get(islEntry.getSrcSwitchId());
        if (history == null) {
            log.error("Orphaned ISL relation - {}-{} (read race condition?)", islEntry.getSrcSwitchId(), islEntry.getSrcPort());
            continue;
        }
        islRepository.detach(islEntry);
        history.addLink(islEntry);
    }
    return switchById.values();
}
Also used : IslRepository(org.openkilda.persistence.repositories.IslRepository) Isl(org.openkilda.model.Isl) Switch(org.openkilda.model.Switch) HashMap(java.util.HashMap) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) SwitchId(org.openkilda.model.SwitchId) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) HistoryFacts(org.openkilda.wfm.topology.network.model.facts.HistoryFacts) SwitchStatus(org.openkilda.model.SwitchStatus)

Example 2 with IslRepository

use of org.openkilda.persistence.repositories.IslRepository in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldFailRerouteFlowIfMultipleOverprovisionBandwidth.

@Test
public void shouldFailRerouteFlowIfMultipleOverprovisionBandwidth() throws RecoverableException, UnroutableFlowException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    IslRepository repository = setupIslRepositorySpy();
    doReturn(-1L).when(repository).updateAvailableBandwidth(any(), anyInt(), any(), anyInt());
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    testExpectedFailure(dummyRequestKey, request, commandContext, origin, FlowStatus.UP, ErrorType.INTERNAL_ERROR);
    verify(repository, times(PATH_ALLOCATION_RETRIES_LIMIT + 1)).updateAvailableBandwidth(any(), anyInt(), any(), anyInt());
}
Also used : IslRepository(org.openkilda.persistence.repositories.IslRepository) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 3 with IslRepository

use of org.openkilda.persistence.repositories.IslRepository in project open-kilda by telstra.

the class FlowUpdateServiceTest method shouldFailUpdateFlowIfMultipleOverprovisionBandwidth.

@Test
public void shouldFailUpdateFlowIfMultipleOverprovisionBandwidth() throws RecoverableException, UnroutableFlowException, DuplicateKeyException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    IslRepository repository = setupIslRepositorySpy();
    doReturn(-1L).when(repository).updateAvailableBandwidth(any(), anyInt(), any(), anyInt());
    FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
    testExpectedFailure(request, origin, ErrorType.INTERNAL_ERROR);
    verify(repository, times(PATH_ALLOCATION_RETRIES_LIMIT + 1)).updateAvailableBandwidth(any(), anyInt(), any(), anyInt());
}
Also used : IslRepository(org.openkilda.persistence.repositories.IslRepository) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 4 with IslRepository

use of org.openkilda.persistence.repositories.IslRepository in project open-kilda by telstra.

the class NetworkIslServiceTest method initialMoveEvent.

@Test
@Ignore("become invalid due to change initialisation logic")
public void initialMoveEvent() {
    emulateEmptyPersistentDb();
    IslReference ref = new IslReference(endpointAlpha1, endpointBeta2);
    service.islMove(ref.getSource(), ref);
    // System.out.println(mockingDetails(carrier).printInvocations());
    verify(carrier, times(2)).triggerReroute(any(RerouteAffectedFlows.class));
    // System.out.println(mockingDetails(islRepository).printInvocations());
    verify(islRepository).add(argThat(link -> link.getSrcSwitchId().equals(endpointAlpha1.getDatapath()) && link.getSrcPort() == endpointAlpha1.getPortNumber() && link.getDestSwitchId().equals(endpointBeta2.getDatapath()) && link.getDestPort() == endpointBeta2.getPortNumber() && link.getActualStatus() == IslStatus.INACTIVE && link.getStatus() == IslStatus.INACTIVE));
    verify(islRepository).add(argThat(link -> link.getSrcSwitchId().equals(endpointBeta2.getDatapath()) && link.getSrcPort() == endpointBeta2.getPortNumber() && link.getDestSwitchId().equals(endpointAlpha1.getDatapath()) && link.getDestPort() == endpointAlpha1.getPortNumber() && link.getActualStatus() == IslStatus.INACTIVE && link.getStatus() == IslStatus.INACTIVE));
    verifyNoMoreInteractions(carrier);
}
Also used : Mockito.mockingDetails(org.mockito.Mockito.mockingDetails) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) IslReference(org.openkilda.wfm.share.model.IslReference) NetworkOptions(org.openkilda.wfm.topology.network.model.NetworkOptions) IslDataHolder(org.openkilda.wfm.topology.network.model.IslDataHolder) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) RerouteAffectedFlows(org.openkilda.messaging.command.reroute.RerouteAffectedFlows) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Duration(java.time.Duration) Map(java.util.Map) LinkProps(org.openkilda.model.LinkProps) ClassRule(org.junit.ClassRule) SwitchProperties(org.openkilda.model.SwitchProperties) IslStatusUpdateNotification(org.openkilda.messaging.info.event.IslStatusUpdateNotification) IslDownReason(org.openkilda.model.IslDownReason) ManualClock(org.openkilda.stubs.ManualClock) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) BfdStatusUpdate(org.openkilda.wfm.topology.network.model.BfdStatusUpdate) RetryPolicy(net.jodah.failsafe.RetryPolicy) EqualsAndHashCode(lombok.EqualsAndHashCode) Instant(java.time.Instant) BfdSessionStatus(org.openkilda.model.BfdSessionStatus) Objects(java.util.Objects) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) List(java.util.List) Optional(java.util.Optional) RerouteInactiveFlows(org.openkilda.messaging.command.reroute.RerouteInactiveFlows) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) RoundTripStatus(org.openkilda.wfm.topology.network.model.RoundTripStatus) BfdProperties(org.openkilda.model.BfdProperties) TransactionManager(org.openkilda.persistence.tx.TransactionManager) Getter(lombok.Getter) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) RemoveIslDefaultRulesResult(org.openkilda.messaging.info.discovery.RemoveIslDefaultRulesResult) LinkPropsRepository(org.openkilda.persistence.repositories.LinkPropsRepository) IslControllerNotFoundException(org.openkilda.wfm.topology.network.error.IslControllerNotFoundException) IslRepository(org.openkilda.persistence.repositories.IslRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) InMemoryGraphPersistenceManager(org.openkilda.persistence.inmemory.InMemoryGraphPersistenceManager) Switch(org.openkilda.model.Switch) Endpoint(org.openkilda.wfm.share.model.Endpoint) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) IslStatus(org.openkilda.model.IslStatus) PathNode(org.openkilda.messaging.info.event.PathNode) Mockito.verify(org.mockito.Mockito.verify) Failsafe(net.jodah.failsafe.Failsafe) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) SwitchId(org.openkilda.model.SwitchId) Ignore(org.junit.Ignore) InstallIslDefaultRulesResult(org.openkilda.messaging.info.discovery.InstallIslDefaultRulesResult) TransactionCallbackWithoutResult(org.openkilda.persistence.tx.TransactionCallbackWithoutResult) AllArgsConstructor(lombok.AllArgsConstructor) Assert(org.junit.Assert) Mockito.reset(org.mockito.Mockito.reset) Isl(org.openkilda.model.Isl) SwitchStatus(org.openkilda.model.SwitchStatus) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) NetworkTopologyDashboardLogger(org.openkilda.wfm.topology.network.NetworkTopologyDashboardLogger) IslReference(org.openkilda.wfm.share.model.IslReference) RerouteAffectedFlows(org.openkilda.messaging.command.reroute.RerouteAffectedFlows) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

IslRepository (org.openkilda.persistence.repositories.IslRepository)4 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Flow (org.openkilda.model.Flow)2 Isl (org.openkilda.model.Isl)2 Switch (org.openkilda.model.Switch)2 SwitchId (org.openkilda.model.SwitchId)2 SwitchStatus (org.openkilda.model.SwitchStatus)2 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)2 SwitchRepository (org.openkilda.persistence.repositories.SwitchRepository)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 AllArgsConstructor (lombok.AllArgsConstructor)1 EqualsAndHashCode (lombok.EqualsAndHashCode)1 Getter (lombok.Getter)1