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 java.net.HttpURLConnection;
14 import org.opendaylight.neutron.spi.INeutronFloatingIPAware;
15 import org.opendaylight.neutron.spi.NeutronFloatingIP;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
17 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
18 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
19 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
20 import org.osgi.framework.BundleContext;
21 import org.osgi.framework.ServiceReference;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Handle requests for Neutron Floating IP.
28 public class FloatingIPHandler extends AbstractHandler
29 implements INeutronFloatingIPAware, ConfigInterface {
31 private static final Logger LOG = LoggerFactory.getLogger(FloatingIPHandler.class);
33 // The implementation for each of these services is resolved by the OSGi Service Manager
34 private volatile NeutronL3Adapter neutronL3Adapter;
37 * Services provide this interface method to indicate if the specified floatingIP can be created
40 * instance of proposed new Neutron FloatingIP object
42 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
43 * results in the create operation being interrupted and the returned status value reflected in the
47 public int canCreateFloatingIP(NeutronFloatingIP floatingIP) {
48 return HttpURLConnection.HTTP_OK;
53 * Services provide this interface method for taking action after a floatingIP has been created
56 * instance of new Neutron FloatingIP object
59 public void neutronFloatingIPCreated(NeutronFloatingIP floatingIP) {
60 enqueueEvent(new NorthboundEvent(floatingIP, Action.ADD));
64 * Services provide this interface method to indicate if the specified floatingIP can be changed using the specified
68 * updates to the floatingIP object using patch semantics
70 * instance of the Neutron FloatingIP object to be updated
72 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
73 * results in the update operation being interrupted and the returned status value reflected in the
77 public int canUpdateFloatingIP(NeutronFloatingIP delta, NeutronFloatingIP original) {
78 return HttpURLConnection.HTTP_OK;
82 * Services provide this interface method for taking action after a floatingIP has been updated
85 * instance of modified Neutron FloatingIP object
88 public void neutronFloatingIPUpdated(NeutronFloatingIP floatingIP) {
89 enqueueEvent(new NorthboundEvent(floatingIP, Action.UPDATE));
93 * Services provide this interface method to indicate if the specified floatingIP can be deleted
96 * instance of the Neutron FloatingIP object to be deleted
98 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
99 * results in the delete operation being interrupted and the returned status value reflected in the
103 public int canDeleteFloatingIP(NeutronFloatingIP floatingIP) {
104 return HttpURLConnection.HTTP_OK;
108 * Services provide this interface method for taking action after a floatingIP has been deleted
111 * instance of deleted Neutron FloatingIP object
114 public void neutronFloatingIPDeleted(NeutronFloatingIP floatingIP) {
115 enqueueEvent(new NorthboundEvent(floatingIP, Action.DELETE));
121 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
122 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
125 public void processEvent(AbstractEvent abstractEvent) {
126 if (!(abstractEvent instanceof NorthboundEvent)) {
127 LOG.error("Unable to process abstract event {}", abstractEvent);
130 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
131 switch (ev.getAction()) {
137 neutronL3Adapter.handleNeutronFloatingIPEvent(ev.getNeutronFloatingIP(), ev.getAction());
140 LOG.warn("Unable to process event action {}", ev.getAction());
146 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
148 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
149 eventDispatcher.eventHandlerAdded(
150 bundleContext.getServiceReference(INeutronFloatingIPAware.class.getName()), this);
152 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
156 public void setDependencies(Object impl) {}