Merge "BUG-997 Use shared schema context factory in netconf-connector"
authorEd Warnicke <eaw@cisco.com>
Wed, 13 Aug 2014 13:43:31 +0000 (13:43 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 13 Aug 2014 13:43:31 +0000 (13:43 +0000)
1  2 
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/NetconfDeviceReadOnlyTx.java

index 70d4f4336558d8d5897df9db297154f62d76cf09,7b43e1702872679523568b228c9e4f74131ef75a..6c46bed7626f27fd86d1f4b11c9462bbda395611
@@@ -7,6 -7,12 +7,6 @@@
   */
  package org.opendaylight.controller.sal.connect.netconf.sal.tx;
  
 -import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.CONFIG_SOURCE_RUNNING;
 -import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_DATA_QNAME;
 -import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME;
 -import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_QNAME;
 -import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.toFilterStructure;
 -
  import com.google.common.base.Function;
  import com.google.common.base.Optional;
  import com.google.common.base.Preconditions;
@@@ -29,14 -35,6 +29,14 @@@ import org.opendaylight.yangtools.yang.
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
 +import java.util.concurrent.ExecutionException;
 +
 +import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.CONFIG_SOURCE_RUNNING;
 +import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_DATA_QNAME;
 +import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME;
 +import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_QNAME;
 +import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.toFilterStructure;
 +
  
  public final class NetconfDeviceReadOnlyTx implements DOMDataReadOnlyTransaction {
  
@@@ -57,7 -55,7 +57,7 @@@
          final ListenableFuture<RpcResult<CompositeNode>> future = rpc.invokeRpc(NETCONF_GET_CONFIG_QNAME,
                  NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, CONFIG_SOURCE_RUNNING, toFilterStructure(path)));
  
-         ListenableFuture<Optional<NormalizedNode<?, ?>>> transformedFuture = Futures.transform(future, new Function<RpcResult<CompositeNode>, Optional<NormalizedNode<?, ?>>>() {
+         final ListenableFuture<Optional<NormalizedNode<?, ?>>> transformedFuture = Futures.transform(future, new Function<RpcResult<CompositeNode>, Optional<NormalizedNode<?, ?>>>() {
              @Override
              public Optional<NormalizedNode<?, ?>> apply(final RpcResult<CompositeNode> result) {
                  checkReadSuccess(result, path);
@@@ -99,7 -97,7 +99,7 @@@
              final YangInstanceIdentifier path) {
          final ListenableFuture<RpcResult<CompositeNode>> future = rpc.invokeRpc(NETCONF_GET_QNAME, NetconfMessageTransformUtil.wrap(NETCONF_GET_QNAME, toFilterStructure(path)));
  
-         ListenableFuture<Optional<NormalizedNode<?, ?>>> transformedFuture = Futures.transform(future, new Function<RpcResult<CompositeNode>, Optional<NormalizedNode<?, ?>>>() {
+         final ListenableFuture<Optional<NormalizedNode<?, ?>>> transformedFuture = Futures.transform(future, new Function<RpcResult<CompositeNode>, Optional<NormalizedNode<?, ?>>>() {
              @Override
              public Optional<NormalizedNode<?, ?>> apply(final RpcResult<CompositeNode> result) {
                  checkReadSuccess(result, path);
          throw new IllegalArgumentException(String.format("%s, Cannot read data %s for %s datastore, unknown datastore type", id, path, store));
      }
  
 +    @Override public CheckedFuture<Boolean, ReadFailedException> exists(
 +        LogicalDatastoreType store,
 +        YangInstanceIdentifier path) {
 +        CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>
 +            data = read(store, path);
 +
 +        try {
 +            return Futures.immediateCheckedFuture(data.get().isPresent());
 +        } catch (InterruptedException | ExecutionException e) {
 +            return Futures.immediateFailedCheckedFuture(new ReadFailedException("Exists failed",e));
 +        }
 +    }
 +
      static YangInstanceIdentifier toLegacyPath(final DataNormalizer normalizer, final YangInstanceIdentifier path, final RemoteDeviceId id) {
          try {
              return normalizer.toLegacy(path);