@Test public void testUploadConfigError() throws ExecutionException, InterruptedException, NetconfMessageBuilderException { m_newDevice.getDeviceManagement().setPushPmaConfigurationToDevice("false"); Future<NetConfResponse> responseFuture = mock(Future.class); NetConfResponse netConfResponse = null; try { netConfResponse = DocumentToPojoTransformer.getNetconfResponse(DocumentUtils.stringToDocument(SAMPLE_NON_EMPTY_NC_RES)); } catch (NetconfMessageBuilderException e) { throw new RuntimeException(e); } when(responseFuture.get()).thenReturn(netConfResponse); when(m_devInterface.getConfig(eq(m_newDevice), anyObject())).thenReturn(responseFuture); Map<NetConfResponse, List<Notification>> map = new HashMap<>(); NetConfResponse netConfRespons = DocumentToPojoTransformer.getNetconfResponse(DocumentUtils.stringToDocument(ERROR_RESPONSE)); map.put(netConfRespons, Collections.emptyList()); when(m_pmaSession.executeNC(EDIT_CONFIG_REQ)).thenReturn(map); m_timer.runAlignment(); assertEquals("false", m_newDevice.getDeviceManagement().getPushPmaConfigurationToDevice()); verify(m_deviceDao, never()).updateDeviceAlignmentState(anyString(), anyString()); assertTrue(m_newDevice.isNeverAligned()); }
public void runAlignment() { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { List<Device> devices = m_deviceDao.findAllDevices(); for (Device device : devices) { try { m_pmaRegistry.executeWithPmaSession(device.getDeviceName(), session -> { if (device.isNeverAligned()) { LOGGER.debug(String.format("Device %s is " + NEVER_ALIGNED, device)); AlignmentOption alignmentOption = device.getAlignmentOption(); if (AlignmentOption.PUSH.equals(alignmentOption)) { if (deviceHasConfigurations(device)) { session.forceAlign(); } } else if (AlignmentOption.PULL.equals(alignmentOption)) { invokeUploadConfig(device, session); LOGGER.debug("Upload config done"); m_deviceDao.updateDeviceAlignmentState(device.getDeviceName(), ALIGNED); } } else if (!device.isAligned()) { session.align(); } return null; }); } catch (ExecutionException e) { LOGGER.error(String.format("Could not align device %s", device), e); } } return null; } }); }
AlignmentTimer { public void runAlignment() { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { List<Device> devices = m_deviceDao.findAllDevices(); for (Device device : devices) { try { m_pmaRegistry.executeWithPmaSession(device.getDeviceName(), session -> { if (device.isNeverAligned()) { LOGGER.debug(String.format("Device %s is " + NEVER_ALIGNED, device)); AlignmentOption alignmentOption = device.getAlignmentOption(); if (AlignmentOption.PUSH.equals(alignmentOption)) { if (deviceHasConfigurations(device)) { session.forceAlign(); } } else if (AlignmentOption.PULL.equals(alignmentOption)) { invokeUploadConfig(device, session); LOGGER.debug("Upload config done"); m_deviceDao.updateDeviceAlignmentState(device.getDeviceName(), ALIGNED); } } else if (!device.isAligned()) { session.align(); } return null; }); } catch (ExecutionException e) { LOGGER.error(String.format("Could not align device %s", device), e); } } return null; } }); } }
AlignmentTimer { public void runAlignment() { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { List<Device> devices = m_deviceDao.findAllDevices(); for (Device device : devices) { try { m_pmaRegistry.executeWithPmaSession(device.getDeviceName(), session -> { if (device.isNeverAligned()) { LOGGER.debug(String.format("Device %s is " + NEVER_ALIGNED, device)); AlignmentOption alignmentOption = device.getAlignmentOption(); if (AlignmentOption.PUSH.equals(alignmentOption)) { if (deviceHasConfigurations(device)) { session.forceAlign(); } } else if (AlignmentOption.PULL.equals(alignmentOption)) { invokeUploadConfig(device, session); LOGGER.debug("Upload config done"); m_deviceDao.updateDeviceAlignmentState(device.getDeviceName(), ALIGNED); } } else if (!device.isAligned()) { session.align(); } return null; }); } catch (ExecutionException e) { LOGGER.error(String.format("Could not align device %s", device), e); } } return null; } }); } AlignmentTimer(PmaRegistry pmaRegistry, AdapterManager adaperMgr,
                          DeviceDao deviceDao, TxService txService); }
AlignmentTimer { public void runAlignment() { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { List<Device> devices = m_deviceDao.findAllDevices(); for (Device device : devices) { try { m_pmaRegistry.executeWithPmaSession(device.getDeviceName(), session -> { if (device.isNeverAligned()) { LOGGER.debug(String.format("Device %s is " + NEVER_ALIGNED, device)); AlignmentOption alignmentOption = device.getAlignmentOption(); if (AlignmentOption.PUSH.equals(alignmentOption)) { if (deviceHasConfigurations(device)) { session.forceAlign(); } } else if (AlignmentOption.PULL.equals(alignmentOption)) { invokeUploadConfig(device, session); LOGGER.debug("Upload config done"); m_deviceDao.updateDeviceAlignmentState(device.getDeviceName(), ALIGNED); } } else if (!device.isAligned()) { session.align(); } return null; }); } catch (ExecutionException e) { LOGGER.error(String.format("Could not align device %s", device), e); } } return null; } }); } AlignmentTimer(PmaRegistry pmaRegistry, AdapterManager adaperMgr,
                          DeviceDao deviceDao, TxService txService); TxService getTxService(); void setTxService(TxService txService); DeviceDao getDeviceDao(); void setDeviceDao(DeviceDao deviceDao); void init(); void destroy(); void runAlignment(); }
AlignmentTimer { public void runAlignment() { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { List<Device> devices = m_deviceDao.findAllDevices(); for (Device device : devices) { try { m_pmaRegistry.executeWithPmaSession(device.getDeviceName(), session -> { if (device.isNeverAligned()) { LOGGER.debug(String.format("Device %s is " + NEVER_ALIGNED, device)); AlignmentOption alignmentOption = device.getAlignmentOption(); if (AlignmentOption.PUSH.equals(alignmentOption)) { if (deviceHasConfigurations(device)) { session.forceAlign(); } } else if (AlignmentOption.PULL.equals(alignmentOption)) { invokeUploadConfig(device, session); LOGGER.debug("Upload config done"); m_deviceDao.updateDeviceAlignmentState(device.getDeviceName(), ALIGNED); } } else if (!device.isAligned()) { session.align(); } return null; }); } catch (ExecutionException e) { LOGGER.error(String.format("Could not align device %s", device), e); } } return null; } }); } AlignmentTimer(PmaRegistry pmaRegistry, AdapterManager adaperMgr,
                          DeviceDao deviceDao, TxService txService); TxService getTxService(); void setTxService(TxService txService); DeviceDao getDeviceDao(); void setDeviceDao(DeviceDao deviceDao); void init(); void destroy(); void runAlignment();  }