771484d0ade9349ef97182d75797745d7b25e8d5
[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         OvsdbConnectionService
336                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
337         Node node = connectionService.getNode(nodeId);
338
339         OvsdbClient client = connectionService.getConnection(node).getClient();
340         OvsdbRow localRow = OvsdbRow.fromJsonNode(client, OvsVswitchdSchemaConstants.DATABASE_NAME, rowJson);
341         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
342
343         if (localRow == null) {
344             return Response.status(Response.Status.BAD_REQUEST).build();
345         }
346
347         StatusWithUuid
348                 statusWithUuid = ovsdbTable.insertRow(node, bckCompatibleTableName, localRow.getParentUuid(), localRow.getRow());
349
350         if (statusWithUuid.isSuccess()) {
351             UUID uuid = statusWithUuid.getUuid();
352             return Response.status(Response.Status.CREATED)
353                     .header("Location", String.format("%s/%s", _uriInfo.getAbsolutePath().toString(),
354                                                                 uuid.toString()))
355                     .entity(uuid.toString())
356                     .build();
357         }
358         return NorthboundUtils.getResponse(statusWithUuid);
359     }
360
361     /**
362      * Read a Row
363      *
364      * @param nodeType type of node e.g OVS
365      * @param nodeId ID of the node
366      * @param tableName name of the ovsdb table
367      * @param rowUuid UUID of the row being read
368      *
369      * @return Row corresponding to the UUID.
370      *
371      * <br>
372      * Examples:
373      * <br>
374      * <pre>
375      * Get a specific Bridge Row:
376      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/bridge/rows/6f4c602c-026f-4390-beea-d50d6d448100
377      *
378      * Get a specific Port Row:
379      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/port/rows/6f4c602c-026f-4390-beea-d50d6d448100
380      *
381      * Get a specific Interface Row:
382      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/interface/rows/6f4c602c-026f-4390-beea-d50d6d448100
383      *
384      * Get a specific Controller Row:
385      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/controller/rows/6f4c602c-026f-4390-beea-d50d6d448100
386      *
387      * Get a specific SSL Row:
388      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/SSL/rows/6f4c602c-026f-4390-beea-d50d6d448100
389      *
390      * Get a specific sFlow Row:
391      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/sflow/rows/6f4c602c-026f-4390-beea-d50d6d448100
392      *
393      * Get a specific QoS Row:
394      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/qos/rows/6f4c602c-026f-4390-beea-d50d6d448100
395      *
396      * Get a specific Queue Row:
397      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/queue/rows/6f4c602c-026f-4390-beea-d50d6d448100
398      *
399      * Get a specific Netflow Row:
400      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/netflow/rows/6f4c602c-026f-4390-beea-d50d6d448100
401      *
402      * Get a specific Manager Row:
403      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/manager/rows/6f4c602c-026f-4390-beea-d50d6d448100
404      * </pre>
405      */
406
407     @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows/{rowUuid}")
408     @GET
409     @StatusCodes({ @ResponseCode(code = 200, condition = "Row Updated successfully"),
410         @ResponseCode(code = 400, condition = "Invalid data passed"),
411         @ResponseCode(code = 401, condition = "User not authorized to perform this operation")})
412     @Produces({ MediaType.APPLICATION_JSON})
413     @TypeHint(Row.class)
414     public Row getRow(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
415                            @PathParam("tableName") String tableName, @PathParam("rowUuid") String rowUuid) {
416
417         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
418             throw new UnauthorizedException("User is not authorized to perform this operation");
419         }
420
421         OvsdbConfigurationService
422                 ovsdbTable = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class,
423                                                                                             this);
424         if (ovsdbTable == null) {
425             throw new ServiceUnavailableException("UserManager " + RestMessages.SERVICEUNAVAILABLE.toString());
426         }
427
428         OvsdbConnectionService
429                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
430         Node node = connectionService.getNode(nodeId);
431         OvsdbClient client = connectionService.getConnection(node).getClient();
432         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
433
434         Row row = null;
435         try {
436             row = ovsdbTable.getRow(node, bckCompatibleTableName, rowUuid);
437         } catch (Exception e) {
438             throw new BadRequestException(e.getMessage());
439         }
440         return row;
441     }
442
443     /**
444      * Read all Rows of a table
445      *
446      * @param nodeType type of node e.g OVS
447      * @param nodeId ID of the node
448      * @param tableName name of the ovsdb table
449      *
450      * @return All the Rows of a table
451      *
452      * <br>
453      * Examples:
454      * <br>
455      * <pre>
456      * Get all Bridge Rows:
457      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/bridge/rows
458      *
459      * Get all Port Rows:
460      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/port/rows
461      *
462      * Get all Interface Rows:
463      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/interface/rows
464      *
465      * Get all Controller Rows:
466      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/controller/rows
467      *
468      * Get all SSL Rows:
469      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/SSL/rows
470      *
471      * Get all sFlow Rows:
472      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/sflow/rows
473      *
474      * Get all QoS Rows:
475      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/qos/rows
476      *
477      * Get all Queue Rows:
478      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/queue/rows
479      *
480      * Get all Netflow Rows:
481      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/netflow/rows
482      *
483      * Get all Manager Rows:
484      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/manager/rows
485      *
486      * Get all Open vSwitch Rows:
487      * GET http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/open_vswitch/rows
488      * </pre>
489      */
490
491     @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows")
492     @GET
493     @StatusCodes({ @ResponseCode(code = 200, condition = "Row Updated successfully"),
494         @ResponseCode(code = 400, condition = "Invalid data passed"),
495         @ResponseCode(code = 401, condition = "User not authorized to perform this operation")})
496     @Produces({ MediaType.APPLICATION_JSON})
497     @TypeHint(OvsdbRows.class)
498     public OvsdbRows getAllRows(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
499                                @PathParam("tableName") String tableName) {
500         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
501             throw new UnauthorizedException("User is not authorized to perform this operation");
502         }
503
504         OvsdbConfigurationService
505                 ovsdbTable = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class,
506                                                                                             this);
507         if (ovsdbTable == null) {
508             throw new ServiceUnavailableException("UserManager " + RestMessages.SERVICEUNAVAILABLE.toString());
509         }
510
511         OvsdbConnectionService
512                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
513         Node node = connectionService.getNode(nodeId);
514         OvsdbClient client = connectionService.getConnection(node).getClient();
515         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
516         Map<String, Row> rows = null;
517         try {
518             rows = ovsdbTable.getRows(node, bckCompatibleTableName);
519         } catch (Exception e) {
520             throw new BadRequestException(e.getMessage());
521         }
522         return new OvsdbRows(rows);
523     }
524
525     /*
526     /**
527      * Update a Row
528      *
529      * @param nodeType type of node e.g OVS
530      * @param nodeId ID of the node
531      * @param tableName name of the ovsdb table
532      * @param rowUuid UUID of the row being updated
533      * @param row the {@link OVSDBRow} Row that is being updated
534      *
535      * @return Response as dictated by the HTTP Response Status code
536      *
537      * <br>
538      * Examples:
539      * <br>
540      * Update the Bridge row to add a controller
541      * <pre>
542      *
543      * Request URL:
544      * PUT http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/bridge/rows/b01cd26b-9c63-4216-8cf2-55f7087adab1
545      *
546      * JSON:
547      * {
548      *   "row": {
549      *     "Bridge": {
550      *       "controller": [
551      *         "set",
552      *         [
553      *           [
554      *             "uuid",
555      *             "a566e8b4-fc38-499b-8623-6087d5b36b72"
556      *           ]
557      *         ]
558      *       ]
559      *     }
560      *   }
561      * }
562      * </pre>
563      */
564
565     @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows/{rowUuid}")
566     @PUT
567     @StatusCodes({ @ResponseCode(code = 200, condition = "Row Updated successfully"),
568         @ResponseCode(code = 400, condition = "Invalid data passed"),
569         @ResponseCode(code = 401, condition = "User not authorized to perform this operation")})
570     @Consumes({ MediaType.APPLICATION_JSON})
571     public Response updateRow(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
572                            @PathParam("tableName") String tableName, @PathParam("rowUuid") String rowUuid,
573                            JsonNode rowJson) {
574
575         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
576             throw new UnauthorizedException("User is not authorized to perform this operation");
577         }
578
579         OvsdbConfigurationService
580                 ovsdbTable = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class,
581                                                                                             this);
582         if (ovsdbTable == null) {
583             throw new ServiceUnavailableException("OVS Configuration Service " + RestMessages.SERVICEUNAVAILABLE.toString());
584         }
585
586         OvsdbConnectionService
587                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
588         Node node = connectionService.getNode(nodeId);
589         OvsdbClient client = connectionService.getConnection(node).getClient();
590         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
591         OvsdbRow localRow = OvsdbRow.fromJsonNode(client, OvsVswitchdSchemaConstants.DATABASE_NAME, rowJson);
592
593         if (localRow == null) {
594             return Response.status(Response.Status.BAD_REQUEST).build();
595         }
596
597         Status status = ovsdbTable.updateRow(node, bckCompatibleTableName, localRow.getParentUuid(), rowUuid, localRow.getRow());
598         return NorthboundUtils.getResponse(status);
599     }
600
601     /**
602      * Delete a row
603      *
604      * @param nodeType type of node e.g OVS
605      * @param nodeId ID of the node
606      * @param tableName name of the ovsdb table
607      * @param uuid UUID of the Row to be removed
608      *
609      * @return Response as dictated by the HTTP Response Status code
610      *
611      * <br>
612      * Examples:
613      * <br>
614      * <pre>
615      * Delete a specific Bridge Row:
616      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/bridge/rows/6f4c602c-026f-4390-beea-d50d6d448100
617      *
618      * Delete a specific Port Row:
619      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/port/rows/6f4c602c-026f-4390-beea-d50d6d448100
620      *
621      * Delete a specific Interface Row:
622      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/interface/rows/6f4c602c-026f-4390-beea-d50d6d448100
623      *
624      * Delete a specific Controller Row:
625      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/controller/rows/6f4c602c-026f-4390-beea-d50d6d448100
626      *
627      * Delete a specific SSL Row:
628      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/SSL/rows/6f4c602c-026f-4390-beea-d50d6d448100
629      *
630      * Delete a specific sFlow Row:
631      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/sflow/rows/6f4c602c-026f-4390-beea-d50d6d448100
632      *
633      * Delete a specific QoS Row:
634      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/qos/rows/6f4c602c-026f-4390-beea-d50d6d448100
635      *
636      * Delete a specific Queue Row:
637      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/queue/rows/6f4c602c-026f-4390-beea-d50d6d448100
638      *
639      * Delete a specific Netflow Row:
640      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/netflow/rows/6f4c602c-026f-4390-beea-d50d6d448100
641      *
642      * Delete a specific Manager Row:
643      * DELETE http://localhost:8080/ovsdb/nb/v2/node/OVS/HOST1/tables/manager/rows/6f4c602c-026f-4390-beea-d50d6d448100
644      * </pre>
645      */
646
647     @Path("/node/{nodeType}/{nodeId}/tables/{tableName}/rows/{uuid}")
648     @DELETE
649     @StatusCodes({ @ResponseCode(code = 204, condition = "User Deleted Successfully"),
650         @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
651         @ResponseCode(code = 404, condition = "The userName passed was not found"),
652         @ResponseCode(code = 500, condition = "Internal Server Error : Removal of user failed"),
653         @ResponseCode(code = 503, condition = "Service unavailable") })
654     public Response removeRow(@PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
655                               @PathParam("tableName") String tableName, @PathParam("uuid") String uuid) {
656         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
657             throw new UnauthorizedException("User is not authorized to perform this operation");
658         }
659
660         OvsdbConfigurationService
661                 ovsdbTable = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class,
662                 this);
663         if (ovsdbTable == null) {
664             throw new ServiceUnavailableException("OVS Configuration Service " + RestMessages.SERVICEUNAVAILABLE.toString());
665         }
666
667         OvsdbConnectionService
668                 connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
669         Node node = connectionService.getNode(nodeId);
670         OvsdbClient client = connectionService.getConnection(node).getClient();
671         String bckCompatibleTableName = this.getBackwardCompatibleTableName(client, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName);
672
673         Status status = ovsdbTable.deleteRow(node, bckCompatibleTableName, uuid);
674         if (status.isSuccess()) {
675             return Response.noContent().build();
676         }
677         return NorthboundUtils.getResponse(status);
678     }
679
680     private String getBackwardCompatibleTableName(OvsdbClient client, String databaseName, String tableName) {
681         DatabaseSchema dbSchema = client.getDatabaseSchema(databaseName);
682         if (dbSchema == null || tableName == null) return tableName;
683         for (String dbTableName : dbSchema.getTables()) {
684             if (dbTableName.equalsIgnoreCase(tableName)) return dbTableName;
685         }
686         return tableName;
687     }
688 }