/* * 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 com.google.common.util.concurrent.ListenableFuture; import java.util.List; import java.util.Optional; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMMountPoint; import org.opendaylight.netconf.dom.api.NetconfDataTreeService; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; /** * Baseline execution strategy for various RESTCONF operations. * * @see NetconfRestconfStrategy * @see MdsalRestconfStrategy */ // FIXME: it seems the first three operations deal with lifecycle of a transaction, while others invoke various // operations. This should be handled through proper allocation indirection. public abstract class RestconfStrategy { RestconfStrategy() { // Hidden on purpose } /** * Look up the appropriate strategy for a particular mount point. * * @param mountPoint Target mount point * @return A strategy, or null if the mount point does not expose a supported interface * @throws NullPointerException if {@code mountPoint} is null */ public static Optional forMountPoint(final DOMMountPoint mountPoint) { final Optional netconf = mountPoint.getService(NetconfDataTreeService.class) .map(NetconfRestconfStrategy::new); if (netconf.isPresent()) { return netconf; } return mountPoint.getService(DOMDataBroker.class).map(MdsalRestconfStrategy::new); } /** * Lock the entire datastore. * * @return A {@link RestconfTransaction}. This transaction needs to be either committed or canceled before doing * anything else. */ public abstract RestconfTransaction prepareWriteExecution(); /** * Read data from the datastore. * * @param store the logical data store which should be modified * @param path the data object path * @return a ListenableFuture containing the result of the read */ public abstract ListenableFuture> read(LogicalDatastoreType store, YangInstanceIdentifier path); /** * Read data selected using fields from the datastore. * * @param store the logical data store which should be modified * @param path the parent data object path * @param fields paths to selected fields relative to parent path * @return a ListenableFuture containing the result of the read */ public abstract ListenableFuture> read(LogicalDatastoreType store, YangInstanceIdentifier path, List fields); /** * Check if data already exists in the datastore. * * @param store the logical data store which should be modified * @param path the data object path * @return a FluentFuture containing the result of the check */ public abstract ListenableFuture exists(LogicalDatastoreType store, YangInstanceIdentifier path); }