Added insertControllerRow and fixed getSerializedRow. getRows still need to return... 93/2893/1
authorMadhu Venugopal <mavenugo@gmail.com>
Wed, 20 Nov 2013 09:33:22 +0000 (01:33 -0800)
committerMadhu Venugopal <mavenugo@gmail.com>
Wed, 20 Nov 2013 09:38:54 +0000 (01:38 -0800)
which will be used by the neutron integration piece. Also the insertControllerRow is used for that
cause.

Change-Id: I0a8b03b24a22dcb31b67d1ee5f606bd0220c34dc
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
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

index 47c6fde9e55fcb967759911791fab0ed16d63a76..e6b7aba4a88de22437e139362d2a528d5e0f1df7 100644 (file)
@@ -192,7 +192,7 @@ public class OVSDBNorthbound {
         //Table<?> row = null;
         String row = null;
         try {
-            row = ovsdbTable.getRow(node, ovsTableName, rowUuid);
+            row = ovsdbTable.getSerializedRow(node, ovsTableName, rowUuid);
         } catch (Exception e) {
             throw new BadRequestException(e.getMessage());
         }
@@ -242,7 +242,7 @@ public class OVSDBNorthbound {
         //Map<String, Table<?>> rows = null;
         String rows = null;
         try {
-            rows = ovsdbTable.getRows(node, ovsTableName);
+            rows = ovsdbTable.getSerializedRows(node, ovsTableName);
         } catch (Exception e) {
             throw new BadRequestException(e.getMessage());
         }
index 993f1d30b1237466252ae91bbba9d3d629e77e7c..c01f3c55c8d2f064f3d3efe1b8e703aaa721ab46 100755 (executable)
@@ -986,30 +986,51 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
     }
 
     @Override
-    public String getRows(Node node, String tableName) throws Exception{
+    public Map<String, Table<?>> getRows(Node node, String tableName) throws Exception{
         try{
             if (inventoryServiceInternal == null) {
                 throw new Exception("Inventory Service is Unavailable.");
             }
             Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, tableName);
-            if (ovsTable == null) return null;
-            ObjectMapper mapper = new ObjectMapper();
-            return mapper.writeValueAsString(ovsTable);
+            return ovsTable;
         } catch(Exception e){
             throw new Exception("Unable to read table due to "+e.getMessage());
         }
     }
 
     @Override
-    public String getRow(Node node, String tableName, String uuid) throws Exception {
+    public Table<?> getRow(Node node, String tableName, String uuid) throws Exception {
         try{
             if (inventoryServiceInternal == null) {
                 throw new Exception("Inventory Service is Unavailable.");
             }
             Map<String, Table<?>> ovsTable = inventoryServiceInternal.getTableCache(node, tableName);
             if (ovsTable == null) return null;
+            return ovsTable.get(uuid);
+        } catch(Exception e){
+            throw new Exception("Unable to read table due to "+e.getMessage());
+        }
+    }
+
+    @Override
+    public String getSerializedRows(Node node, String tableName) throws Exception{
+        try{
+            Map<String, Table<?>> ovsTable = this.getRows(node, tableName);
+            if (ovsTable == null) return null;
+            ObjectMapper mapper = new ObjectMapper();
+            return mapper.writeValueAsString(ovsTable);
+        } catch(Exception e){
+            throw new Exception("Unable to read table due to "+e.getMessage());
+        }
+    }
+
+    @Override
+    public String getSerializedRow(Node node, String tableName, String uuid) throws Exception {
+        try{
+            Table<?> row = this.getRow(node, tableName, uuid);
+            if (row == null) return null;
             ObjectMapper mapper = new ObjectMapper();
-            return mapper.writeValueAsString(ovsTable.get(uuid));
+            return mapper.writeValueAsString(row);
         } catch(Exception e){
             throw new Exception("Unable to read table due to "+e.getMessage());
         }
@@ -1248,7 +1269,67 @@ public class ConfigurationService implements IPluginInBridgeDomainConfigService,
     }
 
     private Status insertControllerRow(Node node, String bridge_uuid, Controller row) {
-        return new Status(StatusCode.NOTIMPLEMENTED, "Insert operation for this Table is not implemented yet.");
+        try{
+            if (connectionService == null) {
+                logger.error("Couldn't refer to the ConnectionService");
+                return new Status(StatusCode.NOSERVICE);
+            }
+            Connection connection = this.getConnection(node);
+            if (connection == null) {
+                return new Status(StatusCode.NOSERVICE, "Connection to ovsdb-server not available");
+            }
+
+            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");
+            }
+            String newController = "new_controller";
+            UUID controllerUUID = new UUID(newController);
+            Mutation bm = new Mutation("controller", Mutator.INSERT, controllerUUID);
+            List<Mutation> mutations = new ArrayList<Mutation>();
+            mutations.add(bm);
+
+            UUID uuid = new UUID(bridge_uuid);
+            Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
+            List<Condition> where = new ArrayList<Condition>();
+            where.add(condition);
+            Operation addBrMutRequest = new MutateOperation(Bridge.NAME.getName(), where, mutations);
+
+            InsertOperation addControllerRequest = new InsertOperation(Controller.NAME.getName(), newController, row);
+
+            TransactBuilder transaction = new TransactBuilder();
+            transaction.addOperations(new ArrayList<Operation>
+            (Arrays.asList(addBrMutRequest, addControllerRequest)));
+            int portInsertIndex = transaction.getRequests().indexOf(addControllerRequest);
+            ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
+            List<OperationResult> tr = transResponse.get();
+            List<Operation> requests = transaction.getRequests();
+            Status status = new Status(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());
+                }
+            }
+
+            if (tr.size() > requests.size()) {
+                OperationResult result = tr.get(tr.size()-1);
+                logger.error("Error creating port : {}\n Error : {}\n Details : {}", row.getTarget(),
+                        result.getError(),
+                        result.getDetails());
+                status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
+            }
+            if (status.isSuccess()) {
+                uuid = tr.get(portInsertIndex).getUuid();
+                status = new Status(StatusCode.SUCCESS, uuid.toString());
+            }
+
+            return status;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return new Status(StatusCode.INTERNALERROR);
     }
 
     private Status insertSSLRow(Node node, String parent_uuid, SSL row) {
index 4032541201172d3f2611cf0f0113f87df9e8c368..f199d682526ad26be73791a2cae094e811e6db7e 100644 (file)
@@ -1,6 +1,7 @@
 package org.opendaylight.ovsdb.plugin;
 
 import java.util.List;
+import java.util.Map;
 
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.utils.Status;
@@ -10,7 +11,9 @@ public interface OVSDBConfigService {
     public Status 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 getRow(Node node, String tableName, String uuid) throws Exception;
-    public String getRows(Node node, String tableName) throws Exception;
+    public String getSerializedRow(Node node, String tableName, String uuid) throws Exception;
+    public String getSerializedRows(Node node, String tableName) throws Exception;
+    public Table<?> getRow(Node node, String tableName, String uuid) throws Exception;
+    public Map<String, Table<?>> getRows(Node node, String tableName) throws Exception;
     public List<String> getTables(Node node) throws Exception;
 }