Merge "Bug 5368 - NeutronL3Adapter ipv6 work around for mac address resolver"
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / LBaaSPoolHandler.java
index ee349b235a161403781634dea74f2c7feb7e795c..93b4ce626ecabb3b93fd2269bed9d627f8c08c1c 100755 (executable)
@@ -1,23 +1,25 @@
 /*
- * Copyright (C) 2014 SDN Hub, LLC.
+ * Copyright (c) 2014, 2015 SDN Hub, LLC. 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
- *
- * Authors : Srini Seetharaman
  */
 
 package org.opendaylight.ovsdb.openstack.netvirt;
 
-import org.opendaylight.neutron.spi.INeutronLoadBalancerCRUD;
-import org.opendaylight.neutron.spi.INeutronLoadBalancerPoolAware;
-import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
-import org.opendaylight.neutron.spi.INeutronPortCRUD;
-import org.opendaylight.neutron.spi.INeutronSubnetCRUD;
-import org.opendaylight.neutron.spi.NeutronLoadBalancer;
-import org.opendaylight.neutron.spi.NeutronLoadBalancerPool;
-import org.opendaylight.neutron.spi.NeutronLoadBalancerPoolMember;
+import java.net.HttpURLConnection;
+import java.util.List;
+import java.util.Map;
+
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronLoadBalancer;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronLoadBalancerPool;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronLoadBalancerPoolMember;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronLoadBalancerCRUD;
+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.iaware.INeutronLoadBalancerPoolAware;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
 import org.opendaylight.ovsdb.openstack.netvirt.api.LoadBalancerConfiguration;
@@ -25,7 +27,7 @@ import org.opendaylight.ovsdb.openstack.netvirt.api.LoadBalancerProvider;
 import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager;
 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.osgi.framework.BundleContext;
+
 import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,10 +35,6 @@ import org.slf4j.LoggerFactory;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 
-import java.net.HttpURLConnection;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Handle requests for OpenStack Neutron v2.0 LBaaS API calls for
  * /v2.0/pools . It is possible that each pool spans multiple subnets.
