Search in sources :

Example 1 with Meter

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

the class ValidationServiceImpl method validateMeters.

@Override
public ValidateMetersResult validateMeters(SwitchId switchId, List<MeterSpeakerData> presentMeters, List<MeterSpeakerData> expectedMeterSpeakerData) {
    log.debug("Validating meters on switch {}", switchId);
    Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
    boolean isESwitch = Switch.isNoviflowESwitch(sw.getOfDescriptionManufacturer(), sw.getOfDescriptionHardware());
    List<MeterInfoEntry> actualMeters = presentMeters.stream().map(meter -> convertMeter(switchId, meter)).collect(toList());
    List<MeterInfoEntry> expectedMeters = expectedMeterSpeakerData.stream().map(meter -> convertMeter(switchId, meter)).collect(toList());
    ValidateMetersResult result = comparePresentedAndExpectedMeters(isESwitch, actualMeters, expectedMeters);
    if (!result.getMissingMeters().isEmpty() && log.isErrorEnabled()) {
        log.error("On switch {} the following meters are missed: {}", switchId, metersIntoLogRepresentation(result.getMissingMeters()));
    }
    if (!result.getExcessMeters().isEmpty() && log.isWarnEnabled()) {
        log.warn("On switch {} the following meters are excessive: {}", switchId, metersIntoLogRepresentation(result.getExcessMeters()));
    }
    if (!result.getMisconfiguredMeters().isEmpty() && log.isWarnEnabled()) {
        for (MeterInfoEntry meter : result.getMisconfiguredMeters()) {
            log.warn("On switch {} meter {} is misconfigured: {}", switchId, meter.getMeterId(), getMisconfiguredMeterDifferenceAsString(meter.getExpected(), meter.getActual()));
        }
    }
    return result;
}
Also used : Arrays(java.util.Arrays) FlowPath(org.openkilda.model.FlowPath) ValidationService(org.openkilda.wfm.topology.switchmanager.service.ValidationService) LogicalPortInfoEntry(org.openkilda.messaging.info.switches.LogicalPortInfoEntry) Map(java.util.Map) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) ValidateLogicalPortsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateLogicalPortsResult) ImmutableSet(com.google.common.collect.ImmutableSet) LogicalPortMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.LogicalPortMisconfiguredInfoEntry) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) MeterEntryConverter(org.openkilda.wfm.topology.switchmanager.mappers.MeterEntryConverter) Collection(java.util.Collection) Set(java.util.Set) GroupEntryConverter(org.openkilda.wfm.topology.switchmanager.mappers.GroupEntryConverter) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) Meter(org.openkilda.model.Meter) GroupInfoEntry(org.openkilda.messaging.info.switches.GroupInfoEntry) MeterMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.MeterMisconfiguredInfoEntry) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) FlowMeter(org.openkilda.model.FlowMeter) LogicalPort(org.openkilda.messaging.model.grpc.LogicalPort) BucketEntry(org.openkilda.messaging.info.switches.GroupInfoEntry.BucketEntry) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) ImmutableList(com.google.common.collect.ImmutableList) Cookie(org.openkilda.model.cookie.Cookie) LogicalPortMapper(org.openkilda.wfm.topology.switchmanager.mappers.LogicalPortMapper) PersistenceManager(org.openkilda.persistence.PersistenceManager) ValidateGroupsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateGroupsResult) LogicalPortType(org.openkilda.messaging.info.switches.LogicalPortType) Switch(org.openkilda.model.Switch) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Collectors.toList(java.util.stream.Collectors.toList) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchId(org.openkilda.model.SwitchId) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) LagLogicalPortRepository(org.openkilda.persistence.repositories.LagLogicalPortRepository) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) Switch(org.openkilda.model.Switch) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1