* 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 akka.util.Timeout;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
import java.util.List;
-import java.util.stream.Collectors;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
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.AbstractNetconfDataTreeService;
import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceDataBroker;
import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceNotificationService;
import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
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 final ActorRef masterActorRef;
private final ActorSystem actorSystem;
- private SchemaContext remoteSchemaContext = null;
+ private MountPointContext currentMountContext = null;
private NetconfSessionPreferences netconfSessionPreferences = null;
private DOMRpcService deviceRpc = null;
private DOMDataBroker deviceDataBroker = null;
+ private NetconfDataTreeService netconfService = null;
+ private DOMActionService deviceAction = null;
MasterSalFacade(final RemoteDeviceId id,
final ActorSystem actorSystem,
final DOMMountPointService mountService,
final DataBroker dataBroker) {
this.id = id;
- this.salProvider = new NetconfDeviceSalProvider(id, mountService, dataBroker);
+ salProvider = new NetconfDeviceSalProvider(id, mountService, dataBroker);
this.actorSystem = actorSystem;
this.masterActorRef = masterActorRef;
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 MountPointContext mountContext,
+ final NetconfSessionPreferences sessionPreferences,
+ final DOMRpcService domRpcService, final DOMActionService domActionService) {
+ deviceAction = domActionService;
+ LOG.debug("{}: YANG 1.1 actions are supported in clustered netconf topology, "
+ + "DOMActionService exposed for the device", id);
+ onDeviceConnected(mountContext, sessionPreferences, domRpcService);
+ }
+
+ @Override
+ public void onDeviceConnected(final MountPointContext mountContext,
+ final NetconfSessionPreferences sessionPreferences,
+ final DOMRpcService domRpcService) {
+ currentMountContext = mountContext;
+ netconfSessionPreferences = sessionPreferences;
+ deviceRpc = domRpcService;
+
+ 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() {
+ LOG.info("Device {} disconnected - unregistering master mount point", id);
salProvider.getTopologyDatastoreAdapter().updateDeviceData(false, new NetconfDeviceCapabilities());
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);
+ requireNonNull(currentMountContext, "Device has no remote schema context yet. Probably not fully connected.");
+ requireNonNull(netconfSessionPreferences, "Device has no capabilities yet. Probably not fully connected.");
final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
+ deviceDataBroker = newDeviceDataBroker();
+ netconfService = newNetconfDataTreeService();
- LOG.info("{}: Creating master data broker for device", id);
-
- deviceDataBroker = new NetconfDeviceDataBroker(id, remoteSchemaContext, deviceRpc, netconfSessionPreferences);
// We need to create ProxyDOMDataBroker so accessing mountpoint
// on leader node would be same as on follower node
- final ProxyDOMDataBroker proxyDataBroker =
- new ProxyDOMDataBroker(actorSystem, id, masterActorRef, actorResponseWaitTime);
- 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(currentMountContext.getEffectiveModelContext(),
+ proxyDataBroker, proxyNetconfService, deviceRpc, notificationService, deviceAction);
+ }
+
+ protected DOMDataBroker newDeviceDataBroker() {
+ return new NetconfDeviceDataBroker(id, currentMountContext, deviceRpc, netconfSessionPreferences);
+ }
+
+ protected NetconfDataTreeService newNetconfDataTreeService() {
+ return AbstractNetconfDataTreeService.of(id, currentMountContext, deviceRpc, netconfSessionPreferences);
}
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(mi.getQNameModule().getFormattedRevision()))))
- .collect(Collectors.toList());
-
- // send initial data to master actor and create actor for providing it
- return Patterns.ask(masterActorRef, new CreateInitialMasterActorData(deviceDataBroker, sourceIdentifiers,
- deviceRpc), actorResponseWaitTime);
+ final List<SourceIdentifier> sourceIdentifiers = List.copyOf(SchemaContextUtil.getConstituentModuleIdentifiers(
+ currentMountContext.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, deviceRpc, deviceAction), actorResponseWaitTime);
}
private void updateDeviceData() {
- final Cluster cluster = Cluster.get(actorSystem);
- salProvider.getTopologyDatastoreAdapter().updateClusteredDeviceData(true, cluster.selfAddress().toString(),
+ final String masterAddress = Cluster.get(actorSystem).selfAddress().toString();
+ LOG.debug("{}: updateDeviceData with master address {}", id, masterAddress);
+ salProvider.getTopologyDatastoreAdapter().updateClusteredDeviceData(true, masterAddress,
netconfSessionPreferences.getNetconfDeviceCapabilities());
}
salProvider.getMountInstance().onTopologyDeviceDisconnected();
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
private void closeGracefully(final AutoCloseable resource) {
if (resource != null) {
try {
}
}
}
-
}