* 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.netconf.topology.singleton.impl;
+import static java.util.Objects.requireNonNull;
+
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.cluster.Cluster;
import akka.dispatch.OnComplete;
import akka.pattern.Patterns;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
+import akka.util.Timeout;
import java.util.List;
-import java.util.stream.Collectors;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.core.api.Broker;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
-import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceNotificationService;
+import org.opendaylight.netconf.sal.connect.netconf.sal.AbstractNetconfDataTreeService;
+import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceDataBroker;
import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.netconf.topology.singleton.api.NetconfDOMTransaction;
-import org.opendaylight.netconf.topology.singleton.impl.tx.NetconfMasterDOMTransaction;
-import org.opendaylight.netconf.topology.singleton.impl.tx.NetconfProxyDOMTransaction;
-import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils;
import org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.concurrent.Future;
-class MasterSalFacade implements AutoCloseable, RemoteDeviceHandler<NetconfSessionPreferences> {
-
+class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(MasterSalFacade.class);
private final RemoteDeviceId id;
-
- private SchemaContext remoteSchemaContext = null;
- private NetconfSessionPreferences netconfSessionPreferences = null;
- private DOMRpcService deviceRpc = null;
+ private final Timeout actorResponseWaitTime;
private final NetconfDeviceSalProvider salProvider;
-
private final ActorRef masterActorRef;
private final ActorSystem actorSystem;
+
+ private NetconfDeviceSchema currentSchema = null;
+ private NetconfSessionPreferences netconfSessionPreferences = null;
+ private RemoteDeviceServices deviceServices = null;
private DOMDataBroker deviceDataBroker = null;
+ private NetconfDataTreeService netconfService = null;
MasterSalFacade(final RemoteDeviceId id,
- final Broker domBroker,
- final BindingAwareBroker bindingBroker,
- final ActorSystem actorSystem,
- final ActorRef masterActorRef) {
+ final ActorSystem actorSystem,
+ final ActorRef masterActorRef,
+ final Timeout actorResponseWaitTime,
+ final DOMMountPointService mountService,
+ final DataBroker dataBroker) {
this.id = id;
- this.salProvider = new NetconfDeviceSalProvider(id);
+ salProvider = new NetconfDeviceSalProvider(id, mountService, dataBroker);
this.actorSystem = actorSystem;
this.masterActorRef = masterActorRef;
-
- registerToSal(domBroker, bindingBroker);
- }
-
- private void registerToSal(final Broker domRegistryDependency, final BindingAwareBroker bindingBroker) {
- // TODO: remove use of provider, there is possible directly create mount instance and
- // TODO: NetconfDeviceTopologyAdapter in constructor = less complexity
-
- domRegistryDependency.registerProvider(salProvider);
- bindingBroker.registerProvider(salProvider);
+ this.actorResponseWaitTime = actorResponseWaitTime;
}
@Override
- public void onDeviceConnected(final SchemaContext remoteSchemaContext,
- final NetconfSessionPreferences netconfSessionPreferences,
- final DOMRpcService deviceRpc) {
- this.remoteSchemaContext = remoteSchemaContext;
- this.netconfSessionPreferences = netconfSessionPreferences;
- this.deviceRpc = deviceRpc;
+ public void onDeviceConnected(final NetconfDeviceSchema deviceSchema,
+ final NetconfSessionPreferences sessionPreferences, final RemoteDeviceServices services) {
+ currentSchema = requireNonNull(deviceSchema);
+ netconfSessionPreferences = requireNonNull(sessionPreferences);
+ deviceServices = requireNonNull(services);
+ if (services.actions() != null) {
+ LOG.debug("{}: YANG 1.1 actions are supported in clustered netconf topology, DOMActionService exposed for "
+ + "the device", id);
+ }
+
+ LOG.info("Device {} connected - registering master mount point", id);
registerMasterMountPoint();
- sendInitialDataToActor().onComplete(new OnComplete<Object>() {
+ sendInitialDataToActor().onComplete(new OnComplete<>() {
@Override
- public void onComplete(final Throwable failure, final Object success) throws Throwable {
+ public void onComplete(final Throwable failure, final Object success) {
if (failure == null) {
updateDeviceData();
return;
}
- throw failure;
+
+ LOG.error("{}: CreateInitialMasterActorData to {} failed", id, masterActorRef, failure);
}
}, actorSystem.dispatcher());
-
}
@Override
public void onDeviceDisconnected() {
- salProvider.getTopologyDatastoreAdapter().updateDeviceData(false, new NetconfDeviceCapabilities());
+ LOG.info("Device {} disconnected - unregistering master mount point", id);
+ salProvider.getTopologyDatastoreAdapter().updateDeviceData(false, NetconfDeviceCapabilities.empty());
unregisterMasterMountPoint();
}
}
private void registerMasterMountPoint() {
- Preconditions.checkNotNull(id);
- Preconditions.checkNotNull(remoteSchemaContext,
- "Device has no remote schema context yet. Probably not fully connected.");
- Preconditions.checkNotNull(netconfSessionPreferences,
- "Device has no capabilities yet. Probably not fully connected.");
+ requireNonNull(id);
- final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
+ final var mountContext = requireNonNull(currentSchema,
+ "Device has no remote schema context yet. Probably not fully connected.")
+ .mountContext();
+ final var preferences = requireNonNull(netconfSessionPreferences,
+ "Device has no capabilities yet. Probably not fully connected.");
- LOG.info("{}: Creating master data broker for device", id);
+ deviceDataBroker = newDeviceDataBroker(mountContext, preferences);
+ netconfService = newNetconfDataTreeService(mountContext, preferences);
- final NetconfDOMTransaction masterDOMTransactions =
- new NetconfMasterDOMTransaction(id, remoteSchemaContext, deviceRpc, netconfSessionPreferences);
- deviceDataBroker =
- new NetconfDOMDataBroker(actorSystem, id, masterDOMTransactions);
- // We need to create NetconfProxyDOMTransaction so accessing mountpoint
+ // We need to create ProxyDOMDataBroker so accessing mountpoint
// on leader node would be same as on follower node
- final NetconfDOMTransaction proxyDOMTransation =
- new NetconfProxyDOMTransaction(id, actorSystem, masterActorRef);
- final NetconfDOMDataBroker proxyDataBroker = new NetconfDOMDataBroker(actorSystem, id, proxyDOMTransation);
- salProvider.getMountInstance()
- .onTopologyDeviceConnected(remoteSchemaContext, proxyDataBroker, deviceRpc, notificationService);
+ final ProxyDOMDataBroker proxyDataBroker = new ProxyDOMDataBroker(id, masterActorRef, actorSystem.dispatcher(),
+ actorResponseWaitTime);
+ final NetconfDataTreeService proxyNetconfService = new ProxyNetconfDataTreeService(id, masterActorRef,
+ actorSystem.dispatcher(), actorResponseWaitTime);
+ salProvider.getMountInstance().onTopologyDeviceConnected(mountContext.getEffectiveModelContext(),
+ deviceServices, proxyDataBroker, proxyNetconfService);
+ }
+
+ protected DOMDataBroker newDeviceDataBroker(final MountPointContext mountContext,
+ final NetconfSessionPreferences preferences) {
+ return new NetconfDeviceDataBroker(id, mountContext, deviceServices.rpcs(), preferences);
+ }
+
+ protected NetconfDataTreeService newNetconfDataTreeService(final MountPointContext mountContext,
+ final NetconfSessionPreferences preferences) {
+ return AbstractNetconfDataTreeService.of(id, mountContext, deviceServices.rpcs(), preferences);
}
private Future<Object> sendInitialDataToActor() {
- final List<SourceIdentifier> sourceIdentifiers =
- remoteSchemaContext.getAllModuleIdentifiers().stream().map(mi ->
- RevisionSourceIdentifier.create(mi.getName(),
- (SimpleDateFormatUtil.DEFAULT_DATE_REV == mi.getRevision() ? Optional.<String>absent() :
- Optional.of(SimpleDateFormatUtil.getRevisionFormat().format(mi.getRevision())))))
- .collect(Collectors.toList());
-
- // send initial data to master actor and create actor for providing it
- return Patterns.ask(masterActorRef, new CreateInitialMasterActorData(deviceDataBroker, sourceIdentifiers,
- deviceRpc), NetconfTopologyUtils.TIMEOUT);
+ final List<SourceIdentifier> sourceIdentifiers = List.copyOf(SchemaContextUtil.getConstituentModuleIdentifiers(
+ currentSchema.mountContext().getEffectiveModelContext()));
+
+ LOG.debug("{}: Sending CreateInitialMasterActorData with sourceIdentifiers {} to {}", id, sourceIdentifiers,
+ masterActorRef);
+
+ // send initial data to master actor
+ return Patterns.ask(masterActorRef, new CreateInitialMasterActorData(deviceDataBroker, netconfService,
+ sourceIdentifiers, deviceServices.rpcs(), deviceServices.actions()), actorResponseWaitTime);
}
private void updateDeviceData() {
- Cluster cluster = Cluster.get(actorSystem);
- salProvider.getTopologyDatastoreAdapter().updateClusteredDeviceData(true, cluster.selfAddress().toString(),
- netconfSessionPreferences.getNetconfDeviceCapabilities());
+ final String masterAddress = Cluster.get(actorSystem).selfAddress().toString();
+ LOG.debug("{}: updateDeviceData with master address {}", id, masterAddress);
+ salProvider.getTopologyDatastoreAdapter().updateClusteredDeviceData(true, masterAddress,
+ currentSchema.capabilities());
}
private void unregisterMasterMountPoint() {
salProvider.getMountInstance().onTopologyDeviceDisconnected();
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
private void closeGracefully(final AutoCloseable resource) {
if (resource != null) {
try {
}
}
}
-
}