NetconfDeviceAlignmentServiceImpl implements NetconfDeviceAlignmentService { @Override public void forceAlign(Device device, NetConfResponse getConfigResponse) { m_txService.executeWithTx(new TXTemplate<Void>() { @Override public Void execute() { new WithSynchronousDeviceQueue<Void>() { @Override Void execute(String info, List<EditConfigRequest> deviceQueue) throws RuntimeException { try { deviceQueue.clear(); DeviceInterface deviceInterface = AdapterUtils.getAdapterContext(device, m_adapterManager).getDeviceInterface(); Pair<AbstractNetconfRequest, Future<NetConfResponse>> copyConfigFuture = deviceInterface.forceAlign(device, getConfigResponse); NetConfResponse response = null; response = copyConfigFuture.getSecond().get(); if (response == null || !response.isOk()) { markDeviceInError(info, deviceQueue, copyConfigFuture.getFirst().requestToString(), response); } else { markDeviceAligned(info); } } catch (IllegalStateException e) { LOGGER.info(String.format("Device %s is not connected, force-align would be retried", device.getDeviceName())); } catch (ExecutionException | InterruptedException | NetconfMessageBuilderException e) { throw new RuntimeException(e); } return null; } }.execute(device.getDeviceName()); return null; } }); } NetconfDeviceAlignmentServiceImpl(DeviceManager dm, NetconfConnectionManager ncm, AdapterManager manager); void init(); void destroy(); TxService getTxService(); void setTxService(TxService txService); @Override void queueEdit(String deviceName, EditConfigRequest request); @Override List<EditConfigRequest> getEditQueue(String deviceName); void alignAllDevices(); @Override String getAlignmentState(String deviceName); @Override void deviceAdded(String deviceName); @Override void deviceRemoved(String deviceName); @Override void forceAlign(Device device, NetConfResponse getConfigResponse); @Override void align(Device device, NetConfResponse getConfigResponse); static final String EDITS_PENDING; static final String REQUEST_TIMED_OUT; static final String LINE_SEPARATOR; static final String RESPONSE_RECEIVED; static final String REQUEST_SENT; static final String COMMA; static final String ALIGNMENT_STATE; }
@Test public void testFullResyncError() throws ExecutionException, NetconfMessageBuilderException { makeDeviceError(null); m_das.forceAlign(m_device1, m_getResponse); verify(m_deviceInterface).forceAlign(m_device1, m_getResponse); String expected; if (isWindowsSys()) { expected = "In Error, request sent : <rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\r\n" + " <copy-config>\r\n" + " <source>blah<source>\r\n" + "\t<target>\r\n" + " <running />\r\n" + " </target>\r\n" + " <test-option>set</test-option>\r\n" + " <config>\r\n" + " <some-config xmlns=\"some:ns\"/>\r\n" + " </config>\r\n" + " </copy-config>\r\n" + "</rpc>,\r\n" + "response received : <rpc-reply message-id=\"1\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\r\n" + " <rpc-error>\r\n" + " <error-type>application</error-type>\r\n" + " <error-tag>operation-failed</error-tag>\r\n" + " <error-severity>error</error-severity>\r\n" + " <error-message>Something went wrong</error-message>\r\n" + " </rpc-error>\r\n" + "</rpc-reply>\r\n"; } else { expected = "In Error, request sent : <rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n" + " <copy-config>\n" + " <source>blah<source>\n" + "\t<target>\n" + " <running />\n" + " </target>\n" + " <test-option>set</test-option>\n" + " <config>\n" + " <some-config xmlns=\"some:ns\"/>\n" + " </config>\n" + " </copy-config>\n" + "</rpc>,\n" + "response received : <rpc-reply message-id=\"1\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + " <rpc-error>\n" + " <error-type>application</error-type>\n" + " <error-tag>operation-failed</error-tag>\n" + " <error-severity>error</error-severity>\n" + " <error-message>Something went wrong</error-message>\n" + " </rpc-error>\n" + "</rpc-reply>\n"; } verify(m_dm).updateConfigAlignmentState(m_device1.getDeviceName(),expected); }
@Test public void testFullResyncTimeout() throws ExecutionException, InterruptedException, NetconfMessageBuilderException { makeDeviceTimeout(null); m_das.forceAlign(m_device1, m_getResponse); verify(m_deviceInterface).forceAlign(m_device1, m_getResponse); String expected; if (isWindowsSys()) { expected = "In Error, request sent : <rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\r\n" + " <copy-config>\r\n" + " <source>blah<source>\r\n" + "\t<target>\r\n" + " <running />\r\n" + " </target>\r\n" + " <test-option>set</test-option>\r\n" + " <config>\r\n" + " <some-config xmlns=\"some:ns\"/>\r\n" + " </config>\r\n" + " </copy-config>\r\n" + "</rpc>,\r\n" + "response received : request timed out"; } else { expected = "In Error, request sent : <rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n" + " <copy-config>\n" + " <source>blah<source>\n" + "\t<target>\n" + " <running />\n" + " </target>\n" + " <test-option>set</test-option>\n" + " <config>\n" + " <some-config xmlns=\"some:ns\"/>\n" + " </config>\n" + " </copy-config>\n" + "</rpc>,\n" + "response received : request timed out"; } verify(m_dm).updateConfigAlignmentState(m_device1.getDeviceName(), expected); }