X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fmdsal-netconf-notification%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fmdsal%2Fnotification%2Fimpl%2FCapabilityChangeNotificationProducer.java;fp=netconf%2Fmdsal-netconf-notification%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fmdsal%2Fnotification%2Fimpl%2FCapabilityChangeNotificationProducer.java;h=0000000000000000000000000000000000000000;hb=0ff6ea042b7c74fd99c0e48afd7e6e8fb5bdd95d;hp=9fe607e43e12170ace1a877af5f208a2fe7cd3f8;hpb=87530da0c4c7e634be1bc3e030e391a56d1ea54a;p=netconf.git diff --git a/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/CapabilityChangeNotificationProducer.java b/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/CapabilityChangeNotificationProducer.java deleted file mode 100644 index 9fe607e43e..0000000000 --- a/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/CapabilityChangeNotificationProducer.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. 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.netconf.mdsal.notification.impl; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import java.util.Collection; -import java.util.Set; -import org.opendaylight.mdsal.binding.api.DataBroker; -import org.opendaylight.mdsal.binding.api.DataObjectModification; -import org.opendaylight.mdsal.binding.api.DataTreeModification; -import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration; -import org.opendaylight.netconf.notifications.NetconfNotificationCollector; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.changed.by.parms.ChangedByBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.changed.by.parms.changed.by.server.or.user.ServerBuilder; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.Empty; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Deactivate; -import org.osgi.service.component.annotations.Reference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Listens on capabilities changes in data store and publishes them to base - * netconf notification stream listener. - */ -@Component(service = { }) -public final class CapabilityChangeNotificationProducer extends OperationalDatastoreListener - implements AutoCloseable { - private static final Logger LOG = LoggerFactory.getLogger(CapabilityChangeNotificationProducer.class); - private static final InstanceIdentifier CAPABILITIES_INSTANCE_IDENTIFIER = - InstanceIdentifier.builder(NetconfState.class).child(Capabilities.class).build(); - - private final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration; - private final ListenerRegistration capabilityChangeListenerRegistration; - - @Activate - public CapabilityChangeNotificationProducer( - @Reference(target = "(type=netconf-notification-manager)") final NetconfNotificationCollector notifManager, - @Reference final DataBroker dataBroker) { - super(CAPABILITIES_INSTANCE_IDENTIFIER); - baseNotificationPublisherRegistration = notifManager.registerBaseNotificationPublisher(); - capabilityChangeListenerRegistration = registerOnChanges(dataBroker); - } - - @Deactivate - @Override - public void close() { - if (baseNotificationPublisherRegistration != null) { - baseNotificationPublisherRegistration.close(); - } - if (capabilityChangeListenerRegistration != null) { - capabilityChangeListenerRegistration.close(); - } - } - - @Override - public void onDataTreeChanged(final Collection> changes) { - for (DataTreeModification change : changes) { - final DataObjectModification rootNode = change.getRootNode(); - final DataObjectModification.ModificationType modificationType = rootNode.getModificationType(); - switch (modificationType) { - case WRITE: { - final Capabilities dataAfter = rootNode.getDataAfter(); - final Capabilities dataBefore = rootNode.getDataBefore(); - final Set before = dataBefore != null ? ImmutableSet.copyOf(dataBefore.getCapability()) - : Set.of(); - final Set after = dataAfter != null ? ImmutableSet.copyOf(dataAfter.getCapability()) - : Set.of(); - final Set added = Sets.difference(after, before); - final Set removed = Sets.difference(before, after); - publishNotification(added, removed); - break; - } - case DELETE: { - final Capabilities dataBeforeDelete = rootNode.getDataBefore(); - if (dataBeforeDelete != null) { - final Set removed = ImmutableSet.copyOf(dataBeforeDelete.getCapability()); - publishNotification(Set.of(), removed); - } - break; - } - default: - LOG.debug("Received intentionally unhandled type: {}.", modificationType); - } - } - } - - private void publishNotification(final Set added, final Set removed) { - baseNotificationPublisherRegistration.onCapabilityChanged(new NetconfCapabilityChangeBuilder() - .setChangedBy(new ChangedByBuilder() - .setServerOrUser(new ServerBuilder().setServer(Empty.value()).build()) - .build()) - .setAddedCapability(Set.copyOf(added)) - .setDeletedCapability(Set.copyOf(removed)) - // TODO modified should be computed ... but why ? - .setModifiedCapability(Set.of()) - .build()); - } -}