import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
-import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMActionResult;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.context.WriterParameters;
import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataService;
import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
-import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.DeleteDataTransactionUtil;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.PatchDataTransactionUtil;
// FIXME: why is this synchronized?
public synchronized RestconfStrategy getRestconfStrategy(final DOMMountPoint mountPoint) {
- final TransactionChainHandler transactionChain;
- if (mountPoint != null) {
- final Optional<NetconfDataTreeService> service = mountPoint.getService(NetconfDataTreeService.class);
- if (service.isPresent()) {
- return new NetconfRestconfStrategy(service.get());
- }
- transactionChain = transactionChainOfMountPoint(mountPoint);
- } else {
- transactionChain = transactionChainHandler;
- }
- return new MdsalRestconfStrategy(transactionChain);
- }
-
- /**
- * Prepare transaction chain to access data of mount point.
- *
- * @param mountPoint mount point reference
- * @return {@link TransactionChainHandler}
- */
- private static TransactionChainHandler transactionChainOfMountPoint(final @NonNull DOMMountPoint mountPoint) {
- final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
- if (domDataBrokerService.isPresent()) {
- return new TransactionChainHandler(domDataBrokerService.get());
+ if (mountPoint == null) {
+ return new MdsalRestconfStrategy(transactionChainHandler);
}
- final String errMsg = "DOM data broker service isn't available for mount point " + mountPoint.getIdentifier();
- LOG.warn(errMsg);
- throw new RestconfDocumentedException(errMsg);
+ return RestconfStrategy.forMountPoint(mountPoint).orElseThrow(() -> {
+ LOG.warn("Mount point {} does not expose a suitable access interface", mountPoint.getIdentifier());
+ return new RestconfDocumentedException("Could not find a supported access interface in mount point "
+ + mountPoint.getIdentifier());
+ });
}
/**
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
private DOMDataTreeReadWriteTransaction rwTx;
+ public MdsalRestconfStrategy(final DOMDataBroker dataBroker) {
+ this(new TransactionChainHandler(dataBroker));
+ }
+
public MdsalRestconfStrategy(final TransactionChainHandler transactionChainHandler) {
this.transactionChainHandler = requireNonNull(transactionChainHandler);
transactionChain = transactionChainHandler.get();
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
+import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
// 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<RestconfStrategy> forMountPoint(final DOMMountPoint mountPoint) {
+ final Optional<RestconfStrategy> 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.
*/