2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.nb.rfc8040.rests.transactions;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.List;
12 import java.util.Optional;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
15 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
16 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 * Baseline execution strategy for various RESTCONF operations.
23 * @see NetconfRestconfStrategy
24 * @see MdsalRestconfStrategy
26 // FIXME: it seems the first three operations deal with lifecycle of a transaction, while others invoke various
27 // operations. This should be handled through proper allocation indirection.
28 public abstract class RestconfStrategy {
34 * Look up the appropriate strategy for a particular mount point.
36 * @param mountPoint Target mount point
37 * @return A strategy, or null if the mount point does not expose a supported interface
38 * @throws NullPointerException if {@code mountPoint} is null
40 public static Optional<RestconfStrategy> forMountPoint(final DOMMountPoint mountPoint) {
41 final Optional<RestconfStrategy> netconf = mountPoint.getService(NetconfDataTreeService.class)
42 .map(NetconfRestconfStrategy::new);
43 if (netconf.isPresent()) {
47 return mountPoint.getService(DOMDataBroker.class).map(MdsalRestconfStrategy::new);
51 * Lock the entire datastore.
53 * @return A {@link RestconfTransaction}. This transaction needs to be either committed or canceled before doing
56 public abstract RestconfTransaction prepareWriteExecution();
59 * Read data from the datastore.
61 * @param store the logical data store which should be modified
62 * @param path the data object path
63 * @return a ListenableFuture containing the result of the read
65 public abstract ListenableFuture<Optional<NormalizedNode>> read(LogicalDatastoreType store,
66 YangInstanceIdentifier path);
69 * Read data selected using fields from the datastore.
71 * @param store the logical data store which should be modified
72 * @param path the parent data object path
73 * @param fields paths to selected fields relative to parent path
74 * @return a ListenableFuture containing the result of the read
76 public abstract ListenableFuture<Optional<NormalizedNode>> read(LogicalDatastoreType store,
77 YangInstanceIdentifier path, List<YangInstanceIdentifier> fields);
80 * Check if data already exists in the datastore.
82 * @param store the logical data store which should be modified
83 * @param path the data object path
84 * @return a FluentFuture containing the result of the check
86 public abstract ListenableFuture<Boolean> exists(LogicalDatastoreType store, YangInstanceIdentifier path);