General Sonar clean-up
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / PortSecurityHandler.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
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
7  *
8  * Authors : Brent Salisbury, Madhu Venugopal
9  */
10
11 package org.opendaylight.ovsdb.openstack.netvirt;
12
13 import java.net.HttpURLConnection;
14
15 import org.opendaylight.neutron.spi.INeutronSecurityGroupAware;
16 import org.opendaylight.neutron.spi.INeutronSecurityRuleAware;
17 import org.opendaylight.neutron.spi.NeutronSecurityGroup;
18 import org.opendaylight.neutron.spi.NeutronSecurityRule;
19 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
20 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
21 import org.osgi.framework.BundleContext;
22 import org.osgi.framework.ServiceReference;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Handle requests for OpenStack Neutron v2.0 Port Security API calls.
28  */
29 public class PortSecurityHandler extends AbstractHandler
30         implements INeutronSecurityGroupAware, INeutronSecurityRuleAware, ConfigInterface {
31
32     private static final Logger LOG = LoggerFactory.getLogger(PortSecurityHandler.class);
33
34     @Override
35     public int canCreateNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
36         return HttpURLConnection.HTTP_CREATED;
37     }
38
39     @Override
40     public void neutronSecurityGroupCreated(NeutronSecurityGroup neutronSecurityGroup) {
41         int result = canCreateNeutronSecurityGroup(neutronSecurityGroup);
42         if (result != HttpURLConnection.HTTP_CREATED) {
43             LOG.debug("Neutron Security Group creation failed {} ", result);
44         }
45     }
46
47     @Override
48     public int canUpdateNeutronSecurityGroup(NeutronSecurityGroup delta, NeutronSecurityGroup original) {
49         return HttpURLConnection.HTTP_OK;
50     }
51
52     @Override
53     public void neutronSecurityGroupUpdated(NeutronSecurityGroup neutronSecurityGroup) {
54         // Nothing to do
55     }
56
57     @Override
58     public int canDeleteNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
59         return HttpURLConnection.HTTP_OK;
60     }
61
62     @Override
63     public void neutronSecurityGroupDeleted(NeutronSecurityGroup neutronSecurityGroup) {
64         //TODO: Trigger flowmod removals
65         int result = canDeleteNeutronSecurityGroup(neutronSecurityGroup);
66         if  (result != HttpURLConnection.HTTP_OK) {
67             LOG.error(" delete Neutron Security Rule validation failed for result - {} ", result);
68         }
69     }
70
71     /**
72      * Invoked when a Security Rules creation is requested
73      * to indicate if the specified Rule can be created.
74      *
75      * @param neutronSecurityRule  An instance of proposed new Neutron Security Rule object.
76      * @return A HTTP status code to the creation request.
77      */
78
79     @Override
80     public int canCreateNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
81         return HttpURLConnection.HTTP_CREATED;
82     }
83
84     @Override
85     public void neutronSecurityRuleCreated(NeutronSecurityRule neutronSecurityRule) {
86         int result = canCreateNeutronSecurityRule(neutronSecurityRule);
87         if (result != HttpURLConnection.HTTP_CREATED) {
88             LOG.debug("Neutron Security Group creation failed {} ", result);
89         }
90     }
91
92     @Override
93     public int canUpdateNeutronSecurityRule(NeutronSecurityRule delta, NeutronSecurityRule original) {
94         return HttpURLConnection.HTTP_OK;
95     }
96
97     @Override
98     public void neutronSecurityRuleUpdated(NeutronSecurityRule neutronSecurityRule) {
99         // Nothing to do
100     }
101
102     @Override
103     public int canDeleteNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
104         return HttpURLConnection.HTTP_OK;
105     }
106
107     @Override
108     public void neutronSecurityRuleDeleted(NeutronSecurityRule neutronSecurityRule) {
109         int result = canDeleteNeutronSecurityRule(neutronSecurityRule);
110         if  (result != HttpURLConnection.HTTP_OK) {
111             LOG.error(" delete Neutron Security Rule validation failed for result - {} ", result);
112         }
113     }
114
115     /**
116      * Process the event.
117      *
118      * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
119      * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
120      */
121     @Override
122     public void processEvent(AbstractEvent abstractEvent) {
123         if (!(abstractEvent instanceof NorthboundEvent)) {
124             LOG.error("Unable to process abstract event {}", abstractEvent);
125             return;
126         }
127         NorthboundEvent ev = (NorthboundEvent) abstractEvent;
128         switch (ev.getAction()) {
129             // TODO: add handling of events here, once callbacks do something
130             //       other than logging.
131             default:
132                 LOG.warn("Unable to process event action {}", ev.getAction());
133                 break;
134         }
135     }
136
137     @Override
138     public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
139         eventDispatcher =
140                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
141         eventDispatcher.eventHandlerAdded(
142                 bundleContext.getServiceReference(INeutronSecurityGroupAware.class.getName()), this);
143     }
144
145     @Override
146     public void setDependencies(Object impl) {}
147 }