Use config instead of Activator for netvirt and netvirt-providers
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / SubnetHandler.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Authors : Madhu Venugopal, Brent Salisbury
9  */
10
11 package org.opendaylight.ovsdb.openstack.netvirt;
12
13 import org.opendaylight.neutron.spi.INeutronSubnetAware;
14 import org.opendaylight.neutron.spi.NeutronSubnet;
15 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
17 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
18
19 import com.google.common.base.Preconditions;
20 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
21 import org.osgi.framework.BundleContext;
22 import org.osgi.framework.ServiceReference;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import java.net.HttpURLConnection;
27
28 public class SubnetHandler extends AbstractHandler implements INeutronSubnetAware, ConfigInterface {
29
30     static final Logger logger = LoggerFactory.getLogger(SubnetHandler.class);
31
32     // The implementation for each of these services is resolved by the OSGi Service Manager
33     private volatile NeutronL3Adapter neutronL3Adapter;
34     private EventDispatcher eventDispatcher;
35
36     @Override
37     public int canCreateSubnet(NeutronSubnet subnet) {
38         return HttpURLConnection.HTTP_OK;
39     }
40
41     @Override
42     public void neutronSubnetCreated(NeutronSubnet subnet) {
43         enqueueEvent(new NorthboundEvent(subnet, Action.ADD));
44     }
45
46     @Override
47     public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original) {
48         return HttpURLConnection.HTTP_OK;
49     }
50
51     @Override
52     public void neutronSubnetUpdated(NeutronSubnet subnet) {
53         enqueueEvent(new NorthboundEvent(subnet, Action.UPDATE));
54     }
55
56     @Override
57     public int canDeleteSubnet(NeutronSubnet subnet) {
58         return HttpURLConnection.HTTP_OK;
59     }
60
61     @Override
62     public void neutronSubnetDeleted(NeutronSubnet subnet) {
63         enqueueEvent(new NorthboundEvent(subnet, Action.DELETE));
64     }
65
66     /**
67      * Process the event.
68      *
69      * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
70      * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
71      */
72     @Override
73     public void processEvent(AbstractEvent abstractEvent) {
74         if (!(abstractEvent instanceof NorthboundEvent)) {
75             logger.error("Unable to process abstract event " + abstractEvent);
76             return;
77         }
78         NorthboundEvent ev = (NorthboundEvent) abstractEvent;
79         switch (ev.getAction()) {
80             case ADD:
81                 // fall through
82             case DELETE:
83                 // fall through
84             case UPDATE:
85                 Preconditions.checkNotNull(neutronL3Adapter);
86                 neutronL3Adapter.handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());
87                 break;
88             default:
89                 logger.warn("Unable to process event action " + ev.getAction());
90                 break;
91         }
92     }
93
94     @Override
95     public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
96         neutronL3Adapter =
97                 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
98         eventDispatcher =
99                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
100         eventDispatcher.eventHandlerAdded(
101                 bundleContext.getServiceReference(INeutronSubnetAware.class.getName()), this);
102         super.setDispatcher(eventDispatcher);
103     }
104
105     @Override
106     public void setDependencies(Object impl) {
107
108     }
109 }