GET API uses @Consumes annotation incorrectly, while it should be @Produces.
[ovsdb.git] / northbound / src / main / java / org / opendaylight / ovsdb / northbound / OvsdbNorthboundV2.java
1 /*
2  * Copyright (C) 2014 Red Hat, Inc. and others
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, Dave Tucker
9  */
10 package org.opendaylight.ovsdb.northbound;
11
12 import java.io.IOException;
13 import java.util.Map;
14 import java.util.concurrent.ExecutionException;
15
16 import javax.ws.rs.Consumes;
17 import javax.ws.rs.DELETE;
18 import javax.ws.rs.GET;
19 import javax.ws.rs.POST;
20 import javax.ws.rs.PUT;
21 import javax.ws.rs.Path;
22 import javax.ws.rs.PathParam;
23 import javax.ws.rs.Produces;
24 import javax.ws.rs.core.Context;
25 import javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
27 import javax.ws.rs.core.SecurityContext;
28 import javax.ws.rs.core.UriInfo;
29
30 import org.codehaus.enunciate.jaxrs.ResponseCode;
31 import org.codehaus.enunciate.jaxrs.StatusCodes;
32 import org.codehaus.enunciate.jaxrs.TypeHint;
33 import org.opendaylight.controller.northbound.commons.RestMessages;
34 import org.opendaylight.controller.northbound.commons.exception.BadRequestException;
35 import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException;
36 import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
37 import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
38 import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
39 import org.opendaylight.controller.sal.authorization.Privilege;
40 import org.opendaylight.controller.sal.core.Node;
41 import org.opendaylight.controller.sal.utils.ServiceHelper;
42 import org.opendaylight.controller.sal.utils.Status;
43 import org.opendaylight.ovsdb.lib.OvsdbClient;
44 import org.opendaylight.ovsdb.lib.notation.Row;
45 import org.opendaylight.ovsdb.lib.notation.UUID;
46 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
47 import org.opendaylight.ovsdb.plugin.api.OvsVswitchdSchemaConstants;
48 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
49 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
50 import org.opendaylight.ovsdb.plugin.api.StatusWithUuid;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53
54 import com.fasterxml.jackson.databind.JsonNode;
55
56 /**
57 * OVSDB Northbound REST API.<br>
58 * This class provides REST APIs to Create, Read, Update and Delete OVSDB Row in any of the ovsdb table
59 * database one at a time. The JSON used to create rows is in the same format as the OVSDB JSON-RPC messages.
60 * This format is documented in the <a href="http://openvswitch.org/ovs-vswitchd.conf.db.5.pdf">OVSDB Schema</a>
61 * and in <a href="http://tools.ietf.org/rfc/rfc7047.txt">RFC 7047</a>.
62 *
63 * <br>
64 * <br>
65 * Authentication scheme : <b>HTTP Basic</b><br>
66 * Authentication realm : <b>opendaylight</b><br>
67 * Transport : <b>HTTP and HTTPS</b><br>
68 * <br>
69 * HTTPS Authentication is disabled by default.
70 */
71
72 @Path("/v2/")
73 @Deprecated
74 public class OvsdbNorthboundV2 {
75     protected static final Logger logger = LoggerFactory.getLogger(OvsdbNorthboundV2.class);
76
77     @Context
78     private UriInfo _uriInfo;
79     private String username;
80
81     @Context
82     public void setSecurityContext(SecurityContext context) {
83         if (context != null && context.getUserPrincipal() != null) {
84             username = context.getUserPrincipal().getName();
85         }
86     }
87
88     protected String getUserName() {
89         return username;
90     }
91
92     private void handleNameMismatch(String name, String nameinURL) {
93         if (name == null || nameinURL == null) {
94             throw new BadRequestException(RestMessages.INVALIDDATA.toString() + " : Name is null");
95         }
96
97         if (name.equalsIgnoreCase(nameinURL)) {
98             return;
99         }
100         throw new ResourceConflictException(RestMessages.INVALIDDATA.toString()
101                 + " : Table Name in URL does not match the row name in request body");
102     }
103
104     /**
105      * Create a Row for Open_vSwitch schema
106      *
107      * @param nodeType type of node e.g OVS
108      * @param nodeId ID of the node
109      * @param tableName name of the OVSDB table
110      * @param row the {@link OvsdbRow} Row that is being inserted
111      *
112      * @return Response as dictated by the HTTP Response Status code
113      *
114      * <br>
115      * Examples:
116      * <br>
117      * Create a Bridge Row:
118      * <pre>
119      *
120      * Request URL:
121      * POST http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/bridge/rows
122      *
123      * JSON:
124      * {
125      *   "row": {
126      *     "Bridge": {
127      *       "name": "bridge1",
128      *       "datapath_type": "OPENFLOW"
129      *     }
130      *   }
131      * }
132      * </pre>
133      *
134      *
135      * Create a Port Row:
136      * <pre>
137      *
138      * Request URL:
139      * POST http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/port/rows
140      *
141      * JSON:
142      * {
143      *   "parent_uuid": "b01cd26b-9c63-4216-8cf2-55f7087adab1",
144      *   "row": {
145      *     "Port": {
146      *       "name": "port1",
147      *       "mac": [
148      *         "set",
149      *         "00:00:00:00:00:01"
150      *       ],
151      *       "tag": [
152      *         "set",
153      *         200
154      *       ]
155      *     }
156      *   }
157      * }
158      * </pre>
159      *
160      *
161      * Create an Interface Row:
162      * <pre>
163      *
164      * Request URL:
165      * POST http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/interface/rows
166      *
167      * JSON:
168      * {
169      *   "parent_uuid": "c7b54c9b-9b25-4801-a81d-d7bc489d4840",
170      *   "row": {
171      *     "Interface": {
172      *       "name": "br2",
173      *       "mac": [
174      *         "set",
175      *         "00:00:bb:bb:00:01"
176      *       ],
177      *       "admin_state": "up"
178      *     }
179      *   }
180      * }
181      * </pre>
182      *
183      *
184      * Create an SSL Row:
185      * <pre>
186      *
187      * Request URL:
188      * POST http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/SSL/rows
189      *
190      * JSON:
191      * {
192      *   "row": {
193      *     "SSL": {
194      *       "name": "mySSL",
195      *       "ca_cert": "ca_cert",
196      *       "bootstrap_ca_cert": true,
197      *       "certificate": "pieceofpaper",
198      *       "private_key": "private"
199      *     }
200      *   }
201      * }
202      * </pre>
203      *
204      *
205      * Create an sFlow Row:
206      * <pre>
207      *
208      * Request URL:
209      * POST http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/sflow/rows
210      *
211      * JSON:
212      * {
213      *   "parent_uuid": "6b3072ba-a120-4db9-82f8-a8ce4eae6942",
214      *   "row": {
215      *     "sFlow": {
216      *       "agent": [
217      *         "set",
218      *         "agent_string"
219      *       ],
220      *       "targets": [
221      *         "set",
222      *         "targets_string"
223      *       ]
224      *     }
225      *   }
226      * }
227      * </pre>
228      *
229      *
230      * Create a QoS Row:
231      * <pre>
232      *
233      * Request URL:
234      * POST http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/qos/rows
235      *
236      * JSON:
237      * {
238      *   "parent_uuid": "b109dbcf-47bb-4121-b244-e623b3421d6e",
239      *   "row": {
240      *     "QoS": {
241      *       "type": "linux-htb"
242      *     }
243      *   }
244      * }
245      * </pre>
246      *
247      *
248      * Create a Queue Row:
249      * <pre>
250      *
251      * Request URL:
252      * POST http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/queue/rows
253      *
254      * {
255      *   "parent_uuid": "b16eae7d-7e97-46d2-95d1-333d1de4a3d7",
256      *   "row": {
257      *     "Queue": {
258      *       "dscp": [
259      *         "set",
260      *         "25"
261      *       ]
262      *     }
263      *   }
264      * }
265      * </pre>
266      *
267      *
268      * Create a Netflow Row:
269      * <pre>
270      *
271      * Request URL:
272      * POST http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/netflow/rows
273      *
274      * JSON:
275      * {
276      *   "parent_uuid": "b01cd26b-9c63-4216-8cf2-55f7087adab1",
277      *   "row": {
278      *     "NetFlow": {
279      *       "targets": [
280      *         "set",
281      *         [
282      *           "192.168.1.102:9998"
283      *         ]
284      *       ],
285      *       "active_timeout": "0"
286      *     }
287      *   }
288      * }
289      * </pre>
290      *
291      *
292      * Create a Manager Row:
293      * <pre>
294      *
295      * Request URL:
296      * POST http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/manager/rows
297      *
298      * JSON:
299      * {
300      *   "parent_uuid": "8d3fb89b-5fac-4631-a990-f5a4e7f5383a",
301      *   "row": {
302      *     "Manager": {
303      *       "target": "a_string",
304      *       "is_connected": true,
305      *       "state": "active"
306      *     }
307      *   }
308      * }
309      * </pre>
310      * @throws IOException
311      * @throws ExecutionException
312      * @throws InterruptedException
313      */
314
315     @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows")
316     @POST
317     @StatusCodes({ @ResponseCode(code = 201, condition = "Row Inserted successfully"),
318         @ResponseCode(code = 400, condition = "Invalid data passed"),
319         @ResponseCode(code = 401, condition = "User not authorized to perform this operation")})
320     @Consumes({ MediaType.APPLICATION_JSON})
321     public Response addRow(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
322                            @PathParam("tableName") String tableName, JsonNode rowJson) throws IOException, InterruptedException, ExecutionException {
323
324         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
325             throw new UnauthorizedException("User is not authorized to perform this operation");
326         }
327
328         OvsdbConfigurationService
329                 ovsdbTable = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class,
330                                                                                             this);
331         if (ovsdbTable == null) {
332             throw new ServiceUnavailableException("OVS Configuration Service " + RestMessages.SERVICEUNAVAILABLE.toString());
333         }
334
335         Node node = Node.fromString(nodeType, nodeId);
336         OvsdbConnectionService
337                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
338         OvsdbClient client = connectionService.getConnection(node).getClient();
339         OvsdbRow localRow = OvsdbRow.fromJsonNode(client, OvsVswitchdSchemaConstants.DATABASE_NAME, rowJson);
340         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
341
342         if (localRow == null) {
343             return Response.status(Response.Status.BAD_REQUEST).build();
344         }
345
346         StatusWithUuid
347                 statusWithUuid = ovsdbTable.insertRow(node, bckCompatibleTableName, localRow.getParentUuid(), localRow.getRow());
348
349         if (statusWithUuid.isSuccess()) {
350             UUID uuid = statusWithUuid.getUuid();
351             return Response.status(Response.Status.CREATED)
352                     .header("Location", String.format("%s/%s", _uriInfo.getAbsolutePath().toString(),
353                                                                 uuid.toString()))
354                     .entity(uuid.toString())
355                     .build();
356         }
357         return NorthboundUtils.getResponse(statusWithUuid);
358     }
359
360     /**
361      * Read a Row
362      *
363      * @param nodeType type of node e.g OVS
364      * @param nodeId ID of the node
365      * @param tableName name of the ovsdb table
366      * @param rowUuid UUID of the row being read
367      *
368      * @return Row corresponding to the UUID.
369      *
370      * <br>
371      * Examples:
372      * <br>
373      * <pre>
374      * Get a specific Bridge Row:
375      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/bridge/rows/6f4c602c-026f-4390-beea-d50d6d448100
376      *
377      * Get a specific Port Row:
378      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/port/rows/6f4c602c-026f-4390-beea-d50d6d448100
379      *
380      * Get a specific Interface Row:
381      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/interface/rows/6f4c602c-026f-4390-beea-d50d6d448100
382      *
383      * Get a specific Controller Row:
384      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/controller/rows/6f4c602c-026f-4390-beea-d50d6d448100
385      *
386      * Get a specific SSL Row:
387      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/SSL/rows/6f4c602c-026f-4390-beea-d50d6d448100
388      *
389      * Get a specific sFlow Row:
390      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/sflow/rows/6f4c602c-026f-4390-beea-d50d6d448100
391      *
392      * Get a specific QoS Row:
393      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/qos/rows/6f4c602c-026f-4390-beea-d50d6d448100
394      *
395      * Get a specific Queue Row:
396      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/queue/rows/6f4c602c-026f-4390-beea-d50d6d448100
397      *
398      * Get a specific Netflow Row:
399      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/netflow/rows/6f4c602c-026f-4390-beea-d50d6d448100
400      *
401      * Get a specific Manager Row:
402      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/manager/rows/6f4c602c-026f-4390-beea-d50d6d448100
403      * </pre>
404      */
405
406     @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows/{rowUuid}")
407     @GET
408     @StatusCodes({ @ResponseCode(code = 200, condition = "Row Updated successfully"),
409         @ResponseCode(code = 400, condition = "Invalid data passed"),
410         @ResponseCode(code = 401, condition = "User not authorized to perform this operation")})
411     @Produces({ MediaType.APPLICATION_JSON})
412     @TypeHint(Row.class)
413     public Row getRow(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
414                            @PathParam("tableName") String tableName, @PathParam("rowUuid") String rowUuid) {
415
416         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
417             throw new UnauthorizedException("User is not authorized to perform this operation");
418         }
419
420         OvsdbConfigurationService
421                 ovsdbTable = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class,
422                                                                                             this);
423         if (ovsdbTable == null) {
424             throw new ServiceUnavailableException("UserManager " + RestMessages.SERVICEUNAVAILABLE.toString());
425         }
426
427         Node node = Node.fromString(nodeType, nodeId);
428         OvsdbConnectionService
429                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
430         OvsdbClient client = connectionService.getConnection(node).getClient();
431         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
432
433         Row row = null;
434         try {
435             row = ovsdbTable.getRow(node, bckCompatibleTableName, rowUuid);
436         } catch (Exception e) {
437             throw new BadRequestException(e.getMessage());
438         }
439         return row;
440     }
441
442     /**
443      * Read all Rows of a table
444      *
445      * @param nodeType type of node e.g OVS
446      * @param nodeId ID of the node
447      * @param tableName name of the ovsdb table
448      *
449      * @return All the Rows of a table
450      *
451      * <br>
452      * Examples:
453      * <br>
454      * <pre>
455      * Get all Bridge Rows:
456      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/bridge/rows
457      *
458      * Get all Port Rows:
459      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/port/rows
460      *
461      * Get all Interface Rows:
462      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/interface/rows
463      *
464      * Get all Controller Rows:
465      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/controller/rows
466      *
467      * Get all SSL Rows:
468      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/SSL/rows
469      *
470      * Get all sFlow Rows:
471      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/sflow/rows
472      *
473      * Get all QoS Rows:
474      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/qos/rows
475      *
476      * Get all Queue Rows:
477      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/queue/rows
478      *
479      * Get all Netflow Rows:
480      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/netflow/rows
481      *
482      * Get all Manager Rows:
483      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/manager/rows
484      *
485      * Get all Open vSwitch Rows:
486      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/open_vswitch/rows
487      * </pre>
488      */
489
490     @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows")
491     @GET
492     @StatusCodes({ @ResponseCode(code = 200, condition = "Row Updated successfully"),
493         @ResponseCode(code = 400, condition = "Invalid data passed"),
494         @ResponseCode(code = 401, condition = "User not authorized to perform this operation")})
495     @Produces({ MediaType.APPLICATION_JSON})
496     @TypeHint(OvsdbRows.class)
497     public OvsdbRows getAllRows(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
498                                @PathParam("tableName") String tableName) {
499         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
500             throw new UnauthorizedException("User is not authorized to perform this operation");
501         }
502
503         OvsdbConfigurationService
504                 ovsdbTable = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class,
505                                                                                             this);
506         if (ovsdbTable == null) {
507             throw new ServiceUnavailableException("UserManager " + RestMessages.SERVICEUNAVAILABLE.toString());
508         }
509
510         Node node = Node.fromString(nodeType, nodeId);
511         OvsdbConnectionService
512                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
513         OvsdbClient client = connectionService.getConnection(node).getClient();
514         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
515         Map<String, Row> rows = null;
516         try {
517             rows = ovsdbTable.getRows(node, bckCompatibleTableName);
518         } catch (Exception e) {
519             throw new BadRequestException(e.getMessage());
520         }
521         return new OvsdbRows(rows);
522     }
523
524     /*
525     /**
526      * Update a Row
527      *
528      * @param nodeType type of node e.g OVS
529      * @param nodeId ID of the node
530      * @param tableName name of the ovsdb table
531      * @param rowUuid UUID of the row being updated
532      * @param row the {@link OVSDBRow} Row that is being updated
533      *
534      * @return Response as dictated by the HTTP Response Status code
535      *
536      * <br>
537      * Examples:
538      * <br>
539      * Update the Bridge row to add a controller
540      * <pre>
541      *
542      * Request URL:
543      * PUT http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/bridge/rows/b01cd26b-9c63-4216-8cf2-55f7087adab1
544      *
545      * JSON:
546      * {
547      *   "row": {
548      *     "Bridge": {
549      *       "controller": [
550      *         "set",
551      *         [
552      *           [
553      *             "uuid",
554      *             "a566e8b4-fc38-499b-8623-6087d5b36b72"
555      *           ]
556      *         ]
557      *       ]
558      *     }
559      *   }
560      * }
561      * </pre>
562      */
563
564     @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows/{rowUuid}")
565     @PUT
566     @StatusCodes({ @ResponseCode(code = 200, condition = "Row Updated successfully"),
567         @ResponseCode(code = 400, condition = "Invalid data passed"),
568         @ResponseCode(code = 401, condition = "User not authorized to perform this operation")})
569     @Consumes({ MediaType.APPLICATION_JSON})
570     public Response updateRow(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
571                            @PathParam("tableName") String tableName, @PathParam("rowUuid") String rowUuid,
572                            JsonNode rowJson) {
573
574         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
575             throw new UnauthorizedException("User is not authorized to perform this operation");
576         }
577
578         OvsdbConfigurationService
579                 ovsdbTable = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class,
580                                                                                             this);
581         if (ovsdbTable == null) {
582             throw new ServiceUnavailableException("OVS Configuration Service " + RestMessages.SERVICEUNAVAILABLE.toString());
583         }
584
585         Node node = Node.fromString(nodeType, nodeId);
586         OvsdbConnectionService
587                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
588         OvsdbClient client = connectionService.getConnection(node).getClient();
589         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
590         OvsdbRow localRow = OvsdbRow.fromJsonNode(client, OvsVswitchdSchemaConstants.DATABASE_NAME, rowJson);
591
592         if (localRow == null) {
593             return Response.status(Response.Status.BAD_REQUEST).build();
594         }
595
596         Status status = ovsdbTable.updateRow(node, bckCompatibleTableName, localRow.getParentUuid(), rowUuid, localRow.getRow());
597         return NorthboundUtils.getResponse(status);
598     }
599
600     /**
601      * Delete a row
602      *
603      * @param nodeType type of node e.g OVS
604      * @param nodeId ID of the node
605      * @param tableName name of the ovsdb table
606      * @param uuid UUID of the Row to be removed
607      *
608      * @return Response as dictated by the HTTP Response Status code
609      *
610      * <br>
611      * Examples:
612      * <br>
613      * <pre>
614      * Delete a specific Bridge Row:
615      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/bridge/rows/6f4c602c-026f-4390-beea-d50d6d448100
616      *
617      * Delete a specific Port Row:
618      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/port/rows/6f4c602c-026f-4390-beea-d50d6d448100
619      *
620      * Delete a specific Interface Row:
621      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/interface/rows/6f4c602c-026f-4390-beea-d50d6d448100
622      *
623      * Delete a specific Controller Row:
624      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/controller/rows/6f4c602c-026f-4390-beea-d50d6d448100
625      *
626      * Delete a specific SSL Row:
627      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/SSL/rows/6f4c602c-026f-4390-beea-d50d6d448100
628      *
629      * Delete a specific sFlow Row:
630      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/sflow/rows/6f4c602c-026f-4390-beea-d50d6d448100
631      *
632      * Delete a specific QoS Row:
633      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/qos/rows/6f4c602c-026f-4390-beea-d50d6d448100
634      *
635      * Delete a specific Queue Row:
636      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/queue/rows/6f4c602c-026f-4390-beea-d50d6d448100
637      *
638      * Delete a specific Netflow Row:
639      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/netflow/rows/6f4c602c-026f-4390-beea-d50d6d448100
640      *
641      * Delete a specific Manager Row:
642      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/manager/rows/6f4c602c-026f-4390-beea-d50d6d448100
643      * </pre>
644      */
645
646     @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows/{uuid}")
647     @DELETE
648     @StatusCodes({ @ResponseCode(code = 204, condition = "User Deleted Successfully"),
649         @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
650         @ResponseCode(code = 404, condition = "The userName passed was not found"),
651         @ResponseCode(code = 500, condition = "Internal Server Error : Removal of user failed"),
652         @ResponseCode(code = 503, condition = "Service unavailable") })
653     public Response removeRow(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
654                               @PathParam("tableName") String tableName, @PathParam("uuid") String uuid) {
655         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
656             throw new UnauthorizedException("User is not authorized to perform this operation");
657         }
658
659         OvsdbConfigurationService
660                 ovsdbTable = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class,
661                 this);
662         if (ovsdbTable == null) {
663             throw new ServiceUnavailableException("OVS Configuration Service " + RestMessages.SERVICEUNAVAILABLE.toString());
664         }
665
666         Node node = Node.fromString(nodeType, nodeId);
667         OvsdbConnectionService
668                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
669         OvsdbClient client = connectionService.getConnection(node).getClient();
670         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
671
672         Status status = ovsdbTable.deleteRow(node, bckCompatibleTableName, uuid);
673         if (status.isSuccess()) {
674             return Response.noContent().build();
675         }
676         return NorthboundUtils.getResponse(status);
677     }
678
679     private String getBackwardCompatibleTableName(OvsdbClient client, String databaseName, String tableName) {
680         DatabaseSchema dbSchema = client.getDatabaseSchema(databaseName);
681         if (dbSchema == null || tableName == null) return tableName;
682         for (String dbTableName : dbSchema.getTables()) {
683             if (dbTableName.equalsIgnoreCase(tableName)) return dbTableName;
684         }
685         return tableName;
686     }
687 }