From: Tom Pantelis Date: Wed, 23 Jan 2019 02:13:37 +0000 (+0000) Subject: Merge "Do not start netconf-impl for css netconf endpoint" X-Git-Tag: release/neon~14 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=00556a5df20d2b29067935f642262bc8e5a7f395;hp=c041eb2ba3038d7f692afaf213a8f1a10633bec7;p=netconf.git Merge "Do not start netconf-impl for css netconf endpoint" --- diff --git a/netconf/netconf-impl/pom.xml b/netconf/netconf-impl/pom.xml index d90d3d9018..2ebd6713b8 100644 --- a/netconf/netconf-impl/pom.xml +++ b/netconf/netconf-impl/pom.xml @@ -109,14 +109,6 @@ xmlunit-legacy test - - org.osgi - org.osgi.compendium - - - org.osgi - org.osgi.core - @@ -126,7 +118,6 @@ maven-bundle-plugin - org.opendaylight.netconf.impl.osgi.NetconfImplActivator org.opendaylight.netconf.impl.* diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfImplActivator.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfImplActivator.java deleted file mode 100644 index 8529da681d..0000000000 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfImplActivator.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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.netconf.impl.osgi; - -import com.google.common.base.Preconditions; -import io.netty.channel.local.LocalAddress; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.util.HashedWheelTimer; -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.concurrent.TimeUnit; -import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService; -import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl; -import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl.ServerChannelInitializer; -import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory; -import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactoryBuilder; -import org.opendaylight.netconf.impl.SessionIdProvider; -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener; -import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration; -import org.opendaylight.netconf.notifications.NetconfNotificationCollector; -import org.opendaylight.netconf.util.NetconfConfiguration; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -import org.osgi.util.tracker.ServiceTracker; -import org.osgi.util.tracker.ServiceTrackerCustomizer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class NetconfImplActivator implements BundleActivator { - - private static final Logger LOG = LoggerFactory.getLogger(NetconfImplActivator.class); - - private NetconfOperationServiceFactoryTracker factoriesTracker; - private NioEventLoopGroup eventLoopGroup; - private HashedWheelTimer timer; - private ServiceRegistration regMonitoring; - - private BaseNotificationPublisherRegistration listenerReg; - - @SuppressWarnings("checkstyle:IllegalCatch") - @Override - public void start(final BundleContext context) { - try { - AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); - startOperationServiceFactoryTracker(context, factoriesListener); - - SessionIdProvider idProvider = new SessionIdProvider(); - timer = new HashedWheelTimer(); - - long connectionTimeoutMillis = NetconfConfiguration.DEFAULT_TIMEOUT_MILLIS; - - final NetconfMonitoringServiceImpl monitoringService = startMonitoringService(context, factoriesListener); - - NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = - new NetconfServerSessionNegotiatorFactoryBuilder() - .setAggregatedOpService(factoriesListener) - .setTimer(timer) - .setIdProvider(idProvider) - .setMonitoringService(monitoringService) - .setConnectionTimeoutMillis(connectionTimeoutMillis) - .build(); - - eventLoopGroup = new NioEventLoopGroup(); - - ServerChannelInitializer serverChannelInitializer = new ServerChannelInitializer( - serverNegotiatorFactory); - NetconfServerDispatcherImpl dispatch = new NetconfServerDispatcherImpl(serverChannelInitializer, - eventLoopGroup, eventLoopGroup); - - LocalAddress address = NetconfConfiguration.NETCONF_LOCAL_ADDRESS; - LOG.trace("Starting local netconf server at {}", address); - dispatch.createLocalServer(address); - - final ServiceTracker - notificationServiceTracker = new ServiceTracker<>(context, NetconfNotificationCollector.class, - new ServiceTrackerCustomizer() { - @Override - public NetconfNotificationCollector addingService(ServiceReference< - NetconfNotificationCollector> reference) { - Preconditions.checkState(listenerReg == null, - "Notification collector service was already added"); - listenerReg = context.getService(reference).registerBaseNotificationPublisher(); - monitoringService.setNotificationPublisher(listenerReg); - return null; - } - - @Override - public void modifiedService(ServiceReference reference, - NetconfNotificationCollector service) { - - } - - @Override - public void removedService(ServiceReference reference, - NetconfNotificationCollector service) { - listenerReg.close(); - listenerReg = null; - monitoringService.setNotificationPublisher(listenerReg); - } - }); - notificationServiceTracker.open(); - } catch (Exception e) { - LOG.warn("Unable to start NetconfImplActivator", e); - } - } - - private void startOperationServiceFactoryTracker(BundleContext context, - NetconfOperationServiceFactoryListener factoriesListener) { - factoriesTracker = new NetconfOperationServiceFactoryTracker(context, factoriesListener); - factoriesTracker.open(); - } - - private NetconfMonitoringServiceImpl startMonitoringService( - BundleContext context, - AggregatedNetconfOperationServiceFactory factoriesListener) { - NetconfMonitoringServiceImpl netconfMonitoringServiceImpl = new NetconfMonitoringServiceImpl(factoriesListener); - Dictionary dic = new Hashtable<>(); - regMonitoring = context.registerService(NetconfMonitoringService.class, netconfMonitoringServiceImpl, dic); - - return netconfMonitoringServiceImpl; - } - - @Override - public void stop(final BundleContext context) { - LOG.info("Shutting down netconf because YangStoreService service was removed"); - - eventLoopGroup.shutdownGracefully(0, 1, TimeUnit.SECONDS); - timer.stop(); - - regMonitoring.unregister(); - factoriesTracker.close(); - } -} diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java deleted file mode 100644 index f1845b1038..0000000000 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.netconf.impl.osgi; - -import org.opendaylight.netconf.api.util.NetconfConstants; -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -class NetconfOperationServiceFactoryTracker extends - ServiceTracker { - private final NetconfOperationServiceFactoryListener factoriesListener; - - NetconfOperationServiceFactoryTracker(final BundleContext context, - final NetconfOperationServiceFactoryListener factoriesListener) { - super(context, NetconfOperationServiceFactory.class, null); - this.factoriesListener = factoriesListener; - } - - @Override - public NetconfOperationServiceFactory addingService( - final ServiceReference reference) { - Object property = reference.getProperty(NetconfConstants.SERVICE_NAME); - if (property != null && isMarkedForConfig(property)) { - NetconfOperationServiceFactory netconfOperationServiceFactory = super.addingService(reference); - factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory); - return netconfOperationServiceFactory; - } - - return null; - } - - @Override - public void removedService(final ServiceReference reference, - final NetconfOperationServiceFactory netconfOperationServiceFactory) { - if (netconfOperationServiceFactory != null) { - factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory); - } - } - - private static boolean isMarkedForConfig(final Object property) { - return NetconfConstants.CONFIG_SERVICE_MARKERS.contains(property); - } - -} diff --git a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfImplActivatorTest.java b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfImplActivatorTest.java deleted file mode 100644 index 4e6a94c083..0000000000 --- a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfImplActivatorTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.netconf.impl.osgi; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - -import java.util.Arrays; -import java.util.Dictionary; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; - -public class NetconfImplActivatorTest { - - @Mock - private BundleContext bundle; - @Mock - private Filter filter; - @Mock - private ServiceReference reference; - @Mock - private ServiceRegistration registration; - @Mock - private ServiceRegistration monRegistration; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - doReturn(filter).when(bundle).createFilter(anyString()); - doNothing().when(bundle).addServiceListener(any(ServiceListener.class), any()); - - ServiceReference[] refs = {}; - doReturn(refs).when(bundle).getServiceReferences(anyString(), any()); - doReturn(Arrays.asList(refs)).when(bundle).getServiceReferences(any(Class.class), any()); - doReturn("").when(bundle).getProperty(anyString()); - doReturn(monRegistration).when(bundle).registerService(any(Class.class), - any(NetconfMonitoringServiceImpl.class), any(Dictionary.class)); - doNothing().when(monRegistration).unregister(); - doReturn(registration).when(bundle).registerService(any(Class.class), - any(AggregatedNetconfOperationServiceFactory.class), any(Dictionary.class)); - doNothing().when(registration).unregister(); - doNothing().when(bundle).removeServiceListener(any(ServiceListener.class)); - } - - @Test - public void testStart() throws Exception { - NetconfImplActivator activator = new NetconfImplActivator(); - activator.start(bundle); - verify(bundle).registerService(any(Class.class), any(NetconfMonitoringServiceImpl.class), - any(Dictionary.class)); - activator.stop(bundle); - } -} diff --git a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java deleted file mode 100644 index e8b3f47529..0000000000 --- a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.netconf.impl.osgi; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.netconf.api.util.NetconfConstants; -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.ServiceReference; - -public class NetconfOperationServiceFactoryTrackerTest { - - @Mock - private Filter filter; - @Mock - private BundleContext context; - @Mock - private NetconfOperationServiceFactoryListener listener; - @Mock - private NetconfOperationServiceFactory factory; - @Mock - private ServiceReference reference; - - private NetconfOperationServiceFactoryTracker tracker; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - doNothing().when(listener).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class)); - doReturn(filter).when(context).createFilter(anyString()); - doReturn("").when(reference).toString(); - doReturn(NetconfConstants.CONFIG_NETCONF_CONNECTOR).when(reference).getProperty(NetconfConstants.SERVICE_NAME); - doReturn(factory).when(context).getService(any(ServiceReference.class)); - doReturn("").when(factory).toString(); - doNothing().when(listener).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class)); - tracker = new NetconfOperationServiceFactoryTracker(context, listener); - } - - @Test - public void testNetconfOperationServiceFactoryTracker() throws Exception { - tracker.removedService(null, factory); - verify(listener, times(1)).onRemoveNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class)); - } - - @Test - public void testAddingService() throws Exception { - assertNotNull(tracker.addingService(reference)); - verify(listener, times(1)).onAddNetconfOperationServiceFactory(any(NetconfOperationServiceFactory.class)); - } -}