2 * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.openstack.netvirt;
11 import java.net.HttpURLConnection;
13 import org.opendaylight.neutron.spi.INeutronFloatingIPAware;
14 import org.opendaylight.neutron.spi.NeutronFloatingIP;
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;
25 * Handle requests for Neutron Floating IP.
27 public class FloatingIPHandler extends AbstractHandler
28 implements INeutronFloatingIPAware, ConfigInterface {
30 private static final Logger LOG = LoggerFactory.getLogger(FloatingIPHandler.class);
32 // The implementation for each of these services is resolved by the OSGi Service Manager
33 private volatile NeutronL3Adapter neutronL3Adapter;
36 * Services provide this interface method to indicate if the specified floatingIP can be created
39 * instance of proposed new Neutron FloatingIP object
41 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
42 * results in the create operation being interrupted and the returned status value reflected in the
46 public int canCreateFloatingIP(NeutronFloatingIP floatingIP) {
47 return HttpURLConnection.HTTP_OK;
52 * Services provide this interface method for taking action after a floatingIP has been created
55 * instance of new Neutron FloatingIP object
58 public void neutronFloatingIPCreated(NeutronFloatingIP floatingIP) {
59 enqueueEvent(new NorthboundEvent(floatingIP, Action.ADD));
63 * Services provide this interface method to indicate if the specified floatingIP can be changed using the specified
67 * updates to the floatingIP object using patch semantics
69 * instance of the Neutron FloatingIP object to be updated
71 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
72 * results in the update operation being interrupted and the returned status value reflected in the
76 public int canUpdateFloatingIP(NeutronFloatingIP delta, NeutronFloatingIP original) {
77 return HttpURLConnection.HTTP_OK;
81 * Services provide this interface method for taking action after a floatingIP has been updated
84 * instance of modified Neutron FloatingIP object
87 public void neutronFloatingIPUpdated(NeutronFloatingIP floatingIP) {
88 enqueueEvent(new NorthboundEvent(floatingIP, Action.UPDATE));
92 * Services provide this interface method to indicate if the specified floatingIP can be deleted
95 * instance of the Neutron FloatingIP object to be deleted
97 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
98 * results in the delete operation being interrupted and the returned status value reflected in the
102 public int canDeleteFloatingIP(NeutronFloatingIP floatingIP) {
103 return HttpURLConnection.HTTP_OK;
107 * Services provide this interface method for taking action after a floatingIP has been deleted
110 * instance of deleted Neutron FloatingIP object
113 public void neutronFloatingIPDeleted(NeutronFloatingIP floatingIP) {
114 enqueueEvent(new NorthboundEvent(floatingIP, Action.DELETE));
120 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
121 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
124 public void processEvent(AbstractEvent abstractEvent) {
125 if (!(abstractEvent instanceof NorthboundEvent)) {
126 LOG.error("Unable to process abstract event {}", abstractEvent);
129 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
130 switch (ev.getAction()) {
136 neutronL3Adapter.handleNeutronFloatingIPEvent(ev.getNeutronFloatingIP(), ev.getAction());
139 LOG.warn("Unable to process event action {}", ev.getAction());
145 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
147 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
148 eventDispatcher.eventHandlerAdded(
149 bundleContext.getServiceReference(INeutronFloatingIPAware.class.getName()), this);
151 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
155 public void setDependencies(Object impl) {}