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.FluentFuture;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.List;
13 import java.util.Optional;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
16 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
17 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 * Baseline execution strategy for various RESTCONF operations.
24 * @see NetconfRestconfStrategy
25 * @see MdsalRestconfStrategy
27 // FIXME: it seems the first three operations deal with lifecycle of a transaction, while others invoke various
28 // operations. This should be handled through proper allocation indirection.
29 public abstract class RestconfStrategy {
35 * Look up the appropriate strategy for a particular mount point.
37 * @param mountPoint Target mount point
38 * @return A strategy, or null if the mount point does not expose a supported interface
39 * @throws NullPointerException if {@code mountPoint} is null
41 public static Optional<RestconfStrategy> forMountPoint(final DOMMountPoint mountPoint) {
42 final Optional<RestconfStrategy> netconf = mountPoint.getService(NetconfDataTreeService.class)
43 .map(NetconfRestconfStrategy::new);
44 if (netconf.isPresent()) {
48 return mountPoint.getService(DOMDataBroker.class).map(MdsalRestconfStrategy::new);
52 * Lock the entire datastore.
54 * @return A {@link RestconfTransaction}. This transaction needs to be either committed or canceled before doing
57 public abstract RestconfTransaction prepareWriteExecution();
60 * Read data from the datastore.
62 * @param store the logical data store which should be modified
63 * @param path the data object path
64 * @return a ListenableFuture containing the result of the read
66 public abstract ListenableFuture<Optional<NormalizedNode<?, ?>>> read(LogicalDatastoreType store,
67 YangInstanceIdentifier path);
70 * Read data selected using fields from the datastore.
72 * @param store the logical data store which should be modified
73 * @param path the parent data object path
74 * @param fields paths to selected fields relative to parent path
75 * @return a ListenableFuture containing the result of the read
77 public abstract ListenableFuture<Optional<NormalizedNode<?, ?>>> read(LogicalDatastoreType store,
78 YangInstanceIdentifier path, List<YangInstanceIdentifier> fields);
81 * Check if data already exists in the datastore.
83 * @param store the logical data store which should be modified
84 * @param path the data object path
85 * @return a FluentFuture containing the result of the check
87 public abstract FluentFuture<Boolean> exists(LogicalDatastoreType store, YangInstanceIdentifier path);