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.ServiceReference;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Handle requests for Neutron Floating IP.
26 public class FloatingIPHandler extends AbstractHandler
27 implements INeutronFloatingIPAware, ConfigInterface {
29 private static final Logger LOG = LoggerFactory.getLogger(FloatingIPHandler.class);
31 // The implementation for each of these services is resolved by the OSGi Service Manager
32 private volatile NeutronL3Adapter neutronL3Adapter;
35 * Services provide this interface method to indicate if the specified floatingIP can be created
38 * instance of proposed new Neutron FloatingIP object
40 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
41 * results in the create operation being interrupted and the returned status value reflected in the
45 public int canCreateFloatingIP(NeutronFloatingIP floatingIP) {
46 return HttpURLConnection.HTTP_OK;
51 * Services provide this interface method for taking action after a floatingIP has been created
54 * instance of new Neutron FloatingIP object
57 public void neutronFloatingIPCreated(NeutronFloatingIP floatingIP) {
58 enqueueEvent(new NorthboundEvent(floatingIP, Action.ADD));
62 * Services provide this interface method to indicate if the specified floatingIP can be changed using the specified
66 * updates to the floatingIP object using patch semantics
68 * instance of the Neutron FloatingIP object to be updated
70 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
71 * results in the update operation being interrupted and the returned status value reflected in the
75 public int canUpdateFloatingIP(NeutronFloatingIP delta, NeutronFloatingIP original) {
76 return HttpURLConnection.HTTP_OK;
80 * Services provide this interface method for taking action after a floatingIP has been updated
83 * instance of modified Neutron FloatingIP object
86 public void neutronFloatingIPUpdated(NeutronFloatingIP floatingIP) {
87 enqueueEvent(new NorthboundEvent(floatingIP, Action.UPDATE));
91 * Services provide this interface method to indicate if the specified floatingIP can be deleted
94 * instance of the Neutron FloatingIP object to be deleted
96 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
97 * results in the delete operation being interrupted and the returned status value reflected in the
101 public int canDeleteFloatingIP(NeutronFloatingIP floatingIP) {
102 return HttpURLConnection.HTTP_OK;
106 * Services provide this interface method for taking action after a floatingIP has been deleted
109 * instance of deleted Neutron FloatingIP object
112 public void neutronFloatingIPDeleted(NeutronFloatingIP floatingIP) {
113 enqueueEvent(new NorthboundEvent(floatingIP, Action.DELETE));
119 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
120 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
123 public void processEvent(AbstractEvent abstractEvent) {
124 if (!(abstractEvent instanceof NorthboundEvent)) {
125 LOG.error("Unable to process abstract event {}", abstractEvent);
128 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
129 switch (ev.getAction()) {
135 neutronL3Adapter.handleNeutronFloatingIPEvent(ev.getNeutronFloatingIP(), ev.getAction());
138 LOG.warn("Unable to process event action {}", ev.getAction());
144 public void setDependencies(ServiceReference serviceReference) {
146 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
148 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
149 eventDispatcher.eventHandlerAdded(serviceReference, this);
153 public void setDependencies(Object impl) {}