Removed the ovsdb subdirectory properly in lieu of the upcoming rebase with master
[netvirt.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / PortHandler.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 : Madhu Venugopal, Brent Salisbury
9  */
10 package org.opendaylight.ovsdb.neutron;
11
12 import java.net.HttpURLConnection;
13
14 import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware;
15 import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Handle requests for Neutron Port.
21  */
22 public class PortHandler extends BaseHandler
23                          implements INeutronPortAware {
24
25     /**
26      * Logger instance.
27      */
28     static final Logger logger = LoggerFactory.getLogger(PortHandler.class);
29
30     /**
31      * Invoked when a port creation is requested
32      * to indicate if the specified port can be created.
33      *
34      * @param port     An instance of proposed new Port object.
35      * @return A HTTP status code to the creation request.
36      */
37     @Override
38     public int canCreatePort(NeutronPort port) {
39         return HttpURLConnection.HTTP_CREATED;
40     }
41
42     /**
43      * Invoked to take action after a port has been created.
44      *
45      * @param port An instance of new Neutron Port object.
46      */
47     @Override
48     public void neutronPortCreated(NeutronPort port) {
49         int result = canCreatePort(port);
50         if (result != HttpURLConnection.HTTP_CREATED) {
51             logger.error(" Port create validation failed result - {} ", result);
52             return;
53         }
54
55         logger.debug(" Port-ADD successful for tenant-id - {}," +
56                      " network-id - {}, port-id - {}, result - {} ",
57                      port.getTenantID(), port.getNetworkUUID(),
58                      port.getID(), result);
59     }
60
61     /**
62      * Invoked when a port update is requested
63      * to indicate if the specified port can be changed
64      * using the specified delta.
65      *
66      * @param delta    Updates to the port object using patch semantics.
67      * @param original An instance of the Neutron Port object
68      *                  to be updated.
69      * @return A HTTP status code to the update request.
70      */
71     @Override
72     public int canUpdatePort(NeutronPort delta,
73                              NeutronPort original) {
74         int result = HttpURLConnection.HTTP_OK;
75         /**
76          * To basic validation of the request
77          */
78
79         if ((original == null) || (delta == null)) {
80             logger.error("port object not specified");
81             return HttpURLConnection.HTTP_BAD_REQUEST;
82         }
83         return result;
84     }
85
86     /**
87      * Invoked to take action after a port has been updated.
88      *
89      * @param port An instance of modified Neutron Port object.
90      */
91     @Override
92     public void neutronPortUpdated(NeutronPort port) {
93     }
94
95     /**
96      * Invoked when a port deletion is requested
97      * to indicate if the specified port can be deleted.
98      *
99      * @param port     An instance of the Neutron Port object to be deleted.
100      * @return A HTTP status code to the deletion request.
101      */
102     @Override
103     public int canDeletePort(NeutronPort port) {
104         return HttpURLConnection.HTTP_OK;
105     }
106
107     /**
108      * Invoked to take action after a port has been deleted.
109      *
110      * @param port  An instance of deleted Neutron Port object.
111      */
112     @Override
113     public void neutronPortDeleted(NeutronPort port) {
114
115         int result = canDeletePort(port);
116         if  (result != HttpURLConnection.HTTP_OK) {
117             logger.error(" deletePort validation failed - result {} ", result);
118             return;
119         }
120
121         logger.debug(" PORT delete successful for tenant-id - {}, " +
122                      " network-id - {}, port-id - {}",
123                      port.getTenantID(), port.getNetworkUUID(),
124                      port.getID());
125     }
126 }