X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2Fsal%2FNetconfDeviceRpc.java;fp=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2Fsal%2FNetconfDeviceRpc.java;h=0000000000000000000000000000000000000000;hb=23fe9ca678ada6263fec5dd996f4025e4a32fcf5;hp=178b0502edbb9678a21adca7738679e7ff355f32;hpb=071a641d7c12c0e6112d5ce0afe806b54f116ed2;p=controller.git diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceRpc.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceRpc.java deleted file mode 100644 index 178b0502ed..0000000000 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceRpc.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.connect.netconf.sal; - -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import java.util.Collection; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcException; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; -import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult; -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.sal.connect.api.MessageTransformer; -import org.opendaylight.controller.sal.connect.api.RemoteDeviceCommunicator; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.model.api.RpcDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; - -/** - * Invokes RPC by sending netconf message via listener. Also transforms result from NetconfMessage to CompositeNode. - */ -public final class NetconfDeviceRpc implements DOMRpcService { - - private static final Function RPC_TO_RPC_IDENTIFIER = new Function() { - @Override - public DOMRpcIdentifier apply(final RpcDefinition input) { - // TODO add support for routed rpcs ... is it necessary in this case ? - return DOMRpcIdentifier.create(input.getPath()); - } - }; - - private final RemoteDeviceCommunicator listener; - private final MessageTransformer transformer; - private final Collection availableRpcs; - - public NetconfDeviceRpc(final SchemaContext schemaContext, final RemoteDeviceCommunicator listener, final MessageTransformer transformer) { - this.listener = listener; - this.transformer = transformer; - - availableRpcs = Collections2.transform(schemaContext.getOperations(), RPC_TO_RPC_IDENTIFIER); - } - - @Nonnull - @Override - public CheckedFuture invokeRpc(@Nonnull final SchemaPath type, @Nullable final NormalizedNode input) { - final NetconfMessage message = transformer.toRpcRequest(type, input); - final ListenableFuture> delegateFutureWithPureResult = listener.sendRequest(message, type.getLastComponent()); - - final ListenableFuture transformed = Futures.transform(delegateFutureWithPureResult, new Function, DOMRpcResult>() { - @Override - public DOMRpcResult apply(final RpcResult input) { - if (input.isSuccessful()) { - return transformer.toRpcResult(input.getResult(), type); - } else { - // TODO check whether the listener sets errors properly - return new DefaultDOMRpcResult(input.getErrors()); - } - } - }); - - return Futures.makeChecked(transformed, new Function() { - @Nullable - @Override - public DOMRpcException apply(@Nullable final Exception e) { - // FIXME what other possible exceptions are there ? - return new DOMRpcImplementationNotAvailableException(e, "Unable to invoke rpc %s", type); - } - }); - } - - @Nonnull - @Override - public ListenerRegistration registerRpcListener(@Nonnull final T listener) { - - listener.onRpcAvailable(availableRpcs); - - return new ListenerRegistration() { - @Override - public void close() { - // NOOP, no rpcs appear and disappear in this implementation - } - - @Override - public T getInstance() { - return listener; - } - }; - } -}