import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.Transaction;
-import org.opendaylight.mdsal.binding.api.TransactionChain;
-import org.opendaylight.mdsal.binding.api.TransactionChainListener;
import org.opendaylight.mdsal.dom.api.DOMActionService;
import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.mdsal.dom.api.DOMNotification;
import org.opendaylight.mdsal.dom.api.DOMNotificationService;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
+import org.opendaylight.netconf.sal.connect.api.NetconfRpcService;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Actions;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
+import org.opendaylight.netconf.sal.connect.api.SchemalessRpcService;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+// FIXME: remove this class and promote MountInstance to a top-level construct
+// Non-final for mocking
public class NetconfDeviceSalProvider implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceSalProvider.class);
private final RemoteDeviceId id;
private final MountInstance mountInstance;
- private final DataBroker dataBroker;
-
- private volatile NetconfDeviceTopologyAdapter topologyDatastoreAdapter;
-
- private TransactionChain txChain;
-
- private final TransactionChainListener transactionChainListener = new TransactionChainListener() {
- @Override
- public void onTransactionChainFailed(final TransactionChain chain, final Transaction transaction,
- final Throwable cause) {
- LOG.error("{}: TransactionChain({}) {} FAILED!", id, chain, transaction.getIdentifier(), cause);
- chain.close();
- resetTransactionChainForAdapaters();
- throw new IllegalStateException(id + " TransactionChain(" + chain + ") not committed correctly", cause);
- }
-
- @Override
- public void onTransactionChainSuccessful(final TransactionChain chain) {
- LOG.trace("{}: TransactionChain({}) SUCCESSFUL", id, chain);
- }
- };
public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final DOMMountPointService mountService) {
- this(deviceId, mountService, null);
- }
-
- public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final DOMMountPointService mountService,
- final DataBroker dataBroker) {
- this.id = deviceId;
+ id = requireNonNull(deviceId);
mountInstance = new MountInstance(mountService, id);
- this.dataBroker = dataBroker;
- if (dataBroker != null) {
- txChain = requireNonNull(dataBroker).createTransactionChain(transactionChainListener);
- topologyDatastoreAdapter = new NetconfDeviceTopologyAdapter(id, txChain);
- }
}
public MountInstance getMountInstance() {
return mountInstance;
}
- public NetconfDeviceTopologyAdapter getTopologyDatastoreAdapter() {
- final NetconfDeviceTopologyAdapter local = topologyDatastoreAdapter;
- checkState(local != null,
- "%s: Sal provider %s was not initialized by sal. Cannot get topology datastore adapter", id, this);
- return local;
- }
-
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
- private void resetTransactionChainForAdapaters() {
- txChain = requireNonNull(dataBroker).createTransactionChain(transactionChainListener);
- topologyDatastoreAdapter.setTxChain(txChain);
- LOG.trace("{}: Resetting TransactionChain {}", id, txChain);
- }
-
@Override
public void close() {
mountInstance.close();
- if (topologyDatastoreAdapter != null) {
- topologyDatastoreAdapter.close();
- }
- topologyDatastoreAdapter = null;
- if (txChain != null) {
- txChain.close();
- }
}
public static class MountInstance implements AutoCloseable {
}
public void onTopologyDeviceConnected(final EffectiveModelContext initialCtx,
- final DOMDataBroker broker, final DOMRpcService rpc,
- final NetconfDeviceNotificationService newNotificationService) {
- onTopologyDeviceConnected(initialCtx, broker, null, rpc, newNotificationService, null);
+ final RemoteDeviceServices services, final DOMDataBroker broker,
+ final NetconfDataTreeService dataTreeService) {
+ onTopologyDeviceConnected(initialCtx, services, new NetconfDeviceNotificationService(), broker,
+ dataTreeService);
}
public synchronized void onTopologyDeviceConnected(final EffectiveModelContext initialCtx,
- final DOMDataBroker broker, final NetconfDataTreeService netconfService, final DOMRpcService rpc,
- final NetconfDeviceNotificationService newNotificationService, final DOMActionService deviceAction) {
+ final RemoteDeviceServices services, final NetconfDeviceNotificationService newNotificationService,
+ final DOMDataBroker broker, final NetconfDataTreeService dataTreeService) {
requireNonNull(mountService, "Closed");
checkState(topologyRegistration == null, "Already initialized");
- final DOMMountPointService.DOMMountPointBuilder mountBuilder =
- mountService.createMountPoint(id.getTopologyPath());
- mountBuilder.addInitialSchemaContext(initialCtx);
+ final var mountBuilder = mountService.createMountPoint(id.getTopologyPath());
+ mountBuilder.addService(DOMSchemaService.class, FixedDOMSchemaService.of(() -> initialCtx));
+
+ final var rpcs = services.rpcs();
+ mountBuilder.addService(NetconfRpcService.class, rpcs);
+ if (rpcs instanceof Rpcs.Normalized normalized) {
+ mountBuilder.addService(DOMRpcService.class, normalized);
+ } else if (rpcs instanceof Rpcs.Schemaless schemaless) {
+ mountBuilder.addService(SchemalessRpcService.class, schemaless);
+ }
+ if (services.actions() instanceof Actions.Normalized normalized) {
+ mountBuilder.addService(DOMActionService.class, normalized);
+ }
if (broker != null) {
mountBuilder.addService(DOMDataBroker.class, broker);
}
- mountBuilder.addService(DOMRpcService.class, rpc);
- mountBuilder.addService(DOMNotificationService.class, newNotificationService);
- if (deviceAction != null) {
- mountBuilder.addService(DOMActionService.class, deviceAction);
+ if (dataTreeService != null) {
+ mountBuilder.addService(NetconfDataTreeService.class, dataTreeService);
}
- if (netconfService != null) {
- mountBuilder.addService(NetconfDataTreeService.class, netconfService);
- }
- this.notificationService = newNotificationService;
+ mountBuilder.addService(DOMNotificationService.class, newNotificationService);
+ notificationService = newNotificationService;
topologyRegistration = mountBuilder.register();
LOG.debug("{}: TOPOLOGY Mountpoint exposed into MD-SAL {}", id, topologyRegistration);