2 * Copyright (C) 2013 Red Hat, Inc.
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
8 * Authors : Madhu Venugopal, Brent Salisbury
10 package org.opendaylight.ovsdb.northbound;
12 import java.io.IOException;
13 import java.util.Iterator;
14 import java.util.concurrent.ExecutionException;
16 import javax.xml.bind.annotation.XmlElement;
18 import org.opendaylight.ovsdb.lib.OvsdbClient;
19 import org.opendaylight.ovsdb.lib.notation.Row;
20 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
21 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
23 import com.fasterxml.jackson.core.JsonParseException;
24 import com.fasterxml.jackson.databind.JsonNode;
25 import com.fasterxml.jackson.databind.node.ObjectNode;
28 public class OvsdbRow {
29 private static final String PARENTUUID = "parent_uuid";
30 private static final String ROW = "row";
32 @XmlElement(name=PARENTUUID)
38 Row<GenericTableSchema> row;
43 public OvsdbRow(String parentUuid, String tableName, Row<GenericTableSchema> row) {
44 this.parentUuid = parentUuid;
45 this.tableName = tableName;
49 public static OvsdbRow fromJsonNode(OvsdbClient client, String dbName, JsonNode json) {
50 JsonNode parentUuidNode = json.get(PARENTUUID);
51 String parentUuid = null;
52 if (parentUuidNode != null) parentUuid = parentUuidNode.asText();
54 JsonNode rowNode = json.get(ROW);
55 if (rowNode == null) return null;
56 for(Iterator<String> fieldNames = rowNode.fieldNames(); fieldNames.hasNext();) {
57 String tableName = fieldNames.next();
58 Row<GenericTableSchema> row = null;
60 row = getRow(client, dbName, tableName, rowNode.get(tableName));
61 } catch (InterruptedException | ExecutionException | IOException e) {
65 return new OvsdbRow(parentUuid, tableName, row);
70 public static Row<GenericTableSchema> getRow(OvsdbClient client, String dbName, String tableName, JsonNode rowJson) throws InterruptedException, ExecutionException, JsonParseException, IOException {
71 DatabaseSchema dbSchema = client.getSchema(dbName).get();
72 GenericTableSchema schema = dbSchema.table(tableName, GenericTableSchema.class);
73 return schema.createRow((ObjectNode)rowJson);
76 public String getParentUuid() {
80 public String getTableName() {
84 public Row<GenericTableSchema> getRow() {
89 public String toString() {
90 return "OVSDBRow [parentUuid=" + parentUuid + ", tableName="
91 + tableName + ", row=" + row + "]";