Search in sources :

Example 1 with SwitchNotFoundException

use of org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException 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)

Example 2 with SwitchNotFoundException

use of org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException in project open-kilda by telstra.

the class SwitchValidateFsm method emitRequests.

public void emitRequests(SwitchValidateState from, SwitchValidateState to, SwitchValidateEvent event, SwitchValidateContext context) {
    try {
        SwitchId switchId = getSwitchId();
        log.info("The switch validate process for {} has been started (key={})", switchId, key);
        // FIXME(surabujin): not reliable check - corresponding error from speaker is much more better
        Optional<Switch> sw = switchRepository.findById(switchId);
        if (!sw.isPresent()) {
            throw new SwitchNotFoundException(switchId);
        }
        requestSwitchOfFlows();
        requestSwitchOfGroups();
        if (sw.get().getFeatures().contains(LAG)) {
            // at this moment Kilda validated only LAG logical ports
            Optional<String> ipAddress = sw.map(Switch::getSocketAddress).map(IpSocketAddress::getAddress);
            if (ipAddress.isPresent()) {
                requestLogicalPorts(ipAddress.get());
            } else {
                log.warn("Unable to get IP address of switch {} to get LAGs", switchId);
            }
        }
        if (request.isProcessMeters()) {
            requestSwitchMeters();
        }
    } catch (Exception ex) {
        log.error("Failure in emitRequests", ex);
        throw ex;
    }
}
Also used : Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) IpSocketAddress(org.openkilda.model.IpSocketAddress) SwitchManagerException(org.openkilda.wfm.topology.switchmanager.error.SwitchManagerException) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException)

Example 3 with SwitchNotFoundException

use of org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException in project open-kilda by telstra.

the class DeleteLagPortFsm method createGrpcRequest.

void createGrpcRequest(DeleteLagState from, DeleteLagState to, DeleteLagEvent event, DeleteLagContext context) {
    log.info("Removing LAG {} on switch {}. Key={}", request, switchId, key);
    try {
        lagPortOperationService.ensureDeleteIsPossible(switchId, request.getLogicalPortNumber());
        String ipAddress = lagPortOperationService.getSwitchIpAddress(switchId);
        grpcRequest = new DeleteLogicalPortRequest(ipAddress, request.getLogicalPortNumber());
    } catch (LagPortNotFoundException | InvalidDataException | SwitchNotFoundException | InconsistentDataException e) {
        log.error(format("Unable to delete LAG logical port %d on switch %s. Error: %s", request.getLogicalPortNumber(), switchId, e.getMessage()), e);
        fire(ERROR, DeleteLagContext.builder().error(e).build());
    }
}
Also used : LagPortNotFoundException(org.openkilda.wfm.topology.switchmanager.error.LagPortNotFoundException) DeleteLogicalPortRequest(org.openkilda.messaging.command.grpc.DeleteLogicalPortRequest) InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) InconsistentDataException(org.openkilda.wfm.topology.switchmanager.error.InconsistentDataException)

Example 4 with SwitchNotFoundException

use of org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException in project open-kilda by telstra.

the class CreateLagPortFsm method createLagInDb.

void createLagInDb(CreateLagState from, CreateLagState to, CreateLagEvent event, CreateLagContext context) {
    log.info("Creating LAG {} on switch {}. Key={}", request, switchId, key);
    try {
        HashSet<Integer> targetPorts = new HashSet<>(request.getPortNumbers());
        lagLogicalPortNumber = lagPortOperationService.createLagPort(switchId, targetPorts);
        String ipAddress = lagPortOperationService.getSwitchIpAddress(switchId);
        grpcRequest = new CreateLogicalPortRequest(ipAddress, request.getPortNumbers(), lagLogicalPortNumber, LAG);
    } catch (InvalidDataException | InconsistentDataException | SwitchNotFoundException e) {
        log.error(format("Unable to handle %s. Error: %s", request, e.getMessage()), e);
        fire(ERROR, CreateLagContext.builder().error(e).build());
    }
}
Also used : InvalidDataException(org.openkilda.wfm.topology.switchmanager.error.InvalidDataException) InconsistentDataException(org.openkilda.wfm.topology.switchmanager.error.InconsistentDataException) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) HashSet(java.util.HashSet) CreateLogicalPortRequest(org.openkilda.messaging.command.grpc.CreateLogicalPortRequest)

Aggregations

SwitchNotFoundException (org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException)4 HashSet (java.util.HashSet)2 Switch (org.openkilda.model.Switch)2 SwitchId (org.openkilda.model.SwitchId)2 InconsistentDataException (org.openkilda.wfm.topology.switchmanager.error.InconsistentDataException)2 InvalidDataException (org.openkilda.wfm.topology.switchmanager.error.InvalidDataException)2 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 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1