use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfDeviceRpc method invokeRpc.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<DOMRpcResult> invokeRpc(final QName type, final NormalizedNode input) {
final ListenableFuture<RpcResult<NetconfMessage>> delegateFuture = communicator.sendRequest(transformer.toRpcRequest(type, input), type);
final SettableFuture<DOMRpcResult> ret = SettableFuture.create();
Futures.addCallback(delegateFuture, new FutureCallback<RpcResult<NetconfMessage>>() {
@Override
public void onSuccess(final RpcResult<NetconfMessage> result) {
try {
ret.set(result.isSuccessful() ? transformer.toRpcResult(result.getResult(), type) : new DefaultDOMRpcResult(result.getErrors()));
} catch (Exception cause) {
ret.setException(new DefaultDOMRpcException("Unable to parse rpc reply. type: " + type + " input: " + input, cause));
}
}
@Override
public void onFailure(final Throwable cause) {
ret.setException(new DOMRpcImplementationNotAvailableException(cause, "Unable to invoke rpc %s", type));
}
}, MoreExecutors.directExecutor());
return ret;
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NotificationHandler method onRemoteSchemaUp.
/**
* Forward all cached notifications and pass all notifications from this point directly to sal facade.
* @param transformer Message transformer
*/
synchronized void onRemoteSchemaUp(final MessageTransformer<NetconfMessage> transformer) {
this.messageTransformer = requireNonNull(transformer);
passNotifications = true;
for (final NetconfMessage cachedNotification : queue) {
passNotification(transformNotification(cachedNotification));
}
queue.clear();
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfMessageUtilTest method testNetconfMessageUtil.
@Test
public void testNetconfMessageUtil() throws Exception {
final NetconfMessage okMessage = new NetconfMessage(XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml"));
assertTrue(NetconfMessageUtil.isOKMessage(okMessage));
assertFalse(NetconfMessageUtil.isErrorMessage(okMessage));
final NetconfMessage errorMessage = new NetconfMessage(XmlFileLoader.xmlFileToDocument("netconfMessages/communicationError/testClientSendsRpcReply_expectedResponse.xml"));
assertTrue(NetconfMessageUtil.isErrorMessage(errorMessage));
assertFalse(NetconfMessageUtil.isOKMessage(errorMessage));
final Collection<String> caps = NetconfMessageUtil.extractCapabilitiesFromHello(XmlFileLoader.xmlFileToDocument("netconfMessages/client_hello.xml"));
assertTrue(caps.contains("urn:ietf:params:netconf:base:1.0"));
assertTrue(caps.contains("urn:ietf:params:netconf:base:1.1"));
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class CallHomeMountSessionContextTest method activationOfListenerSupportsSessionMessages.
@Test
public void activationOfListenerSupportsSessionMessages() {
// given
when(mockActivator.activate(any(NetconfClientSessionListener.class))).thenAnswer(invocationOnMock -> {
NetconfClientSession mockSession = mock(NetconfClientSession.class);
NetconfMessage mockMsg = mock(NetconfMessage.class);
Object arg = invocationOnMock.getArguments()[0];
((NetconfClientSessionListener) arg).onMessage(mockSession, mockMsg);
return null;
});
// given
NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class);
// when
mockActivator.activate(mockListener);
// then
verify(mockListener, times(1)).onMessage(any(NetconfClientSession.class), any(NetconfMessage.class));
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class AsyncExecutionStrategy method invoke.
@Override
public void invoke() {
final AtomicInteger responseCounter = new AtomicInteger(0);
final List<ListenableFuture<RpcResult<NetconfMessage>>> futures = new ArrayList<>();
int batchI = 0;
for (final Integer editBatch : getEditBatches()) {
for (int i = 0; i < editBatch; i++) {
final int msgId = i + batchI * getParams().editBatchSize;
final NetconfMessage msg = getPreparedMessages().get(msgId);
LOG.debug("Sending message {}", msgId);
if (LOG.isDebugEnabled()) {
LOG.debug("Sending message {}", XmlUtil.toString(msg.getDocument()));
}
final ListenableFuture<RpcResult<NetconfMessage>> netconfMessageFuture = getSessionListener().sendRequest(msg, StressClient.EDIT_QNAME);
futures.add(netconfMessageFuture);
}
batchI++;
LOG.info("Batch {} with size {} sent. Committing", batchI, editBatch);
if (getParams().candidateDatastore) {
futures.add(getSessionListener().sendRequest(StressClient.COMMIT_MSG, StressClient.COMMIT_QNAME));
}
}
LOG.info("All batches sent. Waiting for responses");
// Wait for every future
for (final ListenableFuture<RpcResult<NetconfMessage>> future : futures) {
try {
final RpcResult<NetconfMessage> netconfMessageRpcResult = future.get(getParams().msgTimeout, TimeUnit.SECONDS);
if (netconfMessageRpcResult.isSuccessful()) {
responseCounter.incrementAndGet();
LOG.debug("Received response {}", responseCounter.get());
} else {
LOG.warn("Request failed {}", netconfMessageRpcResult);
}
} catch (final InterruptedException e) {
throw new RuntimeException(e);
} catch (final ExecutionException | TimeoutException e) {
throw new RuntimeException("Request not finished", e);
}
}
Preconditions.checkState(responseCounter.get() == getEditAmount() + (getParams().candidateDatastore ? getEditBatches().size() : 0), "Not all responses were received, only %s from %s", responseCounter.get(), getParams().editCount + getEditBatches().size());
}
Aggregations