Modified the insertRow methods to return StatusWithUuid instead of Status 20/3220/5
authorMadhu Venugopal <mavenugo@gmail.com>
Fri, 29 Nov 2013 17:27:38 +0000 (09:27 -0800)
committerMadhu Venugopal <mavenugo@gmail.com>
Fri, 29 Nov 2013 17:27:38 +0000 (09:27 -0800)
This is in addition to Hugo's existing fixes.

Change-Id: I9671ee4afbd5e29c29e2b762f2dca91019db1e02
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
commons/parent/pom.xml
neutron/src/main/java/org/opendaylight/ovsdb/neutron/InternalNetworkManager.java
neutron/src/main/java/org/opendaylight/ovsdb/neutron/provider/OF10ProviderManager.java
northbound/ovsdb/pom.xml
northbound/ovsdb/src/main/java/org/opendaylight/ovsdb/northbound/OVSDBNorthbound.java
ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/ConfigurationService.java
ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/OVSDBConfigService.java
ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/StatusWithUuid.java [new file with mode: 0644]

index 42e03c295db2fea439b3c9a24d623b62bed85619..c5d1df0ff9474b15af33990f665197c7db23ab4c 100755 (executable)
@@ -24,6 +24,7 @@
   </properties>
   <modules>
     <module>../../ovsdb/</module>
+    <module>../../northbound/ovsdb</module>
     <module>../../distribution/opendaylight</module>
   </modules>
   <repositories>
index 5750e1b76020035e094a1e0c7f9be7b742d0338c..5bd049dbd9fd0f72c719b275ad9c14c1d2f8f7dc 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.ovsdb.lib.table.Port;
 import org.opendaylight.ovsdb.lib.table.internal.Table;
 import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
+import org.opendaylight.ovsdb.plugin.StatusWithUuid;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -106,21 +107,22 @@ public class InternalNetworkManager {
         Bridge brTun = new Bridge();
         brTun.setName(AdminConfigManager.getManager().getTunnelBridgeName());
         // Create br-tun bridge
-        Status status = ovsdbTable.insertRow(node, Bridge.NAME.getName(), null, brTun);
-        if (!status.isSuccess()) return status;
-        String bridgeUUID = status.getDescription();
+        StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, Bridge.NAME.getName(), null, brTun);
+        if (!statusWithUuid.isSuccess()) return statusWithUuid;
+        String bridgeUUID = statusWithUuid.getUuid().toString();
+
         // Set OF Controller
         IConnectionServiceInternal connectionService = (IConnectionServiceInternal)ServiceHelper.getGlobalInstance(IConnectionServiceInternal.class, this);
         connectionService.setOFController(node, bridgeUUID);
 
         Port port = new Port();
         port.setName(brTun.getName());
-        status = ovsdbTable.insertRow(node, Port.NAME.getName(), bridgeUUID, port);
+        statusWithUuid = ovsdbTable.insertRow(node, Port.NAME.getName(), bridgeUUID, port);
 
         String patchInt = AdminConfigManager.getManager().getPatchToIntegration();
         String patchTun = AdminConfigManager.getManager().getPatchToTunnel();
 
-        status = addPatchPort(node, bridgeUUID, patchInt, patchTun);
+        Status status = addPatchPort(node, bridgeUUID, patchInt, patchTun);
         if (!status.isSuccess()) return status;
 
         // Create the corresponding patch-tun port in br-int
@@ -136,16 +138,15 @@ public class InternalNetworkManager {
     }
 
     private Status addPatchPort (Node node, String bridgeUUID, String portName, String patchName) throws Exception {
-        Status status = null;
         OVSDBConfigService ovsdbTable = (OVSDBConfigService)ServiceHelper.getGlobalInstance(OVSDBConfigService.class, this);
 
         Port patchPort = new Port();
         patchPort.setName(portName);
         // Create patch-int port and interface
-        status = ovsdbTable.insertRow(node, Port.NAME.getName(), bridgeUUID, patchPort);
-        if (!status.isSuccess()) return status;
+        StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, Port.NAME.getName(), bridgeUUID, patchPort);
+        if (!statusWithUuid.isSuccess()) return statusWithUuid;
 
