Do not start netconf-impl for css netconf endpoint 94/79794/4
authorJakub Morvay <jmorvay@frinx.io>
Mon, 21 Jan 2019 15:46:17 +0000 (16:46 +0100)
committerTom Pantelis <tompantelis@gmail.com>
Wed, 23 Jan 2019 01:17:33 +0000 (01:17 +0000)
netconf-impl project contains both implementation of APIs defined in
netconf-api and netconf-mapping-api projects and also instantiation
logic of some base netconf server components for netconf css northbound
endpoint. Remove this logic, css is not used anymore, so it is its
netconf endpoint.

Change-Id: Iad381885d229e374957d87087a4a96ba46f75551
Signed-off-by: Jakub Morvay <jmorvay@frinx.io>
netconf/netconf-impl/pom.xml
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfImplActivator.java [deleted file]
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationServiceFactoryTracker.java [deleted file]
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfImplActivatorTest.java [deleted file]
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfOperationServiceFactoryTrackerTest.java [deleted file]

index d90d3d9018f15d993f22060d9c528f5267a15790..2ebd6713b8d8264e3229dcd35045a42e0236bdc0 100644 (file)
       <artifactId>xmlunit-legacy</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.compendium</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.core</artifactId>
-    </dependency>
   </dependencies>
 
   <build>
         <artifactId>maven-bundle-plugin</artifactId>
         <configuration>
           <instructions>
-            <Bundle-Activator>org.opendaylight.netconf.impl.osgi.NetconfImplActivator</Bundle-Activator>
             <Export-Package>org.opendaylight.netconf.impl.*</Export-Package>
           </instructions>
         </configuration>
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 (file)
index 8529da6..0000000
+++ /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<NetconfMonitoringService> 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<NetconfNotificationCollector, NetconfNotificationCollector>
-                    notificationServiceTracker = new ServiceTracker<>(context, NetconfNotificationCollector.class,
-                    new ServiceTrackerCustomizer<NetconfNotificationCollector, NetconfNotificationCollector>() {
-                            @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<NetconfNotificationCollector> reference,
-                                            NetconfNotificationCollector service) {
-
-                                }
-
-                            @Override
-                            public void removedService(ServiceReference<NetconfNotificationCollector> 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<String, ?> 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 (file)
index f1845b1..0000000
+++ /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<NetconfOperationServiceFactory, NetconfOperationServiceFactory> {
-    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<NetconfOperationServiceFactory> 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<NetconfOperationServiceFactory> 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 (file)
index 4e6a94c..0000000
+++ /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 (file)
index e8b3f47..0000000
+++ /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<NetconfOperationServiceFactory> 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));
-    }
-}