use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class ActorProxyNetconfServiceFacade method lock.
@Override
public ListenableFuture<DOMRpcResult> lock() {
LOG.debug("{}: Lock via actor {}", id, masterActor);
final SettableFuture<DOMRpcResult> lockResult = SettableFuture.create();
final Future<Object> future = Patterns.ask(masterActor, new LockRequest(), askTimeout);
future.onComplete(new OnComplete<>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
lockResult.setException(failure);
} else if (response instanceof InvokeRpcMessageReply) {
lockResult.set(mapInvokeRpcMessageReplyToDOMRpcResult((InvokeRpcMessageReply) response));
} else {
lockResult.setException(new ClusteringRpcException("Lock operation returned unexpected type"));
LOG.error("{}: Lock via actor {} returned unexpected type", id, masterActor);
}
}
}, executionContext);
return lockResult;
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class ActorProxyNetconfServiceFacade method unlock.
@Override
public ListenableFuture<DOMRpcResult> unlock() {
LOG.debug("{}: Unlock via actor {}", id, masterActor);
final SettableFuture<DOMRpcResult> unlockResult = SettableFuture.create();
final Future<Object> future = Patterns.ask(masterActor, new UnlockRequest(), askTimeout);
future.onComplete(new OnComplete<>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
unlockResult.setException(failure);
} else if (response instanceof InvokeRpcMessageReply) {
unlockResult.set(mapInvokeRpcMessageReplyToDOMRpcResult((InvokeRpcMessageReply) response));
} else {
unlockResult.setException(new ClusteringRpcException("Unlock operation returned unexpected type"));
LOG.error("{}: Unlock via actor {} returned unexpected type", id, masterActor);
}
}
}, executionContext);
return unlockResult;
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class AbstractWriteTx method extractResult.
@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private void extractResult(final List<DOMRpcResult> domRpcResults, final SettableFuture<RpcResult<Void>> transformed) {
ErrorType errType = ErrorType.APPLICATION;
ErrorSeverity errSeverity = ErrorSeverity.ERROR;
StringBuilder msgBuilder = new StringBuilder();
boolean errorsEncouneterd = false;
String errorTag = "operation-failed";
for (final DOMRpcResult domRpcResult : domRpcResults) {
if (!domRpcResult.getErrors().isEmpty()) {
errorsEncouneterd = true;
final RpcError error = domRpcResult.getErrors().iterator().next();
errType = error.getErrorType().toNetconf();
errSeverity = error.getSeverity().toNetconf();
msgBuilder.append(error.getMessage());
msgBuilder.append(error.getInfo());
errorTag = error.getTag();
}
}
if (errorsEncouneterd) {
final NetconfDocumentedException exception = new NetconfDocumentedException(id + ":RPC during tx failed. " + msgBuilder, errType, new ErrorTag(errorTag), errSeverity);
transformed.setException(exception);
return;
}
transformed.set(RpcResultBuilder.<Void>success().build());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class NetconfStateSchemas method create.
/**
* Issue get request to remote device and parse response to find all schemas under netconf-state/schemas.
*/
static NetconfStateSchemas create(final DOMRpcService deviceRpc, final NetconfSessionPreferences remoteSessionCapabilities, final RemoteDeviceId id, final EffectiveModelContext schemaContext) {
if (!remoteSessionCapabilities.isMonitoringSupported()) {
// TODO - need to search for get-schema support, not just ietf-netconf-monitoring support
// issue might be a deviation to ietf-netconf-monitoring where get-schema is unsupported...
LOG.warn("{}: Netconf monitoring not supported on device, cannot detect provided schemas", id);
return EMPTY;
}
final DOMRpcResult schemasNodeResult;
try {
schemasNodeResult = deviceRpc.invokeRpc(NETCONF_GET_QNAME, GET_SCHEMAS_RPC).get();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(id + ": Interrupted while waiting for response to " + STATE_SCHEMAS_IDENTIFIER, e);
} catch (final ExecutionException e) {
LOG.warn("{}: Unable to detect available schemas, get to {} failed", id, STATE_SCHEMAS_IDENTIFIER, e);
return EMPTY;
}
if (!schemasNodeResult.getErrors().isEmpty()) {
LOG.warn("{}: Unable to detect available schemas, get to {} failed, {}", id, STATE_SCHEMAS_IDENTIFIER, schemasNodeResult.getErrors());
return EMPTY;
}
final Optional<? extends NormalizedNode> optSchemasNode = findSchemasNode(schemasNodeResult.getResult(), schemaContext);
if (optSchemasNode.isEmpty()) {
LOG.warn("{}: Unable to detect available schemas, get to {} was empty", id, STATE_SCHEMAS_IDENTIFIER);
return EMPTY;
}
final NormalizedNode schemasNode = optSchemasNode.get();
checkState(schemasNode instanceof ContainerNode, "Expecting container containing schemas, but was %s", schemasNode);
return create(id, (ContainerNode) schemasNode);
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class RestconfInvokeOperationsServiceImplTest method invokeRpcViaMountPointTest.
@Test
public void invokeRpcViaMountPointTest() throws InterruptedException, ExecutionException {
doReturn(Optional.ofNullable(rpcService)).when(mountPoint).getService(DOMRpcService.class);
final DOMRpcResult mockResult = new DefaultDOMRpcResult(OUTPUT, List.of());
doReturn(immediateFluentFuture(mockResult)).when(rpcService).invokeRpc(RPC, INPUT);
final DOMRpcResult rpcResult = RestconfInvokeOperationsServiceImpl.invokeRpc(INPUT, RPC, mountPoint).get();
assertTrue(rpcResult.getErrors().isEmpty());
assertEquals(OUTPUT, rpcResult.getResult());
}
Aggregations