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();
}
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());
}
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()));
}
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());
}
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();
}
Aggregations