import java.util.Iterator;
import java.util.concurrent.ExecutionException;
-import javax.xml.bind.annotation.XmlElement;
-
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
-@Deprecated
public class OvsdbRow {
private static final String PARENTUUID = "parent_uuid";
+ private static final String PARENTTABLE = "parent_table";
+ private static final String PARENTCOLUMN = "parent_column";
private static final String ROW = "row";
- @XmlElement(name=PARENTUUID)
- String parentUuid;
-
- String tableName;
-
- @XmlElement(name=ROW)
- Row<GenericTableSchema> row;
+ private String parentUuid;
+ private String parentTable;
+ private String parentColumn;
+ private String tableName;
+ private Row<GenericTableSchema> row;
public OvsdbRow() {
}
this.row = row;
}
+ public OvsdbRow(String parentTable, String parentUuid, String parentColumn, String tableName, Row<GenericTableSchema> row) {
+ this.parentTable = parentTable;
+ this.parentColumn = parentColumn;
+ this.parentUuid = parentUuid;
+ this.tableName = tableName;
+ this.row = row;
+ }
+
public static OvsdbRow fromJsonNode(OvsdbClient client, String dbName, JsonNode json) {
JsonNode parentUuidNode = json.get(PARENTUUID);
String parentUuid = null;
if (parentUuidNode != null) parentUuid = parentUuidNode.asText();
+ JsonNode parentTableNode = json.get(PARENTTABLE);
+ String parentTable = null;
+ if (parentTableNode != null) parentTable = parentTableNode.asText();
+
+ JsonNode parentColumnNode = json.get(PARENTCOLUMN);
+ String parentColumn = null;
+ if (parentColumnNode != null) parentColumn = parentColumnNode.asText();
+
JsonNode rowNode = json.get(ROW);
if (rowNode == null) return null;
for(Iterator<String> fieldNames = rowNode.fieldNames(); fieldNames.hasNext();) {
e.printStackTrace();
return null;
}
- return new OvsdbRow(parentUuid, tableName, row);
+ return new OvsdbRow(parentTable, parentUuid, parentColumn, tableName, row);
}
return null;
}
return schema.createRow((ObjectNode)rowJson);
}
+ public String getParentTable() {
+ return parentTable;
+ }
+
public String getParentUuid() {
return parentUuid;
}
+ public String getParentColumn() {
+ return parentColumn;
+ }
+
public String getTableName() {
return tableName;
}
public Row<GenericTableSchema> getRow() {
return row;
}
-
- @Override
- public String toString() {
- return "OVSDBRow [parentUuid=" + parentUuid + ", tableName="
- + tableName + ", row=" + row + "]";
- }
}
package org.opendaylight.ovsdb.northbound;
+import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.opendaylight.controller.northbound.commons.RestMessages;
+import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.opendaylight.ovsdb.lib.OvsdbClient;
+import org.opendaylight.ovsdb.lib.notation.Row;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.plugin.api.OvsVswitchdSchemaConstants;
+import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
+import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
/**
* Northbound interface for OVSDB Rows
*/
String nodeId;
String databaseName;
- String rowName;
+ String tableName;
- public RowResource(String nodeId, String databaseName, String rowName) {
+ public RowResource(String nodeId, String databaseName, String tableName) {
this.nodeId = nodeId;
this.databaseName = databaseName;
- this.rowName = rowName;
+ this.tableName = tableName;
}
@GET
return Response.noContent().build();
}
+ private OvsdbRow getOvsdbRow (InputStream stream) throws IOException {
+ StringBuilder rowNodeStrBuilder = new StringBuilder();
+ BufferedReader in = new BufferedReader(new InputStreamReader(stream));
+ String line = null;
+ while ((line = in.readLine()) != null) {
+ rowNodeStrBuilder.append(line);
+ }
+
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode jsonNode = mapper.readTree(rowNodeStrBuilder.toString());
+
+ Node node = Node.fromString(nodeId);
+ OvsdbConnectionService
+ connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
+ OvsdbClient client = connectionService.getConnection(node).getClient();
+ return OvsdbRow.fromJsonNode(client, OvsVswitchdSchemaConstants.DATABASE_NAME, jsonNode);
+ }
+
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Response createRow(InputStream stream) {
- return Response.noContent().build();
+ public Response createRow(InputStream stream) throws IOException {
+ Node node = Node.fromString(nodeId);
+ OvsdbRow localRow = this.getOvsdbRow(stream);
+ if (localRow == null) {
+ return Response.status(Response.Status.BAD_REQUEST).build();
+ }
+ OvsdbConfigurationService
+ ovsdbTable = (OvsdbConfigurationService)ServiceHelper.getGlobalInstance(OvsdbConfigurationService.class,
+ this);
+ if (ovsdbTable == null) {
+ throw new ServiceUnavailableException("OVS Configuration Service " + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+
+ Row row = ovsdbTable.insertTree(node, OvsVswitchdSchemaConstants.DATABASE_NAME, tableName,
+ localRow.getParentTable(), new UUID(localRow.getParentUuid()), localRow.getParentColumn(),
+ localRow.getRow());
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ String response = objectMapper.writeValueAsString(row);
+ return Response.status(Response.Status.CREATED)
+ .entity(response)
+ .build();
}
@GET