X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-rfc8040%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2Frests%2Ftransactions%2FNetconfRestconfStrategy.java;fp=restconf%2Frestconf-nb-rfc8040%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2Frests%2Ftransactions%2FNetconfRestconfStrategy.java;h=0000000000000000000000000000000000000000;hb=0c6d75de46e116e8d54ddda6aefd767a5b1e2257;hp=4cb04a0b461a3fc8dd227016f243a12368d6311d;hpb=29e06cbd92b039d501a004cabcf0eb19f63c427a;p=netconf.git diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfStrategy.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfStrategy.java deleted file mode 100644 index 4cb04a0b46..0000000000 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfStrategy.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.restconf.nb.rfc8040.rests.transactions; - -import static java.util.Objects.requireNonNull; - -import com.google.common.util.concurrent.FluentFuture; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.common.util.concurrent.SettableFuture; -import java.util.List; -import java.util.Optional; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; -import org.opendaylight.mdsal.common.api.ReadFailedException; -import org.opendaylight.netconf.dom.api.NetconfDataTreeService; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Implementation of RESTCONF operations on top of a raw NETCONF backend. - * - * @see NetconfDataTreeService - */ -public final class NetconfRestconfStrategy extends RestconfStrategy { - private static final Logger LOG = LoggerFactory.getLogger(NetconfRestconfStrategy.class); - - private final NetconfDataTreeService netconfService; - - public NetconfRestconfStrategy(final NetconfDataTreeService netconfService) { - this.netconfService = requireNonNull(netconfService); - } - - @Override - public RestconfTransaction prepareWriteExecution() { - return new NetconfRestconfTransaction(netconfService); - } - - @Override - public ListenableFuture> read(final LogicalDatastoreType store, - final YangInstanceIdentifier path) { - switch (store) { - case CONFIGURATION: - return netconfService.getConfig(path); - case OPERATIONAL: - return netconfService.get(path); - default: - LOG.info("Unknown datastore type: {}.", store); - throw new IllegalArgumentException(String.format( - "%s, Cannot read data %s for %s datastore, unknown datastore type", - netconfService.getDeviceId(), path, store)); - } - } - - @Override - public ListenableFuture> read(final LogicalDatastoreType store, - final YangInstanceIdentifier path, final List fields) { - switch (store) { - case CONFIGURATION: - return netconfService.getConfig(path, fields); - case OPERATIONAL: - return netconfService.get(path, fields); - default: - LOG.info("Unknown datastore type: {}.", store); - throw new IllegalArgumentException(String.format( - "%s, Cannot read data %s with fields %s for %s datastore, unknown datastore type", - netconfService.getDeviceId(), path, fields, store)); - } - } - - @Override - public FluentFuture exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) { - return remapException(read(store, path)) - .transform(optionalNode -> optionalNode != null && optionalNode.isPresent(), - MoreExecutors.directExecutor()); - } - - private static FluentFuture remapException(final ListenableFuture input) { - final SettableFuture ret = SettableFuture.create(); - Futures.addCallback(input, new FutureCallback() { - - @Override - public void onSuccess(final T result) { - ret.set(result); - } - - @Override - public void onFailure(final Throwable cause) { - ret.setException(cause instanceof ReadFailedException ? cause - : new ReadFailedException("NETCONF operation failed", cause)); - } - }, MoreExecutors.directExecutor()); - return FluentFuture.from(ret); - } -}