Search in sources :

Example 1 with SwitchRepository

use of org.openkilda.persistence.repositories.SwitchRepository 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 SwitchRepository

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

the class LinkOperationsBoltTest method shouldCreateLinkProps.

@Test
public void shouldCreateLinkProps() {
    SwitchRepository switchRepository = persistenceManager.getRepositoryFactory().createSwitchRepository();
    switchRepository.add(Switch.builder().switchId(SWITCH_ID_1).build());
    switchRepository.add(Switch.builder().switchId(SWITCH_ID_2).build());
    LinkOperationsBolt bolt = new LinkOperationsBolt(persistenceManager);
    bolt.prepare(null, topologyContext, null);
    LinkPropsPut linkPropsPutRequest = new LinkPropsPut(new LinkPropsDto(new NetworkEndpoint(SWITCH_ID_1, 1), new NetworkEndpoint(SWITCH_ID_2, 1), Collections.emptyMap()));
    LinkPropsResponse response = (LinkPropsResponse) bolt.processRequest(null, linkPropsPutRequest).get(0);
    assertNotNull(response.getLinkProps());
}
Also used : LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) LinkPropsPut(org.openkilda.messaging.nbtopology.request.LinkPropsPut) LinkPropsDto(org.openkilda.messaging.model.LinkPropsDto) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) Test(org.junit.Test)

Example 3 with SwitchRepository

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

the class SwitchValidateServiceImplTest method setUp.

@Before
public void setUp() {
    RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
    FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
    SwitchRepository switchRepository = Mockito.mock(SwitchRepository.class);
    when(switchRepository.findById(eq(SWITCH_ID))).thenReturn(Optional.of(SWITCH_1));
    when(switchRepository.findById(eq(SWITCH_ID_MISSING))).thenReturn(Optional.empty());
    LagLogicalPortRepository lagLogicalPortRepository = Mockito.mock(LagLogicalPortRepository.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
    when(repositoryFactory.createSwitchRepository()).thenReturn(switchRepository);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    service = new SwitchValidateServiceImpl(carrier, persistenceManager, validationService, ruleManager);
    request = SwitchValidateRequest.builder().switchId(SWITCH_ID).processMeters(true).build();
    flowSpeakerData = FlowSpeakerData.builder().ofVersion(OfVersion.OF_13).cookie(new Cookie(1L)).table(OfTable.INPUT).priority(10).match(emptySet()).instructions(Instructions.builder().build()).flags(emptySet()).build();
    meterSpeakerData = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
    when(validationService.validateRules(any(), any(), any())).thenReturn(new ValidateRulesResult(newHashSet(flowSpeakerData.getCookie().getValue()), emptySet(), emptySet(), emptySet()));
    when(validationService.validateMeters(any(), any(), any())).thenReturn(new ValidateMetersResult(emptyList(), emptyList(), emptyList(), emptyList()));
}
Also used : LagLogicalPortRepository(org.openkilda.persistence.repositories.LagLogicalPortRepository) Cookie(org.openkilda.model.cookie.Cookie) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) MeterId(org.openkilda.model.MeterId) Before(org.junit.Before)

Example 4 with SwitchRepository

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

the class NetworkIslServiceTest method initialUp.

@Test
@Ignore("incomplete")
public void initialUp() {
    persistenceManager = InMemoryGraphPersistenceManager.newInstance();
    persistenceManager.install();
    emulateEmptyPersistentDb();
    SwitchRepository switchRepository = persistenceManager.getRepositoryFactory().createSwitchRepository();
    Switch swA = Switch.builder().switchId(endpointAlpha1.getDatapath()).description("alpha").build();
    switchRepository.add(swA);
    switchPropertiesRepository.add(SwitchProperties.builder().multiTable(false).supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES).switchObj(swA).build());
    Switch swB = Switch.builder().switchId(endpointBeta2.getDatapath()).description("alpha").build();
    switchRepository.add(swB);
    switchPropertiesRepository.add(SwitchProperties.builder().multiTable(false).supportedTransitEncapsulation(SwitchProperties.DEFAULT_FLOW_ENCAPSULATION_TYPES).switchObj(swB).build());
    IslReference ref = new IslReference(endpointAlpha1, endpointBeta2);
    IslDataHolder islData = new IslDataHolder(1000, 1000, 1000);
    service = new NetworkIslService(carrier, persistenceManager, options);
    service.islUp(ref.getSource(), ref, islData);
    System.out.println(mockingDetails(carrier).printInvocations());
    System.out.println(mockingDetails(islRepository).printInvocations());
}
Also used : Switch(org.openkilda.model.Switch) IslReference(org.openkilda.wfm.share.model.IslReference) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) IslDataHolder(org.openkilda.wfm.topology.network.model.IslDataHolder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with SwitchRepository

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

the class MeterPoolTest method setUp.

@Before
public void setUp() {
    meterPool = new MeterPool(persistenceManager, MIN_METER_ID, MAX_METER_ID, 1);
    SwitchRepository switchRepository = persistenceManager.getRepositoryFactory().createSwitchRepository();
    switchRepository.add(Switch.builder().switchId(SWITCH_ID).build());
    flowMeterRepository = persistenceManager.getRepositoryFactory().createFlowMeterRepository();
}
Also used : SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) Before(org.junit.Before)

Aggregations

SwitchRepository (org.openkilda.persistence.repositories.SwitchRepository)6 Before (org.junit.Before)3 Switch (org.openkilda.model.Switch)3 Test (org.junit.Test)2 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)2 HashMap (java.util.HashMap)1 Ignore (org.junit.Ignore)1 LinkPropsDto (org.openkilda.messaging.model.LinkPropsDto)1 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)1 LinkPropsPut (org.openkilda.messaging.nbtopology.request.LinkPropsPut)1 LinkPropsResponse (org.openkilda.messaging.nbtopology.response.LinkPropsResponse)1 Isl (org.openkilda.model.Isl)1 MeterId (org.openkilda.model.MeterId)1 SwitchId (org.openkilda.model.SwitchId)1 SwitchStatus (org.openkilda.model.SwitchStatus)1 Cookie (org.openkilda.model.cookie.Cookie)1 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)1 IslRepository (org.openkilda.persistence.repositories.IslRepository)1 KildaConfigurationRepository (org.openkilda.persistence.repositories.KildaConfigurationRepository)1 LagLogicalPortRepository (org.openkilda.persistence.repositories.LagLogicalPortRepository)1