@Test public void shouldForceDeleteBusyIsl() throws IslNotFoundException, IllegalIslStateException { createIsl(IslStatus.INACTIVE); createFlow("test_flow_id", TEST_SWITCH_A_ID, TEST_SWITCH_A_PORT, TEST_SWITCH_B_ID, TEST_SWITCH_B_PORT); linkOperationsService .deleteIsl(TEST_SWITCH_A_ID, TEST_SWITCH_A_PORT, TEST_SWITCH_B_ID, TEST_SWITCH_B_PORT, true); assertTrue(islRepository.findAll().isEmpty()); }
public Collection<Isl> deleteIsl(SwitchId sourceSwitch, int sourcePort, SwitchId destinationSwitch, int destinationPort, boolean force) throws IllegalIslStateException, IslNotFoundException { log.info("Delete ISL with following parameters: " + "source switch '{}', source port '{}', destination switch '{}', destination port '{}', " + "force '{}'", sourceSwitch, sourcePort, destinationSwitch, destinationPort, force); return transactionManager.doInTransaction(() -> { List<Isl> isls = new ArrayList<>(); islRepository.findByEndpoints(sourceSwitch, sourcePort, destinationSwitch, destinationPort).ifPresent(isls::add); islRepository.findByEndpoints(destinationSwitch, destinationPort, sourceSwitch, sourcePort).ifPresent(isls::add); if (isls.isEmpty()) { throw new IslNotFoundException(sourceSwitch, sourcePort, destinationSwitch, destinationPort); } if (!force) { if (isls.stream().anyMatch(x -> x.getStatus() == IslStatus.ACTIVE)) { throw new IllegalIslStateException(sourceSwitch, sourcePort, destinationSwitch, destinationPort, "ISL must NOT be in active state."); } Collection<FlowPath> flowPaths = flowPathRepository.findWithPathSegment(sourceSwitch, sourcePort, destinationSwitch, destinationPort); if (!flowPaths.isEmpty()) { throw new IllegalIslStateException(sourceSwitch, sourcePort, destinationSwitch, destinationPort, "This ISL is busy by flow paths."); } } isls.forEach(islRepository::remove); log.info("ISLs {} have been removed from the database", isls); return isls; }); }
LinkOperationsService { public Collection<Isl> deleteIsl(SwitchId sourceSwitch, int sourcePort, SwitchId destinationSwitch, int destinationPort, boolean force) throws IllegalIslStateException, IslNotFoundException { log.info("Delete ISL with following parameters: " + "source switch '{}', source port '{}', destination switch '{}', destination port '{}', " + "force '{}'", sourceSwitch, sourcePort, destinationSwitch, destinationPort, force); return transactionManager.doInTransaction(() -> { List<Isl> isls = new ArrayList<>(); islRepository.findByEndpoints(sourceSwitch, sourcePort, destinationSwitch, destinationPort).ifPresent(isls::add); islRepository.findByEndpoints(destinationSwitch, destinationPort, sourceSwitch, sourcePort).ifPresent(isls::add); if (isls.isEmpty()) { throw new IslNotFoundException(sourceSwitch, sourcePort, destinationSwitch, destinationPort); } if (!force) { if (isls.stream().anyMatch(x -> x.getStatus() == IslStatus.ACTIVE)) { throw new IllegalIslStateException(sourceSwitch, sourcePort, destinationSwitch, destinationPort, "ISL must NOT be in active state."); } Collection<FlowPath> flowPaths = flowPathRepository.findWithPathSegment(sourceSwitch, sourcePort, destinationSwitch, destinationPort); if (!flowPaths.isEmpty()) { throw new IllegalIslStateException(sourceSwitch, sourcePort, destinationSwitch, destinationPort, "This ISL is busy by flow paths."); } } isls.forEach(islRepository::remove); log.info("ISLs {} have been removed from the database", isls); return isls; }); } }
LinkOperationsService { public Collection<Isl> deleteIsl(SwitchId sourceSwitch, int sourcePort, SwitchId destinationSwitch, int destinationPort, boolean force) throws IllegalIslStateException, IslNotFoundException { log.info("Delete ISL with following parameters: " + "source switch '{}', source port '{}', destination switch '{}', destination port '{}', " + "force '{}'", sourceSwitch, sourcePort, destinationSwitch, destinationPort, force); return transactionManager.doInTransaction(() -> { List<Isl> isls = new ArrayList<>(); islRepository.findByEndpoints(sourceSwitch, sourcePort, destinationSwitch, destinationPort).ifPresent(isls::add); islRepository.findByEndpoints(destinationSwitch, destinationPort, sourceSwitch, sourcePort).ifPresent(isls::add); if (isls.isEmpty()) { throw new IslNotFoundException(sourceSwitch, sourcePort, destinationSwitch, destinationPort); } if (!force) { if (isls.stream().anyMatch(x -> x.getStatus() == IslStatus.ACTIVE)) { throw new IllegalIslStateException(sourceSwitch, sourcePort, destinationSwitch, destinationPort, "ISL must NOT be in active state."); } Collection<FlowPath> flowPaths = flowPathRepository.findWithPathSegment(sourceSwitch, sourcePort, destinationSwitch, destinationPort); if (!flowPaths.isEmpty()) { throw new IllegalIslStateException(sourceSwitch, sourcePort, destinationSwitch, destinationPort, "This ISL is busy by flow paths."); } } isls.forEach(islRepository::remove); log.info("ISLs {} have been removed from the database", isls); return isls; }); } LinkOperationsService(ILinkOperationsServiceCarrier carrier,
                                 RepositoryFactory repositoryFactory,
                                 TransactionManager transactionManager); }
