2 * Copyright (c) 2013, 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.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;
24 import com.google.common.base.Preconditions;
26 public class SubnetHandler extends AbstractHandler implements INeutronSubnetAware, ConfigInterface {
28 private static final Logger LOG = LoggerFactory.getLogger(SubnetHandler.class);
30 // The implementation for each of these services is resolved by the OSGi Service Manager
31 private volatile NeutronL3Adapter neutronL3Adapter;
34 public int canCreateSubnet(NeutronSubnet subnet) {
35 return HttpURLConnection.HTTP_OK;
39 public void neutronSubnetCreated(NeutronSubnet subnet) {
40 enqueueEvent(new NorthboundEvent(subnet, Action.ADD));
44 public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original) {
45 return HttpURLConnection.HTTP_OK;
49 public void neutronSubnetUpdated(NeutronSubnet subnet) {
50 enqueueEvent(new NorthboundEvent(subnet, Action.UPDATE));
54 public int canDeleteSubnet(NeutronSubnet subnet) {
55 return HttpURLConnection.HTTP_OK;
59 public void neutronSubnetDeleted(NeutronSubnet subnet) {
60 enqueueEvent(new NorthboundEvent(subnet, Action.DELETE));
66 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
67 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
70 public void processEvent(AbstractEvent abstractEvent) {
71 if (!(abstractEvent instanceof NorthboundEvent)) {
72 LOG.error("Unable to process abstract event {}", abstractEvent);
75 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
76 switch (ev.getAction()) {
82 Preconditions.checkNotNull(neutronL3Adapter);
83 neutronL3Adapter.handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());
86 LOG.warn("Unable to process event action {}", ev.getAction());
92 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
94 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
96 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
97 eventDispatcher.eventHandlerAdded(
98 bundleContext.getServiceReference(INeutronSubnetAware.class.getName()), this);
102 public void setDependencies(Object impl) {