@@ -46,7 +44,7 @@ import java.util.Map;
 public class LBaaSPoolHandler extends AbstractHandler
         implements INeutronLoadBalancerPoolAware, ConfigInterface {
 
-    private static final Logger logger = LoggerFactory.getLogger(LBaaSPoolHandler.class);
+    private static final Logger LOG = LoggerFactory.getLogger(LBaaSPoolHandler.class);
 
     // The implementation for each of these services is resolved by the OSGi Service Manager
     private volatile INeutronLoadBalancerCRUD neutronLBCache;
@@ -55,7 +53,6 @@ public class LBaaSPoolHandler extends AbstractHandler
     private volatile INeutronSubnetCRUD neutronSubnetCache;
     private volatile LoadBalancerProvider loadBalancerProvider;
     private volatile NodeCacheManager nodeCacheManager;
-    private volatile EventDispatcher eventDispatcher;
 
     @Override
     public int canCreateNeutronLoadBalancerPool(NeutronLoadBalancerPool neutronLBPool) {
@@ -73,7 +70,7 @@ public class LBaaSPoolHandler extends AbstractHandler
 
     @Override
     public void neutronLoadBalancerPoolCreated(NeutronLoadBalancerPool neutronLBPool) {
-        logger.debug("Neutron LB Pool Creation : {}", neutronLBPool.toString());
+        LOG.debug("Neutron LB Pool Creation : {}", neutronLBPool.toString());
         enqueueEvent(new NorthboundEvent(neutronLBPool, Action.ADD));
     }
 
@@ -87,16 +84,15 @@ public class LBaaSPoolHandler extends AbstractHandler
         List<LoadBalancerConfiguration> lbConfigList = extractLBConfiguration(neutronLBPool);
         final List<Node> nodes = nodeCacheManager.getBridgeNodes();
         if (lbConfigList == null) {
-            logger.debug("Neutron LB configuration invalid for pool {} ", neutronLBPool.getLoadBalancerPoolID());
+            LOG.debug("Neutron LB configuration invalid for pool {} ", neutronLBPool.getID());
         } else if (lbConfigList.size() == 0) {
-            logger.debug("No Neutron LB VIP not created yet for pool {} ", neutronLBPool.getLoadBalancerPoolID());
+            LOG.debug("No Neutron LB VIP not created yet for pool {} ", neutronLBPool.getID());
         } else if (nodes.isEmpty()) {
-            logger.debug("Noop with LB pool {} creation because no nodes available.", neutronLBPool.getLoadBalancerPoolID());
+            LOG.debug("Noop with LB pool {} creation because no nodes available.", neutronLBPool.getID());
         } else {
             for (LoadBalancerConfiguration lbConfig: lbConfigList) {
                 if (!lbConfig.isValid()) {
-                    logger.debug("Neutron LB pool configuration invalid for {} ", lbConfig.getName());
-                    continue;
+                    LOG.debug("Neutron LB pool configuration invalid for {} ", lbConfig.getName());
                 } else {
                     for (Node node : nodes) {
                         loadBalancerProvider.programLoadBalancerRules(node, lbConfig, Action.ADD);
@@ -113,7 +109,7 @@ public class LBaaSPoolHandler extends AbstractHandler
 
     @Override
     public void neutronLoadBalancerPoolUpdated(NeutronLoadBalancerPool neutronLBPool) {
-        logger.debug("Neutron LB Pool Update : {}", neutronLBPool.toString());
+        LOG.debug("Neutron LB Pool Update : {}", neutronLBPool.toString());
         enqueueEvent(new NorthboundEvent(neutronLBPool, Action.UPDATE));
     }
 
@@ -133,7 +129,7 @@ public class LBaaSPoolHandler extends AbstractHandler
 
     @Override
     public void neutronLoadBalancerPoolDeleted(NeutronLoadBalancerPool neutronLBPool) {
-        logger.debug("Neutron LB Pool Deletion : {}", neutronLBPool.toString());
+        LOG.debug("Neutron LB Pool Deletion : {}", neutronLBPool.toString());
         enqueueEvent(new NorthboundEvent(neutronLBPool, Action.DELETE));
     }
 
@@ -143,16 +139,15 @@ public class LBaaSPoolHandler extends AbstractHandler
         List<LoadBalancerConfiguration> lbConfigList = extractLBConfiguration(neutronLBPool);
         final List<Node> nodes = nodeCacheManager.getBridgeNodes();
         if (lbConfigList == null) {
-            logger.debug("Neutron LB configuration invalid for pool {} ", neutronLBPool.getLoadBalancerPoolID());
+            LOG.debug("Neutron LB configuration invalid for pool {} ", neutronLBPool.getID());
         } else if (lbConfigList.size() == 0) {
-            logger.debug("No Neutron LB VIP not created yet for pool {} ", neutronLBPool.getLoadBalancerPoolID());
+            LOG.debug("No Neutron LB VIP not created yet for pool {} ", neutronLBPool.getID());
         } else if (nodes.isEmpty()) {
-            logger.debug("Noop with LB pool {} deletion because no nodes available.", neutronLBPool.getLoadBalancerPoolID());
+            LOG.debug("Noop with LB pool {} deletion because no nodes available.", neutronLBPool.getID());
         } else {
             for (LoadBalancerConfiguration lbConfig: lbConfigList) {
                 if (!lbConfig.isValid()) {
-                    logger.debug("Neutron LB pool configuration invalid for {} ", lbConfig.getName());
-                    continue;
+                    LOG.debug("Neutron LB pool configuration invalid for {} ", lbConfig.getName());
                 } else {
                     for (Node node : nodes) {
                         loadBalancerProvider.programLoadBalancerRules(node, lbConfig, Action.DELETE);
@@ -170,9 +165,9 @@ public class LBaaSPoolHandler extends AbstractHandler
      */
     @Override
     public void processEvent(AbstractEvent abstractEvent) {
-        logger.debug("Processing Loadbalancer Pool event " + abstractEvent);
+        LOG.debug("Processing Loadbalancer Pool event {}", abstractEvent);
         if (!(abstractEvent instanceof NorthboundEvent)) {
-            logger.error("Unable to process abstract event " + abstractEvent);
+            LOG.error("Unable to process abstract event {}", abstractEvent);
             return;
         }
         NorthboundEvent ev = (NorthboundEvent) abstractEvent;
@@ -188,10 +183,10 @@ public class LBaaSPoolHandler extends AbstractHandler
                  * Typical upgrade involves changing algorithm. Right now
                  * we do not support this flexibility. TODO
                  */
-                logger.warn("Load balancer pool update is not supported");
+                LOG.warn("Load balancer pool update is not supported");
                 break;
             default:
-                logger.warn("Unable to process event action " + ev.getAction());
+                LOG.warn("Unable to process event action {}", ev.getAction());
                 break;
         }
     }
@@ -199,6 +194,8 @@ public class LBaaSPoolHandler extends AbstractHandler
     /**
      * Useful utility for extracting the loadbalancer instance. With
      * each LB pool, we allow multiple VIP and LB to be instantiated.
+     * @param neutronLBPool Neutron load balancer pool object
+     * @return list of loadbalancer configuration of pool members
      */
     public List<LoadBalancerConfiguration> extractLBConfiguration(NeutronLoadBalancerPool neutronLBPool) {
         String poolProtocol = neutronLBPool.getLoadBalancerPoolProtocol();
@@ -212,7 +209,7 @@ public class LBaaSPoolHandler extends AbstractHandler
 
         List<NeutronLoadBalancerPoolMember> poolMembers = neutronLBPool.getLoadBalancerPoolMembers();
         if (poolMembers.size() == 0) {
-            logger.debug("Neutron LB pool is empty: {}", neutronLBPool);
+            LOG.debug("Neutron LB pool is empty: {}", neutronLBPool);
             return null;
         }
 
@@ -220,11 +217,10 @@ public class LBaaSPoolHandler extends AbstractHandler
 
         /* Iterate over all the Loadbalancers created so far and identify VIP
          */
-        String loadBalancerSubnetID, loadBalancerVip=null, loadBalancerName=null;
         for (NeutronLoadBalancer neutronLB: neutronLBCache.getAllNeutronLoadBalancers()) {
-            loadBalancerSubnetID = neutronLB.getLoadBalancerVipSubnetID();
-            loadBalancerName = neutronLB.getLoadBalancerName();
-            loadBalancerVip = neutronLB.getLoadBalancerVipAddress();
+            String loadBalancerSubnetID = neutronLB.getLoadBalancerVipSubnetID();
+            String loadBalancerName = neutronLB.getLoadBalancerName();
+            String loadBalancerVip = neutronLB.getLoadBalancerVipAddress();
 
             LoadBalancerConfiguration lbConfig = new LoadBalancerConfiguration(loadBalancerName, loadBalancerVip);
             Map.Entry<String,String> providerInfo = NeutronCacheUtils.getProviderInformation(neutronNetworkCache, neutronSubnetCache, loadBalancerSubnetID);
@@ -243,14 +239,13 @@ public class LBaaSPoolHandler extends AbstractHandler
             for (NeutronLoadBalancerPoolMember neutronLBPoolMember: neutronLBPool.getLoadBalancerPoolMembers()) {
                 memberAdminStateIsUp = neutronLBPoolMember.getPoolMemberAdminStateIsUp();
                 memberSubnetID = neutronLBPoolMember.getPoolMemberSubnetID();
-                if (memberSubnetID == null || memberAdminStateIsUp == null) {
-                    continue;
-                } else if (memberSubnetID.equals(loadBalancerSubnetID) && memberAdminStateIsUp.booleanValue()) {
-                    memberID = neutronLBPoolMember.getPoolMemberID();
+                if (memberSubnetID != null && memberAdminStateIsUp != null &&
+                        memberSubnetID.equals(loadBalancerSubnetID) && memberAdminStateIsUp) {
+                    memberID = neutronLBPoolMember.getID();
                     memberIP = neutronLBPoolMember.getPoolMemberAddress();
                     memberPort = neutronLBPoolMember.getPoolMemberProtoPort();
-                    if (memberSubnetID == null || memberID == null || memberIP == null || memberPort == null) {
-                        logger.debug("Neutron LB pool member details incomplete: {}", neutronLBPoolMember);
+                    if (memberID == null || memberIP == null || memberPort == null) {
+                        LOG.debug("Neutron LB pool member details incomplete: {}", neutronLBPoolMember);
                         continue;
                     }
                     memberMAC = NeutronCacheUtils.getMacAddress(neutronPortCache, memberSubnetID, memberIP);
@@ -261,24 +256,23 @@ public class LBaaSPoolHandler extends AbstractHandler
                 }
             }
 
-            if (lbConfig.getMembers().size() > 0)
+            if (lbConfig.getMembers().size() > 0) {
                 lbConfigList.add(lbConfig);
+            }
         }
 
         return lbConfigList;
     }
 
     @Override
-    public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
+    public void setDependencies(ServiceReference serviceReference) {
         loadBalancerProvider =
                 (LoadBalancerProvider) ServiceHelper.getGlobalInstance(LoadBalancerProvider.class, this);
         nodeCacheManager =
                 (NodeCacheManager) ServiceHelper.getGlobalInstance(NodeCacheManager.class, this);
         eventDispatcher =
                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
-        eventDispatcher.eventHandlerAdded(
-                bundleContext.getServiceReference(INeutronLoadBalancerPoolAware.class.getName()), this);
-        super.setDispatcher(eventDispatcher);
+        eventDispatcher.eventHandlerAdded(serviceReference, this);
     }
 
     @Override