2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.infra.distro.netconf
19 import com.google.inject.Inject
20 import groovy.transform.ToString
21 import groovy.util.logging.Slf4j
22 import io.fd.honeycomb.infra.distro.ProviderTrait
23 import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration
24 import io.fd.honeycomb.notification.NotificationCollector
25 import io.fd.honeycomb.notification.impl.NotificationProducerRegistry
26 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter
27 import org.opendaylight.controller.sal.core.api.model.SchemaService
28 import org.opendaylight.netconf.notifications.NetconfNotificationCollector
29 import io.fd.honeycomb.notification.impl.TranslationUtil
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder
32 import org.opendaylight.yangtools.yang.model.api.SchemaPath
36 class HoneycombNotification2NetconfProvider extends ProviderTrait<HoneycombNotification2Netconf> {
39 DOMNotificationRouter notificationRouter
41 SchemaService schemaService
43 HoneycombConfiguration cfgAttributes
45 NotificationCollector hcNotificationCollector
47 NetconfNotificationCollector netconfNotificationCollector
51 def streamType = new StreamNameType(cfgAttributes.netconfNotificationStreamName.get());
53 // Register as HONEYCOMB_NETCONF notification publisher under configured name
54 def netconfNotifReg = netconfNotificationCollector.registerNotificationPublisher(new StreamBuilder()
56 .setReplaySupport(false)
57 .setDescription(cfgAttributes.netconfNotificationStreamName.get()).build());
59 // Notification Translator, get notification from HC producers and put into HONEYCOMB_NETCONF notification collector
60 def domNotificationListener = { notif ->
61 log.debug "Propagating notification: {} into HONEYCOMB_NETCONF", notif.type
62 netconfNotifReg.onNotification(streamType, TranslationUtil.notificationToXml(notif, schemaService.globalContext))
65 // NotificationManager is used to provide list of available notifications (which are all of the notifications registered)
66 // TODO make available notifications configurable here so that any number of notification streams for HONEYCOMB_NETCONF
67 // can be configured on top of a single notification manager
68 log.debug "Current notifications to be exposed over HONEYCOMB_NETCONF: {}", hcNotificationCollector.notificationTypes
69 def currentNotificationSchemaPaths = hcNotificationCollector.notificationTypes
70 .collect {SchemaPath.create(true, NotificationProducerRegistry.getQName(it))}
72 // Register as listener to HC'OPERATIONAL DOM notification service
73 // TODO This should only be triggered when HONEYCOMB_NETCONF notifications are activated
74 // Because this way we actually start all notification producers
75 // final Collection<QName> notificationQNames =
76 def domNotifListenerReg = notificationRouter
77 .registerNotificationListener(domNotificationListener, currentNotificationSchemaPaths);
79 log.info "Exposing HONEYCOMB_NETCONF notification stream: {}", streamType.value
81 new HoneycombNotification2Netconf(domNotifListenerReg: domNotifListenerReg, netconfNotifReg: netconfNotifReg)
84 static class HoneycombNotification2Netconf {
85 def domNotifListenerReg