Sho SHIMIZU
Committed by Gerrit Code Review

Use LF as line separator

Change-Id: I41ed7eeefe076ab3f8b09f26d1e091e6d3394846
Showing 21 changed files with 3792 additions and 3792 deletions
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.controller.driver; 16 +package org.onosproject.ovsdb.controller.driver;
17 - 17 +
18 -import io.netty.channel.Channel; 18 +import io.netty.channel.Channel;
19 - 19 +
20 -import java.net.InetSocketAddress; 20 +import java.net.InetSocketAddress;
21 -import java.util.ArrayList; 21 +import java.util.ArrayList;
22 -import java.util.HashSet; 22 +import java.util.HashSet;
23 -import java.util.Iterator; 23 +import java.util.Iterator;
24 -import java.util.List; 24 +import java.util.List;
25 -import java.util.Map; 25 +import java.util.Map;
26 -import java.util.Set; 26 +import java.util.Set;
27 -import java.util.concurrent.ConcurrentMap; 27 +import java.util.concurrent.ConcurrentMap;
28 -import java.util.concurrent.ExecutionException; 28 +import java.util.concurrent.ExecutionException;
29 - 29 +
30 -import org.onlab.packet.IpAddress; 30 +import org.onlab.packet.IpAddress;
31 -import org.onosproject.ovsdb.controller.OvsdbBridge; 31 +import org.onosproject.ovsdb.controller.OvsdbBridge;
32 -import org.onosproject.ovsdb.controller.OvsdbBridgeName; 32 +import org.onosproject.ovsdb.controller.OvsdbBridgeName;
33 -import org.onosproject.ovsdb.controller.OvsdbClientService; 33 +import org.onosproject.ovsdb.controller.OvsdbClientService;
34 -import org.onosproject.ovsdb.controller.OvsdbConstant; 34 +import org.onosproject.ovsdb.controller.OvsdbConstant;
35 -import org.onosproject.ovsdb.controller.OvsdbDatapathId; 35 +import org.onosproject.ovsdb.controller.OvsdbDatapathId;
36 -import org.onosproject.ovsdb.controller.OvsdbNodeId; 36 +import org.onosproject.ovsdb.controller.OvsdbNodeId;
37 -import org.onosproject.ovsdb.controller.OvsdbPort; 37 +import org.onosproject.ovsdb.controller.OvsdbPort;
38 -import org.onosproject.ovsdb.controller.OvsdbPortName; 38 +import org.onosproject.ovsdb.controller.OvsdbPortName;
39 -import org.onosproject.ovsdb.controller.OvsdbPortNumber; 39 +import org.onosproject.ovsdb.controller.OvsdbPortNumber;
40 -import org.onosproject.ovsdb.controller.OvsdbRowStore; 40 +import org.onosproject.ovsdb.controller.OvsdbRowStore;
41 -import org.onosproject.ovsdb.controller.OvsdbStore; 41 +import org.onosproject.ovsdb.controller.OvsdbStore;
42 -import org.onosproject.ovsdb.controller.OvsdbTableStore; 42 +import org.onosproject.ovsdb.controller.OvsdbTableStore;
43 -import org.onosproject.ovsdb.controller.OvsdbTunnel; 43 +import org.onosproject.ovsdb.controller.OvsdbTunnel;
44 -import org.onosproject.ovsdb.rfc.jsonrpc.Callback; 44 +import org.onosproject.ovsdb.rfc.jsonrpc.Callback;
45 -import org.onosproject.ovsdb.rfc.message.OperationResult; 45 +import org.onosproject.ovsdb.rfc.message.OperationResult;
46 -import org.onosproject.ovsdb.rfc.message.TableUpdates; 46 +import org.onosproject.ovsdb.rfc.message.TableUpdates;
47 -import org.onosproject.ovsdb.rfc.notation.Condition; 47 +import org.onosproject.ovsdb.rfc.notation.Condition;
48 -import org.onosproject.ovsdb.rfc.notation.Mutation; 48 +import org.onosproject.ovsdb.rfc.notation.Mutation;
49 -import org.onosproject.ovsdb.rfc.notation.OvsdbSet; 49 +import org.onosproject.ovsdb.rfc.notation.OvsdbSet;
50 -import org.onosproject.ovsdb.rfc.notation.Row; 50 +import org.onosproject.ovsdb.rfc.notation.Row;
51 -import org.onosproject.ovsdb.rfc.notation.UUID; 51 +import org.onosproject.ovsdb.rfc.notation.UUID;
52 -import org.onosproject.ovsdb.rfc.operations.Delete; 52 +import org.onosproject.ovsdb.rfc.operations.Delete;
53 -import org.onosproject.ovsdb.rfc.operations.Insert; 53 +import org.onosproject.ovsdb.rfc.operations.Insert;
54 -import org.onosproject.ovsdb.rfc.operations.Mutate; 54 +import org.onosproject.ovsdb.rfc.operations.Mutate;
55 -import org.onosproject.ovsdb.rfc.operations.Operation; 55 +import org.onosproject.ovsdb.rfc.operations.Operation;
56 -import org.onosproject.ovsdb.rfc.operations.Update; 56 +import org.onosproject.ovsdb.rfc.operations.Update;
57 -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; 57 +import org.onosproject.ovsdb.rfc.schema.ColumnSchema;
58 -import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 58 +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
59 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 59 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
60 -import org.onosproject.ovsdb.rfc.table.Bridge; 60 +import org.onosproject.ovsdb.rfc.table.Bridge;
61 -import org.onosproject.ovsdb.rfc.table.Controller; 61 +import org.onosproject.ovsdb.rfc.table.Controller;
62 -import org.onosproject.ovsdb.rfc.table.Interface; 62 +import org.onosproject.ovsdb.rfc.table.Interface;
63 -import org.onosproject.ovsdb.rfc.table.OvsdbTable; 63 +import org.onosproject.ovsdb.rfc.table.OvsdbTable;
64 -import org.onosproject.ovsdb.rfc.table.Port; 64 +import org.onosproject.ovsdb.rfc.table.Port;
65 -import org.onosproject.ovsdb.rfc.table.TableGenerator; 65 +import org.onosproject.ovsdb.rfc.table.TableGenerator;
66 -import org.onosproject.ovsdb.rfc.utils.ConditionUtil; 66 +import org.onosproject.ovsdb.rfc.utils.ConditionUtil;
67 -import org.onosproject.ovsdb.rfc.utils.FromJsonUtil; 67 +import org.onosproject.ovsdb.rfc.utils.FromJsonUtil;
68 -import org.onosproject.ovsdb.rfc.utils.JsonRpcWriterUtil; 68 +import org.onosproject.ovsdb.rfc.utils.JsonRpcWriterUtil;
69 -import org.onosproject.ovsdb.rfc.utils.MutationUtil; 69 +import org.onosproject.ovsdb.rfc.utils.MutationUtil;
70 -import org.slf4j.Logger; 70 +import org.slf4j.Logger;
71 -import org.slf4j.LoggerFactory; 71 +import org.slf4j.LoggerFactory;
72 - 72 +
73 -import com.fasterxml.jackson.databind.JsonNode; 73 +import com.fasterxml.jackson.databind.JsonNode;
74 -import com.google.common.base.Function; 74 +import com.google.common.base.Function;
75 -import com.google.common.collect.Lists; 75 +import com.google.common.collect.Lists;
76 -import com.google.common.collect.Maps; 76 +import com.google.common.collect.Maps;
77 -import com.google.common.util.concurrent.Futures; 77 +import com.google.common.util.concurrent.Futures;
78 -import com.google.common.util.concurrent.ListenableFuture; 78 +import com.google.common.util.concurrent.ListenableFuture;
79 -import com.google.common.util.concurrent.SettableFuture; 79 +import com.google.common.util.concurrent.SettableFuture;
80 - 80 +
81 -/** 81 +/**
82 - * An representation of an ovsdb client. 82 + * An representation of an ovsdb client.
83 - */ 83 + */
84 -public class DefaultOvsdbClient 84 +public class DefaultOvsdbClient
85 - implements OvsdbProviderService, OvsdbClientService { 85 + implements OvsdbProviderService, OvsdbClientService {
86 - 86 +
87 - private final Logger log = LoggerFactory 87 + private final Logger log = LoggerFactory
88 - .getLogger(DefaultOvsdbClient.class); 88 + .getLogger(DefaultOvsdbClient.class);
89 - 89 +
90 - private Channel channel; 90 + private Channel channel;
91 - 91 +
92 - private OvsdbAgent agent; 92 + private OvsdbAgent agent;
93 - private boolean connected; 93 + private boolean connected;
94 - private OvsdbNodeId nodeId; 94 + private OvsdbNodeId nodeId;
95 - private Callback monitorCallBack; 95 + private Callback monitorCallBack;
96 - 96 +
97 - private OvsdbStore ovsdbStore = new OvsdbStore(); 97 + private OvsdbStore ovsdbStore = new OvsdbStore();
98 - 98 +
99 - private final Map<String, String> requestMethod = Maps.newHashMap(); 99 + private final Map<String, String> requestMethod = Maps.newHashMap();
100 - private final Map<String, SettableFuture<? extends Object>> requestResult = Maps 100 + private final Map<String, SettableFuture<? extends Object>> requestResult = Maps
101 - .newHashMap(); 101 + .newHashMap();
102 - 102 +
103 - private final Map<String, DatabaseSchema> schema = Maps.newHashMap(); 103 + private final Map<String, DatabaseSchema> schema = Maps.newHashMap();
104 - private final Set<OvsdbTunnel> ovsdbTunnels = new HashSet<OvsdbTunnel>(); 104 + private final Set<OvsdbTunnel> ovsdbTunnels = new HashSet<OvsdbTunnel>();
105 - 105 +
106 - /** 106 + /**
107 - * Creates an OvsdbClient. 107 + * Creates an OvsdbClient.
108 - * 108 + *
109 - * @param nodeId ovsdb node id 109 + * @param nodeId ovsdb node id
110 - */ 110 + */
111 - public DefaultOvsdbClient(OvsdbNodeId nodeId) { 111 + public DefaultOvsdbClient(OvsdbNodeId nodeId) {
112 - this.nodeId = nodeId; 112 + this.nodeId = nodeId;
113 - } 113 + }
114 - 114 +
115 - @Override 115 + @Override
116 - public OvsdbNodeId nodeId() { 116 + public OvsdbNodeId nodeId() {
117 - return nodeId; 117 + return nodeId;
118 - } 118 + }
119 - 119 +
120 - @Override 120 + @Override
121 - public void setAgent(OvsdbAgent agent) { 121 + public void setAgent(OvsdbAgent agent) {
122 - if (this.agent == null) { 122 + if (this.agent == null) {
123 - this.agent = agent; 123 + this.agent = agent;
124 - } 124 + }
125 - } 125 + }
126 - 126 +
127 - @Override 127 + @Override
128 - public void setChannel(Channel channel) { 128 + public void setChannel(Channel channel) {
129 - this.channel = channel; 129 + this.channel = channel;
130 - } 130 + }
131 - 131 +
132 - @Override 132 + @Override
133 - public void setConnection(boolean connected) { 133 + public void setConnection(boolean connected) {
134 - this.connected = connected; 134 + this.connected = connected;
135 - } 135 + }
136 - 136 +
137 - @Override 137 + @Override
138 - public boolean isConnected() { 138 + public boolean isConnected() {
139 - return this.connected; 139 + return this.connected;
140 - } 140 + }
141 - 141 +
142 - @Override 142 + @Override
143 - public void nodeAdded() { 143 + public void nodeAdded() {
144 - this.agent.addConnectedNode(nodeId, this); 144 + this.agent.addConnectedNode(nodeId, this);
145 - } 145 + }
146 - 146 +
147 - @Override 147 + @Override
148 - public void nodeRemoved() { 148 + public void nodeRemoved() {
149 - this.agent.removeConnectedNode(nodeId); 149 + this.agent.removeConnectedNode(nodeId);
150 - channel.disconnect(); 150 + channel.disconnect();
151 - } 151 + }
152 - 152 +
153 - /** 153 + /**
154 - * Gets the ovsdb table store. 154 + * Gets the ovsdb table store.
155 - * 155 + *
156 - * @param dbName the ovsdb database name 156 + * @param dbName the ovsdb database name
157 - * @return ovsTableStore, empty if table store is find 157 + * @return ovsTableStore, empty if table store is find
158 - */ 158 + */
159 - private OvsdbTableStore getTableStore(String dbName) { 159 + private OvsdbTableStore getTableStore(String dbName) {
160 - if (ovsdbStore == null) { 160 + if (ovsdbStore == null) {
161 - return null; 161 + return null;
162 - } 162 + }
163 - return ovsdbStore.getOvsdbTableStore(dbName); 163 + return ovsdbStore.getOvsdbTableStore(dbName);
164 - } 164 + }
165 - 165 +
166 - /** 166 + /**
167 - * Gets the ovsdb row store. 167 + * Gets the ovsdb row store.
168 - * 168 + *
169 - * @param dbName the ovsdb database name 169 + * @param dbName the ovsdb database name
170 - * @param tableName the ovsdb table name 170 + * @param tableName the ovsdb table name
171 - * 171 + *
172 - * @return ovsRowStore, empty if row store is find 172 + * @return ovsRowStore, empty if row store is find
173 - */ 173 + */
174 - private OvsdbRowStore getRowStore(String dbName, String tableName) { 174 + private OvsdbRowStore getRowStore(String dbName, String tableName) {
175 - OvsdbTableStore tableStore = getTableStore(dbName); 175 + OvsdbTableStore tableStore = getTableStore(dbName);
176 - if (tableStore == null) { 176 + if (tableStore == null) {
177 - return null; 177 + return null;
178 - } 178 + }
179 - return tableStore.getRows(tableName); 179 + return tableStore.getRows(tableName);
180 - } 180 + }
181 - 181 +
182 - /** 182 + /**
183 - * Gets the ovsdb row. 183 + * Gets the ovsdb row.
184 - * 184 + *
185 - * @param dbName the ovsdb database name 185 + * @param dbName the ovsdb database name
186 - * @param tableName the ovsdb table name 186 + * @param tableName the ovsdb table name
187 - * @param uuid the key of the row 187 + * @param uuid the key of the row
188 - * @return row, empty if row is find 188 + * @return row, empty if row is find
189 - */ 189 + */
190 - @Override 190 + @Override
191 - public Row getRow(String dbName, String tableName, String uuid) { 191 + public Row getRow(String dbName, String tableName, String uuid) {
192 - OvsdbTableStore tableStore = getTableStore(dbName); 192 + OvsdbTableStore tableStore = getTableStore(dbName);
193 - if (tableStore == null) { 193 + if (tableStore == null) {
194 - return null; 194 + return null;
195 - } 195 + }
196 - OvsdbRowStore rowStore = tableStore.getRows(tableName); 196 + OvsdbRowStore rowStore = tableStore.getRows(tableName);
197 - if (rowStore == null) { 197 + if (rowStore == null) {
198 - return null; 198 + return null;
199 - } 199 + }
200 - return rowStore.getRow(uuid); 200 + return rowStore.getRow(uuid);
201 - } 201 + }
202 - 202 +
203 - @Override 203 + @Override
204 - public void removeRow(String dbName, String tableName, String uuid) { 204 + public void removeRow(String dbName, String tableName, String uuid) {
205 - OvsdbTableStore tableStore = getTableStore(dbName); 205 + OvsdbTableStore tableStore = getTableStore(dbName);
206 - if (tableStore == null) { 206 + if (tableStore == null) {
207 - return; 207 + return;
208 - } 208 + }
209 - OvsdbRowStore rowStore = tableStore.getRows(tableName); 209 + OvsdbRowStore rowStore = tableStore.getRows(tableName);
210 - if (rowStore == null) { 210 + if (rowStore == null) {
211 - return; 211 + return;
212 - } 212 + }
213 - rowStore.deleteRow(uuid); 213 + rowStore.deleteRow(uuid);
214 - } 214 + }
215 - 215 +
216 - @Override 216 + @Override
217 - public void updateOvsdbStore(String dbName, String tableName, String uuid, 217 + public void updateOvsdbStore(String dbName, String tableName, String uuid,
218 - Row row) { 218 + Row row) {
219 - OvsdbTableStore tableStore = ovsdbStore.getOvsdbTableStore(dbName); 219 + OvsdbTableStore tableStore = ovsdbStore.getOvsdbTableStore(dbName);
220 - if (tableStore == null) { 220 + if (tableStore == null) {
221 - tableStore = new OvsdbTableStore(); 221 + tableStore = new OvsdbTableStore();
222 - } 222 + }
223 - OvsdbRowStore rowStore = tableStore.getRows(tableName); 223 + OvsdbRowStore rowStore = tableStore.getRows(tableName);
224 - if (rowStore == null) { 224 + if (rowStore == null) {
225 - rowStore = new OvsdbRowStore(); 225 + rowStore = new OvsdbRowStore();
226 - } 226 + }
227 - rowStore.insertRow(uuid, row); 227 + rowStore.insertRow(uuid, row);
228 - tableStore.createOrUpdateTable(tableName, rowStore); 228 + tableStore.createOrUpdateTable(tableName, rowStore);
229 - ovsdbStore.createOrUpdateOvsdbStore(dbName, tableStore); 229 + ovsdbStore.createOrUpdateOvsdbStore(dbName, tableStore);
230 - } 230 + }
231 - 231 +
232 - @Override 232 + @Override
233 - public String getPortUuid(String portName, String bridgeUuid) { 233 + public String getPortUuid(String portName, String bridgeUuid) {
234 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 234 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
235 - 235 +
236 - Row bridgeRow = getRow(OvsdbConstant.DATABASENAME, 236 + Row bridgeRow = getRow(OvsdbConstant.DATABASENAME,
237 - OvsdbConstant.BRIDGE, bridgeUuid); 237 + OvsdbConstant.BRIDGE, bridgeUuid);
238 - 238 +
239 - Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, 239 + Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow,
240 - OvsdbTable.BRIDGE); 240 + OvsdbTable.BRIDGE);
241 - if (bridge != null) { 241 + if (bridge != null) {
242 - OvsdbSet setPorts = (OvsdbSet) bridge.getPortsColumn().data(); 242 + OvsdbSet setPorts = (OvsdbSet) bridge.getPortsColumn().data();
243 - @SuppressWarnings("unchecked") 243 + @SuppressWarnings("unchecked")
244 - Set<UUID> ports = setPorts.set(); 244 + Set<UUID> ports = setPorts.set();
245 - if (ports == null || ports.size() == 0) { 245 + if (ports == null || ports.size() == 0) {
246 - log.warn("The port uuid is null"); 246 + log.warn("The port uuid is null");
247 - return null; 247 + return null;
248 - } 248 + }
249 - 249 +
250 - for (UUID uuid : ports) { 250 + for (UUID uuid : ports) {
251 - Row portRow = getRow(OvsdbConstant.DATABASENAME, 251 + Row portRow = getRow(OvsdbConstant.DATABASENAME,
252 - OvsdbConstant.PORT, uuid.value()); 252 + OvsdbConstant.PORT, uuid.value());
253 - Port port = (Port) TableGenerator.getTable(dbSchema, portRow, 253 + Port port = (Port) TableGenerator.getTable(dbSchema, portRow,
254 - OvsdbTable.PORT); 254 + OvsdbTable.PORT);
255 - if (port != null && portName.equalsIgnoreCase(port.getName())) { 255 + if (port != null && portName.equalsIgnoreCase(port.getName())) {
256 - return uuid.value(); 256 + return uuid.value();
257 - } 257 + }
258 - } 258 + }
259 - 259 +
260 - } 260 + }
261 - return null; 261 + return null;
262 - } 262 + }
263 - 263 +
264 - @Override 264 + @Override
265 - public String getInterfaceUuid(String portUuid, String portName) { 265 + public String getInterfaceUuid(String portUuid, String portName) {
266 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 266 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
267 - 267 +
268 - Row portRow = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.PORT, 268 + Row portRow = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.PORT,
269 - portUuid); 269 + portUuid);
270 - Port port = (Port) TableGenerator.getTable(dbSchema, portRow, 270 + Port port = (Port) TableGenerator.getTable(dbSchema, portRow,
271 - OvsdbTable.PORT); 271 + OvsdbTable.PORT);
272 - 272 +
273 - if (port != null) { 273 + if (port != null) {
274 - OvsdbSet setInterfaces = (OvsdbSet) port.getInterfacesColumn().data(); 274 + OvsdbSet setInterfaces = (OvsdbSet) port.getInterfacesColumn().data();
275 - @SuppressWarnings("unchecked") 275 + @SuppressWarnings("unchecked")
276 - Set<UUID> interfaces = setInterfaces.set(); 276 + Set<UUID> interfaces = setInterfaces.set();
277 - 277 +
278 - if (interfaces == null || interfaces.size() == 0) { 278 + if (interfaces == null || interfaces.size() == 0) {
279 - log.warn("The interface uuid is null"); 279 + log.warn("The interface uuid is null");
280 - return null; 280 + return null;
281 - } 281 + }
282 - 282 +
283 - for (UUID uuid : interfaces) { 283 + for (UUID uuid : interfaces) {
284 - Row intfRow = getRow(OvsdbConstant.DATABASENAME, 284 + Row intfRow = getRow(OvsdbConstant.DATABASENAME,
285 - OvsdbConstant.INTERFACE, uuid.value()); 285 + OvsdbConstant.INTERFACE, uuid.value());
286 - Interface intf = (Interface) TableGenerator 286 + Interface intf = (Interface) TableGenerator
287 - .getTable(dbSchema, intfRow, OvsdbTable.INTERFACE); 287 + .getTable(dbSchema, intfRow, OvsdbTable.INTERFACE);
288 - if (intf != null && portName.equalsIgnoreCase(intf.getName())) { 288 + if (intf != null && portName.equalsIgnoreCase(intf.getName())) {
289 - return uuid.value(); 289 + return uuid.value();
290 - } 290 + }
291 - } 291 + }
292 - 292 +
293 - } 293 + }
294 - 294 +
295 - return null; 295 + return null;
296 - } 296 + }
297 - 297 +
298 - @Override 298 + @Override
299 - public String getBridgeUuid(String bridgeName) { 299 + public String getBridgeUuid(String bridgeName) {
300 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 300 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
301 - 301 +
302 - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, 302 + OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
303 - OvsdbConstant.BRIDGE); 303 + OvsdbConstant.BRIDGE);
304 - if (rowStore == null) { 304 + if (rowStore == null) {
305 - log.debug("The bridge uuid is null"); 305 + log.debug("The bridge uuid is null");
306 - return null; 306 + return null;
307 - } 307 + }
308 - 308 +
309 - ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore(); 309 + ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore();
310 - if (bridgeTableRows == null) { 310 + if (bridgeTableRows == null) {
311 - log.debug("The bridge uuid is null"); 311 + log.debug("The bridge uuid is null");
312 - return null; 312 + return null;
313 - } 313 + }
314 - 314 +
315 - for (String uuid : bridgeTableRows.keySet()) { 315 + for (String uuid : bridgeTableRows.keySet()) {
316 - Bridge bridge = (Bridge) TableGenerator 316 + Bridge bridge = (Bridge) TableGenerator
317 - .getTable(dbSchema, bridgeTableRows.get(uuid), 317 + .getTable(dbSchema, bridgeTableRows.get(uuid),
318 - OvsdbTable.BRIDGE); 318 + OvsdbTable.BRIDGE);
319 - 319 +
320 - if (bridge.getName().equals(bridgeName)) { 320 + if (bridge.getName().equals(bridgeName)) {
321 - return uuid; 321 + return uuid;
322 - } 322 + }
323 - 323 +
324 - } 324 + }
325 - return null; 325 + return null;
326 - } 326 + }
327 - 327 +
328 - @Override 328 + @Override
329 - public String getControllerUuid(String controllerName, 329 + public String getControllerUuid(String controllerName,
330 - String controllerTarget) { 330 + String controllerTarget) {
331 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 331 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
332 - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, 332 + OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
333 - OvsdbConstant.CONTROLLER); 333 + OvsdbConstant.CONTROLLER);
334 - if (rowStore == null) { 334 + if (rowStore == null) {
335 - log.debug("The controller uuid is null"); 335 + log.debug("The controller uuid is null");
336 - return null; 336 + return null;
337 - } 337 + }
338 - 338 +
339 - ConcurrentMap<String, Row> controllerTableRows = rowStore.getRowStore(); 339 + ConcurrentMap<String, Row> controllerTableRows = rowStore.getRowStore();
340 - if (controllerTableRows != null) { 340 + if (controllerTableRows != null) {
341 - for (String uuid : controllerTableRows.keySet()) { 341 + for (String uuid : controllerTableRows.keySet()) {
342 - 342 +
343 - Controller controller = (Controller) TableGenerator 343 + Controller controller = (Controller) TableGenerator
344 - .getTable(dbSchema, controllerTableRows.get(uuid), 344 + .getTable(dbSchema, controllerTableRows.get(uuid),
345 - OvsdbTable.CONTROLLER); 345 + OvsdbTable.CONTROLLER);
346 - String target = (String) controller.getTargetColumn().data(); 346 + String target = (String) controller.getTargetColumn().data();
347 - if (target.equalsIgnoreCase(controllerTarget)) { 347 + if (target.equalsIgnoreCase(controllerTarget)) {
348 - return uuid; 348 + return uuid;
349 - } 349 + }
350 - 350 +
351 - } 351 + }
352 - } 352 + }
353 - return null; 353 + return null;
354 - } 354 + }
355 - 355 +
356 - @Override 356 + @Override
357 - public String getOvsUuid(String dbName) { 357 + public String getOvsUuid(String dbName) {
358 - OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME, 358 + OvsdbRowStore rowStore = getRowStore(OvsdbConstant.DATABASENAME,
359 - OvsdbConstant.DATABASENAME); 359 + OvsdbConstant.DATABASENAME);
360 - if (rowStore == null) { 360 + if (rowStore == null) {
361 - log.debug("The bridge uuid is null"); 361 + log.debug("The bridge uuid is null");
362 - return null; 362 + return null;
363 - } 363 + }
364 - ConcurrentMap<String, Row> ovsTableRows = rowStore.getRowStore(); 364 + ConcurrentMap<String, Row> ovsTableRows = rowStore.getRowStore();
365 - if (ovsTableRows != null) { 365 + if (ovsTableRows != null) {
366 - for (String uuid : ovsTableRows.keySet()) { 366 + for (String uuid : ovsTableRows.keySet()) {
367 - Row row = ovsTableRows.get(uuid); 367 + Row row = ovsTableRows.get(uuid);
368 - String tableName = row.tableName(); 368 + String tableName = row.tableName();
369 - if (tableName.equals(dbName)) { 369 + if (tableName.equals(dbName)) {
370 - return uuid; 370 + return uuid;
371 - } 371 + }
372 - } 372 + }
373 - } 373 + }
374 - return null; 374 + return null;
375 - } 375 + }
376 - 376 +
377 - @Override 377 + @Override
378 - public void createPort(String bridgeName, String portName) { 378 + public void createPort(String bridgeName, String portName) {
379 - String bridgeUuid = getBridgeUuid(bridgeName); 379 + String bridgeUuid = getBridgeUuid(bridgeName);
380 - if (bridgeUuid == null) { 380 + if (bridgeUuid == null) {
381 - log.error("Can't find bridge {} in {}", bridgeName, 381 + log.error("Can't find bridge {} in {}", bridgeName,
382 - nodeId.getIpAddress()); 382 + nodeId.getIpAddress());
383 - return; 383 + return;
384 - } 384 + }
385 - 385 +
386 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 386 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
387 - String portUuid = getPortUuid(portName, bridgeUuid); 387 + String portUuid = getPortUuid(portName, bridgeUuid);
388 - 388 +
389 - Port port = (Port) TableGenerator 389 + Port port = (Port) TableGenerator
390 - .createTable(dbSchema, OvsdbTable.PORT); 390 + .createTable(dbSchema, OvsdbTable.PORT);
391 - 391 +
392 - port.setName(portName); 392 + port.setName(portName);
393 - if (portUuid == null) { 393 + if (portUuid == null) {
394 - insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE, 394 + insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE,
395 - "ports", bridgeUuid, port.getRow()); 395 + "ports", bridgeUuid, port.getRow());
396 - } else { 396 + } else {
397 - updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow()); 397 + updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow());
398 - } 398 + }
399 - 399 +
400 - return; 400 + return;
401 - } 401 + }
402 - 402 +
403 - @Override 403 + @Override
404 - public void dropPort(String bridgeName, String portName) { 404 + public void dropPort(String bridgeName, String portName) {
405 - String bridgeUuid = getBridgeUuid(bridgeName); 405 + String bridgeUuid = getBridgeUuid(bridgeName);
406 - if (bridgeUuid == null) { 406 + if (bridgeUuid == null) {
407 - log.error("Could not find Bridge {} in {}", bridgeName, nodeId); 407 + log.error("Could not find Bridge {} in {}", bridgeName, nodeId);
408 - return; 408 + return;
409 - } 409 + }
410 - 410 +
411 - String portUuid = getPortUuid(portName, bridgeUuid); 411 + String portUuid = getPortUuid(portName, bridgeUuid);
412 - if (portUuid != null) { 412 + if (portUuid != null) {
413 - log.info("Port {} delete", portName); 413 + log.info("Port {} delete", portName);
414 - deleteConfig(OvsdbConstant.PORT, "_uuid", portUuid, 414 + deleteConfig(OvsdbConstant.PORT, "_uuid", portUuid,
415 - OvsdbConstant.BRIDGE, "ports"); 415 + OvsdbConstant.BRIDGE, "ports");
416 - } 416 + }
417 - } 417 + }
418 - 418 +
419 - @Override 419 + @Override
420 - public void createBridge(String bridgeName) { 420 + public void createBridge(String bridgeName) {
421 - log.debug("create bridge {}", bridgeName); 421 + log.debug("create bridge {}", bridgeName);
422 - 422 +
423 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 423 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
424 - if (dbSchema == null) { 424 + if (dbSchema == null) {
425 - log.warn("The schema is null"); 425 + log.warn("The schema is null");
426 - return; 426 + return;
427 - } 427 + }
428 - 428 +
429 - Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, 429 + Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema,
430 - OvsdbTable.BRIDGE); 430 + OvsdbTable.BRIDGE);
431 - if (bridge == null) { 431 + if (bridge == null) {
432 - log.debug("Can not create bridge"); 432 + log.debug("Can not create bridge");
433 - return; 433 + return;
434 - } 434 + }
435 - 435 +
436 - Set<String> failModes = new HashSet<>(); 436 + Set<String> failModes = new HashSet<>();
437 - failModes.add("secure"); 437 + failModes.add("secure");
438 - bridge.setFailMode(failModes); 438 + bridge.setFailMode(failModes);
439 - 439 +
440 - Set<String> protocols = new HashSet<>(); 440 + Set<String> protocols = new HashSet<>();
441 - protocols.add(OvsdbConstant.OPENFLOW13); 441 + protocols.add(OvsdbConstant.OPENFLOW13);
442 - bridge.setProtocols(protocols); 442 + bridge.setProtocols(protocols);
443 - 443 +
444 - String ovsUuid = getOvsUuid(OvsdbConstant.DATABASENAME); 444 + String ovsUuid = getOvsUuid(OvsdbConstant.DATABASENAME);
445 - if (ovsUuid == null) { 445 + if (ovsUuid == null) {
446 - log.warn("The Open_vSwitch is null"); 446 + log.warn("The Open_vSwitch is null");
447 - return; 447 + return;
448 - } 448 + }
449 - 449 +
450 - String bridgeUuid = getBridgeUuid(bridgeName); 450 + String bridgeUuid = getBridgeUuid(bridgeName);
451 - if (bridgeUuid == null) { 451 + if (bridgeUuid == null) {
452 - log.debug("Create a new bridge"); 452 + log.debug("Create a new bridge");
453 - 453 +
454 - bridge.setName(bridgeName); 454 + bridge.setName(bridgeName);
455 - bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid", 455 + bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid",
456 - OvsdbConstant.DATABASENAME, "bridges", 456 + OvsdbConstant.DATABASENAME, "bridges",
457 - ovsUuid, bridge.getRow()); 457 + ovsUuid, bridge.getRow());
458 - 458 +
459 - if (bridgeUuid != null) { 459 + if (bridgeUuid != null) {
460 - Port port = (Port) TableGenerator.createTable(dbSchema, 460 + Port port = (Port) TableGenerator.createTable(dbSchema,
461 - OvsdbTable.PORT); 461 + OvsdbTable.PORT);
462 - if (port != null) { 462 + if (port != null) {
463 - log.debug("the port is not null"); 463 + log.debug("the port is not null");
464 - port.setName(bridgeName); 464 + port.setName(bridgeName);
465 - 465 +
466 - insertConfig(OvsdbConstant.PORT, "_uuid", "Bridge", "ports", bridgeUuid, 466 + insertConfig(OvsdbConstant.PORT, "_uuid", "Bridge", "ports", bridgeUuid,
467 - port.getRow()); 467 + port.getRow());
468 - } 468 + }
469 - } 469 + }
470 - 470 +
471 - } else { 471 + } else {
472 - log.info("Update a bridge"); 472 + log.info("Update a bridge");
473 - updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow()); 473 + updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow());
474 - } 474 + }
475 - 475 +
476 - setController(bridgeUuid); 476 + setController(bridgeUuid);
477 - log.info("Create bridge success"); 477 + log.info("Create bridge success");
478 - } 478 + }
479 - 479 +
480 - /** 480 + /**
481 - * Sets the Controller. 481 + * Sets the Controller.
482 - * 482 + *
483 - * @param bridgeUuid bridge uuid 483 + * @param bridgeUuid bridge uuid
484 - */ 484 + */
485 - private void setController(String bridgeUuid) { 485 + private void setController(String bridgeUuid) {
486 - String controllerUuid = null; 486 + String controllerUuid = null;
487 - String iPAddress = IpAddress.valueOf(((InetSocketAddress) channel 487 + String iPAddress = IpAddress.valueOf(((InetSocketAddress) channel
488 - .localAddress()) 488 + .localAddress())
489 - .getAddress() 489 + .getAddress()
490 - .getHostAddress()) 490 + .getHostAddress())
491 - .toString(); 491 + .toString();
492 - 492 +
493 - String target = "tcp:" + iPAddress + ":" + OvsdbConstant.OFPORT; 493 + String target = "tcp:" + iPAddress + ":" + OvsdbConstant.OFPORT;
494 - log.debug("controller IP {}: port {}", iPAddress, OvsdbConstant.OFPORT); 494 + log.debug("controller IP {}: port {}", iPAddress, OvsdbConstant.OFPORT);
495 - 495 +
496 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 496 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
497 - Controller controller = (Controller) TableGenerator 497 + Controller controller = (Controller) TableGenerator
498 - .createTable(dbSchema, OvsdbTable.CONTROLLER); 498 + .createTable(dbSchema, OvsdbTable.CONTROLLER);
499 - 499 +
500 - if (controller != null) { 500 + if (controller != null) {
501 - controller.setTarget(target); 501 + controller.setTarget(target);
502 - controllerUuid = getControllerUuid(OvsdbConstant.CONTROLLER, target); 502 + controllerUuid = getControllerUuid(OvsdbConstant.CONTROLLER, target);
503 - if (controllerUuid == null) { 503 + if (controllerUuid == null) {
504 - 504 +
505 - insertConfig(OvsdbConstant.CONTROLLER, "_uuid", 505 + insertConfig(OvsdbConstant.CONTROLLER, "_uuid",
506 - OvsdbConstant.BRIDGE, "controller", bridgeUuid, 506 + OvsdbConstant.BRIDGE, "controller", bridgeUuid,
507 - controller.getRow()); 507 + controller.getRow());
508 - 508 +
509 - } else { 509 + } else {
510 - 510 +
511 - Bridge bridge = (Bridge) TableGenerator 511 + Bridge bridge = (Bridge) TableGenerator
512 - .createTable(dbSchema, OvsdbTable.BRIDGE); 512 + .createTable(dbSchema, OvsdbTable.BRIDGE);
513 - Set<UUID> controllerUuids = new HashSet<>(); 513 + Set<UUID> controllerUuids = new HashSet<>();
514 - controllerUuids.add(UUID.uuid(controllerUuid)); 514 + controllerUuids.add(UUID.uuid(controllerUuid));
515 - bridge.setController(controllerUuids); 515 + bridge.setController(controllerUuids);
516 - updateConfig(OvsdbConstant.CONTROLLER, "_uuid", bridgeUuid, bridge.getRow()); 516 + updateConfig(OvsdbConstant.CONTROLLER, "_uuid", bridgeUuid, bridge.getRow());
517 - 517 +
518 - } 518 + }
519 - } 519 + }
520 - 520 +
521 - } 521 + }
522 - 522 +
523 - @Override 523 + @Override
524 - public void dropBridge(String bridgeName) { 524 + public void dropBridge(String bridgeName) {
525 - String bridgeUUID = getBridgeUuid(bridgeName); 525 + String bridgeUUID = getBridgeUuid(bridgeName);
526 - if (bridgeUUID == null) { 526 + if (bridgeUUID == null) {
527 - log.warn("Could not find bridge in node", nodeId.getIpAddress()); 527 + log.warn("Could not find bridge in node", nodeId.getIpAddress());
528 - return; 528 + return;
529 - } 529 + }
530 - deleteConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUUID, 530 + deleteConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUUID,
531 - OvsdbConstant.DATABASENAME, "bridges"); 531 + OvsdbConstant.DATABASENAME, "bridges");
532 - } 532 + }
533 - 533 +
534 - @Override 534 + @Override
535 - public void createTunnel(IpAddress srcIp, IpAddress dstIp) { 535 + public void createTunnel(IpAddress srcIp, IpAddress dstIp) {
536 - String bridgeUuid = getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE); 536 + String bridgeUuid = getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE);
537 - if (bridgeUuid == null) { 537 + if (bridgeUuid == null) {
538 - log.warn("Could not find bridge {} and Could not create tunnel. ", 538 + log.warn("Could not find bridge {} and Could not create tunnel. ",
539 - OvsdbConstant.INTEGRATION_BRIDGE); 539 + OvsdbConstant.INTEGRATION_BRIDGE);
540 - return; 540 + return;
541 - } 541 + }
542 - 542 +
543 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 543 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
544 - String portName = getTunnelName(OvsdbConstant.TYPEVXLAN, dstIp); 544 + String portName = getTunnelName(OvsdbConstant.TYPEVXLAN, dstIp);
545 - String portUuid = getPortUuid(portName, bridgeUuid); 545 + String portUuid = getPortUuid(portName, bridgeUuid);
546 - 546 +
547 - Port port = (Port) TableGenerator 547 + Port port = (Port) TableGenerator
548 - .createTable(dbSchema, OvsdbTable.PORT); 548 + .createTable(dbSchema, OvsdbTable.PORT);
549 - if (port != null) { 549 + if (port != null) {
550 - port.setName(portName); 550 + port.setName(portName);
551 - } 551 + }
552 - 552 +
553 - if (portUuid == null) { 553 + if (portUuid == null) {
554 - portUuid = insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE, 554 + portUuid = insertConfig(OvsdbConstant.PORT, "_uuid", OvsdbConstant.BRIDGE,
555 - "ports", bridgeUuid, port.getRow()); 555 + "ports", bridgeUuid, port.getRow());
556 - } else { 556 + } else {
557 - updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow()); 557 + updateConfig(OvsdbConstant.PORT, "_uuid", portUuid, port.getRow());
558 - } 558 + }
559 - 559 +
560 - // When a tunnel is created, A row is inserted into port table and 560 + // When a tunnel is created, A row is inserted into port table and
561 - // interface table of the ovsdb node. 561 + // interface table of the ovsdb node.
562 - // and the following step is to get the interface uuid from local store 562 + // and the following step is to get the interface uuid from local store
563 - // in controller node. 563 + // in controller node.
564 - // but it need spend some time synchronising data between node and 564 + // but it need spend some time synchronising data between node and
565 - // controller. 565 + // controller.
566 - // so loop to judge if interfaceUUid is null is necessary. 566 + // so loop to judge if interfaceUUid is null is necessary.
567 - String interfaceUuid = null; 567 + String interfaceUuid = null;
568 - for (int i = 0; i < 10; i++) { 568 + for (int i = 0; i < 10; i++) {
569 - interfaceUuid = getInterfaceUuid(portUuid, portName); 569 + interfaceUuid = getInterfaceUuid(portUuid, portName);
570 - if (interfaceUuid == null) { 570 + if (interfaceUuid == null) {
571 - try { 571 + try {
572 - Thread.sleep(500); 572 + Thread.sleep(500);
573 - } catch (InterruptedException e) { 573 + } catch (InterruptedException e) {
574 - log.warn("Interrupted while waiting to get interfaceUuid"); 574 + log.warn("Interrupted while waiting to get interfaceUuid");
575 - Thread.currentThread().interrupt(); 575 + Thread.currentThread().interrupt();
576 - } 576 + }
577 - } else { 577 + } else {
578 - break; 578 + break;
579 - } 579 + }
580 - } 580 + }
581 - 581 +
582 - if (interfaceUuid != null) { 582 + if (interfaceUuid != null) {
583 - 583 +
584 - Interface tunInterface = (Interface) TableGenerator 584 + Interface tunInterface = (Interface) TableGenerator
585 - .createTable(dbSchema, OvsdbTable.INTERFACE); 585 + .createTable(dbSchema, OvsdbTable.INTERFACE);
586 - 586 +
587 - if (tunInterface != null) { 587 + if (tunInterface != null) {
588 - 588 +
589 - tunInterface.setType(OvsdbConstant.TYPEVXLAN); 589 + tunInterface.setType(OvsdbConstant.TYPEVXLAN);
590 - Map<String, String> options = Maps.newHashMap(); 590 + Map<String, String> options = Maps.newHashMap();
591 - options.put("key", "flow"); 591 + options.put("key", "flow");
592 - options.put("local_ip", srcIp.toString()); 592 + options.put("local_ip", srcIp.toString());
593 - options.put("remote_ip", dstIp.toString()); 593 + options.put("remote_ip", dstIp.toString());
594 - tunInterface.setOptions(options); 594 + tunInterface.setOptions(options);
595 - updateConfig(OvsdbConstant.INTERFACE, "_uuid", interfaceUuid, 595 + updateConfig(OvsdbConstant.INTERFACE, "_uuid", interfaceUuid,
596 - tunInterface.getRow()); 596 + tunInterface.getRow());
597 - log.info("Tunnel added success", tunInterface); 597 + log.info("Tunnel added success", tunInterface);
598 - 598 +
599 - } 599 + }
600 - } 600 + }
601 - 601 +
602 - return; 602 + return;
603 - } 603 + }
604 - 604 +
605 - @Override 605 + @Override
606 - public void dropTunnel(IpAddress srcIp, IpAddress dstIp) { 606 + public void dropTunnel(IpAddress srcIp, IpAddress dstIp) {
607 - String bridgeName = OvsdbConstant.INTEGRATION_BRIDGE; 607 + String bridgeName = OvsdbConstant.INTEGRATION_BRIDGE;
608 - String portName = getTunnelName(OvsdbConstant.TYPEVXLAN, dstIp); 608 + String portName = getTunnelName(OvsdbConstant.TYPEVXLAN, dstIp);
609 - String bridgeUuid = getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE); 609 + String bridgeUuid = getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE);
610 - if (bridgeUuid == null) { 610 + if (bridgeUuid == null) {
611 - log.warn("Could not find bridge {} in {}", bridgeName, 611 + log.warn("Could not find bridge {} in {}", bridgeName,
612 - nodeId.getIpAddress()); 612 + nodeId.getIpAddress());
613 - return; 613 + return;
614 - } 614 + }
615 - 615 +
616 - String portUUID = getPortUuid(portName, bridgeUuid); 616 + String portUUID = getPortUuid(portName, bridgeUuid);
617 - if (portUUID != null) { 617 + if (portUUID != null) {
618 - log.info("Delete tunnel"); 618 + log.info("Delete tunnel");
619 - deleteConfig(OvsdbConstant.PORT, "_uuid", portUUID, 619 + deleteConfig(OvsdbConstant.PORT, "_uuid", portUUID,
620 - OvsdbConstant.BRIDGE, "ports"); 620 + OvsdbConstant.BRIDGE, "ports");
621 - } 621 + }
622 - 622 +
623 - return; 623 + return;
624 - } 624 + }
625 - 625 +
626 - /** 626 + /**
627 - * Delete transact config. 627 + * Delete transact config.
628 - * 628 + *
629 - * @param childTableName child table name 629 + * @param childTableName child table name
630 - * @param childColumnName child column name 630 + * @param childColumnName child column name
631 - * @param childUuid child row uuid 631 + * @param childUuid child row uuid
632 - * @param parentTableName parent table name 632 + * @param parentTableName parent table name
633 - * @param parentColumnName parent column 633 + * @param parentColumnName parent column
634 - * 634 + *
635 - */ 635 + */
636 - private void deleteConfig(String childTableName, String childColumnName, 636 + private void deleteConfig(String childTableName, String childColumnName,
637 - String childUuid, String parentTableName, 637 + String childUuid, String parentTableName,
638 - String parentColumnName) { 638 + String parentColumnName) {
639 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 639 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
640 - TableSchema childTableSchema = dbSchema.getTableSchema(childTableName); 640 + TableSchema childTableSchema = dbSchema.getTableSchema(childTableName);
641 - 641 +
642 - ArrayList<Operation> operations = Lists.newArrayList(); 642 + ArrayList<Operation> operations = Lists.newArrayList();
643 - if (parentTableName != null && parentColumnName != null) { 643 + if (parentTableName != null && parentColumnName != null) {
644 - TableSchema parentTableSchema = dbSchema 644 + TableSchema parentTableSchema = dbSchema
645 - .getTableSchema(parentTableName); 645 + .getTableSchema(parentTableName);
646 - ColumnSchema parentColumnSchema = parentTableSchema 646 + ColumnSchema parentColumnSchema = parentTableSchema
647 - .getColumnSchema(parentColumnName); 647 + .getColumnSchema(parentColumnName);
648 - List<Mutation> mutations = Lists.newArrayList(); 648 + List<Mutation> mutations = Lists.newArrayList();
649 - Mutation mutation = MutationUtil.delete(parentColumnSchema.name(), 649 + Mutation mutation = MutationUtil.delete(parentColumnSchema.name(),
650 - UUID.uuid(childUuid)); 650 + UUID.uuid(childUuid));
651 - mutations.add(mutation); 651 + mutations.add(mutation);
652 - List<Condition> conditions = Lists.newArrayList(); 652 + List<Condition> conditions = Lists.newArrayList();
653 - Condition condition = ConditionUtil.includes(parentColumnName, 653 + Condition condition = ConditionUtil.includes(parentColumnName,
654 - UUID.uuid(childUuid)); 654 + UUID.uuid(childUuid));
655 - conditions.add(condition); 655 + conditions.add(condition);
656 - Mutate op = new Mutate(parentTableSchema, conditions, mutations); 656 + Mutate op = new Mutate(parentTableSchema, conditions, mutations);
657 - operations.add(op); 657 + operations.add(op);
658 - } 658 + }
659 - 659 +
660 - List<Condition> conditions = Lists.newArrayList(); 660 + List<Condition> conditions = Lists.newArrayList();
661 - Condition condition = ConditionUtil.equals(childColumnName, UUID.uuid(childUuid)); 661 + Condition condition = ConditionUtil.equals(childColumnName, UUID.uuid(childUuid));
662 - conditions.add(condition); 662 + conditions.add(condition);
663 - Delete del = new Delete(childTableSchema, conditions); 663 + Delete del = new Delete(childTableSchema, conditions);
664 - operations.add(del); 664 + operations.add(del);
665 - transactConfig(OvsdbConstant.DATABASENAME, operations); 665 + transactConfig(OvsdbConstant.DATABASENAME, operations);
666 - 666 +
667 - return; 667 + return;
668 - } 668 + }
669 - 669 +
670 - /** 670 + /**
671 - * Update transact config. 671 + * Update transact config.
672 - * 672 + *
673 - * @param tableName table name 673 + * @param tableName table name
674 - * @param columnName column name 674 + * @param columnName column name
675 - * @param uuid uuid 675 + * @param uuid uuid
676 - * @param row the config data 676 + * @param row the config data
677 - * 677 + *
678 - */ 678 + */
679 - private void updateConfig(String tableName, String columnName, String uuid, 679 + private void updateConfig(String tableName, String columnName, String uuid,
680 - Row row) { 680 + Row row) {
681 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 681 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
682 - TableSchema tableSchema = dbSchema.getTableSchema(tableName); 682 + TableSchema tableSchema = dbSchema.getTableSchema(tableName);
683 - 683 +
684 - List<Condition> conditions = Lists.newArrayList(); 684 + List<Condition> conditions = Lists.newArrayList();
685 - Condition condition = ConditionUtil.equals(columnName, UUID.uuid(uuid)); 685 + Condition condition = ConditionUtil.equals(columnName, UUID.uuid(uuid));
686 - conditions.add(condition); 686 + conditions.add(condition);
687 - 687 +
688 - Update update = new Update(tableSchema, row, conditions); 688 + Update update = new Update(tableSchema, row, conditions);
689 - 689 +
690 - ArrayList<Operation> operations = Lists.newArrayList(); 690 + ArrayList<Operation> operations = Lists.newArrayList();
691 - operations.add(update); 691 + operations.add(update);
692 - 692 +
693 - transactConfig(OvsdbConstant.DATABASENAME, operations); 693 + transactConfig(OvsdbConstant.DATABASENAME, operations);
694 - } 694 + }
695 - 695 +
696 - /** 696 + /**
697 - * Insert transact config. 697 + * Insert transact config.
698 - * 698 + *
699 - * @param childTableName child table name 699 + * @param childTableName child table name
700 - * @param childColumnName child column name 700 + * @param childColumnName child column name
701 - * @param parentTableName parent table name 701 + * @param parentTableName parent table name
702 - * @param parentColumnName parent column 702 + * @param parentColumnName parent column
703 - * @param parentUuid parent uuid 703 + * @param parentUuid parent uuid
704 - * @param row the config data 704 + * @param row the config data
705 - * 705 + *
706 - * @return uuid, empty if no uuid is find 706 + * @return uuid, empty if no uuid is find
707 - */ 707 + */
708 - private String insertConfig(String childTableName, String childColumnName, 708 + private String insertConfig(String childTableName, String childColumnName,
709 - String parentTableName, String parentColumnName, 709 + String parentTableName, String parentColumnName,
710 - String parentUuid, Row row) { 710 + String parentUuid, Row row) {
711 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 711 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
712 - TableSchema tableSchema = dbSchema.getTableSchema(childTableName); 712 + TableSchema tableSchema = dbSchema.getTableSchema(childTableName);
713 - 713 +
714 - String namedUuid = childTableName; 714 + String namedUuid = childTableName;
715 - Insert insert = new Insert(tableSchema, namedUuid, row); 715 + Insert insert = new Insert(tableSchema, namedUuid, row);
716 - 716 +
717 - ArrayList<Operation> operations = Lists.newArrayList(); 717 + ArrayList<Operation> operations = Lists.newArrayList();
718 - operations.add(insert); 718 + operations.add(insert);
719 - 719 +
720 - if (parentTableName != null && parentColumnName != null) { 720 + if (parentTableName != null && parentColumnName != null) {
721 - TableSchema parentTableSchema = dbSchema 721 + TableSchema parentTableSchema = dbSchema
722 - .getTableSchema(parentTableName); 722 + .getTableSchema(parentTableName);
723 - ColumnSchema parentColumnSchema = parentTableSchema 723 + ColumnSchema parentColumnSchema = parentTableSchema
724 - .getColumnSchema(parentColumnName); 724 + .getColumnSchema(parentColumnName);
725 - 725 +
726 - List<Mutation> mutations = Lists.newArrayList(); 726 + List<Mutation> mutations = Lists.newArrayList();
727 - Mutation mutation = MutationUtil.insert(parentColumnSchema.name(), 727 + Mutation mutation = MutationUtil.insert(parentColumnSchema.name(),
728 - UUID.uuid(namedUuid)); 728 + UUID.uuid(namedUuid));
729 - mutations.add(mutation); 729 + mutations.add(mutation);
730 - 730 +
731 - List<Condition> conditions = Lists.newArrayList(); 731 + List<Condition> conditions = Lists.newArrayList();
732 - Condition condition = ConditionUtil.equals("_uuid", 732 + Condition condition = ConditionUtil.equals("_uuid",
733 - UUID.uuid(parentUuid)); 733 + UUID.uuid(parentUuid));
734 - conditions.add(condition); 734 + conditions.add(condition);
735 - 735 +
736 - Mutate op = new Mutate(parentTableSchema, conditions, mutations); 736 + Mutate op = new Mutate(parentTableSchema, conditions, mutations);
737 - operations.add(op); 737 + operations.add(op);
738 - } 738 + }
739 - if (childTableName.equalsIgnoreCase(OvsdbConstant.PORT)) { 739 + if (childTableName.equalsIgnoreCase(OvsdbConstant.PORT)) {
740 - log.info("Handle port insert"); 740 + log.info("Handle port insert");
741 - Insert intfInsert = handlePortInsertTable(OvsdbConstant.INTERFACE, 741 + Insert intfInsert = handlePortInsertTable(OvsdbConstant.INTERFACE,
742 - row); 742 + row);
743 - 743 +
744 - if (intfInsert != null) { 744 + if (intfInsert != null) {
745 - operations.add(intfInsert); 745 + operations.add(intfInsert);
746 - } 746 + }
747 - 747 +
748 - Insert ins = (Insert) operations.get(0); 748 + Insert ins = (Insert) operations.get(0);
749 - ins.getRow().put("interfaces", 749 + ins.getRow().put("interfaces",
750 - UUID.uuid(OvsdbConstant.INTERFACE)); 750 + UUID.uuid(OvsdbConstant.INTERFACE));
751 - } 751 + }
752 - 752 +
753 - List<OperationResult> results; 753 + List<OperationResult> results;
754 - try { 754 + try {
755 - results = transactConfig(OvsdbConstant.DATABASENAME, operations) 755 + results = transactConfig(OvsdbConstant.DATABASENAME, operations)
756 - .get(); 756 + .get();
757 - 757 +
758 - return results.get(0).getUuid().value(); 758 + return results.get(0).getUuid().value();
759 - } catch (InterruptedException e) { 759 + } catch (InterruptedException e) {
760 - log.warn("Interrupted while waiting to get result"); 760 + log.warn("Interrupted while waiting to get result");
761 - Thread.currentThread().interrupt(); 761 + Thread.currentThread().interrupt();
762 - } catch (ExecutionException e) { 762 + } catch (ExecutionException e) {
763 - log.error("Exception thrown while to get result"); 763 + log.error("Exception thrown while to get result");
764 - } 764 + }
765 - 765 +
766 - return null; 766 + return null;
767 - } 767 + }
768 - 768 +
769 - /** 769 + /**
770 - * Handles port insert. 770 + * Handles port insert.
771 - * 771 + *
772 - * @param tableName ovsdb table interface 772 + * @param tableName ovsdb table interface
773 - * @param portRow row of port 773 + * @param portRow row of port
774 - * 774 + *
775 - * @return insert, empty if null 775 + * @return insert, empty if null
776 - */ 776 + */
777 - private Insert handlePortInsertTable(String tableName, Row portRow) { 777 + private Insert handlePortInsertTable(String tableName, Row portRow) {
778 - DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); 778 + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME);
779 - 779 +
780 - TableSchema portTableSchema = dbSchema 780 + TableSchema portTableSchema = dbSchema
781 - .getTableSchema(OvsdbConstant.PORT); 781 + .getTableSchema(OvsdbConstant.PORT);
782 - ColumnSchema portColumnSchema = portTableSchema.getColumnSchema("name"); 782 + ColumnSchema portColumnSchema = portTableSchema.getColumnSchema("name");
783 - 783 +
784 - String portName = (String) portRow.getColumn(portColumnSchema.name()).data(); 784 + String portName = (String) portRow.getColumn(portColumnSchema.name()).data();
785 - 785 +
786 - Interface inf = (Interface) TableGenerator 786 + Interface inf = (Interface) TableGenerator
787 - .createTable(dbSchema, OvsdbTable.INTERFACE); 787 + .createTable(dbSchema, OvsdbTable.INTERFACE);
788 - 788 +
789 - inf.setName(portName); 789 + inf.setName(portName);
790 - 790 +
791 - TableSchema intfTableSchema = dbSchema 791 + TableSchema intfTableSchema = dbSchema
792 - .getTableSchema(OvsdbConstant.INTERFACE); 792 + .getTableSchema(OvsdbConstant.INTERFACE);
793 - Insert insert = new Insert(intfTableSchema, OvsdbConstant.INTERFACE, 793 + Insert insert = new Insert(intfTableSchema, OvsdbConstant.INTERFACE,
794 - inf.getRow()); 794 + inf.getRow());
795 - return insert; 795 + return insert;
796 - } 796 + }
797 - 797 +
798 - /** 798 + /**
799 - * Gets tunnel name. 799 + * Gets tunnel name.
800 - * 800 + *
801 - * @param tunnelType 801 + * @param tunnelType
802 - * @param dstIp the remote ip address 802 + * @param dstIp the remote ip address
803 - * 803 + *
804 - * @return tunnel name 804 + * @return tunnel name
805 - */ 805 + */
806 - private String getTunnelName(String tunnelType, IpAddress dstIp) { 806 + private String getTunnelName(String tunnelType, IpAddress dstIp) {
807 - return tunnelType + "-" + dstIp.toString(); 807 + return tunnelType + "-" + dstIp.toString();
808 - } 808 + }
809 - 809 +
810 - @Override 810 + @Override
811 - public ListenableFuture<DatabaseSchema> getOvsdbSchema(String dbName) { 811 + public ListenableFuture<DatabaseSchema> getOvsdbSchema(String dbName) {
812 - if (dbName == null) { 812 + if (dbName == null) {
813 - return null; 813 + return null;
814 - } 814 + }
815 - DatabaseSchema databaseSchema = schema.get(dbName); 815 + DatabaseSchema databaseSchema = schema.get(dbName);
816 - if (databaseSchema == null) { 816 + if (databaseSchema == null) {
817 - List<String> dbNames = new ArrayList<String>(); 817 + List<String> dbNames = new ArrayList<String>();
818 - dbNames.add(dbName); 818 + dbNames.add(dbName);
819 - Function<JsonNode, DatabaseSchema> rowFunction = new Function<JsonNode, DatabaseSchema>() { 819 + Function<JsonNode, DatabaseSchema> rowFunction = new Function<JsonNode, DatabaseSchema>() {
820 - @Override 820 + @Override
821 - public DatabaseSchema apply(JsonNode input) { 821 + public DatabaseSchema apply(JsonNode input) {
822 - log.info("Get ovsdb database schema", dbName); 822 + log.info("Get ovsdb database schema", dbName);
823 - DatabaseSchema dbSchema = FromJsonUtil 823 + DatabaseSchema dbSchema = FromJsonUtil
824 - .jsonNodeToDbSchema(dbName, input); 824 + .jsonNodeToDbSchema(dbName, input);
825 - if (dbSchema == null) { 825 + if (dbSchema == null) {
826 - log.debug("Get ovsdb database schema error"); 826 + log.debug("Get ovsdb database schema error");
827 - return null; 827 + return null;
828 - } 828 + }
829 - schema.put(dbName, dbSchema); 829 + schema.put(dbName, dbSchema);
830 - 830 +
831 - return dbSchema; 831 + return dbSchema;
832 - } 832 + }
833 - }; 833 + };
834 - 834 +
835 - ListenableFuture<JsonNode> input = getSchema(dbNames); 835 + ListenableFuture<JsonNode> input = getSchema(dbNames);
836 - if (input != null) { 836 + if (input != null) {
837 - return Futures.transform(input, rowFunction); 837 + return Futures.transform(input, rowFunction);
838 - } 838 + }
839 - return null; 839 + return null;
840 - } else { 840 + } else {
841 - return Futures.immediateFuture(databaseSchema); 841 + return Futures.immediateFuture(databaseSchema);
842 - } 842 + }
843 - } 843 + }
844 - 844 +
845 - @Override 845 + @Override
846 - public ListenableFuture<TableUpdates> monitorTables(String dbName, String id) { 846 + public ListenableFuture<TableUpdates> monitorTables(String dbName, String id) {
847 - if (dbName == null) { 847 + if (dbName == null) {
848 - return null; 848 + return null;
849 - } 849 + }
850 - DatabaseSchema dbSchema = schema.get(dbName); 850 + DatabaseSchema dbSchema = schema.get(dbName);
851 - if (dbSchema != null) { 851 + if (dbSchema != null) {
852 - Function<JsonNode, TableUpdates> rowFunction = new Function<JsonNode, TableUpdates>() { 852 + Function<JsonNode, TableUpdates> rowFunction = new Function<JsonNode, TableUpdates>() {
853 - @Override 853 + @Override
854 - public TableUpdates apply(JsonNode input) { 854 + public TableUpdates apply(JsonNode input) {
855 - log.info("Get table updates"); 855 + log.info("Get table updates");
856 - TableUpdates updates = FromJsonUtil 856 + TableUpdates updates = FromJsonUtil
857 - .jsonNodeToTableUpdates(input, dbSchema); 857 + .jsonNodeToTableUpdates(input, dbSchema);
858 - if (updates == null) { 858 + if (updates == null) {
859 - log.debug("Get table updates error"); 859 + log.debug("Get table updates error");
860 - return null; 860 + return null;
861 - } 861 + }
862 - return updates; 862 + return updates;
863 - } 863 + }
864 - }; 864 + };
865 - return Futures.transform(monitor(dbSchema, id), rowFunction); 865 + return Futures.transform(monitor(dbSchema, id), rowFunction);
866 - } 866 + }
867 - return null; 867 + return null;
868 - } 868 + }
869 - 869 +
870 - @Override 870 + @Override
871 - public ListenableFuture<List<OperationResult>> transactConfig(String dbName, 871 + public ListenableFuture<List<OperationResult>> transactConfig(String dbName,
872 - List<Operation> operations) { 872 + List<Operation> operations) {
873 - if (dbName == null) { 873 + if (dbName == null) {
874 - return null; 874 + return null;
875 - } 875 + }
876 - DatabaseSchema dbSchema = schema.get(dbName); 876 + DatabaseSchema dbSchema = schema.get(dbName);
877 - if (dbSchema != null) { 877 + if (dbSchema != null) {
878 - Function<List<JsonNode>, List<OperationResult>> rowFunction = 878 + Function<List<JsonNode>, List<OperationResult>> rowFunction =
879 - new Function<List<JsonNode>, List<OperationResult>>() { 879 + new Function<List<JsonNode>, List<OperationResult>>() {
880 - @Override 880 + @Override
881 - public List<OperationResult> apply(List<JsonNode> input) { 881 + public List<OperationResult> apply(List<JsonNode> input) {
882 - log.info("Get ovsdb operation result"); 882 + log.info("Get ovsdb operation result");
883 - List<OperationResult> result = FromJsonUtil 883 + List<OperationResult> result = FromJsonUtil
884 - .jsonNodeToOperationResult(input, operations); 884 + .jsonNodeToOperationResult(input, operations);
885 - 885 +
886 - if (result == null) { 886 + if (result == null) {
887 - log.debug("The operation result is null"); 887 + log.debug("The operation result is null");
888 - return null; 888 + return null;
889 - } 889 + }
890 - return result; 890 + return result;
891 - } 891 + }
892 - }; 892 + };
893 - return Futures.transform(transact(dbSchema, operations), 893 + return Futures.transform(transact(dbSchema, operations),
894 - rowFunction); 894 + rowFunction);
895 - } 895 + }
896 - return null; 896 + return null;
897 - } 897 + }
898 - 898 +
899 - @Override 899 + @Override
900 - public ListenableFuture<JsonNode> getSchema(List<String> dbnames) { 900 + public ListenableFuture<JsonNode> getSchema(List<String> dbnames) {
901 - String id = java.util.UUID.randomUUID().toString(); 901 + String id = java.util.UUID.randomUUID().toString();
902 - String getSchemaString = JsonRpcWriterUtil.getSchemaStr(id, dbnames); 902 + String getSchemaString = JsonRpcWriterUtil.getSchemaStr(id, dbnames);
903 - 903 +
904 - SettableFuture<JsonNode> sf = SettableFuture.create(); 904 + SettableFuture<JsonNode> sf = SettableFuture.create();
905 - requestResult.put(id, sf); 905 + requestResult.put(id, sf);
906 - requestMethod.put(id, "getSchema"); 906 + requestMethod.put(id, "getSchema");
907 - 907 +
908 - channel.writeAndFlush(getSchemaString); 908 + channel.writeAndFlush(getSchemaString);
909 - return sf; 909 + return sf;
910 - 910 +
911 - } 911 + }
912 - 912 +
913 - @Override 913 + @Override
914 - public ListenableFuture<List<String>> echo() { 914 + public ListenableFuture<List<String>> echo() {
915 - String id = java.util.UUID.randomUUID().toString(); 915 + String id = java.util.UUID.randomUUID().toString();
916 - String echoString = JsonRpcWriterUtil.echoStr(id); 916 + String echoString = JsonRpcWriterUtil.echoStr(id);
917 - 917 +
918 - SettableFuture<List<String>> sf = SettableFuture.create(); 918 + SettableFuture<List<String>> sf = SettableFuture.create();
919 - requestResult.put(id, sf); 919 + requestResult.put(id, sf);
920 - requestMethod.put(id, "echo"); 920 + requestMethod.put(id, "echo");
921 - 921 +
922 - channel.writeAndFlush(echoString); 922 + channel.writeAndFlush(echoString);
923 - return sf; 923 + return sf;
924 - 924 +
925 - } 925 + }
926 - 926 +
927 - @Override 927 + @Override
928 - public ListenableFuture<JsonNode> monitor(DatabaseSchema dbSchema, 928 + public ListenableFuture<JsonNode> monitor(DatabaseSchema dbSchema,
929 - String monitorId) { 929 + String monitorId) {
930 - String id = java.util.UUID.randomUUID().toString(); 930 + String id = java.util.UUID.randomUUID().toString();
931 - String monitorString = JsonRpcWriterUtil.monitorStr(id, monitorId, 931 + String monitorString = JsonRpcWriterUtil.monitorStr(id, monitorId,
932 - dbSchema); 932 + dbSchema);
933 - 933 +
934 - SettableFuture<JsonNode> sf = SettableFuture.create(); 934 + SettableFuture<JsonNode> sf = SettableFuture.create();
935 - requestResult.put(id, sf); 935 + requestResult.put(id, sf);
936 - requestMethod.put(id, "monitor"); 936 + requestMethod.put(id, "monitor");
937 - 937 +
938 - channel.writeAndFlush(monitorString); 938 + channel.writeAndFlush(monitorString);
939 - return sf; 939 + return sf;
940 - 940 +
941 - } 941 + }
942 - 942 +
943 - @Override 943 + @Override
944 - public ListenableFuture<List<String>> listDbs() { 944 + public ListenableFuture<List<String>> listDbs() {
945 - String id = java.util.UUID.randomUUID().toString(); 945 + String id = java.util.UUID.randomUUID().toString();
946 - String listDbsString = JsonRpcWriterUtil.listDbsStr(id); 946 + String listDbsString = JsonRpcWriterUtil.listDbsStr(id);
947 - 947 +
948 - SettableFuture<List<String>> sf = SettableFuture.create(); 948 + SettableFuture<List<String>> sf = SettableFuture.create();
949 - requestResult.put(id, sf); 949 + requestResult.put(id, sf);
950 - requestMethod.put(id, "listDbs"); 950 + requestMethod.put(id, "listDbs");
951 - 951 +
952 - channel.writeAndFlush(listDbsString); 952 + channel.writeAndFlush(listDbsString);
953 - return sf; 953 + return sf;
954 - 954 +
955 - } 955 + }
956 - 956 +
957 - @Override 957 + @Override
958 - public ListenableFuture<List<JsonNode>> transact(DatabaseSchema dbSchema, 958 + public ListenableFuture<List<JsonNode>> transact(DatabaseSchema dbSchema,
959 - List<Operation> operations) { 959 + List<Operation> operations) {
960 - String id = java.util.UUID.randomUUID().toString(); 960 + String id = java.util.UUID.randomUUID().toString();
961 - String transactString = JsonRpcWriterUtil.transactStr(id, dbSchema, 961 + String transactString = JsonRpcWriterUtil.transactStr(id, dbSchema,
962 - operations); 962 + operations);
963 - 963 +
964 - SettableFuture<List<JsonNode>> sf = SettableFuture.create(); 964 + SettableFuture<List<JsonNode>> sf = SettableFuture.create();
965 - requestResult.put(id, sf); 965 + requestResult.put(id, sf);
966 - requestMethod.put(id, "transact"); 966 + requestMethod.put(id, "transact");
967 - 967 +
968 - channel.writeAndFlush(transactString); 968 + channel.writeAndFlush(transactString);
969 - return sf; 969 + return sf;
970 - 970 +
971 - } 971 + }
972 - 972 +
973 - @SuppressWarnings({ "rawtypes", "unchecked" }) 973 + @SuppressWarnings({ "rawtypes", "unchecked" })
974 - @Override 974 + @Override
975 - public void processResult(JsonNode response) { 975 + public void processResult(JsonNode response) {
976 - log.debug("Handle result"); 976 + log.debug("Handle result");
977 - String requestId = response.get("id").asText(); 977 + String requestId = response.get("id").asText();
978 - SettableFuture sf = requestResult.get(requestId); 978 + SettableFuture sf = requestResult.get(requestId);
979 - if (sf == null) { 979 + if (sf == null) {
980 - log.debug("No such future to process"); 980 + log.debug("No such future to process");
981 - return; 981 + return;
982 - } 982 + }
983 - String methodName = requestMethod.get(requestId); 983 + String methodName = requestMethod.get(requestId);
984 - 984 +
985 - Object result; 985 + Object result;
986 - result = FromJsonUtil.jsonResultParser(response, methodName); 986 + result = FromJsonUtil.jsonResultParser(response, methodName);
987 - 987 +
988 - sf.set(result); 988 + sf.set(result);
989 - return; 989 + return;
990 - } 990 + }
991 - 991 +
992 - @Override 992 + @Override
993 - public void processRequest(JsonNode requestJson) { 993 + public void processRequest(JsonNode requestJson) {
994 - log.debug("Handle request"); 994 + log.debug("Handle request");
995 - if (requestJson.get("method").asText().equalsIgnoreCase("echo")) { 995 + if (requestJson.get("method").asText().equalsIgnoreCase("echo")) {
996 - log.debug("handle echo request"); 996 + log.debug("handle echo request");
997 - 997 +
998 - String replyString = FromJsonUtil.getEchoRequestStr(requestJson); 998 + String replyString = FromJsonUtil.getEchoRequestStr(requestJson);
999 - channel.writeAndFlush(replyString); 999 + channel.writeAndFlush(replyString);
1000 - 1000 +
1001 - return; 1001 + return;
1002 - } else { 1002 + } else {
1003 - FromJsonUtil 1003 + FromJsonUtil
1004 - .jsonCallbackRequestParser(requestJson, monitorCallBack); 1004 + .jsonCallbackRequestParser(requestJson, monitorCallBack);
1005 - return; 1005 + return;
1006 - } 1006 + }
1007 - } 1007 + }
1008 - 1008 +
1009 - @Override 1009 + @Override
1010 - public void setCallback(Callback monitorCallback) { 1010 + public void setCallback(Callback monitorCallback) {
1011 - this.monitorCallBack = monitorCallback; 1011 + this.monitorCallBack = monitorCallback;
1012 - } 1012 + }
1013 - 1013 +
1014 - @Override 1014 + @Override
1015 - public Set<OvsdbTunnel> getTunnels() { 1015 + public Set<OvsdbTunnel> getTunnels() {
1016 - return ovsdbTunnels; 1016 + return ovsdbTunnels;
1017 - } 1017 + }
1018 - 1018 +
1019 - @Override 1019 + @Override
1020 - public Set<OvsdbBridge> getBridges() { 1020 + public Set<OvsdbBridge> getBridges() {
1021 - Set<OvsdbBridge> ovsdbBridges = new HashSet<OvsdbBridge>(); 1021 + Set<OvsdbBridge> ovsdbBridges = new HashSet<OvsdbBridge>();
1022 - OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME); 1022 + OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME);
1023 - if (tableStore == null) { 1023 + if (tableStore == null) {
1024 - return null; 1024 + return null;
1025 - } 1025 + }
1026 - OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.BRIDGE); 1026 + OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.BRIDGE);
1027 - if (rowStore == null) { 1027 + if (rowStore == null) {
1028 - return null; 1028 + return null;
1029 - } 1029 + }
1030 - ConcurrentMap<String, Row> rows = rowStore.getRowStore(); 1030 + ConcurrentMap<String, Row> rows = rowStore.getRowStore();
1031 - for (String uuid : rows.keySet()) { 1031 + for (String uuid : rows.keySet()) {
1032 - Row row = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.BRIDGE, 1032 + Row row = getRow(OvsdbConstant.DATABASENAME, OvsdbConstant.BRIDGE,
1033 - uuid); 1033 + uuid);
1034 - OvsdbBridge ovsdbBridge = getOvsdbBridge(row); 1034 + OvsdbBridge ovsdbBridge = getOvsdbBridge(row);
1035 - if (ovsdbBridge != null) { 1035 + if (ovsdbBridge != null) {
1036 - ovsdbBridges.add(ovsdbBridge); 1036 + ovsdbBridges.add(ovsdbBridge);
1037 - } 1037 + }
1038 - } 1038 + }
1039 - return ovsdbBridges; 1039 + return ovsdbBridges;
1040 - } 1040 + }
1041 - 1041 +
1042 - @Override 1042 + @Override
1043 - public Set<OvsdbPort> getPorts() { 1043 + public Set<OvsdbPort> getPorts() {
1044 - Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>(); 1044 + Set<OvsdbPort> ovsdbPorts = new HashSet<OvsdbPort>();
1045 - OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME); 1045 + OvsdbTableStore tableStore = getTableStore(OvsdbConstant.DATABASENAME);
1046 - if (tableStore == null) { 1046 + if (tableStore == null) {
1047 - return null; 1047 + return null;
1048 - } 1048 + }
1049 - OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.INTERFACE); 1049 + OvsdbRowStore rowStore = tableStore.getRows(OvsdbConstant.INTERFACE);
1050 - if (rowStore == null) { 1050 + if (rowStore == null) {
1051 - return null; 1051 + return null;
1052 - } 1052 + }
1053 - ConcurrentMap<String, Row> rows = rowStore.getRowStore(); 1053 + ConcurrentMap<String, Row> rows = rowStore.getRowStore();
1054 - for (String uuid : rows.keySet()) { 1054 + for (String uuid : rows.keySet()) {
1055 - Row row = getRow(OvsdbConstant.DATABASENAME, 1055 + Row row = getRow(OvsdbConstant.DATABASENAME,
1056 - OvsdbConstant.INTERFACE, uuid); 1056 + OvsdbConstant.INTERFACE, uuid);
1057 - OvsdbPort ovsdbPort = getOvsdbPort(row); 1057 + OvsdbPort ovsdbPort = getOvsdbPort(row);
1058 - if (ovsdbPort != null) { 1058 + if (ovsdbPort != null) {
1059 - ovsdbPorts.add(ovsdbPort); 1059 + ovsdbPorts.add(ovsdbPort);
1060 - } 1060 + }
1061 - } 1061 + }
1062 - return ovsdbPorts; 1062 + return ovsdbPorts;
1063 - } 1063 + }
1064 - 1064 +
1065 - @Override 1065 + @Override
1066 - public DatabaseSchema getDatabaseSchema(String dbName) { 1066 + public DatabaseSchema getDatabaseSchema(String dbName) {
1067 - return schema.get(dbName); 1067 + return schema.get(dbName);
1068 - } 1068 + }
1069 - 1069 +
1070 - //Gets ovsdb port. 1070 + //Gets ovsdb port.
1071 - private OvsdbPort getOvsdbPort(Row row) { 1071 + private OvsdbPort getOvsdbPort(Row row) {
1072 - DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME); 1072 + DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME);
1073 - Interface intf = (Interface) TableGenerator 1073 + Interface intf = (Interface) TableGenerator
1074 - .getTable(dbSchema, row, OvsdbTable.INTERFACE); 1074 + .getTable(dbSchema, row, OvsdbTable.INTERFACE);
1075 - if (intf == null) { 1075 + if (intf == null) {
1076 - return null; 1076 + return null;
1077 - } 1077 + }
1078 - long ofPort = getOfPort(intf); 1078 + long ofPort = getOfPort(intf);
1079 - String portName = intf.getName(); 1079 + String portName = intf.getName();
1080 - if ((ofPort < 0) || (portName == null)) { 1080 + if ((ofPort < 0) || (portName == null)) {
1081 - return null; 1081 + return null;
1082 - } 1082 + }
1083 - 1083 +
1084 - OvsdbPort ovsdbPort = new OvsdbPort(new OvsdbPortNumber(ofPort), 1084 + OvsdbPort ovsdbPort = new OvsdbPort(new OvsdbPortNumber(ofPort),
1085 - new OvsdbPortName(portName)); 1085 + new OvsdbPortName(portName));
1086 - return ovsdbPort; 1086 + return ovsdbPort;
1087 - } 1087 + }
1088 - 1088 +
1089 - ////Gets ovsdb bridge. 1089 + ////Gets ovsdb bridge.
1090 - private OvsdbBridge getOvsdbBridge(Row row) { 1090 + private OvsdbBridge getOvsdbBridge(Row row) {
1091 - DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME); 1091 + DatabaseSchema dbSchema = getDatabaseSchema(OvsdbConstant.DATABASENAME);
1092 - Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row, 1092 + Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row,
1093 - OvsdbTable.BRIDGE); 1093 + OvsdbTable.BRIDGE);
1094 - if (bridge == null) { 1094 + if (bridge == null) {
1095 - return null; 1095 + return null;
1096 - } 1096 + }
1097 - 1097 +
1098 - OvsdbSet datapathIdSet = (OvsdbSet) bridge.getDatapathIdColumn().data(); 1098 + OvsdbSet datapathIdSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
1099 - @SuppressWarnings("unchecked") 1099 + @SuppressWarnings("unchecked")
1100 - Set<String> datapathIds = datapathIdSet.set(); 1100 + Set<String> datapathIds = datapathIdSet.set();
1101 - if (datapathIds == null || datapathIds.size() == 0) { 1101 + if (datapathIds == null || datapathIds.size() == 0) {
1102 - return null; 1102 + return null;
1103 - } 1103 + }
1104 - String datapathId = (String) datapathIds.toArray()[0]; 1104 + String datapathId = (String) datapathIds.toArray()[0];
1105 - String bridgeName = bridge.getName(); 1105 + String bridgeName = bridge.getName();
1106 - if ((datapathId == null) || (bridgeName == null)) { 1106 + if ((datapathId == null) || (bridgeName == null)) {
1107 - return null; 1107 + return null;
1108 - } 1108 + }
1109 - 1109 +
1110 - OvsdbBridge ovsdbBridge = new OvsdbBridge(new OvsdbBridgeName(bridgeName), 1110 + OvsdbBridge ovsdbBridge = new OvsdbBridge(new OvsdbBridgeName(bridgeName),
1111 - new OvsdbDatapathId(datapathId)); 1111 + new OvsdbDatapathId(datapathId));
1112 - return ovsdbBridge; 1112 + return ovsdbBridge;
1113 - } 1113 + }
1114 - 1114 +
1115 - //Gets ofPort in the interface. 1115 + //Gets ofPort in the interface.
1116 - private long getOfPort(Interface intf) { 1116 + private long getOfPort(Interface intf) {
1117 - OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data(); 1117 + OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data();
1118 - @SuppressWarnings("unchecked") 1118 + @SuppressWarnings("unchecked")
1119 - Set<Integer> ofPorts = ofPortSet.set(); 1119 + Set<Integer> ofPorts = ofPortSet.set();
1120 - while (ofPorts == null || ofPorts.size() <= 0) { 1120 + while (ofPorts == null || ofPorts.size() <= 0) {
1121 - log.debug("The ofport is null in {}", intf.getName()); 1121 + log.debug("The ofport is null in {}", intf.getName());
1122 - return -1; 1122 + return -1;
1123 - } 1123 + }
1124 - // return (long) ofPorts.toArray()[0]; 1124 + // return (long) ofPorts.toArray()[0];
1125 - Iterator<Integer> it = ofPorts.iterator(); 1125 + Iterator<Integer> it = ofPorts.iterator();
1126 - return Long.parseLong(it.next().toString()); 1126 + return Long.parseLong(it.next().toString());
1127 - } 1127 + }
1128 -} 1128 +}
......
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.controller.impl; 16 +package org.onosproject.ovsdb.controller.impl;
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.math.BigInteger; 20 +import java.math.BigInteger;
21 -import java.util.HashSet; 21 +import java.util.HashSet;
22 -import java.util.Iterator; 22 +import java.util.Iterator;
23 -import java.util.List; 23 +import java.util.List;
24 -import java.util.Map; 24 +import java.util.Map;
25 -import java.util.Set; 25 +import java.util.Set;
26 -import java.util.concurrent.ConcurrentHashMap; 26 +import java.util.concurrent.ConcurrentHashMap;
27 -import java.util.concurrent.CopyOnWriteArraySet; 27 +import java.util.concurrent.CopyOnWriteArraySet;
28 -import java.util.concurrent.ExecutionException; 28 +import java.util.concurrent.ExecutionException;
29 - 29 +
30 -import org.apache.felix.scr.annotations.Activate; 30 +import org.apache.felix.scr.annotations.Activate;
31 -import org.apache.felix.scr.annotations.Component; 31 +import org.apache.felix.scr.annotations.Component;
32 -import org.apache.felix.scr.annotations.Deactivate; 32 +import org.apache.felix.scr.annotations.Deactivate;
33 -import org.apache.felix.scr.annotations.Service; 33 +import org.apache.felix.scr.annotations.Service;
34 -import org.onlab.packet.IpAddress; 34 +import org.onlab.packet.IpAddress;
35 -import org.onlab.packet.MacAddress; 35 +import org.onlab.packet.MacAddress;
36 -import org.onosproject.ovsdb.controller.DefaultEventSubject; 36 +import org.onosproject.ovsdb.controller.DefaultEventSubject;
37 -import org.onosproject.ovsdb.controller.EventSubject; 37 +import org.onosproject.ovsdb.controller.EventSubject;
38 -import org.onosproject.ovsdb.controller.OvsdbClientService; 38 +import org.onosproject.ovsdb.controller.OvsdbClientService;
39 -import org.onosproject.ovsdb.controller.OvsdbConstant; 39 +import org.onosproject.ovsdb.controller.OvsdbConstant;
40 -import org.onosproject.ovsdb.controller.OvsdbController; 40 +import org.onosproject.ovsdb.controller.OvsdbController;
41 -import org.onosproject.ovsdb.controller.OvsdbDatapathId; 41 +import org.onosproject.ovsdb.controller.OvsdbDatapathId;
42 -import org.onosproject.ovsdb.controller.OvsdbEvent; 42 +import org.onosproject.ovsdb.controller.OvsdbEvent;
43 -import org.onosproject.ovsdb.controller.OvsdbEvent.Type; 43 +import org.onosproject.ovsdb.controller.OvsdbEvent.Type;
44 -import org.onosproject.ovsdb.controller.OvsdbEventListener; 44 +import org.onosproject.ovsdb.controller.OvsdbEventListener;
45 -import org.onosproject.ovsdb.controller.OvsdbIfaceId; 45 +import org.onosproject.ovsdb.controller.OvsdbIfaceId;
46 -import org.onosproject.ovsdb.controller.OvsdbNodeId; 46 +import org.onosproject.ovsdb.controller.OvsdbNodeId;
47 -import org.onosproject.ovsdb.controller.OvsdbNodeListener; 47 +import org.onosproject.ovsdb.controller.OvsdbNodeListener;
48 -import org.onosproject.ovsdb.controller.OvsdbPortName; 48 +import org.onosproject.ovsdb.controller.OvsdbPortName;
49 -import org.onosproject.ovsdb.controller.OvsdbPortNumber; 49 +import org.onosproject.ovsdb.controller.OvsdbPortNumber;
50 -import org.onosproject.ovsdb.controller.OvsdbPortType; 50 +import org.onosproject.ovsdb.controller.OvsdbPortType;
51 -import org.onosproject.ovsdb.controller.driver.OvsdbAgent; 51 +import org.onosproject.ovsdb.controller.driver.OvsdbAgent;
52 -import org.onosproject.ovsdb.rfc.jsonrpc.Callback; 52 +import org.onosproject.ovsdb.rfc.jsonrpc.Callback;
53 -import org.onosproject.ovsdb.rfc.message.TableUpdate; 53 +import org.onosproject.ovsdb.rfc.message.TableUpdate;
54 -import org.onosproject.ovsdb.rfc.message.TableUpdates; 54 +import org.onosproject.ovsdb.rfc.message.TableUpdates;
55 -import org.onosproject.ovsdb.rfc.message.UpdateNotification; 55 +import org.onosproject.ovsdb.rfc.message.UpdateNotification;
56 -import org.onosproject.ovsdb.rfc.notation.OvsdbMap; 56 +import org.onosproject.ovsdb.rfc.notation.OvsdbMap;
57 -import org.onosproject.ovsdb.rfc.notation.OvsdbSet; 57 +import org.onosproject.ovsdb.rfc.notation.OvsdbSet;
58 -import org.onosproject.ovsdb.rfc.notation.Row; 58 +import org.onosproject.ovsdb.rfc.notation.Row;
59 -import org.onosproject.ovsdb.rfc.notation.UUID; 59 +import org.onosproject.ovsdb.rfc.notation.UUID;
60 -import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 60 +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
61 -import org.onosproject.ovsdb.rfc.table.Bridge; 61 +import org.onosproject.ovsdb.rfc.table.Bridge;
62 -import org.onosproject.ovsdb.rfc.table.Interface; 62 +import org.onosproject.ovsdb.rfc.table.Interface;
63 -import org.onosproject.ovsdb.rfc.table.OvsdbTable; 63 +import org.onosproject.ovsdb.rfc.table.OvsdbTable;
64 -import org.onosproject.ovsdb.rfc.table.TableGenerator; 64 +import org.onosproject.ovsdb.rfc.table.TableGenerator;
65 -import org.onosproject.ovsdb.rfc.utils.FromJsonUtil; 65 +import org.onosproject.ovsdb.rfc.utils.FromJsonUtil;
66 -import org.osgi.service.component.ComponentContext; 66 +import org.osgi.service.component.ComponentContext;
67 -import org.slf4j.Logger; 67 +import org.slf4j.Logger;
68 -import org.slf4j.LoggerFactory; 68 +import org.slf4j.LoggerFactory;
69 - 69 +
70 -import com.fasterxml.jackson.databind.JsonNode; 70 +import com.fasterxml.jackson.databind.JsonNode;
71 - 71 +
72 -/** 72 +/**
73 - * The implementation of OvsdbController. 73 + * The implementation of OvsdbController.
74 - */ 74 + */
75 -@Component(immediate = true) 75 +@Component(immediate = true)
76 -@Service 76 +@Service
77 -public class OvsdbControllerImpl implements OvsdbController { 77 +public class OvsdbControllerImpl implements OvsdbController {
78 - 78 +
79 - public static final Logger log = LoggerFactory 79 + public static final Logger log = LoggerFactory
80 - .getLogger(OvsdbControllerImpl.class); 80 + .getLogger(OvsdbControllerImpl.class);
81 - 81 +
82 - protected ConcurrentHashMap<OvsdbNodeId, OvsdbClientService> ovsdbClients = 82 + protected ConcurrentHashMap<OvsdbNodeId, OvsdbClientService> ovsdbClients =
83 - new ConcurrentHashMap<OvsdbNodeId, OvsdbClientService>(); 83 + new ConcurrentHashMap<OvsdbNodeId, OvsdbClientService>();
84 - 84 +
85 - protected OvsdbAgent agent = new InternalOvsdbNodeAgent(); 85 + protected OvsdbAgent agent = new InternalOvsdbNodeAgent();
86 - protected InternalMonitorCallBack updateCallback = new InternalMonitorCallBack(); 86 + protected InternalMonitorCallBack updateCallback = new InternalMonitorCallBack();
87 - 87 +
88 - protected Set<OvsdbNodeListener> ovsdbNodeListener = new CopyOnWriteArraySet<>(); 88 + protected Set<OvsdbNodeListener> ovsdbNodeListener = new CopyOnWriteArraySet<>();
89 - protected Set<OvsdbEventListener> ovsdbEventListener = new CopyOnWriteArraySet<>(); 89 + protected Set<OvsdbEventListener> ovsdbEventListener = new CopyOnWriteArraySet<>();
90 - 90 +
91 - protected ConcurrentHashMap<String, OvsdbClientService> requestNotification = 91 + protected ConcurrentHashMap<String, OvsdbClientService> requestNotification =
92 - new ConcurrentHashMap<String, OvsdbClientService>(); 92 + new ConcurrentHashMap<String, OvsdbClientService>();
93 - 93 +
94 - protected ConcurrentHashMap<String, String> requestDbName = new ConcurrentHashMap<String, String>(); 94 + protected ConcurrentHashMap<String, String> requestDbName = new ConcurrentHashMap<String, String>();
95 - 95 +
96 - private final Controller controller = new Controller(); 96 + private final Controller controller = new Controller();
97 - 97 +
98 - @Activate 98 + @Activate
99 - public void activate(ComponentContext context) { 99 + public void activate(ComponentContext context) {
100 - controller.start(agent, updateCallback); 100 + controller.start(agent, updateCallback);
101 - log.info("Started"); 101 + log.info("Started");
102 - } 102 + }
103 - 103 +
104 - @Deactivate 104 + @Deactivate
105 - public void deactivate() { 105 + public void deactivate() {
106 - controller.stop(); 106 + controller.stop();
107 - log.info("Stoped"); 107 + log.info("Stoped");
108 - } 108 + }
109 - 109 +
110 - @Override 110 + @Override
111 - public void addNodeListener(OvsdbNodeListener listener) { 111 + public void addNodeListener(OvsdbNodeListener listener) {
112 - if (!ovsdbNodeListener.contains(listener)) { 112 + if (!ovsdbNodeListener.contains(listener)) {
113 - this.ovsdbNodeListener.add(listener); 113 + this.ovsdbNodeListener.add(listener);
114 - } 114 + }
115 - } 115 + }
116 - 116 +
117 - @Override 117 + @Override
118 - public void removeNodeListener(OvsdbNodeListener listener) { 118 + public void removeNodeListener(OvsdbNodeListener listener) {
119 - this.ovsdbNodeListener.remove(listener); 119 + this.ovsdbNodeListener.remove(listener);
120 - } 120 + }
121 - 121 +
122 - @Override 122 + @Override
123 - public void addOvsdbEventListener(OvsdbEventListener listener) { 123 + public void addOvsdbEventListener(OvsdbEventListener listener) {
124 - if (!ovsdbEventListener.contains(listener)) { 124 + if (!ovsdbEventListener.contains(listener)) {
125 - this.ovsdbEventListener.add(listener); 125 + this.ovsdbEventListener.add(listener);
126 - } 126 + }
127 - } 127 + }
128 - 128 +
129 - @Override 129 + @Override
130 - public void removeOvsdbEventListener(OvsdbEventListener listener) { 130 + public void removeOvsdbEventListener(OvsdbEventListener listener) {
131 - this.ovsdbEventListener.remove(listener); 131 + this.ovsdbEventListener.remove(listener);
132 - } 132 + }
133 - 133 +
134 - @Override 134 + @Override
135 - public List<OvsdbNodeId> getNodeIds() { 135 + public List<OvsdbNodeId> getNodeIds() {
136 - // TODO Auto-generated method stub 136 + // TODO Auto-generated method stub
137 - return null; 137 + return null;
138 - } 138 + }
139 - 139 +
140 - @Override 140 + @Override
141 - public OvsdbClientService getOvsdbClient(OvsdbNodeId nodeId) { 141 + public OvsdbClientService getOvsdbClient(OvsdbNodeId nodeId) {
142 - return ovsdbClients.get(nodeId); 142 + return ovsdbClients.get(nodeId);
143 - } 143 + }
144 - 144 +
145 - /** 145 + /**
146 - * Implementation of an Ovsdb Agent which is responsible for keeping track 146 + * Implementation of an Ovsdb Agent which is responsible for keeping track
147 - * of connected node and the state in which they are. 147 + * of connected node and the state in which they are.
148 - */ 148 + */
149 - private class InternalOvsdbNodeAgent implements OvsdbAgent { 149 + private class InternalOvsdbNodeAgent implements OvsdbAgent {
150 - @Override 150 + @Override
151 - public void addConnectedNode(OvsdbNodeId nodeId, 151 + public void addConnectedNode(OvsdbNodeId nodeId,
152 - OvsdbClientService ovsdbClient) { 152 + OvsdbClientService ovsdbClient) {
153 - 153 +
154 - if (ovsdbClients.get(nodeId) != null) { 154 + if (ovsdbClients.get(nodeId) != null) {
155 - return; 155 + return;
156 - } else { 156 + } else {
157 - ovsdbClients.put(nodeId, ovsdbClient); 157 + ovsdbClients.put(nodeId, ovsdbClient);
158 - 158 +
159 - try { 159 + try {
160 - List<String> dbNames = ovsdbClient.listDbs().get(); 160 + List<String> dbNames = ovsdbClient.listDbs().get();
161 - for (String dbName : dbNames) { 161 + for (String dbName : dbNames) {
162 - DatabaseSchema dbSchema; 162 + DatabaseSchema dbSchema;
163 - dbSchema = ovsdbClient.getOvsdbSchema(dbName).get(); 163 + dbSchema = ovsdbClient.getOvsdbSchema(dbName).get();
164 - 164 +
165 - log.debug("Begin to monitor tables"); 165 + log.debug("Begin to monitor tables");
166 - String id = java.util.UUID.randomUUID().toString(); 166 + String id = java.util.UUID.randomUUID().toString();
167 - TableUpdates updates = ovsdbClient 167 + TableUpdates updates = ovsdbClient
168 - .monitorTables(dbName, id).get(); 168 + .monitorTables(dbName, id).get();
169 - 169 +
170 - requestDbName.put(id, dbName); 170 + requestDbName.put(id, dbName);
171 - requestNotification.put(id, ovsdbClient); 171 + requestNotification.put(id, ovsdbClient);
172 - 172 +
173 - if (updates != null) { 173 + if (updates != null) {
174 - processTableUpdates(ovsdbClient, updates, 174 + processTableUpdates(ovsdbClient, updates,
175 - dbSchema.name()); 175 + dbSchema.name());
176 - } 176 + }
177 - } 177 + }
178 - } catch (InterruptedException e) { 178 + } catch (InterruptedException e) {
179 - log.warn("Interrupted while waiting to get message from ovsdb"); 179 + log.warn("Interrupted while waiting to get message from ovsdb");
180 - Thread.currentThread().interrupt(); 180 + Thread.currentThread().interrupt();
181 - } catch (ExecutionException e) { 181 + } catch (ExecutionException e) {
182 - log.error("Exception thrown while to get message from ovsdb"); 182 + log.error("Exception thrown while to get message from ovsdb");
183 - } 183 + }
184 - 184 +
185 - log.debug("Add node to north"); 185 + log.debug("Add node to north");
186 - for (OvsdbNodeListener l : ovsdbNodeListener) { 186 + for (OvsdbNodeListener l : ovsdbNodeListener) {
187 - l.nodeAdded(nodeId); 187 + l.nodeAdded(nodeId);
188 - } 188 + }
189 - return; 189 + return;
190 - } 190 + }
191 - } 191 + }
192 - 192 +
193 - @Override 193 + @Override
194 - public void removeConnectedNode(OvsdbNodeId nodeId) { 194 + public void removeConnectedNode(OvsdbNodeId nodeId) {
195 - ovsdbClients.remove(nodeId); 195 + ovsdbClients.remove(nodeId);
196 - log.debug("Node connection is removed"); 196 + log.debug("Node connection is removed");
197 - for (OvsdbNodeListener l : ovsdbNodeListener) { 197 + for (OvsdbNodeListener l : ovsdbNodeListener) {
198 - l.nodeRemoved(nodeId); 198 + l.nodeRemoved(nodeId);
199 - } 199 + }
200 - } 200 + }
201 - } 201 + }
202 - 202 +
203 - /** 203 + /**
204 - * Processes table updates. 204 + * Processes table updates.
205 - * 205 + *
206 - * @param clientService OvsdbClientService instance 206 + * @param clientService OvsdbClientService instance
207 - * @param updates TableUpdates instance 207 + * @param updates TableUpdates instance
208 - * @param dbName ovsdb database name 208 + * @param dbName ovsdb database name
209 - */ 209 + */
210 - private void processTableUpdates(OvsdbClientService clientService, 210 + private void processTableUpdates(OvsdbClientService clientService,
211 - TableUpdates updates, String dbName) 211 + TableUpdates updates, String dbName)
212 - throws InterruptedException { 212 + throws InterruptedException {
213 - checkNotNull(clientService, "OvsdbClientService is not null"); 213 + checkNotNull(clientService, "OvsdbClientService is not null");
214 - 214 +
215 - DatabaseSchema dbSchema = clientService.getDatabaseSchema(dbName); 215 + DatabaseSchema dbSchema = clientService.getDatabaseSchema(dbName);
216 - 216 +
217 - for (String tableName : updates.result().keySet()) { 217 + for (String tableName : updates.result().keySet()) {
218 - TableUpdate update = updates.result().get(tableName); 218 + TableUpdate update = updates.result().get(tableName);
219 - for (UUID uuid : (Set<UUID>) update.rows().keySet()) { 219 + for (UUID uuid : (Set<UUID>) update.rows().keySet()) {
220 - log.debug("Begin to process table updates uuid: {}, databaseName: {}, tableName: {}", 220 + log.debug("Begin to process table updates uuid: {}, databaseName: {}, tableName: {}",
221 - uuid.value(), dbName, tableName); 221 + uuid.value(), dbName, tableName);
222 - 222 +
223 - Row oldRow = update.getOld(uuid); 223 + Row oldRow = update.getOld(uuid);
224 - Row newRow = update.getNew(uuid); 224 + Row newRow = update.getNew(uuid);
225 - if (newRow != null) { 225 + if (newRow != null) {
226 - clientService.updateOvsdbStore(dbName, tableName, 226 + clientService.updateOvsdbStore(dbName, tableName,
227 - uuid.value(), newRow); 227 + uuid.value(), newRow);
228 - 228 +
229 - if (OvsdbConstant.INTERFACE.equals(tableName)) { 229 + if (OvsdbConstant.INTERFACE.equals(tableName)) {
230 - dispatchInterfaceEvent(clientService, 230 + dispatchInterfaceEvent(clientService,
231 - newRow, null, 231 + newRow, null,
232 - OvsdbEvent.Type.PORT_ADDED, 232 + OvsdbEvent.Type.PORT_ADDED,
233 - dbSchema); 233 + dbSchema);
234 - } 234 + }
235 - } else if (update.getOld(uuid) != null) { 235 + } else if (update.getOld(uuid) != null) {
236 - clientService.removeRow(dbName, tableName, uuid.value()); 236 + clientService.removeRow(dbName, tableName, uuid.value());
237 - if (OvsdbConstant.PORT.equals(tableName)) { 237 + if (OvsdbConstant.PORT.equals(tableName)) {
238 - dispatchInterfaceEvent(clientService, null, 238 + dispatchInterfaceEvent(clientService, null,
239 - oldRow, 239 + oldRow,
240 - OvsdbEvent.Type.PORT_REMOVED, 240 + OvsdbEvent.Type.PORT_REMOVED,
241 - dbSchema); 241 + dbSchema);
242 - } 242 + }
243 - } 243 + }
244 - } 244 + }
245 - } 245 + }
246 - } 246 + }
247 - 247 +
248 - /** 248 + /**
249 - * Dispatches event to the north. 249 + * Dispatches event to the north.
250 - * 250 + *
251 - * @param clientService OvsdbClientService instance 251 + * @param clientService OvsdbClientService instance
252 - * @param newRow a new row 252 + * @param newRow a new row
253 - * @param oldRow an old row 253 + * @param oldRow an old row
254 - * @param eventType type of event 254 + * @param eventType type of event
255 - * @param dbSchema ovsdb database schema 255 + * @param dbSchema ovsdb database schema
256 - */ 256 + */
257 - private void dispatchInterfaceEvent(OvsdbClientService clientService, 257 + private void dispatchInterfaceEvent(OvsdbClientService clientService,
258 - Row newRow, Row oldRow, 258 + Row newRow, Row oldRow,
259 - Type eventType, 259 + Type eventType,
260 - DatabaseSchema dbSchema) { 260 + DatabaseSchema dbSchema) {
261 - 261 +
262 - long dpid = getDataPathid(clientService, dbSchema); 262 + long dpid = getDataPathid(clientService, dbSchema);
263 - Interface intf = (Interface) TableGenerator 263 + Interface intf = (Interface) TableGenerator
264 - .getTable(dbSchema, newRow, OvsdbTable.INTERFACE); 264 + .getTable(dbSchema, newRow, OvsdbTable.INTERFACE);
265 - if (intf == null) { 265 + if (intf == null) {
266 - return; 266 + return;
267 - } 267 + }
268 - 268 +
269 - String portType = (String) intf.getTypeColumn().data(); 269 + String portType = (String) intf.getTypeColumn().data();
270 - long localPort = getOfPort(intf); 270 + long localPort = getOfPort(intf);
271 - if (localPort < 0) { 271 + if (localPort < 0) {
272 - return; 272 + return;
273 - } 273 + }
274 - String[] macAndIfaceId = getMacAndIfaceid(intf); 274 + String[] macAndIfaceId = getMacAndIfaceid(intf);
275 - if (macAndIfaceId == null) { 275 + if (macAndIfaceId == null) {
276 - return; 276 + return;
277 - } 277 + }
278 - 278 +
279 - EventSubject eventSubject = new DefaultEventSubject(MacAddress.valueOf( 279 + EventSubject eventSubject = new DefaultEventSubject(MacAddress.valueOf(
280 - macAndIfaceId[0]), 280 + macAndIfaceId[0]),
281 - new HashSet<IpAddress>(), 281 + new HashSet<IpAddress>(),
282 - new OvsdbPortName(intf 282 + new OvsdbPortName(intf
283 - .getName()), 283 + .getName()),
284 - new OvsdbPortNumber(localPort), 284 + new OvsdbPortNumber(localPort),
285 - new OvsdbDatapathId(Long 285 + new OvsdbDatapathId(Long
286 - .toString(dpid)), 286 + .toString(dpid)),
287 - new OvsdbPortType(portType), 287 + new OvsdbPortType(portType),
288 - new OvsdbIfaceId(macAndIfaceId[1])); 288 + new OvsdbIfaceId(macAndIfaceId[1]));
289 - for (OvsdbEventListener listener : ovsdbEventListener) { 289 + for (OvsdbEventListener listener : ovsdbEventListener) {
290 - listener.handle(new OvsdbEvent<EventSubject>(eventType, 290 + listener.handle(new OvsdbEvent<EventSubject>(eventType,
291 - eventSubject)); 291 + eventSubject));
292 - } 292 + }
293 - } 293 + }
294 - 294 +
295 - /** 295 + /**
296 - * Gets mac and iface from the table Interface. 296 + * Gets mac and iface from the table Interface.
297 - * 297 + *
298 - * @param intf Interface instance 298 + * @param intf Interface instance
299 - * @return attachedMac, ifaceid 299 + * @return attachedMac, ifaceid
300 - */ 300 + */
301 - private String[] getMacAndIfaceid(Interface intf) { 301 + private String[] getMacAndIfaceid(Interface intf) {
302 - OvsdbMap ovsdbMap = (OvsdbMap) intf.getExternalIdsColumn().data(); 302 + OvsdbMap ovsdbMap = (OvsdbMap) intf.getExternalIdsColumn().data();
303 - @SuppressWarnings("unchecked") 303 + @SuppressWarnings("unchecked")
304 - Map<String, String> externalIds = ovsdbMap.map(); 304 + Map<String, String> externalIds = ovsdbMap.map();
305 - if (externalIds == null) { 305 + if (externalIds == null) {
306 - log.warn("The external_ids is null"); 306 + log.warn("The external_ids is null");
307 - return null; 307 + return null;
308 - } 308 + }
309 - 309 +
310 - String attachedMac = externalIds.get(OvsdbConstant.EXTERNAL_ID_VM_MAC); 310 + String attachedMac = externalIds.get(OvsdbConstant.EXTERNAL_ID_VM_MAC);
311 - if (attachedMac == null) { 311 + if (attachedMac == null) {
312 - log.warn("The attachedMac is null"); 312 + log.warn("The attachedMac is null");
313 - return null; 313 + return null;
314 - } 314 + }
315 - String ifaceid = externalIds 315 + String ifaceid = externalIds
316 - .get(OvsdbConstant.EXTERNAL_ID_INTERFACE_ID); 316 + .get(OvsdbConstant.EXTERNAL_ID_INTERFACE_ID);
317 - if (ifaceid == null) { 317 + if (ifaceid == null) {
318 - log.warn("The ifaceid is null"); 318 + log.warn("The ifaceid is null");
319 - return null; 319 + return null;
320 - } 320 + }
321 - return new String[] {attachedMac, ifaceid}; 321 + return new String[] {attachedMac, ifaceid};
322 - } 322 + }
323 - 323 +
324 - /** 324 + /**
325 - * Gets ofPorts number from table Interface. 325 + * Gets ofPorts number from table Interface.
326 - * 326 + *
327 - * @param intf Interface instance 327 + * @param intf Interface instance
328 - * @return ofport the ofport number 328 + * @return ofport the ofport number
329 - */ 329 + */
330 - private long getOfPort(Interface intf) { 330 + private long getOfPort(Interface intf) {
331 - OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data(); 331 + OvsdbSet ofPortSet = (OvsdbSet) intf.getOpenFlowPortColumn().data();
332 - @SuppressWarnings("unchecked") 332 + @SuppressWarnings("unchecked")
333 - Set<Integer> ofPorts = ofPortSet.set(); 333 + Set<Integer> ofPorts = ofPortSet.set();
334 - while (ofPorts == null || ofPorts.size() <= 0) { 334 + while (ofPorts == null || ofPorts.size() <= 0) {
335 - log.debug("The ofport is null in {}", intf.getName()); 335 + log.debug("The ofport is null in {}", intf.getName());
336 - return -1; 336 + return -1;
337 - } 337 + }
338 - Iterator<Integer> it = ofPorts.iterator(); 338 + Iterator<Integer> it = ofPorts.iterator();
339 - return Long.parseLong(it.next().toString()); 339 + return Long.parseLong(it.next().toString());
340 - } 340 + }
341 - 341 +
342 - /** 342 + /**
343 - * Gets datapathid from table bridge. 343 + * Gets datapathid from table bridge.
344 - * 344 + *
345 - * @param clientService OvsdbClientService instance 345 + * @param clientService OvsdbClientService instance
346 - * @param dbSchema ovsdb database schema 346 + * @param dbSchema ovsdb database schema
347 - * @return datapathid the bridge datapathid 347 + * @return datapathid the bridge datapathid
348 - */ 348 + */
349 - private long getDataPathid(OvsdbClientService clientService, 349 + private long getDataPathid(OvsdbClientService clientService,
350 - DatabaseSchema dbSchema) { 350 + DatabaseSchema dbSchema) {
351 - String bridgeUuid = clientService 351 + String bridgeUuid = clientService
352 - .getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE); 352 + .getBridgeUuid(OvsdbConstant.INTEGRATION_BRIDGE);
353 - if (bridgeUuid == null) { 353 + if (bridgeUuid == null) {
354 - log.debug("Unable to spot bridge uuid for {} in {}", 354 + log.debug("Unable to spot bridge uuid for {} in {}",
355 - OvsdbConstant.INTEGRATION_BRIDGE, clientService); 355 + OvsdbConstant.INTEGRATION_BRIDGE, clientService);
356 - return 0; 356 + return 0;
357 - } 357 + }
358 - 358 +
359 - Row bridgeRow = clientService.getRow(OvsdbConstant.DATABASENAME, 359 + Row bridgeRow = clientService.getRow(OvsdbConstant.DATABASENAME,
360 - "Bridge", bridgeUuid); 360 + "Bridge", bridgeUuid);
361 - Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, 361 + Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow,
362 - OvsdbTable.BRIDGE); 362 + OvsdbTable.BRIDGE);
363 - OvsdbSet dpidSet = (OvsdbSet) bridge.getDatapathIdColumn().data(); 363 + OvsdbSet dpidSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
364 - @SuppressWarnings("unchecked") 364 + @SuppressWarnings("unchecked")
365 - Set<String> dpids = dpidSet.set(); 365 + Set<String> dpids = dpidSet.set();
366 - if (dpids == null || dpids.size() == 0) { 366 + if (dpids == null || dpids.size() == 0) {
367 - return 0; 367 + return 0;
368 - } 368 + }
369 - return stringToLong((String) dpids.toArray()[0]); 369 + return stringToLong((String) dpids.toArray()[0]);
370 - } 370 + }
371 - 371 +
372 - private long stringToLong(String values) { 372 + private long stringToLong(String values) {
373 - long value = (new BigInteger(values.replaceAll(":", ""), 16)) 373 + long value = (new BigInteger(values.replaceAll(":", ""), 16))
374 - .longValue(); 374 + .longValue();
375 - return value; 375 + return value;
376 - } 376 + }
377 - 377 +
378 - /** 378 + /**
379 - * Implementation of an Callback which is responsible for receiving request 379 + * Implementation of an Callback which is responsible for receiving request
380 - * infomation from ovsdb. 380 + * infomation from ovsdb.
381 - */ 381 + */
382 - private class InternalMonitorCallBack implements Callback { 382 + private class InternalMonitorCallBack implements Callback {
383 - @Override 383 + @Override
384 - public void update(UpdateNotification updateNotification) { 384 + public void update(UpdateNotification updateNotification) {
385 - Object key = updateNotification.jsonValue(); 385 + Object key = updateNotification.jsonValue();
386 - OvsdbClientService ovsdbClient = requestNotification.get(key); 386 + OvsdbClientService ovsdbClient = requestNotification.get(key);
387 - 387 +
388 - String dbName = requestDbName.get(key); 388 + String dbName = requestDbName.get(key);
389 - JsonNode updatesJson = updateNotification.tbUpdatesJsonNode(); 389 + JsonNode updatesJson = updateNotification.tbUpdatesJsonNode();
390 - DatabaseSchema dbSchema = ovsdbClient.getDatabaseSchema(dbName); 390 + DatabaseSchema dbSchema = ovsdbClient.getDatabaseSchema(dbName);
391 - TableUpdates updates = FromJsonUtil 391 + TableUpdates updates = FromJsonUtil
392 - .jsonNodeToTableUpdates(updatesJson, dbSchema); 392 + .jsonNodeToTableUpdates(updatesJson, dbSchema);
393 - try { 393 + try {
394 - processTableUpdates(ovsdbClient, updates, dbName); 394 + processTableUpdates(ovsdbClient, updates, dbName);
395 - } catch (InterruptedException e) { 395 + } catch (InterruptedException e) {
396 - log.warn("Interrupted while processing table updates"); 396 + log.warn("Interrupted while processing table updates");
397 - Thread.currentThread().interrupt(); 397 + Thread.currentThread().interrupt();
398 - } 398 + }
399 - } 399 + }
400 - 400 +
401 - @Override 401 + @Override
402 - public void locked(List<String> ids) { 402 + public void locked(List<String> ids) {
403 - // TODO Auto-generated method stub 403 + // TODO Auto-generated method stub
404 - } 404 + }
405 - 405 +
406 - @Override 406 + @Override
407 - public void stolen(List<String> ids) { 407 + public void stolen(List<String> ids) {
408 - // TODO Auto-generated method stub 408 + // TODO Auto-generated method stub
409 - } 409 + }
410 - 410 +
411 - } 411 + }
412 - 412 +
413 -} 413 +}
......
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 jsonValue; 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 jsonValue 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 jsonValue, JsonNode tbUpdatesJsonNode) { 43 + public UpdateNotification(Object jsonValue, JsonNode tbUpdatesJsonNode) {
44 - checkNotNull(jsonValue, "jsonValue 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.jsonValue = jsonValue; 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 jsonValue() { 54 + public Object jsonValue() {
55 - return jsonValue; 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(jsonValue, 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.jsonValue, other.jsonValue) 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("jsonValue", jsonValue) 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 -/** 23 +/**
24 - * Column is the basic element of the OpenVswitch database. 24 + * Column is the basic element of the OpenVswitch database.
25 - */ 25 + */
26 -public final class Column { 26 +public final class Column {
27 - private final String columnName; 27 + private final String columnName;
28 - private final Object data; 28 + private final Object data;
29 - 29 +
30 - /** 30 + /**
31 - * Column constructor. 31 + * Column constructor.
32 - * @param columnName the column name 32 + * @param columnName the column name
33 - * @param obj the data of the column 33 + * @param obj the data of the column
34 - */ 34 + */
35 - public Column(String columnName, Object obj) { 35 + public Column(String columnName, Object obj) {
36 - checkNotNull(columnName, "columnName cannot be null"); 36 + checkNotNull(columnName, "columnName cannot be null");
37 - checkNotNull(obj, "data cannot be null"); 37 + checkNotNull(obj, "data cannot be null");
38 - this.columnName = columnName; 38 + this.columnName = columnName;
39 - this.data = obj; 39 + this.data = obj;
40 - } 40 + }
41 - 41 +
42 - /** 42 + /**
43 - * Returns column data. 43 + * Returns column data.
44 - * @return column data 44 + * @return column data
45 - */ 45 + */
46 - public Object data() { 46 + public Object data() {
47 - return data; 47 + return data;
48 - } 48 + }
49 - 49 +
50 - /** 50 + /**
51 - * Returns columnName. 51 + * Returns columnName.
52 - * @return columnName 52 + * @return columnName
53 - */ 53 + */
54 - public String columnName() { 54 + public String columnName() {
55 - return columnName; 55 + return columnName;
56 - } 56 + }
57 - 57 +
58 - @Override 58 + @Override
59 - public int hashCode() { 59 + public int hashCode() {
60 - return Objects.hash(columnName, data); 60 + return Objects.hash(columnName, data);
61 - } 61 + }
62 - 62 +
63 - @Override 63 + @Override
64 - public boolean equals(Object obj) { 64 + public boolean equals(Object obj) {
65 - if (this == obj) { 65 + if (this == obj) {
66 - return true; 66 + return true;
67 - } 67 + }
68 - if (obj instanceof Column) { 68 + if (obj instanceof Column) {
69 - final Column other = (Column) obj; 69 + final Column other = (Column) obj;
70 - return Objects.equals(this.columnName, other.columnName) 70 + return Objects.equals(this.columnName, other.columnName)
71 - && Objects.equals(this.data, other.data); 71 + && Objects.equals(this.data, other.data);
72 - } 72 + }
73 - return false; 73 + return false;
74 - } 74 + }
75 - 75 +
76 - @Override 76 + @Override
77 - public String toString() { 77 + public String toString() {
78 - return toStringHelper(this).add("columnName", columnName) 78 + return toStringHelper(this).add("columnName", columnName)
79 - .add("data", data).toString(); 79 + .add("data", data).toString();
80 - } 80 + }
81 -} 81 +}
......
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.Map; 22 +import java.util.Map;
23 -import java.util.Objects; 23 +import java.util.Objects;
24 - 24 +
25 -import com.google.common.collect.Maps; 25 +import com.google.common.collect.Maps;
26 - 26 +
27 -/** 27 +/**
28 - * Row is the basic element of the OpenVswitch's table. 28 + * Row is the basic element of the OpenVswitch's table.
29 - */ 29 + */
30 -public final class Row { 30 +public final class Row {
31 - private String tableName; 31 + private String tableName;
32 - private Map<String, Column> columns; 32 + private Map<String, Column> columns;
33 - 33 +
34 - /** 34 + /**
35 - * Row constructor. 35 + * Row constructor.
36 - */ 36 + */
37 - public Row() { 37 + public Row() {
38 - this.columns = Maps.newHashMap(); 38 + this.columns = Maps.newHashMap();
39 - } 39 + }
40 - 40 +
41 - /** 41 + /**
42 - * Row constructor. 42 + * Row constructor.
43 - * @param tableName table name 43 + * @param tableName table name
44 - */ 44 + */
45 - public Row(String tableName) { 45 + public Row(String tableName) {
46 - checkNotNull(tableName, "tableName cannot be null"); 46 + checkNotNull(tableName, "tableName cannot be null");
47 - this.tableName = tableName; 47 + this.tableName = tableName;
48 - this.columns = Maps.newHashMap(); 48 + this.columns = Maps.newHashMap();
49 - } 49 + }
50 - 50 +
51 - /** 51 + /**
52 - * Row constructor. 52 + * Row constructor.
53 - * @param tableName table name 53 + * @param tableName table name
54 - * @param columns Map of Column entity 54 + * @param columns Map of Column entity
55 - */ 55 + */
56 - public Row(String tableName, Map<String, Column> columns) { 56 + public Row(String tableName, Map<String, Column> columns) {
57 - checkNotNull(tableName, "table name cannot be null"); 57 + checkNotNull(tableName, "table name cannot be null");
58 - checkNotNull(columns, "columns cannot be null"); 58 + checkNotNull(columns, "columns cannot be null");
59 - this.tableName = tableName; 59 + this.tableName = tableName;
60 - this.columns = columns; 60 + this.columns = columns;
61 - } 61 + }
62 - 62 +
63 - /** 63 + /**
64 - * Returns tableName. 64 + * Returns tableName.
65 - * @return tableName 65 + * @return tableName
66 - */ 66 + */
67 - public String tableName() { 67 + public String tableName() {
68 - return tableName; 68 + return tableName;
69 - } 69 + }
70 - 70 +
71 - /** 71 + /**
72 - * Set tableName value. 72 + * Set tableName value.
73 - * @param tableName table name 73 + * @param tableName table name
74 - */ 74 + */
75 - public void setTableName(String tableName) { 75 + public void setTableName(String tableName) {
76 - this.tableName = tableName; 76 + this.tableName = tableName;
77 - } 77 + }
78 - 78 +
79 - /** 79 + /**
80 - * Returns Column by ColumnSchema. 80 + * Returns Column by ColumnSchema.
81 - * @param columnName column name 81 + * @param columnName column name
82 - * @return Column 82 + * @return Column
83 - */ 83 + */
84 - public Column getColumn(String columnName) { 84 + public Column getColumn(String columnName) {
85 - return columns.get(columnName); 85 + return columns.get(columnName);
86 - } 86 + }
87 - 87 +
88 - /** 88 + /**
89 - * Returns Collection of Column. 89 + * Returns Collection of Column.
90 - * @return Collection of Column 90 + * @return Collection of Column
91 - */ 91 + */
92 - public Collection<Column> getColumns() { 92 + public Collection<Column> getColumns() {
93 - return columns.values(); 93 + return columns.values();
94 - } 94 + }
95 - 95 +
96 - /** 96 + /**
97 - * add Column. 97 + * add Column.
98 - * @param columnName column name 98 + * @param columnName column name
99 - * @param data Column entity 99 + * @param data Column entity
100 - */ 100 + */
101 - public void addColumn(String columnName, Column data) { 101 + public void addColumn(String columnName, Column data) {
102 - this.columns.put(columnName, data); 102 + this.columns.put(columnName, data);
103 - } 103 + }
104 - 104 +
105 - @Override 105 + @Override
106 - public int hashCode() { 106 + public int hashCode() {
107 - return Objects.hash(tableName, columns); 107 + return Objects.hash(tableName, columns);
108 - } 108 + }
109 - 109 +
110 - @Override 110 + @Override
111 - public boolean equals(Object obj) { 111 + public boolean equals(Object obj) {
112 - if (this == obj) { 112 + if (this == obj) {
113 - return true; 113 + return true;
114 - } 114 + }
115 - if (obj instanceof Row) { 115 + if (obj instanceof Row) {
116 - final Row other = (Row) obj; 116 + final Row other = (Row) obj;
117 - return Objects.equals(this.tableName, other.tableName) 117 + return Objects.equals(this.tableName, other.tableName)
118 - && Objects.equals(this.columns, other.columns); 118 + && Objects.equals(this.columns, other.columns);
119 - } 119 + }
120 - return false; 120 + return false;
121 - } 121 + }
122 - 122 +
123 - @Override 123 + @Override
124 - public String toString() { 124 + public String toString() {
125 - return toStringHelper(this).add("tableName", tableName) 125 + return toStringHelper(this).add("tableName", tableName)
126 - .add("columns", columns).toString(); 126 + .add("columns", columns).toString();
127 - } 127 + }
128 -} 128 +}
......
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.json; 16 +package org.onosproject.ovsdb.rfc.notation.json;
17 - 17 +
18 -import org.onosproject.ovsdb.rfc.notation.UUID; 18 +import org.onosproject.ovsdb.rfc.notation.UUID;
19 - 19 +
20 -import com.fasterxml.jackson.databind.JsonNode; 20 +import com.fasterxml.jackson.databind.JsonNode;
21 -import com.fasterxml.jackson.databind.util.StdConverter; 21 +import com.fasterxml.jackson.databind.util.StdConverter;
22 - 22 +
23 -/** 23 +/**
24 - * UUIDConverter Converter. 24 + * UUIDConverter Converter.
25 - */ 25 + */
26 -public class UUIDConverter extends StdConverter<JsonNode, UUID> { 26 +public class UUIDConverter extends StdConverter<JsonNode, UUID> {
27 - 27 +
28 - @Override 28 + @Override
29 - public UUID convert(JsonNode json) { 29 + public UUID convert(JsonNode json) {
30 - return UUID.uuid(json.get(1).asText()); 30 + return UUID.uuid(json.get(1).asText());
31 - } 31 + }
32 -} 32 +}
......
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.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.TableSchema; 25 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
26 -import org.onosproject.ovsdb.rfc.utils.TransValueUtil; 26 +import org.onosproject.ovsdb.rfc.utils.TransValueUtil;
27 - 27 +
28 -import com.fasterxml.jackson.annotation.JsonIgnore; 28 +import com.fasterxml.jackson.annotation.JsonIgnore;
29 -import com.fasterxml.jackson.annotation.JsonProperty; 29 +import com.fasterxml.jackson.annotation.JsonProperty;
30 -import com.google.common.collect.Maps; 30 +import com.google.common.collect.Maps;
31 - 31 +
32 -/** 32 +/**
33 - * insert operation.Refer to RFC 7047 Section 5.2. 33 + * insert operation.Refer to RFC 7047 Section 5.2.
34 - */ 34 + */
35 -public final class Insert implements Operation { 35 +public final class Insert implements Operation {
36 - 36 +
37 - @JsonIgnore 37 + @JsonIgnore
38 - private final TableSchema tableSchema; 38 + private final TableSchema tableSchema;
39 - private final String op; 39 + private final String op;
40 - @JsonProperty("uuid-name") 40 + @JsonProperty("uuid-name")
41 - private final String uuidName; 41 + private final String uuidName;
42 - private final Map<String, Object> row; 42 + private final Map<String, Object> row;
43 - 43 +
44 - /** 44 + /**
45 - * Constructs a Insert object. 45 + * Constructs a Insert object.
46 - * @param schema TableSchema entity 46 + * @param schema TableSchema entity
47 - * @param uuidName uuid-name 47 + * @param uuidName uuid-name
48 - * @param row Row entity 48 + * @param row Row entity
49 - */ 49 + */
50 - public Insert(TableSchema schema, String uuidName, Row row) { 50 + public Insert(TableSchema schema, String uuidName, Row row) {
51 - checkNotNull(schema, "TableSchema cannot be null"); 51 + checkNotNull(schema, "TableSchema cannot be null");
52 - checkNotNull(uuidName, "uuid name cannot be null"); 52 + checkNotNull(uuidName, "uuid name cannot be null");
53 - checkNotNull(row, "row cannot be null"); 53 + checkNotNull(row, "row cannot be null");
54 - this.tableSchema = schema; 54 + this.tableSchema = schema;
55 - this.op = Operations.INSERT.op(); 55 + this.op = Operations.INSERT.op();
56 - this.uuidName = uuidName; 56 + this.uuidName = uuidName;
57 - this.row = Maps.newHashMap(); 57 + this.row = Maps.newHashMap();
58 - generateOperationRow(row); 58 + generateOperationRow(row);
59 - } 59 + }
60 - 60 +
61 - /** 61 + /**
62 - * Row entity convert into the row format of insert operation. Refer to RFC 62 + * Row entity convert into the row format of insert operation. Refer to RFC
63 - * 7047 Section 5.2. 63 + * 7047 Section 5.2.
64 - * @param row Row entity 64 + * @param row Row entity
65 - */ 65 + */
66 - private void generateOperationRow(Row row) { 66 + private void generateOperationRow(Row row) {
67 - Collection<Column> columns = row.getColumns(); 67 + Collection<Column> columns = row.getColumns();
68 - for (Column column : columns) { 68 + for (Column column : columns) {
69 - String columnName = column.columnName(); 69 + String columnName = column.columnName();
70 - Object value = column.data(); 70 + Object value = column.data();
71 - Object formatValue = TransValueUtil.getFormatData(value); 71 + Object formatValue = TransValueUtil.getFormatData(value);
72 - this.row.put(columnName, formatValue); 72 + this.row.put(columnName, formatValue);
73 - } 73 + }
74 - } 74 + }
75 - 75 +
76 - /** 76 + /**
77 - * Returns the uuid-name member of insert operation. 77 + * Returns the uuid-name member of insert operation.
78 - * @return the uuid-name member of insert operation 78 + * @return the uuid-name member of insert operation
79 - */ 79 + */
80 - public String getUuidName() { 80 + public String getUuidName() {
81 - return uuidName; 81 + return uuidName;
82 - } 82 + }
83 - 83 +
84 - /** 84 + /**
85 - * Returns the row member of insert operation. 85 + * Returns the row member of insert operation.
86 - * @return the row member of insert operation 86 + * @return the row member of insert operation
87 - */ 87 + */
88 - public Map<String, Object> getRow() { 88 + public Map<String, Object> getRow() {
89 - return row; 89 + return row;
90 - } 90 + }
91 - 91 +
92 - @Override 92 + @Override
93 - public String getOp() { 93 + public String getOp() {
94 - return op; 94 + return op;
95 - } 95 + }
96 - 96 +
97 - @Override 97 + @Override
98 - public TableSchema getTableSchema() { 98 + public TableSchema getTableSchema() {
99 - return tableSchema; 99 + return tableSchema;
100 - } 100 + }
101 - 101 +
102 - /** 102 + /**
103 - * For the use of serialization. 103 + * For the use of serialization.
104 - * @return the table member of update operation 104 + * @return the table member of update operation
105 - */ 105 + */
106 - @JsonProperty 106 + @JsonProperty
107 - public String getTable() { 107 + public String getTable() {
108 - return tableSchema.name(); 108 + return tableSchema.name();
109 - } 109 + }
110 -} 110 +}
......
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.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.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.TableSchema; 27 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
28 -import org.onosproject.ovsdb.rfc.utils.TransValueUtil; 28 +import org.onosproject.ovsdb.rfc.utils.TransValueUtil;
29 - 29 +
30 -import com.fasterxml.jackson.annotation.JsonIgnore; 30 +import com.fasterxml.jackson.annotation.JsonIgnore;
31 -import com.fasterxml.jackson.annotation.JsonProperty; 31 +import com.fasterxml.jackson.annotation.JsonProperty;
32 -import com.google.common.collect.Maps; 32 +import com.google.common.collect.Maps;
33 - 33 +
34 -/** 34 +/**
35 - * update operation.Refer to RFC 7047 Section 5.2. 35 + * update operation.Refer to RFC 7047 Section 5.2.
36 - */ 36 + */
37 -public final class Update implements Operation { 37 +public final class Update implements Operation {
38 - 38 +
39 - @JsonIgnore 39 + @JsonIgnore
40 - private final TableSchema tableSchema; 40 + private final TableSchema tableSchema;
41 - private final String op; 41 + private final String op;
42 - private final Map<String, Object> row; 42 + private final Map<String, Object> row;
43 - private final List<Condition> where; 43 + private final List<Condition> where;
44 - 44 +
45 - /** 45 + /**
46 - * Constructs a Update object. 46 + * Constructs a Update object.
47 - * @param schema TableSchema entity 47 + * @param schema TableSchema entity
48 - * @param row Row entity 48 + * @param row Row entity
49 - * @param where the List of Condition entity 49 + * @param where the List of Condition entity
50 - */ 50 + */
51 - public Update(TableSchema schema, Row row, List<Condition> where) { 51 + public Update(TableSchema schema, Row row, List<Condition> where) {
52 - checkNotNull(schema, "TableSchema cannot be null"); 52 + checkNotNull(schema, "TableSchema cannot be null");
53 - checkNotNull(row, "row cannot be null"); 53 + checkNotNull(row, "row cannot be null");
54 - checkNotNull(where, "where cannot be null"); 54 + checkNotNull(where, "where cannot be null");
55 - this.tableSchema = schema; 55 + this.tableSchema = schema;
56 - this.op = Operations.UPDATE.op(); 56 + this.op = Operations.UPDATE.op();
57 - this.row = Maps.newHashMap(); 57 + this.row = Maps.newHashMap();
58 - this.where = where; 58 + this.where = where;
59 - generateOperationRow(row); 59 + generateOperationRow(row);
60 - } 60 + }
61 - 61 +
62 - /** 62 + /**
63 - * Row entity convert into the row format of update operation. Refer to RFC 63 + * Row entity convert into the row format of update operation. Refer to RFC
64 - * 7047 Section 5.2. 64 + * 7047 Section 5.2.
65 - * @param row Row entity 65 + * @param row Row entity
66 - */ 66 + */
67 - private void generateOperationRow(Row row) { 67 + private void generateOperationRow(Row row) {
68 - Collection<Column> columns = row.getColumns(); 68 + Collection<Column> columns = row.getColumns();
69 - for (Column column : columns) { 69 + for (Column column : columns) {
70 - String columnName = column.columnName(); 70 + String columnName = column.columnName();
71 - Object value = column.data(); 71 + Object value = column.data();
72 - Object formatValue = TransValueUtil.getFormatData(value); 72 + Object formatValue = TransValueUtil.getFormatData(value);
73 - this.row.put(columnName, formatValue); 73 + this.row.put(columnName, formatValue);
74 - } 74 + }
75 - } 75 + }
76 - 76 +
77 - /** 77 + /**
78 - * Returns the row member of update operation. 78 + * Returns the row member of update operation.
79 - * @return the row member of update operation 79 + * @return the row member of update operation
80 - */ 80 + */
81 - public Map<String, Object> getRow() { 81 + public Map<String, Object> getRow() {
82 - return row; 82 + return row;
83 - } 83 + }
84 - 84 +
85 - /** 85 + /**
86 - * Returns the where member of update operation. 86 + * Returns the where member of update operation.
87 - * @return the where member of update operation 87 + * @return the where member of update operation
88 - */ 88 + */
89 - public List<Condition> getWhere() { 89 + public List<Condition> getWhere() {
90 - return where; 90 + return where;
91 - } 91 + }
92 - 92 +
93 - @Override 93 + @Override
94 - public String getOp() { 94 + public String getOp() {
95 - return op; 95 + return op;
96 - } 96 + }
97 - 97 +
98 - @Override 98 + @Override
99 - public TableSchema getTableSchema() { 99 + public TableSchema getTableSchema() {
100 - return tableSchema; 100 + return tableSchema;
101 - } 101 + }
102 - 102 +
103 - /** 103 + /**
104 - * For the use of serialization. 104 + * For the use of serialization.
105 - * @return the table member of update operation 105 + * @return the table member of update operation
106 - */ 106 + */
107 - @JsonProperty 107 + @JsonProperty
108 - public String getTable() { 108 + public String getTable() {
109 - return tableSchema.name(); 109 + return tableSchema.name();
110 - } 110 + }
111 -} 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.schema.type; 16 +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.AbnormalJsonNodeException; 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 +import org.onosproject.ovsdb.rfc.utils.ObjectMapperUtil;
23 - 23 +
24 -import com.fasterxml.jackson.databind.JsonNode; 24 +import com.fasterxml.jackson.databind.JsonNode;
25 -import com.google.common.collect.Sets; 25 +import com.google.common.collect.Sets;
26 - 26 +
27 -/** 27 +/**
28 - * BaseType Factory class. 28 + * BaseType Factory class.
29 - */ 29 + */
30 -public final class BaseTypeFactory { 30 +public final class BaseTypeFactory {
31 - 31 +
32 - /** 32 + /**
33 - * Constructs a BaseTypeFactory object. This class should not be 33 + * Constructs a BaseTypeFactory object. This class should not be
34 - * instantiated. 34 + * instantiated.
35 - */ 35 + */
36 - private BaseTypeFactory() { 36 + private BaseTypeFactory() {
37 - } 37 + }
38 - 38 +
39 - /** 39 + /**
40 - * Create a BaseType from the JsonNode. 40 + * Create a BaseType from the JsonNode.
41 - * @param baseTypeJson the BaseType JsonNode 41 + * @param baseTypeJson the BaseType JsonNode
42 - * @param keyorval the key node or value node 42 + * @param keyorval the key node or value node
43 - * @return BaseType 43 + * @return BaseType
44 - */ 44 + */
45 - public static BaseType getBaseTypeFromJson(JsonNode baseTypeJson, String keyorval) { 45 + public static BaseType getBaseTypeFromJson(JsonNode baseTypeJson, String keyorval) {
46 - if (baseTypeJson.isValueNode()) { 46 + if (baseTypeJson.isValueNode()) {
47 - String type = baseTypeJson.asText().trim(); 47 + String type = baseTypeJson.asText().trim();
48 - return fromTypeStr(type); 48 + return fromTypeStr(type);
49 - } else { 49 + } else {
50 - if (!baseTypeJson.has(keyorval)) { 50 + if (!baseTypeJson.has(keyorval)) {
51 - String message = "Abnormal BaseType JsonNode, it should contain 'key' or 'value' node but was not found" 51 + String message = "Abnormal BaseType JsonNode, it should contain 'key' or 'value' node but was not found"
52 - + ObjectMapperUtil.convertToString(baseTypeJson); 52 + + ObjectMapperUtil.convertToString(baseTypeJson);
53 - throw new AbnormalJsonNodeException(message); 53 + throw new AbnormalJsonNodeException(message);
54 - } 54 + }
55 - return fromJsonNode(baseTypeJson.get(keyorval)); 55 + return fromJsonNode(baseTypeJson.get(keyorval));
56 - } 56 + }
57 - } 57 + }
58 - 58 +
59 - /** 59 + /**
60 - * Get BaseType by the type value of JsonNode. 60 + * Get BaseType by the type value of JsonNode.
61 - * @param type the type value of JsonNode 61 + * @param type the type value of JsonNode
62 - * @return BaseType 62 + * @return BaseType
63 - */ 63 + */
64 - private static BaseType fromTypeStr(String type) { 64 + private static BaseType fromTypeStr(String type) {
65 - switch (type) { 65 + switch (type) {
66 - case "boolean": 66 + case "boolean":
67 - return new BooleanBaseType(); 67 + return new BooleanBaseType();
68 - case "integer": 68 + case "integer":
69 - return new IntegerBaseType(); 69 + return new IntegerBaseType();
70 - case "real": 70 + case "real":
71 - return new RealBaseType(); 71 + return new RealBaseType();
72 - case "string": 72 + case "string":
73 - return new StringBaseType(); 73 + return new StringBaseType();
74 - case "uuid": 74 + case "uuid":
75 - return new UuidBaseType(); 75 + return new UuidBaseType();
76 - default: 76 + default:
77 - return null; 77 + return null;
78 - } 78 + }
79 - } 79 + }
80 - 80 +
81 - /** 81 + /**
82 - * json like "string" or json like {"type" : "string", "enum": ["set", 82 + * json like "string" or json like {"type" : "string", "enum": ["set",
83 - * ["access", "native-tagged"]]}" for key or value. 83 + * ["access", "native-tagged"]]}" for key or value.
84 - * @param type JsonNode 84 + * @param type JsonNode
85 - */ 85 + */
86 - private static BaseType fromJsonNode(JsonNode type) { 86 + private static BaseType fromJsonNode(JsonNode type) {
87 - if (type.isTextual()) { 87 + if (type.isTextual()) {
88 - return fromTypeStr(type.asText()); 88 + return fromTypeStr(type.asText());
89 - } else if (type.isObject() && type.has("type")) { 89 + } else if (type.isObject() && type.has("type")) {
90 - String typeStr = type.get("type").asText(); 90 + String typeStr = type.get("type").asText();
91 - switch (typeStr) { 91 + switch (typeStr) {
92 - case "boolean": 92 + case "boolean":
93 - return new BooleanBaseType(); 93 + return new BooleanBaseType();
94 - case "integer": 94 + case "integer":
95 - return getIntegerBaseType(type); 95 + return getIntegerBaseType(type);
96 - case "real": 96 + case "real":
97 - return getRealBaseType(type); 97 + return getRealBaseType(type);
98 - case "string": 98 + case "string":
99 - return getStringBaseType(type); 99 + return getStringBaseType(type);
100 - case "uuid": 100 + case "uuid":
101 - return getUuidBaseType(type); 101 + return getUuidBaseType(type);
102 - default: 102 + default:
103 - return null; 103 + return null;
104 - } 104 + }
105 - } 105 + }
106 - return null; 106 + return null;
107 - } 107 + }
108 - 108 +
109 - /** 109 + /**
110 - * Get IntegerBaseType by the type value of JsonNode which contains the 110 + * Get IntegerBaseType by the type value of JsonNode which contains the
111 - * constraints. 111 + * constraints.
112 - * @param type the type value of JsonNode 112 + * @param type the type value of JsonNode
113 - * @return IntegerBaseType 113 + * @return IntegerBaseType
114 - */ 114 + */
115 - private static IntegerBaseType getIntegerBaseType(JsonNode type) { 115 + private static IntegerBaseType getIntegerBaseType(JsonNode type) {
116 - int min = Integer.MIN_VALUE; 116 + int min = Integer.MIN_VALUE;
117 - int max = Integer.MAX_VALUE; 117 + int max = Integer.MAX_VALUE;
118 - Set<Integer> enums = Sets.newHashSet(); 118 + Set<Integer> enums = Sets.newHashSet();
119 - JsonNode node = type.get("minInteger"); 119 + JsonNode node = type.get("minInteger");
120 - if (node != null) { 120 + if (node != null) {
121 - min = node.asInt(); 121 + min = node.asInt();
122 - } 122 + }
123 - node = type.get("maxInteger"); 123 + node = type.get("maxInteger");
124 - if (node != null) { 124 + if (node != null) {
125 - max = node.asInt(); 125 + max = node.asInt();
126 - } 126 + }
127 - if (type.has("enum")) { 127 + if (type.has("enum")) {
128 - JsonNode anEnum = type.get("enum").get(1); 128 + JsonNode anEnum = type.get("enum").get(1);
129 - for (JsonNode n : anEnum) { 129 + for (JsonNode n : anEnum) {
130 - enums.add(n.asInt()); 130 + enums.add(n.asInt());
131 - } 131 + }
132 - } 132 + }
133 - return new IntegerBaseType(min, max, enums); 133 + return new IntegerBaseType(min, max, enums);
134 - } 134 + }
135 - 135 +
136 - /** 136 + /**
137 - * Get RealBaseType by the type value of JsonNode which contains the 137 + * Get RealBaseType by the type value of JsonNode which contains the
138 - * constraints. 138 + * constraints.
139 - * @param type the type value of JsonNode 139 + * @param type the type value of JsonNode
140 - * @return RealBaseType 140 + * @return RealBaseType
141 - */ 141 + */
142 - private static RealBaseType getRealBaseType(JsonNode type) { 142 + private static RealBaseType getRealBaseType(JsonNode type) {
143 - double min = Double.MIN_VALUE; 143 + double min = Double.MIN_VALUE;
144 - double max = Double.MAX_VALUE; 144 + double max = Double.MAX_VALUE;
145 - Set<Double> enums = Sets.newHashSet(); 145 + Set<Double> enums = Sets.newHashSet();
146 - JsonNode node = type.get("minReal"); 146 + JsonNode node = type.get("minReal");
147 - if (node != null) { 147 + if (node != null) {
148 - min = node.asDouble(); 148 + min = node.asDouble();
149 - } 149 + }
150 - node = type.get("maxReal"); 150 + node = type.get("maxReal");
151 - if (node != null) { 151 + if (node != null) {
152 - max = node.asDouble(); 152 + max = node.asDouble();
153 - } 153 + }
154 - if (type.has("enum")) { 154 + if (type.has("enum")) {
155 - JsonNode anEnum = type.get("enum").get(1); 155 + JsonNode anEnum = type.get("enum").get(1);
156 - for (JsonNode n : anEnum) { 156 + for (JsonNode n : anEnum) {
157 - enums.add(n.asDouble()); 157 + enums.add(n.asDouble());
158 - } 158 + }
159 - } 159 + }
160 - return new RealBaseType(min, max, enums); 160 + return new RealBaseType(min, max, enums);
161 - } 161 + }
162 - 162 +
163 - /** 163 + /**
164 - * Get StringBaseType by the type value of JsonNode which contains the 164 + * Get StringBaseType by the type value of JsonNode which contains the
165 - * constraints. 165 + * constraints.
166 - * @param type the type value of JsonNode 166 + * @param type the type value of JsonNode
167 - * @return StringBaseType 167 + * @return StringBaseType
168 - */ 168 + */
169 - private static StringBaseType getStringBaseType(JsonNode type) { 169 + private static StringBaseType getStringBaseType(JsonNode type) {
170 - int minLength = Integer.MIN_VALUE; 170 + int minLength = Integer.MIN_VALUE;
171 - int maxLength = Integer.MAX_VALUE; 171 + int maxLength = Integer.MAX_VALUE;
172 - Set<String> enums = Sets.newHashSet(); 172 + Set<String> enums = Sets.newHashSet();
173 - JsonNode node = type.get("minLength"); 173 + JsonNode node = type.get("minLength");
174 - if (node != null) { 174 + if (node != null) {
175 - minLength = node.asInt(); 175 + minLength = node.asInt();
176 - } 176 + }
177 - node = type.get("maxLength"); 177 + node = type.get("maxLength");
178 - if (node != null) { 178 + if (node != null) {
179 - maxLength = node.asInt(); 179 + maxLength = node.asInt();
180 - } 180 + }
181 - if (type.has("enum")) { 181 + if (type.has("enum")) {
182 - JsonNode enumVal = type.get("enum"); 182 + JsonNode enumVal = type.get("enum");
183 - if (enumVal.isArray()) { 183 + if (enumVal.isArray()) {
184 - JsonNode anEnum = enumVal.get(1); 184 + JsonNode anEnum = enumVal.get(1);
185 - for (JsonNode n : anEnum) { 185 + for (JsonNode n : anEnum) {
186 - enums.add(n.asText()); 186 + enums.add(n.asText());
187 - } 187 + }
188 - } else if (enumVal.isTextual()) { 188 + } else if (enumVal.isTextual()) {
189 - enums.add(enumVal.asText()); 189 + enums.add(enumVal.asText());
190 - } 190 + }
191 - } 191 + }
192 - return new StringBaseType(minLength, maxLength, enums); 192 + return new StringBaseType(minLength, maxLength, enums);
193 - } 193 + }
194 - 194 +
195 - /** 195 + /**
196 - * Get UuidBaseType by the type value of JsonNode which contains the 196 + * Get UuidBaseType by the type value of JsonNode which contains the
197 - * constraints. 197 + * constraints.
198 - * @param type the type value of JsonNode 198 + * @param type the type value of JsonNode
199 - * @return UuidBaseType 199 + * @return UuidBaseType
200 - */ 200 + */
201 - private static UuidBaseType getUuidBaseType(JsonNode type) { 201 + private static UuidBaseType getUuidBaseType(JsonNode type) {
202 - String refTable = null; 202 + String refTable = null;
203 - String refType = RefType.STRONG.refType(); 203 + String refType = RefType.STRONG.refType();
204 - JsonNode node = type.get("refTable"); 204 + JsonNode node = type.get("refTable");
205 - if (node != null) { 205 + if (node != null) {
206 - refTable = node.asText(); 206 + refTable = node.asText();
207 - } 207 + }
208 - node = type.get("refType"); 208 + node = type.get("refType");
209 - if (node != null) { 209 + if (node != null) {
210 - refType = node.asText(); 210 + refType = node.asText();
211 - } 211 + }
212 - return new UuidBaseType(refTable, refType); 212 + return new UuidBaseType(refTable, refType);
213 - } 213 + }
214 -} 214 +}
......
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.schema.type; 16 +package org.onosproject.ovsdb.rfc.schema.type;
17 - 17 +
18 -import org.onosproject.ovsdb.rfc.error.AbnormalJsonNodeException; 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;
22 - 22 +
23 -/** 23 +/**
24 - * ColumnType Factory class. 24 + * ColumnType Factory class.
25 - */ 25 + */
26 -public final class ColumnTypeFactory { 26 +public final class ColumnTypeFactory {
27 - 27 +
28 - /** 28 + /**
29 - * Constructs a ColumnTypeFactory object. This class should not be 29 + * Constructs a ColumnTypeFactory object. This class should not be
30 - * instantiated. 30 + * instantiated.
31 - */ 31 + */
32 - private ColumnTypeFactory() { 32 + private ColumnTypeFactory() {
33 - } 33 + }
34 - 34 +
35 - /** 35 + /**
36 - * Those Json's key/value pairs. 36 + * Those Json's key/value pairs.
37 - */ 37 + */
38 - public enum Type { 38 + public enum Type {
39 - KEY("key"), VALUE("value"); 39 + KEY("key"), VALUE("value");
40 - 40 +
41 - private final String type; 41 + private final String type;
42 - 42 +
43 - private Type(String type) { 43 + private Type(String type) {
44 - this.type = type; 44 + this.type = type;
45 - } 45 + }
46 - 46 +
47 - /** 47 + /**
48 - * Returns the type for Type. 48 + * Returns the type for Type.
49 - * @return the type 49 + * @return the type
50 - */ 50 + */
51 - public String type() { 51 + public String type() {
52 - return type; 52 + return type;
53 - } 53 + }
54 - } 54 + }
55 - 55 +
56 - /** 56 + /**
57 - * JsonNode like 57 + * JsonNode like
58 - * "flow_tables":{"type":{"key":{"maxInteger":254,"minInteger":0,"type": 58 + * "flow_tables":{"type":{"key":{"maxInteger":254,"minInteger":0,"type":
59 - * "integer"},"min":0,"value":{"type":"uuid","refTable":"Flow_Table"},"max": 59 + * "integer"},"min":0,"value":{"type":"uuid","refTable":"Flow_Table"},"max":
60 - * "unlimited"}}. 60 + * "unlimited"}}.
61 - * @param columnTypeJson the ColumnType JsonNode 61 + * @param columnTypeJson the ColumnType JsonNode
62 - * @return ColumnType 62 + * @return ColumnType
63 - */ 63 + */
64 - public static ColumnType getColumnTypeFromJson(JsonNode columnTypeJson) { 64 + public static ColumnType getColumnTypeFromJson(JsonNode columnTypeJson) {
65 - if (!columnTypeJson.isObject() || !columnTypeJson.has(Type.VALUE.type())) { 65 + if (!columnTypeJson.isObject() || !columnTypeJson.has(Type.VALUE.type())) {
66 - return createAtomicColumnType(columnTypeJson); 66 + return createAtomicColumnType(columnTypeJson);
67 - } else if (!columnTypeJson.isValueNode() && columnTypeJson.has(Type.VALUE.type())) { 67 + } else if (!columnTypeJson.isValueNode() && columnTypeJson.has(Type.VALUE.type())) {
68 - return createKeyValuedColumnType(columnTypeJson); 68 + return createKeyValuedColumnType(columnTypeJson);
69 - } 69 + }
70 - String message = "Abnormal ColumnType JsonNode, it should be AtomicColumnType or KeyValuedColumnType" 70 + String message = "Abnormal ColumnType JsonNode, it should be AtomicColumnType or KeyValuedColumnType"
71 - + ObjectMapperUtil.convertToString(columnTypeJson); 71 + + ObjectMapperUtil.convertToString(columnTypeJson);
72 - throw new AbnormalJsonNodeException(message); 72 + throw new AbnormalJsonNodeException(message);
73 - } 73 + }
74 - 74 +
75 - /** 75 + /**
76 - * Create AtomicColumnType entity. 76 + * Create AtomicColumnType entity.
77 - * @param json JsonNode 77 + * @param json JsonNode
78 - * @return AtomicColumnType entity 78 + * @return AtomicColumnType entity
79 - */ 79 + */
80 - private static AtomicColumnType createAtomicColumnType(JsonNode json) { 80 + private static AtomicColumnType createAtomicColumnType(JsonNode json) {
81 - BaseType baseType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type()); 81 + BaseType baseType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type());
82 - int min = 1; 82 + int min = 1;
83 - int max = 1; 83 + int max = 1;
84 - JsonNode node = json.get("min"); 84 + JsonNode node = json.get("min");
85 - if (node != null && node.isNumber()) { 85 + if (node != null && node.isNumber()) {
86 - min = node.asInt(); 86 + min = node.asInt();
87 - } 87 + }
88 - node = json.get("max"); 88 + node = json.get("max");
89 - if (node != null) { 89 + if (node != null) {
90 - if (node.isNumber()) { 90 + if (node.isNumber()) {
91 - max = node.asInt(); 91 + max = node.asInt();
92 - } else if (node.isTextual() && "unlimited".equals(node.asText())) { 92 + } else if (node.isTextual() && "unlimited".equals(node.asText())) {
93 - max = Integer.MAX_VALUE; 93 + max = Integer.MAX_VALUE;
94 - } 94 + }
95 - } 95 + }
96 - return new AtomicColumnType(baseType, min, max); 96 + return new AtomicColumnType(baseType, min, max);
97 - } 97 + }
98 - 98 +
99 - /** 99 + /**
100 - * Create KeyValuedColumnType entity. 100 + * Create KeyValuedColumnType entity.
101 - * @param json JsonNode 101 + * @param json JsonNode
102 - * @return KeyValuedColumnType entity 102 + * @return KeyValuedColumnType entity
103 - */ 103 + */
104 - private static KeyValuedColumnType createKeyValuedColumnType(JsonNode json) { 104 + private static KeyValuedColumnType createKeyValuedColumnType(JsonNode json) {
105 - BaseType keyType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type()); 105 + BaseType keyType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type());
106 - BaseType valueType = BaseTypeFactory.getBaseTypeFromJson(json, Type.VALUE.type()); 106 + BaseType valueType = BaseTypeFactory.getBaseTypeFromJson(json, Type.VALUE.type());
107 - int min = 1; 107 + int min = 1;
108 - int max = 1; 108 + int max = 1;
109 - JsonNode node = json.get("min"); 109 + JsonNode node = json.get("min");
110 - if (node != null && node.isNumber()) { 110 + if (node != null && node.isNumber()) {
111 - min = node.asInt(); 111 + min = node.asInt();
112 - } 112 + }
113 - node = json.get("max"); 113 + node = json.get("max");
114 - if (node != null) { 114 + if (node != null) {
115 - if (node.isNumber()) { 115 + if (node.isNumber()) {
116 - max = node.asInt(); 116 + max = node.asInt();
117 - } else if (node.isTextual() && "unlimited".equals(node.asText())) { 117 + } else if (node.isTextual() && "unlimited".equals(node.asText())) {
118 - max = Integer.MAX_VALUE; 118 + max = Integer.MAX_VALUE;
119 - } 119 + }
120 - } 120 + }
121 - return new KeyValuedColumnType(keyType, valueType, min, max); 121 + return new KeyValuedColumnType(keyType, valueType, min, max);
122 - } 122 + }
123 -} 123 +}
......
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.table; 16 +package org.onosproject.ovsdb.rfc.table;
17 - 17 +
18 -/** 18 +/**
19 - * Ovsdb table name. Refer to RFC7047's Section 9.2. 19 + * Ovsdb table name. Refer to RFC7047's Section 9.2.
20 - */ 20 + */
21 -public enum OvsdbTable { 21 +public enum OvsdbTable {
22 - INTERFACE("Interface"), BRIDGE("Bridge"), CONTROLLER("Controller"), 22 + INTERFACE("Interface"), BRIDGE("Bridge"), CONTROLLER("Controller"),
23 - PORT("Port"), OPENVSWITCH("Open_vSwitch"), FLWTABLE("Flow_Table"), 23 + PORT("Port"), OPENVSWITCH("Open_vSwitch"), FLWTABLE("Flow_Table"),
24 - QOS("Qos"), QUEUE("Queue"), MIRROR("Mirror"), MANAGER("Manager"), 24 + QOS("Qos"), QUEUE("Queue"), MIRROR("Mirror"), MANAGER("Manager"),
25 - NETFLOW("NetFlow"), SSL("SSL"), SFLOW("sFlow"), IPFIX("IPFIX"), 25 + NETFLOW("NetFlow"), SSL("SSL"), SFLOW("sFlow"), IPFIX("IPFIX"),
26 - FLOWSAMPLECOLLECTORSET("Flow_Sample_Collector_Set"); 26 + FLOWSAMPLECOLLECTORSET("Flow_Sample_Collector_Set");
27 - 27 +
28 - private final String tableName; 28 + private final String tableName;
29 - 29 +
30 - private OvsdbTable(String tableName) { 30 + private OvsdbTable(String tableName) {
31 - this.tableName = tableName; 31 + this.tableName = tableName;
32 - } 32 + }
33 - 33 +
34 - /** 34 + /**
35 - * Returns the table name for OvsdbTable. 35 + * Returns the table name for OvsdbTable.
36 - * @return the table name 36 + * @return the table name
37 - */ 37 + */
38 - public String tableName() { 38 + public String tableName() {
39 - return tableName; 39 + return tableName;
40 - } 40 + }
41 -} 41 +}
......
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.table; 16 +package org.onosproject.ovsdb.rfc.table;
17 - 17 +
18 -/** 18 +/**
19 - * The version number of tables and columns. 19 + * The version number of tables and columns.
20 - */ 20 + */
21 -public enum VersionNum { 21 +public enum VersionNum {
22 - VERSION100("1.0.0"), VERSION102("1.0.2"), VERSION103("1.0.3"), 22 + VERSION100("1.0.0"), VERSION102("1.0.2"), VERSION103("1.0.3"),
23 - VERSION104("1.0.4"), VERSION106("1.0.6"), VERSION110("1.1.0"), 23 + VERSION104("1.0.4"), VERSION106("1.0.6"), VERSION110("1.1.0"),
24 - VERSION130("1.3.0"), VERSION200("2.0.0"), VERSION300("3.0.0"), 24 + VERSION130("1.3.0"), VERSION200("2.0.0"), VERSION300("3.0.0"),
25 - VERSION330("3.3.0"), VERSION350("3.5.0"), VERSION400("4.0.0"), 25 + VERSION330("3.3.0"), VERSION350("3.5.0"), VERSION400("4.0.0"),
26 - VERSION510("5.1.0"), VERSION520("5.2.0"), VERSION600("6.0.0"), 26 + VERSION510("5.1.0"), VERSION520("5.2.0"), VERSION600("6.0.0"),
27 - VERSION610("6.1.0"), VERSION620("6.2.0"), VERSION630("6.3.0"), 27 + VERSION610("6.1.0"), VERSION620("6.2.0"), VERSION630("6.3.0"),
28 - VERSION640("6.4.0"), VERSION650("6.5.0"), VERSION660("6.6.0"), 28 + VERSION640("6.4.0"), VERSION650("6.5.0"), VERSION660("6.6.0"),
29 - VERSION670("6.7.0"), VERSION680("6.8.0"), VERSION690("6.9.0"), 29 + VERSION670("6.7.0"), VERSION680("6.8.0"), VERSION690("6.9.0"),
30 - VERSION6100("6.10.0"), VERSION6111("6.11.1"), VERSION710("7.1.0"), 30 + VERSION6100("6.10.0"), VERSION6111("6.11.1"), VERSION710("7.1.0"),
31 - VERSION720("7.2.0"), VERSION721("7.2.1"), VERSION730("7.3.0"), 31 + VERSION720("7.2.0"), VERSION721("7.2.1"), VERSION730("7.3.0"),
32 - VERSION740("7.4.0"), VERSION750("7.5.0"), VERSION770("7.7.0"); 32 + VERSION740("7.4.0"), VERSION750("7.5.0"), VERSION770("7.7.0");
33 - 33 +
34 - private final String versionNum; 34 + private final String versionNum;
35 - 35 +
36 - private VersionNum(String versionNum) { 36 + private VersionNum(String versionNum) {
37 - this.versionNum = versionNum; 37 + this.versionNum = versionNum;
38 - } 38 + }
39 - 39 +
40 - /** 40 + /**
41 - * Returns the version number for VersionNum. 41 + * Returns the version number for VersionNum.
42 - * @return the version number 42 + * @return the version number
43 - */ 43 + */
44 - public String versionNum() { 44 + public String versionNum() {
45 - return versionNum; 45 + return versionNum;
46 - } 46 + }
47 -} 47 +}
......
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.VersionMismatchException; 25 +import org.onosproject.ovsdb.rfc.error.VersionMismatchException;
26 -import org.onosproject.ovsdb.rfc.notation.Column; 26 +import org.onosproject.ovsdb.rfc.notation.Column;
27 -import org.onosproject.ovsdb.rfc.notation.Row; 27 +import org.onosproject.ovsdb.rfc.notation.Row;
28 -import org.onosproject.ovsdb.rfc.notation.UUID; 28 +import org.onosproject.ovsdb.rfc.notation.UUID;
29 -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; 29 +import org.onosproject.ovsdb.rfc.schema.ColumnSchema;
30 -import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 30 +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
31 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 31 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
32 -import org.onosproject.ovsdb.rfc.table.OvsdbTable; 32 +import org.onosproject.ovsdb.rfc.table.OvsdbTable;
33 -import org.onosproject.ovsdb.rfc.table.VersionNum; 33 +import org.onosproject.ovsdb.rfc.table.VersionNum;
34 -import org.onosproject.ovsdb.rfc.utils.VersionUtil; 34 +import org.onosproject.ovsdb.rfc.utils.VersionUtil;
35 - 35 +
36 -/** 36 +/**
37 - * Representation of conversion between Ovsdb table and Row. 37 + * Representation of conversion between Ovsdb table and Row.
38 - */ 38 + */
39 -public abstract class AbstractOvsdbTableService implements OvsdbTableService { 39 +public abstract class AbstractOvsdbTableService implements OvsdbTableService {
40 - 40 +
41 - private final DatabaseSchema dbSchema; 41 + private final DatabaseSchema dbSchema;
42 - private final Row row; 42 + private final Row row;
43 - private final TableDescription tableDesc; 43 + private final TableDescription tableDesc;
44 - 44 +
45 - /** 45 + /**
46 - * Constructs a AbstractOvsdbTableService object. 46 + * Constructs a AbstractOvsdbTableService object.
47 - * @param dbSchema DatabaseSchema entity 47 + * @param dbSchema DatabaseSchema entity
48 - * @param row Row entity 48 + * @param row Row entity
49 - * @param table table name 49 + * @param table table name
50 - * @param formVersion the initial version 50 + * @param formVersion the initial version
51 - */ 51 + */
52 - public AbstractOvsdbTableService(DatabaseSchema dbSchema, Row row, OvsdbTable table, 52 + public AbstractOvsdbTableService(DatabaseSchema dbSchema, Row row, OvsdbTable table,
53 - VersionNum formVersion) { 53 + VersionNum formVersion) {
54 - checkNotNull(dbSchema, "database schema cannot be null"); 54 + checkNotNull(dbSchema, "database schema cannot be null");
55 - checkNotNull(row, "row cannot be null"); 55 + checkNotNull(row, "row cannot be null");
56 - checkNotNull(table, "table cannot be null"); 56 + checkNotNull(table, "table cannot be null");
57 - checkNotNull(formVersion, "the initial version cannot be null"); 57 + checkNotNull(formVersion, "the initial version cannot be null");
58 - this.dbSchema = dbSchema; 58 + this.dbSchema = dbSchema;
59 - row.setTableName(table.tableName()); 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 - } 63 + }
64 - 64 +
65 - /** 65 + /**
66 - * Check whether the parameter of dbSchema is valid and check whether the 66 + * Check whether the parameter of dbSchema is valid and check whether the
67 - * table is existent in Database Schema. 67 + * table is existent in Database Schema.
68 - */ 68 + */
69 - private boolean isValid() { 69 + private boolean isValid() {
70 - if (dbSchema == null) { 70 + if (dbSchema == null) {
71 - return false; 71 + return false;
72 - } 72 + }
73 - if (!dbSchema.name().equalsIgnoreCase(tableDesc.database())) { 73 + if (!dbSchema.name().equalsIgnoreCase(tableDesc.database())) {
74 - return false; 74 + return false;
75 - } 75 + }
76 - checkTableSchemaVersion(); 76 + checkTableSchemaVersion();
77 - return true; 77 + return true;
78 - } 78 + }
79 - 79 +
80 - /** 80 + /**
81 - * Check the table version. 81 + * Check the table version.
82 - */ 82 + */
83 - private void checkTableSchemaVersion() { 83 + private void checkTableSchemaVersion() {
84 - String fromVersion = tableDesc.fromVersion(); 84 + String fromVersion = tableDesc.fromVersion();
85 - String untilVersion = tableDesc.untilVersion(); 85 + String untilVersion = tableDesc.untilVersion();
86 - String schemaVersion = dbSchema.version(); 86 + String schemaVersion = dbSchema.version();
87 - checkVersion(schemaVersion, fromVersion, untilVersion); 87 + checkVersion(schemaVersion, fromVersion, untilVersion);
88 - } 88 + }
89 - 89 +
90 - /** 90 + /**
91 - * Check the column version. 91 + * Check the column version.
92 - * @param columnDesc ColumnDescription entity 92 + * @param columnDesc ColumnDescription entity
93 - */ 93 + */
94 - private void checkColumnSchemaVersion(ColumnDescription columnDesc) { 94 + private void checkColumnSchemaVersion(ColumnDescription columnDesc) {
95 - String fromVersion = columnDesc.fromVersion(); 95 + String fromVersion = columnDesc.fromVersion();
96 - String untilVersion = columnDesc.untilVersion(); 96 + String untilVersion = columnDesc.untilVersion();
97 - String schemaVersion = dbSchema.version(); 97 + String schemaVersion = dbSchema.version();
98 - checkVersion(schemaVersion, fromVersion, untilVersion); 98 + checkVersion(schemaVersion, fromVersion, untilVersion);
99 - } 99 + }
100 - 100 +
101 - /** 101 + /**
102 - * Check whether the DatabaseSchema version between the initial version and 102 + * Check whether the DatabaseSchema version between the initial version and
103 - * the end of the version. 103 + * the end of the version.
104 - * @param schemaVersion DatabaseSchema version 104 + * @param schemaVersion DatabaseSchema version
105 - * @param fromVersion The initial version 105 + * @param fromVersion The initial version
106 - * @param untilVersion The end of the version 106 + * @param untilVersion The end of the version
107 - * @throws VersionMismatchException this is a version mismatch exception 107 + * @throws VersionMismatchException this is a version mismatch exception
108 - */ 108 + */
109 - private void checkVersion(String schemaVersion, String fromVersion, String untilVersion) { 109 + private void checkVersion(String schemaVersion, String fromVersion, String untilVersion) {
110 - VersionUtil.versionMatch(fromVersion); 110 + VersionUtil.versionMatch(fromVersion);
111 - VersionUtil.versionMatch(untilVersion); 111 + VersionUtil.versionMatch(untilVersion);
112 - if (!fromVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) { 112 + if (!fromVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) {
113 - if (VersionUtil.versionCompare(schemaVersion, fromVersion) < 0) { 113 + if (VersionUtil.versionCompare(schemaVersion, fromVersion) < 0) {
114 - String message = VersionMismatchException.createFromMessage(schemaVersion, 114 + String message = VersionMismatchException.createFromMessage(schemaVersion,
115 - fromVersion); 115 + fromVersion);
116 - throw new VersionMismatchException(message); 116 + throw new VersionMismatchException(message);
117 - } 117 + }
118 - } 118 + }
119 - if (!untilVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) { 119 + if (!untilVersion.equals(VersionUtil.DEFAULT_VERSION_STRING)) {
120 - if (VersionUtil.versionCompare(untilVersion, schemaVersion) < 0) { 120 + if (VersionUtil.versionCompare(untilVersion, schemaVersion) < 0) {
121 - String message = VersionMismatchException.createToMessage(schemaVersion, 121 + String message = VersionMismatchException.createToMessage(schemaVersion,
122 - untilVersion); 122 + untilVersion);
123 - throw new VersionMismatchException(message); 123 + throw new VersionMismatchException(message);
124 - } 124 + }
125 - } 125 + }
126 - } 126 + }
127 - 127 +
128 - /** 128 + /**
129 - * Returns TableSchema from dbSchema by table name. 129 + * Returns TableSchema from dbSchema by table name.
130 - * @return TableSchema 130 + * @return TableSchema
131 - */ 131 + */
132 - private TableSchema getTableSchema() { 132 + private TableSchema getTableSchema() {
133 - String tableName = tableDesc.name(); 133 + String tableName = tableDesc.name();
134 - return dbSchema.getTableSchema(tableName); 134 + return dbSchema.getTableSchema(tableName);
135 - } 135 + }
136 - 136 +
137 - /** 137 + /**
138 - * Returns ColumnSchema from TableSchema by column name. 138 + * Returns ColumnSchema from TableSchema by column name.
139 - * @param columnName column name 139 + * @param columnName column name
140 - * @return ColumnSchema 140 + * @return ColumnSchema
141 - */ 141 + */
142 - private ColumnSchema getColumnSchema(String columnName) { 142 + private ColumnSchema getColumnSchema(String columnName) {
143 - TableSchema tableSchema = getTableSchema(); 143 + TableSchema tableSchema = getTableSchema();
144 - if (tableSchema == null) { 144 + if (tableSchema == null) {
145 - String message = TableSchemaNotFoundException.createMessage(tableDesc.name(), 145 + String message = TableSchemaNotFoundException.createMessage(tableDesc.name(),
146 - dbSchema.name()); 146 + dbSchema.name());
147 - throw new TableSchemaNotFoundException(message); 147 + throw new TableSchemaNotFoundException(message);
148 - } 148 + }
149 - ColumnSchema columnSchema = tableSchema.getColumnSchema(columnName); 149 + ColumnSchema columnSchema = tableSchema.getColumnSchema(columnName);
150 - if (columnSchema == null) { 150 + if (columnSchema == null) {
151 - String message = ColumnSchemaNotFoundException.createMessage(columnName, 151 + String message = ColumnSchemaNotFoundException.createMessage(columnName,
152 - tableSchema.name()); 152 + tableSchema.name());
153 - throw new ColumnSchemaNotFoundException(message); 153 + throw new ColumnSchemaNotFoundException(message);
154 - } 154 + }
155 - return columnSchema; 155 + return columnSchema;
156 - } 156 + }
157 - 157 +
158 - @Override 158 + @Override
159 - public Column getColumnHandler(ColumnDescription columnDesc) { 159 + public Column getColumnHandler(ColumnDescription columnDesc) {
160 - if (!isValid()) { 160 + if (!isValid()) {
161 - return null; 161 + return null;
162 - } 162 + }
163 - String columnName = columnDesc.name(); 163 + String columnName = columnDesc.name();
164 - checkColumnSchemaVersion(columnDesc); 164 + checkColumnSchemaVersion(columnDesc);
165 - ColumnSchema columnSchema = getColumnSchema(columnName); 165 + ColumnSchema columnSchema = getColumnSchema(columnName);
166 - if (row == null) { 166 + if (row == null) {
167 - return null; 167 + return null;
168 - } 168 + }
169 - return row.getColumn(columnSchema.name()); 169 + return row.getColumn(columnSchema.name());
170 - } 170 + }
171 - 171 +
172 - @Override 172 + @Override
173 - public Object getDataHandler(ColumnDescription columnDesc) { 173 + public Object getDataHandler(ColumnDescription columnDesc) {
174 - if (!isValid()) { 174 + if (!isValid()) {
175 - return null; 175 + return null;
176 - } 176 + }
177 - String columnName = columnDesc.name(); 177 + String columnName = columnDesc.name();
178 - checkColumnSchemaVersion(columnDesc); 178 + checkColumnSchemaVersion(columnDesc);
179 - ColumnSchema columnSchema = getColumnSchema(columnName); 179 + ColumnSchema columnSchema = getColumnSchema(columnName);
180 - if (row == null || row.getColumn(columnSchema.name()) == null) { 180 + if (row == null || row.getColumn(columnSchema.name()) == null) {
181 - return null; 181 + return null;
182 - } 182 + }
183 - return row.getColumn(columnSchema.name()).data(); 183 + return row.getColumn(columnSchema.name()).data();
184 - } 184 + }
185 - 185 +
186 - @Override 186 + @Override
187 - public void setDataHandler(ColumnDescription columnDesc, Object obj) { 187 + public void setDataHandler(ColumnDescription columnDesc, Object obj) {
188 - if (!isValid()) { 188 + if (!isValid()) {
189 - return; 189 + return;
190 - } 190 + }
191 - String columnName = columnDesc.name(); 191 + String columnName = columnDesc.name();
192 - checkColumnSchemaVersion(columnDesc); 192 + checkColumnSchemaVersion(columnDesc);
193 - ColumnSchema columnSchema = getColumnSchema(columnName); 193 + ColumnSchema columnSchema = getColumnSchema(columnName);
194 - Column column = new Column(columnSchema.name(), obj); 194 + Column column = new Column(columnSchema.name(), obj);
195 - row.addColumn(columnName, column); 195 + row.addColumn(columnName, column);
196 - } 196 + }
197 - 197 +
198 - @Override 198 + @Override
199 - public UUID getTableUuid() { 199 + public UUID getTableUuid() {
200 - if (!isValid()) { 200 + if (!isValid()) {
201 - return null; 201 + return null;
202 - } 202 + }
203 - ColumnDescription columnDesc = new ColumnDescription("_uuid", "getTableUuid"); 203 + ColumnDescription columnDesc = new ColumnDescription("_uuid", "getTableUuid");
204 - return (UUID) getDataHandler(columnDesc); 204 + return (UUID) getDataHandler(columnDesc);
205 - } 205 + }
206 - 206 +
207 - @Override 207 + @Override
208 - public Column getTableUuidColumn() { 208 + public Column getTableUuidColumn() {
209 - if (!isValid()) { 209 + if (!isValid()) {
210 - return null; 210 + return null;
211 - } 211 + }
212 - ColumnDescription columnDesc = new ColumnDescription("_uuid", "getTableUuidColumn"); 212 + ColumnDescription columnDesc = new ColumnDescription("_uuid", "getTableUuidColumn");
213 - return (Column) getColumnHandler(columnDesc); 213 + return (Column) getColumnHandler(columnDesc);
214 - } 214 + }
215 - 215 +
216 - @Override 216 + @Override
217 - public UUID getTableVersion() { 217 + public UUID getTableVersion() {
218 - if (!isValid()) { 218 + if (!isValid()) {
219 - return null; 219 + return null;
220 - } 220 + }
221 - ColumnDescription columnDesc = new ColumnDescription("_version", "getTableVersion"); 221 + ColumnDescription columnDesc = new ColumnDescription("_version", "getTableVersion");
222 - return (UUID) getDataHandler(columnDesc); 222 + return (UUID) getDataHandler(columnDesc);
223 - } 223 + }
224 - 224 +
225 - @Override 225 + @Override
226 - public Column getTableVersionColumn() { 226 + public Column getTableVersionColumn() {
227 - if (!isValid()) { 227 + if (!isValid()) {
228 - return null; 228 + return null;
229 - } 229 + }
230 - ColumnDescription columnDesc = new ColumnDescription("_version", "getTableVersionColumn"); 230 + ColumnDescription columnDesc = new ColumnDescription("_version", "getTableVersionColumn");
231 - return (Column) getColumnHandler(columnDesc); 231 + return (Column) getColumnHandler(columnDesc);
232 - } 232 + }
233 - 233 +
234 - /** 234 + /**
235 - * Get DatabaseSchema entity. 235 + * Get DatabaseSchema entity.
236 - * @return DatabaseSchema entity 236 + * @return DatabaseSchema entity
237 - */ 237 + */
238 - public DatabaseSchema dbSchema() { 238 + public DatabaseSchema dbSchema() {
239 - return dbSchema; 239 + return dbSchema;
240 - } 240 + }
241 - 241 +
242 - /** 242 + /**
243 - * Get Row entity. 243 + * Get Row entity.
244 - * @return Row entity 244 + * @return Row entity
245 - */ 245 + */
246 - public Row getRow() { 246 + public Row getRow() {
247 - if (!isValid()) { 247 + if (!isValid()) {
248 - return null; 248 + return null;
249 - } 249 + }
250 - return this.row; 250 + return this.row;
251 - } 251 + }
252 - 252 +
253 - /** 253 + /**
254 - * Get TableDescription entity. 254 + * Get TableDescription entity.
255 - * @return TableDescription entity 255 + * @return TableDescription entity
256 - */ 256 + */
257 - public TableDescription tableDesc() { 257 + public TableDescription tableDesc() {
258 - return tableDesc; 258 + return tableDesc;
259 - } 259 + }
260 - 260 +
261 - @Override 261 + @Override
262 - public int hashCode() { 262 + public int hashCode() {
263 - return Objects.hash(row); 263 + return Objects.hash(row);
264 - } 264 + }
265 - 265 +
266 - @Override 266 + @Override
267 - public boolean equals(Object obj) { 267 + public boolean equals(Object obj) {
268 - if (this == obj) { 268 + if (this == obj) {
269 - return true; 269 + return true;
270 - } 270 + }
271 - if (obj instanceof AbstractOvsdbTableService) { 271 + if (obj instanceof AbstractOvsdbTableService) {
272 - final AbstractOvsdbTableService other = (AbstractOvsdbTableService) obj; 272 + final AbstractOvsdbTableService other = (AbstractOvsdbTableService) obj;
273 - return Objects.equals(this.row, other.row); 273 + return Objects.equals(this.row, other.row);
274 - } 274 + }
275 - return false; 275 + return false;
276 - } 276 + }
277 - 277 +
278 - @Override 278 + @Override
279 - public String toString() { 279 + public String toString() {
280 - TableSchema schema = (TableSchema) getTableSchema(); 280 + TableSchema schema = (TableSchema) getTableSchema();
281 - String tableName = schema.name(); 281 + String tableName = schema.name();
282 - return toStringHelper(this).add("tableName", tableName).add("row", row).toString(); 282 + return toStringHelper(this).add("tableName", tableName).add("row", row).toString();
283 - } 283 + }
284 -} 284 +}
......
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 UUID which column name is _uuid. 48 + * Returns UUID which column name is _uuid.
49 - * @return UUID 49 + * @return UUID
50 - */ 50 + */
51 - public UUID getTableUuid(); 51 + public UUID getTableUuid();
52 - 52 +
53 - /** 53 + /**
54 - * Returns UUID Column which column name is _uuid. 54 + * Returns UUID Column which column name is _uuid.
55 - * @return UUID Column 55 + * @return UUID Column
56 - */ 56 + */
57 - public Column getTableUuidColumn(); 57 + public Column getTableUuidColumn();
58 - 58 +
59 - /** 59 + /**
60 - * Returns UUID which column name is _version. 60 + * Returns UUID which column name is _version.
61 - * @return UUID 61 + * @return UUID
62 - */ 62 + */
63 - public UUID getTableVersion(); 63 + public UUID getTableVersion();
64 - 64 +
65 - /** 65 + /**
66 - * Returns UUID Column which column name is _version. 66 + * Returns UUID Column which column name is _version.
67 - * @return UUID Column 67 + * @return UUID Column
68 - */ 68 + */
69 - public Column getTableVersionColumn(); 69 + public Column getTableVersionColumn();
70 -} 70 +}
......
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 - 23 +
24 -import org.onosproject.ovsdb.rfc.error.AbnormalJsonNodeException; 24 +import org.onosproject.ovsdb.rfc.error.AbnormalJsonNodeException;
25 -import org.onosproject.ovsdb.rfc.error.UnsupportedException; 25 +import org.onosproject.ovsdb.rfc.error.UnsupportedException;
26 -import org.onosproject.ovsdb.rfc.jsonrpc.Callback; 26 +import org.onosproject.ovsdb.rfc.jsonrpc.Callback;
27 -import org.onosproject.ovsdb.rfc.jsonrpc.JsonRpcResponse; 27 +import org.onosproject.ovsdb.rfc.jsonrpc.JsonRpcResponse;
28 -import org.onosproject.ovsdb.rfc.message.OperationResult; 28 +import org.onosproject.ovsdb.rfc.message.OperationResult;
29 -import org.onosproject.ovsdb.rfc.message.RowUpdate; 29 +import org.onosproject.ovsdb.rfc.message.RowUpdate;
30 -import org.onosproject.ovsdb.rfc.message.TableUpdate; 30 +import org.onosproject.ovsdb.rfc.message.TableUpdate;
31 -import org.onosproject.ovsdb.rfc.message.TableUpdates; 31 +import org.onosproject.ovsdb.rfc.message.TableUpdates;
32 -import org.onosproject.ovsdb.rfc.message.UpdateNotification; 32 +import org.onosproject.ovsdb.rfc.message.UpdateNotification;
33 -import org.onosproject.ovsdb.rfc.notation.Column; 33 +import org.onosproject.ovsdb.rfc.notation.Column;
34 -import org.onosproject.ovsdb.rfc.notation.Row; 34 +import org.onosproject.ovsdb.rfc.notation.Row;
35 -import org.onosproject.ovsdb.rfc.notation.UUID; 35 +import org.onosproject.ovsdb.rfc.notation.UUID;
36 -import org.onosproject.ovsdb.rfc.operations.Operation; 36 +import org.onosproject.ovsdb.rfc.operations.Operation;
37 -import org.onosproject.ovsdb.rfc.schema.ColumnSchema; 37 +import org.onosproject.ovsdb.rfc.schema.ColumnSchema;
38 -import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 38 +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
39 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 39 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
40 -import org.onosproject.ovsdb.rfc.schema.type.ColumnTypeFactory; 40 +import org.onosproject.ovsdb.rfc.schema.type.ColumnTypeFactory;
41 -import org.slf4j.Logger; 41 +import org.slf4j.Logger;
42 -import org.slf4j.LoggerFactory; 42 +import org.slf4j.LoggerFactory;
43 - 43 +
44 -import com.fasterxml.jackson.core.JsonProcessingException; 44 +import com.fasterxml.jackson.core.JsonProcessingException;
45 -import com.fasterxml.jackson.databind.JsonNode; 45 +import com.fasterxml.jackson.databind.JsonNode;
46 -import com.fasterxml.jackson.databind.ObjectMapper; 46 +import com.fasterxml.jackson.databind.ObjectMapper;
47 -import com.google.common.collect.Lists; 47 +import com.google.common.collect.Lists;
48 -import com.google.common.collect.Maps; 48 +import com.google.common.collect.Maps;
49 - 49 +
50 -/** 50 +/**
51 - * JsonNode utility class. convert JsonNode into Object. 51 + * JsonNode utility class. convert JsonNode into Object.
52 - */ 52 + */
53 -public final class FromJsonUtil { 53 +public final class FromJsonUtil {
54 - 54 +
55 - private static final Logger log = LoggerFactory.getLogger(FromJsonUtil.class); 55 + private static final Logger log = LoggerFactory.getLogger(FromJsonUtil.class);
56 - 56 +
57 - /** 57 + /**
58 - * Constructs a FromJsonUtil object. Utility classes should not have a 58 + * Constructs a FromJsonUtil object. Utility classes should not have a
59 - * public or default constructor, otherwise IDE will compile unsuccessfully. 59 + * public or default constructor, otherwise IDE will compile unsuccessfully.
60 - * This class should not be instantiated. 60 + * This class should not be instantiated.
61 - */ 61 + */
62 - private FromJsonUtil() { 62 + private FromJsonUtil() {
63 - } 63 + }
64 - 64 +
65 - /** 65 + /**
66 - * Verify whether the jsonNode is normal. 66 + * Verify whether the jsonNode is normal.
67 - * @param jsonNode JsonNode 67 + * @param jsonNode JsonNode
68 - * @param nodeStr the node name of JsonNode 68 + * @param nodeStr the node name of JsonNode
69 - */ 69 + */
70 - private static void validateJsonNode(JsonNode jsonNode, String nodeStr) { 70 + private static void validateJsonNode(JsonNode jsonNode, String nodeStr) {
71 - if (!jsonNode.isObject() || !jsonNode.has(nodeStr)) { 71 + if (!jsonNode.isObject() || !jsonNode.has(nodeStr)) {
72 - String message = "Abnormal DatabaseSchema JsonNode, it should contain " + nodeStr 72 + String message = "Abnormal DatabaseSchema JsonNode, it should contain " + nodeStr
73 - + " node but was not found"; 73 + + " node but was not found";
74 - throw new AbnormalJsonNodeException(message); 74 + throw new AbnormalJsonNodeException(message);
75 - } 75 + }
76 - } 76 + }
77 - 77 +
78 - /** 78 + /**
79 - * convert JsonNode into DatabaseSchema. 79 + * convert JsonNode into DatabaseSchema.
80 - * @param dbName database name 80 + * @param dbName database name
81 - * @param dbJson the JsonNode of get_schema result 81 + * @param dbJson the JsonNode of get_schema result
82 - * @return DatabaseSchema 82 + * @return DatabaseSchema
83 - * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception 83 + * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception
84 - */ 84 + */
85 - public static DatabaseSchema jsonNodeToDbSchema(String dbName, JsonNode dbJson) { 85 + public static DatabaseSchema jsonNodeToDbSchema(String dbName, JsonNode dbJson) {
86 - validateJsonNode(dbJson, "tables"); 86 + validateJsonNode(dbJson, "tables");
87 - validateJsonNode(dbJson, "version"); 87 + validateJsonNode(dbJson, "version");
88 - String dbVersion = dbJson.get("version").asText(); 88 + String dbVersion = dbJson.get("version").asText();
89 - Map<String, TableSchema> tables = new HashMap<>(); 89 + Map<String, TableSchema> tables = new HashMap<>();
90 - Iterator<Map.Entry<String, JsonNode>> tablesIter = dbJson.get("tables").fields(); 90 + Iterator<Map.Entry<String, JsonNode>> tablesIter = dbJson.get("tables").fields();
91 - while (tablesIter.hasNext()) { 91 + while (tablesIter.hasNext()) {
92 - Map.Entry<String, JsonNode> table = tablesIter.next(); 92 + Map.Entry<String, JsonNode> table = tablesIter.next();
93 - tables.put(table.getKey(), jsonNodeToTableSchema(table.getKey(), table.getValue())); 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 tableJson table JsonNode 101 + * @param tableJson table JsonNode
102 - * @return TableSchema 102 + * @return TableSchema
103 - * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception 103 + * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception
104 - */ 104 + */
105 - private static TableSchema jsonNodeToTableSchema(String tableName, JsonNode tableJson) { 105 + private static TableSchema jsonNodeToTableSchema(String tableName, JsonNode tableJson) {
106 - validateJsonNode(tableJson, "columns"); 106 + validateJsonNode(tableJson, "columns");
107 - Map<String, ColumnSchema> columns = new HashMap<>(); 107 + Map<String, ColumnSchema> columns = new HashMap<>();
108 - Iterator<Map.Entry<String, JsonNode>> columnsIter = tableJson.get("columns").fields(); 108 + Iterator<Map.Entry<String, JsonNode>> columnsIter = tableJson.get("columns").fields();
109 - while (columnsIter.hasNext()) { 109 + while (columnsIter.hasNext()) {
110 - Map.Entry<String, JsonNode> column = columnsIter.next(); 110 + Map.Entry<String, JsonNode> column = columnsIter.next();
111 - columns.put(column.getKey(), jsonNodeToColumnSchema(column.getKey(), column.getValue())); 111 + columns.put(column.getKey(), jsonNodeToColumnSchema(column.getKey(), column.getValue()));
112 - } 112 + }
113 - return new TableSchema(tableName, columns); 113 + return new TableSchema(tableName, columns);
114 - } 114 + }
115 - 115 +
116 - /** 116 + /**
117 - * convert JsonNode into ColumnSchema. 117 + * convert JsonNode into ColumnSchema.
118 - * @param name column name 118 + * @param name column name
119 - * @param columnJson column JsonNode 119 + * @param columnJson column JsonNode
120 - * @return ColumnSchema 120 + * @return ColumnSchema
121 - * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception 121 + * @throws AbnormalJsonNodeException this is an abnormal JsonNode exception
122 - */ 122 + */
123 - private static ColumnSchema jsonNodeToColumnSchema(String name, JsonNode columnJson) { 123 + private static ColumnSchema jsonNodeToColumnSchema(String name, JsonNode columnJson) {
124 - validateJsonNode(columnJson, "type"); 124 + validateJsonNode(columnJson, "type");
125 - return new ColumnSchema(name, ColumnTypeFactory.getColumnTypeFromJson(columnJson 125 + return new ColumnSchema(name, ColumnTypeFactory.getColumnTypeFromJson(columnJson
126 - .get("type"))); 126 + .get("type")));
127 - } 127 + }
128 - 128 +
129 - /** 129 + /**
130 - * convert JsonNode into the returnType of methods in OvsdbRPC class. 130 + * convert JsonNode into the returnType of methods in OvsdbRPC class.
131 - * @param resultJsonNode the result JsonNode 131 + * @param resultJsonNode the result JsonNode
132 - * @param methodName the method name of methods in OvsdbRPC class 132 + * @param methodName the method name of methods in OvsdbRPC class
133 - * @param objectMapper ObjectMapper entity 133 + * @param objectMapper ObjectMapper entity
134 - * @return Object 134 + * @return Object
135 - * @throws UnsupportedException this is an unsupported exception 135 + * @throws UnsupportedException this is an unsupported exception
136 - */ 136 + */
137 - private static Object convertResultType(JsonNode resultJsonNode, String methodName, 137 + private static Object convertResultType(JsonNode resultJsonNode, String methodName,
138 - ObjectMapper objectMapper) { 138 + ObjectMapper objectMapper) {
139 - switch (methodName) { 139 + switch (methodName) {
140 - case "getSchema": 140 + case "getSchema":
141 - case "monitor": 141 + case "monitor":
142 - return resultJsonNode; 142 + return resultJsonNode;
143 - case "echo": 143 + case "echo":
144 - case "listDbs": 144 + case "listDbs":
145 - return objectMapper.convertValue(resultJsonNode, objectMapper.getTypeFactory() 145 + return objectMapper.convertValue(resultJsonNode, objectMapper.getTypeFactory()
146 - .constructParametricType(List.class, String.class)); 146 + .constructParametricType(List.class, String.class));
147 - case "transact": 147 + case "transact":
148 - return objectMapper.convertValue(resultJsonNode, objectMapper.getTypeFactory() 148 + return objectMapper.convertValue(resultJsonNode, objectMapper.getTypeFactory()
149 - .constructParametricType(List.class, JsonNode.class)); 149 + .constructParametricType(List.class, JsonNode.class));
150 - default: 150 + default:
151 - throw new UnsupportedException("does not support this rpc method" + methodName); 151 + throw new UnsupportedException("does not support this rpc method" + methodName);
152 - } 152 + }
153 - } 153 + }
154 - 154 +
155 - /** 155 + /**
156 - * convert JsonNode into the returnType of methods in OvsdbRPC class. 156 + * convert JsonNode into the returnType of methods in OvsdbRPC class.
157 - * @param jsonNode the result JsonNode 157 + * @param jsonNode the result JsonNode
158 - * @param methodName the method name of methods in OvsdbRPC class 158 + * @param methodName the method name of methods in OvsdbRPC class
159 - * @return Object 159 + * @return Object
160 - */ 160 + */
161 - public static Object jsonResultParser(JsonNode jsonNode, String methodName) { 161 + public static Object jsonResultParser(JsonNode jsonNode, String methodName) {
162 - ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); 162 + ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper();
163 - JsonNode error = jsonNode.get("error"); 163 + JsonNode error = jsonNode.get("error");
164 - if (error != null && !error.isNull()) { 164 + if (error != null && !error.isNull()) {
165 - log.error("jsonRpcResponse error : {}", error.toString()); 165 + log.error("jsonRpcResponse error : {}", error.toString());
166 - } 166 + }
167 - JsonNode resultJsonNode = jsonNode.get("result"); 167 + JsonNode resultJsonNode = jsonNode.get("result");
168 - Object result = convertResultType(resultJsonNode, methodName, objectMapper); 168 + Object result = convertResultType(resultJsonNode, methodName, objectMapper);
169 - return result; 169 + return result;
170 - } 170 + }
171 - 171 +
172 - /** 172 + /**
173 - * When monitor the ovsdb tables, if a table update, ovs send update 173 + * When monitor the ovsdb tables, if a table update, ovs send update
174 - * notification, then call callback function. 174 + * notification, then call callback function.
175 - * @param jsonNode the result JsonNode 175 + * @param jsonNode the result JsonNode
176 - * @param callback the callback function 176 + * @param callback the callback function
177 - * @throws UnsupportedException this is an unsupported exception 177 + * @throws UnsupportedException this is an unsupported exception
178 - */ 178 + */
179 - public static void jsonCallbackRequestParser(JsonNode jsonNode, Callback callback) { 179 + public static void jsonCallbackRequestParser(JsonNode jsonNode, Callback callback) {
180 - ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); 180 + ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper();
181 - JsonNode params = jsonNode.get("params"); 181 + JsonNode params = jsonNode.get("params");
182 - Object param = null; 182 + Object param = null;
183 - String methodName = jsonNode.get("method").asText(); 183 + String methodName = jsonNode.get("method").asText();
184 - switch (methodName) { 184 + switch (methodName) {
185 - case "update": 185 + case "update":
186 - param = objectMapper.convertValue(params, UpdateNotification.class); 186 + param = objectMapper.convertValue(params, UpdateNotification.class);
187 - callback.update((UpdateNotification) param); 187 + callback.update((UpdateNotification) param);
188 - break; 188 + break;
189 - default: 189 + default:
190 - throw new UnsupportedException("does not support this callback method: " + methodName); 190 + throw new UnsupportedException("does not support this callback method: " + methodName);
191 - } 191 + }
192 - } 192 + }
193 - 193 +
194 - /** 194 + /**
195 - * Ovs send echo request to keep the heart, need we return echo result. 195 + * Ovs send echo request to keep the heart, need we return echo result.
196 - * @param jsonNode the result JsonNode 196 + * @param jsonNode the result JsonNode
197 - * @return JsonRpcResponse String 197 + * @return JsonRpcResponse String
198 - */ 198 + */
199 - public static String getEchoRequestStr(JsonNode jsonNode) { 199 + public static String getEchoRequestStr(JsonNode jsonNode) {
200 - ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(); 200 + ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper();
201 - String str = null; 201 + String str = null;
202 - if (jsonNode.get("method").asText().equals("echo")) { 202 + if (jsonNode.get("method").asText().equals("echo")) {
203 - JsonRpcResponse response = new JsonRpcResponse(jsonNode.get("id").asText()); 203 + JsonRpcResponse response = new JsonRpcResponse(jsonNode.get("id").asText());
204 - try { 204 + try {
205 - str = objectMapper.writeValueAsString(response); 205 + str = objectMapper.writeValueAsString(response);
206 - } catch (JsonProcessingException e) { 206 + } catch (JsonProcessingException e) {
207 - log.error("JsonProcessingException while converting JsonNode into string: ", e); 207 + log.error("JsonProcessingException while converting JsonNode into string: ", e);
208 - } 208 + }
209 - } 209 + }
210 - return str; 210 + return str;
211 - } 211 + }
212 - 212 +
213 - /** 213 + /**
214 - * Convert the List of Operation result into List of OperationResult . 214 + * Convert the List of Operation result into List of OperationResult .
215 - * @param input the List of JsonNode 215 + * @param input the List of JsonNode
216 - * @param operations the List of Operation 216 + * @param operations the List of Operation
217 - * @return the List of OperationResult 217 + * @return the List of OperationResult
218 - */ 218 + */
219 - public static List<OperationResult> jsonNodeToOperationResult(List<JsonNode> input, 219 + public static List<OperationResult> jsonNodeToOperationResult(List<JsonNode> input,
220 - List<Operation> operations) { 220 + List<Operation> operations) {
221 - ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(false); 221 + ObjectMapper objectMapper = ObjectMapperUtil.getObjectMapper(false);
222 - List<OperationResult> operationResults = new ArrayList<OperationResult>(); 222 + List<OperationResult> operationResults = new ArrayList<OperationResult>();
223 - for (int i = 0; i < input.size(); i++) { 223 + for (int i = 0; i < input.size(); i++) {
224 - JsonNode jsonNode = input.get(i); 224 + JsonNode jsonNode = input.get(i);
225 - Operation operation = operations.get(i); 225 + Operation operation = operations.get(i);
226 - if (jsonNode != null && jsonNode.size() > 0) { 226 + if (jsonNode != null && jsonNode.size() > 0) {
227 - if (i >= operations.size() || operation.getOp() != "select") { 227 + if (i >= operations.size() || operation.getOp() != "select") {
228 - OperationResult or = objectMapper.convertValue(jsonNode, OperationResult.class); 228 + OperationResult or = objectMapper.convertValue(jsonNode, OperationResult.class);
229 - operationResults.add(or); 229 + operationResults.add(or);
230 - } else { 230 + } else {
231 - List<Row> rows = createRows(operation.getTableSchema(), jsonNode); 231 + List<Row> rows = createRows(operation.getTableSchema(), jsonNode);
232 - OperationResult or = new OperationResult(rows); 232 + OperationResult or = new OperationResult(rows);
233 - operationResults.add(or); 233 + operationResults.add(or);
234 - } 234 + }
235 - } 235 + }
236 - } 236 + }
237 - return operationResults; 237 + return operationResults;
238 - } 238 + }
239 - 239 +
240 - /** 240 + /**
241 - * Convert Operation JsonNode into Rows. 241 + * Convert Operation JsonNode into Rows.
242 - * @param tableSchema TableSchema entity 242 + * @param tableSchema TableSchema entity
243 - * @param rowsNode JsonNode 243 + * @param rowsNode JsonNode
244 - * @return ArrayList<Row> the List of Row 244 + * @return ArrayList<Row> the List of Row
245 - */ 245 + */
246 - private static ArrayList<Row> createRows(TableSchema tableSchema, JsonNode rowsNode) { 246 + private static ArrayList<Row> createRows(TableSchema tableSchema, JsonNode rowsNode) {
247 - validateJsonNode(rowsNode, "rows"); 247 + validateJsonNode(rowsNode, "rows");
248 - ArrayList<Row> rows = Lists.newArrayList(); 248 + ArrayList<Row> rows = Lists.newArrayList();
249 - for (JsonNode rowNode : rowsNode.get("rows")) { 249 + for (JsonNode rowNode : rowsNode.get("rows")) {
250 - rows.add(createRow(tableSchema, rowNode)); 250 + rows.add(createRow(tableSchema, rowNode));
251 - } 251 + }
252 - return rows; 252 + return rows;
253 - } 253 + }
254 - 254 +
255 - /** 255 + /**
256 - * convert the params of Update Notification into TableUpdates. 256 + * convert the params of Update Notification into TableUpdates.
257 - * @param updatesJson the params of Update Notification 257 + * @param updatesJson the params of Update Notification
258 - * @param dbSchema DatabaseSchema entity 258 + * @param dbSchema DatabaseSchema entity
259 - * @return TableUpdates 259 + * @return TableUpdates
260 - */ 260 + */
261 - public static TableUpdates jsonNodeToTableUpdates(JsonNode updatesJson, DatabaseSchema dbSchema) { 261 + public static TableUpdates jsonNodeToTableUpdates(JsonNode updatesJson, DatabaseSchema dbSchema) {
262 - Map<String, TableUpdate> tableUpdateMap = Maps.newHashMap(); 262 + Map<String, TableUpdate> tableUpdateMap = Maps.newHashMap();
263 - Iterator<Map.Entry<String, JsonNode>> tableUpdatesItr = updatesJson.fields(); 263 + Iterator<Map.Entry<String, JsonNode>> tableUpdatesItr = updatesJson.fields();
264 - while (tableUpdatesItr.hasNext()) { 264 + while (tableUpdatesItr.hasNext()) {
265 - Map.Entry<String, JsonNode> entry = tableUpdatesItr.next(); 265 + Map.Entry<String, JsonNode> entry = tableUpdatesItr.next();
266 - TableSchema tableSchema = dbSchema.getTableSchema(entry.getKey()); 266 + TableSchema tableSchema = dbSchema.getTableSchema(entry.getKey());
267 - TableUpdate tableUpdate = jsonNodeToTableUpdate(tableSchema, entry.getValue()); 267 + TableUpdate tableUpdate = jsonNodeToTableUpdate(tableSchema, entry.getValue());
268 - tableUpdateMap.put(entry.getKey(), tableUpdate); 268 + tableUpdateMap.put(entry.getKey(), tableUpdate);
269 - } 269 + }
270 - return TableUpdates.tableUpdates(tableUpdateMap); 270 + return TableUpdates.tableUpdates(tableUpdateMap);
271 - } 271 + }
272 - 272 +
273 - /** 273 + /**
274 - * convert the params of Update Notification into TableUpdate. 274 + * convert the params of Update Notification into TableUpdate.
275 - * @param tableSchema TableSchema entity 275 + * @param tableSchema TableSchema entity
276 - * @param updateJson the table-update in params of Update Notification 276 + * @param updateJson the table-update in params of Update Notification
277 - * @return TableUpdate 277 + * @return TableUpdate
278 - */ 278 + */
279 - public static TableUpdate jsonNodeToTableUpdate(TableSchema tableSchema, JsonNode updateJson) { 279 + public static TableUpdate jsonNodeToTableUpdate(TableSchema tableSchema, JsonNode updateJson) {
280 - Map<UUID, RowUpdate> rows = Maps.newHashMap(); 280 + Map<UUID, RowUpdate> rows = Maps.newHashMap();
281 - Iterator<Map.Entry<String, JsonNode>> tableUpdateItr = updateJson.fields(); 281 + Iterator<Map.Entry<String, JsonNode>> tableUpdateItr = updateJson.fields();
282 - while (tableUpdateItr.hasNext()) { 282 + while (tableUpdateItr.hasNext()) {
283 - Map.Entry<String, JsonNode> oldNewRow = tableUpdateItr.next(); 283 + Map.Entry<String, JsonNode> oldNewRow = tableUpdateItr.next();
284 - String uuidStr = oldNewRow.getKey(); 284 + String uuidStr = oldNewRow.getKey();
285 - UUID uuid = UUID.uuid(uuidStr); 285 + UUID uuid = UUID.uuid(uuidStr);
286 - JsonNode newR = oldNewRow.getValue().get("new"); 286 + JsonNode newR = oldNewRow.getValue().get("new");
287 - JsonNode oldR = oldNewRow.getValue().get("old"); 287 + JsonNode oldR = oldNewRow.getValue().get("old");
288 - Row newRow = newR != null ? createRow(tableSchema, newR) : null; 288 + Row newRow = newR != null ? createRow(tableSchema, newR) : null;
289 - Row oldRow = oldR != null ? createRow(tableSchema, oldR) : null; 289 + Row oldRow = oldR != null ? createRow(tableSchema, oldR) : null;
290 - RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow); 290 + RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow);
291 - rows.put(uuid, rowUpdate); 291 + rows.put(uuid, rowUpdate);
292 - } 292 + }
293 - return TableUpdate.tableUpdate(rows); 293 + return TableUpdate.tableUpdate(rows);
294 - } 294 + }
295 - 295 +
296 - /** 296 + /**
297 - * Convert Operation JsonNode into Row. 297 + * Convert Operation JsonNode into Row.
298 - * @param tableSchema TableSchema entity 298 + * @param tableSchema TableSchema entity
299 - * @param rowNode JsonNode 299 + * @param rowNode JsonNode
300 - * @return Row 300 + * @return Row
301 - */ 301 + */
302 - private static Row createRow(TableSchema tableSchema, JsonNode rowNode) { 302 + private static Row createRow(TableSchema tableSchema, JsonNode rowNode) {
303 - if (tableSchema == null) { 303 + if (tableSchema == null) {
304 - return null; 304 + return null;
305 - } 305 + }
306 - Map<String, Column> columns = Maps.newHashMap(); 306 + Map<String, Column> columns = Maps.newHashMap();
307 - Iterator<Map.Entry<String, JsonNode>> rowIter = rowNode.fields(); 307 + Iterator<Map.Entry<String, JsonNode>> rowIter = rowNode.fields();
308 - while (rowIter.hasNext()) { 308 + while (rowIter.hasNext()) {
309 - Map.Entry<String, JsonNode> next = rowIter.next(); 309 + Map.Entry<String, JsonNode> next = rowIter.next();
310 - ColumnSchema columnSchema = tableSchema.getColumnSchema(next.getKey()); 310 + ColumnSchema columnSchema = tableSchema.getColumnSchema(next.getKey());
311 - if (columnSchema != null) { 311 + if (columnSchema != null) {
312 - String columnName = columnSchema.name(); 312 + String columnName = columnSchema.name();
313 - Object obj = TransValueUtil.getValueFromJson(next.getValue(), columnSchema.type()); 313 + Object obj = TransValueUtil.getValueFromJson(next.getValue(), columnSchema.type());
314 - columns.put(columnName, new Column(columnName, obj)); 314 + columns.put(columnName, new Column(columnName, obj));
315 - } 315 + }
316 - } 316 + }
317 - return new Row(tableSchema.name(), columns); 317 + return new Row(tableSchema.name(), columns);
318 - } 318 + }
319 - 319 +
320 -} 320 +}
......
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.UnsupportedException; 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, JsonReadContext jrContext) 58 + public static void readToJsonNode(ByteBuf in, List<Object> out, JsonReadContext jrContext)
59 - throws JsonParseException, IOException { 59 + throws JsonParseException, IOException {
60 - int lastReadBytes = jrContext.getLastReadBytes(); 60 + int lastReadBytes = jrContext.getLastReadBytes();
61 - if (lastReadBytes == 0) { 61 + if (lastReadBytes == 0) {
62 - if (in.readableBytes() < 4) { 62 + if (in.readableBytes() < 4) {
63 - return; 63 + return;
64 - } 64 + }
65 - checkEncoding(in); 65 + checkEncoding(in);
66 - } 66 + }
67 - 67 +
68 - int i = lastReadBytes + in.readerIndex(); 68 + int i = lastReadBytes + in.readerIndex();
69 - Stack<Byte> bufStack = jrContext.getBufStack(); 69 + Stack<Byte> bufStack = jrContext.getBufStack();
70 - for (; i < in.writerIndex(); i++) { 70 + for (; i < in.writerIndex(); i++) {
71 - byte b = in.getByte(i); 71 + byte b = in.getByte(i);
72 - switch (b) { 72 + switch (b) {
73 - case '{': 73 + case '{':
74 - if (!isDoubleQuote(bufStack)) { 74 + if (!isDoubleQuote(bufStack)) {
75 - bufStack.push(b); 75 + bufStack.push(b);
76 - jrContext.setStartMatch(true); 76 + jrContext.setStartMatch(true);
77 - } 77 + }
78 - break; 78 + break;
79 - case '}': 79 + case '}':
80 - if (!isDoubleQuote(bufStack)) { 80 + if (!isDoubleQuote(bufStack)) {
81 - bufStack.pop(); 81 + bufStack.pop();
82 - } 82 + }
83 - break; 83 + break;
84 - case '"': 84 + case '"':
85 - if (in.getByte(i - 1) != '\\') { 85 + if (in.getByte(i - 1) != '\\') {
86 - if (!bufStack.isEmpty() && bufStack.peek() != '"') { 86 + if (!bufStack.isEmpty() && bufStack.peek() != '"') {
87 - bufStack.push(b); 87 + bufStack.push(b);
88 - } else { 88 + } else {
89 - bufStack.pop(); 89 + bufStack.pop();
90 - } 90 + }
91 - } 91 + }
92 - break; 92 + break;
93 - default: 93 + default:
94 - break; 94 + break;
95 - } 95 + }
96 - 96 +
97 - if (jrContext.isStartMatch() && bufStack.isEmpty()) { 97 + if (jrContext.isStartMatch() && bufStack.isEmpty()) {
98 - ByteBuf buf = in.readSlice(i - in.readerIndex() + 1); 98 + ByteBuf buf = in.readSlice(i - in.readerIndex() + 1);
99 - JsonParser jf = new MappingJsonFactory().createParser(new ByteBufInputStream(buf)); 99 + JsonParser jf = new MappingJsonFactory().createParser(new ByteBufInputStream(buf));
100 - JsonNode jsonNode = jf.readValueAsTree(); 100 + JsonNode jsonNode = jf.readValueAsTree();
101 - out.add(jsonNode); 101 + out.add(jsonNode);
102 - lastReadBytes = 0; 102 + lastReadBytes = 0;
103 - jrContext.setLastReadBytes(lastReadBytes); 103 + jrContext.setLastReadBytes(lastReadBytes);
104 - break; 104 + break;
105 - } 105 + }
106 - } 106 + }
107 - 107 +
108 - if (i >= in.writerIndex()) { 108 + if (i >= in.writerIndex()) {
109 - lastReadBytes = in.readableBytes(); 109 + lastReadBytes = in.readableBytes();
110 - jrContext.setLastReadBytes(lastReadBytes); 110 + jrContext.setLastReadBytes(lastReadBytes);
111 - } 111 + }
112 - } 112 + }
113 - 113 +
114 - /** 114 + /**
115 - * Filter the invalid characters before decoding. 115 + * Filter the invalid characters before decoding.
116 - * @param in input of bytes 116 + * @param in input of bytes
117 - * @param lastReadBytes the bytes for last decoding incomplete record 117 + * @param lastReadBytes the bytes for last decoding incomplete record
118 - */ 118 + */
119 - private static void fliterCharaters(ByteBuf in) { 119 + private static void fliterCharaters(ByteBuf in) {
120 - while (in.isReadable()) { 120 + while (in.isReadable()) {
121 - int ch = in.getByte(in.readerIndex()); 121 + int ch = in.getByte(in.readerIndex());
122 - if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) { 122 + if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) {
123 - break; 123 + break;
124 - } else { 124 + } else {
125 - in.readByte(); 125 + in.readByte();
126 - } 126 + }
127 - } 127 + }
128 - } 128 + }
129 - 129 +
130 - /** 130 + /**
131 - * Check whether the peek of the stack element is double quote. 131 + * Check whether the peek of the stack element is double quote.
132 - * @param jrContext context for the last decoding process 132 + * @param jrContext context for the last decoding process
133 - * @return boolean 133 + * @return boolean
134 - */ 134 + */
135 - private static boolean isDoubleQuote(Stack<Byte> bufStack) { 135 + private static boolean isDoubleQuote(Stack<Byte> bufStack) {
136 - if (!bufStack.isEmpty() && bufStack.peek() == '"') { 136 + if (!bufStack.isEmpty() && bufStack.peek() == '"') {
137 - return true; 137 + return true;
138 - } 138 + }
139 - return false; 139 + return false;
140 - } 140 + }
141 - 141 +
142 - /** 142 + /**
143 - * Check whether the encoding is valid. 143 + * Check whether the encoding is valid.
144 - * @param in input of bytes 144 + * @param in input of bytes
145 - * @throws IOException this is an IO exception 145 + * @throws IOException this is an IO exception
146 - * @throws UnsupportedException this is an unsupported exception 146 + * @throws UnsupportedException this is an unsupported exception
147 - */ 147 + */
148 - private static void checkEncoding(ByteBuf in) throws IOException { 148 + private static void checkEncoding(ByteBuf in) throws IOException {
149 - int inputStart = 0; 149 + int inputStart = 0;
150 - int inputLength = 4; 150 + int inputLength = 4;
151 - fliterCharaters(in); 151 + fliterCharaters(in);
152 - byte[] buff = new byte[4]; 152 + byte[] buff = new byte[4];
153 - in.getBytes(in.readerIndex(), buff); 153 + in.getBytes(in.readerIndex(), buff);
154 - ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(new IOContext(new BufferRecycler(), 154 + ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(new IOContext(new BufferRecycler(),
155 - null, 155 + null,
156 - false), 156 + false),
157 - buff, inputStart, 157 + buff, inputStart,
158 - inputLength); 158 + inputLength);
159 - JsonEncoding jsonEncoding = strapper.detectEncoding(); 159 + JsonEncoding jsonEncoding = strapper.detectEncoding();
160 - if (!JsonEncoding.UTF8.equals(jsonEncoding)) { 160 + if (!JsonEncoding.UTF8.equals(jsonEncoding)) {
161 - throw new UnsupportedException("Only UTF-8 encoding is supported."); 161 + throw new UnsupportedException("Only UTF-8 encoding is supported.");
162 - } 162 + }
163 - } 163 + }
164 - 164 +
165 -} 165 +}
......
1 -package org.onosproject.ovsdb.rfc.utils; 1 +package org.onosproject.ovsdb.rfc.utils;
2 - 2 +
3 -import org.onosproject.ovsdb.rfc.notation.Mutation; 3 +import org.onosproject.ovsdb.rfc.notation.Mutation;
4 -import org.onosproject.ovsdb.rfc.notation.Mutation.Mutator; 4 +import org.onosproject.ovsdb.rfc.notation.Mutation.Mutator;
5 - 5 +
6 -public final class MutationUtil { 6 +public final class MutationUtil {
7 - 7 +
8 - /** 8 + /**
9 - * Constructs a MutationUtil object. Utility classes should not have a 9 + * Constructs a MutationUtil object. Utility classes should not have a
10 - * public or default constructor, otherwise IDE will compile unsuccessfully. This 10 + * public or default constructor, otherwise IDE will compile unsuccessfully. This
11 - * class should not be instantiated. 11 + * class should not be instantiated.
12 - */ 12 + */
13 - private MutationUtil() { 13 + private MutationUtil() {
14 - } 14 + }
15 - 15 +
16 - /** 16 + /**
17 - * Returns a Mutation that means += . 17 + * Returns a Mutation that means += .
18 - * @param columnName column name 18 + * @param columnName column name
19 - * @param data column value 19 + * @param data column value
20 - * @return Mutation 20 + * @return Mutation
21 - */ 21 + */
22 - public static Mutation sum(String columnName, Object data) { 22 + public static Mutation sum(String columnName, Object data) {
23 - Object value = TransValueUtil.getFormatData(data); 23 + Object value = TransValueUtil.getFormatData(data);
24 - return new Mutation(columnName, Mutator.SUM, value); 24 + return new Mutation(columnName, Mutator.SUM, value);
25 - } 25 + }
26 - 26 +
27 - /** 27 + /**
28 - * Returns a Mutation that means -= . 28 + * Returns a Mutation that means -= .
29 - * @param columnName column name 29 + * @param columnName column name
30 - * @param data column value 30 + * @param data column value
31 - * @return Mutation 31 + * @return Mutation
32 - */ 32 + */
33 - public static Mutation difference(String columnName, Object data) { 33 + public static Mutation difference(String columnName, Object data) {
34 - Object value = TransValueUtil.getFormatData(data); 34 + Object value = TransValueUtil.getFormatData(data);
35 - return new Mutation(columnName, Mutator.DIFFERENCE, value); 35 + return new Mutation(columnName, Mutator.DIFFERENCE, value);
36 - } 36 + }
37 - 37 +
38 - /** 38 + /**
39 - * Returns a Mutation that means *= . 39 + * Returns a Mutation that means *= .
40 - * @param columnName column name 40 + * @param columnName column name
41 - * @param data column value 41 + * @param data column value
42 - * @return Mutation 42 + * @return Mutation
43 - */ 43 + */
44 - public static Mutation product(String columnName, Object data) { 44 + public static Mutation product(String columnName, Object data) {
45 - Object value = TransValueUtil.getFormatData(data); 45 + Object value = TransValueUtil.getFormatData(data);
46 - return new Mutation(columnName, Mutator.PRODUCT, value); 46 + return new Mutation(columnName, Mutator.PRODUCT, value);
47 - } 47 + }
48 - 48 +
49 - /** 49 + /**
50 - * Returns a Mutation that means /= . 50 + * Returns a Mutation that means /= .
51 - * @param columnName column name 51 + * @param columnName column name
52 - * @param data column value 52 + * @param data column value
53 - * @return Mutation 53 + * @return Mutation
54 - */ 54 + */
55 - public static Mutation quotient(String columnName, Object data) { 55 + public static Mutation quotient(String columnName, Object data) {
56 - Object value = TransValueUtil.getFormatData(data); 56 + Object value = TransValueUtil.getFormatData(data);
57 - return new Mutation(columnName, Mutator.QUOTIENT, value); 57 + return new Mutation(columnName, Mutator.QUOTIENT, value);
58 - } 58 + }
59 - 59 +
60 - /** 60 + /**
61 - * Returns a Mutation that means %= . 61 + * Returns a Mutation that means %= .
62 - * @param columnName column name 62 + * @param columnName column name
63 - * @param data column value 63 + * @param data column value
64 - * @return Mutation 64 + * @return Mutation
65 - */ 65 + */
66 - public static Mutation remainder(String columnName, Object data) { 66 + public static Mutation remainder(String columnName, Object data) {
67 - Object value = TransValueUtil.getFormatData(data); 67 + Object value = TransValueUtil.getFormatData(data);
68 - return new Mutation(columnName, Mutator.REMAINDER, value); 68 + return new Mutation(columnName, Mutator.REMAINDER, value);
69 - } 69 + }
70 - 70 +
71 - /** 71 + /**
72 - * Returns a Mutation that means insert . 72 + * Returns a Mutation that means insert .
73 - * @param columnName column name 73 + * @param columnName column name
74 - * @param data column value 74 + * @param data column value
75 - * @return Mutation 75 + * @return Mutation
76 - */ 76 + */
77 - public static Mutation insert(String columnName, Object data) { 77 + public static Mutation insert(String columnName, Object data) {
78 - Object value = TransValueUtil.getFormatData(data); 78 + Object value = TransValueUtil.getFormatData(data);
79 - return new Mutation(columnName, Mutator.INSERT, value); 79 + return new Mutation(columnName, Mutator.INSERT, value);
80 - } 80 + }
81 - 81 +
82 - /** 82 + /**
83 - * Returns a Mutation that means delete . 83 + * Returns a Mutation that means delete .
84 - * @param columnName column name 84 + * @param columnName column name
85 - * @param data column value 85 + * @param data column value
86 - * @return Mutation 86 + * @return Mutation
87 - */ 87 + */
88 - public static Mutation delete(String columnName, Object data) { 88 + public static Mutation delete(String columnName, Object data) {
89 - Object value = TransValueUtil.getFormatData(data); 89 + Object value = TransValueUtil.getFormatData(data);
90 - return new Mutation(columnName, Mutator.DELETE, value); 90 + return new Mutation(columnName, Mutator.DELETE, value);
91 - } 91 + }
92 -} 92 +}
......
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.Map; 19 +import java.util.Map;
20 -import java.util.Set; 20 +import java.util.Set;
21 - 21 +
22 -import org.onosproject.ovsdb.rfc.message.MonitorRequest; 22 +import org.onosproject.ovsdb.rfc.message.MonitorRequest;
23 -import org.onosproject.ovsdb.rfc.message.MonitorSelect; 23 +import org.onosproject.ovsdb.rfc.message.MonitorSelect;
24 -import org.onosproject.ovsdb.rfc.operations.Operation; 24 +import org.onosproject.ovsdb.rfc.operations.Operation;
25 -import org.onosproject.ovsdb.rfc.schema.DatabaseSchema; 25 +import org.onosproject.ovsdb.rfc.schema.DatabaseSchema;
26 -import org.onosproject.ovsdb.rfc.schema.TableSchema; 26 +import org.onosproject.ovsdb.rfc.schema.TableSchema;
27 - 27 +
28 -import com.google.common.collect.Lists; 28 +import com.google.common.collect.Lists;
29 -import com.google.common.collect.Maps; 29 +import com.google.common.collect.Maps;
30 - 30 +
31 -/** 31 +/**
32 - * Params utility class. Params of the request object, refer to RFC7047's 32 + * Params utility class. Params of the request object, refer to RFC7047's
33 - * Section 4.1. 33 + * Section 4.1.
34 - */ 34 + */
35 -public final class ParamUtil { 35 +public final class ParamUtil {
36 - 36 +
37 - /** 37 + /**
38 - * Constructs a ParamUtil object. Utility classes should not have a public 38 + * Constructs a ParamUtil object. Utility classes should not have a public
39 - * or default constructor, otherwise IDE will compile unsuccessfully. This 39 + * or default constructor, otherwise IDE will compile unsuccessfully. This
40 - * class should not be instantiated. 40 + * class should not be instantiated.
41 - */ 41 + */
42 - private ParamUtil() { 42 + private ParamUtil() {
43 - } 43 + }
44 - 44 +
45 - /** 45 + /**
46 - * Returns MonitorRequest, refer to RFC7047's Section 4.1.5. 46 + * Returns MonitorRequest, refer to RFC7047's Section 4.1.5.
47 - * @param tableSchema entity 47 + * @param tableSchema entity
48 - * @return MonitorRequest 48 + * @return MonitorRequest
49 - */ 49 + */
50 - private static MonitorRequest getAllColumnsMonitorRequest(TableSchema tableSchema) { 50 + private static MonitorRequest getAllColumnsMonitorRequest(TableSchema tableSchema) {
51 - String tableName = tableSchema.name(); 51 + String tableName = tableSchema.name();
52 - Set<String> columns = tableSchema.getColumnNames(); 52 + Set<String> columns = tableSchema.getColumnNames();
53 - MonitorSelect select = new MonitorSelect(true, true, true, true); 53 + MonitorSelect select = new MonitorSelect(true, true, true, true);
54 - MonitorRequest monitorRequest = new MonitorRequest(tableName, columns, select); 54 + MonitorRequest monitorRequest = new MonitorRequest(tableName, columns, select);
55 - return monitorRequest; 55 + return monitorRequest;
56 - } 56 + }
57 - 57 +
58 - /** 58 + /**
59 - * Returns params of monitor method, refer to RFC7047's Section 4.1.5. 59 + * Returns params of monitor method, refer to RFC7047's Section 4.1.5.
60 - * @param monotorId json-value, refer to RFC7047's Section 4.1.5. 60 + * @param monotorId json-value, refer to RFC7047's Section 4.1.5.
61 - * @param dbSchema DatabaseSchema entity 61 + * @param dbSchema DatabaseSchema entity
62 - * @return List of Object, the params of monitor request 62 + * @return List of Object, the params of monitor request
63 - */ 63 + */
64 - public static List<Object> getMonitorParams(String monotorId, DatabaseSchema dbSchema) { 64 + public static List<Object> getMonitorParams(String monotorId, DatabaseSchema dbSchema) {
65 - Set<String> tables = dbSchema.getTableNames(); 65 + Set<String> tables = dbSchema.getTableNames();
66 - Map<String, MonitorRequest> mrMap = Maps.newHashMap(); 66 + Map<String, MonitorRequest> mrMap = Maps.newHashMap();
67 - for (String tableName : tables) { 67 + for (String tableName : tables) {
68 - TableSchema tableSchema = dbSchema.getTableSchema(tableName); 68 + TableSchema tableSchema = dbSchema.getTableSchema(tableName);
69 - MonitorRequest monitorRequest = getAllColumnsMonitorRequest(tableSchema); 69 + MonitorRequest monitorRequest = getAllColumnsMonitorRequest(tableSchema);
70 - mrMap.put(tableName, monitorRequest); 70 + mrMap.put(tableName, monitorRequest);
71 - } 71 + }
72 - return Lists.newArrayList(dbSchema.name(), monotorId, mrMap); 72 + return Lists.newArrayList(dbSchema.name(), monotorId, mrMap);
73 - } 73 + }
74 - 74 +
75 - /** 75 + /**
76 - * Returns params of transact method, refer to RFC7047's Section 4.1.3. 76 + * Returns params of transact method, refer to RFC7047's Section 4.1.3.
77 - * @param dbSchema DatabaseSchema entity 77 + * @param dbSchema DatabaseSchema entity
78 - * @param operations operation*, refer to RFC7047's Section 4.1.3. 78 + * @param operations operation*, refer to RFC7047's Section 4.1.3.
79 - * @return List of Object, the params of transact request 79 + * @return List of Object, the params of transact request
80 - */ 80 + */
81 - public static List<Object> getTransactParams(DatabaseSchema dbSchema, List<Operation> operations) { 81 + public static List<Object> getTransactParams(DatabaseSchema dbSchema, List<Operation> operations) {
82 - List<Object> lists = Lists.newArrayList(dbSchema.name()); 82 + List<Object> lists = Lists.newArrayList(dbSchema.name());
83 - lists.addAll(operations); 83 + lists.addAll(operations);
84 - return lists; 84 + return lists;
85 - } 85 + }
86 -} 86 +}
......