Search in sources :

Example 1 with SwitchNotFoundException

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

the class SwitchOperationsBolt method deleteSwitch.

private DeleteSwitchResponse deleteSwitch(DeleteSwitchRequest request) {
    SwitchId switchId = request.getSwitchId();
    boolean force = request.isForce();
    boolean deleted = transactionManager.doInTransaction(() -> {
        try {
            if (!force) {
                switchOperationsService.checkSwitchIsDeactivated(switchId);
                switchOperationsService.checkSwitchHasNoFlows(switchId);
                switchOperationsService.checkSwitchHasNoFlowSegments(switchId);
                switchOperationsService.checkSwitchHasNoIsls(switchId);
            }
            return switchOperationsService.deleteSwitch(switchId, force);
        } catch (SwitchNotFoundException e) {
            String message = format("Could not delete switch '%s': '%s'", switchId, e.getMessage());
            throw new MessageException(ErrorType.NOT_FOUND, message, "Switch is not found.");
        } catch (IllegalSwitchStateException e) {
            String message = format("Could not delete switch '%s': '%s'", switchId, e.getMessage());
            throw new MessageException(ErrorType.REQUEST_INVALID, message, "Switch is in illegal state");
        }
    });
    if (deleted) {
        DeactivateSwitchInfoData data = new DeactivateSwitchInfoData(switchId);
        getOutput().emit(StreamType.DISCO.toString(), getCurrentTuple(), new Values(data, getCorrelationId()));
    }
    log.info("{} deletion of switch '{}'", deleted ? "Successful" : "Unsuccessful", switchId);
    return new DeleteSwitchResponse(deleted);
}
Also used : DeleteSwitchResponse(org.openkilda.messaging.nbtopology.response.DeleteSwitchResponse) IllegalSwitchStateException(org.openkilda.wfm.error.IllegalSwitchStateException) MessageException(org.openkilda.messaging.error.MessageException) Values(org.apache.storm.tuple.Values) SwitchId(org.openkilda.model.SwitchId) DeactivateSwitchInfoData(org.openkilda.messaging.info.event.DeactivateSwitchInfoData) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 2 with SwitchNotFoundException

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

the class SwitchOperationsService method getSwitchConnections.

/**
 * Find and return the set of connections to the speakers for specific switch.
 */
public SwitchConnectionsResponse getSwitchConnections(SwitchId switchId) throws SwitchNotFoundException {
    Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
    SwitchAvailabilityData.SwitchAvailabilityDataBuilder payload = SwitchAvailabilityData.builder();
    for (SwitchConnect entry : switchConnectRepository.findBySwitchId(switchId)) {
        payload.connection(SwitchMapper.INSTANCE.map(entry));
    }
    return new SwitchConnectionsResponse(sw.getSwitchId(), sw.getStatus(), payload.build());
}
Also used : Switch(org.openkilda.model.Switch) SwitchAvailabilityData(org.openkilda.messaging.model.SwitchAvailabilityData) SwitchConnect(org.openkilda.model.SwitchConnect) SwitchConnectionsResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectionsResponse) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 3 with SwitchNotFoundException

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

the class SwitchOperationsService method deleteSwitch.

/**
 * Delete switch.
 *
 * @param switchId ID of switch to be deleted
 * @param force    if True all switch relationships will be deleted too.
 *                 If False switch will be deleted only if it has no relations.
 * @return True if switch was deleted, False otherwise
 * @throws SwitchNotFoundException if switch is not found
 */
public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException {
    transactionManager.doInTransaction(() -> {
        Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
        switchPropertiesRepository.findBySwitchId(sw.getSwitchId()).ifPresent(sp -> switchPropertiesRepository.remove(sp));
        portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()).forEach(portPropertiesRepository::remove);
        if (force) {
            // remove() removes switch along with all relationships.
            switchRepository.remove(sw);
        } else {
            // removeIfNoDependant() is used to be sure that we wouldn't delete switch
            // if it has even one relationship.
            switchRepository.removeIfNoDependant(sw);
        }
    });
    return !switchRepository.exists(switchId);
}
Also used : Switch(org.openkilda.model.Switch) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 4 with SwitchNotFoundException

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

the class SwitchOperationsService method getSwitch.

/**
 * Get switch by switch id.
 *
 * @param switchId switch id.
 */
public GetSwitchResponse getSwitch(SwitchId switchId) throws SwitchNotFoundException {
    Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
    switchRepository.detach(sw);
    return new GetSwitchResponse(sw);
}
Also used : GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) Switch(org.openkilda.model.Switch) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 5 with SwitchNotFoundException

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

the class FlowValidationHubServiceTest method testMainPath.

@Test
public void testMainPath() throws DuplicateKeyException, UnknownKeyException {
    FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {

        @Override
        public void sendSpeakerRequest(String flowId, CommandData commandData) {
            assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
            List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
            if (commandData instanceof DumpRulesForFlowHsRequest) {
                assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
            } else if (commandData instanceof DumpMetersForFlowHsRequest) {
                assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
            } else {
                assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
            }
        }

        @Override
        public void sendNorthboundResponse(List<? extends InfoData> message) {
            assertEquals(4, message.size());
            try {
                assertEquals(flowValidationService.validateFlow(TEST_FLOW_ID_A, getSwitchFlowEntriesWithTransitVlan(), getSwitchMeterEntries(), getSwitchGroupEntries()), message);
            } catch (FlowNotFoundException | SwitchNotFoundException e) {
            // tested in the FlowValidationServiceTest
            }
        }

        @Override
        public void sendNorthboundResponse(Message message) {
            fail();
        }

        @Override
        public void cancelTimeoutCallback(String key) {
            assertEquals(TEST_KEY, key);
        }

        @Override
        public void sendInactive() {
        }
    };
    flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
    buildTransitVlanFlow("");
    flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
    for (SwitchFlowEntries switchFlowEntries : getSwitchFlowEntriesWithTransitVlan()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchFlowEntries);
    }
    for (SwitchMeterEntries switchMeterEntries : getSwitchMeterEntries()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchMeterEntries);
    }
    for (SwitchGroupEntries switchGroupEntries : getSwitchGroupEntries()) {
        flowValidationHubService.handleAsyncResponse(TEST_KEY, switchGroupEntries);
    }
}
Also used : DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) Message(org.openkilda.messaging.Message) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandContext(org.openkilda.wfm.CommandContext) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) FlowValidationRequest(org.openkilda.messaging.command.flow.FlowValidationRequest) InfoData(org.openkilda.messaging.info.InfoData) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) List(java.util.List) CommandData(org.openkilda.messaging.command.CommandData) Test(org.junit.Test)

Aggregations

SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)12 Switch (org.openkilda.model.Switch)7 SwitchId (org.openkilda.model.SwitchId)6 MessageException (org.openkilda.messaging.error.MessageException)4 CommandContext (org.openkilda.wfm.CommandContext)4 List (java.util.List)3 Values (org.apache.storm.tuple.Values)3 GetSwitchResponse (org.openkilda.messaging.nbtopology.response.GetSwitchResponse)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Message (org.openkilda.messaging.Message)2 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)2 InfoData (org.openkilda.messaging.info.InfoData)2 DeactivateSwitchInfoData (org.openkilda.messaging.info.event.DeactivateSwitchInfoData)2 FlowPath (org.openkilda.model.FlowPath)2 IslEndpoint (org.openkilda.model.IslEndpoint)2 SwitchPropertiesNotFoundException (org.openkilda.wfm.error.SwitchPropertiesNotFoundException)2