Search in sources :

Example 11 with KildaFeatureToggles

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

the class SwitchRuleServiceImpl method deleteRules.

@Override
public void deleteRules(String key, SwitchRulesDeleteRequest data) {
    isOperationCompleted = false;
    SwitchId switchId = data.getSwitchId();
    if (!switchRepository.exists(switchId)) {
        ErrorData errorData = new ErrorData(ErrorType.NOT_FOUND, format("Switch %s not found", switchId), "Error when deleting switch rules");
        ErrorMessage errorMessage = new ErrorMessage(errorData, System.currentTimeMillis(), key);
        carrier.response(key, errorMessage);
        return;
    }
    Optional<SwitchProperties> switchProperties = switchPropertiesRepository.findBySwitchId(switchId);
    KildaFeatureToggles featureToggles = featureTogglesRepository.getOrDefault();
    boolean server42FlowRttFeatureToggle = featureToggles.getServer42FlowRtt();
    data.setServer42FlowRttFeatureToggle(server42FlowRttFeatureToggle);
    data.setServer42IslRttEnabled(featureToggles.getServer42IslRtt() && switchProperties.map(SwitchProperties::hasServer42IslRttEnabled).orElse(false));
    if (switchProperties.isPresent()) {
        data.setMultiTable(switchProperties.get().isMultiTable());
        data.setSwitchLldp(switchProperties.get().isSwitchLldp());
        data.setSwitchArp(switchProperties.get().isSwitchArp());
        data.setServer42FlowRttSwitchProperty(switchProperties.get().isServer42FlowRtt());
        data.setServer42Port(switchProperties.get().getServer42Port());
        data.setServer42Vlan(switchProperties.get().getServer42Vlan());
        data.setServer42MacAddress(switchProperties.get().getServer42MacAddress());
        Collection<FlowPath> flowPaths = flowPathRepository.findBySrcSwitch(switchId);
        List<Integer> flowPorts = new ArrayList<>();
        Set<Integer> flowLldpPorts = new HashSet<>();
        Set<Integer> flowArpPorts = new HashSet<>();
        Set<Integer> server42FlowPorts = new HashSet<>();
        fillFlowPorts(switchProperties.get(), flowPaths, flowPorts, flowLldpPorts, flowArpPorts, server42FlowPorts, server42FlowRttFeatureToggle && switchProperties.get().isServer42FlowRtt());
        data.setFlowPorts(flowPorts);
        data.setFlowLldpPorts(flowLldpPorts);
        data.setFlowArpPorts(flowArpPorts);
        data.setServer42FlowRttPorts(server42FlowPorts);
        List<Integer> islPorts = islRepository.findBySrcSwitch(switchId).stream().map(isl -> isl.getSrcPort()).collect(Collectors.toList());
        data.setIslPorts(islPorts);
    }
    carrier.sendCommandToSpeaker(key, data);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowPath(org.openkilda.model.FlowPath) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchRuleService(org.openkilda.wfm.topology.switchmanager.service.SwitchRuleService) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) SwitchManagerCarrier(org.openkilda.wfm.topology.switchmanager.service.SwitchManagerCarrier) IslRepository(org.openkilda.persistence.repositories.IslRepository) SwitchProperties(org.openkilda.model.SwitchProperties) ErrorType(org.openkilda.messaging.error.ErrorType) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) Optional(java.util.Optional) ErrorData(org.openkilda.messaging.error.ErrorData) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) FlowPath(org.openkilda.model.FlowPath) ErrorData(org.openkilda.messaging.error.ErrorData) SwitchProperties(org.openkilda.model.SwitchProperties) HashSet(java.util.HashSet)

Example 12 with KildaFeatureToggles

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

the class SpeakerStatsRequesterBoltTest method doNotRequestGrpcStatsIfNoActiveSwitchesTest.

@Test
public void doNotRequestGrpcStatsIfNoActiveSwitchesTest() {
    KildaFeatureToggles featureToggles = new KildaFeatureToggles(KildaFeatureToggles.DEFAULTS);
    featureToggles.setCollectGrpcStats(true);
    when(switchRepository.findActive()).thenReturn(Collections.emptyList());
    when(featureTogglesRepository.getOrDefault()).thenReturn(featureToggles);
    runDoNotRequestGrpcStatsTest();
    verify(switchRepository, times(1)).findActive();
}
Also used : KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Test(org.junit.Test)

