Search in sources :

Example 46 with DOMRpcResult

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;
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) LockRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.LockRequest) ClusteringRpcException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException) InvokeRpcMessageReply(org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)

Example 47 with DOMRpcResult

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;
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) UnlockRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.UnlockRequest) ClusteringRpcException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException) InvokeRpcMessageReply(org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)

Example 48 with DOMRpcResult

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());
}
Also used : ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) ErrorType(org.opendaylight.yangtools.yang.common.ErrorType) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) ErrorSeverity(org.opendaylight.yangtools.yang.common.ErrorSeverity) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 49 with DOMRpcResult

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);
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DataContainerNode(org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode) ExecutionException(java.util.concurrent.ExecutionException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 50 with DOMRpcResult

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());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) Test(org.junit.Test)

Aggregations

DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)61 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)39 Test (org.junit.Test)38 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 QName (org.opendaylight.yangtools.yang.common.QName)18 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)16 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)10 RpcError (org.opendaylight.yangtools.yang.common.RpcError)8 ExecutionException (java.util.concurrent.ExecutionException)7 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)7 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)7 ClusteringRpcException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException)6 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)5 InvokeRpcMessageReply (org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)5 DOMRpcImplementationNotAvailableException (org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException)4 NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3