From 77fa76b4b15ec6d74920349f9a066ec4597b2585 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Tue, 16 Aug 2016 11:04:00 +0200 Subject: HONEYCOMB-22: Remove karaf based distribution and wiring Change-Id: I48aafb726de53b6ad3fb9b97c202f712dfa4a540 Signed-off-by: Maros Marsalek --- .../api/src/main/yang/notification-api.yang | 31 ----- infra/notification/impl/pom.xml | 32 ----- .../impl/src/main/config/default-config.xml | 71 ---------- .../main/config/notification-to-netconf-config.xml | 58 -------- .../notification/impl/TranslationUtil.java | 104 ++++++++++++++ .../HoneycombDomNotificationServiceModule.java | 27 ---- ...neycombDomNotificationServiceModuleFactory.java | 13 -- .../HoneycombNotificationManagerModule.java | 93 ------------- .../HoneycombNotificationManagerModuleFactory.java | 13 -- ...ycombNotificationToNetconfTranslatorModule.java | 155 --------------------- ...tificationToNetconfTranslatorModuleFactory.java | 13 -- .../impl/src/main/yang/notification-impl.yang | 141 ------------------- .../NoetificationToNetconfModuleTest.java | 3 +- 13 files changed, 106 insertions(+), 648 deletions(-) delete mode 100644 infra/notification/api/src/main/yang/notification-api.yang delete mode 100644 infra/notification/impl/src/main/config/default-config.xml delete mode 100644 infra/notification/impl/src/main/config/notification-to-netconf-config.xml create mode 100644 infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/TranslationUtil.java delete mode 100644 infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombDomNotificationServiceModule.java delete mode 100644 infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombDomNotificationServiceModuleFactory.java delete mode 100644 infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModule.java delete mode 100644 infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModuleFactory.java delete mode 100644 infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModule.java delete mode 100644 infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModuleFactory.java delete mode 100644 infra/notification/impl/src/main/yang/notification-impl.yang (limited to 'infra/notification') diff --git a/infra/notification/api/src/main/yang/notification-api.yang b/infra/notification/api/src/main/yang/notification-api.yang deleted file mode 100644 index f0331bc07..000000000 --- a/infra/notification/api/src/main/yang/notification-api.yang +++ /dev/null @@ -1,31 +0,0 @@ -module notification-api { - yang-version 1; - namespace "urn:honeycomb:params:xml:ns:yang:notification:api"; - prefix "hc-notif-a"; - - import config { prefix config; revision-date 2013-04-05; } - - description - "Module definition for honeycomb notification service APIs"; - - revision "2016-06-01" { - description - "Initial revision"; - } - - identity honeycomb-notification-collector { - base "config:service-type"; - config:java-class io.fd.honeycomb.notification.NotificationCollector; - } - - identity dom-notification-service { - base "config:service-type"; - config:java-class org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; - } - - identity honeycomb-notification-producer { - base "config:service-type"; - config:java-class io.fd.honeycomb.notification.ManagedNotificationProducer; - } - -} diff --git a/infra/notification/impl/pom.xml b/infra/notification/impl/pom.xml index 9fa542422..bc0a78e6e 100644 --- a/infra/notification/impl/pom.xml +++ b/infra/notification/impl/pom.xml @@ -57,36 +57,4 @@ test - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - - attach-artifact - - package - - - - ${config.file} - xml - config - - - src/main/config/notification-to-netconf-config.xml - xml - notification2netconf - - - - - - - - diff --git a/infra/notification/impl/src/main/config/default-config.xml b/infra/notification/impl/src/main/config/default-config.xml deleted file mode 100644 index 2b91de47f..000000000 --- a/infra/notification/impl/src/main/config/default-config.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - urn:honeycomb:params:xml:ns:yang:notification:impl?module=notification-impl&revision=2016-06-01 - - - - - - - - prefix:honeycomb-dom-notification-service - honeycomb-dom-notification-service - 1024 - - - - - prefix:honeycomb-notification-manager - honeycomb-notification-manager - - binding-impl:binding-dom-mapping-service - runtime-mapping-singleton - - - prefix:dom-notification-service - honeycomb-dom-notification-service - - - - - - - - - - - prefix:dom-notification-service - - honeycomb-dom-notification-service - /modules/module[type='honeycomb-dom-notification-service'][name='honeycomb-dom-notification-service'] - - - - prefix:honeycomb-notification-collector - - honeycomb-notification-manager - /modules/module[type='honeycomb-notification-manager'][name='honeycomb-notification-manager'] - - - - - - - - diff --git a/infra/notification/impl/src/main/config/notification-to-netconf-config.xml b/infra/notification/impl/src/main/config/notification-to-netconf-config.xml deleted file mode 100644 index d64de6413..000000000 --- a/infra/notification/impl/src/main/config/notification-to-netconf-config.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - urn:honeycomb:params:xml:ns:yang:notification:impl?module=notification-impl&revision=2016-06-01 - - - - - - - prefix:honeycomb-notification-to-netconf-translator - honeycomb-notification-to-netconf-translator - - - prefix:netconf-notification-registry - - honeycomb-netconf-notification-manager - - - - prefix:netconf-notification-collector - - honeycomb-netconf-notification-manager - - - dom:schema-service - yang-schema-service - - - prefix:honeycomb-notification-collector - honeycomb-notification-manager - - - prefix:dom-notification-service - honeycomb-dom-notification-service - - honeycomb - All notifications received by honeycomb's plugins - - - - - diff --git a/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/TranslationUtil.java b/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/TranslationUtil.java new file mode 100644 index 000000000..e53d59196 --- /dev/null +++ b/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/TranslationUtil.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.notification.impl; + +import java.io.IOException; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import javax.xml.transform.dom.DOMResult; +import org.opendaylight.controller.config.util.xml.XmlUtil; +import org.opendaylight.controller.md.sal.dom.api.DOMNotification; +import org.opendaylight.netconf.notifications.NetconfNotification; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; +import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; +import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; +import org.opendaylight.yangtools.yang.data.impl.codec.xml.XMLStreamNormalizedNodeStreamWriter; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public final class TranslationUtil { + + public TranslationUtil() {} + + private static final Logger LOG = LoggerFactory.getLogger(TranslationUtil.class); + private static final XMLOutputFactory XML_FACTORY; + + static { + XML_FACTORY = XMLOutputFactory.newFactory(); + XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false); + } + + /** + * Transform {@link org.opendaylight.mdsal.dom.api.DOMNotification} into an XML based {@link NetconfNotification}. + */ + public static NetconfNotification notificationToXml(final DOMNotification domNotification, final SchemaContext ctx) { + + LOG.trace("Transforming notification: {} into XML", domNotification.getType()); + + final SchemaPath type = domNotification.getType(); + final QName notificationQName = type.getLastComponent(); + final DOMResult result = prepareDomResultForRpcRequest(notificationQName); + + try { + writeNormalizedRpc(domNotification, result, type, ctx); + } catch (final XMLStreamException | IOException | IllegalStateException e) { + LOG.warn("Unable to transform notification: {} into XML", domNotification.getType(), e); + throw new IllegalArgumentException("Unable to serialize " + type, e); + } + + final Document node = result.getNode().getOwnerDocument(); + return new NetconfNotification(node); + } + + private static DOMResult prepareDomResultForRpcRequest(final QName notificationQName) { + final Document document = XmlUtil.newDocument(); + final Element notificationElement = + document.createElementNS(notificationQName.getNamespace().toString(), notificationQName.getLocalName()); + document.appendChild(notificationElement); + return new DOMResult(notificationElement); + } + + private static void writeNormalizedRpc(final DOMNotification normalized, final DOMResult result, + final SchemaPath schemaPath, final SchemaContext baseNetconfCtx) + throws IOException, XMLStreamException { + final XMLStreamWriter writer = XML_FACTORY.createXMLStreamWriter(result); + try { + try (final NormalizedNodeStreamWriter normalizedNodeStreamWriter = + XMLStreamNormalizedNodeStreamWriter.create(writer, baseNetconfCtx, schemaPath)) { + try (final NormalizedNodeWriter normalizedNodeWriter = + NormalizedNodeWriter.forStreamWriter(normalizedNodeStreamWriter)) { + for (DataContainerChild dataContainerChild : normalized.getBody().getValue()) { + normalizedNodeWriter.write(dataContainerChild); + } + normalizedNodeWriter.flush(); + } + } + } finally { + try { + writer.close(); + } catch (final Exception e) { + LOG.warn("Unable to close resource properly. Ignoring", e); + } + } + } +} diff --git a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombDomNotificationServiceModule.java b/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombDomNotificationServiceModule.java deleted file mode 100644 index 9a9c7def0..000000000 --- a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombDomNotificationServiceModule.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601; - -import org.opendaylight.controller.config.api.JmxAttributeValidationException; -import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; - -public class HoneycombDomNotificationServiceModule extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.AbstractHoneycombDomNotificationServiceModule { - public HoneycombDomNotificationServiceModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public HoneycombDomNotificationServiceModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.HoneycombDomNotificationServiceModule oldModule, java.lang.AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - public void customValidation() { - JmxAttributeValidationException.checkCondition(getQueueDepth() > 0, "Queue depth must be > 0", queueDepthJmxAttribute); - } - - @Override - public java.lang.AutoCloseable createInstance() { - // Create DOMNotificationRouter to do the heavy lifting for HoneycombNotificationCollector - // It creates executor internally - return DOMNotificationRouter.create(getQueueDepth()); - } - -} diff --git a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombDomNotificationServiceModuleFactory.java b/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombDomNotificationServiceModuleFactory.java deleted file mode 100644 index d3603acb3..000000000 --- a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombDomNotificationServiceModuleFactory.java +++ /dev/null @@ -1,13 +0,0 @@ -/* -* Generated file -* -* Generated from: yang module name: notification-impl yang module local name: honeycomb-dom-notification-service -* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator -* Generated at: Wed Jun 08 09:49:08 CEST 2016 -* -* Do not modify this file unless it is present under src/main directory -*/ -package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601; -public class HoneycombDomNotificationServiceModuleFactory extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.AbstractHoneycombDomNotificationServiceModuleFactory { - -} diff --git a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModule.java b/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModule.java deleted file mode 100644 index 056b38798..000000000 --- a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModule.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601; - -import io.fd.honeycomb.notification.NotificationCollector; -import io.fd.honeycomb.notification.NotificationProducer; -import io.fd.honeycomb.notification.impl.HoneycombNotificationCollector; -import io.fd.honeycomb.notification.impl.NotificationProducerRegistry; -import io.fd.honeycomb.notification.impl.NotificationProducerTracker; -import java.util.Collection; -import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter; -import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; -import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; -import org.opendaylight.yangtools.yang.binding.Notification; - -public class HoneycombNotificationManagerModule extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.AbstractHoneycombNotificationManagerModule { - - public HoneycombNotificationManagerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public HoneycombNotificationManagerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.HoneycombNotificationManagerModule oldModule, java.lang.AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - public void customValidation() { - // add custom validation form module attributes here. - } - - @Override - public java.lang.AutoCloseable createInstance() { - final DOMNotificationRouter notificationRouter = getDomNotificationServiceDependency(); - - // Create the registry to keep track of what's registered - final NotificationProducerRegistry notificationProducerRegistry = - new NotificationProducerRegistry(getNotificationProducersDependency()); - - // Create BA version of notification service (implementation is free from ODL) - final BindingToNormalizedNodeCodec codec = getRuntimeMappingCodecDependency(); - final BindingDOMNotificationPublishServiceAdapter bindingDOMNotificationPublishServiceAdapter = - new BindingDOMNotificationPublishServiceAdapter(codec, notificationRouter); - - // Create Collector on top of BA notification service and registry - final HoneycombNotificationCollector honeycombNotificationCollector = - new HoneycombNotificationCollector(bindingDOMNotificationPublishServiceAdapter, notificationProducerRegistry); - - // Create tracker, responsible for starting and stopping registered notification producers whenever necessary - final NotificationProducerTracker notificationProducerTracker = - new NotificationProducerTracker(notificationProducerRegistry, honeycombNotificationCollector, - notificationRouter); - - // TODO wire with restconf - // DOMNotificationService is already provided by DOMBroker injected into RESTCONF, however RESTCONF - // only supports data-change notification, nothing else. So currently its impossible. - - return new CloseableCollector(honeycombNotificationCollector, () -> { - // Close all resources in order opposite to instantiation - notificationProducerTracker.close(); - honeycombNotificationCollector.close(); - bindingDOMNotificationPublishServiceAdapter.close(); - // notificationProducerRegistry; no close, it's just a collection - }); - } - - /** - * NotificationCollector wrapper in which close method execution can be injected - */ - private class CloseableCollector implements AutoCloseable, NotificationCollector, NotificationProducer { - - private final HoneycombNotificationCollector honeycombNotificationCollector; - private final AutoCloseable resources; - - CloseableCollector(final HoneycombNotificationCollector honeycombNotificationCollector, - final AutoCloseable resources) { - this.honeycombNotificationCollector = honeycombNotificationCollector; - this.resources = resources; - } - - @Override - public void close() throws Exception { - resources.close(); - } - - @Override - public void onNotification(final Notification notification) { - honeycombNotificationCollector.onNotification(notification); - } - - @Override - public Collection> getNotificationTypes() { - return honeycombNotificationCollector.getNotificationTypes(); - } - } -} diff --git a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModuleFactory.java b/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModuleFactory.java deleted file mode 100644 index b12b70017..000000000 --- a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModuleFactory.java +++ /dev/null @@ -1,13 +0,0 @@ -/* -* Generated file -* -* Generated from: yang module name: notification-impl yang module local name: honeycomb-notification-manager -* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator -* Generated at: Wed Jun 01 16:08:01 CEST 2016 -* -* Do not modify this file unless it is present under src/main directory -*/ -package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601; -public class HoneycombNotificationManagerModuleFactory extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.AbstractHoneycombNotificationManagerModuleFactory { - -} diff --git a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModule.java b/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModule.java deleted file mode 100644 index a6f625589..000000000 --- a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModule.java +++ /dev/null @@ -1,155 +0,0 @@ -package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601; - -import io.fd.honeycomb.notification.NotificationCollector; -import io.fd.honeycomb.notification.impl.NotificationProducerRegistry; -import java.io.IOException; -import java.util.Set; -import java.util.stream.Collectors; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.dom.DOMResult; -import org.opendaylight.controller.config.api.JmxAttributeValidationException; -import org.opendaylight.controller.config.util.xml.XmlUtil; -import org.opendaylight.controller.md.sal.dom.api.DOMNotification; -import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener; -import org.opendaylight.controller.sal.core.api.model.SchemaService; -import org.opendaylight.netconf.notifications.NetconfNotification; -import org.opendaylight.netconf.notifications.NotificationPublisherRegistration; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; -import org.opendaylight.yangtools.yang.data.impl.codec.xml.XMLStreamNormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class HoneycombNotificationToNetconfTranslatorModule extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.AbstractHoneycombNotificationToNetconfTranslatorModule { - - private static final Logger LOG = LoggerFactory.getLogger(HoneycombNotificationToNetconfTranslatorModule.class); - - public HoneycombNotificationToNetconfTranslatorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public HoneycombNotificationToNetconfTranslatorModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.HoneycombNotificationToNetconfTranslatorModule oldModule, java.lang.AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - public void customValidation() { - JmxAttributeValidationException.checkCondition(!getNetconfStreamName().isEmpty(), - "Stream name cannot be empty", netconfStreamNameJmxAttribute); - JmxAttributeValidationException.checkCondition(!getNetconfStreamDescription().isEmpty(), - "Stream description cannot be empty", netconfStreamDescriptionJmxAttribute); - } - - @Override - public java.lang.AutoCloseable createInstance() { - final SchemaService schemaService = getSchemaServiceDependency(); - final StreamNameType streamType = new StreamNameType(getNetconfStreamName()); - final NotificationCollector hcNotificationCollector = getHoneycombNotificationCollectorDependency(); - - // Register as NETCONF notification publisher under configured name - final NotificationPublisherRegistration netconfNotificationProducerReg = - getNetconfNotificationCollectorDependency().registerNotificationPublisher(new StreamBuilder() - .setName(streamType) - .setReplaySupport(false) - .setDescription(getNetconfStreamDescription()).build()); - - // Notification Translator, get notification from HC producers and put into NETCONF notification collector - final DOMNotificationListener domNotificationListener = - notification -> { - LOG.debug("Propagating notification: {} into NETCONF", notification.getType()); - netconfNotificationProducerReg.onNotification(streamType, notificationToXml(notification, schemaService.getGlobalContext())); - }; - - // NotificationManager is used to provide list of available notifications (which are all of the notifications registered) - // TODO make available notifications configurable here so that any number of notification streams for NETCONF - // can be configured on top of a single notification manager - LOG.debug("Current notifications to be exposed over NETCONF: {}", hcNotificationCollector.getNotificationTypes()); - final Set currentNotificationSchemaPaths = hcNotificationCollector.getNotificationTypes() - .stream() - .map(NotificationProducerRegistry::getQName) - .map(qName -> SchemaPath.create(true, qName)) - .collect(Collectors.toSet()); - - // Register as listener to HC's DOM notification service - // TODO This should only be triggered when NETCONF notifications are activated - // Because this way we actually start all notification producers - // final Collection notificationQNames = - final ListenerRegistration domNotificationListenerReg = getDomNotificationServiceDependency() - .registerNotificationListener(domNotificationListener, currentNotificationSchemaPaths); - - LOG.info("Exposing NETCONF notification stream: {}", streamType.getValue()); - return () -> { - domNotificationListenerReg.close(); - netconfNotificationProducerReg.close(); - }; - } - - public static NetconfNotification notificationToXml(final DOMNotification domNotification, final SchemaContext ctx) { - LOG.trace("Transforming notification: {} into XML", domNotification.getType()); - - final SchemaPath type = domNotification.getType(); - final QName notificationQName = type.getLastComponent(); - final DOMResult result = prepareDomResultForRpcRequest(notificationQName); - - try { - writeNormalizedRpc(domNotification, result, type, ctx); - } catch (final XMLStreamException | IOException | IllegalStateException e) { - LOG.warn("Unable to transform notification: {} into XML", domNotification.getType(), e); - throw new IllegalArgumentException("Unable to serialize " + type, e); - } - - final Document node = result.getNode().getOwnerDocument(); - return new NetconfNotification(node); - } - - private static DOMResult prepareDomResultForRpcRequest(final QName notificationQName) { - final Document document = XmlUtil.newDocument(); - final Element notificationElement = - document.createElementNS(notificationQName.getNamespace().toString(), notificationQName.getLocalName()); - document.appendChild(notificationElement); - return new DOMResult(notificationElement); - } - - private static final XMLOutputFactory XML_FACTORY; - - static { - XML_FACTORY = XMLOutputFactory.newFactory(); - XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false); - } - - private static void writeNormalizedRpc(final DOMNotification normalized, final DOMResult result, - final SchemaPath schemaPath, final SchemaContext baseNetconfCtx) - throws IOException, XMLStreamException { - final XMLStreamWriter writer = XML_FACTORY.createXMLStreamWriter(result); - try { - try (final NormalizedNodeStreamWriter normalizedNodeStreamWriter = - XMLStreamNormalizedNodeStreamWriter.create(writer, baseNetconfCtx, schemaPath)) { - try (final NormalizedNodeWriter normalizedNodeWriter = - NormalizedNodeWriter.forStreamWriter(normalizedNodeStreamWriter)) { - for (DataContainerChild dataContainerChild : normalized.getBody().getValue()) { - normalizedNodeWriter.write(dataContainerChild); - } - normalizedNodeWriter.flush(); - } - } - } finally { - try { - writer.close(); - } catch (final Exception e) { - LOG.warn("Unable to close resource properly. Ignoring", e); - } - } - } - -} diff --git a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModuleFactory.java b/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModuleFactory.java deleted file mode 100644 index 336223040..000000000 --- a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModuleFactory.java +++ /dev/null @@ -1,13 +0,0 @@ -/* -* Generated file -* -* Generated from: yang module name: notification-impl yang module local name: honeycomb-notification-to-netconf-translator -* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator -* Generated at: Thu Jun 02 14:39:23 CEST 2016 -* -* Do not modify this file unless it is present under src/main directory -*/ -package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601; -public class HoneycombNotificationToNetconfTranslatorModuleFactory extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.AbstractHoneycombNotificationToNetconfTranslatorModuleFactory { - -} diff --git a/infra/notification/impl/src/main/yang/notification-impl.yang b/infra/notification/impl/src/main/yang/notification-impl.yang deleted file mode 100644 index 84899751c..000000000 --- a/infra/notification/impl/src/main/yang/notification-impl.yang +++ /dev/null @@ -1,141 +0,0 @@ -module notification-impl { - yang-version 1; - namespace "urn:honeycomb:params:xml:ns:yang:notification:impl"; - prefix "hc-notif-i"; - - import config { prefix config; revision-date 2013-04-05; } - import netconf-northbound-notification { prefix notify-api; revision-date 2015-08-06; } - import notification-api { prefix hc-notif-a; revision-date 2016-06-01; } - import opendaylight-md-sal-dom { prefix dom; revision-date 2013-10-28;} - import opendaylight-sal-binding-broker-impl { prefix binding-impl; revision-date 2013-10-28;} - - description - "Module definition for honeycomb notification implementations"; - - revision "2016-06-01" { - description - "Initial revision"; - } - - identity honeycomb-notification-manager { - base config:module-type; - config:java-name-prefix HoneycombNotificationManager; - config:provided-service hc-notif-a:honeycomb-notification-collector; - } - - augment "/config:modules/config:module/config:configuration" { - case honeycomb-notification-manager { - when "/config:modules/config:module/config:type = 'honeycomb-notification-manager'"; - - container runtime-mapping-codec { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity binding-impl:binding-dom-mapping-service; - } - } - } - - container dom-notification-service { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity hc-notif-a:dom-notification-service; - } - } - } - - list notification-producers { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity hc-notif-a:honeycomb-notification-producer; - } - } - } - - } - } - - identity honeycomb-dom-notification-service { - base config:module-type; - config:provided-service hc-notif-a:dom-notification-service; - } - - augment "/config:modules/config:module/config:configuration" { - case honeycomb-dom-notification-service { - when "/config:modules/config:module/config:type = 'honeycomb-dom-notification-service'"; - - leaf queue-depth { - type uint16; - description "Size of the queue for outgoing notifications"; - } - } - } - - identity honeycomb-notification-to-netconf-translator { - base config:module-type; - config:java-name-prefix HoneycombNotificationToNetconfTranslator; - } - - augment "/config:modules/config:module/config:configuration" { - case honeycomb-notification-to-netconf-translator { - when "/config:modules/config:module/config:type = 'honeycomb-notification-to-netconf-translator'"; - - container netconf-notification-collector { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity notify-api:netconf-notification-collector; - } - } - } - container honeycomb-notification-collector { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity hc-notif-a:honeycomb-notification-collector; - } - } - } - container netconf-notification-registry { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity notify-api:netconf-notification-registry; - } - } - } - container schema-service { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity dom:schema-service; - } - } - } - container dom-notification-service { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity hc-notif-a:dom-notification-service; - } - } - } - - leaf netconf-stream-name { - type string; - mandatory true; - description "Name of the stream under which all the registered notifications should be emitted"; - } - - leaf netconf-stream-description { - type string; - mandatory true; - description "Description for the stream under which all the registered notifications should be emitted"; - } - - } - } - -} diff --git a/infra/notification/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/NoetificationToNetconfModuleTest.java b/infra/notification/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/NoetificationToNetconfModuleTest.java index ccfb4bb9d..d9b487be7 100644 --- a/infra/notification/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/NoetificationToNetconfModuleTest.java +++ b/infra/notification/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/NoetificationToNetconfModuleTest.java @@ -15,6 +15,7 @@ */ package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601; +import io.fd.honeycomb.notification.impl.TranslationUtil; import javax.annotation.Nonnull; import org.hamcrest.CoreMatchers; import org.junit.Assert; @@ -61,7 +62,7 @@ public class NoetificationToNetconfModuleTest { public void notificationToXml() throws Exception { final ModuleInfoBackedContext moduleInfoBackedContext = getModuleInfoBackedCOntext(); - final NetconfNotification netconfNotification = HoneycombNotificationToNetconfTranslatorModule + final NetconfNotification netconfNotification = TranslationUtil .notificationToXml(notification, moduleInfoBackedContext.getSchemaContext()); final String notificationString = netconfNotification.toString(); -- cgit 1.2.3-korg