LinkOperationsService { public Collection<Isl> deleteIsl(SwitchId sourceSwitch, int sourcePort, SwitchId destinationSwitch, int destinationPort, boolean force) throws IllegalIslStateException, IslNotFoundException { log.info("Delete ISL with following parameters: " + "source switch '{}', source port '{}', destination switch '{}', destination port '{}', " + "force '{}'", sourceSwitch, sourcePort, destinationSwitch, destinationPort, force); return transactionManager.doInTransaction(() -> { List<Isl> isls = new ArrayList<>(); islRepository.findByEndpoints(sourceSwitch, sourcePort, destinationSwitch, destinationPort).ifPresent(isls::add); islRepository.findByEndpoints(destinationSwitch, destinationPort, sourceSwitch, sourcePort).ifPresent(isls::add); if (isls.isEmpty()) { throw new IslNotFoundException(sourceSwitch, sourcePort, destinationSwitch, destinationPort); } if (!force) { if (isls.stream().anyMatch(x -> x.getStatus() == IslStatus.ACTIVE)) { throw new IllegalIslStateException(sourceSwitch, sourcePort, destinationSwitch, destinationPort, "ISL must NOT be in active state."); } Collection<FlowPath> flowPaths = flowPathRepository.findWithPathSegment(sourceSwitch, sourcePort, destinationSwitch, destinationPort); if (!flowPaths.isEmpty()) { throw new IllegalIslStateException(sourceSwitch, sourcePort, destinationSwitch, destinationPort, "This ISL is busy by flow paths."); } } isls.forEach(islRepository::remove); log.info("ISLs {} have been removed from the database", isls); return isls; }); } LinkOperationsService(ILinkOperationsServiceCarrier carrier,
                                 RepositoryFactory repositoryFactory,
                                 TransactionManager transactionManager); List<Isl> updateLinkUnderMaintenanceFlag(SwitchId srcSwitchId, Integer srcPort,
                                                    SwitchId dstSwitchId, Integer dstPort,
                                                    boolean underMaintenance); Collection<Isl> getAllIsls(SwitchId srcSwitch, Integer srcPort,
                                      SwitchId dstSwitch, Integer dstPort); Collection<Isl> deleteIsl(SwitchId sourceSwitch, int sourcePort, SwitchId destinationSwitch,
                                     int destinationPort, boolean force); Collection<Isl> updateEnableBfdFlag(Endpoint source, Endpoint destination, boolean flagValue); }
LinkOperationsService { public Collection<Isl> deleteIsl(SwitchId sourceSwitch, int sourcePort, SwitchId destinationSwitch, int destinationPort, boolean force) throws IllegalIslStateException, IslNotFoundException { log.info("Delete ISL with following parameters: " + "source switch '{}', source port '{}', destination switch '{}', destination port '{}', " + "force '{}'", sourceSwitch, sourcePort, destinationSwitch, destinationPort, force); return transactionManager.doInTransaction(() -> { List<Isl> isls = new ArrayList<>(); islRepository.findByEndpoints(sourceSwitch, sourcePort, destinationSwitch, destinationPort).ifPresent(isls::add); islRepository.findByEndpoints(destinationSwitch, destinationPort, sourceSwitch, sourcePort).ifPresent(isls::add); if (isls.isEmpty()) { throw new IslNotFoundException(sourceSwitch, sourcePort, destinationSwitch, destinationPort); } if (!force) { if (isls.stream().anyMatch(x -> x.getStatus() == IslStatus.ACTIVE)) { throw new IllegalIslStateException(sourceSwitch, sourcePort, destinationSwitch, destinationPort, "ISL must NOT be in active state."); } Collection<FlowPath> flowPaths = flowPathRepository.findWithPathSegment(sourceSwitch, sourcePort, destinationSwitch, destinationPort); if (!flowPaths.isEmpty()) { throw new IllegalIslStateException(sourceSwitch, sourcePort, destinationSwitch, destinationPort, "This ISL is busy by flow paths."); } } isls.forEach(islRepository::remove); log.info("ISLs {} have been removed from the database", isls); return isls; }); } LinkOperationsService(ILinkOperationsServiceCarrier carrier,
                                 RepositoryFactory repositoryFactory,
                                 TransactionManager transactionManager); List<Isl> updateLinkUnderMaintenanceFlag(SwitchId srcSwitchId, Integer srcPort,
                                                    SwitchId dstSwitchId, Integer dstPort,
                                                    boolean underMaintenance); Collection<Isl> getAllIsls(SwitchId srcSwitch, Integer srcPort,
                                      SwitchId dstSwitch, Integer dstPort); Collection<Isl> deleteIsl(SwitchId sourceSwitch, int sourcePort, SwitchId destinationSwitch,
                                     int destinationPort, boolean force); Collection<Isl> updateEnableBfdFlag(Endpoint source, Endpoint destination, boolean flagValue);  }