Since getting services is done by class name, we needed to add additional filtering by
name to not get controller subsystem netconf operations mixed up with md-sal northbound.
Change-Id: I6aeb161ae0ace977f590d73e4fcb98c0898b1956
Signed-off-by: Tomas Cere <tcere@cisco.com>
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
import java.util.Dictionary;
import java.util.Hashtable;
+import org.opendaylight.controller.netconf.api.util.NetconfConstants;
import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
import org.osgi.framework.BundleActivator;
NetconfOperationServiceFactoryImpl factory = new NetconfOperationServiceFactoryImpl(yangStoreService);
LOG.debug("Registering into OSGi");
Dictionary<String, String> properties = new Hashtable<>();
- properties.put("name", "config-netconf-connector");
+ properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.CONFIG_NETCONF_CONNECTOR);
osgiRegistration = context.registerService(NetconfOperationServiceFactory.class, factory, properties);
}
}
--- /dev/null
+/*
+ * 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.api.util;
+
+public final class NetconfConstants {
+ /*
+ * TODO define marker interface in mapping-api that the serviceFactories in cofing subsystem
+ * will implement so we can check for services with instanceof instead of constants
+ */
+ public static final String SERVICE_NAME = "name";
+ public static final String CONFIG_NETCONF_CONNECTOR = "config-netconf-connector";
+ public static final String NETCONF_MONITORING = "ietf-netconf-monitoring";
+}
*/
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.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@Override
public NetconfOperationServiceFactory addingService(ServiceReference<NetconfOperationServiceFactory> reference) {
- NetconfOperationServiceFactory netconfOperationServiceFactory = super.addingService(reference);
- factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory);
- return netconfOperationServiceFactory;
+ Object property = reference.getProperty(NetconfConstants.SERVICE_NAME);
+ if (property != null
+ && (property.equals(NetconfConstants.CONFIG_NETCONF_CONNECTOR)
+ || property.equals(NetconfConstants.NETCONF_MONITORING))) {
+ NetconfOperationServiceFactory netconfOperationServiceFactory = super.addingService(reference);
+ factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory);
+ return netconfOperationServiceFactory;
+ }
+
+ return null;
}
@Override
public void removedService(ServiceReference<NetconfOperationServiceFactory> reference,
NetconfOperationServiceFactory netconfOperationServiceFactory) {
- factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory);
+ if (netconfOperationServiceFactory != null)
+ factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory);
}
}
import org.junit.Test;
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.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
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));
package org.opendaylight.controller.netconf.monitoring.osgi;
import com.google.common.base.Preconditions;
+import java.util.Dictionary;
import java.util.Hashtable;
import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
+import org.opendaylight.controller.netconf.api.util.NetconfConstants;
import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
final NetconfOperationServiceFactory factory = new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
operationService);
- reg = context.registerService(NetconfOperationServiceFactory.class, factory, new Hashtable<String, Object>());
+ Dictionary<String, String> properties = new Hashtable<>();
+ properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
+ reg = context.registerService(NetconfOperationServiceFactory.class, factory, properties);
return netconfMonitoringService;
}
import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.Collections;
+import java.util.Dictionary;
import java.util.Hashtable;
import java.util.Set;
+import org.opendaylight.controller.netconf.api.util.NetconfConstants;
import org.opendaylight.controller.netconf.mapping.api.Capability;
import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
}
};
- operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, new Hashtable<String, Object>());
+ Dictionary<String, String> properties = new Hashtable<>();
+ properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
+ operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
}