lishuai
Committed by Gerrit Code Review

[ONOS-2563]Optimize RFC 7047's code.

Change-Id: I000f2b802420e4f47ce320f6ed021049bd2fd83e
Showing 23 changed files with 1765 additions and 2052 deletions
...@@ -16,25 +16,25 @@ ...@@ -16,25 +16,25 @@
16 package org.onosproject.ovsdb.rfc.error; 16 package org.onosproject.ovsdb.rfc.error;
17 17
18 /** 18 /**
19 - * AbnormalSchema exception is thrown when the received schema is invalid. 19 + * AbnormalJsonNodeException exception is thrown when the received JsonNode is invalid.
20 */ 20 */
21 -public class AbnormalSchemaException extends RuntimeException { 21 +public class AbnormalJsonNodeException extends RuntimeException {
22 private static final long serialVersionUID = 8328377718334680368L; 22 private static final long serialVersionUID = 8328377718334680368L;
23 23
24 /** 24 /**
25 - * Constructs a AbnormalSchemaException object. 25 + * Constructs a AbnormalJsonNodeException object.
26 * @param message error message 26 * @param message error message
27 */ 27 */
28 - public AbnormalSchemaException(String message) { 28 + public AbnormalJsonNodeException(String message) {
29 super(message); 29 super(message);
30 } 30 }
31 31
32 /** 32 /**
33 - * Constructs a AbnormalSchemaException object. 33 + * Constructs a AbnormalJsonNodeException object.
34 * @param message error message 34 * @param message error message
35 * @param cause Throwable 35 * @param cause Throwable
36 */ 36 */
37 - public AbnormalSchemaException(String message, Throwable cause) { 37 + public AbnormalJsonNodeException(String message, Throwable cause) {
38 super(message, cause); 38 super(message, cause);
39 } 39 }
40 40
......
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.ovsdb.rfc.error;
17 -
18 -/**
19 - * This exception is thrown when the argument is not supported.
20 - */
21 -public class ArgumentException extends RuntimeException {
22 - private static final long serialVersionUID = 4950089877540156797L;
23 -
24 - /**
25 - * Constructs a ArgumentException object.
26 - * @param message error message
27 - */
28 - public ArgumentException(String message) {
29 - super(message);
30 - }
31 -
32 - /**
33 - * Constructs a ArgumentException object.
34 - * @param message error message
35 - * @param cause Throwable
36 - */
37 - public ArgumentException(String message, Throwable cause) {
38 - super(message, cause);
39 - }
40 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.ovsdb.rfc.error;
17 -
18 -/**
19 - * The JsonParsingException is thrown when JSON could not be successfully
20 - * parsed.
21 - */
22 -public class JsonParsingException extends RuntimeException {
23 - private static final long serialVersionUID = 1424752181911923235L;
24 -
25 - /**
26 - * Constructs a JsonParsingException object.
27 - * @param message error message
28 - */
29 - public JsonParsingException(String message) {
30 - super(message);
31 - }
32 -
33 - /**
34 - * Constructs a JsonParsingException object.
35 - * @param message error message
36 - * @param cause Throwable
37 - */
38 - public JsonParsingException(String message, Throwable cause) {
39 - super(message, cause);
40 - }
41 -
42 - /**
43 - * Constructs a JsonParsingException object.
44 - * @param cause Throwable
45 - */
46 - public JsonParsingException(Throwable cause) {
47 - super(cause);
48 - }
49 -
50 - /**
51 - * Constructs a JsonParsingException object.
52 - * @param message error message
53 - * @param cause Throwable
54 - * @param enableSuppression enable Suppression
55 - * @param writableStackTrace writable StackTrace
56 - */
57 - public JsonParsingException(String message, Throwable cause,
58 - boolean enableSuppression,
59 - boolean writableStackTrace) {
60 - super(message, cause, enableSuppression, writableStackTrace);
61 - }
62 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.ovsdb.rfc.error;
17 -
18 -/**
19 - * This is a generic exception thrown by the Typed Schema utilities.
20 - */
21 -public class TypedSchemaException extends RuntimeException {
22 - private static final long serialVersionUID = -1452257990783176715L;
23 -
24 - /**
25 - * Constructs a TypedSchemaException object.
26 - * @param message error message
27 - */
28 - public TypedSchemaException(String message) {
29 - super(message);
30 - }
31 -
32 - /**
33 - * Constructs a TypedSchemaException object.
34 - * @param message error message
35 - * @param cause Throwable
36 - */
37 - public TypedSchemaException(String message, Throwable cause) {
38 - super(message, cause);
39 - }
40 -}
1 -package org.onosproject.ovsdb.rfc.error;
2 -
3 -/**
4 - * This exception is thrown when the encoding does not meet UTF-8 in RFC7047.
5 - */
6 -public class UnsupportedEncodingException extends RuntimeException {
7 - private static final long serialVersionUID = -4865311369828520666L;
8 -
9 - /**
10 - * Constructs a UnsupportedEncodingException object.
11 - * @param message error message
12 - */
13 - public UnsupportedEncodingException(String message) {
14 - super(message);
15 - }
16 -}
...@@ -16,26 +16,26 @@ ...@@ -16,26 +16,26 @@
16 package org.onosproject.ovsdb.rfc.error; 16 package org.onosproject.ovsdb.rfc.error;
17 17
18 /** 18 /**
19 - * This exception is thrown when a result does not meet any of the known formats 19 + * This exception is thrown when the caller invoke the unsupported method or
20 - * in RFC7047. 20 + * use the encoding is not supported.
21 */ 21 */
22 -public class UnknownResultException extends RuntimeException { 22 +public class UnsupportedException extends RuntimeException {
23 private static final long serialVersionUID = 1377011546616825375L; 23 private static final long serialVersionUID = 1377011546616825375L;
24 24
25 /** 25 /**
26 - * Constructs a UnknownResultException object. 26 + * Constructs a UnsupportedException object.
27 * @param message error message 27 * @param message error message
28 */ 28 */
29 - public UnknownResultException(String message) { 29 + public UnsupportedException(String message) {
30 super(message); 30 super(message);
31 } 31 }
32 32
33 /** 33 /**
34 - * Constructs a UnknownResultException object. 34 + * Constructs a UnsupportedException object.
35 * @param message error message 35 * @param message error message
36 * @param cause Throwable 36 * @param cause Throwable
37 */ 37 */
38 - public UnknownResultException(String message, Throwable cause) { 38 + public UnsupportedException(String message, Throwable cause) {
39 super(message, cause); 39 super(message, cause);
40 } 40 }
41 } 41 }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.ovsdb.rfc.error; 16 package org.onosproject.ovsdb.rfc.error;
17 17
18 -import static com.google.common.base.MoreObjects.toStringHelper;
19 18
20 /** 19 /**
21 * This exception is used when the a table or row is accessed though a typed 20 * This exception is used when the a table or row is accessed though a typed
...@@ -47,15 +46,9 @@ public class VersionMismatchException extends RuntimeException { ...@@ -47,15 +46,9 @@ public class VersionMismatchException extends RuntimeException {
47 * @param fromVersion the initial version 46 * @param fromVersion the initial version
48 * @return message 47 * @return message
49 */ 48 */
50 - public static String createFromMessage(String actualVersion, 49 + public static String createFromMessage(String actualVersion, String fromVersion) {
51 - String fromVersion) { 50 + String message = "The fromVersion should less than the actualVersion.\n fromVersion: "
52 - String message = toStringHelper("VersionMismatchException") 51 + + fromVersion + ".\n" + "actualVersion: " + actualVersion;
53 - .addValue("The fromVersion should less than the actualVersion.\n"
54 - + "fromVersion: "
55 - + fromVersion
56 - + ".\n"
57 - + "actualVersion: " + actualVersion)
58 - .toString();
59 return message; 52 return message;
60 } 53 }
61 54
...@@ -66,13 +59,8 @@ public class VersionMismatchException extends RuntimeException { ...@@ -66,13 +59,8 @@ public class VersionMismatchException extends RuntimeException {
66 * @return message 59 * @return message
67 */ 60 */
68 public static String createToMessage(String actualVersion, String toVersion) { 61 public static String createToMessage(String actualVersion, String toVersion) {
69 - String message = toStringHelper("VersionMismatchException") 62 + String message = "The toVersion should greater than the actualVersion.\n"
70 - .addValue("The toVersion should greater than the required version.\n" 63 + + "toVersion: " + toVersion + ".\n" + " actualVersion: " + actualVersion;
71 - + "toVersion: "
72 - + toVersion
73 - + ".\n"
74 - + "Actual Version: " + actualVersion)
75 - .toString();
76 return message; 64 return message;
77 } 65 }
78 } 66 }
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.message; 16 +package org.onosproject.ovsdb.rfc.message;
17 - 17 +
18 -import static com.google.common.base.MoreObjects.toStringHelper; 18 +import static com.google.common.base.MoreObjects.toStringHelper;
19 -import static com.google.common.base.Preconditions.checkNotNull; 19 +import static com.google.common.base.Preconditions.checkNotNull;
20 - 20 +
21 -import java.util.Objects; 21 +import java.util.Objects;
22 - 22 +
23 -import org.onosproject.ovsdb.rfc.notation.json.UpdateNotificationConverter; 23 +import org.onosproject.ovsdb.rfc.notation.json.UpdateNotificationConverter;
24 - 24 +
25 -import com.fasterxml.jackson.databind.JsonNode; 25 +import com.fasterxml.jackson.databind.JsonNode;
26 -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 26 +import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
27 - 27 +
28 -/** 28 +/**
29 - * The "update" notification is sent by the server to the client to report 29 + * The "update" notification is sent by the server to the client to report
30 - * changes in tables that are being monitored following a "monitor" request. The 30 + * changes in tables that are being monitored following a "monitor" request. The
31 - * "params" of the result JsonNode. 31 + * "params" of the result JsonNode.
32 - */ 32 + */
33 -@JsonDeserialize(converter = UpdateNotificationConverter.class) 33 +@JsonDeserialize(converter = UpdateNotificationConverter.class)
34 -public final class UpdateNotification { 34 +public final class UpdateNotification {
35 - private final Object context; 35 + private final Object jsonValue;
36 - private final JsonNode tbUpdatesJsonNode; 36 + private final JsonNode tbUpdatesJsonNode;
37 - 37 +
38 - /** 38 + /**
39 - * Constructs a UpdateNotification object. 39 + * Constructs a UpdateNotification object.
40 - * @param context the "json-value" in "params" of the result JsonNode 40 + * @param jsonValue the "json-value" in "params" of the result JsonNode
41 - * @param tbUpdatesJsonNode the "table-updates" in "params" of the result JsonNode 41 + * @param tbUpdatesJsonNode the "table-updates" in "params" of the result JsonNode
42 - */ 42 + */
43 - public UpdateNotification(Object context, JsonNode tbUpdatesJsonNode) { 43 + public UpdateNotification(Object jsonValue, JsonNode tbUpdatesJsonNode) {
44 - checkNotNull(context, "context cannot be null"); 44 + checkNotNull(jsonValue, "jsonValue cannot be null");
45 - checkNotNull(tbUpdatesJsonNode, "tablebUpdates JsonNode cannot be null"); 45 + checkNotNull(tbUpdatesJsonNode, "tablebUpdates JsonNode cannot be null");
46 - this.context = context; 46 + this.jsonValue = jsonValue;
47 - this.tbUpdatesJsonNode = tbUpdatesJsonNode; 47 + this.tbUpdatesJsonNode = tbUpdatesJsonNode;
48 - } 48 + }
49 - 49 +
50 - /** 50 + /**
51 - * Return context. 51 + * Return context.
52 - * @return context 52 + * @return context
53 - */ 53 + */
54 - public Object context() { 54 + public Object jsonValue() {
55 - return context; 55 + return jsonValue;
56 - } 56 + }
57 - 57 +
58 - /** 58 + /**
59 - * Return tbUpdatesJsonNode. 59 + * Return tbUpdatesJsonNode.
60 - * @return tbUpdatesJsonNode 60 + * @return tbUpdatesJsonNode
61 - */ 61 + */
62 - public JsonNode tbUpdatesJsonNode() { 62 + public JsonNode tbUpdatesJsonNode() {
63 - return tbUpdatesJsonNode; 63 + return tbUpdatesJsonNode;
64 - } 64 + }
65 - 65 +
66 - @Override 66 + @Override
67 - public int hashCode() { 67 + public int hashCode() {
68 - return Objects.hash(context, tbUpdatesJsonNode); 68 + return Objects.hash(jsonValue, tbUpdatesJsonNode);
69 - } 69 + }
70 - 70 +
71 - @Override 71 + @Override
72 - public boolean equals(Object obj) { 72 + public boolean equals(Object obj) {
73 - if (this == obj) { 73 + if (this == obj) {
74 - return true; 74 + return true;
75 - } 75 + }
76 - if (obj instanceof UpdateNotification) { 76 + if (obj instanceof UpdateNotification) {
77 - final UpdateNotification other = (UpdateNotification) obj; 77 + final UpdateNotification other = (UpdateNotification) obj;
78 - return Objects.equals(this.context, other.context) 78 + return Objects.equals(this.jsonValue, other.jsonValue)
79 - && Objects.equals(this.tbUpdatesJsonNode, 79 + && Objects.equals(this.tbUpdatesJsonNode,
80 - other.tbUpdatesJsonNode); 80 + other.tbUpdatesJsonNode);
81 - } 81 + }
82 - return false; 82 + return false;
83 - } 83 + }
84 - 84 +
85 - @Override 85 + @Override
86 - public String toString() { 86 + public String toString() {
87 - return toStringHelper(this).add("context", context) 87 + return toStringHelper(this).add("jsonValue", jsonValue)
88 - .add("tbUpdatesJsonNode", tbUpdatesJsonNode).toString(); 88 + .add("tbUpdatesJsonNode", tbUpdatesJsonNode).toString();
89 - } 89 + }
90 -} 90 +}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.notation; 16 +package org.onosproject.ovsdb.rfc.notation;
17 - 17 +
18 -import static com.google.common.base.MoreObjects.toStringHelper; 18 +import static com.google.common.base.MoreObjects.toStringHelper;
19 -import static com.google.common.base.Preconditions.checkNotNull; 19 +import static com.google.common.base.Preconditions.checkNotNull;
20 - 20 +
21 -import java.util.Objects; 21 +import java.util.Objects;
22 - 22 +
23 -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; 23 +/**
24 - 24 + * Column is the basic element of the OpenVswitch database.
25 -import com.fasterxml.jackson.annotation.JsonIgnore; 25 + */
26 - 26 +public final class Column {
27 -/** 27 + private final String columnName;
28 - * Column is the basic element of the OpenVswitch database. 28 + private final Object data;
29 - */ 29 +
30 -public final class Column { 30 + /**
31 - @JsonIgnore 31 + * Column constructor.
32 - private final ColumnSchema schema; 32 + * @param columnName the column name
33 - private final Object data; 33 + * @param obj the data of the column
34 - 34 + */
35 - /** 35 + public Column(String columnName, Object obj) {
36 - * Column constructor. 36 + checkNotNull(columnName, "columnName cannot be null");
37 - * @param schema the column schema 37 + checkNotNull(obj, "data cannot be null");
38 - * @param obj the data of the column 38 + this.columnName = columnName;
39 - */ 39 + this.data = obj;
40 - public Column(ColumnSchema schema, Object obj) { 40 + }
41 - checkNotNull(schema, "schema cannot be null"); 41 +
42 - checkNotNull(obj, "data cannot be null"); 42 + /**
43 - this.schema = schema; 43 + * Returns column data.
44 - this.data = obj; 44 + * @return column data
45 - } 45 + */
46 - 46 + public Object data() {
47 - /** 47 + return data;
48 - * Returns column data. 48 + }
49 - * @return column data 49 +
50 - */ 50 + /**
51 - public Object data() { 51 + * Returns columnName.
52 - return data; 52 + * @return columnName
53 - } 53 + */
54 - 54 + public String columnName() {
55 - /** 55 + return columnName;
56 - * Returns ColumnSchema. 56 + }
57 - * @return ColumnSchema 57 +
58 - */ 58 + @Override
59 - public ColumnSchema schema() { 59 + public int hashCode() {
60 - return schema; 60 + return Objects.hash(columnName, data);
61 - } 61 + }
62 - 62 +
63 - @Override 63 + @Override
64 - public int hashCode() { 64 + public boolean equals(Object obj) {
65 - return Objects.hash(schema, data); 65 + if (this == obj) {
66 - } 66 + return true;
67 - 67 + }
68 - @Override 68 + if (obj instanceof Column) {
69 - public boolean equals(Object obj) { 69 + final Column other = (Column) obj;
70 - if (this == obj) { 70 + return Objects.equals(this.columnName, other.columnName)
71 - return true; 71 + && Objects.equals(this.data, other.data);
72 - } 72 + }
73 - if (obj instanceof Column) { 73 + return false;
74 - final Column other = (Column) obj; 74 + }
75 - return Objects.equals(this.schema, other.schema) 75 +
76 - && Objects.equals(this.data, other.data); 76 + @Override
77 - } 77 + public String toString() {
78 - return false; 78 + return toStringHelper(this).add("columnName", columnName)
79 - } 79 + .add("data", data).toString();
80 - 80 + }
81 - @Override 81 +}
82 - public String toString() {
83 - return toStringHelper(this).add("schema", schema).add("data", data)
84 - .toString();
85 - }
86 -}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.notation; 16 +package org.onosproject.ovsdb.rfc.notation;
17 - 17 +
18 -import static com.google.common.base.MoreObjects.toStringHelper; 18 +import static com.google.common.base.MoreObjects.toStringHelper;
19 -import static com.google.common.base.Preconditions.checkNotNull; 19 +import static com.google.common.base.Preconditions.checkNotNull;
20 - 20 +
21 -import java.util.Collection; 21 +import java.util.Collection;
22 -import java.util.List; 22 +import java.util.Map;
23 -import java.util.Map; 23 +import java.util.Objects;
24 -import java.util.Objects; 24 +
25 - 25 +import com.google.common.collect.Maps;
26 -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; 26 +
27 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 27 +/**
28 - 28 + * Row is the basic element of the OpenVswitch's table.
29 -import com.fasterxml.jackson.annotation.JsonIgnore; 29 + */
30 -import com.google.common.collect.Maps; 30 +public final class Row {
31 - 31 + private String tableName;
32 -/** 32 + private Map<String, Column> columns;
33 - * Row is the basic element of the OpenVswitch's table. 33 +
34 - */ 34 + /**
35 -public final class Row { 35 + * Row constructor.
36 - @JsonIgnore 36 + */
37 - private TableSchema tableSchema; 37 + public Row() {
38 - private Map<String, Column> columns; 38 + this.columns = Maps.newHashMap();
39 - 39 + }
40 - /** 40 +
41 - * Row constructor. 41 + /**
42 - */ 42 + * Row constructor.
43 - public Row() { 43 + * @param tableName table name
44 - this.columns = Maps.newHashMap(); 44 + */
45 - } 45 + public Row(String tableName) {
46 - 46 + checkNotNull(tableName, "tableName cannot be null");
47 - /** 47 + this.tableName = tableName;
48 - * Row constructor. 48 + this.columns = Maps.newHashMap();
49 - * @param tableSchema TableSchema entity 49 + }
50 - */ 50 +
51 - public Row(TableSchema tableSchema) { 51 + /**
52 - checkNotNull(tableSchema, "tableSchema cannot be null"); 52 + * Row constructor.
53 - this.tableSchema = tableSchema; 53 + * @param tableName table name
54 - this.columns = Maps.newHashMap(); 54 + * @param columns Map of Column entity
55 - } 55 + */
56 - 56 + public Row(String tableName, Map<String, Column> columns) {
57 - /** 57 + checkNotNull(tableName, "table name cannot be null");
58 - * Row constructor. 58 + checkNotNull(columns, "columns cannot be null");
59 - * @param tableSchema TableSchema entity 59 + this.tableName = tableName;
60 - * @param columns List of Column entity 60 + this.columns = columns;
61 - */ 61 + }
62 - public Row(TableSchema tableSchema, List<Column> columns) { 62 +
63 - checkNotNull(tableSchema, "tableSchema cannot be null"); 63 + /**
64 - checkNotNull(columns, "columns cannot be null"); 64 + * Returns tableName.
65 - this.tableSchema = tableSchema; 65 + * @return tableName
66 - this.columns = Maps.newHashMap(); 66 + */
67 - for (Column column : columns) { 67 + public String tableName() {
68 - this.columns.put(column.schema().name(), column); 68 + return tableName;
69 - } 69 + }
70 - } 70 +
71 - 71 + /**
72 - /** 72 + * Set tableName value.
73 - * Returns tableSchema. 73 + * @param tableName table name
74 - * @return tableSchema 74 + */
75 - */ 75 + public void setTableName(String tableName) {
76 - public TableSchema getTableSchema() { 76 + this.tableName = tableName;
77 - return tableSchema; 77 + }
78 - } 78 +
79 - 79 + /**
80 - /** 80 + * Returns Column by ColumnSchema.
81 - * Set tableSchema value. 81 + * @param columnName column name
82 - * @param tableSchema TableSchema entity 82 + * @return Column
83 - */ 83 + */
84 - public void setTableSchema(TableSchema tableSchema) { 84 + public Column getColumn(String columnName) {
85 - this.tableSchema = tableSchema; 85 + return columns.get(columnName);
86 - } 86 + }
87 - 87 +
88 - /** 88 + /**
89 - * Returns Column by ColumnSchema. 89 + * Returns Collection of Column.
90 - * @param schema ColumnSchema entity 90 + * @return Collection of Column
91 - * @return Column 91 + */
92 - */ 92 + public Collection<Column> getColumns() {
93 - public Column getColumn(ColumnSchema schema) { 93 + return columns.values();
94 - return (Column) columns.get(schema.name()); 94 + }
95 - } 95 +
96 - 96 + /**
97 - /** 97 + * add Column.
98 - * Returns Collection of Column. 98 + * @param columnName column name
99 - * @return Collection of Column 99 + * @param data Column entity
100 - */ 100 + */
101 - public Collection<Column> getColumns() { 101 + public void addColumn(String columnName, Column data) {
102 - return columns.values(); 102 + this.columns.put(columnName, data);
103 - } 103 + }
104 - 104 +
105 - /** 105 + @Override
106 - * add Column. 106 + public int hashCode() {
107 - * @param columnName column name 107 + return Objects.hash(tableName, columns);
108 - * @param data Column entity 108 + }
109 - */ 109 +
110 - public void addColumn(String columnName, Column data) { 110 + @Override
111 - this.columns.put(columnName, data); 111 + public boolean equals(Object obj) {
112 - } 112 + if (this == obj) {
113 - 113 + return true;
114 - @Override 114 + }
115 - public int hashCode() { 115 + if (obj instanceof Row) {
116 - return Objects.hash(tableSchema, columns); 116 + final Row other = (Row) obj;
117 - } 117 + return Objects.equals(this.tableName, other.tableName)
118 - 118 + && Objects.equals(this.columns, other.columns);
119 - @Override 119 + }
120 - public boolean equals(Object obj) { 120 + return false;
121 - if (this == obj) { 121 + }
122 - return true; 122 +
123 - } 123 + @Override
124 - if (obj instanceof Row) { 124 + public String toString() {
125 - final Row other = (Row) obj; 125 + return toStringHelper(this).add("tableName", tableName)
126 - return Objects.equals(this.tableSchema, other.tableSchema) 126 + .add("columns", columns).toString();
127 - && Objects.equals(this.columns, other.columns); 127 + }
128 - } 128 +}
129 - return false;
130 - }
131 -
132 - @Override
133 - public String toString() {
134 - return toStringHelper(this).add("tableSchema", tableSchema).add("columns", columns).toString();
135 - }
136 -}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.operations; 16 +package org.onosproject.ovsdb.rfc.operations;
17 - 17 +
18 -import static com.google.common.base.Preconditions.checkNotNull; 18 +import static com.google.common.base.Preconditions.checkNotNull;
19 - 19 +
20 -import java.util.List; 20 +import java.util.List;
21 - 21 +
22 -import org.onosproject.ovsdb.rfc.notation.Condition; 22 +import org.onosproject.ovsdb.rfc.notation.Condition;
23 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 23 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
24 - 24 +
25 -import com.fasterxml.jackson.annotation.JsonIgnore; 25 +import com.fasterxml.jackson.annotation.JsonIgnore;
26 -import com.fasterxml.jackson.annotation.JsonProperty; 26 +import com.fasterxml.jackson.annotation.JsonProperty;
27 - 27 +
28 -/** 28 +/**
29 - * delete operation.Refer to RFC 7047 Section 5.2. 29 + * delete operation.Refer to RFC 7047 Section 5.2.
30 - */ 30 + */
31 -public final class Delete implements Operation { 31 +public final class Delete implements Operation {
32 - 32 +
33 - @JsonIgnore 33 + @JsonIgnore
34 - private final TableSchema tableSchema; 34 + private final TableSchema tableSchema;
35 - private final String op; 35 + private final String op;
36 - private final List<Condition> where; 36 + private final List<Condition> where;
37 - 37 +
38 - /** 38 + /**
39 - * Constructs a Delete object. 39 + * Constructs a Delete object.
40 - * @param schema TableSchema entity 40 + * @param schema TableSchema entity
41 - * @param where the List of Condition entity 41 + * @param where the List of Condition entity
42 - */ 42 + */
43 - public Delete(TableSchema schema, List<Condition> where) { 43 + public Delete(TableSchema schema, List<Condition> where) {
44 - checkNotNull(schema, "TableSchema cannot be null"); 44 + checkNotNull(schema, "TableSchema cannot be null");
45 - checkNotNull(where, "where is not null"); 45 + checkNotNull(where, "where is not null");
46 - this.tableSchema = schema; 46 + this.tableSchema = schema;
47 - this.op = Operations.DELETE.op(); 47 + this.op = Operations.DELETE.op();
48 - this.where = where; 48 + this.where = where;
49 - } 49 + }
50 - 50 +
51 - /** 51 + /**
52 - * Returns the where member of delete operation. 52 + * Returns the where member of delete operation.
53 - * @return the where member of delete operation 53 + * @return the where member of delete operation
54 - */ 54 + */
55 - public List<Condition> getWhere() { 55 + public List<Condition> getWhere() {
56 - return where; 56 + return where;
57 - } 57 + }
58 - 58 +
59 - @Override 59 + @Override
60 - public String getOp() { 60 + public String getOp() {
61 - return op; 61 + return op;
62 - } 62 + }
63 - 63 +
64 - @Override 64 + @Override
65 - public TableSchema getTableSchema() { 65 + public TableSchema getTableSchema() {
66 - return tableSchema; 66 + return tableSchema;
67 - } 67 + }
68 - 68 +
69 - /** 69 + /**
70 - * For the use of serialization. 70 + * For the use of serialization.
71 - * @return the table member of update operation 71 + * @return the table member of update operation
72 - */ 72 + */
73 - @JsonProperty 73 + @JsonProperty
74 - public String getTable() { 74 + public String getTable() {
75 - return (tableSchema == null) ? null : tableSchema.name(); 75 + return tableSchema.name();
76 - } 76 + }
77 -} 77 +}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.operations; 16 +package org.onosproject.ovsdb.rfc.operations;
17 - 17 +
18 -import static com.google.common.base.Preconditions.checkNotNull; 18 +import static com.google.common.base.Preconditions.checkNotNull;
19 - 19 +
20 -import java.util.Collection; 20 +import java.util.Collection;
21 -import java.util.Map; 21 +import java.util.Map;
22 - 22 +
23 -import org.onosproject.ovsdb.rfc.notation.Column; 23 +import org.onosproject.ovsdb.rfc.notation.Column;
24 -import org.onosproject.ovsdb.rfc.notation.Row; 24 +import org.onosproject.ovsdb.rfc.notation.Row;
25 -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; 25 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
26 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 26 +import org.onosproject.ovsdb.rfc.utils.TransValueUtil;
27 -import org.onosproject.ovsdb.rfc.utils.TransValueUtil; 27 +
28 - 28 +import com.fasterxml.jackson.annotation.JsonIgnore;
29 -import com.fasterxml.jackson.annotation.JsonIgnore; 29 +import com.fasterxml.jackson.annotation.JsonProperty;
30 -import com.fasterxml.jackson.annotation.JsonProperty; 30 +import com.google.common.collect.Maps;
31 -import com.google.common.collect.Maps; 31 +
32 - 32 +/**
33 -/** 33 + * insert operation.Refer to RFC 7047 Section 5.2.
34 - * insert operation.Refer to RFC 7047 Section 5.2. 34 + */
35 - */ 35 +public final class Insert implements Operation {
36 -public final class Insert implements Operation { 36 +
37 - 37 + @JsonIgnore
38 - @JsonIgnore 38 + private final TableSchema tableSchema;
39 - private final TableSchema tableSchema; 39 + private final String op;
40 - private final String op; 40 + @JsonProperty("uuid-name")
41 - @JsonProperty("uuid-name") 41 + private final String uuidName;
42 - private final String uuidName; 42 + private final Map<String, Object> row;
43 - private final Map<String, Object> row; 43 +
44 - 44 + /**
45 - /** 45 + * Constructs a Insert object.
46 - * Constructs a Insert object. 46 + * @param schema TableSchema entity
47 - * @param schema TableSchema entity 47 + * @param uuidName uuid-name
48 - * @param uuidName uuid-name 48 + * @param row Row entity
49 - * @param row Row entity 49 + */
50 - */ 50 + public Insert(TableSchema schema, String uuidName, Row row) {
51 - public Insert(TableSchema schema, String uuidName, Row row) { 51 + checkNotNull(schema, "TableSchema cannot be null");
52 - checkNotNull(schema, "TableSchema cannot be null"); 52 + checkNotNull(uuidName, "uuid name cannot be null");
53 - checkNotNull(uuidName, "uuid name cannot be null"); 53 + checkNotNull(row, "row cannot be null");
54 - checkNotNull(row, "row cannot be null"); 54 + this.tableSchema = schema;
55 - this.tableSchema = schema; 55 + this.op = Operations.INSERT.op();
56 - this.op = Operations.INSERT.op(); 56 + this.uuidName = uuidName;
57 - this.uuidName = uuidName; 57 + this.row = Maps.newHashMap();
58 - this.row = Maps.newHashMap(); 58 + generateOperationRow(row);
59 - generateOperationRow(row); 59 + }
60 - } 60 +
61 - 61 + /**
62 - /** 62 + * Row entity convert into the row format of insert operation. Refer to RFC
63 - * Row entity convert into the row format of insert operation. Refer to RFC 63 + * 7047 Section 5.2.
64 - * 7047 Section 5.2. 64 + * @param row Row entity
65 - * @param row Row entity 65 + */
66 - */ 66 + private void generateOperationRow(Row row) {
67 - private void generateOperationRow(Row row) { 67 + Collection<Column> columns = row.getColumns();
68 - Collection<Column> columns = row.getColumns(); 68 + for (Column column : columns) {
69 - for (Column column : columns) { 69 + String columnName = column.columnName();
70 - ColumnSchema columnSchema = column.schema(); 70 + Object value = column.data();
71 - Object value = column.data(); 71 + Object formatValue = TransValueUtil.getFormatData(value);
72 - Object untypedValue = TransValueUtil.getFormatData(value); 72 + this.row.put(columnName, formatValue);
73 - this.row.put(columnSchema.name(), untypedValue); 73 + }
74 - } 74 + }
75 - } 75 +
76 - 76 + /**
77 - /** 77 + * Returns the uuid-name member of insert operation.
78 - * Returns the uuid-name member of insert operation. 78 + * @return the uuid-name member of insert operation
79 - * @return the uuid-name member of insert operation 79 + */
80 - */ 80 + public String getUuidName() {
81 - public String getUuidName() { 81 + return uuidName;
82 - return uuidName; 82 + }
83 - } 83 +
84 - 84 + /**
85 - /** 85 + * Returns the row member of insert operation.
86 - * Returns the row member of insert operation. 86 + * @return the row member of insert operation
87 - * @return the row member of insert operation 87 + */
88 - */ 88 + public Map<String, Object> getRow() {
89 - public Map<String, Object> getRow() { 89 + return row;
90 - return row; 90 + }
91 - } 91 +
92 - 92 + @Override
93 - @Override 93 + public String getOp() {
94 - public String getOp() { 94 + return op;
95 - return op; 95 + }
96 - } 96 +
97 - 97 + @Override
98 - @Override 98 + public TableSchema getTableSchema() {
99 - public TableSchema getTableSchema() { 99 + return tableSchema;
100 - return tableSchema; 100 + }
101 - } 101 +
102 - 102 + /**
103 - /** 103 + * For the use of serialization.
104 - * For the use of serialization. 104 + * @return the table member of update operation
105 - * @return the table member of update operation 105 + */
106 - */ 106 + @JsonProperty
107 - @JsonProperty 107 + public String getTable() {
108 - public String getTable() { 108 + return tableSchema.name();
109 - return (tableSchema == null) ? null : tableSchema.name(); 109 + }
110 - } 110 +}
111 -}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.operations; 16 +package org.onosproject.ovsdb.rfc.operations;
17 - 17 +
18 -import static com.google.common.base.Preconditions.checkNotNull; 18 +import static com.google.common.base.Preconditions.checkNotNull;
19 - 19 +
20 -import java.util.List; 20 +import java.util.List;
21 - 21 +
22 -import org.onosproject.ovsdb.rfc.notation.Condition; 22 +import org.onosproject.ovsdb.rfc.notation.Condition;
23 -import org.onosproject.ovsdb.rfc.notation.Mutation; 23 +import org.onosproject.ovsdb.rfc.notation.Mutation;
24 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 24 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
25 - 25 +
26 -import com.fasterxml.jackson.annotation.JsonIgnore; 26 +import com.fasterxml.jackson.annotation.JsonIgnore;
27 -import com.fasterxml.jackson.annotation.JsonProperty; 27 +import com.fasterxml.jackson.annotation.JsonProperty;
28 - 28 +
29 -/** 29 +/**
30 - * mutate operation.Refer to RFC 7047 Section 5.2. 30 + * mutate operation.Refer to RFC 7047 Section 5.2.
31 - */ 31 + */
32 -public final class Mutate implements Operation { 32 +public final class Mutate implements Operation {
33 - 33 +
34 - @JsonIgnore 34 + @JsonIgnore
35 - private final TableSchema tableSchema; 35 + private final TableSchema tableSchema;
36 - private final String op; 36 + private final String op;
37 - private final List<Condition> where; 37 + private final List<Condition> where;
38 - private final List<Mutation> mutations; 38 + private final List<Mutation> mutations;
39 - 39 +
40 - /** 40 + /**
41 - * Constructs a Mutate object. 41 + * Constructs a Mutate object.
42 - * @param schema TableSchema entity 42 + * @param schema TableSchema entity
43 - * @param where the List of Condition entity 43 + * @param where the List of Condition entity
44 - * @param mutations the List of Mutation entity 44 + * @param mutations the List of Mutation entity
45 - */ 45 + */
46 - public Mutate(TableSchema schema, List<Condition> where, 46 + public Mutate(TableSchema schema, List<Condition> where,
47 - List<Mutation> mutations) { 47 + List<Mutation> mutations) {
48 - checkNotNull(schema, "TableSchema cannot be null"); 48 + checkNotNull(schema, "TableSchema cannot be null");
49 - checkNotNull(mutations, "mutations cannot be null"); 49 + checkNotNull(mutations, "mutations cannot be null");
50 - checkNotNull(where, "where cannot be null"); 50 + checkNotNull(where, "where cannot be null");
51 - this.tableSchema = schema; 51 + this.tableSchema = schema;
52 - this.op = Operations.MUTATE.op(); 52 + this.op = Operations.MUTATE.op();
53 - this.where = where; 53 + this.where = where;
54 - this.mutations = mutations; 54 + this.mutations = mutations;
55 - } 55 + }
56 - 56 +
57 - /** 57 + /**
58 - * Returns the mutations member of mutate operation. 58 + * Returns the mutations member of mutate operation.
59 - * @return the mutations member of mutate operation 59 + * @return the mutations member of mutate operation
60 - */ 60 + */
61 - public List<Mutation> getMutations() { 61 + public List<Mutation> getMutations() {
62 - return mutations; 62 + return mutations;
63 - } 63 + }
64 - 64 +
65 - /** 65 + /**
66 - * Returns the where member of mutate operation. 66 + * Returns the where member of mutate operation.
67 - * @return the where member of mutate operation 67 + * @return the where member of mutate operation
68 - */ 68 + */
69 - public List<Condition> getWhere() { 69 + public List<Condition> getWhere() {
70 - return where; 70 + return where;
71 - } 71 + }
72 - 72 +
73 - @Override 73 + @Override
74 - public String getOp() { 74 + public String getOp() {
75 - return op; 75 + return op;
76 - } 76 + }
77 - 77 +
78 - @Override 78 + @Override
79 - public TableSchema getTableSchema() { 79 + public TableSchema getTableSchema() {
80 - return tableSchema; 80 + return tableSchema;
81 - } 81 + }
82 - 82 +
83 - /** 83 + /**
84 - * For the use of serialization. 84 + * For the use of serialization.
85 - * @return the table member of update operation 85 + * @return the table member of update operation
86 - */ 86 + */
87 - @JsonProperty 87 + @JsonProperty
88 - public String getTable() { 88 + public String getTable() {
89 - return (tableSchema == null) ? null : tableSchema.name(); 89 + return tableSchema.name();
90 - } 90 + }
91 -} 91 +}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.operations; 16 +package org.onosproject.ovsdb.rfc.operations;
17 - 17 +
18 -import static com.google.common.base.Preconditions.checkNotNull; 18 +import static com.google.common.base.Preconditions.checkNotNull;
19 - 19 +
20 -import java.util.List; 20 +import java.util.List;
21 - 21 +
22 -import org.onosproject.ovsdb.rfc.notation.Condition; 22 +import org.onosproject.ovsdb.rfc.notation.Condition;
23 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 23 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
24 - 24 +
25 -import com.fasterxml.jackson.annotation.JsonIgnore; 25 +import com.fasterxml.jackson.annotation.JsonIgnore;
26 -import com.fasterxml.jackson.annotation.JsonProperty; 26 +import com.fasterxml.jackson.annotation.JsonProperty;
27 - 27 +
28 -/** 28 +/**
29 - * select operation.Refer to RFC 7047 Section 5.2. 29 + * select operation.Refer to RFC 7047 Section 5.2.
30 - */ 30 + */
31 -public final class Select implements Operation { 31 +public final class Select implements Operation {
32 - 32 +
33 - @JsonIgnore 33 + @JsonIgnore
34 - private final TableSchema tableSchema; 34 + private final TableSchema tableSchema;
35 - private final String op; 35 + private final String op;
36 - private final List<Condition> where; 36 + private final List<Condition> where;
37 - private final List<String> columns; 37 + private final List<String> columns;
38 - 38 +
39 - /** 39 + /**
40 - * Constructs a Select object. 40 + * Constructs a Select object.
41 - * @param schema TableSchema entity 41 + * @param schema TableSchema entity
42 - * @param where the List of Condition entity 42 + * @param where the List of Condition entity
43 - * @param columns the List of column name 43 + * @param columns the List of column name
44 - */ 44 + */
45 - public Select(TableSchema schema, List<Condition> where, List<String> columns) { 45 + public Select(TableSchema schema, List<Condition> where, List<String> columns) {
46 - checkNotNull(schema, "TableSchema cannot be null"); 46 + checkNotNull(schema, "TableSchema cannot be null");
47 - checkNotNull(where, "where cannot be null"); 47 + checkNotNull(where, "where cannot be null");
48 - checkNotNull(columns, "columns cannot be null"); 48 + checkNotNull(columns, "columns cannot be null");
49 - this.tableSchema = schema; 49 + this.tableSchema = schema;
50 - this.op = Operations.SELECT.op(); 50 + this.op = Operations.SELECT.op();
51 - this.where = where; 51 + this.where = where;
52 - this.columns = columns; 52 + this.columns = columns;
53 - } 53 + }
54 - 54 +
55 - /** 55 + /**
56 - * Returns the columns member of select operation. 56 + * Returns the columns member of select operation.
57 - * @return the columns member of select operation 57 + * @return the columns member of select operation
58 - */ 58 + */
59 - public List<String> getColumns() { 59 + public List<String> getColumns() {
60 - return columns; 60 + return columns;
61 - } 61 + }
62 - 62 +
63 - /** 63 + /**
64 - * Returns the where member of select operation. 64 + * Returns the where member of select operation.
65 - * @return the where member of select operation 65 + * @return the where member of select operation
66 - */ 66 + */
67 - public List<Condition> getWhere() { 67 + public List<Condition> getWhere() {
68 - return where; 68 + return where;
69 - } 69 + }
70 - 70 +
71 - @Override 71 + @Override
72 - public String getOp() { 72 + public String getOp() {
73 - return op; 73 + return op;
74 - } 74 + }
75 - 75 +
76 - @Override 76 + @Override
77 - public TableSchema getTableSchema() { 77 + public TableSchema getTableSchema() {
78 - return tableSchema; 78 + return tableSchema;
79 - } 79 + }
80 - 80 +
81 - /** 81 + /**
82 - * For the use of serialization. 82 + * For the use of serialization.
83 - * @return the table member of update operation 83 + * @return the table member of update operation
84 - */ 84 + */
85 - @JsonProperty 85 + @JsonProperty
86 - public String getTable() { 86 + public String getTable() {
87 - return (tableSchema == null) ? null : tableSchema.name(); 87 + return tableSchema.name();
88 - } 88 + }
89 -} 89 +}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.operations; 16 +package org.onosproject.ovsdb.rfc.operations;
17 - 17 +
18 -import static com.google.common.base.Preconditions.checkNotNull; 18 +import static com.google.common.base.Preconditions.checkNotNull;
19 - 19 +
20 -import java.util.Collection; 20 +import java.util.Collection;
21 -import java.util.List; 21 +import java.util.List;
22 -import java.util.Map; 22 +import java.util.Map;
23 - 23 +
24 -import org.onosproject.ovsdb.rfc.notation.Column; 24 +import org.onosproject.ovsdb.rfc.notation.Column;
25 -import org.onosproject.ovsdb.rfc.notation.Condition; 25 +import org.onosproject.ovsdb.rfc.notation.Condition;
26 -import org.onosproject.ovsdb.rfc.notation.Row; 26 +import org.onosproject.ovsdb.rfc.notation.Row;
27 -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; 27 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
28 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 28 +import org.onosproject.ovsdb.rfc.utils.TransValueUtil;
29 -import org.onosproject.ovsdb.rfc.utils.TransValueUtil; 29 +
30 - 30 +import com.fasterxml.jackson.annotation.JsonIgnore;
31 -import com.fasterxml.jackson.annotation.JsonIgnore; 31 +import com.fasterxml.jackson.annotation.JsonProperty;
32 -import com.fasterxml.jackson.annotation.JsonProperty; 32 +import com.google.common.collect.Maps;
33 -import com.google.common.collect.Maps; 33 +
34 - 34 +/**
35 -/** 35 + * update operation.Refer to RFC 7047 Section 5.2.
36 - * update operation.Refer to RFC 7047 Section 5.2. 36 + */
37 - */ 37 +public final class Update implements Operation {
38 -public final class Update implements Operation { 38 +
39 - 39 + @JsonIgnore
40 - @JsonIgnore 40 + private final TableSchema tableSchema;
41 - private final TableSchema tableSchema; 41 + private final String op;
42 - private final String op; 42 + private final Map<String, Object> row;
43 - private final Map<String, Object> row; 43 + private final List<Condition> where;
44 - private final List<Condition> where; 44 +
45 - 45 + /**
46 - /** 46 + * Constructs a Update object.
47 - * Constructs a Update object. 47 + * @param schema TableSchema entity
48 - * @param schema TableSchema entity 48 + * @param row Row entity
49 - * @param row Row entity 49 + * @param where the List of Condition entity
50 - * @param where the List of Condition entity 50 + */
51 - */ 51 + public Update(TableSchema schema, Row row, List<Condition> where) {
52 - public Update(TableSchema schema, Row row, List<Condition> where) { 52 + checkNotNull(schema, "TableSchema cannot be null");
53 - checkNotNull(schema, "TableSchema cannot be null"); 53 + checkNotNull(row, "row cannot be null");
54 - checkNotNull(row, "row cannot be null"); 54 + checkNotNull(where, "where cannot be null");
55 - checkNotNull(where, "where cannot be null"); 55 + this.tableSchema = schema;
56 - this.tableSchema = schema; 56 + this.op = Operations.UPDATE.op();
57 - this.op = Operations.UPDATE.op(); 57 + this.row = Maps.newHashMap();
58 - this.row = Maps.newHashMap(); 58 + this.where = where;
59 - this.where = where; 59 + generateOperationRow(row);
60 - generateOperationRow(row); 60 + }
61 - } 61 +
62 - 62 + /**
63 - /** 63 + * Row entity convert into the row format of update operation. Refer to RFC
64 - * Row entity convert into the row format of update operation. Refer to RFC 64 + * 7047 Section 5.2.
65 - * 7047 Section 5.2. 65 + * @param row Row entity
66 - * @param row Row entity 66 + */
67 - */ 67 + private void generateOperationRow(Row row) {
68 - private void generateOperationRow(Row row) { 68 + Collection<Column> columns = row.getColumns();
69 - Collection<Column> columns = row.getColumns(); 69 + for (Column column : columns) {
70 - for (Column column : columns) { 70 + String columnName = column.columnName();
71 - ColumnSchema columnSchema = column.schema(); 71 + Object value = column.data();
72 - Object value = column.data(); 72 + Object formatValue = TransValueUtil.getFormatData(value);
73 - Object untypedValue = TransValueUtil.getFormatData(value); 73 + this.row.put(columnName, formatValue);
74 - this.row.put(columnSchema.name(), untypedValue); 74 + }
75 - } 75 + }
76 - } 76 +
77 - 77 + /**
78 - /** 78 + * Returns the row member of update operation.
79 - * Returns the row member of update operation. 79 + * @return the row member of update operation
80 - * @return the row member of update operation 80 + */
81 - */ 81 + public Map<String, Object> getRow() {
82 - public Map<String, Object> getRow() { 82 + return row;
83 - return row; 83 + }
84 - } 84 +
85 - 85 + /**
86 - /** 86 + * Returns the where member of update operation.
87 - * Returns the where member of update operation. 87 + * @return the where member of update operation
88 - * @return the where member of update operation 88 + */
89 - */ 89 + public List<Condition> getWhere() {
90 - public List<Condition> getWhere() { 90 + return where;
91 - return where; 91 + }
92 - } 92 +
93 - 93 + @Override
94 - @Override 94 + public String getOp() {
95 - public String getOp() { 95 + return op;
96 - return op; 96 + }
97 - } 97 +
98 - 98 + @Override
99 - @Override 99 + public TableSchema getTableSchema() {
100 - public TableSchema getTableSchema() { 100 + return tableSchema;
101 - return tableSchema; 101 + }
102 - } 102 +
103 - 103 + /**
104 - /** 104 + * For the use of serialization.
105 - * For the use of serialization. 105 + * @return the table member of update operation
106 - * @return the table member of update operation 106 + */
107 - */ 107 + @JsonProperty
108 - @JsonProperty 108 + public String getTable() {
109 - public String getTable() { 109 + return tableSchema.name();
110 - return (tableSchema == null) ? null : tableSchema.name(); 110 + }
111 - } 111 +}
112 -}
......
...@@ -17,8 +17,9 @@ package org.onosproject.ovsdb.rfc.schema.type; ...@@ -17,8 +17,9 @@ package org.onosproject.ovsdb.rfc.schema.type;
17 17
18 import java.util.Set; 18 import java.util.Set;
19 19
20 -import org.onosproject.ovsdb.rfc.error.TypedSchemaException; 20 +import org.onosproject.ovsdb.rfc.error.AbnormalJsonNodeException;
21 import org.onosproject.ovsdb.rfc.schema.type.UuidBaseType.RefType; 21 import org.onosproject.ovsdb.rfc.schema.type.UuidBaseType.RefType;
22 +import org.onosproject.ovsdb.rfc.utils.ObjectMapperUtil;
22 23
23 import com.fasterxml.jackson.databind.JsonNode; 24 import com.fasterxml.jackson.databind.JsonNode;
24 import com.google.common.collect.Sets; 25 import com.google.common.collect.Sets;
...@@ -29,27 +30,29 @@ import com.google.common.collect.Sets; ...@@ -29,27 +30,29 @@ import com.google.common.collect.Sets;
29 public final class BaseTypeFactory { 30 public final class BaseTypeFactory {
30 31
31 /** 32 /**
32 - * Constructs a BaseTypeFactory object. 33 + * Constructs a BaseTypeFactory object. This class should not be
33 - * This class should not be instantiated. 34 + * instantiated.
34 */ 35 */
35 private BaseTypeFactory() { 36 private BaseTypeFactory() {
36 } 37 }
37 38
38 /** 39 /**
39 * Create a BaseType from the JsonNode. 40 * Create a BaseType from the JsonNode.
40 - * @param json the BaseType JsonNode 41 + * @param baseTypeJson the BaseType JsonNode
41 * @param keyorval the key node or value node 42 * @param keyorval the key node or value node
42 * @return BaseType 43 * @return BaseType
43 */ 44 */
44 - public static BaseType getBaseTypeFromJson(JsonNode json, String keyorval) { 45 + public static BaseType getBaseTypeFromJson(JsonNode baseTypeJson, String keyorval) {
45 - if (json.isValueNode()) { 46 + if (baseTypeJson.isValueNode()) {
46 - String type = json.asText().trim(); 47 + String type = baseTypeJson.asText().trim();
47 return fromTypeStr(type); 48 return fromTypeStr(type);
48 } else { 49 } else {
49 - if (!json.has(keyorval)) { 50 + if (!baseTypeJson.has(keyorval)) {
50 - throw new TypedSchemaException("not a type"); 51 + String message = "Abnormal BaseType JsonNode, it should contain 'key' or 'value' node but was not found"
52 + + ObjectMapperUtil.convertToString(baseTypeJson);
53 + throw new AbnormalJsonNodeException(message);
51 } 54 }
52 - return fromJsonNode(json.get(keyorval)); 55 + return fromJsonNode(baseTypeJson.get(keyorval));
53 } 56 }
54 } 57 }
55 58
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
15 */ 15 */
16 package org.onosproject.ovsdb.rfc.schema.type; 16 package org.onosproject.ovsdb.rfc.schema.type;
17 17
18 -import org.onosproject.ovsdb.rfc.error.TypedSchemaException; 18 +import org.onosproject.ovsdb.rfc.error.AbnormalJsonNodeException;
19 import org.onosproject.ovsdb.rfc.utils.ObjectMapperUtil; 19 import org.onosproject.ovsdb.rfc.utils.ObjectMapperUtil;
20 20
21 import com.fasterxml.jackson.databind.JsonNode; 21 import com.fasterxml.jackson.databind.JsonNode;
...@@ -26,8 +26,8 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -26,8 +26,8 @@ import com.fasterxml.jackson.databind.JsonNode;
26 public final class ColumnTypeFactory { 26 public final class ColumnTypeFactory {
27 27
28 /** 28 /**
29 - * Constructs a ColumnTypeFactory object. 29 + * Constructs a ColumnTypeFactory object. This class should not be
30 - * This class should not be instantiated. 30 + * instantiated.
31 */ 31 */
32 private ColumnTypeFactory() { 32 private ColumnTypeFactory() {
33 } 33 }
...@@ -54,20 +54,22 @@ public final class ColumnTypeFactory { ...@@ -54,20 +54,22 @@ public final class ColumnTypeFactory {
54 } 54 }
55 55
56 /** 56 /**
57 - * JsonNode like "flow_tables":{"type":{"key":{"maxInteger":254,"minInteger":0,"type": 57 + * JsonNode like
58 + * "flow_tables":{"type":{"key":{"maxInteger":254,"minInteger":0,"type":
58 * "integer"},"min":0,"value":{"type":"uuid","refTable":"Flow_Table"},"max": 59 * "integer"},"min":0,"value":{"type":"uuid","refTable":"Flow_Table"},"max":
59 * "unlimited"}}. 60 * "unlimited"}}.
60 - * @param json the ColumnType JsonNode 61 + * @param columnTypeJson the ColumnType JsonNode
61 * @return ColumnType 62 * @return ColumnType
62 */ 63 */
63 - public static ColumnType getColumnTypeFromJson(JsonNode json) { 64 + public static ColumnType getColumnTypeFromJson(JsonNode columnTypeJson) {
64 - if (!json.isObject() || !json.has(Type.VALUE.type())) { 65 + if (!columnTypeJson.isObject() || !columnTypeJson.has(Type.VALUE.type())) {
65 - return createAtomicColumnType(json); 66 + return createAtomicColumnType(columnTypeJson);
66 - } else if (!json.isValueNode() && json.has(Type.VALUE.type())) { 67 + } else if (!columnTypeJson.isValueNode() && columnTypeJson.has(Type.VALUE.type())) {
67 - return createKeyValuedColumnType(json); 68 + return createKeyValuedColumnType(columnTypeJson);
68 } 69 }
69 - throw new TypedSchemaException("could not find the right column type :" 70 + String message = "Abnormal ColumnType JsonNode, it should be AtomicColumnType or KeyValuedColumnType"
70 - + ObjectMapperUtil.convertToString(json)); 71 + + ObjectMapperUtil.convertToString(columnTypeJson);
72 + throw new AbnormalJsonNodeException(message);
71 } 73 }
72 74
73 /** 75 /**
...@@ -76,12 +78,11 @@ public final class ColumnTypeFactory { ...@@ -76,12 +78,11 @@ public final class ColumnTypeFactory {
76 * @return AtomicColumnType entity 78 * @return AtomicColumnType entity
77 */ 79 */
78 private static AtomicColumnType createAtomicColumnType(JsonNode json) { 80 private static AtomicColumnType createAtomicColumnType(JsonNode json) {
79 - BaseType baseType = BaseTypeFactory 81 + BaseType baseType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type());
80 - .getBaseTypeFromJson(json, Type.KEY.type());
81 int min = 1; 82 int min = 1;
82 int max = 1; 83 int max = 1;
83 JsonNode node = json.get("min"); 84 JsonNode node = json.get("min");
84 - if (node != null) { 85 + if (node != null && node.isNumber()) {
85 min = node.asInt(); 86 min = node.asInt();
86 } 87 }
87 node = json.get("max"); 88 node = json.get("max");
...@@ -101,14 +102,12 @@ public final class ColumnTypeFactory { ...@@ -101,14 +102,12 @@ public final class ColumnTypeFactory {
101 * @return KeyValuedColumnType entity 102 * @return KeyValuedColumnType entity
102 */ 103 */
103 private static KeyValuedColumnType createKeyValuedColumnType(JsonNode json) { 104 private static KeyValuedColumnType createKeyValuedColumnType(JsonNode json) {
104 - BaseType keyType = BaseTypeFactory.getBaseTypeFromJson(json, 105 + BaseType keyType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type());
105 - Type.KEY.type()); 106 + BaseType valueType = BaseTypeFactory.getBaseTypeFromJson(json, Type.VALUE.type());
106 - BaseType valueType = BaseTypeFactory
107 - .getBaseTypeFromJson(json, Type.VALUE.type());
108 int min = 1; 107 int min = 1;
109 int max = 1; 108 int max = 1;
110 JsonNode node = json.get("min"); 109 JsonNode node = json.get("min");
111 - if (node != null) { 110 + if (node != null && node.isNumber()) {
112 min = node.asInt(); 111 min = node.asInt();
113 } 112 }
114 node = json.get("max"); 113 node = json.get("max");
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.tableservice; 16 +package org.onosproject.ovsdb.rfc.tableservice;
17 - 17 +
18 -import static com.google.common.base.MoreObjects.toStringHelper; 18 +import static com.google.common.base.MoreObjects.toStringHelper;
19 -import static com.google.common.base.Preconditions.checkNotNull; 19 +import static com.google.common.base.Preconditions.checkNotNull;
20 - 20 +
21 -import java.util.Objects; 21 +import java.util.Objects;
22 - 22 +
23 -import org.onosproject.ovsdb.rfc.error.ColumnSchemaNotFoundException; 23 +import org.onosproject.ovsdb.rfc.error.ColumnSchemaNotFoundException;
24 -import org.onosproject.ovsdb.rfc.error.TableSchemaNotFoundException; 24 +import org.onosproject.ovsdb.rfc.error.TableSchemaNotFoundException;
25 -import org.onosproject.ovsdb.rfc.error.TypedSchemaException; 25 +import org.onosproject.ovsdb.rfc.error.VersionMismatchException;
26 -import org.onosproject.ovsdb.rfc.error.VersionMismatchException; 26 +import org.onosproject.ovsdb.rfc.notation.Column;
27 -import org.onosproject.ovsdb.rfc.notation.Column; 27 +import org.onosproject.ovsdb.rfc.notation.Row;
28 -import org.onosproject.ovsdb.rfc.notation.Row; 28 +import org.onosproject.ovsdb.rfc.notation.UUID;
29 -import org.onosproject.ovsdb.rfc.notation.UUID; 29 +import org.onosproject.ovsdb.rfc.schema.ColumnSchema;
30 -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; 30 +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
31 -import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 31 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
32 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 32 +import org.onosproject.ovsdb.rfc.table.OvsdbTable;
33 -import org.onosproject.ovsdb.rfc.table.OvsdbTable; 33 +import org.onosproject.ovsdb.rfc.table.VersionNum;
34 -import org.onosproject.ovsdb.rfc.table.VersionNum; 34 +import org.onosproject.ovsdb.rfc.utils.VersionUtil;
35 -import org.onosproject.ovsdb.rfc.utils.VersionUtil; 35 +
36 - 36 +/**
37 -/** 37 + * Representation of conversion between Ovsdb table and Row.
38 - * Representation of conversion between Ovsdb table and Row. 38 + */
39 - */ 39 +public abstract class AbstractOvsdbTableService implements OvsdbTableService {
40 -public abstract class AbstractOvsdbTableService implements OvsdbTableService { 40 +
41 - 41 + private final DatabaseSchema dbSchema;
42 - private final DatabaseSchema dbSchema; 42 + private final Row row;
43 - private final Row row; 43 + private final TableDescription tableDesc;
44 - private final TableDescription tableDesc; 44 +
45 - 45 + /**
46 - /** 46 + * Constructs a AbstractOvsdbTableService object.
47 - * Constructs a AbstractOvsdbTableService object. 47 + * @param dbSchema DatabaseSchema entity
48 - * @param dbSchema DatabaseSchema entity 48 + * @param row Row entity
49 - * @param row Row entity 49 + * @param table table name
50 - * @param table table name 50 + * @param formVersion the initial version
51 - * @param formVersion the initial version 51 + */
52 - */ 52 + public AbstractOvsdbTableService(DatabaseSchema dbSchema, Row row, OvsdbTable table,
53 - public AbstractOvsdbTableService(DatabaseSchema dbSchema, Row row, 53 + VersionNum formVersion) {
54 - OvsdbTable table, VersionNum formVersion) { 54 + checkNotNull(dbSchema, "database schema cannot be null");
55 - checkNotNull(dbSchema, "database schema cannot be null"); 55 + checkNotNull(row, "row cannot be null");
56 - checkNotNull(row, "row cannot be null"); 56 + checkNotNull(table, "table cannot be null");
57 - checkNotNull(table, "table cannot be null"); 57 + checkNotNull(formVersion, "the initial version cannot be null");
58 - checkNotNull(formVersion, "the initial version cannot be null"); 58 + this.dbSchema = dbSchema;
59 - this.dbSchema = dbSchema; 59 + row.setTableName(table.tableName());
60 - this.row = row; 60 + this.row = row;
61 - TableDescription tableDesc = new TableDescription(table, formVersion); 61 + TableDescription tableDesc = new TableDescription(table, formVersion);
62 - this.tableDesc = tableDesc; 62 + this.tableDesc = tableDesc;
63 - row.setTableSchema(dbSchema.getTableSchema(table.tableName())); 63 + }
64 - } 64 +
65 - 65 + /**
66 - /** 66 + * Check whether the parameter of dbSchema is valid and check whether the
67 - * Check whether the parameter of dbSchema is valid and check whether the 67 + * table is existent in Database Schema.
68 - * table is existent in Database Schema. 68 + */
69 - */ 69 + private boolean isValid() {
70 - private boolean isValid() { 70 + if (dbSchema == null) {
71 - if (dbSchema == null) { 71 + return false;
72 - return false; 72 + }
73 - } 73 + if (!dbSchema.name().equalsIgnoreCase(tableDesc.database())) {
74 - if (!dbSchema.name().equalsIgnoreCase(tableDesc.database())) { 74 + return false;
75 - return false; 75 + }
76 - } 76 + checkTableSchemaVersion();
77 - checkTableSchemaVersion(); 77 + return true;
78 - return true; 78 + }
79 - } 79 +
80 - 80 + /**
81 - /** 81 + * Check the table version.
82 - * Check the table version. 82 + */
83 - */ 83 + private void checkTableSchemaVersion() {
84 - private void checkTableSchemaVersion() { 84 + String fromVersion = tableDesc.fromVersion();
85 - String fromVersion = tableDesc.fromVersion(); 85 + String untilVersion = tableDesc.untilVersion();
86 - String untilVersion = tableDesc.untilVersion(); 86 + String schemaVersion = dbSchema.version();
87 - String schemaVersion = dbSchema.version(); 87 + checkVersion(schemaVersion, fromVersion, untilVersion);
88 - checkVersion(schemaVersion, fromVersion, untilVersion); 88 + }
89 - } 89 +
90 - 90 + /**
91 - /** 91 + * Check the column version.
92 - * Check the column version. 92 + * @param columnDesc ColumnDescription entity
93 - * @param columnDesc ColumnDescription entity 93 + */
94 - */ 94 + private void checkColumnSchemaVersion(ColumnDescription columnDesc) {
95 - private void checkColumnSchemaVersion(ColumnDescription columnDesc) { 95 + String fromVersion = columnDesc.fromVersion();
96 - String fromVersion = columnDesc.fromVersion(); 96 + String untilVersion = columnDesc.untilVersion();
97 - String untilVersion = columnDesc.untilVersion(); 97 + String schemaVersion = dbSchema.version();
98 - String schemaVersion = dbSchema.version(); 98 + checkVersion(schemaVersion, fromVersion, untilVersion);
99 - checkVersion(schemaVersion, fromVersion, untilVersion); 99 + }
100 - } 100 +
101 - 101 + /**
102 - /** 102 + * Check whether the DatabaseSchema version between the initial version and
103 - * Check whether the DatabaseSchema version between the initial version and 103 + * the end of the version.
104 - * the end of the version. 104 + * @param schemaVersion DatabaseSchema version
105 - * @param schemaVersion DatabaseSchema version 105 + * @param fromVersion The initial version
106 - * @param fromVersion The initial version 106 + * @param untilVersion The end of the version
107 - * @param untilVersion The end of the version 107 + * @throws VersionMismatchException this is a version mismatch exception
108 - * @throws VersionMismatchException this is a version mismatch exception 108 + */
109 - */ 109 + private void checkVersion(String schemaVersion, String fromVersion, String untilVersion) {
110 - private void checkVersion(String schemaVersion, String fromVersion, 110 + VersionUtil.versionMatch(fromVersion);
111 - String untilVersion) { 111 + VersionUtil.versionMatch(untilVersion);
112 - VersionUtil.versionMatch(fromVersion); 112 + if (!fromVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) {
113 - VersionUtil.versionMatch(untilVersion); 113 + if (VersionUtil.versionCompare(schemaVersion, fromVersion) < 0) {
114 - if (!fromVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) { 114 + String message = VersionMismatchException.createFromMessage(schemaVersion,
115 - if (VersionUtil.versionCompare(schemaVersion, fromVersion) < 0) { 115 + fromVersion);
116 - String message = VersionMismatchException 116 + throw new VersionMismatchException(message);
117 - .createFromMessage(schemaVersion, fromVersion); 117 + }
118 - throw new VersionMismatchException(message); 118 + }
119 - } 119 + if (!untilVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) {
120 - } 120 + if (VersionUtil.versionCompare(untilVersion, schemaVersion) < 0) {
121 - if (!untilVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) { 121 + String message = VersionMismatchException.createToMessage(schemaVersion,
122 - if (VersionUtil.versionCompare(untilVersion, schemaVersion) < 0) { 122 + untilVersion);
123 - String message = VersionMismatchException 123 + throw new VersionMismatchException(message);
124 - .createToMessage(schemaVersion, untilVersion); 124 + }
125 - throw new VersionMismatchException(message); 125 + }
126 - } 126 + }
127 - } 127 +
128 - } 128 + /**
129 - 129 + * Returns TableSchema from dbSchema by table name.
130 - /** 130 + * @return TableSchema
131 - * Returns TableSchema from dbSchema by table name. 131 + */
132 - * @return TableSchema 132 + private TableSchema getTableSchema() {
133 - */ 133 + String tableName = tableDesc.name();
134 - private TableSchema getTableSchema() { 134 + return dbSchema.getTableSchema(tableName);
135 - String tableName = tableDesc.name(); 135 + }
136 - return dbSchema.getTableSchema(tableName); 136 +
137 - } 137 + /**
138 - 138 + * Returns ColumnSchema from TableSchema by column name.
139 - /** 139 + * @param columnName column name
140 - * Returns ColumnSchema from TableSchema by column name. 140 + * @return ColumnSchema
141 - * @param tableSchema TableSchema entity 141 + */
142 - * @param columnName column name 142 + private ColumnSchema getColumnSchema(String columnName) {
143 - * @return ColumnSchema 143 + TableSchema tableSchema = getTableSchema();
144 - */ 144 + if (tableSchema == null) {
145 - private ColumnSchema getColumnSchema(TableSchema tableSchema, 145 + String message = TableSchemaNotFoundException.createMessage(tableDesc.name(),
146 - String columnName) { 146 + dbSchema.name());
147 - return tableSchema.getColumnSchema(columnName); 147 + throw new TableSchemaNotFoundException(message);
148 - } 148 + }
149 - 149 + ColumnSchema columnSchema = tableSchema.getColumnSchema(columnName);
150 - @Override 150 + if (columnSchema == null) {
151 - public Column getColumnHandler(ColumnDescription columnDesc) { 151 + String message = ColumnSchemaNotFoundException.createMessage(columnName,
152 - if (!isValid()) { 152 + tableSchema.name());
153 - return null; 153 + throw new ColumnSchemaNotFoundException(message);
154 - } 154 + }
155 - String columnName = columnDesc.name(); 155 + return columnSchema;
156 - checkColumnSchemaVersion(columnDesc); 156 + }
157 - if (columnName == null) { 157 +
158 - throw new TypedSchemaException("Error processing GetColumn : " 158 + @Override
159 - + tableDesc.name() + "." + columnDesc.method()); 159 + public Column getColumnHandler(ColumnDescription columnDesc) {
160 - } 160 + if (!isValid()) {
161 - TableSchema tableSchema = getTableSchema(); 161 + return null;
162 - if (tableSchema == null) { 162 + }
163 - String message = TableSchemaNotFoundException 163 + String columnName = columnDesc.name();
164 - .createMessage(tableDesc.name(), dbSchema.name()); 164 + checkColumnSchemaVersion(columnDesc);
165 - throw new TableSchemaNotFoundException(message); 165 + ColumnSchema columnSchema = getColumnSchema(columnName);
166 - } 166 + if (row == null) {
167 - ColumnSchema columnSchema = getColumnSchema(tableSchema, columnName); 167 + return null;
168 - if (columnSchema == null) { 168 + }
169 - String message = ColumnSchemaNotFoundException 169 + return row.getColumn(columnSchema.name());
170 - .createMessage(columnName, tableSchema.name()); 170 + }
171 - throw new ColumnSchemaNotFoundException(message); 171 +
172 - } 172 + @Override
173 - if (row == null) { 173 + public Object getDataHandler(ColumnDescription columnDesc) {
174 - return new Column(columnSchema, null); 174 + if (!isValid()) {
175 - } 175 + return null;
176 - return row.getColumn(columnSchema); 176 + }
177 - } 177 + String columnName = columnDesc.name();
178 - 178 + checkColumnSchemaVersion(columnDesc);
179 - @Override 179 + ColumnSchema columnSchema = getColumnSchema(columnName);
180 - public Object getDataHandler(ColumnDescription columnDesc) { 180 + if (row == null || row.getColumn(columnSchema.name()) == null) {
181 - if (!isValid()) { 181 + return null;
182 - return null; 182 + }
183 - } 183 + return row.getColumn(columnSchema.name()).data();
184 - String columnName = columnDesc.name(); 184 + }
185 - checkColumnSchemaVersion(columnDesc); 185 +
186 - if (columnName == null) { 186 + @Override
187 - throw new TypedSchemaException("Error processing GetColumn : " 187 + public void setDataHandler(ColumnDescription columnDesc, Object obj) {
188 - + tableDesc.name() + "." + columnDesc.method()); 188 + if (!isValid()) {
189 - } 189 + return;
190 - TableSchema tableSchema = getTableSchema(); 190 + }
191 - if (tableSchema == null) { 191 + String columnName = columnDesc.name();
192 - String message = TableSchemaNotFoundException 192 + checkColumnSchemaVersion(columnDesc);
193 - .createMessage(tableDesc.name(), dbSchema.name()); 193 + ColumnSchema columnSchema = getColumnSchema(columnName);
194 - throw new TableSchemaNotFoundException(message); 194 + Column column = new Column(columnSchema.name(), obj);
195 - } 195 + row.addColumn(columnName, column);
196 - ColumnSchema columnSchema = getColumnSchema(tableSchema, columnName); 196 + }
197 - if (columnSchema == null) { 197 +
198 - String message = ColumnSchemaNotFoundException 198 + @Override
199 - .createMessage(columnName, tableSchema.name()); 199 + public UUID getTableUuid() {
200 - throw new ColumnSchemaNotFoundException(message); 200 + if (!isValid()) {
201 - } 201 + return null;
202 - if (row == null || row.getColumn(columnSchema) == null) { 202 + }
203 - return null; 203 + ColumnDescription columnDesc = new ColumnDescription("_uuid", "getTableUuid");
204 - } 204 + return (UUID) getDataHandler(columnDesc);
205 - return row.getColumn(columnSchema).data(); 205 + }
206 - } 206 +
207 - 207 + @Override
208 - @Override 208 + public Column getTableUuidColumn() {
209 - public void setDataHandler(ColumnDescription columnDesc, Object obj) { 209 + if (!isValid()) {
210 - if (!isValid()) { 210 + return null;
211 - return; 211 + }
212 - } 212 + ColumnDescription columnDesc = new ColumnDescription("_uuid", "getTableUuidColumn");
213 - String columnName = columnDesc.name(); 213 + return (Column) getColumnHandler(columnDesc);
214 - checkColumnSchemaVersion(columnDesc); 214 + }
215 - if (columnName == null) { 215 +
216 - throw new TypedSchemaException("Unable to locate Column Name for " 216 + @Override
217 - + tableDesc.name() + "." + columnDesc.method()); 217 + public UUID getTableVersion() {
218 - } 218 + if (!isValid()) {
219 - TableSchema tableSchema = getTableSchema(); 219 + return null;
220 - ColumnSchema columnSchema = getColumnSchema(tableSchema, columnName); 220 + }
221 - Column column = new Column(columnSchema, obj); 221 + ColumnDescription columnDesc = new ColumnDescription("_version", "getTableVersion");
222 - row.addColumn(columnName, column); 222 + return (UUID) getDataHandler(columnDesc);
223 - } 223 + }
224 - 224 +
225 - @Override 225 + @Override
226 - public Object getTbSchema() { 226 + public Column getTableVersionColumn() {
227 - if (!isValid()) { 227 + if (!isValid()) {
228 - return null; 228 + return null;
229 - } 229 + }
230 - if (dbSchema == null) { 230 + ColumnDescription columnDesc = new ColumnDescription("_version", "getTableVersionColumn");
231 - return null; 231 + return (Column) getColumnHandler(columnDesc);
232 - } 232 + }
233 - return getTableSchema(); 233 +
234 - } 234 + /**
235 - 235 + * Get DatabaseSchema entity.
236 - @Override 236 + * @return DatabaseSchema entity
237 - public UUID getUuid() { 237 + */
238 - if (!isValid()) { 238 + public DatabaseSchema dbSchema() {
239 - return null; 239 + return dbSchema;
240 - } 240 + }
241 - ColumnDescription columnDesc = new ColumnDescription("_uuid", 241 +
242 - "getTbUuid"); 242 + /**
243 - return (UUID) getDataHandler(columnDesc); 243 + * Get Row entity.
244 - } 244 + * @return Row entity
245 - 245 + */
246 - @Override 246 + public Row getRow() {
247 - public Column getUuidColumn() { 247 + if (!isValid()) {
248 - if (!isValid()) { 248 + return null;
249 - return null; 249 + }
250 - } 250 + return this.row;
251 - ColumnDescription columnDesc = new ColumnDescription("_uuid", 251 + }
252 - "getTbUuidColumn"); 252 +
253 - return (Column) getColumnHandler(columnDesc); 253 + /**
254 - } 254 + * Get TableDescription entity.
255 - 255 + * @return TableDescription entity
256 - @Override 256 + */
257 - public UUID getVersion() { 257 + public TableDescription tableDesc() {
258 - if (!isValid()) { 258 + return tableDesc;
259 - return null; 259 + }
260 - } 260 +
261 - ColumnDescription columnDesc = new ColumnDescription("_version", 261 + @Override
262 - "getTbVersion"); 262 + public int hashCode() {
263 - return (UUID) getDataHandler(columnDesc); 263 + return Objects.hash(row);
264 - } 264 + }
265 - 265 +
266 - @Override 266 + @Override
267 - public Column getVersionColumn() { 267 + public boolean equals(Object obj) {
268 - if (!isValid()) { 268 + if (this == obj) {
269 - return null; 269 + return true;
270 - } 270 + }
271 - ColumnDescription columnDesc = new ColumnDescription("_version", 271 + if (obj instanceof AbstractOvsdbTableService) {
272 - "getTbVersionColumn"); 272 + final AbstractOvsdbTableService other = (AbstractOvsdbTableService) obj;
273 - return (Column) getColumnHandler(columnDesc); 273 + return Objects.equals(this.row, other.row);
274 - } 274 + }
275 - 275 + return false;
276 - /** 276 + }
277 - * Get DatabaseSchema entity. 277 +
278 - * @return DatabaseSchema entity 278 + @Override
279 - */ 279 + public String toString() {
280 - public DatabaseSchema dbSchema() { 280 + TableSchema schema = (TableSchema) getTableSchema();
281 - return dbSchema; 281 + String tableName = schema.name();
282 - } 282 + return toStringHelper(this).add("tableName", tableName).add("row", row).toString();
283 - 283 + }
284 - /** 284 +}
285 - * Get Row entity.
286 - * @return Row entity
287 - */
288 - public Row getRow() {
289 - if (!isValid()) {
290 - return null;
291 - }
292 - return this.row;
293 - }
294 -
295 - /**
296 - * Get TableDescription entity.
297 - * @return TableDescription entity
298 - */
299 - public TableDescription tableDesc() {
300 - return tableDesc;
301 - }
302 -
303 - @Override
304 - public int hashCode() {
305 - return Objects.hash(row);
306 - }
307 -
308 - @Override
309 - public boolean equals(Object obj) {
310 - if (this == obj) {
311 - return true;
312 - }
313 - if (obj instanceof AbstractOvsdbTableService) {
314 - final AbstractOvsdbTableService other = (AbstractOvsdbTableService) obj;
315 - return Objects.equals(this.row, other.row);
316 - }
317 - return false;
318 - }
319 -
320 - @Override
321 - public String toString() {
322 - TableSchema schema = (TableSchema) getTbSchema();
323 - String tableName = schema.name();
324 - return toStringHelper(this).add("tableName", tableName).add("row", row)
325 - .toString();
326 - }
327 -}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.tableservice; 16 +package org.onosproject.ovsdb.rfc.tableservice;
17 - 17 +
18 -import org.onosproject.ovsdb.rfc.notation.Column; 18 +import org.onosproject.ovsdb.rfc.notation.Column;
19 -import org.onosproject.ovsdb.rfc.notation.UUID; 19 +import org.onosproject.ovsdb.rfc.notation.UUID;
20 - 20 +
21 -/** 21 +/**
22 - * Representation of conversion between Ovsdb table and Row. 22 + * Representation of conversion between Ovsdb table and Row.
23 - */ 23 + */
24 -public interface OvsdbTableService { 24 +public interface OvsdbTableService {
25 - 25 +
26 - /** 26 + /**
27 - * Get Column from row. 27 + * Get Column from row.
28 - * @param columndesc Column description 28 + * @param columndesc Column description
29 - * @return Column 29 + * @return Column
30 - */ 30 + */
31 - public Column getColumnHandler(ColumnDescription columndesc); 31 + public Column getColumnHandler(ColumnDescription columndesc);
32 - 32 +
33 - /** 33 + /**
34 - * Get Data from row. 34 + * Get Data from row.
35 - * @param columndesc Column description 35 + * @param columndesc Column description
36 - * @return Object column data 36 + * @return Object column data
37 - */ 37 + */
38 - public Object getDataHandler(ColumnDescription columndesc); 38 + public Object getDataHandler(ColumnDescription columndesc);
39 - 39 +
40 - /** 40 + /**
41 - * Set column data of row. 41 + * Set column data of row.
42 - * @param columndesc Column description 42 + * @param columndesc Column description
43 - * @param obj column data 43 + * @param obj column data
44 - */ 44 + */
45 - public void setDataHandler(ColumnDescription columndesc, Object obj); 45 + public void setDataHandler(ColumnDescription columndesc, Object obj);
46 - 46 +
47 - /** 47 + /**
48 - * Returns the TableSchema from row. 48 + * Returns UUID which column name is _uuid.
49 - * @return Object TableSchema 49 + * @return UUID
50 - */ 50 + */
51 - public Object getTbSchema(); 51 + public UUID getTableUuid();
52 - 52 +
53 - /** 53 + /**
54 - * Returns UUID which column name is _uuid. 54 + * Returns UUID Column which column name is _uuid.
55 - * @return UUID 55 + * @return UUID Column
56 - */ 56 + */
57 - public UUID getUuid(); 57 + public Column getTableUuidColumn();
58 - 58 +
59 - /** 59 + /**
60 - * Returns UUID Column which column name is _uuid. 60 + * Returns UUID which column name is _version.
61 - * @return UUID Column 61 + * @return UUID
62 - */ 62 + */
63 - public Column getUuidColumn(); 63 + public UUID getTableVersion();
64 - 64 +
65 - /** 65 + /**
66 - * Returns UUID which column name is _version. 66 + * Returns UUID Column which column name is _version.
67 - * @return UUID 67 + * @return UUID Column
68 - */ 68 + */
69 - public UUID getVersion(); 69 + public Column getTableVersionColumn();
70 - 70 +}
71 - /**
72 - * Returns UUID Column which column name is _version.
73 - * @return UUID Column
74 - */
75 - public Column getVersionColumn();
76 -}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.utils; 16 +package org.onosproject.ovsdb.rfc.utils;
17 - 17 +
18 -import java.util.ArrayList; 18 +import java.util.ArrayList;
19 -import java.util.HashMap; 19 +import java.util.HashMap;
20 -import java.util.Iterator; 20 +import java.util.Iterator;
21 -import java.util.List; 21 +import java.util.List;
22 -import java.util.Map; 22 +import java.util.Map;
23 -import java.util.Map.Entry; 23 +
24 - 24 +import org.onosproject.ovsdb.rfc.error.AbnormalJsonNodeException;
25 -import org.onosproject.ovsdb.rfc.error.AbnormalSchemaException; 25 +import org.onosproject.ovsdb.rfc.error.UnsupportedException;
26 -import org.onosproject.ovsdb.rfc.error.JsonParsingException; 26 +import org.onosproject.ovsdb.rfc.jsonrpc.Callback;
27 -import org.onosproject.ovsdb.rfc.error.UnknownResultException; 27 +import org.onosproject.ovsdb.rfc.jsonrpc.JsonRpcResponse;
28 -import org.onosproject.ovsdb.rfc.jsonrpc.Callback; 28 +import org.onosproject.ovsdb.rfc.message.OperationResult;
29 -import org.onosproject.ovsdb.rfc.jsonrpc.JsonRpcResponse; 29 +import org.onosproject.ovsdb.rfc.message.RowUpdate;
30 -import org.onosproject.ovsdb.rfc.message.OperationResult; 30 +import org.onosproject.ovsdb.rfc.message.TableUpdate;
31 -import org.onosproject.ovsdb.rfc.message.RowUpdate; 31 +import org.onosproject.ovsdb.rfc.message.TableUpdates;
32 -import org.onosproject.ovsdb.rfc.message.TableUpdate; 32 +import org.onosproject.ovsdb.rfc.message.UpdateNotification;
33 -import org.onosproject.ovsdb.rfc.message.TableUpdates; 33 +import org.onosproject.ovsdb.rfc.notation.Column;
34 -import org.onosproject.ovsdb.rfc.message.UpdateNotification; 34 +import org.onosproject.ovsdb.rfc.notation.Row;
35 -import org.onosproject.ovsdb.rfc.notation.Column; 35 +import org.onosproject.ovsdb.rfc.notation.UUID;
36 -import org.onosproject.ovsdb.rfc.notation.Row; 36 +import org.onosproject.ovsdb.rfc.operations.Operation;
37 -import org.onosproject.ovsdb.rfc.notation.UUID; 37 +import org.onosproject.ovsdb.rfc.schema.ColumnSchema;
38 -import org.onosproject.ovsdb.rfc.operations.Operation; 38 +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
39 -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; 39 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
40 -import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 40 +import org.onosproject.ovsdb.rfc.schema.type.ColumnTypeFactory;
41 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 41 +import org.slf4j.Logger;
42 -import org.onosproject.ovsdb.rfc.schema.type.ColumnTypeFactory; 42 +import org.slf4j.LoggerFactory;
43 -import org.slf4j.Logger; 43 +
44 -import org.slf4j.LoggerFactory; 44 +import com.fasterxml.jackson.core.JsonProcessingException;
45 - 45 +import com.fasterxml.jackson.databind.JsonNode;
46 -import com.fasterxml.jackson.core.JsonProcessingException; 46 +import com.fasterxml.jackson.databind.ObjectMapper;
47 -import com.fasterxml.jackson.databind.JsonNode; 47 +import com.google.common.collect.Lists;
48 -import com.fasterxml.jackson.databind.ObjectMapper; 48 +import com.google.common.collect.Maps;
49 -import com.google.common.collect.Lists; 49 +
50 -import com.google.common.collect.Maps; 50 +/**
51 - 51 + * JsonNode utility class. convert JsonNode into Object.
52 -/** 52 + */
53 - * JsonNode utility class. convert JsonNode into Object. 53 +public final class FromJsonUtil {
54 - */ 54 +
55 -public final class FromJsonUtil { 55 + private static final Logger log = LoggerFactory.getLogger(FromJsonUtil.class);
56 - 56 +
57 - private static final Logger log = LoggerFactory 57 + /**
58 - .getLogger(FromJsonUtil.class); 58 + * Constructs a FromJsonUtil object. Utility classes should not have a
59 - 59 + * public or default constructor, otherwise IDE will compile unsuccessfully.
60 - /** 60 + * This class should not be instantiated.
61 - * Constructs a FromJsonUtil object. Utility classes should not have a 61 + */
62 - * public or default constructor, otherwise IDE will compile unsuccessfully. This 62 + private FromJsonUtil() {
63 - * class should not be instantiated. 63 + }
64 - */ 64 +
65 - private FromJsonUtil() { 65 + /**
66 - } 66 + * Verify whether the jsonNode is normal.
67 - 67 + * @param jsonNode JsonNode
68 - /** 68 + * @param nodeStr the node name of JsonNode
69 - * convert JsonNode into DatabaseSchema. 69 + */
70 - * @param dbName database name 70 + private static void validateJsonNode(JsonNode jsonNode, String nodeStr) {
71 - * @param json the JsonNode of get_schema result 71 + if (!jsonNode.isObject() || !jsonNode.has(nodeStr)) {
72 - * @return DatabaseSchema 72 + String message = "Abnormal DatabaseSchema JsonNode, it should contain " + nodeStr
73 - * @throws JsonParsingException this is a JsonNode parse exception 73 + + " node but was not found";
74 - */ 74 + throw new AbnormalJsonNodeException(message);
75 - public static DatabaseSchema jsonNodeToDbSchema(String dbName, JsonNode json) { 75 + }
76 - if (!json.isObject() || !json.has("tables")) { 76 + }
77 - throw new JsonParsingException( 77 +
78 - "bad DatabaseSchema root, expected \"tables\" as child but was not found"); 78 + /**
79 - } 79 + * convert JsonNode into DatabaseSchema.
80 - if (!json.isObject() || !json.has("version")) { 80 + * @param dbName database name
81 - throw new JsonParsingException( 81 + * @param dbJson the JsonNode of get_schema result
82 - "bad DatabaseSchema root, expected \"version\" as child but was not found"); 82 + * @return DatabaseSchema
83 - } 83 + * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception
84 - 84 + */
85 - String dbVersion = json.get("version").asText(); 85 + public static DatabaseSchema jsonNodeToDbSchema(String dbName, JsonNode dbJson) {
86 - 86 + validateJsonNode(dbJson, "tables");
87 - Map<String, TableSchema> tables = new HashMap<>(); 87 + validateJsonNode(dbJson, "version");
88 - for (Iterator<Map.Entry<String, JsonNode>> iter = json.get("tables") 88 + String dbVersion = dbJson.get("version").asText();
89 - .fields(); iter.hasNext();) { 89 + Map<String, TableSchema> tables = new HashMap<>();
90 - Map.Entry<String, JsonNode> table = iter.next(); 90 + Iterator<Map.Entry<String, JsonNode>> tablesIter = dbJson.get("tables").fields();
91 - tables.put(table.getKey(), 91 + while (tablesIter.hasNext()) {
92 - jsonNodeToTableSchema(table.getKey(), table.getValue())); 92 + Map.Entry<String, JsonNode> table = tablesIter.next();
93 - } 93 + tables.put(table.getKey(), jsonNodeToTableSchema(table.getKey(), table.getValue()));
94 - 94 + }
95 - return new DatabaseSchema(dbName, dbVersion, tables); 95 + return new DatabaseSchema(dbName, dbVersion, tables);
96 - } 96 + }
97 - 97 +
98 - /** 98 + /**
99 - * convert JsonNode into TableSchema. 99 + * convert JsonNode into TableSchema.
100 - * @param tableName table name 100 + * @param tableName table name
101 - * @param json table JsonNode 101 + * @param tableJson table JsonNode
102 - * @return TableSchema 102 + * @return TableSchema
103 - * @throws AbnormalSchemaException this is an abnormal schema exception 103 + * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception
104 - */ 104 + */
105 - private static TableSchema jsonNodeToTableSchema(String tableName, 105 + private static TableSchema jsonNodeToTableSchema(String tableName, JsonNode tableJson) {
106 - JsonNode json) { 106 + validateJsonNode(tableJson, "columns");
107 - 107 + Map<String, ColumnSchema> columns = new HashMap<>();
108 - if (!json.isObject() || !json.has("columns")) { 108 + Iterator<Map.Entry<String, JsonNode>> columnsIter = tableJson.get("columns").fields();
109 - throw new AbnormalSchemaException( 109 + while (columnsIter.hasNext()) {
110 - "bad tableschema root, expected \"columns\" as child"); 110 + Map.Entry<String, JsonNode> column = columnsIter.next();
111 - } 111 + columns.put(column.getKey(), jsonNodeToColumnSchema(column.getKey(), column.getValue()));
112 - 112 + }
113 - Map<String, ColumnSchema> columns = new HashMap<>(); 113 + return new TableSchema(tableName, columns);
114 - for (Iterator<Map.Entry<String, JsonNode>> iter = json.get("columns") 114 + }
115 - .fields(); iter.hasNext();) { 115 +
116 - Map.Entry<String, JsonNode> column = iter.next(); 116 + /**
117 - columns.put(column.getKey(), 117 + * convert JsonNode into ColumnSchema.
118 - jsonNodeToColumnSchema(column.getKey(), 118 + * @param name column name
119 - column.getValue())); 119 + * @param columnJson column JsonNode
120 - } 120 + * @return ColumnSchema
121 - 121 + * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception
122 - return new TableSchema(tableName, columns); 122 + */
123 - } 123 + private static ColumnSchema jsonNodeToColumnSchema(String name, JsonNode columnJson) {
124 - 124 + validateJsonNode(columnJson, "type");
125 - /** 125 + return new ColumnSchema(name, ColumnTypeFactory.getColumnTypeFromJson(columnJson
126 - * convert JsonNode into ColumnSchema. 126 + .get("type")));
127 - * @param name column name 127 + }
128 - * @param json JsonNode 128 +
129 - * @return ColumnSchema 129 + /**
130 - * @throws AbnormalSchemaException this is an abnormal schema exception 130 + * convert JsonNode into the returnType of methods in OvsdbRPC class.
131 - */ 131 + * @param resultJsonNode the result JsonNode
132 - private static ColumnSchema jsonNodeToColumnSchema(String name, 132 + * @param methodName the method name of methods in OvsdbRPC class
133 - JsonNode json) { 133 + * @param objectMapper ObjectMapper entity
134 - if (!json.isObject() || !json.has("type")) { 134 + * @return Object
135 - throw new AbnormalSchemaException( 135 + * @throws UnsupportedException this is an unsupported exception
136 - "bad column schema root, expected \"type\" as child"); 136 + */
137 - } 137 + private static Object convertResultType(JsonNode resultJsonNode, String methodName,
138 - 138 + ObjectMapper objectMapper) {
139 - return new ColumnSchema(name, 139 + switch (methodName) {
140 - ColumnTypeFactory.getColumnTypeFromJson(json 140 + case "getSchema":
141 - .get("type"))); 141 + case "monitor":
142 - } 142 + return resultJsonNode;
143 - 143 + case "echo":
144 - /** 144 + case "listDbs":
145 - * convert JsonNode into the returnType of methods in OvsdbRPC class. 145 + return objectMapper.convertValue(resultJsonNode, objectMapper.getTypeFactory()
146 - * @param resultJsonNode the result JsonNode 146 + .constructParametricType(List.class, String.class));
147 - * @param methodName the method name of methods in OvsdbRPC class 147 + case "transact":
148 - * @param objectMapper ObjectMapper entity 148 + return objectMapper.convertValue(resultJsonNode, objectMapper.getTypeFactory()
149 - * @return Object 149 + .constructParametricType(List.class, JsonNode.class));
150 - * @throws UnknownResultException this is an unknown result exception 150 + default:
151 - */ 151 + throw new UnsupportedException("does not support this rpc method" + methodName);
152 - private static Object convertResultType(JsonNode resultJsonNode, 152 + }
153 - String methodName, 153 + }
154 - ObjectMapper objectMapper) { 154 +
155 - switch (methodName) { 155 + /**
156 - case "getSchema": 156 + * convert JsonNode into the returnType of methods in OvsdbRPC class.
157 - case "monitor": 157 + * @param jsonNode the result JsonNode
158 - return resultJsonNode; 158 + * @param methodName the method name of methods in OvsdbRPC class
159 - case "echo": 159 + * @return Object
160 - case "listDbs": 160 + */
161 - return objectMapper 161 + public static Object jsonResultParser(JsonNode jsonNode, String methodName) {
162 - .convertValue(resultJsonNode, objectMapper.getTypeFactory() 162 + ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper();
163 - .constructParametricType(List.class, String.class)); 163 + JsonNode error = jsonNode.get("error");
164 - case "transact": 164 + if (error != null && !error.isNull()) {
165 - return objectMapper 165 + log.error("jsonRpcResponse error : {}", error.toString());
166 - .convertValue(resultJsonNode, 166 + }
167 - objectMapper 167 + JsonNode resultJsonNode = jsonNode.get("result");
168 - .getTypeFactory() 168 + Object result = convertResultType(resultJsonNode, methodName, objectMapper);
169 - .constructParametricType(List.class, 169 + return result;
170 - JsonNode.class)); 170 + }
171 - default: 171 +
172 - throw new UnknownResultException("Don't know how to handle this"); 172 + /**
173 - } 173 + * When monitor the ovsdb tables, if a table update, ovs send update
174 - } 174 + * notification, then call callback function.
175 - 175 + * @param jsonNode the result JsonNode
176 - /** 176 + * @param callback the callback function
177 - * convert JsonNode into the returnType of methods in OvsdbRPC class. 177 + * @throws UnsupportedException this is an unsupported exception
178 - * @param jsonNode the result JsonNode 178 + */
179 - * @param methodName the method name of methods in OvsdbRPC class 179 + public static void jsonCallbackRequestParser(JsonNode jsonNode, Callback callback) {
180 - * @return Object 180 + ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper();
181 - */ 181 + JsonNode params = jsonNode.get("params");
182 - public static Object jsonResultParser(JsonNode jsonNode, String methodName) { 182 + Object param = null;
183 - ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); 183 + String methodName = jsonNode.get("method").asText();
184 - JsonNode error = jsonNode.get("error"); 184 + switch (methodName) {
185 - if (error != null && !error.isNull()) { 185 + case "update":
186 - log.error("Error : {}", error.toString()); 186 + param = objectMapper.convertValue(params, UpdateNotification.class);
187 - } 187 + callback.update((UpdateNotification) param);
188 - JsonNode resultJsonNode = jsonNode.get("result"); 188 + break;
189 - Object result = convertResultType(resultJsonNode, methodName, 189 + default:
190 - objectMapper); 190 + throw new UnsupportedException("does not support this callback method: " + methodName);
191 - return result; 191 + }
192 - } 192 + }
193 - 193 +
194 - /** 194 + /**
195 - * When monitor the ovsdb tables, if a table update, ovs send update 195 + * Ovs send echo request to keep the heart, need we return echo result.
196 - * notification, then call callback function. 196 + * @param jsonNode the result JsonNode
197 - * @param jsonNode the result JsonNode 197 + * @return JsonRpcResponse String
198 - * @param callback the callback function 198 + */
199 - * @throws UnknownResultException this is an unknown result exception 199 + public static String getEchoRequestStr(JsonNode jsonNode) {
200 - */ 200 + ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper();
201 - public static void jsonCallbackRequestParser(JsonNode jsonNode, 201 + String str = null;
202 - Callback callback) { 202 + if (jsonNode.get("method").asText().equals("echo")) {
203 - ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); 203 + JsonRpcResponse response = new JsonRpcResponse(jsonNode.get("id").asText());
204 - JsonNode params = jsonNode.get("params"); 204 + try {
205 - Object param = null; 205 + str = objectMapper.writeValueAsString(response);
206 - String methodName = jsonNode.get("method").asText(); 206 + } catch (JsonProcessingException e) {
207 - switch (methodName) { 207 + log.error("JsonProcessingException while converting JsonNode into string: ", e);
208 - case "update": 208 + }
209 - param = objectMapper.convertValue(params, UpdateNotification.class); 209 + }
210 - callback.update((UpdateNotification) param); 210 + return str;
211 - break; 211 + }
212 - default: 212 +
213 - throw new UnknownResultException("Cannot handle this method: " 213 + /**
214 - + methodName); 214 + * Convert the List of Operation result into List of OperationResult .
215 - } 215 + * @param input the List of JsonNode
216 - } 216 + * @param operations the List of Operation
217 - 217 + * @return the List of OperationResult
218 - /** 218 + */
219 - * Ovs send echo request to keep the heart, need we return echo result. 219 + public static List<OperationResult> jsonNodeToOperationResult(List<JsonNode> input,
220 - * @param jsonNode the result JsonNode 220 + List<Operation> operations) {
221 - * @return JsonRpcResponse String 221 + ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(false);
222 - */ 222 + List<OperationResult> operationResults = new ArrayList<OperationResult>();
223 - public static String getEchoRequestStr(JsonNode jsonNode) { 223 + for (int i = 0; i < input.size(); i++) {
224 - ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); 224 + JsonNode jsonNode = input.get(i);
225 - String str = null; 225 + Operation operation = operations.get(i);
226 - if (jsonNode.get("method").asText().equals("echo")) { 226 + if (jsonNode != null && jsonNode.size() > 0) {
227 - JsonRpcResponse response = new JsonRpcResponse(jsonNode.get("id") 227 + if (i >= operations.size() || operation.getOp() != "select") {
228 - .asText()); 228 + OperationResult or = objectMapper.convertValue(jsonNode, OperationResult.class);
229 - try { 229 + operationResults.add(or);
230 - str = objectMapper.writeValueAsString(response); 230 + } else {
231 - } catch (JsonProcessingException e) { 231 + List<Row> rows = createRows(operation.getTableSchema(), jsonNode);
232 - log.error("JsonProcessingException while converting JsonNode into string ", e); 232 + OperationResult or = new OperationResult(rows);
233 - } 233 + operationResults.add(or);
234 - } 234 + }
235 - return str; 235 + }
236 - } 236 + }
237 - 237 + return operationResults;
238 - /** 238 + }
239 - * Convert the List of Operation result into List of OperationResult . 239 +
240 - * @param input the List of JsonNode 240 + /**
241 - * @param operations the List of Operation 241 + * Convert Operation JsonNode into Rows.
242 - * @return the List of OperationResult 242 + * @param tableSchema TableSchema entity
243 - */ 243 + * @param rowsNode JsonNode
244 - public static List<OperationResult> jsonNodeToOperationResult(List<JsonNode> input, 244 + * @return ArrayList<Row> the List of Row
245 - List<Operation> operations) { 245 + */
246 - ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(false); 246 + private static ArrayList<Row> createRows(TableSchema tableSchema, JsonNode rowsNode) {
247 - List<OperationResult> operationResults = new ArrayList<OperationResult>(); 247 + validateJsonNode(rowsNode, "rows");
248 - for (int i = 0; i < input.size(); i++) { 248 + ArrayList<Row> rows = Lists.newArrayList();
249 - JsonNode jsonNode = input.get(i); 249 + for (JsonNode rowNode : rowsNode.get("rows")) {
250 - Operation operation = operations.get(i); 250 + rows.add(createRow(tableSchema, rowNode));
251 - if (jsonNode != null && jsonNode.size() > 0) { 251 + }
252 - if (i >= operations.size() || operation.getOp() != "select") { 252 + return rows;
253 - OperationResult or = objectMapper.convertValue(jsonNode, 253 + }
254 - OperationResult.class); 254 +
255 - operationResults.add(or); 255 + /**
256 - } else { 256 + * convert the params of Update Notification into TableUpdates.
257 - List<Row> rows = createRows(operation.getTableSchema(), jsonNode); 257 + * @param updatesJson the params of Update Notification
258 - OperationResult or = new OperationResult(rows); 258 + * @param dbSchema DatabaseSchema entity
259 - operationResults.add(or); 259 + * @return TableUpdates
260 - } 260 + */
261 - } 261 + public static TableUpdates jsonNodeToTableUpdates(JsonNode updatesJson, DatabaseSchema dbSchema) {
262 - } 262 + Map<String, TableUpdate> tableUpdateMap = Maps.newHashMap();
263 - return operationResults; 263 + Iterator<Map.Entry<String, JsonNode>> tableUpdatesItr = updatesJson.fields();
264 - } 264 + while (tableUpdatesItr.hasNext()) {
265 - 265 + Map.Entry<String, JsonNode> entry = tableUpdatesItr.next();
266 - /** 266 + TableSchema tableSchema = dbSchema.getTableSchema(entry.getKey());
267 - * Convert Operation JsonNode into Rows. 267 + TableUpdate tableUpdate = jsonNodeToTableUpdate(tableSchema, entry.getValue());
268 - * @param tableSchema TableSchema entity 268 + tableUpdateMap.put(entry.getKey(), tableUpdate);
269 - * @param rowsNode JsonNode 269 + }
270 - * @return ArrayList<Row> the List of Row 270 + return TableUpdates.tableUpdates(tableUpdateMap);
271 - */ 271 + }
272 - private static ArrayList<Row> createRows(TableSchema tableSchema, 272 +
273 - JsonNode rowsNode) { 273 + /**
274 - ArrayList<Row> rows = Lists.newArrayList(); 274 + * convert the params of Update Notification into TableUpdate.
275 - for (JsonNode rowNode : rowsNode.get("rows")) { 275 + * @param tableSchema TableSchema entity
276 - rows.add(createRow(tableSchema, rowNode)); 276 + * @param updateJson the table-update in params of Update Notification
277 - } 277 + * @return TableUpdate
278 - return rows; 278 + */
279 - } 279 + public static TableUpdate jsonNodeToTableUpdate(TableSchema tableSchema, JsonNode updateJson) {
280 - 280 + Map<UUID, RowUpdate> rows = Maps.newHashMap();
281 - /** 281 + Iterator<Map.Entry<String, JsonNode>> tableUpdateItr = updateJson.fields();
282 - * convert the params of Update Notification into TableUpdates. 282 + while (tableUpdateItr.hasNext()) {
283 - * @param updatesJson the params of Update Notification 283 + Map.Entry<String, JsonNode> oldNewRow = tableUpdateItr.next();
284 - * @param dbSchema DatabaseSchema entity 284 + String uuidStr = oldNewRow.getKey();
285 - * @return TableUpdates 285 + UUID uuid = UUID.uuid(uuidStr);
286 - */ 286 + JsonNode newR = oldNewRow.getValue().get("new");
287 - public static TableUpdates jsonNodeToTableUpdates(JsonNode updatesJson, 287 + JsonNode oldR = oldNewRow.getValue().get("old");
288 - DatabaseSchema dbSchema) { 288 + Row newRow = newR != null ? createRow(tableSchema, newR) : null;
289 - Map<String, TableUpdate> tableUpdateMap = Maps.newHashMap(); 289 + Row oldRow = oldR != null ? createRow(tableSchema, oldR) : null;
290 - for (Iterator<Map.Entry<String, JsonNode>> itr = updatesJson.fields(); itr 290 + RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow);
291 - .hasNext();) { 291 + rows.put(uuid, rowUpdate);
292 - Map.Entry<String, JsonNode> entry = itr.next(); 292 + }
293 - TableSchema tableSchema = dbSchema.getTableSchema(entry.getKey()); 293 + return TableUpdate.tableUpdate(rows);
294 - TableUpdate tableUpdate = jsonNodeToTableUpdate(tableSchema, 294 + }
295 - entry.getValue()); 295 +
296 - tableUpdateMap.put(entry.getKey(), tableUpdate); 296 + /**
297 - } 297 + * Convert Operation JsonNode into Row.
298 - return TableUpdates.tableUpdates(tableUpdateMap); 298 + * @param tableSchema TableSchema entity
299 - } 299 + * @param rowNode JsonNode
300 - 300 + * @return Row
301 - /** 301 + */
302 - * convert the params of Update Notification into TableUpdate. 302 + private static Row createRow(TableSchema tableSchema, JsonNode rowNode) {
303 - * @param tableSchema TableSchema entity 303 + if (tableSchema == null) {
304 - * @param value the table-update in params of Update Notification 304 + return null;
305 - * @return TableUpdate 305 + }
306 - */ 306 + Map<String, Column> columns = Maps.newHashMap();
307 - public static TableUpdate jsonNodeToTableUpdate(TableSchema tableSchema, 307 + Iterator<Map.Entry<String, JsonNode>> rowIter = rowNode.fields();
308 - JsonNode value) { 308 + while (rowIter.hasNext()) {
309 - Map<UUID, RowUpdate> rows = Maps.newHashMap(); 309 + Map.Entry<String, JsonNode> next = rowIter.next();
310 - Iterator<Entry<String, JsonNode>> fields = value.fields(); 310 + ColumnSchema columnSchema = tableSchema.getColumnSchema(next.getKey());
311 - while (fields.hasNext()) { 311 + if (columnSchema != null) {
312 - Map.Entry<String, JsonNode> idOldNew = fields.next(); 312 + String columnName = columnSchema.name();
313 - String uuidStr = idOldNew.getKey(); 313 + Object obj = TransValueUtil.getValueFromJson(next.getValue(), columnSchema.type());
314 - UUID uuid = UUID.uuid(uuidStr); 314 + columns.put(columnName, new Column(columnName, obj));
315 - JsonNode newR = idOldNew.getValue().get("new"); 315 + }
316 - JsonNode oldR = idOldNew.getValue().get("old"); 316 + }
317 - Row newRow = newR != null ? createRow(tableSchema, newR) : null; 317 + return new Row(tableSchema.name(), columns);
318 - Row oldRow = oldR != null ? createRow(tableSchema, oldR) : null; 318 + }
319 - RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow); 319 +
320 - rows.put(uuid, rowUpdate); 320 +}
321 - }
322 - return TableUpdate.tableUpdate(rows);
323 - }
324 -
325 - /**
326 - * Convert Operation JsonNode into Row.
327 - * @param tableSchema TableSchema entity
328 - * @param rowNode JsonNode
329 - * @return Row
330 - */
331 - private static Row createRow(TableSchema tableSchema, JsonNode rowNode) {
332 - List<Column> columns = Lists.newArrayList();
333 - for (Iterator<Map.Entry<String, JsonNode>> iter = rowNode.fields(); iter
334 - .hasNext();) {
335 - Map.Entry<String, JsonNode> next = iter.next();
336 - ColumnSchema schema = tableSchema.getColumnSchema(next.getKey());
337 - if (schema != null) {
338 - Object o = TransValueUtil.getValueFromJson(next.getValue(), schema.type());
339 - columns.add(new Column(schema, o));
340 - }
341 - }
342 - return new Row(tableSchema, columns);
343 - }
344 -
345 -}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.utils; 16 +package org.onosproject.ovsdb.rfc.utils;
17 - 17 +
18 -import io.netty.buffer.ByteBuf; 18 +import io.netty.buffer.ByteBuf;
19 -import io.netty.buffer.ByteBufInputStream; 19 +import io.netty.buffer.ByteBufInputStream;
20 - 20 +
21 -import java.io.IOException; 21 +import java.io.IOException;
22 -import java.util.List; 22 +import java.util.List;
23 -import java.util.Stack; 23 +import java.util.Stack;
24 - 24 +
25 -import org.onosproject.ovsdb.rfc.error.UnsupportedEncodingException; 25 +import org.onosproject.ovsdb.rfc.error.UnsupportedException;
26 -import org.onosproject.ovsdb.rfc.jsonrpc.JsonReadContext; 26 +import org.onosproject.ovsdb.rfc.jsonrpc.JsonReadContext;
27 - 27 +
28 -import com.fasterxml.jackson.core.JsonEncoding; 28 +import com.fasterxml.jackson.core.JsonEncoding;
29 -import com.fasterxml.jackson.core.JsonParseException; 29 +import com.fasterxml.jackson.core.JsonParseException;
30 -import com.fasterxml.jackson.core.JsonParser; 30 +import com.fasterxml.jackson.core.JsonParser;
31 -import com.fasterxml.jackson.core.io.IOContext; 31 +import com.fasterxml.jackson.core.io.IOContext;
32 -import com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper; 32 +import com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper;
33 -import com.fasterxml.jackson.core.util.BufferRecycler; 33 +import com.fasterxml.jackson.core.util.BufferRecycler;
34 -import com.fasterxml.jackson.databind.JsonNode; 34 +import com.fasterxml.jackson.databind.JsonNode;
35 -import com.fasterxml.jackson.databind.MappingJsonFactory; 35 +import com.fasterxml.jackson.databind.MappingJsonFactory;
36 - 36 +
37 -/** 37 +/**
38 - * Decoder utility class. 38 + * Decoder utility class.
39 - */ 39 + */
40 -public final class JsonRpcReaderUtil { 40 +public final class JsonRpcReaderUtil {
41 - 41 +
42 - /** 42 + /**
43 - * Constructs a JsonRpcReaderUtil object. Utility classes should not have a 43 + * Constructs a JsonRpcReaderUtil object. Utility classes should not have a
44 - * public or default constructor, otherwise IDE will compile unsuccessfully. 44 + * public or default constructor, otherwise IDE will compile unsuccessfully.
45 - * This class should not be instantiated. 45 + * This class should not be instantiated.
46 - */ 46 + */
47 - private JsonRpcReaderUtil() { 47 + private JsonRpcReaderUtil() {
48 - } 48 + }
49 - 49 +
50 - /** 50 + /**
51 - * Decode the bytes to Json object. 51 + * Decode the bytes to Json object.
52 - * @param in input of bytes 52 + * @param in input of bytes
53 - * @param out ouput of Json object list 53 + * @param out ouput of Json object list
54 - * @param jrContext context for the last decoding process 54 + * @param jrContext context for the last decoding process
55 - * @throws IOException IOException 55 + * @throws IOException IOException
56 - * @throws JsonParseException JsonParseException 56 + * @throws JsonParseException JsonParseException
57 - */ 57 + */
58 - public static void readToJsonNode(ByteBuf in, List<Object> out, 58 + public static void readToJsonNode(ByteBuf in, List<Object> out, JsonReadContext jrContext)
59 - JsonReadContext jrContext) 59 + throws JsonParseException, IOException {
60 - throws JsonParseException, IOException { 60 + int lastReadBytes = jrContext.getLastReadBytes();
61 - int lastReadBytes = jrContext.getLastReadBytes(); 61 + if (lastReadBytes == 0) {
62 - if (lastReadBytes == 0) { 62 + if (in.readableBytes() < 4) {
63 - if (in.readableBytes() < 4) { 63 + return;
64 - return; 64 + }
65 - } 65 + checkEncoding(in);
66 - checkEncoding(in); 66 + }
67 - } 67 +
68 - 68 + int i = lastReadBytes + in.readerIndex();
69 - int i = lastReadBytes + in.readerIndex(); 69 + Stack<Byte> bufStack = jrContext.getBufStack();
70 - Stack<Byte> bufStack = jrContext.getBufStack(); 70 + for (; i < in.writerIndex(); i++) {
71 - for (; i < in.writerIndex(); i++) { 71 + byte b = in.getByte(i);
72 - byte b = in.getByte(i); 72 + switch (b) {
73 - switch (b) { 73 + case '{':
74 - case '{': 74 + if (!isDoubleQuote(bufStack)) {
75 - if (!isDoubleQuote(bufStack)) { 75 + bufStack.push(b);
76 - bufStack.push(b); 76 + jrContext.setStartMatch(true);
77 - jrContext.setStartMatch(true); 77 + }
78 - } 78 + break;
79 - break; 79 + case '}':
80 - case '}': 80 + if (!isDoubleQuote(bufStack)) {
81 - if (!isDoubleQuote(bufStack)) { 81 + bufStack.pop();
82 - bufStack.pop(); 82 + }
83 - } 83 + break;
84 - break; 84 + case '"':
85 - case '"': 85 + if (in.getByte(i - 1) != '\\') {
86 - if (in.getByte(i - 1) != '\\') { 86 + if (!bufStack.isEmpty() && bufStack.peek() != '"') {
87 - if (!bufStack.isEmpty() && bufStack.peek() != '"') { 87 + bufStack.push(b);
88 - bufStack.push(b); 88 + } else {
89 - } else { 89 + bufStack.pop();
90 - bufStack.pop(); 90 + }
91 - } 91 + }
92 - } 92 + break;
93 - break; 93 + default:
94 - default: 94 + break;
95 - break; 95 + }
96 - } 96 +
97 - 97 + if (jrContext.isStartMatch() && bufStack.isEmpty()) {
98 - if (jrContext.isStartMatch() && bufStack.isEmpty()) { 98 + ByteBuf buf = in.readSlice(i - in.readerIndex() + 1);
99 - ByteBuf buf = in.readSlice(i - in.readerIndex() + 1); 99 + JsonParser jf = new MappingJsonFactory().createParser(new ByteBufInputStream(buf));
100 - JsonParser jf = new MappingJsonFactory() 100 + JsonNode jsonNode = jf.readValueAsTree();
101 - .createParser(new ByteBufInputStream(buf)); 101 + out.add(jsonNode);
102 - JsonNode jsonNode = jf.readValueAsTree(); 102 + lastReadBytes = 0;
103 - out.add(jsonNode); 103 + jrContext.setLastReadBytes(lastReadBytes);
104 - lastReadBytes = 0; 104 + break;
105 - jrContext.setLastReadBytes(lastReadBytes); 105 + }
106 - break; 106 + }
107 - } 107 +
108 - } 108 + if (i >= in.writerIndex()) {
109 - 109 + lastReadBytes = in.readableBytes();
110 - if (i >= in.writerIndex()) { 110 + jrContext.setLastReadBytes(lastReadBytes);
111 - lastReadBytes = in.readableBytes(); 111 + }
112 - jrContext.setLastReadBytes(lastReadBytes); 112 + }
113 - } 113 +
114 - } 114 + /**
115 - 115 + * Filter the invalid characters before decoding.
116 - /** 116 + * @param in input of bytes
117 - * Filter the invalid characters before decoding. 117 + * @param lastReadBytes the bytes for last decoding incomplete record
118 - * @param in input of bytes 118 + */
119 - * @param lastReadBytes the bytes for last decoding incomplete record 119 + private static void fliterCharaters(ByteBuf in) {
120 - */ 120 + while (in.isReadable()) {
121 - private static void fliterCharaters(ByteBuf in) { 121 + int ch = in.getByte(in.readerIndex());
122 - while (in.isReadable()) { 122 + if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) {
123 - int ch = in.getByte(in.readerIndex()); 123 + break;
124 - if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) { 124 + } else {
125 - break; 125 + in.readByte();
126 - } else { 126 + }
127 - in.readByte(); 127 + }
128 - } 128 + }
129 - } 129 +
130 - } 130 + /**
131 - 131 + * Check whether the peek of the stack element is double quote.
132 - /** 132 + * @param jrContext context for the last decoding process
133 - * Check whether the peek of the stack element is double quote. 133 + * @return boolean
134 - * @param jrContext context for the last decoding process 134 + */
135 - * @return boolean 135 + private static boolean isDoubleQuote(Stack<Byte> bufStack) {
136 - */ 136 + if (!bufStack.isEmpty() && bufStack.peek() == '"') {
137 - private static boolean isDoubleQuote(Stack<Byte> bufStack) { 137 + return true;
138 - if (!bufStack.isEmpty() && bufStack.peek() == '"') { 138 + }
139 - return true; 139 + return false;
140 - } 140 + }
141 - return false; 141 +
142 - } 142 + /**
143 - 143 + * Check whether the encoding is valid.
144 - /** 144 + * @param in input of bytes
145 - * Check whether the encoding is valid. 145 + * @throws IOException this is an IO exception
146 - * @param in input of bytes 146 + * @throws UnsupportedException this is an unsupported exception
147 - * @throws IOException this is an IO exception 147 + */
148 - * @throws UnsupportedEncodingException this is an unsupported encode 148 + private static void checkEncoding(ByteBuf in) throws IOException {
149 - * exception 149 + int inputStart = 0;
150 - */ 150 + int inputLength = 4;
151 - private static void checkEncoding(ByteBuf in) throws IOException { 151 + fliterCharaters(in);
152 - int inputStart = 0; 152 + byte[] buff = new byte[4];
153 - int inputLength = 4; 153 + in.getBytes(in.readerIndex(), buff);
154 - fliterCharaters(in); 154 + ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(new IOContext(new BufferRecycler(),
155 - byte[] buff = new byte[4]; 155 + null,
156 - in.getBytes(in.readerIndex(), buff); 156 + false),
157 - ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper( 157 + buff, inputStart,
158 - new IOContext( 158 + inputLength);
159 - new BufferRecycler(), 159 + JsonEncoding jsonEncoding = strapper.detectEncoding();
160 - null, 160 + if (!JsonEncoding.UTF8.equals(jsonEncoding)) {
161 - false), 161 + throw new UnsupportedException("Only UTF-8 encoding is supported.");
162 - buff, 162 + }
163 - inputStart, 163 + }
164 - inputLength); 164 +
165 - JsonEncoding jsonEncoding = strapper.detectEncoding(); 165 +}
166 - if (!JsonEncoding.UTF8.equals(jsonEncoding)) {
167 - throw new UnsupportedEncodingException(
168 - "Only UTF-8 encoding is supported.");
169 - }
170 - }
171 -
172 -}
......
1 -/* 1 +/*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015 Open Networking Laboratory
3 - * 3 + *
4 - * Licensed under the Apache License, Version 2.0 (the "License"); 4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License. 5 + * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at 6 + * You may obtain a copy of the License at
7 - * 7 + *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 - * 9 + *
10 - * Unless required by applicable law or agreed to in writing, software 10 + * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS, 11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and 13 + * See the License for the specific language governing permissions and
14 - * limitations under the License. 14 + * limitations under the License.
15 - */ 15 + */
16 -package org.onosproject.ovsdb.rfc.utils; 16 +package org.onosproject.ovsdb.rfc.utils;
17 - 17 +
18 -import java.util.List; 18 +import java.util.List;
19 -import java.util.Set; 19 +import java.util.Map;
20 - 20 +import java.util.Set;
21 -import org.onosproject.ovsdb.rfc.message.MonitorRequest; 21 +
22 -import org.onosproject.ovsdb.rfc.message.MonitorSelect; 22 +import org.onosproject.ovsdb.rfc.message.MonitorRequest;
23 -import org.onosproject.ovsdb.rfc.operations.Operation; 23 +import org.onosproject.ovsdb.rfc.message.MonitorSelect;
24 -import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 24 +import org.onosproject.ovsdb.rfc.operations.Operation;
25 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 25 +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
26 - 26 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
27 -import com.google.common.base.Function; 27 +
28 -import com.google.common.collect.ImmutableMap; 28 +import com.google.common.collect.Lists;
29 -import com.google.common.collect.Lists; 29 +import com.google.common.collect.Maps;
30 -import com.google.common.collect.Maps; 30 +
31 - 31 +/**
32 -/** 32 + * Params utility class. Params of the request object, refer to RFC7047's
33 - * Params utility class. Params of the request object, refer to RFC7047's Section 33 + * Section 4.1.
34 - * 4.1. 34 + */
35 - */ 35 +public final class ParamUtil {
36 -public final class ParamUtil { 36 +
37 - 37 + /**
38 - /** 38 + * Constructs a ParamUtil object. Utility classes should not have a public
39 - * Constructs a ParamUtil object. Utility classes should not have a 39 + * or default constructor, otherwise IDE will compile unsuccessfully. This
40 - * public or default constructor, otherwise IDE will compile unsuccessfully. This 40 + * class should not be instantiated.
41 - * class should not be instantiated. 41 + */
42 - */ 42 + private ParamUtil() {
43 - private ParamUtil() { 43 + }
44 - } 44 +
45 - 45 + /**
46 - /** 46 + * Returns MonitorRequest, refer to RFC7047's Section 4.1.5.
47 - * Returns MonitorRequest, refer to RFC7047's Section 4.1.5. 47 + * @param tableSchema entity
48 - * @param tableSchema entity 48 + * @return MonitorRequest
49 - * @return MonitorRequest 49 + */
50 - */ 50 + private static MonitorRequest getAllColumnsMonitorRequest(TableSchema tableSchema) {
51 - private static MonitorRequest getAllColumnsMonitorRequest(TableSchema tableSchema) { 51 + String tableName = tableSchema.name();
52 - String tableName = tableSchema.name(); 52 + Set<String> columns = tableSchema.getColumnNames();
53 - Set<String> columns = tableSchema.getColumnNames(); 53 + MonitorSelect select = new MonitorSelect(true, true, true, true);
54 - MonitorSelect select = new MonitorSelect(true, true, true, true); 54 + MonitorRequest monitorRequest = new MonitorRequest(tableName, columns, select);
55 - MonitorRequest monitorRequest = new MonitorRequest(tableName, columns, 55 + return monitorRequest;
56 - select); 56 + }
57 - return monitorRequest; 57 +
58 - } 58 + /**
59 - 59 + * Returns params of monitor method, refer to RFC7047's Section 4.1.5.
60 - /** 60 + * @param monotorId json-value, refer to RFC7047's Section 4.1.5.
61 - * Returns params of monitor method, refer to RFC7047's Section 4.1.5. 61 + * @param dbSchema DatabaseSchema entity
62 - * @param monotorId json-value, refer to RFC7047's Section 4.1.5. 62 + * @return List of Object, the params of monitor request
63 - * @param dbSchema DatabaseSchema entity 63 + */
64 - * @return List of Object, the params of monitor request 64 + public static List<Object> getMonitorParams(String monotorId, DatabaseSchema dbSchema) {
65 - */ 65 + Set<String> tables = dbSchema.getTableNames();
66 - public static List<Object> getMonitorParams(String monotorId, 66 + Map<String, MonitorRequest> mrMap = Maps.newHashMap();
67 - DatabaseSchema dbSchema) { 67 + for (String tableName : tables) {
68 - Set<String> tables = dbSchema.getTableNames(); 68 + TableSchema tableSchema = dbSchema.getTableSchema(tableName);
69 - List<MonitorRequest> monitorRequests = Lists.newArrayList(); 69 + MonitorRequest monitorRequest = getAllColumnsMonitorRequest(tableSchema);
70 - for (String tableName : tables) { 70 + mrMap.put(tableName, monitorRequest);
71 - TableSchema tableSchema = dbSchema.getTableSchema(tableName); 71 + }
72 - monitorRequests.add(getAllColumnsMonitorRequest(tableSchema)); 72 + return Lists.newArrayList(dbSchema.name(), monotorId, mrMap);
73 - } 73 + }
74 - ImmutableMap<String, MonitorRequest> reqMap = Maps 74 +
75 - .uniqueIndex(monitorRequests, 75 + /**
76 - new Function<MonitorRequest, String>() { 76 + * Returns params of transact method, refer to RFC7047's Section 4.1.3.
77 - @Override 77 + * @param dbSchema DatabaseSchema entity
78 - public String apply(MonitorRequest input) { 78 + * @param operations operation*, refer to RFC7047's Section 4.1.3.
79 - return input.getTableName(); 79 + * @return List of Object, the params of transact request
80 - } 80 + */
81 - }); 81 + public static List<Object> getTransactParams(DatabaseSchema dbSchema, List<Operation> operations) {
82 - return Lists.<Object>newArrayList(dbSchema.name(), monotorId, 82 + return Lists.newArrayList(dbSchema.name(), operations);
83 - reqMap); 83 + }
84 - } 84 +}
85 -
86 - /**
87 - * Returns params of transact method, refer to RFC7047's Section 4.1.3.
88 - * @param dbSchema DatabaseSchema entity
89 - * @param operations operation*, refer to RFC7047's Section 4.1.3.
90 - * @return List of Object, the params of transact request
91 - */
92 - public static List<Object> getTransactParams(DatabaseSchema dbSchema,
93 - List<Operation> operations) {
94 - List<Object> lists = Lists.newArrayList((Object) dbSchema.name());
95 - lists.addAll(operations);
96 - return lists;
97 - }
98 -}
......
...@@ -87,33 +87,29 @@ public final class TransValueUtil { ...@@ -87,33 +87,29 @@ public final class TransValueUtil {
87 * @param atoType AtomicColumnType entity 87 * @param atoType AtomicColumnType entity
88 * @return Object OvsdbSet or the value of JsonNode 88 * @return Object OvsdbSet or the value of JsonNode
89 */ 89 */
90 - private static Object getValueFromAtoType(JsonNode json, 90 + private static Object getValueFromAtoType(JsonNode json, AtomicColumnType atoType) {
91 - AtomicColumnType atoType) {
92 BaseType baseType = atoType.baseType(); 91 BaseType baseType = atoType.baseType();
93 // If "min" or "max" is not specified, If "min" is not 1 or "max" is not 92 // If "min" or "max" is not specified, If "min" is not 1 or "max" is not
94 - // 1, 93 + // 1, or both, and "value" is not specified, the type is a set of scalar
95 - // or both, and "value" is not specified, the type is a set of scalar 94 + // type "key". Refer to RFC 7047, Section 3.2 <type>.
96 - // type "key".
97 - // Refer to RFC 7047, Section 3.2 <type>.
98 if (atoType.min() != atoType.max()) { 95 if (atoType.min() != atoType.max()) {
99 Set set = Sets.newHashSet(); 96 Set set = Sets.newHashSet();
100 if (json.isArray()) { 97 if (json.isArray()) {
101 if (json.size() == 2) { 98 if (json.size() == 2) {
102 - if (json.get(0).isTextual() 99 + if (json.get(0).isTextual() && "set".equals(json.get(0).asText())) {
103 - && "set".equals(json.get(0).asText())) {
104 for (JsonNode node : json.get(1)) { 100 for (JsonNode node : json.get(1)) {
105 - set.add(TransValueUtil.transToValue(node, baseType)); 101 + set.add(transToValue(node, baseType));
106 } 102 }
107 } else { 103 } else {
108 - set.add(TransValueUtil.transToValue(json, baseType)); 104 + set.add(transToValue(json, baseType));
109 } 105 }
110 } 106 }
111 } else { 107 } else {
112 - set.add(TransValueUtil.transToValue(json, baseType)); 108 + set.add(transToValue(json, baseType));
113 } 109 }
114 return OvsdbSet.ovsdbSet(set); 110 return OvsdbSet.ovsdbSet(set);
115 } else { 111 } else {
116 - return TransValueUtil.transToValue(json, baseType); 112 + return transToValue(json, baseType);
117 } 113 }
118 } 114 }
119 115
...@@ -123,19 +119,15 @@ public final class TransValueUtil { ...@@ -123,19 +119,15 @@ public final class TransValueUtil {
123 * @param kvType KeyValuedColumnType entity 119 * @param kvType KeyValuedColumnType entity
124 * @return Object OvsdbMap 120 * @return Object OvsdbMap
125 */ 121 */
126 - private static Object getValueFromKvType(JsonNode json, 122 + private static Object getValueFromKvType(JsonNode json, KeyValuedColumnType kvType) {
127 - KeyValuedColumnType kvType) {
128 if (json.isArray()) { 123 if (json.isArray()) {
129 if (json.size() == 2) { 124 if (json.size() == 2) {
130 - if (json.get(0).isTextual() 125 + if (json.get(0).isTextual() && "map".equals(json.get(0).asText())) {
131 - && "map".equals(json.get(0).asText())) {
132 Map map = Maps.newHashMap(); 126 Map map = Maps.newHashMap();
133 for (JsonNode pairNode : json.get(1)) { 127 for (JsonNode pairNode : json.get(1)) {
134 if (pairNode.isArray() && json.size() == 2) { 128 if (pairNode.isArray() && json.size() == 2) {
135 - Object key = TransValueUtil.transToValue(pairNode 129 + Object key = transToValue(pairNode.get(0), kvType.keyType());
136 - .get(0), kvType.keyType()); 130 + Object value = transToValue(pairNode.get(1), kvType.valueType());
137 - Object value = TransValueUtil.transToValue(pairNode
138 - .get(1), kvType.valueType());
139 map.put(key, value); 131 map.put(key, value);
140 } 132 }
141 } 133 }
...@@ -166,14 +158,13 @@ public final class TransValueUtil { ...@@ -166,14 +158,13 @@ public final class TransValueUtil {
166 if (valueNode.isArray()) { 158 if (valueNode.isArray()) {
167 if (valueNode.size() == 2) { 159 if (valueNode.size() == 2) {
168 if (valueNode.get(0).isTextual() 160 if (valueNode.get(0).isTextual()
169 - && "uuid".equals(valueNode.get(0).asText()) 161 + && ("uuid".equals(valueNode.get(0).asText()) || "named-uuid"
170 - || "named-uuid".equals(valueNode.get(0).asText())) { 162 + .equals(valueNode.get(0).asText()))) {
171 return UUID.uuid(valueNode.get(1).asText()); 163 return UUID.uuid(valueNode.get(1).asText());
172 } 164 }
173 } 165 }
174 } else { 166 } else {
175 - return new RefTableRow(((UuidBaseType) baseType).getRefTable(), 167 + return new RefTableRow(((UuidBaseType) baseType).getRefTable(), valueNode);
176 - valueNode);
177 } 168 }
178 } 169 }
179 return null; 170 return null;
......