-        String patchPortUUID = status.getDescription();
+        String patchPortUUID = statusWithUuid.getUuid().toString();
 
         String interfaceUUID = null;
         int timeout = 6;
@@ -170,9 +171,7 @@ public class InternalNetworkManager {
         OvsDBMap<String, String> options = new OvsDBMap<String, String>();
         options.put("peer", patchName);
         tunInterface.setOptions(options);
-        status = ovsdbTable.updateRow(node, Interface.NAME.getName(), patchPortUUID, interfaceUUID, tunInterface);
-
-        return status;
+        return ovsdbTable.updateRow(node, Interface.NAME.getName(), patchPortUUID, interfaceUUID, tunInterface);
     }
 
     private void prepareInternalNetwork (NeutronNetwork network, Node node) {
index 83d34e02ef577ba3bbb0bee7522185992f442b9a..f26e553bdee90bad50e3621fc8828471e624516d 100644 (file)
@@ -28,6 +28,7 @@ import org.opendaylight.ovsdb.neutron.InternalNetworkManager;
 import org.opendaylight.ovsdb.neutron.TenantNetworkManager;
 import org.opendaylight.ovsdb.plugin.IConnectionServiceInternal;
 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
+import org.opendaylight.ovsdb.plugin.StatusWithUuid;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -381,14 +382,13 @@ class OF10ProviderManager extends ProviderNetworkManager {
 
             Port tunnelPort = new Port();
             tunnelPort.setName(portName);
-            Status status = ovsdbTable.insertRow(node, Port.NAME.getName(), bridgeUUID, tunnelPort);
-            if (!status.isSuccess()) {
+            StatusWithUuid statusWithUuid = ovsdbTable.insertRow(node, Port.NAME.getName(), bridgeUUID, tunnelPort);
+            if (!statusWithUuid.isSuccess()) {
                 logger.error("Failed to insert Tunnel port {} in {}", portName, bridgeUUID);
-                return status;
+                return statusWithUuid;
             }
 
-            String tunnelPortUUID = status.getDescription();
-
+            String tunnelPortUUID = statusWithUuid.getUuid().toString();
             String interfaceUUID = null;
             int timeout = 6;
             while ((interfaceUUID == null) && (timeout > 0)) {
@@ -417,7 +417,7 @@ class OF10ProviderManager extends ProviderNetworkManager {
             options.put("local_ip", src.getHostAddress());
             options.put("remote_ip", dst.getHostAddress());
             tunInterface.setOptions(options);
-            status = ovsdbTable.updateRow(node, Interface.NAME.getName(), tunnelPortUUID, interfaceUUID, tunInterface);
+            Status status = ovsdbTable.updateRow(node, Interface.NAME.getName(), tunnelPortUUID, interfaceUUID, tunInterface);
             logger.debug("Tunnel {} add status : {}", tunInterface, status);
             return status;
         } catch (Exception e) {
index b2be260d447ce8336557beb7e61ca49557dac731..0754194e9907eb8a5ad021fdc47f054d4426ab71 100644 (file)
@@ -43,6 +43,7 @@
               org.opendaylight.controller.sal.authorization,
               org.opendaylight.ovsdb.lib.table,
               org.opendaylight.ovsdb.lib.table.internal,
+              org.opendaylight.ovsdb.lib.notation,
               org.opendaylight.ovsdb.plugin,
               javax.ws.rs,
               javax.ws.rs.core,
index e6b7aba4a88de22437e139362d2a528d5e0f1df7..4970e29d56efe77340bcce5a465a205c3229ef4a 100644 (file)
@@ -36,9 +36,11 @@ import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
+import org.opendaylight.ovsdb.lib.notation.UUID;
 import org.opendaylight.ovsdb.lib.table.internal.Table;
 import org.opendaylight.ovsdb.lib.table.internal.Tables;
 import org.opendaylight.ovsdb.plugin.OVSDBConfigService;
+import org.opendaylight.ovsdb.plugin.StatusWithUuid;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -133,13 +135,14 @@ public class OVSDBNorthbound {
         if (row != null && row.getRow() != null) {
             handleNameMismatch(tableName, row.getRow().getTableName().getName());
             Node node = Node.fromString(nodeType, nodeId);
-            Status statusWithUUID = ovsdbTable.insertRow(node, ovsTableName, row.getParent_uuid(), row.getRow());
+            StatusWithUuid statusWithUUID = ovsdbTable.insertRow(node, ovsTableName, row.getParent_uuid(), row.getRow());
 
             if (statusWithUUID.isSuccess()) {
+                UUID uuid = statusWithUUID.getUuid();
                 return Response.status(Response.Status.CREATED)
                         .header("Location", String.format("%s/%s", _uriInfo.getAbsolutePath().toString(),
-                                                                    statusWithUUID.getDescription()))
-                        .entity(statusWithUUID.getDescription())
+                                                                    uuid.toString()))
+                        .entity(uuid.toString())
                         .build();
             } else {
                 return NorthboundUtils.getResponse(statusWithUUID);
index 068b278f8fdc6fe8c12be8ed87b30c4d41c523b8..9bba9f8ba332857309ec0ffc38e0aabd6c657630 100755 (executable)
@@ -681,9 +681,9 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
     }
 
     @Override
-    public Status insertRow(Node node, String tableName, String parent_uuid, Table<?> row) {
+    public StatusWithUuid insertRow(Node node, String tableName, String parent_uuid, Table<?> row) {
         logger.info("tableName : {}, parent_uuid : {} Row : {}", tableName, parent_uuid, row.toString());
-        Status statusWithUUID = null;
+        StatusWithUuid statusWithUUID = null;
 
         // Schema based Table handling will help fix this static Table handling.
 
@@ -889,7 +889,7 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
         return null;
     }
 
-    private Status insertBridgeRow(Node node, String open_VSwitch_uuid, Bridge bridgeRow) {
+    private StatusWithUuid insertBridgeRow(Node node, String open_VSwitch_uuid, Bridge bridgeRow) {
 
         String insertErrorMsg = "bridge";
         String rowName=bridgeRow.getName();
@@ -898,7 +898,7 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
             Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, Open_vSwitch.NAME.getName());
 
             if (ovsTable == null) {
-                return new Status(StatusCode.NOTFOUND, "There are no Open_vSwitch instance in the Open_vSwitch table");
+                return new StatusWithUuid(StatusCode.NOTFOUND, "There are no Open_vSwitch instance in the Open_vSwitch table");
             }
 
             String newBridge = "new_bridge";
@@ -932,11 +932,11 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
         } catch(Exception e){
             logger.error("Error in insertBridgeRow(): ",e);
         }
-        return new Status(StatusCode.INTERNALERROR);
+        return new StatusWithUuid(StatusCode.INTERNALERROR);
     }
 
 
-    private Status insertPortRow(Node node, String bridge_uuid, Port portRow) {
+    private StatusWithUuid insertPortRow(Node node, String bridge_uuid, Port portRow) {
 
         String insertErrorMsg = "port";
         String rowName=portRow.getName();
@@ -944,7 +944,7 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
         try{
             Map<String, Table<?>> brTable = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
             if (brTable == null ||  brTable.get(bridge_uuid) == null) {
-                return new Status(StatusCode.NOTFOUND, "Bridge with UUID "+bridge_uuid+" Not found");
+                return new StatusWithUuid(StatusCode.NOTFOUND, "Bridge with UUID "+bridge_uuid+" Not found");
             }
             String newPort = "new_port";
             UUID portUUID = new UUID(newPort);
@@ -984,10 +984,10 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
             } catch (Exception e) {
             logger.error("Error in insertPortRow(): ",e);
         }
-        return new Status(StatusCode.INTERNALERROR);
+        return new StatusWithUuid(StatusCode.INTERNALERROR);
     }
 
-    private Status insertInterfaceRow(Node node, String port_uuid, Interface interfaceRow) {
+    private StatusWithUuid insertInterfaceRow(Node node, String port_uuid, Interface interfaceRow) {
 
         String insertErrorMsg = "interface";
         String rowName=interfaceRow.getName();
@@ -997,7 +997,7 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
             // Interface table must have entry in Port table, checking port table for port
             Map<String, Table<?>> portTable = inventoryServiceInternal.getTableCache(node, Port.NAME.getName());
             if (portTable == null ||  portTable.get(port_uuid) == null) {
-                return new Status(StatusCode.NOTFOUND, "Port with UUID "+port_uuid+" Not found");
+                return new StatusWithUuid(StatusCode.NOTFOUND, "Port with UUID "+port_uuid+" Not found");
             }
             // MUTATOR, need to insert the interface UUID to LIST of interfaces in PORT TABLE for port_uuid
             String newInterface = "new_interface";
@@ -1028,14 +1028,14 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
         } catch (Exception e) {
             logger.error("Error in insertInterfaceRow(): ",e);
         }
-        return new Status(StatusCode.INTERNALERROR);
+        return new StatusWithUuid(StatusCode.INTERNALERROR);
     }
 
-    private Status insertOpen_vSwitchRow(Node node, Open_vSwitch row) {
-        return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+    private StatusWithUuid insertOpen_vSwitchRow(Node node, Open_vSwitch row) {
+        return new StatusWithUuid(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
     }
 
-    private Status insertControllerRow(Node node, String bridge_uuid, Controller row) {
+    private StatusWithUuid insertControllerRow(Node node, String bridge_uuid, Controller row) {
 
         String insertErrorMsg = "controller";
         String rowName=row.getTableName().toString();
@@ -1044,7 +1044,7 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
 
             Map<String, Table<?>> brTable = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
             if (brTable == null ||  brTable.get(bridge_uuid) == null) {
-                return new Status(StatusCode.NOTFOUND, "Bridge with UUID "+bridge_uuid+" Not found");
+                return new StatusWithUuid(StatusCode.NOTFOUND, "Bridge with UUID "+bridge_uuid+" Not found");
             }
 
             Map<String, Table<?>> controllerCache = inventoryServiceInternal.getTableCache(node, Controller.NAME.getName());
@@ -1088,64 +1088,64 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
         } catch (Exception e) {
             logger.error("Error in insertControllerRow(): ",e);
         }
-        return new Status(StatusCode.INTERNALERROR);
+        return new StatusWithUuid(StatusCode.INTERNALERROR);
     }
 
-    private Status insertSSLRow(Node node, String parent_uuid, SSL row) {
-        return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+    private StatusWithUuid insertSSLRow(Node node, String parent_uuid, SSL row) {
+        return new StatusWithUuid(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
     }
 
-    private Status insertSflowRow(Node node, String parent_uuid, SFlow row) {
-        return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+    private StatusWithUuid insertSflowRow(Node node, String parent_uuid, SFlow row) {
+        return new StatusWithUuid(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
     }
 
-    private Status insertQueueRow(Node node, String parent_uuid, Queue row) {
-        return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+    private StatusWithUuid insertQueueRow(Node node, String parent_uuid, Queue row) {
+        return new StatusWithUuid(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
     }
 
-    private Status insertQosRow(Node node, String parent_uuid, Qos row) {
-        return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+    private StatusWithUuid insertQosRow(Node node, String parent_uuid, Qos row) {
+        return new StatusWithUuid(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
     }
 
-    private Status insertNetFlowRow(Node node, String parent_uuid, NetFlow row) {
-        return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+    private StatusWithUuid insertNetFlowRow(Node node, String parent_uuid, NetFlow row) {
+        return new StatusWithUuid(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
     }
 
-    private Status insertMirrorRow(Node node, String parent_uuid, Mirror row) {
-        return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+    private StatusWithUuid insertMirrorRow(Node node, String parent_uuid, Mirror row) {
+        return new StatusWithUuid(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
     }
 
-    private Status insertManagerRow(Node node, String parent_uuid, Manager row) {
-        return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+    private StatusWithUuid insertManagerRow(Node node, String parent_uuid, Manager row) {
+        return new StatusWithUuid(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
     }
 
-    private Status insertCapabilityRow(Node node, String parent_uuid, Capability row) {
-        return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+    private StatusWithUuid insertCapabilityRow(Node node, String parent_uuid, Capability row) {
+        return new StatusWithUuid(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
     }
 
-    private Status _insertTableRow(Node node, TransactBuilder transaction, Integer insertIndex, String insertErrorMsg,String rowName){
+    private StatusWithUuid _insertTableRow(Node node, TransactBuilder transaction, Integer insertIndex, String insertErrorMsg,String rowName){
 
         try{
             //Check for connection before calling RPC to perform transaction
             if (connectionService == null) {
                 logger.error("Couldn't refer to the ConnectionService");
-                return new Status(StatusCode.NOSERVICE);
+                return new StatusWithUuid(StatusCode.NOSERVICE);
             }
 
             Connection connection = this.getConnection(node);
             if (connection == null) {
-                return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
+                return new StatusWithUuid(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
             }
 
             ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
             List<OperationResult> tr = transResponse.get();
             List<Operation> requests = transaction.getRequests();
-            Status status = new Status(StatusCode.SUCCESS);
+            StatusWithUuid status = new StatusWithUuid(StatusCode.SUCCESS);
             for (int i = 0; i < tr.size() ; i++) {
                 if (i < requests.size()) requests.get(i).setResult(tr.get(i));
                 if (tr.get(i) != null && tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
                     OperationResult result = tr.get(i);
-                    status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+                    status = new StatusWithUuid(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
                 }
             }
 
@@ -1155,17 +1155,17 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
                                                                                        rowName,
                                                                                        result.getError(),
                                                                                        result.getDetails());
-                status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+                status = new StatusWithUuid(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
             }
             if (status.isSuccess()) {
-                UUID bridgeUUID = tr.get(insertIndex).getUuid();
-                status = new Status(StatusCode.SUCCESS, bridgeUUID.toString());
+                UUID uuid = tr.get(insertIndex).getUuid();
+                status = new StatusWithUuid(StatusCode.SUCCESS, uuid);
             }
             return status;
         } catch(Exception e){
             logger.error("Error in _insertTableRow(): ",e);
         }
-        return new Status(StatusCode.INTERNALERROR);
+        return new StatusWithUuid(StatusCode.INTERNALERROR);
     }
 
 
index f199d682526ad26be73791a2cae094e811e6db7e..3ff32ef8a55176858101942ebe5516a89a721254 100644 (file)
@@ -8,7 +8,7 @@ import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.ovsdb.lib.table.internal.Table;
 
 public interface OVSDBConfigService {
-    public Status insertRow (Node node, String tableName, String parentUUID, Table<?> row);
+    public StatusWithUuid insertRow (Node node, String tableName, String parentUUID, Table<?> row);
     public Status deleteRow (Node node, String tableName, String rowUUID);
     public Status updateRow (Node node, String tableName, String parentUUID, String rowUUID, Table<?> row);
     public String getSerializedRow(Node node, String tableName, String uuid) throws Exception;
diff --git a/ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/StatusWithUuid.java b/ovsdb/src/main/java/org/opendaylight/ovsdb/plugin/StatusWithUuid.java
new file mode 100644 (file)
index 0000000..def81cf
--- /dev/null
@@ -0,0 +1,35 @@
+package org.opendaylight.ovsdb.plugin;
+
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+
+/**
+ * Extends the Status class to allow functions to return a uuid
+ */
+public class StatusWithUuid extends Status {
+    private static final long serialVersionUID = -5413085099514964003L;
+    private UUID uuid;
+
+    public StatusWithUuid(StatusCode errorCode) {
+        super(errorCode);
+    }
+
+    public StatusWithUuid(StatusCode errorCode, String description) {
+        super(errorCode, description);
+    }
+
+    public StatusWithUuid(StatusCode errorCode, long requestId) {
+        super(errorCode, requestId);
+    }
+
+    public StatusWithUuid(StatusCode errorCode, UUID uuid) {
+        super(errorCode);
+        this.uuid = uuid;
+    }
+
+    public UUID getUuid() {
+        return uuid;
+    }
+
+}