import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
+
+import org.apache.commons.lang3.tuple.Pair;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.neutron.spi.*;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.*;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronLoadBalancerCRUD;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronLoadBalancerPoolCRUD;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronNetworkCRUD;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronPortCRUD;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronSubnetCRUD;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronFirewallInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronFirewallPolicyInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronFirewallRuleInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronFloatingIPInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronLoadBalancerHealthMonitorInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronLoadBalancerInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronLoadBalancerListenerInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronLoadBalancerPoolInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronLoadBalancerPoolMemberInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronNetworkInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronPortInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronRouterInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronSecurityGroupInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronSecurityRuleInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.impl.NeutronSubnetInterface;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronFirewallAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronFirewallPolicyAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronFirewallRuleAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronFloatingIPAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronLoadBalancerAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronLoadBalancerPoolAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronLoadBalancerPoolMemberAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronNetworkAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronPortAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronRouterAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronSecurityGroupAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronSecurityRuleAware;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.iaware.INeutronSubnetAware;
import org.opendaylight.ovsdb.openstack.netvirt.api.*;
import org.opendaylight.ovsdb.openstack.netvirt.impl.*;
import org.osgi.framework.BundleActivator;
public class ConfigActivator implements BundleActivator {
private static final Logger LOG = LoggerFactory.getLogger(ConfigActivator.class);
- private List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
+ private List<ServiceRegistration<?>> translatorCRUDRegistrations = new ArrayList<ServiceRegistration<?>>();
+ private List<Pair<Object, ServiceRegistration>> servicesAndRegistrations = new ArrayList<>();
private ProviderContext providerContext;
- private ServiceTracker iNeutronNetworkCRUDTracker;
- private ServiceTracker iNeutronPortCRUDTracker;
- private ServiceTracker iNeutronLoadBalancerCRUDTracker;
- private ServiceTracker iNeutronLoadBalancerPoolCRUDTracker;
- private ServiceTracker iNeutronSubnetCRUDTracker;
- private ServiceTracker loadBalancerProviderTracker;
- private ServiceTracker arpProviderTracker;
- private ServiceTracker inboundNatProviderTracker;
- private ServiceTracker outboundNatProviderTracker;
- private ServiceTracker routingProviderTracker;
- private ServiceTracker l3ForwardingProviderTracker;
- private ServiceTracker gatewayMacResolverProviderTracker;
public ConfigActivator(ProviderContext providerContext) {
this.providerContext = providerContext;
@Override
public void start(BundleContext context) throws Exception {
LOG.info("ConfigActivator start:");
+ registerCRUDServiceProviders(context, this.providerContext);
ConfigurationServiceImpl configurationService = new ConfigurationServiceImpl();
registerService(context, new String[] {ConfigurationService.class.getName()},
registerService(context, new String[] {VlanConfigurationCache.class.getName()},
null, vlanConfigurationCache);
- Dictionary<String, Object> floatingIPHandlerProperties = new Hashtable<>();
- floatingIPHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
- AbstractEvent.HandlerType.NEUTRON_FLOATING_IP);
FloatingIPHandler floatingIPHandler = new FloatingIPHandler();
- registerService(context,
- new String[] {INeutronFloatingIPAware.class.getName(), AbstractHandler.class.getName()},
- floatingIPHandlerProperties, floatingIPHandler);
+ registerAbstractHandlerService(context, new Class[] {INeutronFloatingIPAware.class},
+ AbstractEvent.HandlerType.NEUTRON_FLOATING_IP, floatingIPHandler);
- Dictionary<String, Object> networkHandlerProperties = new Hashtable<>();
- networkHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_NETWORK);
final NetworkHandler networkHandler = new NetworkHandler();
- registerService(context,
- new String[]{INeutronNetworkAware.class.getName(), AbstractHandler.class.getName()},
- networkHandlerProperties, networkHandler);
+ registerAbstractHandlerService(context, new Class[] {INeutronNetworkAware.class},
+ AbstractEvent.HandlerType.NEUTRON_NETWORK, networkHandler);
- Dictionary<String, Object> subnetHandlerProperties = new Hashtable<>();
- subnetHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_SUBNET);
SubnetHandler subnetHandler = new SubnetHandler();
- registerService(context,
- new String[] {INeutronSubnetAware.class.getName(), AbstractHandler.class.getName()},
- subnetHandlerProperties, subnetHandler);
+ registerAbstractHandlerService(context, new Class[] {INeutronSubnetAware.class},
+ AbstractEvent.HandlerType.NEUTRON_SUBNET, subnetHandler);
- Dictionary<String, Object> portHandlerProperties = new Hashtable<>();
- portHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_PORT);
PortHandler portHandler = new PortHandler();
- registerService(context,
- new String[]{INeutronPortAware.class.getName(), AbstractHandler.class.getName()},
- portHandlerProperties, portHandler);
+ registerAbstractHandlerService(context, new Class[] {INeutronPortAware.class},
+ AbstractEvent.HandlerType.NEUTRON_PORT, portHandler);
- Dictionary<String, Object> routerHandlerProperties = new Hashtable<>();
- routerHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_ROUTER);
RouterHandler routerHandler = new RouterHandler();
- registerService(context,
- new String[]{INeutronRouterAware.class.getName(), AbstractHandler.class.getName()},
- routerHandlerProperties, routerHandler);
+ registerAbstractHandlerService(context, new Class[] {INeutronRouterAware.class},
+ AbstractEvent.HandlerType.NEUTRON_ROUTER, routerHandler);
- Dictionary<String, Object> southboundHandlerProperties = new Hashtable<>();
- southboundHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.SOUTHBOUND);
SouthboundHandler southboundHandler = new SouthboundHandler();
- registerService(context,
- new String[]{OvsdbInventoryListener.class.getName(),
- NodeCacheListener.class.getName(),
- AbstractHandler.class.getName()},
- southboundHandlerProperties, southboundHandler);
-
- Dictionary<String, Object> lbaasHandlerProperties = new Hashtable<>();
- lbaasHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
- AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER);
+ registerAbstractHandlerService(context, new Class[] {OvsdbInventoryListener.class, NodeCacheListener.class},
+ AbstractEvent.HandlerType.SOUTHBOUND, southboundHandler);
+
final LBaaSHandler lBaaSHandler = new LBaaSHandler();
- registerService(context,
- new String[]{INeutronLoadBalancerAware.class.getName(),
- NodeCacheListener.class.getName(), AbstractHandler.class.getName()},
- lbaasHandlerProperties, lBaaSHandler);
+ registerAbstractHandlerService(context, new Class[] {INeutronLoadBalancerAware.class, NodeCacheListener.class},
+ AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER, lBaaSHandler);
- Dictionary<String, Object> lbaasPoolHandlerProperties = new Hashtable<>();
- lbaasPoolHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
- AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL);
final LBaaSPoolHandler lBaaSPoolHandler = new LBaaSPoolHandler();
- registerService(context,
- new String[]{INeutronLoadBalancerPoolAware.class.getName(),
- AbstractHandler.class.getName()}, lbaasPoolHandlerProperties, lBaaSPoolHandler);
+ registerAbstractHandlerService(context, new Class[] {INeutronLoadBalancerPoolAware.class},
+ AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL, lBaaSPoolHandler);
- Dictionary<String, Object> lbaasPoolMemberHandlerProperties = new Hashtable<>();
- lbaasPoolMemberHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
- AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL_MEMBER);
final LBaaSPoolMemberHandler lBaaSPoolMemberHandler = new LBaaSPoolMemberHandler();
- registerService(context,
- new String[]{INeutronLoadBalancerPoolMemberAware.class.getName(),
- AbstractHandler.class.getName()}, lbaasPoolMemberHandlerProperties, lBaaSPoolMemberHandler);
+ registerAbstractHandlerService(context, new Class[] {INeutronLoadBalancerPoolMemberAware.class},
+ AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL_MEMBER, lBaaSPoolMemberHandler);
- Dictionary<String, Object> portSecurityHandlerProperties = new Hashtable<>();
- portSecurityHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY,
- AbstractEvent.HandlerType.NEUTRON_PORT_SECURITY);
PortSecurityHandler portSecurityHandler = new PortSecurityHandler();
- registerService(context,
- new String[]{INeutronSecurityRuleAware.class.getName(),
- INeutronSecurityGroupAware.class.getName(), AbstractHandler.class.getName()},
- portSecurityHandlerProperties, portSecurityHandler);
+ registerAbstractHandlerService(context,
+ new Class[] {INeutronSecurityRuleAware.class, INeutronSecurityGroupAware.class},
+ AbstractEvent.HandlerType.NEUTRON_PORT_SECURITY, portSecurityHandler);
final SecurityServicesImpl securityServices = new SecurityServicesImpl();
registerService(context,
new String[]{SecurityServicesManager.class.getName()}, null, securityServices);
- Dictionary<String, Object> fWaasHandlerProperties = new Hashtable<>();
- fWaasHandlerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NEUTRON_FWAAS);
FWaasHandler fWaasHandler = new FWaasHandler();
- registerService(context,
- new String[]{INeutronFirewallAware.class.getName(),
- INeutronFirewallRuleAware.class.getName(), INeutronFirewallPolicyAware.class.getName(),
- AbstractHandler.class.getName()}, fWaasHandlerProperties, fWaasHandler);
+ registerAbstractHandlerService(context,
+ new Class[] {INeutronFirewallAware.class, INeutronFirewallRuleAware.class, INeutronFirewallPolicyAware.class},
+ AbstractEvent.HandlerType.NEUTRON_FWAAS, fWaasHandler);
ProviderNetworkManagerImpl providerNetworkManager = new ProviderNetworkManagerImpl();
registerService(context,
registerService(context,
new String[]{Southbound.class.getName()}, null, southbound);
- Dictionary<String, Object> nodeCacheManagerProperties = new Hashtable<>();
- nodeCacheManagerProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.NODE);
NodeCacheManagerImpl nodeCacheManager = new NodeCacheManagerImpl();
- registerService(context,
- new String[]{NodeCacheManager.class.getName(), AbstractHandler.class.getName()},
- nodeCacheManagerProperties, nodeCacheManager);
+ registerAbstractHandlerService(context, new Class[] {NodeCacheManager.class},
+ AbstractEvent.HandlerType.NODE, nodeCacheManager);
OvsdbInventoryServiceImpl ovsdbInventoryService = new OvsdbInventoryServiceImpl(providerContext);
registerService(context,
new String[] {OvsdbInventoryService.class.getName()}, null, ovsdbInventoryService);
- ovsdbInventoryService.setDependencies(context, null);
- nodeCacheManager.setDependencies(context, null);
- openstackRouter.setDependencies(context, null);
- neutronL3Adapter.setDependencies(context, null);
- eventDispatcher.setDependencies(context, null);
- providerNetworkManager.setDependencies(context, null);
- fWaasHandler.setDependencies(context, null);
- securityServices.setDependencies(context, null);
- portSecurityHandler.setDependencies(context, null);
- lBaaSPoolMemberHandler.setDependencies(context, null);
- lBaaSPoolHandler.setDependencies(context, null);
- lBaaSHandler.setDependencies(context, null);
- southboundHandler.setDependencies(context, null);
- routerHandler.setDependencies(context, null);
- portHandler.setDependencies(context, null);
- subnetHandler.setDependencies(context, null);
- networkHandler.setDependencies(context, null);
- floatingIPHandler.setDependencies(context, null);
- vlanConfigurationCache.setDependencies(context, null);
- tenantNetworkManager.setDependencies(context, null);
- bridgeConfigurationManager.setDependencies(context, null);
- configurationService.setDependencies(context, null);
+ // Call .setDependencies() starting with the last service registered
+ for (int i = servicesAndRegistrations.size() - 1; i >= 0; i--) {
+ Pair<Object, ServiceRegistration> serviceAndRegistration = servicesAndRegistrations.get(i);
+ Object service = serviceAndRegistration.getLeft();
+ ServiceRegistration<?> serviceRegistration = serviceAndRegistration.getRight();
+ LOG.info("Setting dependencies on service {}/{}, {}", i, servicesAndRegistrations.size(),
+ service.getClass());
+ if (service instanceof ConfigInterface) {
+ ((ConfigInterface) service).setDependencies(
+ serviceRegistration != null ? serviceRegistration.getReference() : null);
+ LOG.info("Dependencies set");
+ } else {
+ LOG.warn("Service isn't a ConfigInterface");
+ }
+ }
// TODO check if services are already available and setDependencies
// addingService may not be called if the service is already available when the ServiceTracker
// is started
- @SuppressWarnings("unchecked")
- ServiceTracker iNeutronNetworkCRUDTracker = new ServiceTracker(context, INeutronNetworkCRUD.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService INeutronNetworkCRUD");
- INeutronNetworkCRUD service = (INeutronNetworkCRUD)context.getService(reference);
- if (service != null) {
- tenantNetworkManager.setDependencies(service);
- networkHandler.setDependencies(service);
- lBaaSHandler.setDependencies(service);
- lBaaSPoolHandler.setDependencies(service);
- lBaaSPoolMemberHandler.setDependencies(service);
- neutronL3Adapter.setDependencies(service);
- }
- return service;
- }
- };
- iNeutronNetworkCRUDTracker.open();
- this.iNeutronNetworkCRUDTracker = iNeutronNetworkCRUDTracker;
-
- @SuppressWarnings("unchecked")
- ServiceTracker iNeutronSubnetCRUDTracker = new ServiceTracker(context, INeutronSubnetCRUD.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService INeutronSubnetCRUD");
- INeutronSubnetCRUD service = (INeutronSubnetCRUD) context.getService(reference);
- if (service != null) {
- lBaaSHandler.setDependencies(service);
- lBaaSPoolHandler.setDependencies(service);
- lBaaSPoolMemberHandler.setDependencies(service);
- securityServices.setDependencies(service);
- neutronL3Adapter.setDependencies(service);
- }
- return service;
- }
- };
- iNeutronSubnetCRUDTracker.open();
- this.iNeutronSubnetCRUDTracker = iNeutronSubnetCRUDTracker;
-
- @SuppressWarnings("unchecked")
- ServiceTracker iNeutronPortCRUDTracker = new ServiceTracker(context, INeutronPortCRUD.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService INeutronPortCRUD");
- INeutronPortCRUD service = (INeutronPortCRUD) context.getService(reference);
- if (service != null) {
- tenantNetworkManager.setDependencies(service);
- lBaaSHandler.setDependencies(service);
- lBaaSPoolHandler.setDependencies(service);
- lBaaSPoolMemberHandler.setDependencies(service);
- securityServices.setDependencies(service);
- neutronL3Adapter.setDependencies(service);
- }
- return service;
- }
- };
- iNeutronPortCRUDTracker.open();
- this.iNeutronPortCRUDTracker = iNeutronPortCRUDTracker;
-
- @SuppressWarnings("unchecked")
- ServiceTracker iNeutronLoadBalancerCRUDTracker = new ServiceTracker(context,
- INeutronLoadBalancerCRUD.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService INeutronLoadBalancerCRUD");
- INeutronLoadBalancerCRUD service = (INeutronLoadBalancerCRUD) context.getService(reference);
- if (service != null) {
- lBaaSHandler.setDependencies(service);
- lBaaSPoolHandler.setDependencies(service);
- lBaaSPoolMemberHandler.setDependencies(service);
- }
- return service;
- }
- };
- iNeutronLoadBalancerCRUDTracker.open();
- this.iNeutronLoadBalancerCRUDTracker = iNeutronLoadBalancerCRUDTracker;
-
- @SuppressWarnings("unchecked")
- ServiceTracker iNeutronLoadBalancerPoolCRUDTracker = new ServiceTracker(context,
- INeutronLoadBalancerPoolCRUD.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService INeutronLoadBalancerPoolCRUD");
- INeutronLoadBalancerPoolCRUD service =
- (INeutronLoadBalancerPoolCRUD) context.getService(reference);
- if (service != null) {
- lBaaSHandler.setDependencies(service);
- lBaaSPoolMemberHandler.setDependencies(service);
- }
- return service;
- }
- };
- iNeutronLoadBalancerPoolCRUDTracker.open();
- this.iNeutronLoadBalancerPoolCRUDTracker = iNeutronLoadBalancerPoolCRUDTracker;
-
- @SuppressWarnings("unchecked")
- ServiceTracker ioadBalancerProviderTracker = new ServiceTracker(context,
- LoadBalancerProvider.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService LoadBalancerProvider");
- LoadBalancerProvider service =
- (LoadBalancerProvider) context.getService(reference);
- if (service != null) {
- lBaaSHandler.setDependencies(service);
- lBaaSPoolHandler.setDependencies(service);
- lBaaSPoolMemberHandler.setDependencies(service);
- }
- return service;
- }
- };
- ioadBalancerProviderTracker.open();
- this.loadBalancerProviderTracker = ioadBalancerProviderTracker;
-
- @SuppressWarnings("unchecked")
- ServiceTracker arpProviderTracker = new ServiceTracker(context,
- ArpProvider.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService ArpProvider");
- ArpProvider service =
- (ArpProvider) context.getService(reference);
- if (service != null) {
- neutronL3Adapter.setDependencies(service);
- }
- return service;
- }
- };
- arpProviderTracker.open();
- this.arpProviderTracker = arpProviderTracker;
-
- @SuppressWarnings("unchecked")
- ServiceTracker inboundNatProviderTracker = new ServiceTracker(context,
- InboundNatProvider.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService InboundNatProvider");
- InboundNatProvider service =
- (InboundNatProvider) context.getService(reference);
- if (service != null) {
- neutronL3Adapter.setDependencies(service);
- }
- return service;
- }
- };
- inboundNatProviderTracker.open();
- this.inboundNatProviderTracker = inboundNatProviderTracker;
-
- @SuppressWarnings("unchecked")
- ServiceTracker outboundNatProviderTracker = new ServiceTracker(context,
- OutboundNatProvider.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService OutboundNatProvider");
- OutboundNatProvider service =
- (OutboundNatProvider) context.getService(reference);
- if (service != null) {
- neutronL3Adapter.setDependencies(service);
- }
- return service;
- }
- };
- outboundNatProviderTracker.open();
- this.outboundNatProviderTracker = outboundNatProviderTracker;
+ trackService(context, INeutronNetworkCRUD.class, tenantNetworkManager, networkHandler, lBaaSHandler,
+ lBaaSPoolHandler, lBaaSPoolMemberHandler, neutronL3Adapter);
+ trackService(context, INeutronSubnetCRUD.class, lBaaSHandler, lBaaSPoolHandler, lBaaSPoolMemberHandler,
+ securityServices, neutronL3Adapter);
+ trackService(context, INeutronPortCRUD.class, tenantNetworkManager, lBaaSHandler, lBaaSPoolHandler,
+ lBaaSPoolMemberHandler, securityServices, neutronL3Adapter);
+ trackService(context, INeutronLoadBalancerCRUD.class, lBaaSHandler, lBaaSPoolHandler, lBaaSPoolMemberHandler);
+ trackService(context, INeutronLoadBalancerPoolCRUD.class, lBaaSHandler, lBaaSPoolMemberHandler);
+ trackService(context, LoadBalancerProvider.class, lBaaSHandler, lBaaSPoolHandler, lBaaSPoolMemberHandler);
+ trackService(context, ArpProvider.class, neutronL3Adapter);
+ trackService(context, InboundNatProvider.class, neutronL3Adapter);
+ trackService(context, OutboundNatProvider.class, neutronL3Adapter);
+ trackService(context, RoutingProvider.class, neutronL3Adapter);
+ trackService(context, L3ForwardingProvider.class, neutronL3Adapter);
+ trackService(context, GatewayMacResolver.class, neutronL3Adapter);
+ trackService(context, IngressAclProvider.class, securityServices);
+ trackService(context, EgressAclProvider.class, securityServices);
+
+ // We no longer need to track the services, avoid keeping references around
+ servicesAndRegistrations.clear();
+ }
- @SuppressWarnings("unchecked")
- ServiceTracker routingProviderTracker = new ServiceTracker(context,
- RoutingProvider.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService RoutingProvider");
- RoutingProvider service =
- (RoutingProvider) context.getService(reference);
- if (service != null) {
- neutronL3Adapter.setDependencies(service);
- }
- return service;
- }
- };
- routingProviderTracker.open();
- this.routingProviderTracker = routingProviderTracker;
+ private void registerCRUDServiceProviders(BundleContext context,
+ ProviderContext providerContext) {
+ LOG.debug("Registering CRUD service providers");
+ NeutronRouterInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronPortInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronSubnetInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronNetworkInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronSecurityGroupInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronSecurityRuleInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronFirewallInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronFirewallPolicyInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronFirewallRuleInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronLoadBalancerInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronLoadBalancerPoolInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronLoadBalancerListenerInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronLoadBalancerHealthMonitorInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronLoadBalancerPoolMemberInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ NeutronFloatingIPInterface.registerNewInterface(context, providerContext, translatorCRUDRegistrations);
+ }
+ private void trackService(BundleContext context, final Class<?> clazz, final ConfigInterface... dependents) {
@SuppressWarnings("unchecked")
- ServiceTracker l3ForwardingProviderTracker = new ServiceTracker(context,
- L3ForwardingProvider.class, null) {
+ ServiceTracker tracker = new ServiceTracker(context, clazz, null) {
@Override
public Object addingService(ServiceReference reference) {
- LOG.info("addingService L3ForwardingProvider");
- L3ForwardingProvider service =
- (L3ForwardingProvider) context.getService(reference);
+ LOG.info("addingService " + clazz.getName());
+ Object service = context.getService(reference);
if (service != null) {
- neutronL3Adapter.setDependencies(service);
+ for (ConfigInterface dependent : dependents) {
+ dependent.setDependencies(service);
+ }
}
return service;
}
};
- l3ForwardingProviderTracker.open();
- this.l3ForwardingProviderTracker = l3ForwardingProviderTracker;
+ tracker.open();
+ }
- @SuppressWarnings("unchecked")
- ServiceTracker gatewayMacResolverProviderTracker = new ServiceTracker(context,
- GatewayMacResolver.class, null) {
- @Override
- public Object addingService(ServiceReference reference) {
- LOG.info("addingService GatwayMacResolverProvider");
- GatewayMacResolver service =
- (GatewayMacResolver) context.getService(reference);
- if (service != null) {
- neutronL3Adapter.setDependencies(service);
- }
- return service;
- }
- };
- gatewayMacResolverProviderTracker.open();
- this.gatewayMacResolverProviderTracker = gatewayMacResolverProviderTracker;
+ private void registerAbstractHandlerService(BundleContext context, Class[] interfaces,
+ AbstractEvent.HandlerType handlerType, AbstractHandler handler) {
+ Dictionary<String, Object> properties = new Hashtable<>();
+ properties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, handlerType);
+ String[] interfaceNames = new String[interfaces.length + 1];
+ for (int i = 0; i < interfaces.length; i++) {
+ interfaceNames[i] = interfaces[i].getName();
+ }
+ interfaceNames[interfaces.length] = AbstractHandler.class.getName();
+ registerService(context, interfaceNames, properties, handler);
}
@Override
public void stop(BundleContext context) throws Exception {
- LOG.info("ConfigActivator stop");
- /* ServiceTrackers and services are already released when bundle stops
- iNeutronNetworkCRUDTracker.close();
- iNeutronPortCRUDTracker.close();
- iNeutronSubnetCRUDTracker.close();
- iNeutronLoadBalancerCRUDTracker.close();
- iNeutronLoadBalancerPoolCRUDTracker.close();
- loadBalancerProviderTracker.close();
-
- for (ServiceRegistration registration : registrations) {
+ LOG.info("Stop Translator CRUD service provides");
+ // ServiceTrackers and services are already released when bundle stops,
+ // so we don't need to close the trackers or unregister the services
+ for (ServiceRegistration registration : translatorCRUDRegistrations) {
if (registration != null) {
registration.unregister();
}
- }*/
+ }
+
}
private ServiceRegistration<?> registerService(BundleContext bundleContext, String[] interfaces,
Dictionary<String, Object> properties, Object impl) {
- ServiceRegistration<?> serviceRegistration = bundleContext.registerService(interfaces, impl, properties);
- if (serviceRegistration != null) {
- registrations.add(serviceRegistration);
+ ServiceRegistration serviceRegistration = bundleContext.registerService(interfaces, impl, properties);
+ if (serviceRegistration == null) {
+ LOG.warn("Service registration for {} failed to return a ServiceRegistration instance", impl.getClass());
}
+ servicesAndRegistrations.add(Pair.of(impl, serviceRegistration));
return serviceRegistration;
}
}