Merge "Clean up logging"
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / SubnetHandler.java
index 82ce662f31f30781d8c00a6a3c46f40de3a12ca8..d477d87659cb86b54c69ac4b77d7fe59c1e9ed38 100644 (file)
 
 package org.opendaylight.ovsdb.openstack.netvirt;
 
-import org.opendaylight.controller.networkconfig.neutron.INeutronSubnetAware;
-import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;
+import java.net.HttpURLConnection;
 
+import org.opendaylight.neutron.spi.INeutronSubnetAware;
+import org.opendaylight.neutron.spi.NeutronSubnet;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
+import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
+import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
+import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.net.HttpURLConnection;
+import com.google.common.base.Preconditions;
 
-public class SubnetHandler extends AbstractHandler implements INeutronSubnetAware {
+public class SubnetHandler extends AbstractHandler implements INeutronSubnetAware, ConfigInterface {
 
-    static final Logger logger = LoggerFactory.getLogger(SubnetHandler.class);
+    private static final Logger LOG = LoggerFactory.getLogger(SubnetHandler.class);
+
+    // The implementation for each of these services is resolved by the OSGi Service Manager
+    private volatile NeutronL3Adapter neutronL3Adapter;
 
     @Override
     public int canCreateSubnet(NeutronSubnet subnet) {
-        return HttpURLConnection.HTTP_CREATED;
+        return HttpURLConnection.HTTP_OK;
     }
 
     @Override
     public void neutronSubnetCreated(NeutronSubnet subnet) {
-        logger.debug("Neutron Subnet Creation : {}", subnet.toString());
+        enqueueEvent(new NorthboundEvent(subnet, Action.ADD));
     }
 
     @Override
     public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original) {
-        return HttpURLConnection.HTTP_CREATED;
+        return HttpURLConnection.HTTP_OK;
     }
 
     @Override
     public void neutronSubnetUpdated(NeutronSubnet subnet) {
-        // TODO Auto-generated method stub
-
+        enqueueEvent(new NorthboundEvent(subnet, Action.UPDATE));
     }
 
     @Override
     public int canDeleteSubnet(NeutronSubnet subnet) {
-        // TODO Auto-generated method stub
-        return HttpURLConnection.HTTP_CREATED;
+        return HttpURLConnection.HTTP_OK;
     }
 
     @Override
     public void neutronSubnetDeleted(NeutronSubnet subnet) {
-        // TODO Auto-generated method stub
+        enqueueEvent(new NorthboundEvent(subnet, Action.DELETE));
+    }
+
+    /**
+     * Process the event.
+     *
+     * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
+     * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
+     */
+    @Override
+    public void processEvent(AbstractEvent abstractEvent) {
+        if (!(abstractEvent instanceof NorthboundEvent)) {
+            LOG.error("Unable to process abstract event {}", abstractEvent);
+            return;
+        }
+        NorthboundEvent ev = (NorthboundEvent) abstractEvent;
+        switch (ev.getAction()) {
+            case ADD:
+                // fall through
+            case DELETE:
+                // fall through
+            case UPDATE:
+                Preconditions.checkNotNull(neutronL3Adapter);
+                neutronL3Adapter.handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());
+                break;
+            default:
+                LOG.warn("Unable to process event action {}", ev.getAction());
+                break;
+        }
+    }
+
+    @Override
+    public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
+        neutronL3Adapter =
+                (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
+        eventDispatcher =
+                (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
+        eventDispatcher.eventHandlerAdded(
+                bundleContext.getServiceReference(INeutronSubnetAware.class.getName()), this);
+    }
+
+    @Override
+    public void setDependencies(Object impl) {
 
     }
 }