From: Tony Tkacik Date: Mon, 23 Feb 2015 11:17:50 +0000 (+0000) Subject: Merge "BUG-2635 Netconf monitoring for md-sal netconf northbound" X-Git-Tag: release/lithium~470^2~9 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=ecabb3cf9b22efd564ef71cb60918318af19d753;hp=ba9a8dbd5baf3c1a235fb42489dbf9c9ba100043 Merge "BUG-2635 Netconf monitoring for md-sal netconf northbound" --- diff --git a/features/mdsal/pom.xml b/features/mdsal/pom.xml index c63b39c74d..5559f92775 100644 --- a/features/mdsal/pom.xml +++ b/features/mdsal/pom.xml @@ -246,6 +246,15 @@ sal-inmemory-datastore + + org.opendaylight.controller + mdsal-netconf-connector + + + org.opendaylight.controller + mdsal-netconf-monitoring + + org.opendaylight.controller sal-netconf-connector diff --git a/features/mdsal/src/main/resources/features.xml b/features/mdsal/src/main/resources/features.xml index 5b9f4a674a..4b9f8c2288 100644 --- a/features/mdsal/src/main/resources/features.xml +++ b/features/mdsal/src/main/resources/features.xml @@ -24,12 +24,14 @@ - + + odl-config-all odl-netconf-all mvn:org.opendaylight.controller/netconf-ssh/${netconf.version} odl-mdsal-broker mvn:org.opendaylight.controller/mdsal-netconf-connector/${netconf.version} + mvn:org.opendaylight.controller/mdsal-netconf-monitoring/${netconf.version} mvn:org.opendaylight.controller/netconf-config-dispatcher/${config.version} mvn:org.opendaylight.controller/netconf-config/${netconf.version}/xml/config diff --git a/features/netconf-connector/pom.xml b/features/netconf-connector/pom.xml index 4e94996634..c69ee197be 100644 --- a/features/netconf-connector/pom.xml +++ b/features/netconf-connector/pom.xml @@ -119,10 +119,6 @@ org.opendaylight.controller netconf-config-dispatcher - - org.opendaylight.controller - mdsal-netconf-connector - org.opendaylight.controller netconf-tcp diff --git a/features/netconf/src/main/resources/features.xml b/features/netconf/src/main/resources/features.xml index a65502124b..aa8287d709 100644 --- a/features/netconf/src/main/resources/features.xml +++ b/features/netconf/src/main/resources/features.xml @@ -27,6 +27,7 @@ mvn:org.opendaylight.controller/ietf-netconf-monitoring-extension/${project.version} mvn:org.opendaylight.yangtools.model/ietf-inet-types/${ietf-inet-types.version} mvn:org.opendaylight.yangtools.model/ietf-yang-types/${ietf-yang-types.version} + mvn:org.opendaylight.yangtools.model/ietf-yang-types-20130715/2013.07.15.7-SNAPSHOT odl-netconf-api diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NotificationHandler.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NotificationHandler.java index b5927f0bd5..80451a1027 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NotificationHandler.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NotificationHandler.java @@ -55,7 +55,10 @@ final class NotificationHandler { passNotifications = true; for (final NetconfMessage cachedNotification : queue) { - passNotification(messageTransformer.toNotification(cachedNotification)); + final CompositeNode parsedNotification = messageTransformer.toNotification(cachedNotification); + // TODO possible race condition here, because this exception is thrown occasionally + Preconditions.checkNotNull(parsedNotification, "Unable to parse received notification %s", cachedNotification); + passNotification(parsedNotification); } queue.clear(); @@ -74,7 +77,6 @@ final class NotificationHandler { private synchronized void passNotification(final CompositeNode parsedNotification) { logger.debug("{}: Forwarding notification {}", id, parsedNotification); - Preconditions.checkNotNull(parsedNotification); if(filter == null || filter.filterNotification(parsedNotification).isPresent()) { salFacade.onNotification(parsedNotification); diff --git a/opendaylight/netconf/ietf-netconf-monitoring/src/main/yang/ietf-netconf-monitoring.yang b/opendaylight/netconf/ietf-netconf-monitoring/src/main/yang/ietf-netconf-monitoring.yang index b4ad89b558..84756fc713 100644 --- a/opendaylight/netconf/ietf-netconf-monitoring/src/main/yang/ietf-netconf-monitoring.yang +++ b/opendaylight/netconf/ietf-netconf-monitoring/src/main/yang/ietf-netconf-monitoring.yang @@ -9,7 +9,9 @@ module ietf-netconf-monitoring { import ietf-yang-types { prefix yang; + revision-date "2010-09-24"; } + import ietf-inet-types { prefix inet; } diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/mapper/NetconfMdsalMapperModule.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/mapper/NetconfMdsalMapperModule.java index ccf751285a..bf8bdb06f3 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/mapper/NetconfMdsalMapperModule.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/mapper/NetconfMdsalMapperModule.java @@ -26,7 +26,15 @@ public class NetconfMdsalMapperModule extends org.opendaylight.controller.config @Override public java.lang.AutoCloseable createInstance() { - return new MdsalNetconfOperationServiceFactory(getRootSchemaServiceDependency(), getDomBrokerDependency()); + final MdsalNetconfOperationServiceFactory mdsalNetconfOperationServiceFactory = new MdsalNetconfOperationServiceFactory(getRootSchemaServiceDependency(), getDomBrokerDependency()) { + @Override + public void close() throws Exception { + super.close(); + getMapperAggregatorDependency().onRemoveNetconfOperationServiceFactory(this); + } + }; + getMapperAggregatorDependency().onAddNetconfOperationServiceFactory(mdsalNetconfOperationServiceFactory); + return mdsalNetconfOperationServiceFactory; } } diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/CurrentSchemaContext.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/CurrentSchemaContext.java index df671e8f4f..1aa38eb80c 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/CurrentSchemaContext.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/CurrentSchemaContext.java @@ -9,7 +9,12 @@ package org.opendaylight.controller.netconf.mdsal.connector; import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; +import java.util.Collections; +import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -18,6 +23,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; public class CurrentSchemaContext implements SchemaContextListener, AutoCloseable { final AtomicReference currentContext = new AtomicReference(); private final ListenerRegistration schemaContextListenerListenerRegistration; + private final Set listeners = Collections.synchronizedSet(Sets.newHashSet()); public SchemaContext getCurrentContext() { Preconditions.checkState(currentContext.get() != null, "Current context not received"); @@ -31,11 +37,28 @@ public class CurrentSchemaContext implements SchemaContextListener, AutoCloseabl @Override public void onGlobalContextUpdated(final SchemaContext schemaContext) { currentContext.set(schemaContext); + // FIXME is notifying all the listeners from this callback wise ? + final Set addedCaps = MdsalNetconfOperationServiceFactory.transformCapabilities(currentContext.get()); + for (final CapabilityListener listener : listeners) { + listener.onCapabilitiesAdded(addedCaps); + } } @Override public void close() throws Exception { + listeners.clear(); schemaContextListenerListenerRegistration.close(); currentContext.set(null); } + + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + listener.onCapabilitiesAdded(MdsalNetconfOperationServiceFactory.transformCapabilities(currentContext.get())); + listeners.add(listener); + return new AutoCloseable() { + @Override + public void close() throws Exception { + listeners.remove(listener); + } + }; + } } \ No newline at end of file diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java index 9bd71c3c7c..ebb0e9d3d1 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java @@ -49,11 +49,15 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ @Override public Set getCapabilities() { + return transformCapabilities(currentSchemaContext.getCurrentContext()); + } + + static Set transformCapabilities(final SchemaContext currentContext1) { final Set capabilities = new HashSet<>(); // [RFC6241] 8.3. Candidate Configuration Capability capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0")); - final SchemaContext currentContext = currentSchemaContext.getCurrentContext(); + final SchemaContext currentContext = currentContext1; final Set modules = currentContext.getModules(); for (final Module module : modules) { if(currentContext.getModuleSource(module).isPresent()) { @@ -69,13 +73,7 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ @Override public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { - // TODO provide notifications about changed schemas - return new AutoCloseable() { - @Override - public void close() throws Exception { - - } - }; + return currentSchemaContext.registerCapabilityListener(listener); } private static class BasicCapability implements Capability { diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/yang/netconf-mdsal-mapper.yang b/opendaylight/netconf/mdsal-netconf-connector/src/main/yang/netconf-mdsal-mapper.yang index b1d04106d7..9d9966e8f1 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/yang/netconf-mdsal-mapper.yang +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/yang/netconf-mdsal-mapper.yang @@ -44,6 +44,15 @@ module netconf-mdsal-mapper { } } } + + container mapper-aggregator { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity nnm:netconf-mapper-registry; + } + } + } } } diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/pom.xml b/opendaylight/netconf/mdsal-netconf-monitoring/pom.xml new file mode 100644 index 0000000000..3e78dd19e3 --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + org.opendaylight.controller + netconf-subsystem + 0.3.0-SNAPSHOT + + mdsal-netconf-monitoring + bundle + ${project.artifactId} + + + + + ${project.groupId} + netconf-api + + + ${project.groupId} + netconf-mapping-api + + + ${project.groupId} + netconf-monitoring + + + ${project.groupId} + netconf-util + + + org.opendaylight.controller + sal-binding-config + + + + com.google.guava + guava + + + + org.opendaylight.yangtools + mockito-configuration + + + org.opendaylight.yangtools.model + ietf-inet-types + + + org.slf4j + slf4j-api + + + + + + + org.apache.felix + maven-bundle-plugin + + + org.opendaylight.yangtools + yang-maven-plugin + + + config + + generate-sources + + + + + org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + ${jmxGeneratorPath} + + urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang + + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + ${salGeneratorPath} + + + true + + + + + + org.opendaylight.controller + yang-jmx-generator-plugin + ${config.version} + + + + + + + diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/MonitoringToMdsalWriter.java b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/MonitoringToMdsalWriter.java new file mode 100644 index 0000000000..50958e423f --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/MonitoringToMdsalWriter.java @@ -0,0 +1,84 @@ +/* + * 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.controller.config.yang.netconf.mdsal.monitoring; + +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final class MonitoringToMdsalWriter implements AutoCloseable, NetconfMonitoringService.MonitoringListener, BindingAwareProvider { + + private static final Logger LOG = LoggerFactory.getLogger(MonitoringToMdsalWriter.class); + + private final NetconfMonitoringService serverMonitoringDependency; + private DataBroker dataBroker; + + public MonitoringToMdsalWriter(final NetconfMonitoringService serverMonitoringDependency) { + this.serverMonitoringDependency = serverMonitoringDependency; + } + + @Override + public void close() { + final WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + tx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(NetconfState.class)); + final CheckedFuture submit = tx.submit(); + + Futures.addCallback(submit, new FutureCallback() { + @Override + public void onSuccess(final Void aVoid) { + LOG.debug("Netconf state cleared successfully"); + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Unable to clear netconf state", throwable); + } + }); + } + + @Override + public void onStateChanged(final NetconfState state) { + Preconditions.checkState(dataBroker != null); + final WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + tx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(NetconfState.class), state); + // FIXME first attempt (right after we register to binding broker) always fails + // Is it due to the fact that we are writing from the onSessionInitiated callback ? + final CheckedFuture submit = tx.submit(); + + Futures.addCallback(submit, new FutureCallback() { + @Override + public void onSuccess(final Void aVoid) { + LOG.debug("Netconf state updated successfully"); + } + + @Override + public void onFailure(final Throwable throwable) { + LOG.warn("Unable to update netconf state", throwable); + } + }); + } + + @Override + public void onSessionInitiated(final BindingAwareBroker.ProviderContext providerContext) { + dataBroker = providerContext.getSALService(DataBroker.class); + serverMonitoringDependency.registerListener(this); + } +} diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModule.java b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModule.java new file mode 100644 index 0000000000..dadc0f493b --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModule.java @@ -0,0 +1,149 @@ +package org.opendaylight.controller.config.yang.netconf.mdsal.monitoring; + +import com.google.common.base.Optional; +import com.google.common.collect.Sets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.monitoring.GetSchema; +import org.opendaylight.controller.netconf.monitoring.MonitoringConstants; + +public class NetconfMdsalMonitoringMapperModule extends org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.AbstractNetconfMdsalMonitoringMapperModule { + public NetconfMdsalMonitoringMapperModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public NetconfMdsalMonitoringMapperModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.NetconfMdsalMonitoringMapperModule oldModule, final 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 NetconfMonitoringService serverMonitoringDependency = getServerMonitoringDependency(); + + final MonitoringToMdsalWriter monitoringToMdsalWriter = new MonitoringToMdsalWriter(serverMonitoringDependency); + getBindingAwareBrokerDependency().registerProvider(monitoringToMdsalWriter); + + final MdSalMonitoringMapperFactory mdSalMonitoringMapperFactory = new MdSalMonitoringMapperFactory(new MdsalMonitoringMapper(serverMonitoringDependency)) { + @Override + public void close() { + super.close(); + monitoringToMdsalWriter.close(); + getAggregatorDependency().onRemoveNetconfOperationServiceFactory(this); + } + }; + + getAggregatorDependency().onAddNetconfOperationServiceFactory(mdSalMonitoringMapperFactory); + return mdSalMonitoringMapperFactory; + + } + + // FIXME almost exactly same code as in netconf-monitoring, refactor + private static class MdSalMonitoringMapperFactory implements NetconfOperationServiceFactory, AutoCloseable { + + private final NetconfOperationService operationService; + + private static final Set CAPABILITIES = Sets.newHashSet(new Capability() { + + @Override + public String getCapabilityUri() { + return MonitoringConstants.URI; + } + + @Override + public Optional getModuleNamespace() { + return Optional.of(MonitoringConstants.NAMESPACE); + } + + @Override + public Optional getModuleName() { + return Optional.of(MonitoringConstants.MODULE_NAME); + } + + @Override + public Optional getRevision() { + return Optional.of(MonitoringConstants.MODULE_REVISION); + } + + @Override + public Optional getCapabilitySchema() { + return Optional.absent(); + } + + @Override + public Collection getLocation() { + return Collections.emptyList(); + } + }); + + private static final AutoCloseable AUTO_CLOSEABLE = new AutoCloseable() { + @Override + public void close() throws Exception { + // NOOP + } + }; + + private final List listeners = new ArrayList<>(); + + public MdSalMonitoringMapperFactory(final NetconfOperationService operationService) { + this.operationService = operationService; + } + + @Override + public NetconfOperationService createService(final String netconfSessionIdForReporting) { + return operationService; + } + + @Override + public Set getCapabilities() { + return CAPABILITIES; + } + + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + listener.onCapabilitiesAdded(getCapabilities()); + listeners.add(listener); + return AUTO_CLOSEABLE; + } + + @Override + public void close() { + for (final CapabilityListener listener : listeners) { + listener.onCapabilitiesRemoved(getCapabilities()); + } + } + } + + + private static class MdsalMonitoringMapper implements NetconfOperationService { + + private final NetconfMonitoringService serverMonitoringDependency; + + public MdsalMonitoringMapper(final NetconfMonitoringService serverMonitoringDependency) { + this.serverMonitoringDependency = serverMonitoringDependency; + } + + @Override + public Set getNetconfOperations() { + return Collections.singleton(new GetSchema(serverMonitoringDependency)); + } + + @Override + public void close() { + // NOOP + } + } +} diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModuleFactory.java b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModuleFactory.java new file mode 100644 index 0000000000..e0d459318f --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/NetconfMdsalMonitoringMapperModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: netconf-mdsal-monitoring yang module local name: netconf-mdsal-monitoring-mapper +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Wed Feb 18 10:22:17 CET 2015 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.netconf.mdsal.monitoring; +public class NetconfMdsalMonitoringMapperModuleFactory extends org.opendaylight.controller.config.yang.netconf.mdsal.monitoring.AbstractNetconfMdsalMonitoringMapperModuleFactory { + +} diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationService.java b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationService.java new file mode 100644 index 0000000000..9ae4df429c --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationService.java @@ -0,0 +1,35 @@ +/* +* Copyright (c) 2013 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.controller.netconf.monitoring; + +import com.google.common.collect.Sets; +import java.util.Set; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; +import org.opendaylight.controller.netconf.monitoring.Get; +import org.opendaylight.controller.netconf.monitoring.GetSchema; + +public class NetconfMonitoringOperationService implements NetconfOperationService { + + private final NetconfMonitoringService monitor; + + public NetconfMonitoringOperationService(final NetconfMonitoringService monitor) { + this.monitor = monitor; + } + + @Override + public Set getNetconfOperations() { + return Sets.newHashSet(new Get(monitor), new GetSchema(monitor)); + } + + @Override + public void close() { + } + +} diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationServiceFactory.java b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationServiceFactory.java new file mode 100644 index 0000000000..78c23688e4 --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/NetconfMonitoringOperationServiceFactory.java @@ -0,0 +1,99 @@ +/* + * 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.controller.netconf.monitoring; + +import com.google.common.base.Optional; +import com.google.common.collect.Sets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import org.opendaylight.controller.netconf.api.Capability; +import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; + +/** +* Created by mmarsale on 18.2.2015. +*/ +public class NetconfMonitoringOperationServiceFactory implements NetconfOperationServiceFactory, AutoCloseable { + + private final NetconfMonitoringOperationService operationService; + + private static final Set CAPABILITIES = Sets.newHashSet(new Capability() { + + @Override + public String getCapabilityUri() { + return MonitoringConstants.URI; + } + + @Override + public Optional getModuleNamespace() { + return Optional.of(MonitoringConstants.NAMESPACE); + } + + @Override + public Optional getModuleName() { + return Optional.of(MonitoringConstants.MODULE_NAME); + } + + @Override + public Optional getRevision() { + return Optional.of(MonitoringConstants.MODULE_REVISION); + } + + @Override + public Optional getCapabilitySchema() { + return Optional.absent(); + } + + @Override + public Collection getLocation() { + return Collections.emptyList(); + } + }); + + private static final AutoCloseable AUTO_CLOSEABLE = new AutoCloseable() { + @Override + public void close() throws Exception { + // NOOP + } + }; + + private final List listeners = new ArrayList<>(); + + public NetconfMonitoringOperationServiceFactory(final NetconfMonitoringOperationService operationService) { + this.operationService = operationService; + } + + @Override + public NetconfOperationService createService(final String netconfSessionIdForReporting) { + return operationService; + } + + @Override + public Set getCapabilities() { + return CAPABILITIES; + } + + @Override + public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { + listener.onCapabilitiesAdded(getCapabilities()); + listeners.add(listener); + return AUTO_CLOSEABLE; + } + + @Override + public void close() { + for (final CapabilityListener listener : listeners) { + listener.onCapabilitiesRemoved(getCapabilities()); + } + } +} diff --git a/opendaylight/netconf/mdsal-netconf-monitoring/src/main/yang/netconf-mdsal-monitoring.yang b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/yang/netconf-mdsal-monitoring.yang new file mode 100644 index 0000000000..68a248e48e --- /dev/null +++ b/opendaylight/netconf/mdsal-netconf-monitoring/src/main/yang/netconf-mdsal-monitoring.yang @@ -0,0 +1,60 @@ +module netconf-mdsal-monitoring { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:monitoring"; + prefix "nmmonitor"; + + import netconf-northbound-mapper { prefix nnm; revision-date 2015-01-14; } + import opendaylight-md-sal-binding {prefix md-sal-binding; revision-date 2013-10-28;} + import netconf-northbound { prefix nn; revision-date 2015-01-14; } + import config { prefix config; revision-date 2013-04-05; } + + organization "Cisco Systems, Inc."; + + description + "This module contains the base YANG definitions for + an MD-SAL monitoring mapper implementation"; + + revision "2015-02-18" { + description + "Initial revision."; + } + + identity netconf-mdsal-monitoring-mapper { + base config:module-type; + config:provided-service nnm:netconf-northbound-mapper; + } + + augment "/config:modules/config:module/config:configuration" { + case netconf-mdsal-monitoring-mapper { + when "/config:modules/config:module/config:type = 'netconf-mdsal-monitoring-mapper'"; + + container server-monitoring { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity nn:netconf-server-monitoring; + } + } + } + + container aggregator { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity nnm:netconf-mapper-registry; + } + } + } + + container binding-aware-broker { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity md-sal-binding:binding-broker-osgi-registry; + } + } + } + } + } + +} diff --git a/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/NetconfMonitoringService.java b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/NetconfMonitoringService.java index 3f0e1a1aa5..d22412c7cf 100644 --- a/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/NetconfMonitoringService.java +++ b/opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/monitoring/NetconfMonitoringService.java @@ -8,7 +8,8 @@ package org.opendaylight.controller.netconf.api.monitoring; import com.google.common.base.Optional; -import java.util.Set; +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.monitoring.rev101004.netconf.state.Schemas; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions; @@ -20,6 +21,16 @@ public interface NetconfMonitoringService extends CapabilityListener, SessionLis String getSchemaForCapability(String moduleName, Optional revision); - Set getCapabilities(); + Capabilities getCapabilities(); + /** + * Allows push based state information transfer. After the listener is registered, current state is pushed to the listener. + */ + AutoCloseable registerListener(MonitoringListener listener); + + interface MonitoringListener { + + // TODO more granular updates would make sense + void onStateChanged(NetconfState state); + } } diff --git a/opendaylight/netconf/netconf-artifacts/pom.xml b/opendaylight/netconf/netconf-artifacts/pom.xml index 1248933915..d27ea55812 100644 --- a/opendaylight/netconf/netconf-artifacts/pom.xml +++ b/opendaylight/netconf/netconf-artifacts/pom.xml @@ -87,6 +87,11 @@ netconf-monitoring ${project.version} + + ${project.groupId} + mdsal-netconf-monitoring + ${project.version} + ${project.groupId} netconf-netty-util diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModule.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModule.java new file mode 100644 index 0000000000..284c600f0c --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModule.java @@ -0,0 +1,22 @@ +package org.opendaylight.controller.config.yang.config.netconf.northbound.impl; + +import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; + +public class NetconfMapperAggregatorModule extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfMapperAggregatorModule { + public NetconfMapperAggregatorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public NetconfMapperAggregatorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.controller.config.yang.config.netconf.northbound.impl.NetconfMapperAggregatorModule oldModule, final java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() {} + + @Override + public java.lang.AutoCloseable createInstance() { + return new AggregatedNetconfOperationServiceFactory(); + } + +} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModuleFactory.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModuleFactory.java new file mode 100644 index 0000000000..0e415bdfcb --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfMapperAggregatorModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: netconf-northbound-impl yang module local name: netconf-mapper-aggregator +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Tue Feb 17 17:24:19 CET 2015 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.config.netconf.northbound.impl; +public class NetconfMapperAggregatorModuleFactory extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfMapperAggregatorModuleFactory { + +} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerDispatcherModule.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerDispatcherModule.java index c1570f4311..3c476608a2 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerDispatcherModule.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerDispatcherModule.java @@ -7,7 +7,6 @@ import org.opendaylight.controller.netconf.impl.NetconfServerDispatcherImpl; import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory; import org.opendaylight.controller.netconf.impl.SessionIdProvider; import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; -import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; public class NetconfServerDispatcherModule extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfServerDispatcherModule { @@ -28,7 +27,7 @@ public class NetconfServerDispatcherModule extends org.opendaylight.controller.c public java.lang.AutoCloseable createInstance() { final AggregatedNetconfOperationServiceFactory aggregatedOpProvider = getAggregatedOpProvider(); - final NetconfMonitoringService monitoringService = startMonitoringService(aggregatedOpProvider); + final NetconfMonitoringService monitoringService = getServerMonitorDependency(); final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( getTimerDependency(), aggregatedOpProvider, new SessionIdProvider(), getConnectionTimeoutMillis(), CommitNotifier.NoopCommitNotifier.getInstance(), monitoringService); final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( @@ -44,10 +43,6 @@ public class NetconfServerDispatcherModule extends org.opendaylight.controller.c } - private NetconfMonitoringServiceImpl startMonitoringService(final AggregatedNetconfOperationServiceFactory netconfOperationProvider) { - return new NetconfMonitoringServiceImpl(netconfOperationProvider); - } - private AggregatedNetconfOperationServiceFactory getAggregatedOpProvider() { final AggregatedNetconfOperationServiceFactory netconfOperationProvider = new AggregatedNetconfOperationServiceFactory(); for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getMappersDependency()) { diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModule.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModule.java new file mode 100644 index 0000000000..dc18cd3687 --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModule.java @@ -0,0 +1,24 @@ +package org.opendaylight.controller.config.yang.config.netconf.northbound.impl; + +import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; + +public class NetconfServerMonitoringModule extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfServerMonitoringModule { + public NetconfServerMonitoringModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public NetconfServerMonitoringModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.netconf.northbound.impl.NetconfServerMonitoringModule 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() { + return new NetconfMonitoringServiceImpl(getAggregatorDependency()); + } + +} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModuleFactory.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModuleFactory.java new file mode 100644 index 0000000000..fe74486a77 --- /dev/null +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/config/yang/config/netconf/northbound/impl/NetconfServerMonitoringModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: netconf-northbound-impl yang module local name: netconf-server-monitoring-impl +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Tue Feb 17 17:24:19 CET 2015 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.config.netconf.northbound.impl; +public class NetconfServerMonitoringModuleFactory extends org.opendaylight.controller.config.yang.config.netconf.northbound.impl.AbstractNetconfServerMonitoringModuleFactory { + +} diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSession.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSession.java index 8f2c39df06..0cf2dbc281 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSession.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSession.java @@ -55,9 +55,9 @@ public final class NetconfServerSession extends AbstractNetconfSession transformCapabilities(final Capabilities capabilities) { + return Sets.newHashSet(Collections2.transform(capabilities.getCapability(), new Function() { + @Override + public String apply(final Uri uri) { + return uri.getValue(); + } + })); + } + @Override protected Element handle(Document document, XmlElement message, NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException { throw new UnsupportedOperationException("Never gets called"); diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java index c299ac7d1a..ae68ecc120 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/AggregatedNetconfOperationServiceFactory.java @@ -22,12 +22,13 @@ import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.netconf.mapping.api.NetconfOperation; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener; import org.opendaylight.controller.netconf.util.CloseableUtil; /** * NetconfOperationService aggregator. Makes a collection of operation services accessible as one. */ -public class AggregatedNetconfOperationServiceFactory implements NetconfOperationServiceFactory, NetconfOperationServiceFactoryListener { +public class AggregatedNetconfOperationServiceFactory implements NetconfOperationServiceFactory, NetconfOperationServiceFactoryListener, AutoCloseable { private final Set factories = new HashSet<>(); private final Multimap registrations = HashMultimap.create(); @@ -96,6 +97,16 @@ public class AggregatedNetconfOperationServiceFactory implements NetconfOperatio return new AggregatedNetconfOperation(factories, netconfSessionIdForReporting); } + @Override + public synchronized void close() throws Exception { + factories.clear(); + for (AutoCloseable reg : registrations.values()) { + reg.close(); + } + registrations.clear(); + listeners.clear(); + } + private static final class AggregatedNetconfOperation implements NetconfOperationService { private final Set services; diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java index 63e837fc18..1e35597d9a 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java @@ -19,6 +19,7 @@ import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProduce import org.opendaylight.controller.netconf.impl.NetconfServerDispatcherImpl; import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory; import org.opendaylight.controller.netconf.impl.SessionIdProvider; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener; import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfMonitoringServiceImpl.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfMonitoringServiceImpl.java index 8e5c1a7da3..b02137b748 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfMonitoringServiceImpl.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfMonitoringServiceImpl.java @@ -13,7 +13,9 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import io.netty.util.internal.ConcurrentSet; import java.util.ArrayList; import java.util.Collection; @@ -27,7 +29,11 @@ import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSessi import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.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.NetconfStateBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Yang; +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.monitoring.rev101004.netconf.state.CapabilitiesBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions; @@ -39,7 +45,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.mon import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class NetconfMonitoringServiceImpl implements NetconfMonitoringService { +public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, AutoCloseable { private static final Schema.Location NETCONF_LOCATION = new Schema.Location(Schema.Location.Enumeration.NETCONF); private static final List NETCONF_LOCATIONS = ImmutableList.of(NETCONF_LOCATION); @@ -50,18 +56,18 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService { return input.toManagementSession(); } }; - - private final Set sessions = new ConcurrentSet<>(); - private final NetconfOperationServiceFactory netconfOperationProvider; - private final Map capabilities = new ConcurrentHashMap<>(); - private static final Function CAPABILITY_TO_URI = new Function() { + private static final Function CAPABILITY_TO_URI = new Function() { @Override - public String apply(final Capability input) { - return input.getCapabilityUri(); + public Uri apply(final Capability input) { + return new Uri(input.getCapabilityUri()); } }; - // FIXME check threadsafety + private final Set sessions = new ConcurrentSet<>(); + private final NetconfOperationServiceFactory netconfOperationProvider; + private final Map capabilities = new ConcurrentHashMap<>(); + + private final Set listeners = Sets.newHashSet(); public NetconfMonitoringServiceImpl(final NetconfOperationServiceFactory netconfOperationProvider) { this.netconfOperationProvider = netconfOperationProvider; @@ -69,26 +75,28 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService { } @Override - public void onSessionUp(final NetconfManagementSession session) { + public synchronized void onSessionUp(final NetconfManagementSession session) { LOG.debug("Session {} up", session); Preconditions.checkState(!sessions.contains(session), "Session %s was already added", session); sessions.add(session); + notifyListeners(); } @Override - public void onSessionDown(final NetconfManagementSession session) { + public synchronized void onSessionDown(final NetconfManagementSession session) { LOG.debug("Session {} down", session); Preconditions.checkState(sessions.contains(session), "Session %s not present", session); sessions.remove(session); + notifyListeners(); } @Override - public Sessions getSessions() { + public synchronized Sessions getSessions() { return new SessionsBuilder().setSession(ImmutableList.copyOf(Collections2.transform(sessions, SESSION_FUNCTION))).build(); } @Override - public Schemas getSchemas() { + public synchronized Schemas getSchemas() { try { return transformSchemas(netconfOperationProvider.getCapabilities()); } catch (final RuntimeException e) { @@ -99,7 +107,7 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService { } @Override - public String getSchemaForCapability(final String moduleName, final Optional revision) { + public synchronized String getSchemaForCapability(final String moduleName, final Optional revision) { // FIXME not effective at all @@ -146,8 +154,28 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService { } @Override - public Set getCapabilities() { - return capabilities.keySet(); + public synchronized Capabilities getCapabilities() { + return new CapabilitiesBuilder().setCapability(Lists.newArrayList(capabilities.keySet())).build(); + } + + @Override + public synchronized AutoCloseable registerListener(final MonitoringListener listener) { + listeners.add(listener); + listener.onStateChanged(getCurrentNetconfState()); + return new AutoCloseable() { + @Override + public void close() throws Exception { + listeners.remove(listener); + } + }; + } + + private NetconfState getCurrentNetconfState() { + return new NetconfStateBuilder() + .setCapabilities(getCapabilities()) + .setSchemas(getSchemas()) + .setSessions(getSessions()) + .build(); } private static Schemas transformSchemas(final Set caps) { @@ -195,15 +223,30 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService { } @Override - public void onCapabilitiesAdded(final Set addedCaps) { - // FIXME what check for duplicates + public synchronized void onCapabilitiesAdded(final Set addedCaps) { + // FIXME howto check for duplicates this.capabilities.putAll(Maps.uniqueIndex(addedCaps, CAPABILITY_TO_URI)); + notifyListeners(); + } + + private void notifyListeners() { + for (final MonitoringListener listener : listeners) { + listener.onStateChanged(getCurrentNetconfState()); + } } @Override - public void onCapabilitiesRemoved(final Set addedCaps) { + public synchronized void onCapabilitiesRemoved(final Set addedCaps) { for (final Capability addedCap : addedCaps) { capabilities.remove(addedCap.getCapabilityUri()); } + notifyListeners(); + } + + @Override + public synchronized void close() throws Exception { + listeners.clear(); + sessions.clear(); + capabilities.clear(); } } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java index fb5a2b325e..9d58bd911c 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java @@ -143,8 +143,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { if (!handlingPriority.equals(HandlingPriority.CANNOT_HANDLE)) { Preconditions.checkState(!sortedPriority.containsKey(handlingPriority), - "Multiple %s available to handle message %s with priority %s", - NetconfOperation.class.getName(), message, handlingPriority); + "Multiple %s available to handle message %s with priority %s, %s and %s", + NetconfOperation.class.getName(), message, handlingPriority, netconfOperation, sortedPriority.get(handlingPriority)); sortedPriority.put(handlingPriority, netconfOperation); } } diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java index 9a077a6130..d97ac90922 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.netconf.impl.osgi; import org.opendaylight.controller.netconf.api.util.NetconfConstants; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.util.tracker.ServiceTracker; @@ -40,8 +41,9 @@ class NetconfOperationServiceFactoryTracker extends @Override public void removedService(ServiceReference reference, NetconfOperationServiceFactory netconfOperationServiceFactory) { - if (netconfOperationServiceFactory != null) + if (netconfOperationServiceFactory != null) { factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory); + } } } diff --git a/opendaylight/netconf/netconf-impl/src/main/yang/netconf-northbound-impl.yang b/opendaylight/netconf/netconf-impl/src/main/yang/netconf-northbound-impl.yang index 6ca0a7781c..7ad1fef55d 100644 --- a/opendaylight/netconf/netconf-impl/src/main/yang/netconf-northbound-impl.yang +++ b/opendaylight/netconf/netconf-impl/src/main/yang/netconf-northbound-impl.yang @@ -67,6 +67,15 @@ module netconf-northbound-impl { } } + container server-monitor { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity nn:netconf-server-monitoring; + } + } + } + container timer { uses config:service-ref { refine type { @@ -77,4 +86,43 @@ module netconf-northbound-impl { } } + + identity netconf-server-monitoring-impl { + base config:module-type; + config:provided-service nn:netconf-server-monitoring; + config:java-name-prefix NetconfServerMonitoring; + } + + // TODO Monitoring could expose the monitoring data over JMX... + + augment "/config:modules/config:module/config:configuration" { + case netconf-server-monitoring-impl { + when "/config:modules/config:module/config:type = 'netconf-server-monitoring-impl'"; + + container aggregator { + uses config:service-ref { + refine type { + config:required-identity nnm:netconf-northbound-mapper; + } + } + } + + } + } + + identity netconf-mapper-aggregator { + base config:module-type; + config:provided-service nnm:netconf-northbound-mapper; + config:provided-service nnm:netconf-mapper-registry; + config:java-name-prefix NetconfMapperAggregator; + description "Aggregated operation provider for netconf servers. Joins all the operations and capabilities of all the mappers it aggregates and exposes them as a single service. The dependency orientation is reversed in order to prevent cyclic dependencies when monitoring service is considered"; + } + + augment "/config:modules/config:module/config:configuration" { + case netconf-mapper-aggregator { + when "/config:modules/config:module/config:type = 'netconf-mapper-aggregator'"; + + } + } + } \ No newline at end of file diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java index 36dfb6f31b..512a127d22 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java @@ -12,6 +12,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anySetOf; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -73,6 +74,8 @@ import org.opendaylight.controller.netconf.util.messages.NetconfMessageUtil; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.opendaylight.protocol.framework.NeverReconnectStrategy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.CapabilitiesBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -121,7 +124,15 @@ public class ConcurrentClientsTest { NetconfMonitoringService monitoring = mock(NetconfMonitoringService.class); doNothing().when(monitoring).onSessionUp(any(NetconfServerSession.class)); doNothing().when(monitoring).onSessionDown(any(NetconfServerSession.class)); - doReturn(Collections.emptySet()).when(monitoring).getCapabilities(); + doReturn(new AutoCloseable() { + @Override + public void close() throws Exception { + + } + }).when(monitoring).registerListener(any(NetconfMonitoringService.MonitoringListener.class)); + doNothing().when(monitoring).onCapabilitiesAdded(anySetOf(Capability.class)); + doNothing().when(monitoring).onCapabilitiesRemoved(anySetOf(Capability.class)); + doReturn(new CapabilitiesBuilder().setCapability(Collections.emptyList()).build()).when(monitoring).getCapabilities(); return monitoring; } diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java index aa8c0a0f60..0c7406543f 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommitTest.java @@ -18,7 +18,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import com.google.common.collect.Sets; +import java.util.Collections; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; @@ -29,6 +29,8 @@ import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.CapabilitiesBuilder; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -50,7 +52,7 @@ public class DefaultCommitTest { notifier = mock(DefaultCommitNotificationProducer.class); doNothing().when(notifier).sendCommitNotification(anyString(), any(Element.class), anySetOf(String.class)); cap = mock(NetconfMonitoringService.class); - doReturn(Sets.newHashSet()).when(cap).getCapabilities(); + doReturn(new CapabilitiesBuilder().setCapability(Collections.emptyList()).build()).when(cap).getCapabilities(); Document rpcData = XmlFileLoader.xmlFileToDocument("netconfMessages/editConfig_expectedResult.xml"); doReturn(rpcData).when(router).onNetconfMessage(any(Document.class), any(NetconfServerSession.class)); commit = new DefaultCommit(notifier, cap, "", router); diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java index 8cb569eaa2..c75cdcd27a 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java @@ -22,6 +22,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.opendaylight.controller.netconf.api.util.NetconfConstants; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener; import org.osgi.framework.BundleContext; import org.osgi.framework.Filter; import org.osgi.framework.ServiceReference; diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java index 379c23af3c..c421a46fdf 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java @@ -80,8 +80,8 @@ public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest { } notificationVerifier.assertNotificationCount(2); - notificationVerifier.assertNotificationContent(0, 0, 0, 9); - notificationVerifier.assertNotificationContent(1, 4, 3, 9); + notificationVerifier.assertNotificationContent(0, 0, 0, 8); + notificationVerifier.assertNotificationContent(1, 4, 3, 8); mockedAggregator.assertSnapshotCount(2); // Capabilities are stripped for persister diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListener.java b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceFactoryListener.java similarity index 79% rename from opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListener.java rename to opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceFactoryListener.java index 8e1052cfeb..30a4f9bf82 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListener.java +++ b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceFactoryListener.java @@ -6,9 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.netconf.impl.osgi; - -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +package org.opendaylight.controller.netconf.mapping.api; public interface NetconfOperationServiceFactoryListener { diff --git a/opendaylight/netconf/netconf-mapping-api/src/main/yang/netconf-northbound-mapper.yang b/opendaylight/netconf/netconf-mapping-api/src/main/yang/netconf-northbound-mapper.yang index a709665c63..3ffecde700 100644 --- a/opendaylight/netconf/netconf-mapping-api/src/main/yang/netconf-northbound-mapper.yang +++ b/opendaylight/netconf/netconf-mapping-api/src/main/yang/netconf-northbound-mapper.yang @@ -19,4 +19,9 @@ module netconf-northbound-mapper { config:java-class "org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory"; } + identity netconf-mapper-registry { + base "config:service-type"; + config:java-class "org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactoryListener"; + } + } \ No newline at end of file diff --git a/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml b/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml index 042447b1e6..4ca3c99e81 100644 --- a/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml +++ b/opendaylight/netconf/netconf-mdsal-config/src/main/resources/initial/08-netconf-mdsal.xml @@ -25,6 +25,10 @@ dom:dom-async-data-broker inmemory-data-broker + + prefix:netconf-mapper-registry + mapper-aggregator-registry + @@ -32,8 +36,12 @@ netconf-mdsal-server-dispatcher dom:netconf-northbound-mapper - netconf-mdsal-mapper + mapper-aggregator + + prefix:netconf-server-monitoring + server-monitor + prefix:netty-threadgroup global-boss-group @@ -48,6 +56,37 @@ + + prefix:netconf-mdsal-monitoring-mapper + netconf-mdsal-monitoring-mapper + + prefix:netconf-server-monitoring + server-monitor + + + prefix:binding-broker-osgi-registry + binding-osgi-broker + + + prefix:netconf-mapper-registry + mapper-aggregator-registry + + + + + prefix:netconf-mapper-aggregator + mapper-aggregator + + + + prefix:netconf-server-monitoring-impl + server-monitor + + dom:netconf-northbound-mapper + mapper-aggregator + + + prefix:netconf-northbound-ssh netconf-mdsal-ssh-server @@ -76,6 +115,13 @@ + + prefix:netconf-server-monitoring + + server-monitor + /modules/module[type='netconf-server-monitoring-impl'][name='server-monitor'] + + prefix:netconf-northbound-mapper @@ -83,6 +129,20 @@ /modules/module[type='netconf-mdsal-mapper'][name='netconf-mdsal-mapper'] + + prefix:netconf-northbound-mapper + + mapper-aggregator + /modules/module[type='netconf-mapper-aggregator'][name='mapper-aggregator'] + + + + prefix:netconf-mapper-registry + + mapper-aggregator-registry + /modules/module[type='netconf-mapper-aggregator'][name='mapper-aggregator'] + + prefix:netconf-server-dispatcher @@ -96,6 +156,7 @@ urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:mapper?module=netconf-mdsal-mapper&revision=2015-01-14 + urn:opendaylight:params:xml:ns:yang:controller:netconf:mdsal:monitoring?module=netconf-mdsal-monitoring&revision=2015-02-18 urn:opendaylight:params:xml:ns:yang:controller:netconf:northbound:ssh?module=netconf-northbound-ssh&revision=2015-01-14 urn:opendaylight:params:xml:ns:yang:controller:config:netconf:northbound:impl?module=netconf-northbound-impl&revision=2015-01-12 urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl:scheduled?module=threadpool-impl-scheduled&revision=2013-12-01 diff --git a/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivator.java b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivator.java index 1b0a50b830..1f094f1caf 100644 --- a/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivator.java +++ b/opendaylight/netconf/netconf-monitoring/src/main/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringActivator.java @@ -7,18 +7,12 @@ */ package org.opendaylight.controller.netconf.monitoring.osgi; -import com.google.common.base.Optional; -import com.google.common.collect.Sets; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.Set; import org.opendaylight.controller.netconf.api.Capability; import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; -import org.opendaylight.controller.netconf.monitoring.MonitoringConstants; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.slf4j.Logger; @@ -51,39 +45,6 @@ public class NetconfMonitoringActivator implements BundleActivator { private final NetconfMonitoringOperationService operationService; - private static final Set CAPABILITIES = Sets.newHashSet(new Capability() { - - @Override - public String getCapabilityUri() { - return MonitoringConstants.URI; - } - - @Override - public Optional getModuleNamespace() { - return Optional.of(MonitoringConstants.NAMESPACE); - } - - @Override - public Optional getModuleName() { - return Optional.of(MonitoringConstants.MODULE_NAME); - } - - @Override - public Optional getRevision() { - return Optional.of(MonitoringConstants.MODULE_REVISION); - } - - @Override - public Optional getCapabilitySchema() { - return Optional.absent(); - } - - @Override - public Collection getLocation() { - return Collections.emptyList(); - } - }); - private static final AutoCloseable AUTO_CLOSEABLE = new AutoCloseable() { @Override public void close() throws Exception { @@ -91,8 +52,6 @@ public class NetconfMonitoringActivator implements BundleActivator { } }; - private final List listeners = new ArrayList<>(); - public NetconfMonitoringOperationServiceFactory(final NetconfMonitoringOperationService operationService) { this.operationService = operationService; } @@ -104,21 +63,15 @@ public class NetconfMonitoringActivator implements BundleActivator { @Override public Set getCapabilities() { - return CAPABILITIES; + return Collections.emptySet(); } @Override public AutoCloseable registerCapabilityListener(final CapabilityListener listener) { - listener.onCapabilitiesAdded(getCapabilities()); - listeners.add(listener); return AUTO_CLOSEABLE; } @Override - public void close() { - for (final CapabilityListener listener : listeners) { - listener.onCapabilitiesRemoved(getCapabilities()); - } - } + public void close() {} } } diff --git a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java index 3a0362277e..67a54366cd 100644 --- a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java +++ b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/osgi/NetconfMonitoringOperationServiceTest.java @@ -11,11 +11,8 @@ package org.opendaylight.controller.netconf.monitoring.osgi; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; -import com.google.common.base.Optional; -import java.util.Collections; import org.junit.Test; import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; -import org.opendaylight.controller.netconf.monitoring.MonitoringConstants; public class NetconfMonitoringOperationServiceTest { @Test @@ -26,11 +23,5 @@ public class NetconfMonitoringOperationServiceTest { assertEquals(2, service.getNetconfOperations().size()); - assertEquals(Optional.absent(), serviceFactory.getCapabilities().iterator().next().getCapabilitySchema()); - assertEquals(Collections.emptyList(), serviceFactory.getCapabilities().iterator().next().getLocation()); - assertEquals(Optional.of(MonitoringConstants.MODULE_REVISION), serviceFactory.getCapabilities().iterator().next().getRevision()); - assertEquals(Optional.of(MonitoringConstants.MODULE_NAME), serviceFactory.getCapabilities().iterator().next().getModuleName()); - assertEquals(Optional.of(MonitoringConstants.NAMESPACE), serviceFactory.getCapabilities().iterator().next().getModuleNamespace()); - assertEquals(MonitoringConstants.URI, serviceFactory.getCapabilities().iterator().next().getCapabilityUri()); } } diff --git a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java index b81d2c144f..a8236b2ebc 100644 --- a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java +++ b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java @@ -29,6 +29,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.mon import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfSsh; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Transport; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Yang; +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.monitoring.rev101004.netconf.state.Schemas; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions; @@ -82,9 +83,19 @@ public class JaxBSerializerTest { } @Override - public Set getCapabilities() { + public Capabilities getCapabilities() { return null; } + + @Override + public AutoCloseable registerListener(final MonitoringListener listener) { + return new AutoCloseable() { + @Override + public void close() throws Exception { + // NOOP + } + }; + } }; final NetconfState model = new NetconfState(service); final String xml = XmlUtil.toString(new JaxBSerializer().toXml(model)).replaceAll("\\s", ""); diff --git a/opendaylight/netconf/pom.xml b/opendaylight/netconf/pom.xml index 4566845e4f..a990b5c6cb 100644 --- a/opendaylight/netconf/pom.xml +++ b/opendaylight/netconf/pom.xml @@ -21,6 +21,7 @@ netconf-impl config-netconf-connector mdsal-netconf-connector + mdsal-netconf-monitoring netconf-util netconf-netty-util config-persister-impl