@Test public void shouldUpdateLinkUnderMaintenanceFlag() throws SwitchNotFoundException { Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build(); switchRepository.add(sw); switchOperationsService.updateSwitchUnderMaintenanceFlag(TEST_SWITCH_ID, true); sw = switchRepository.findById(TEST_SWITCH_ID).get(); assertTrue(sw.isUnderMaintenance()); switchOperationsService.updateSwitchUnderMaintenanceFlag(TEST_SWITCH_ID, false); sw = switchRepository.findById(TEST_SWITCH_ID).get(); assertFalse(sw.isUnderMaintenance()); }
public Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance) throws SwitchNotFoundException { return transactionManager.doInTransaction(() -> { Optional<Switch> foundSwitch = switchRepository.findById(switchId); if (!(foundSwitch.isPresent())) { return Optional.<Switch>empty(); } Switch sw = foundSwitch.get(); if (sw.isUnderMaintenance() == underMaintenance) { switchRepository.detach(sw); return Optional.of(sw); } sw.setUnderMaintenance(underMaintenance); linkOperationsService.getAllIsls(switchId, null, null, null) .forEach(isl -> { try { linkOperationsService.updateLinkUnderMaintenanceFlag( isl.getSrcSwitchId(), isl.getSrcPort(), isl.getDestSwitchId(), isl.getDestPort(), underMaintenance); } catch (IslNotFoundException e) { } }); switchRepository.detach(sw); return Optional.of(sw); }).orElseThrow(() -> new SwitchNotFoundException(switchId)); }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance) throws SwitchNotFoundException { return transactionManager.doInTransaction(() -> { Optional<Switch> foundSwitch = switchRepository.findById(switchId); if (!(foundSwitch.isPresent())) { return Optional.<Switch>empty(); } Switch sw = foundSwitch.get(); if (sw.isUnderMaintenance() == underMaintenance) { switchRepository.detach(sw); return Optional.of(sw); } sw.setUnderMaintenance(underMaintenance); linkOperationsService.getAllIsls(switchId, null, null, null) .forEach(isl -> { try { linkOperationsService.updateLinkUnderMaintenanceFlag( isl.getSrcSwitchId(), isl.getSrcPort(), isl.getDestSwitchId(), isl.getDestPort(), underMaintenance); } catch (IslNotFoundException e) { } }); switchRepository.detach(sw); return Optional.of(sw); }).orElseThrow(() -> new SwitchNotFoundException(switchId)); } }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance) throws SwitchNotFoundException { return transactionManager.doInTransaction(() -> { Optional<Switch> foundSwitch = switchRepository.findById(switchId); if (!(foundSwitch.isPresent())) { return Optional.<Switch>empty(); } Switch sw = foundSwitch.get(); if (sw.isUnderMaintenance() == underMaintenance) { switchRepository.detach(sw); return Optional.of(sw); } sw.setUnderMaintenance(underMaintenance); linkOperationsService.getAllIsls(switchId, null, null, null) .forEach(isl -> { try { linkOperationsService.updateLinkUnderMaintenanceFlag( isl.getSrcSwitchId(), isl.getSrcPort(), isl.getDestSwitchId(), isl.getDestPort(), underMaintenance); } catch (IslNotFoundException e) { } }); switchRepository.detach(sw); return Optional.of(sw); }).orElseThrow(() -> new SwitchNotFoundException(switchId)); } SwitchOperationsService(RepositoryFactory repositoryFactory,
                                   TransactionManager transactionManager,
                                   SwitchOperationsServiceCarrier carrier); }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance) throws SwitchNotFoundException { return transactionManager.doInTransaction(() -> { Optional<Switch> foundSwitch = switchRepository.findById(switchId); if (!(foundSwitch.isPresent())) { return Optional.<Switch>empty(); } Switch sw = foundSwitch.get(); if (sw.isUnderMaintenance() == underMaintenance) { switchRepository.detach(sw); return Optional.of(sw); } sw.setUnderMaintenance(underMaintenance); linkOperationsService.getAllIsls(switchId, null, null, null) .forEach(isl -> { try { linkOperationsService.updateLinkUnderMaintenanceFlag( isl.getSrcSwitchId(), isl.getSrcPort(), isl.getDestSwitchId(), isl.getDestPort(), underMaintenance); } catch (IslNotFoundException e) { } }); switchRepository.detach(sw); return Optional.of(sw); }).orElseThrow(() -> new SwitchNotFoundException(switchId)); } SwitchOperationsService(RepositoryFactory repositoryFactory,
                                   TransactionManager transactionManager,
                                   SwitchOperationsServiceCarrier carrier); GetSwitchResponse getSwitch(SwitchId switchId); List<GetSwitchResponse> getAllSwitches(); Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance); boolean deleteSwitch(SwitchId switchId, boolean force); void checkSwitchIsDeactivated(SwitchId switchId); void checkSwitchHasNoFlows(SwitchId switchId); void checkSwitchHasNoFlowSegments(SwitchId switchId); void checkSwitchHasNoIsls(SwitchId switchId); SwitchPropertiesDto getSwitchProperties(SwitchId switchId); SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto); PortProperties getPortProperties(SwitchId switchId, int port); Collection<SwitchConnectedDevice> getSwitchConnectedDevices(
            SwitchId switchId); List<IslEndpoint> getSwitchIslEndpoints(SwitchId switchId); Switch patchSwitch(SwitchId switchId, SwitchPatch data); }
SwitchOperationsService implements ILinkOperationsServiceCarrier { public Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance) throws SwitchNotFoundException { return transactionManager.doInTransaction(() -> { Optional<Switch> foundSwitch = switchRepository.findById(switchId); if (!(foundSwitch.isPresent())) { return Optional.<Switch>empty(); } Switch sw = foundSwitch.get(); if (sw.isUnderMaintenance() == underMaintenance) { switchRepository.detach(sw); return Optional.of(sw); } sw.setUnderMaintenance(underMaintenance); linkOperationsService.getAllIsls(switchId, null, null, null) .forEach(isl -> { try { linkOperationsService.updateLinkUnderMaintenanceFlag( isl.getSrcSwitchId(), isl.getSrcPort(), isl.getDestSwitchId(), isl.getDestPort(), underMaintenance); } catch (IslNotFoundException e) { } }); switchRepository.detach(sw); return Optional.of(sw); }).orElseThrow(() -> new SwitchNotFoundException(switchId)); } SwitchOperationsService(RepositoryFactory repositoryFactory,
                                   TransactionManager transactionManager,
                                   SwitchOperationsServiceCarrier carrier); GetSwitchResponse getSwitch(SwitchId switchId); List<GetSwitchResponse> getAllSwitches(); Switch updateSwitchUnderMaintenanceFlag(SwitchId switchId, boolean underMaintenance); boolean deleteSwitch(SwitchId switchId, boolean force); void checkSwitchIsDeactivated(SwitchId switchId); void checkSwitchHasNoFlows(SwitchId switchId); void checkSwitchHasNoFlowSegments(SwitchId switchId); void checkSwitchHasNoIsls(SwitchId switchId); SwitchPropertiesDto getSwitchProperties(SwitchId switchId); SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto); PortProperties getPortProperties(SwitchId switchId, int port); Collection<SwitchConnectedDevice> getSwitchConnectedDevices(
            SwitchId switchId); List<IslEndpoint> getSwitchIslEndpoints(SwitchId switchId); Switch patchSwitch(SwitchId switchId, SwitchPatch data);  }