Search in sources :

Example 1 with RepositoryFactory

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

the class FlowValidatorTest method setup.

@BeforeClass
public static void setup() {
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    when(repositoryFactory.createFlowRepository()).thenReturn(mock(FlowRepository.class));
    when(repositoryFactory.createSwitchRepository()).thenReturn(mock(SwitchRepository.class));
    when(repositoryFactory.createIslRepository()).thenReturn(mock(IslRepository.class));
    when(repositoryFactory.createSwitchPropertiesRepository()).thenReturn(mock(SwitchPropertiesRepository.class));
    when(repositoryFactory.createFlowMirrorPathRepository()).thenReturn(mock(FlowMirrorPathRepository.class));
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    flowValidator = new FlowValidator(persistenceManager);
}
Also used : SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) IslRepository(org.openkilda.persistence.repositories.IslRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) FlowMirrorPathRepository(org.openkilda.persistence.repositories.FlowMirrorPathRepository) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) BeforeClass(org.junit.BeforeClass)

Example 2 with RepositoryFactory

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

the class LinkOperationsServiceTest method setUpOnce.

@BeforeClass
public static void setUpOnce() {
    RepositoryFactory repositoryFactory = persistenceManager.getRepositoryFactory();
    islRepository = repositoryFactory.createIslRepository();
    switchRepository = repositoryFactory.createSwitchRepository();
    flowRepository = repositoryFactory.createFlowRepository();
}
Also used : RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) BeforeClass(org.junit.BeforeClass)

Example 3 with RepositoryFactory

use of org.openkilda.persistence.repositories.RepositoryFactory 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 4 with RepositoryFactory

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

the class SwitchSyncServiceImplTest method setUp.

@Before
public void setUp() {
    RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
    FlowRepository flowRepository = Mockito.mock(FlowRepository.class);
    FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
    TransitVlanRepository transitVlanRepository = Mockito.mock(TransitVlanRepository.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    when(repositoryFactory.createTransitVlanRepository()).thenReturn(transitVlanRepository);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    Properties configProps = new Properties();
    configProps.setProperty("flow.meter-id.max", "40");
    configProps.setProperty("flow.vlan.max", "50");
    PropertiesBasedConfigurationProvider configurationProvider = new PropertiesBasedConfigurationProvider(configProps);
    FlowResourcesConfig flowResourcesConfig = configurationProvider.getConfiguration(FlowResourcesConfig.class);
    service = new SwitchSyncServiceImpl(carrier, persistenceManager, flowResourcesConfig);
    service.commandBuilder = commandBuilder;
    request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).build();
    flowEntry = new FlowEntry(new FlowSegmentCookie(FlowPathDirection.FORWARD, 7).getValue(), 0, 0, 0, 0, "", 0, 0, 0, 0, null, null, null);
    InstallIngressFlow installingRule = new InstallIngressFlow(UUID.randomUUID(), FLOW_ID, flowEntry.getCookie(), SWITCH_ID, 1, 2, 50, 0, 60, FlowEncapsulationType.TRANSIT_VLAN, OutputVlanType.POP, 10L, 100L, EGRESS_SWITCH_ID, false, false, false, null);
    when(commandBuilder.buildCommandsToSyncMissingRules(eq(SWITCH_ID), any())).thenReturn(singletonList(installingRule));
    missingRules = singletonList(flowEntry.getCookie());
    excessRules = emptyList();
    misconfiguredRules = emptyList();
    excessMeters = emptyList();
}
Also used : InstallIngressFlow(org.openkilda.messaging.command.flow.InstallIngressFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowResourcesConfig(org.openkilda.wfm.share.flow.resources.FlowResourcesConfig) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) TransitVlanRepository(org.openkilda.persistence.repositories.TransitVlanRepository) PropertiesBasedConfigurationProvider(org.openkilda.config.provider.PropertiesBasedConfigurationProvider) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) Properties(java.util.Properties) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Before(org.junit.Before)

Example 5 with RepositoryFactory

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

the class RerouteServiceTest method shouldSkipRerouteRequestsForFlowWithoutAffectedPathSegment.

@Test
public void shouldSkipRerouteRequestsForFlowWithoutAffectedPathSegment() {
    PathNode islSide = new PathNode(SWITCH_A.getSwitchId(), 1, 0);
    FlowPathRepository pathRepository = mock(FlowPathRepository.class);
    when(pathRepository.findBySegmentEndpoint(eq(islSide.getSwitchId()), eq(islSide.getPortNo()))).thenReturn(asList(regularFlow.getForwardPath(), regularFlow.getReversePath()));
    FlowRepository flowRepository = mock(FlowRepository.class);
    PathSegmentRepository pathSegmentRepository = mock(PathSegmentRepository.class);
    doThrow(new EntityNotFoundException("Not found")).when(pathSegmentRepository).updateFailedStatus(any(), any(), anyBoolean());
    RepositoryFactory repositoryFactory = mock(RepositoryFactory.class);
    when(repositoryFactory.createPathSegmentRepository()).thenReturn(pathSegmentRepository);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(pathRepository);
    when(repositoryFactory.createFlowRepository()).thenReturn(flowRepository);
    PersistenceManager persistenceManager = mock(PersistenceManager.class);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    RerouteService rerouteService = new RerouteService(persistenceManager);
    RerouteAffectedFlows request = new RerouteAffectedFlows(islSide, "dummy-reason - unittest");
    rerouteService.rerouteAffectedFlows(carrier, CORRELATION_ID, request);
    verifyZeroInteractions(carrier);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) PathSegmentRepository(org.openkilda.persistence.repositories.PathSegmentRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) EntityNotFoundException(org.openkilda.persistence.exceptions.EntityNotFoundException) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) RerouteAffectedFlows(org.openkilda.messaging.command.reroute.RerouteAffectedFlows) PathNode(org.openkilda.messaging.info.event.PathNode) Test(org.junit.Test)

Aggregations

RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)23 PersistenceManager (org.openkilda.persistence.PersistenceManager)13 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)11 FlowRepository (org.openkilda.persistence.repositories.FlowRepository)11 Test (org.junit.Test)10 YFlowRepository (org.openkilda.persistence.repositories.YFlowRepository)10 FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)6 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)5 PathSegmentRepository (org.openkilda.persistence.repositories.PathSegmentRepository)5 SwitchRepository (org.openkilda.persistence.repositories.SwitchRepository)4 RerouteAffectedFlows (org.openkilda.messaging.command.reroute.RerouteAffectedFlows)3 PathNode (org.openkilda.messaging.info.event.PathNode)3 FlowPath (org.openkilda.model.FlowPath)3 IslRepository (org.openkilda.persistence.repositories.IslRepository)3 PropertiesBasedConfigurationProvider (org.openkilda.config.provider.PropertiesBasedConfigurationProvider)2 YFlowRerouteRequest (org.openkilda.messaging.command.yflow.YFlowRerouteRequest)2 IslEndpoint (org.openkilda.model.IslEndpoint)2 PathSegment (org.openkilda.model.PathSegment)2 SwitchId (org.openkilda.model.SwitchId)2