Example 13 with KildaFeatureToggles

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

the class SpeakerStatsRequesterBoltTest method doNotRequestGrpcStatsIfNoNoviflowSwitchesTest.

@Test
public void doNotRequestGrpcStatsIfNoNoviflowSwitchesTest() {
    KildaFeatureToggles featureToggles = new KildaFeatureToggles(KildaFeatureToggles.DEFAULTS);
    featureToggles.setCollectGrpcStats(true);
    Switch sw = Switch.builder().switchId(new SwitchId(1)).build();
    sw.setOfDescriptionSoftware("some");
    when(switchRepository.findActive()).thenReturn(Collections.emptyList());
    when(featureTogglesRepository.getOrDefault()).thenReturn(featureToggles);
    runDoNotRequestGrpcStatsTest();
    verify(switchRepository, times(1)).findActive();
}
Also used : Switch(org.openkilda.model.Switch) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) SwitchId(org.openkilda.model.SwitchId) Test(org.junit.Test)

Example 14 with KildaFeatureToggles

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

the class SpeakerStatsRequesterBoltTest method requestGrpcStatsForNoviflowSwitchesTest.

@Test
public void requestGrpcStatsForNoviflowSwitchesTest() {
    KildaFeatureToggles featureToggles = new KildaFeatureToggles(KildaFeatureToggles.DEFAULTS);
    featureToggles.setCollectGrpcStats(true);
    String address = "192.168.1.1";
    Switch sw = Switch.builder().switchId(new SwitchId(1)).socketAddress(new IpSocketAddress(address, 20)).build();
    sw.setOfDescriptionSoftware("NW500.1.1");
    when(switchRepository.findActive()).thenReturn(Collections.singleton(sw));
    when(featureTogglesRepository.getOrDefault()).thenReturn(featureToggles);
    StatsRequesterBolt statsRequesterBolt = new StatsRequesterBolt(persistenceManager, ZooKeeperSpout.SPOUT_ID);
    statsRequesterBolt.prepare(Collections.emptyMap(), topologyContext, output);
    statsRequesterBolt.execute(startTuple);
    verify(output).emit(eq(ZkStreams.ZK.toString()), any(Tuple.class), anyList());
    statsRequesterBolt.execute(input);
    ArgumentCaptor<Values> values = ArgumentCaptor.forClass(Values.class);
    verify(output, times(1)).emit(eq(STATS_REQUEST_STREAM), any(Tuple.class), anyList());
    verify(output, times(1)).emit(eq(GRPC_REQUEST_STREAM), any(Tuple.class), values.capture());
    Values capturedValues = values.getValue();
    assertTrue(capturedValues.get(0) instanceof CommandMessage);
    CommandMessage commandMessage = (CommandMessage) capturedValues.get(0);
    assertTrue(commandMessage.getData() instanceof GetPacketInOutStatsRequest);
    GetPacketInOutStatsRequest request = (GetPacketInOutStatsRequest) commandMessage.getData();
    assertEquals(address, request.getAddress());
}
Also used : Switch(org.openkilda.model.Switch) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Values(org.apache.storm.tuple.Values) SwitchId(org.openkilda.model.SwitchId) GetPacketInOutStatsRequest(org.openkilda.messaging.command.grpc.GetPacketInOutStatsRequest) IpSocketAddress(org.openkilda.model.IpSocketAddress) Tuple(org.apache.storm.tuple.Tuple) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Aggregations

KildaFeatureToggles (org.openkilda.model.KildaFeatureToggles)14 Test (org.junit.Test)6 SwitchId (org.openkilda.model.SwitchId)5 KildaFeatureTogglesRepository (org.openkilda.persistence.repositories.KildaFeatureTogglesRepository)5 ArrayList (java.util.ArrayList)3 Switch (org.openkilda.model.Switch)3 SwitchProperties (org.openkilda.model.SwitchProperties)3 String.format (java.lang.String.format)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Before (org.junit.Before)2 SwitchRulesDeleteRequest (org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest)2 SwitchRulesInstallRequest (org.openkilda.messaging.command.switches.SwitchRulesInstallRequest)2 ErrorData (org.openkilda.messaging.error.ErrorData)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2 ErrorType (org.openkilda.messaging.error.ErrorType)2