Fix license header violations in net-virt
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / SubnetHandler.java
1 /*
2  * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.openstack.netvirt;
10
11 import java.net.HttpURLConnection;
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 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
19 import org.osgi.framework.BundleContext;
20 import org.osgi.framework.ServiceReference;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import com.google.common.base.Preconditions;
25
26 public class SubnetHandler extends AbstractHandler implements INeutronSubnetAware, ConfigInterface {
27
28     private static final Logger LOG = LoggerFactory.getLogger(SubnetHandler.class);
29
30     // The implementation for each of these services is resolved by the OSGi Service Manager
31     private volatile NeutronL3Adapter neutronL3Adapter;
32
33     @Override
34     public int canCreateSubnet(NeutronSubnet subnet) {
35         return HttpURLConnection.HTTP_OK;
36     }
37
38     @Override
39     public void neutronSubnetCreated(NeutronSubnet subnet) {
40         enqueueEvent(new NorthboundEvent(subnet, Action.ADD));
41     }
42
43     @Override
44     public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original) {
45         return HttpURLConnection.HTTP_OK;
46     }
47
48     @Override
49     public void neutronSubnetUpdated(NeutronSubnet subnet) {
50         enqueueEvent(new NorthboundEvent(subnet, Action.UPDATE));
51     }
52
53     @Override
54     public int canDeleteSubnet(NeutronSubnet subnet) {
55         return HttpURLConnection.HTTP_OK;
56     }
57
58     @Override
59     public void neutronSubnetDeleted(NeutronSubnet subnet) {
60         enqueueEvent(new NorthboundEvent(subnet, Action.DELETE));
61     }
62
63     /**
64      * Process the event.
65      *
66      * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
67      * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
68      */
69     @Override
70     public void processEvent(AbstractEvent abstractEvent) {
71         if (!(abstractEvent instanceof NorthboundEvent)) {
72             LOG.error("Unable to process abstract event {}", abstractEvent);
73             return;
74         }
75         NorthboundEvent ev = (NorthboundEvent) abstractEvent;
76         switch (ev.getAction()) {
77             case ADD:
78                 // fall through
79             case DELETE:
80                 // fall through
81             case UPDATE:
82                 Preconditions.checkNotNull(neutronL3Adapter);
83                 neutronL3Adapter.handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());
84                 break;
85             default:
86                 LOG.warn("Unable to process event action {}", ev.getAction());
87                 break;
88         }
89     }
90
91     @Override
92     public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
93         neutronL3Adapter =
94                 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
95         eventDispatcher =
96                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
97         eventDispatcher.eventHandlerAdded(
98                 bundleContext.getServiceReference(INeutronSubnetAware.class.getName()), this);
99     }
100
101     @Override
102     public void setDependencies(Object impl) {
103
104     }
105 }