2 * Copyright (C) 2014 Red Hat, Inc.
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
8 * Authors : Dave Tucker, Flavio Fernandes
10 package org.opendaylight.ovsdb.openstack.netvirt;
12 import org.opendaylight.neutron.spi.INeutronFloatingIPAware;
13 import org.opendaylight.neutron.spi.NeutronFloatingIP;
14 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
15 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
16 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;
24 import java.net.HttpURLConnection;
27 * Handle requests for Neutron Floating IP.
29 public class FloatingIPHandler extends AbstractHandler
30 implements INeutronFloatingIPAware, ConfigInterface {
32 static final Logger logger = LoggerFactory.getLogger(FloatingIPHandler.class);
34 // The implementation for each of these services is resolved by the OSGi Service Manager
35 private volatile NeutronL3Adapter neutronL3Adapter;
36 private volatile EventDispatcher eventDispatcher;
39 * Services provide this interface method to indicate if the specified floatingIP can be created
42 * instance of proposed new Neutron FloatingIP object
44 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
45 * results in the create operation being interrupted and the returned status value reflected in the
49 public int canCreateFloatingIP(NeutronFloatingIP floatingIP) {
50 return HttpURLConnection.HTTP_OK;
55 * Services provide this interface method for taking action after a floatingIP has been created
58 * instance of new Neutron FloatingIP object
61 public void neutronFloatingIPCreated(NeutronFloatingIP floatingIP) {
62 enqueueEvent(new NorthboundEvent(floatingIP, Action.ADD));
66 * Services provide this interface method to indicate if the specified floatingIP can be changed using the specified
70 * updates to the floatingIP object using patch semantics
72 * instance of the Neutron FloatingIP object to be updated
74 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
75 * results in the update operation being interrupted and the returned status value reflected in the
79 public int canUpdateFloatingIP(NeutronFloatingIP delta, NeutronFloatingIP original) {
80 return HttpURLConnection.HTTP_OK;
84 * Services provide this interface method for taking action after a floatingIP has been updated
87 * instance of modified Neutron FloatingIP object
90 public void neutronFloatingIPUpdated(NeutronFloatingIP floatingIP) {
91 enqueueEvent(new NorthboundEvent(floatingIP, Action.UPDATE));
95 * Services provide this interface method to indicate if the specified floatingIP can be deleted
98 * instance of the Neutron FloatingIP object to be deleted
100 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
101 * results in the delete operation being interrupted and the returned status value reflected in the
105 public int canDeleteFloatingIP(NeutronFloatingIP floatingIP) {
106 return HttpURLConnection.HTTP_OK;
110 * Services provide this interface method for taking action after a floatingIP has been deleted
113 * instance of deleted Neutron FloatingIP object
116 public void neutronFloatingIPDeleted(NeutronFloatingIP floatingIP) {
117 enqueueEvent(new NorthboundEvent(floatingIP, Action.DELETE));
123 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
124 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
127 public void processEvent(AbstractEvent abstractEvent) {
128 if (!(abstractEvent instanceof NorthboundEvent)) {
129 logger.error("Unable to process abstract event " + abstractEvent);
132 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
133 switch (ev.getAction()) {
139 neutronL3Adapter.handleNeutronFloatingIPEvent(ev.getNeutronFloatingIP(), ev.getAction());
142 logger.warn("Unable to process event action " + ev.getAction());
148 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
150 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
151 eventDispatcher.eventHandlerAdded(
152 bundleContext.getServiceReference(INeutronFloatingIPAware.class.getName()), this);
153 super.setDispatcher(eventDispatcher);
155 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
159 public void setDependencies(Object impl) {}