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.Optional;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.mdsal.common.api.CommitInfo;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
18 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
19 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
20 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
21 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 * Baseline execution strategy for various RESTCONF operations.
29 * @see NetconfRestconfStrategy
30 * @see MdsalRestconfStrategy
32 // FIXME: it seems the first three operations deal with lifecycle of a transaction, while others invoke various
33 // operations. This should be handled through proper allocation indirection.
34 public abstract class RestconfStrategy {
40 * Look up the appropriate strategy for a particular mount point.
42 * @param mountPoint Target mount point
43 * @return A strategy, or null if the mount point does not expose a supported interface
44 * @throws NullPointerException if {@code mountPoint} is null
46 public static Optional<RestconfStrategy> forMountPoint(final DOMMountPoint mountPoint) {
47 final Optional<RestconfStrategy> netconf = mountPoint.getService(NetconfDataTreeService.class)
48 .map(NetconfRestconfStrategy::new);
49 if (netconf.isPresent()) {
53 return mountPoint.getService(DOMDataBroker.class).map(MdsalRestconfStrategy::new);
57 * Lock the entire datastore.
59 public abstract void prepareReadWriteExecution();
62 * Confirm previous operations.
64 * @return a FluentFuture containing the result of the commit information
66 public abstract FluentFuture<? extends @NonNull CommitInfo> commit();
69 * Rollback changes and unlock the datastore.
71 public abstract void cancel();
74 * Read data from the datastore.
76 * @param store the logical data store which should be modified
77 * @param path the data object path
78 * @return a ListenableFuture containing the result of the read
80 public abstract ListenableFuture<Optional<NormalizedNode<?, ?>>> read(LogicalDatastoreType store,
81 YangInstanceIdentifier path);
84 * Check if data already exists in the datastore.
86 * @param store the logical data store which should be modified
87 * @param path the data object path
88 * @return a FluentFuture containing the result of the check
90 public abstract FluentFuture<Boolean> exists(LogicalDatastoreType store, YangInstanceIdentifier path);
93 * Delete data from the datastore.
95 * @param store the logical data store which should be modified
96 * @param path the data object path
98 public abstract void delete(LogicalDatastoreType store, YangInstanceIdentifier path);
101 * Remove data from the datastore.
103 * @param store the logical data store which should be modified
104 * @param path the data object path
106 public abstract void remove(LogicalDatastoreType store, YangInstanceIdentifier path);
109 * Merges a piece of data with the existing data at a specified path.
111 * @param store the logical data store which should be modified
112 * @param path the data object path
113 * @param data the data object to be merged to the specified path
115 public abstract void merge(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data);
118 * Stores a piece of data at the specified path.
120 * @param store the logical data store which should be modified
121 * @param path the data object path
122 * @param data the data object to be merged to the specified path
123 * @param schemaContext static view of compiled yang files
125 public abstract void create(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data,
126 SchemaContext schemaContext);
129 * Replace a piece of data at the specified path.
131 * @param store the logical data store which should be modified
132 * @param path the data object path
133 * @param data the data object to be merged to the specified path
134 * @param schemaContext static view of compiled yang files
136 public abstract void replace(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data,
137 SchemaContext schemaContext);
141 * Get transaction chain for creating specific transaction for specific operation.
143 * @return transaction chain or null
145 // FIXME: these look like an implementation detail
146 public abstract @Nullable DOMTransactionChain getTransactionChain();
149 * Get transaction chain handler for creating new transaction chain.
151 * @return {@link TransactionChainHandler} or null
153 // FIXME: these look like an implementation detail
154 public abstract @Nullable TransactionChainHandler getTransactionChainHandler();