├── .gitignore ├── ovsdb-client ├── src │ ├── main │ │ ├── resources │ │ │ └── ovsdb-client.properties │ │ └── java │ │ │ └── com │ │ │ └── vmware │ │ │ └── ovsdb │ │ │ ├── protocol │ │ │ ├── operation │ │ │ │ ├── package-info.java │ │ │ │ ├── notation │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── Value.java │ │ │ │ │ ├── Mutator.java │ │ │ │ │ ├── serializer │ │ │ │ │ │ ├── RowSerializer.java │ │ │ │ │ │ └── AtomSerializer.java │ │ │ │ │ ├── deserializer │ │ │ │ │ │ ├── RowDeserializer.java │ │ │ │ │ │ ├── NamedUuidDeserializer.java │ │ │ │ │ │ ├── ConditionDeserializer.java │ │ │ │ │ │ ├── PairDeserializer.java │ │ │ │ │ │ ├── ValueDeserializer.java │ │ │ │ │ │ ├── MapDeserializer.java │ │ │ │ │ │ ├── UuidDeserializer.java │ │ │ │ │ │ ├── AtomDeserializer.java │ │ │ │ │ │ └── SetDeserializer.java │ │ │ │ │ ├── Function.java │ │ │ │ │ ├── Uuid.java │ │ │ │ │ ├── Pair.java │ │ │ │ │ ├── NamedUuid.java │ │ │ │ │ ├── Atom.java │ │ │ │ │ └── Map.java │ │ │ │ ├── result │ │ │ │ │ ├── EmptyResult.java │ │ │ │ │ ├── UpdateResult.java │ │ │ │ │ ├── SelectResult.java │ │ │ │ │ ├── InsertResult.java │ │ │ │ │ └── OperationResult.java │ │ │ │ ├── Abort.java │ │ │ │ ├── Operation.java │ │ │ │ ├── Assert.java │ │ │ │ ├── Commit.java │ │ │ │ └── Comment.java │ │ │ ├── schema │ │ │ │ ├── package-info.java │ │ │ │ ├── BooleanBaseType.java │ │ │ │ ├── AtomicType.java │ │ │ │ ├── RealBaseType.java │ │ │ │ ├── UuidBaseType.java │ │ │ │ ├── StringBaseType.java │ │ │ │ ├── IntegerBaseType.java │ │ │ │ └── deserializer │ │ │ │ │ └── TypeDeserializer.java │ │ │ └── methods │ │ │ │ ├── package-info.java │ │ │ │ ├── serializer │ │ │ │ └── MonitorRequestsSerializer.java │ │ │ │ ├── deserializer │ │ │ │ ├── TableUpdateDeserializer.java │ │ │ │ └── TableUpdatesDeserializer.java │ │ │ │ ├── TableUpdate.java │ │ │ │ ├── TableUpdates.java │ │ │ │ ├── MonitorRequests.java │ │ │ │ ├── LockResult.java │ │ │ │ ├── RowUpdate.java │ │ │ │ └── MonitorRequest.java │ │ │ ├── exception │ │ │ └── OvsdbClientException.java │ │ │ ├── callback │ │ │ ├── LockCallback.java │ │ │ ├── MonitorCallback.java │ │ │ └── ConnectionCallback.java │ │ │ ├── netty │ │ │ ├── ExceptionHandler.java │ │ │ └── JsonNodeDecoder.java │ │ │ ├── service │ │ │ ├── OvsdbActiveConnectionConnector.java │ │ │ ├── OvsdbPassiveConnectionListener.java │ │ │ └── impl │ │ │ │ └── OvsdbActiveConnectionConnectorImpl.java │ │ │ └── util │ │ │ └── PropertyManager.java │ └── test │ │ ├── resources │ │ ├── ovsdb-client.properties │ │ └── log4j.properties │ │ └── java │ │ └── com │ │ └── vmware │ │ └── ovsdb │ │ ├── testutils │ │ ├── HardwareGatewayConstants.java │ │ ├── TestConstants.java │ │ └── ActiveOvsdbServerEmulator.java │ │ ├── protocol │ │ ├── schema │ │ │ ├── Constants.java │ │ │ ├── BaseTypeTest.java │ │ │ ├── DatabaseSchemaTest.java │ │ │ ├── ColumnSchemaTest.java │ │ │ ├── AtomicTypeTest.java │ │ │ ├── BooleanBaseTypeTest.java │ │ │ └── RealBaseTypeTest.java │ │ ├── operation │ │ │ ├── AbortTest.java │ │ │ ├── AssertTest.java │ │ │ ├── result │ │ │ │ ├── UpdateResultTest.java │ │ │ │ ├── InsertResultTest.java │ │ │ │ ├── EmptyResultTest.java │ │ │ │ └── ErrorResultTest.java │ │ │ ├── CommentTest.java │ │ │ ├── CommitTest.java │ │ │ ├── notation │ │ │ │ ├── MutationTest.java │ │ │ │ ├── NamedUuidTest.java │ │ │ │ ├── UuidTest.java │ │ │ │ ├── ValueTest.java │ │ │ │ ├── MapTest.java │ │ │ │ ├── PairTest.java │ │ │ │ ├── ConditionTest.java │ │ │ │ └── SetTest.java │ │ │ └── InsertTest.java │ │ └── methods │ │ │ ├── LockResultTest.java │ │ │ ├── MonitorSelectTest.java │ │ │ └── TableUpdateTest.java │ │ ├── util │ │ └── PropertyManagerTest.java │ │ └── service │ │ ├── OvsdbClientActiveConnectionTest.java │ │ └── OvsdbClientPassiveConnectionTest.java └── pom.xml ├── json-rpc ├── src │ ├── test │ │ ├── resources │ │ │ └── log4j.properties │ │ └── java │ │ │ └── com │ │ │ └── vmware │ │ │ └── ovsdb │ │ │ └── jsonrpc │ │ │ └── v1 │ │ │ ├── util │ │ │ ├── TestUtil.java │ │ │ └── JsonUtilTest.java │ │ │ ├── model │ │ │ ├── JsonRpcV1ResponseTest.java │ │ │ └── JsonRpcV1RequestTest.java │ │ │ └── service │ │ │ └── domain │ │ │ └── SillyCalculator.java │ └── main │ │ └── java │ │ └── com │ │ └── vmware │ │ └── ovsdb │ │ └── jsonrpc │ │ └── v1 │ │ ├── exception │ │ ├── JsonRpcDuplicateIdException.java │ │ ├── JsonRpcConnectionClosedException.java │ │ ├── JsonRpcInvalidResponseException.java │ │ ├── JsonRpcResultTypeMismatchException.java │ │ ├── JsonRpcTransportException.java │ │ └── JsonRpcException.java │ │ ├── util │ │ └── JsonRpcConstant.java │ │ ├── annotation │ │ └── JsonRpcServiceMethod.java │ │ ├── spi │ │ └── JsonRpcTransporter.java │ │ └── service │ │ ├── JsonRpcV1Server.java │ │ └── JsonRpcV1Client.java └── pom.xml ├── NOTICE ├── .travis.yml └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | target/* 4 | */target/* 5 | .DS_Store 6 | 7 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/resources/ovsdb-client.properties: -------------------------------------------------------------------------------- 1 | channel.read.idle.timeout.sec=30 2 | channel.read.idle.max=3 3 | rpc.timeout.sec=60 4 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/resources/ovsdb-client.properties: -------------------------------------------------------------------------------- 1 | channel.read.idle.timeout.sec=5 2 | channel.read.idle.max=3 3 | rpc.timeout.sec=10 4 | 5 | invalid.int=abc 6 | -------------------------------------------------------------------------------- /json-rpc/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Set root logger level to DEBUG 2 | log4j.rootLogger=DEBUG, stdout 3 | # Direct log messages to stdout 4 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 5 | log4j.appender.stdout.Target=System.out 6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.stdout.layout.ConversionPattern=%d | %-5.5p | %-15.50t | %-25.50c{1} | %m%n 8 | 9 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Set root logger level to DEBUG 2 | log4j.rootLogger=DEBUG, stdout 3 | # Reduce debug log from apache 4 | log4j.logger.org.apache=info 5 | # Direct log messages to stdout 6 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 7 | log4j.appender.stdout.Target=System.out 8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.stdout.layout.ConversionPattern=%d | %-5.5p | %-15.50t | %-25.50c{1} | %m%n 10 | 11 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | OvSDB Client Library 2 | 3 | Copyright (c) 2018 VMware, Inc. All Rights Reserved. 4 | 5 | This product is licensed to you under the BSD-2 license (the "License"). You 6 | may not use this product except in compliance with the BSD-2 License. 7 | 8 | This product may include a number of subcomponents with separate copyright 9 | notices and license terms. Your use of these subcomponents is subject to the 10 | terms and conditions of the subcomponent's license, as noted in the LICENSE 11 | file. 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: true 2 | 3 | language: java 4 | 5 | addons: 6 | apt: 7 | packages: 8 | - net-tools 9 | 10 | jdk: oraclejdk8 11 | 12 | env: 13 | - DOCKER_HOST=tcp://127.0.0.1:2375 14 | 15 | services: 16 | - docker 17 | 18 | before_install: 19 | - docker pull hechaol/ovs:2.9.0 20 | - export HOST_IP=$(/sbin/ifconfig docker0 | grep 'inet addr:' | cut -d':' -f2| cut -d' ' -f1) 21 | 22 | script: 23 | - mvn clean verify -Dhost.ip=$HOST_IP 24 | 25 | after_success: 26 | - mvn clean cobertura:cobertura-integration-test coveralls:report -Dhost.ip=$HOST_IP 27 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | /** 16 | * This package includes implementations of operations. 17 | * 18 | * @see OVSDB Management Protocol 5.2 19 | */ 20 | 21 | package com.vmware.ovsdb.protocol.operation; 22 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/schema/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | /** 16 | * This package includes implementations of schema format. 17 | * 18 | * @see OVSDB Management Protocol Section 19 | * 3.2 20 | */ 21 | 22 | package com.vmware.ovsdb.protocol.schema; 23 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/methods/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | /** 16 | * This package includes implementations of notations used in RPC methods. 17 | * 18 | * @see OVSDB Management Protocol 4.1 19 | */ 20 | 21 | package com.vmware.ovsdb.protocol.methods; 22 | -------------------------------------------------------------------------------- /json-rpc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | ovsdb-client-library 7 | com.vmware.ovsdb 8 | 1.0.1 9 | 10 | 4.0.0 11 | 12 | JSON RPC 1.0 13 | json-rpc 14 | 15 | 16 | 17 | com.fasterxml.jackson.core 18 | jackson-core 19 | 20 | 21 | com.fasterxml.jackson.core 22 | jackson-databind 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | /** 16 | * This package includes implementations of notations used in transaction operations. 17 | * 18 | * @see OVSDB Management Protocol 5.1 19 | */ 20 | 21 | package com.vmware.ovsdb.protocol.operation.notation; 22 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/exception/OvsdbClientException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.exception; 16 | 17 | public class OvsdbClientException extends Exception { 18 | 19 | public OvsdbClientException(String message) { 20 | super(message); 21 | } 22 | 23 | public OvsdbClientException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/callback/LockCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.callback; 16 | 17 | /** 18 | * Callback for "lock" operation. 19 | */ 20 | public interface LockCallback { 21 | 22 | /** 23 | * Called when the lock is acquired. 24 | */ 25 | void locked(); 26 | 27 | 28 | /** 29 | * Called when the lock is stolen. 30 | */ 31 | void stolen(); 32 | } 33 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/exception/JsonRpcDuplicateIdException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.exception; 16 | 17 | /** 18 | * Thrown to indicate that a RPC call id duplicate. 19 | */ 20 | public class JsonRpcDuplicateIdException extends JsonRpcException { 21 | 22 | public JsonRpcDuplicateIdException(String message) { 23 | super(message); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/exception/JsonRpcConnectionClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.exception; 16 | 17 | /** 18 | * Thrown to indicate that a RPC connection is closed. 19 | */ 20 | public class JsonRpcConnectionClosedException extends JsonRpcException { 21 | 22 | public JsonRpcConnectionClosedException(String message) { 23 | super(message); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/exception/JsonRpcInvalidResponseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.exception; 16 | 17 | /** 18 | * Thrown to indicate that a RPC response is invalid. 19 | */ 20 | public class JsonRpcInvalidResponseException extends JsonRpcException { 21 | 22 | public JsonRpcInvalidResponseException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/exception/JsonRpcResultTypeMismatchException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.exception; 16 | 17 | /** 18 | * Thrown to indicate that there the RPC method result type does not match the expected type. 19 | */ 20 | public class JsonRpcResultTypeMismatchException extends JsonRpcException { 21 | 22 | public JsonRpcResultTypeMismatchException(String message, Throwable cause) { 23 | super(message, cause); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/testutils/HardwareGatewayConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.testutils; 16 | 17 | public class HardwareGatewayConstants { 18 | 19 | public static final String HARDWARE_VTEP = "hardware_vtep"; 20 | 21 | public static final String LOGICAL_SWITCH = "Logical_Switch"; 22 | 23 | public static final String PHYSICAL_LOCATOR = "Physical_Locator"; 24 | 25 | public static final String UCAST_MACS_REMOTE = "Ucast_Macs_Remote"; 26 | } 27 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/schema/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | public class Constants { 18 | 19 | public static final String JSON_INTEGER = "\"integer\""; 20 | 21 | public static final String JSON_REAL = "\"real\""; 22 | 23 | public static final String JSON_BOOLEAN = "\"boolean\""; 24 | 25 | public static final String JSON_STRING = "\"string\""; 26 | 27 | public static final String JSON_UUID = "\"uuid\""; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/callback/MonitorCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.callback; 16 | 17 | import com.vmware.ovsdb.protocol.methods.TableUpdates; 18 | 19 | /** 20 | * Callback for "monitor" operation. 21 | */ 22 | public interface MonitorCallback { 23 | 24 | /** 25 | * Called when there are updates for the corresponding monitor request. 26 | * 27 | * @param tableUpdates updates from the monitored tables 28 | */ 29 | void update(TableUpdates tableUpdates); 30 | } 31 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/util/JsonRpcConstant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.util; 16 | 17 | /** 18 | * Constants used in JSON-RPC protocol. 19 | */ 20 | public class JsonRpcConstant { 21 | 22 | public static final String METHOD = "method"; 23 | 24 | public static final String PARAMS = "params"; 25 | 26 | public static final String ID = "id"; 27 | 28 | public static final String RESULT = "result"; 29 | 30 | public static final String ERROR = "error"; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/exception/JsonRpcTransportException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.exception; 16 | 17 | /** 18 | * Thrown to indicate that there is something wrong with the JSON-RPC transporter. 19 | */ 20 | public class JsonRpcTransportException extends JsonRpcException { 21 | 22 | public JsonRpcTransportException(String message) { 23 | super(message); 24 | } 25 | 26 | public JsonRpcTransportException(Throwable cause) { 27 | super(cause); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/exception/JsonRpcException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.exception; 16 | 17 | /** 18 | * Thrown to indicate that there is something wrong with this JSON-RPC client / server. 19 | */ 20 | public class JsonRpcException extends Exception { 21 | 22 | public JsonRpcException(String message) { 23 | super(message); 24 | } 25 | 26 | public JsonRpcException(Throwable cause) { 27 | super(cause); 28 | } 29 | 30 | public JsonRpcException(String message, Throwable cause) { 31 | super(message, cause); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/testutils/TestConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.testutils; 16 | 17 | public class TestConstants { 18 | 19 | public static final String OVS_DOCKER_IMAGE = "hechaol/ovs:2.9.0"; 20 | 21 | public static final int VERIFY_TIMEOUT_MILLIS = 5 * 1000; // 5 seconds 22 | 23 | public static final int TEST_TIMEOUT_MILLIS = 60 * 1000; // 1 minutes 24 | 25 | public static String HOST_IP = System.getProperty("host.ip"); 26 | 27 | public static final String LOCAL_HOST = "127.0.0.1"; 28 | 29 | public static final int OVSDB_PORT = 6640; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/AbortTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import org.junit.Test; 23 | 24 | public class AbortTest { 25 | 26 | @Test 27 | public void testSerialization() throws JsonProcessingException { 28 | Abort abort = new Abort(); 29 | String expectedResult = "{\"op\":\"abort\"}"; 30 | assertEquals(expectedResult, JsonUtil.serialize(abort)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/schema/BooleanBaseType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import com.vmware.ovsdb.protocol.operation.notation.Value; 18 | 19 | /** 20 | *
21 |  * {@literal
22 |  * Represent a  with a boolean  as it's type.
23 |  * }
24 |  * 
25 | * 26 | * @see BaseType 27 | * @see AtomicType 28 | */ 29 | public class BooleanBaseType extends BaseType { 30 | 31 | public BooleanBaseType() { 32 | super(AtomicType.BOOLEAN); 33 | } 34 | 35 | public BooleanBaseType(Value enums) { 36 | super(AtomicType.BOOLEAN, enums); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/schema/BaseTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 18 | import org.junit.Test; 19 | 20 | import java.io.IOException; 21 | 22 | public class BaseTypeTest { 23 | 24 | @Test(expected = IOException.class) 25 | public void testInvalidType() throws IOException { 26 | JsonUtil.deserialize("{\"type\": \"double\"}", BaseType.class); 27 | } 28 | 29 | @Test(expected = IOException.class) 30 | public void testMissingType() throws IOException { 31 | JsonUtil.deserialize("{\"minInteger\": 0, \"maxInteger\":1}", BaseType.class); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/result/EmptyResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.result; 16 | 17 | /** 18 | * This is used for operations who has an empty result. For example, "wait", "commit", "abort", 19 | * "comment" and "assert". 20 | */ 21 | public class EmptyResult extends OperationResult { 22 | 23 | @Override 24 | public int hashCode() { 25 | return 0; 26 | } 27 | 28 | @Override 29 | public boolean equals(Object other) { 30 | return this == other || other instanceof EmptyResult; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return getClass().getSimpleName() + " []"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /json-rpc/src/test/java/com/vmware/ovsdb/jsonrpc/v1/util/TestUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.util; 16 | 17 | import com.fasterxml.jackson.databind.JsonNode; 18 | import com.vmware.ovsdb.jsonrpc.v1.model.JsonRpcV1Request; 19 | import com.vmware.ovsdb.jsonrpc.v1.model.JsonRpcV1Response; 20 | 21 | public class TestUtil { 22 | 23 | public static JsonNode getRequestNode(String id, String method, Object... params) { 24 | return JsonUtil.toJsonNode(new JsonRpcV1Request(id, method, params)); 25 | } 26 | 27 | public static JsonNode getResponseNode(String id, Object result, String error) { 28 | return JsonUtil.toJsonNode(new JsonRpcV1Response(result, error, id)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/Value.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 18 | import com.vmware.ovsdb.protocol.operation.notation.deserializer.ValueDeserializer; 19 | 20 | /** 21 | *
22 |  * {@literal
23 |  * 
24 |  *   A JSON value that represents the value of a column in a table row,
25 |  *   one of , , or .
26 |  * }
27 |  * 
28 | * 29 | * @see Atom 30 | * @see Set 31 | * @see Map 32 | */ 33 | @JsonDeserialize(using = ValueDeserializer.class) 34 | public abstract class Value { 35 | 36 | protected Value() { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/netty/ExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.netty; 16 | 17 | import io.netty.channel.ChannelDuplexHandler; 18 | import io.netty.channel.ChannelHandlerContext; 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | 22 | import java.lang.invoke.MethodHandles; 23 | 24 | class ExceptionHandler extends ChannelDuplexHandler { 25 | 26 | private static final Logger LOGGER = LoggerFactory 27 | .getLogger(MethodHandles.lookup().lookupClass()); 28 | 29 | @Override 30 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { 31 | LOGGER.error("Channel " + ctx.channel() + " encountered exception. Closing.", cause); 32 | ctx.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/util/PropertyManagerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.util; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import org.junit.Test; 20 | 21 | public class PropertyManagerTest { 22 | 23 | @Test 24 | public void testBasic() { 25 | // A valid property should return the value in the property file 26 | assertEquals(10, PropertyManager.getIntProperty("rpc.timeout.sec", 42)); 27 | // A nonexistent property should return default value 28 | assertEquals(42, PropertyManager.getLongProperty("non.existent.prop", 42)); 29 | // An invalid integer property should return default value 30 | assertEquals(42, PropertyManager.getLongProperty("invalid.int", 42)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/Mutator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import com.fasterxml.jackson.annotation.JsonValue; 18 | 19 | /** 20 | *
21 |  * {@literal
22 |  * 
23 |  *    One of "+=", "-=", "*=", "/=", "%=", "insert", or "delete".
24 |  * }
25 |  * 
26 | */ 27 | public enum Mutator { 28 | SUM("+="), 29 | DIFFERENCE("-="), 30 | PRODUCT("*="), 31 | QUOTIENT("/="), 32 | REMINDER("%="), 33 | INSERT("insert"), 34 | DELETE("delete"); 35 | 36 | private String name; 37 | 38 | Mutator(String name) { 39 | this.name = name; 40 | } 41 | 42 | @JsonValue 43 | public String toString() { 44 | return name; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/annotation/JsonRpcServiceMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.annotation; 16 | 17 | import java.lang.annotation.ElementType; 18 | import java.lang.annotation.Retention; 19 | import java.lang.annotation.RetentionPolicy; 20 | import java.lang.annotation.Target; 21 | 22 | /** 23 | * Annotate the RPC handler methods. 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target(ElementType.METHOD) 27 | public @interface JsonRpcServiceMethod { 28 | 29 | /** 30 | * JSON-RPC methods name. The value is the RPC method name. By default the value is empty and the 31 | * Java method name is used. 32 | * 33 | * @return JSON-RPC method name 34 | */ 35 | String value() default ""; 36 | } 37 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/spi/JsonRpcTransporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.spi; 16 | 17 | import com.fasterxml.jackson.databind.JsonNode; 18 | import com.vmware.ovsdb.jsonrpc.v1.exception.JsonRpcTransportException; 19 | 20 | /** 21 | * The underlying transport com.vmware.ovsdb.protocol for JSON-RPC. The implementation must be 22 | * thread-safe. 23 | */ 24 | public interface JsonRpcTransporter { 25 | 26 | /** 27 | * Send a JSON data to peer. 28 | * 29 | * @param data JSON data to send 30 | * @throws JsonRpcTransportException if fail to send the data 31 | */ 32 | void send(JsonNode data) throws JsonRpcTransportException; 33 | 34 | /** 35 | * Close the transporter. 36 | */ 37 | void close(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/schema/AtomicType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import com.fasterxml.jackson.annotation.JsonValue; 18 | 19 | /** 20 | *
21 |  * {@literal
22 |  * 
23 |  *   One of the strings "integer", "real", "boolean", "string", or
24 |  *   "uuid", representing the specified scalar type.
25 |  * }
26 |  * 
27 | */ 28 | public enum AtomicType { 29 | INTEGER("integer"), 30 | REAL("real"), 31 | BOOLEAN("boolean"), 32 | STRING("string"), 33 | UUID("uuid"); 34 | 35 | private String atomicType; 36 | 37 | AtomicType(String atomicType) { 38 | this.atomicType = atomicType; 39 | } 40 | 41 | @JsonValue 42 | public String toString() { 43 | return atomicType; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/callback/ConnectionCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.callback; 16 | 17 | import com.vmware.ovsdb.service.OvsdbClient; 18 | 19 | /** 20 | * Callback that is called when an OVSDB server is connected / disconnected to the manager. 21 | */ 22 | public interface ConnectionCallback { 23 | 24 | /** 25 | * Called when an OVSDB server is connected to the manager. 26 | * 27 | * @param ovsdbClient the {@link OvsdbClient} that can be used to communicate with the server 28 | */ 29 | void connected(OvsdbClient ovsdbClient); 30 | 31 | /** 32 | * Called when an OVSDB server is disconnected from the manager. 33 | * 34 | * @param ovsdbClient the {@link OvsdbClient} that is used to communicate with the server 35 | */ 36 | void disconnected(OvsdbClient ovsdbClient); 37 | } 38 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/Abort.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation; 16 | 17 | import static com.vmware.ovsdb.protocol.util.OvsdbConstant.ABORT; 18 | 19 | /** 20 | *
21 |  * {@literal
22 |  * The "abort" object contains the following member:
23 |  *
24 |  *    "op":  "abort"                      required
25 |  *
26 |  * There is no corresponding result object (the operation never
27 |  * succeeds).
28 |  *
29 |  * The operation aborts the entire transaction with an error.  This may
30 |  * be useful for testing.
31 |  *
32 |  * The error that will be returned is:
33 |  *
34 |  * "error": "aborted"
35 |  *    This operation always fails with this error.
36 |  * }
37 |  * 
38 | */ 39 | public class Abort extends Operation { 40 | 41 | protected Abort() { 42 | super(ABORT); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/AssertTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.google.common.testing.EqualsTester; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import org.junit.Test; 24 | 25 | public class AssertTest { 26 | 27 | @Test 28 | public void testSerialization() throws JsonProcessingException { 29 | Assert assrt = new Assert("myLock"); 30 | String expectedResult = "{\"op\":\"assert\",\"lock\":\"myLock\"}"; 31 | assertEquals(expectedResult, JsonUtil.serialize(assrt)); 32 | } 33 | 34 | @Test 35 | public void testEquals() { 36 | new EqualsTester().addEqualityGroup(new Assert("lock"), new Assert("lock")).testEquals(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/serializer/RowSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.serializer; 16 | 17 | import com.fasterxml.jackson.core.JsonGenerator; 18 | import com.fasterxml.jackson.databind.SerializerProvider; 19 | import com.fasterxml.jackson.databind.ser.std.StdSerializer; 20 | import com.vmware.ovsdb.protocol.operation.notation.Row; 21 | 22 | import java.io.IOException; 23 | 24 | public class RowSerializer extends StdSerializer { 25 | 26 | public RowSerializer() { 27 | this(null); 28 | } 29 | 30 | protected RowSerializer(Class klass) { 31 | super(klass); 32 | } 33 | 34 | @Override 35 | public void serialize( 36 | Row row, JsonGenerator jgen, SerializerProvider provider 37 | ) throws IOException { 38 | jgen.writeObject(row.getColumns()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/serializer/AtomSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.serializer; 16 | 17 | import com.fasterxml.jackson.core.JsonGenerator; 18 | import com.fasterxml.jackson.databind.SerializerProvider; 19 | import com.fasterxml.jackson.databind.ser.std.StdSerializer; 20 | import com.vmware.ovsdb.protocol.operation.notation.Atom; 21 | 22 | import java.io.IOException; 23 | 24 | public class AtomSerializer extends StdSerializer { 25 | 26 | public AtomSerializer() { 27 | this(null); 28 | } 29 | 30 | protected AtomSerializer(Class klass) { 31 | super(klass); 32 | } 33 | 34 | @Override 35 | public void serialize( 36 | Atom atom, JsonGenerator jgen, SerializerProvider provider 37 | ) throws IOException { 38 | jgen.writeObject(atom.getValue()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/result/UpdateResultTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.result; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import com.google.common.testing.EqualsTester; 20 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 21 | import org.junit.Test; 22 | 23 | public class UpdateResultTest { 24 | 25 | @Test 26 | public void testDeserialization() { 27 | String jsonString = "{\"count\":2}"; 28 | 29 | UpdateResult expectedResult = new UpdateResult(2); 30 | 31 | assertEquals( 32 | expectedResult, JsonUtil.deserializeNoException(jsonString, OperationResult.class) 33 | ); 34 | } 35 | 36 | @Test 37 | public void testEquals() { 38 | new EqualsTester() 39 | .addEqualityGroup(new UpdateResult(42), new UpdateResult(42)) 40 | .testEquals(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/service/JsonRpcV1Server.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.service; 16 | 17 | import com.fasterxml.jackson.databind.JsonNode; 18 | import com.vmware.ovsdb.jsonrpc.v1.exception.JsonRpcException; 19 | 20 | /** 21 | * Interface for a JSON-RPC 1.0 server that handles RPC requests from the clients. 22 | */ 23 | public interface JsonRpcV1Server { 24 | 25 | /** 26 | * Handle the request from the client. 27 | * 28 | * @param requestNode the request {@link JsonNode} 29 | * @throws JsonRpcException if fail to handle the request 30 | */ 31 | void handleRequest(JsonNode requestNode) throws JsonRpcException; 32 | 33 | /** 34 | * Shutdown this server. After it is called, no other methods shall be called on this server any 35 | * more. The request that is being handled may be affected. 36 | */ 37 | void shutdown(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/CommentTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.google.common.testing.EqualsTester; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import org.junit.Test; 24 | 25 | public class CommentTest { 26 | 27 | @Test 28 | public void testSerialization() throws JsonProcessingException { 29 | Comment comment = new Comment("Transaction from me"); 30 | String expectedResult 31 | = "{\"op\":\"comment\",\"comment\":\"Transaction from me\"}"; 32 | 33 | assertEquals(expectedResult, JsonUtil.serialize(comment)); 34 | } 35 | 36 | @Test 37 | public void testEquals() { 38 | new EqualsTester() 39 | .addEqualityGroup(new Comment("comment"), new Comment("comment")) 40 | .testEquals(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/CommitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.google.common.testing.EqualsTester; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import org.junit.Test; 24 | 25 | public class CommitTest { 26 | 27 | @Test 28 | public void testSerialization() throws JsonProcessingException { 29 | Commit commit = new Commit(true); 30 | String expectedResult = "{\"op\":\"commit\",\"durable\":true}"; 31 | 32 | assertEquals(expectedResult, JsonUtil.serialize(commit)); 33 | } 34 | 35 | @Test 36 | public void testEquals() { 37 | new EqualsTester() 38 | .addEqualityGroup(new Commit(false), new Commit(false)) 39 | .addEqualityGroup(new Commit(true), new Commit(true)) 40 | .testEquals(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/methods/serializer/MonitorRequestsSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods.serializer; 16 | 17 | import com.fasterxml.jackson.core.JsonGenerator; 18 | import com.fasterxml.jackson.databind.SerializerProvider; 19 | import com.fasterxml.jackson.databind.ser.std.StdSerializer; 20 | import com.vmware.ovsdb.protocol.methods.MonitorRequests; 21 | 22 | import java.io.IOException; 23 | 24 | public class MonitorRequestsSerializer extends StdSerializer { 25 | 26 | public MonitorRequestsSerializer() { 27 | this(null); 28 | } 29 | 30 | protected MonitorRequestsSerializer(Class klass) { 31 | super(klass); 32 | } 33 | 34 | @Override 35 | public void serialize( 36 | MonitorRequests monitorRequests, JsonGenerator jgen, 37 | SerializerProvider provider 38 | ) throws IOException { 39 | jgen.writeObject(monitorRequests.getMonitorRequests()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/Operation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation; 16 | 17 | /** 18 | * The operations that may be performed as part of a "transact" RPC request (see Section 4.1.3) are 19 | * described in the following subsections. Each of these operations is a JSON object that may be 20 | * included as one of the elements of the "params" array that is one of the elements of the 21 | * "transact" request. The details of each object, its semantics, results, and possible errors are 22 | * described below. 23 | * 24 | * @see Insert 25 | * @see Select 26 | * @see Update 27 | * @see Mutate 28 | * @see Delete 29 | * @see Wait 30 | * @see Commit 31 | * @see Abort 32 | * @see Comment 33 | * @see Assert 34 | */ 35 | public abstract class Operation { 36 | 37 | private final String op; 38 | 39 | protected Operation(String op) { 40 | this.op = op; 41 | } 42 | 43 | public String getOp() { 44 | return op; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | OvSDB Client Library 2 | 3 | Copyright (c) 2018 VMware, Inc. All rights reserved. 4 | 5 | The BSD-2 license (the License) set forth below applies to all parts of the 6 | OvSDB Client Library project. You may not use this file except in compliance 7 | with the License. 8 | 9 | BSD-2 License 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | Redistributions in binary form must reproduce the above copyright notice, 16 | this list of conditions and the following disclaimer in the documentation and/or 17 | other materials provided with the distribution. 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/deserializer/RowDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.core.type.TypeReference; 19 | import com.fasterxml.jackson.databind.DeserializationContext; 20 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 21 | import com.vmware.ovsdb.protocol.operation.notation.Row; 22 | import com.vmware.ovsdb.protocol.operation.notation.Value; 23 | 24 | import java.io.IOException; 25 | import java.util.Map; 26 | 27 | public class RowDeserializer extends StdDeserializer { 28 | 29 | protected RowDeserializer() { 30 | this(null); 31 | } 32 | 33 | protected RowDeserializer(Class vc) { 34 | super(vc); 35 | } 36 | 37 | @Override 38 | public Row deserialize( 39 | JsonParser jp, DeserializationContext ctxt 40 | ) throws IOException { 41 | TypeReference> typeRef = new TypeReference>() {}; 42 | Map columns = jp.readValueAs(typeRef); 43 | return new Row(columns); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/service/OvsdbActiveConnectionConnector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.service; 16 | 17 | import io.netty.handler.ssl.SslContext; 18 | 19 | import java.util.concurrent.CompletableFuture; 20 | 21 | public interface OvsdbActiveConnectionConnector { 22 | 23 | /** 24 | * Connect to the OVSDB server on ip:port. 25 | * 26 | * @param ip the OVSDB server ip 27 | * @param port port to which the OVSDB is listening 28 | * @return a {@link CompletableFuture} that will complete with an {@link OvsdbClient} 29 | * object when the connection is established 30 | */ 31 | CompletableFuture connect(String ip, int port); 32 | 33 | /** 34 | * Connect to the OVSDB server on ip:port with SSL enabled. 35 | * 36 | * @param ip the OVSDB server ip 37 | * @param port port to which the OVSDB is listening 38 | * @param sslContext the SSL context 39 | * @return a {@link CompletableFuture} that will complete with an {@link OvsdbClient} 40 | * object when the connection is established 41 | */ 42 | CompletableFuture connectWithSsl(String ip, int port, SslContext sslContext); 43 | } 44 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/result/InsertResultTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.result; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import com.google.common.testing.EqualsTester; 20 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 21 | import com.vmware.ovsdb.protocol.operation.notation.Uuid; 22 | import org.junit.Test; 23 | 24 | import java.util.UUID; 25 | 26 | public class InsertResultTest { 27 | 28 | @Test 29 | public void testDeserialization() { 30 | String jsonString 31 | = "{\"uuid\":[\"uuid\"," 32 | + "\"00000000-0000-0000-0000-000000000000\"]}"; 33 | 34 | Uuid uuid = new Uuid( 35 | UUID.fromString("00000000-0000-0000-0000-000000000000")); 36 | InsertResult expectedResult = new InsertResult(uuid); 37 | 38 | assertEquals( 39 | expectedResult, JsonUtil.deserializeNoException(jsonString, OperationResult.class) 40 | ); 41 | } 42 | 43 | @Test 44 | public void testEquals() { 45 | UUID uuid = UUID.randomUUID(); 46 | new EqualsTester() 47 | .addEqualityGroup(new InsertResult(Uuid.of(uuid)), new InsertResult(new Uuid(uuid))) 48 | .testEquals(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/methods/deserializer/TableUpdateDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.core.type.TypeReference; 19 | import com.fasterxml.jackson.databind.DeserializationContext; 20 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 21 | import com.vmware.ovsdb.protocol.methods.RowUpdate; 22 | import com.vmware.ovsdb.protocol.methods.TableUpdate; 23 | 24 | import java.io.IOException; 25 | import java.util.Map; 26 | import java.util.UUID; 27 | 28 | public class TableUpdateDeserializer extends StdDeserializer { 29 | 30 | protected TableUpdateDeserializer() { 31 | this(null); 32 | } 33 | 34 | protected TableUpdateDeserializer(Class vc) { 35 | super(vc); 36 | } 37 | 38 | @Override 39 | public TableUpdate deserialize( 40 | JsonParser jp, DeserializationContext ctxt 41 | ) throws IOException { 42 | TypeReference> typeRef = new TypeReference>() {}; 43 | Map rowUpdates = jp.readValueAs(typeRef); 44 | return new TableUpdate(rowUpdates); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/methods/deserializer/TableUpdatesDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.core.type.TypeReference; 19 | import com.fasterxml.jackson.databind.DeserializationContext; 20 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 21 | import com.vmware.ovsdb.protocol.methods.TableUpdate; 22 | import com.vmware.ovsdb.protocol.methods.TableUpdates; 23 | 24 | import java.io.IOException; 25 | import java.util.Map; 26 | 27 | public class TableUpdatesDeserializer extends StdDeserializer { 28 | 29 | protected TableUpdatesDeserializer() { 30 | this(null); 31 | } 32 | 33 | protected TableUpdatesDeserializer(Class vc) { 34 | super(vc); 35 | } 36 | 37 | @Override 38 | public TableUpdates deserialize( 39 | JsonParser jp, DeserializationContext ctxt 40 | ) throws IOException { 41 | TypeReference> typeRef = 42 | new TypeReference>() {}; 43 | Map tableUpdates = jp.readValueAs(typeRef); 44 | return new TableUpdates(tableUpdates); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import com.fasterxml.jackson.annotation.JsonValue; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | /** 23 | * Representation of {@literal }. 24 | * 25 | *
26 |  * {@literal
27 |  * 
28 |  *    One of "<", "<=", "==", "!=", ">=", ">", "includes", or "excludes".
29 |  * }
30 |  * 
31 | */ 32 | public enum Function { 33 | LESS_THAN("<"), 34 | LESS_THAN_OR_EQUALS("<="), 35 | EQUALS("=="), 36 | NOT_EQUALS("!="), 37 | GREATER_THAN(">"), 38 | GREATER_THAN_OR_EQUALS(">="), 39 | INCLUDES("includes"), 40 | EXCLUDES("excludes"); 41 | 42 | private static final Map lookup = new HashMap<>(); 43 | 44 | static { 45 | for (Function function : Function.values()) { 46 | lookup.put(function.toString(), function); 47 | } 48 | } 49 | 50 | private String name; 51 | 52 | Function(String name) { 53 | this.name = name; 54 | } 55 | 56 | public static Function fromString(String function) { 57 | return lookup.get(function); 58 | } 59 | 60 | @JsonValue 61 | public String toString() { 62 | return name; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/result/EmptyResultTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.result; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import com.google.common.testing.EqualsTester; 20 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 21 | import org.junit.Test; 22 | 23 | import java.io.IOException; 24 | 25 | public class EmptyResultTest { 26 | 27 | @Test 28 | public void testDeserialization() { 29 | String jsonString = "{}"; 30 | 31 | EmptyResult expectedResult = new EmptyResult(); 32 | 33 | assertEquals( 34 | expectedResult, JsonUtil.deserializeNoException(jsonString, OperationResult.class) 35 | ); 36 | } 37 | 38 | @Test(expected = IOException.class) 39 | public void testInvalidResult1() throws IOException { 40 | JsonUtil.deserialize("{\"count\":1, \"error\":\"some error\"}", OperationResult.class); 41 | } 42 | 43 | @Test(expected = IOException.class) 44 | public void testInvalidResult2() throws IOException { 45 | JsonUtil.deserialize("{\"invalid\":\"something\"}", OperationResult.class); 46 | } 47 | 48 | @Test 49 | public void testEquals() { 50 | new EqualsTester().addEqualityGroup(new EmptyResult(), new EmptyResult()).testEquals(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/result/UpdateResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.result; 16 | 17 | import com.fasterxml.jackson.annotation.JsonCreator; 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | 20 | import java.util.Objects; 21 | 22 | /** 23 | * This is used for "update", "mutate" and "delete" operation result. It contains only one "count" 24 | * field. 25 | */ 26 | public class UpdateResult extends OperationResult { 27 | 28 | private long count; 29 | 30 | @JsonCreator 31 | public UpdateResult(@JsonProperty(value = "count", required = true) long count) { 32 | this.count = count; 33 | } 34 | 35 | public Long getCount() { 36 | return count; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object other) { 41 | if (this == other) { 42 | return true; 43 | } 44 | if (!(other instanceof UpdateResult)) { 45 | return false; 46 | } 47 | UpdateResult that = (UpdateResult) other; 48 | return count == that.getCount(); 49 | } 50 | 51 | @Override 52 | public int hashCode() { 53 | return Objects.hash(count); 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return getClass().getSimpleName() + " [" 59 | + "count=" + count 60 | + "]"; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/methods/TableUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods; 16 | 17 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 18 | import com.vmware.ovsdb.protocol.methods.deserializer.TableUpdateDeserializer; 19 | 20 | import java.util.Map; 21 | import java.util.Objects; 22 | import java.util.UUID; 23 | 24 | @JsonDeserialize(using = TableUpdateDeserializer.class) 25 | public class TableUpdate { 26 | 27 | private final Map rowUpdates; 28 | 29 | public TableUpdate(Map rowUpdates) { 30 | this.rowUpdates = rowUpdates; 31 | } 32 | 33 | public Map getRowUpdates() { 34 | return rowUpdates; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object other) { 39 | if (this == other) { 40 | return true; 41 | } 42 | if (!(other instanceof TableUpdate)) { 43 | return false; 44 | } 45 | TableUpdate that = (TableUpdate) other; 46 | return Objects.equals(rowUpdates, that.getRowUpdates()); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return Objects.hash(rowUpdates); 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return getClass().getSimpleName() + " [" 57 | + "rowUpdates=" + rowUpdates 58 | + "]"; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/result/ErrorResultTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.result; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import com.google.common.testing.EqualsTester; 20 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 21 | import org.junit.Test; 22 | 23 | public class ErrorResultTest { 24 | 25 | private final String error = "constraint violation"; 26 | 27 | private final String details = "duplicate name"; 28 | 29 | @Test 30 | public void testDeserialization() { 31 | String jsonString = "{\"error\":\"" + error + "\", " + "\"details\":\"" + details + "\"}"; 32 | 33 | ErrorResult expectedResult = new ErrorResult(error, details); 34 | 35 | assertEquals( 36 | expectedResult, JsonUtil.deserializeNoException(jsonString, OperationResult.class) 37 | ); 38 | 39 | jsonString = "{\"error\":\"" + error + "\"}"; 40 | 41 | expectedResult = new ErrorResult(error, null); 42 | 43 | assertEquals( 44 | expectedResult, JsonUtil.deserializeNoException(jsonString, OperationResult.class) 45 | ); 46 | } 47 | 48 | @Test 49 | public void testEquals() { 50 | new EqualsTester() 51 | .addEqualityGroup(new ErrorResult(error, details), new ErrorResult(error, details)) 52 | .testEquals(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/methods/LockResultTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods; 16 | 17 | import static junit.framework.TestCase.assertFalse; 18 | import static junit.framework.TestCase.assertTrue; 19 | 20 | import com.google.common.testing.EqualsTester; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import org.junit.Test; 23 | 24 | import java.io.IOException; 25 | 26 | public class LockResultTest { 27 | 28 | @Test 29 | public void testDeserialization() throws IOException { 30 | String json = "{\"locked\":true}"; 31 | 32 | LockResult lockResult = JsonUtil.deserialize(json, LockResult.class); 33 | assertTrue(lockResult.isLocked()); 34 | 35 | json = "{\"locked\":false}"; 36 | 37 | lockResult = JsonUtil.deserialize(json, LockResult.class); 38 | assertFalse(lockResult.isLocked()); 39 | } 40 | 41 | @Test(expected = IOException.class) 42 | public void testInvalidResult() throws IOException { 43 | String json = "{\"locked\":t}"; 44 | JsonUtil.deserialize(json, LockResult.class); 45 | } 46 | 47 | @Test 48 | public void testEquals() { 49 | new EqualsTester() 50 | .addEqualityGroup(new LockResult(true), new LockResult(true)) 51 | .addEqualityGroup(new LockResult(false), new LockResult(false)) 52 | .testEquals(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/methods/TableUpdates.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods; 16 | 17 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 18 | import com.vmware.ovsdb.protocol.methods.deserializer.TableUpdatesDeserializer; 19 | 20 | import java.util.Map; 21 | import java.util.Objects; 22 | 23 | @JsonDeserialize(using = TableUpdatesDeserializer.class) 24 | public class TableUpdates { 25 | 26 | private final Map tableUpdates; 27 | 28 | public TableUpdates(Map tableUpdates) { 29 | this.tableUpdates = tableUpdates; 30 | } 31 | 32 | public Map getTableUpdates() { 33 | return tableUpdates; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object other) { 38 | if (this == other) { 39 | return true; 40 | } 41 | if (!(other instanceof TableUpdates)) { 42 | return false; 43 | } 44 | TableUpdates that = (TableUpdates) other; 45 | return Objects.equals(tableUpdates, that.getTableUpdates()); 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return Objects.hash(tableUpdates); 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return getClass().getSimpleName() + " [" 56 | + "tableUpdates=" + tableUpdates 57 | + "]"; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/notation/MutationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.google.common.testing.EqualsTester; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import org.junit.Test; 24 | 25 | public class MutationTest { 26 | 27 | @Test 28 | public void testSerialization() throws JsonProcessingException { 29 | String expectedString = "[\"number\",\"+=\",5]"; 30 | Mutation mutation = new Mutation( 31 | "number", Mutator.SUM, Atom.integer(5)); 32 | 33 | assertEquals( 34 | expectedString, JsonUtil.serialize(mutation)); 35 | 36 | expectedString = "[\"some_set\",\"insert\",\"string\"]"; 37 | mutation = new Mutation( 38 | "some_set", Mutator.INSERT, Atom.string("string")); 39 | 40 | assertEquals( 41 | expectedString, JsonUtil.serialize(mutation)); 42 | } 43 | 44 | @Test 45 | public void testMutation() { 46 | new EqualsTester() 47 | .addEqualityGroup( 48 | new Mutation("physical_locators", Mutator.INSERT, Atom.string("10.1.1.1")), 49 | new Mutation("physical_locators", Mutator.INSERT, new Atom<>("10.1.1.1")) 50 | ).testEquals(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/result/SelectResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.result; 16 | 17 | import com.fasterxml.jackson.annotation.JsonCreator; 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | import com.vmware.ovsdb.protocol.operation.notation.Row; 20 | 21 | import java.util.List; 22 | import java.util.Objects; 23 | 24 | /** 25 | * Result of the "select" operation, which only contains one "row" field. 26 | */ 27 | public class SelectResult extends OperationResult { 28 | 29 | private List rows; 30 | 31 | @JsonCreator 32 | public SelectResult(@JsonProperty(value = "rows", required = true) List rows) { 33 | this.rows = rows; 34 | } 35 | 36 | public List getRows() { 37 | return rows; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object other) { 42 | if (this == other) { 43 | return true; 44 | } 45 | if (!(other instanceof SelectResult)) { 46 | return false; 47 | } 48 | SelectResult that = (SelectResult) other; 49 | return Objects.equals(rows, that.getRows()); 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | return Objects.hash(rows); 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return getClass().getSimpleName() + " [" 60 | + "rows=" + rows 61 | + "]"; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/netty/JsonNodeDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.netty; 16 | 17 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import io.netty.handler.codec.json.JsonObjectDecoder; 21 | import io.netty.util.CharsetUtil; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | 25 | import java.lang.invoke.MethodHandles; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | class JsonNodeDecoder extends JsonObjectDecoder { 30 | 31 | private static final Logger LOGGER = LoggerFactory.getLogger( 32 | MethodHandles.lookup().lookupClass()); 33 | 34 | JsonNodeDecoder() { 35 | // Max message length 1 GB. 36 | super(1024 * 1024 * 1024); 37 | } 38 | 39 | @Override 40 | protected void decode( 41 | ChannelHandlerContext ctx, ByteBuf in, List out 42 | ) throws Exception { 43 | List jsonByteBufs = new ArrayList<>(); 44 | super.decode(ctx, in, jsonByteBufs); 45 | 46 | for (Object byteBuf : jsonByteBufs) { 47 | ByteBuf json = (ByteBuf) byteBuf; 48 | String textJson = json.toString(CharsetUtil.UTF_8); 49 | 50 | LOGGER.debug("Received message {} from channel {}", textJson, ctx.channel()); 51 | out.add(JsonUtil.readTree(textJson)); 52 | json.release(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /json-rpc/src/test/java/com/vmware/ovsdb/jsonrpc/v1/model/JsonRpcV1ResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.model; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import com.google.common.testing.EqualsTester; 20 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonRpcConstant; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import org.junit.Test; 23 | 24 | public class JsonRpcV1ResponseTest { 25 | 26 | private final JsonRpcV1Response response = 27 | new JsonRpcV1Response("value", null, "id"); 28 | 29 | private final String jsonString = "{\"" + JsonRpcConstant.RESULT + "\":\"value\",\"" 30 | + JsonRpcConstant.ERROR + "\":null,\"" + JsonRpcConstant.ID + "\":\"id\"}"; 31 | 32 | @Test 33 | public void testSerialize() { 34 | assertEquals(jsonString, JsonUtil.serializeNoException(response)); 35 | } 36 | 37 | @Test 38 | public void testDeserialize() { 39 | assertEquals(response, JsonUtil.deserializeNoException(jsonString, JsonRpcV1Response.class)); 40 | } 41 | 42 | @Test 43 | public void testEquals() { 44 | new EqualsTester() 45 | .addEqualityGroup( 46 | new JsonRpcV1Response("value", null, "id"), 47 | response 48 | ) 49 | .addEqualityGroup( 50 | new JsonRpcV1Response(null, "error", "id"), 51 | new JsonRpcV1Response(null, "error", "id") 52 | ).testEquals(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/Uuid.java: -------------------------------------------------------------------------------- 1 | package com.vmware.ovsdb.protocol.operation.notation; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.vmware.ovsdb.protocol.operation.notation.deserializer.UuidDeserializer; 6 | import com.vmware.ovsdb.protocol.util.OvsdbConstant; 7 | 8 | import java.util.Objects; 9 | import java.util.UUID; 10 | 11 | /** 12 | * Representation of {@literal }. 13 | *
14 |  * {@literal
15 |  * 
16 |  *   A 2-element JSON array that represents a UUID.  The first element
17 |  *   of the array must be the string "uuid", and the second element
18 |  *   must be a 36-character string giving the UUID in the format
19 |  *   described by RFC 4122 [RFC4122].  For example, the following
20 |  *    represents the UUID 550e8400-e29b-41d4-a716-446655440000:
21 |  *
22 |  *   ["uuid", "550e8400-e29b-41d4-a716-446655440000"]
23 |  * }
24 |  * 
25 | */ 26 | @JsonDeserialize(using = UuidDeserializer.class) 27 | @JsonFormat(shape = JsonFormat.Shape.ARRAY) 28 | public class Uuid { 29 | 30 | public final String uuidString = OvsdbConstant.UUID; // For serializing 31 | 32 | private final UUID uuid; 33 | 34 | public Uuid(UUID uuid) { 35 | this.uuid = uuid; 36 | } 37 | 38 | public static Uuid of(UUID uuid) { 39 | return new Uuid(uuid); 40 | } 41 | 42 | public UUID getUuid() { 43 | return uuid; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object other) { 48 | if (this == other) { 49 | return true; 50 | } 51 | if (!(other instanceof Uuid)) { 52 | return false; 53 | } 54 | Uuid that = (Uuid) other; 55 | return Objects.equals(uuid, that.getUuid()); 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | return Objects.hash(uuidString, uuid); 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return uuid.toString(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/result/InsertResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.result; 16 | 17 | import com.fasterxml.jackson.annotation.JsonCreator; 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 20 | import com.vmware.ovsdb.protocol.operation.notation.Uuid; 21 | 22 | import java.util.Objects; 23 | 24 | /** 25 | * Result of the "insert" operation, which only contains one "uuid" field. 26 | */ 27 | @JsonDeserialize 28 | public class InsertResult extends OperationResult { 29 | 30 | private Uuid uuid; 31 | 32 | @JsonCreator 33 | public InsertResult(@JsonProperty(value = "uuid", required = true) Uuid uuid) { 34 | this.uuid = uuid; 35 | } 36 | 37 | public Uuid getUuid() { 38 | return uuid; 39 | } 40 | 41 | @Override 42 | public boolean equals(Object other) { 43 | if (this == other) { 44 | return true; 45 | } 46 | if (!(other instanceof InsertResult)) { 47 | return false; 48 | } 49 | InsertResult that = (InsertResult) other; 50 | return Objects.equals(uuid, that.getUuid()); 51 | } 52 | 53 | @Override 54 | public int hashCode() { 55 | 56 | return Objects.hash(uuid); 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return getClass().getSimpleName() + " [" 62 | + "uuid=" + uuid 63 | + "]"; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/result/OperationResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.result; 16 | 17 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 18 | import com.vmware.ovsdb.protocol.operation.result.deserializer.OperationResultDeserializer; 19 | 20 | /** 21 | *
22 |  * {@literal
23 |  * Regardless of whether errors occur in the database operations, the response is always a JSON-RPC
24 |  * response with null "error" and a "result" member that is an array with the same number of
25 |  * elements as "params".  Each element of the "result" array corresponds to the same element of the
26 |  * "params" array.  The "result" array elements may be interpreted as follows:
27 |  *
28 |  * o  A JSON object that does not contain an "error" member indicates that the operation completed
29 |  * successfully.  The specific members of the object are specified below in the descriptions of
30 |  * individual operations.  Some operations do not produce any results, in which case the object
31 |  * will
32 |  * have no members.
33 |  *
34 |  * o  An  indicates that the matching operation completed with an error.
35 |  *
36 |  * o  A JSON null value indicates that the operation was not attempted because a prior operation
37 |  * failed.
38 |  * }
39 |  * 
40 | */ 41 | @JsonDeserialize(using = OperationResultDeserializer.class) 42 | public abstract class OperationResult { 43 | 44 | } 45 | -------------------------------------------------------------------------------- /json-rpc/src/test/java/com/vmware/ovsdb/jsonrpc/v1/model/JsonRpcV1RequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.model; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import com.google.common.testing.EqualsTester; 20 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonRpcConstant; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import org.junit.Test; 23 | 24 | public class JsonRpcV1RequestTest { 25 | 26 | private final JsonRpcV1Request request = 27 | new JsonRpcV1Request("id-1", "foo", "string", 123, 4.5, true); 28 | 29 | private final String jsonString = "{\"" + JsonRpcConstant.METHOD + "\":\"foo\"," 30 | + "\"" + JsonRpcConstant.PARAMS + "\":[\"string\",123,4.5,true],\"" 31 | + JsonRpcConstant.ID + "\":\"id-1\"}"; 32 | 33 | @Test 34 | public void testSerialize() { 35 | assertEquals(jsonString, JsonUtil.serializeNoException(request)); 36 | } 37 | 38 | @Test 39 | public void testDeserialize() { 40 | assertEquals(request, JsonUtil.deserializeNoException(jsonString, JsonRpcV1Request.class)); 41 | } 42 | 43 | @Test 44 | public void testEquals() { 45 | new EqualsTester() 46 | .addEqualityGroup( 47 | new JsonRpcV1Request("id", "method", 123, 4.56), 48 | new JsonRpcV1Request("id", "method", 123, 4.56) 49 | ) 50 | .addEqualityGroup( 51 | new JsonRpcV1Request(null, "method"), 52 | new JsonRpcV1Request(null, "method") 53 | ).testEquals(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/schema/DatabaseSchemaTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import static org.junit.Assert.assertNotNull; 18 | import static org.mockito.Mockito.mock; 19 | 20 | 21 | import com.google.common.testing.EqualsTester; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import java.io.IOException; 24 | 25 | import com.vmware.ovsdb.protocol.operation.notation.Map; 26 | import org.junit.Test; 27 | 28 | public class DatabaseSchemaTest { 29 | 30 | @Test 31 | public void testVtepSchema() throws IOException { 32 | testDeserialization("/vtep_schema.json"); 33 | } 34 | 35 | @Test 36 | public void testVswitchSchema() throws IOException { 37 | testDeserialization("/vswitch_schema.json"); 38 | } 39 | 40 | private void testDeserialization(String schemaPath) throws IOException { 41 | // No exception means success 42 | DatabaseSchema dbSchema = JsonUtil.deserialize( 43 | getClass().getResource(schemaPath), 44 | DatabaseSchema.class 45 | ); 46 | assertNotNull(dbSchema); 47 | } 48 | 49 | @Test 50 | public void testEquals() throws IOException { 51 | new EqualsTester() 52 | .addEqualityGroup( 53 | JsonUtil.deserialize( 54 | getClass().getResource("/vswitch_schema.json"), DatabaseSchema.class 55 | ), 56 | JsonUtil.deserialize( 57 | getClass().getResource("/vswitch_schema.json"), DatabaseSchema.class 58 | ) 59 | ).testEquals(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/InsertTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | import static org.mockito.Mockito.mock; 19 | 20 | 21 | import com.fasterxml.jackson.core.JsonProcessingException; 22 | import com.google.common.testing.EqualsTester; 23 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 24 | import com.vmware.ovsdb.protocol.operation.notation.Row; 25 | import org.junit.Test; 26 | 27 | public class InsertTest { 28 | 29 | @Test 30 | public void testSerialization() throws JsonProcessingException { 31 | Row row = new Row().stringColumn("name", "ls1") 32 | .stringColumn("description", "first logical switch"); 33 | Insert insert = new Insert("Logical_Switch", row).withUuidName("insert_ls1"); 34 | 35 | String expectedResult 36 | = "{\"op\":\"insert\",\"table\":\"Logical_Switch\"," 37 | + "\"row\":{\"name\":\"ls1\",\"description\":\"first logical" 38 | + " switch\"}," + "\"uuid-name\":\"insert_ls1\"}"; 39 | assertEquals(expectedResult, JsonUtil.serialize(insert)); 40 | } 41 | 42 | @Test 43 | public void testEquals() { 44 | Row row = mock(Row.class); 45 | String tableName = "table"; 46 | new EqualsTester() 47 | .addEqualityGroup(new Insert(tableName, row), new Insert(tableName, row, null)) 48 | .addEqualityGroup( 49 | new Insert(tableName, row, "uuid-name"), 50 | new Insert(tableName, row).withUuidName("uuid-name") 51 | ).testEquals(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/methods/MonitorRequests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods; 16 | 17 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 18 | import com.vmware.ovsdb.protocol.methods.serializer.MonitorRequestsSerializer; 19 | 20 | import java.util.Map; 21 | import java.util.Objects; 22 | 23 | /** 24 | * The {@literal } object maps the name of the table to be monitored to an array 25 | * of {@literal } objects. 26 | */ 27 | @JsonSerialize(using = MonitorRequestsSerializer.class) 28 | public class MonitorRequests { 29 | 30 | private final Map monitorRequests; 31 | 32 | public MonitorRequests(Map monitorRequests) { 33 | this.monitorRequests = monitorRequests; 34 | } 35 | 36 | public Map getMonitorRequests() { 37 | return monitorRequests; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object other) { 42 | if (this == other) { 43 | return true; 44 | } 45 | if (!(other instanceof MonitorRequests)) { 46 | return false; 47 | } 48 | MonitorRequests that = (MonitorRequests) other; 49 | return Objects.equals(monitorRequests, that.getMonitorRequests()); 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | return Objects.hash(monitorRequests); 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return getClass().getSimpleName() + " [" 60 | + "monitorRequests=" + monitorRequests 61 | + "]"; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/deserializer/NamedUuidDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.databind.DeserializationContext; 19 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 20 | import com.fasterxml.jackson.databind.node.ArrayNode; 21 | import com.vmware.ovsdb.protocol.operation.notation.NamedUuid; 22 | import com.vmware.ovsdb.protocol.util.OvsdbConstant; 23 | 24 | import java.io.IOException; 25 | 26 | public class NamedUuidDeserializer extends StdDeserializer { 27 | 28 | protected NamedUuidDeserializer() { 29 | this(null); 30 | } 31 | 32 | protected NamedUuidDeserializer(Class vc) { 33 | super(vc); 34 | } 35 | 36 | @Override 37 | public NamedUuid deserialize( 38 | JsonParser jp, DeserializationContext ctxt 39 | ) throws IOException { 40 | ArrayNode arrayNode = jp.getCodec().readTree(jp); 41 | if (arrayNode.size() != 2) { 42 | throw new IOException( 43 | " should be a 2-element JSON array. Found " 44 | + arrayNode.size() + " elements"); 45 | } 46 | 47 | if (!OvsdbConstant.NAMED_UUID.equals(arrayNode.get(0).asText())) { 48 | throw new IOException( 49 | "First element of should be \"" 50 | + OvsdbConstant.NAMED_UUID + "\""); 51 | } 52 | 53 | String uuidName = arrayNode.get(1).asText(); 54 | return new NamedUuid(uuidName); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/methods/LockResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods; 16 | 17 | import com.fasterxml.jackson.annotation.JsonCreator; 18 | import com.fasterxml.jackson.annotation.JsonProperty; 19 | 20 | /** 21 | * Represent the result of lock operation. 22 | * 23 | *
24 |  * {@literal
25 |  * For a "lock" operation, the "locked" member in the response object is
26 |  * true if the lock has already been acquired and false if another
27 |  * client holds the lock and the client's request for it was queued.  In
28 |  * the latter case, the client will be notified later with a "locked"
29 |  * message (Section 4.1.9) when acquisition succeeds.
30 |  * }
31 |  * 
32 | */ 33 | public class LockResult { 34 | 35 | private boolean locked; 36 | 37 | @JsonCreator 38 | public LockResult(@JsonProperty(value = "locked", required = true) boolean locked) { 39 | this.locked = locked; 40 | } 41 | 42 | public boolean isLocked() { 43 | return locked; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object other) { 48 | if (this == other) { 49 | return true; 50 | } 51 | if (!(other instanceof LockResult)) { 52 | return false; 53 | } 54 | 55 | LockResult that = (LockResult) other; 56 | 57 | return locked == that.locked; 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return (locked ? 1 : 0); 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return getClass().getSimpleName() + " [" 68 | + "locked=" + locked 69 | + "]"; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/Assert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation; 16 | 17 | import static com.vmware.ovsdb.protocol.util.OvsdbConstant.ASSERT; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | *
23 |  * {@literal
24 |  * The assert object contains the following members:
25 |  *
26 |  *     "op": "assert"                     required
27 |  *     "lock":                        required
28 |  *
29 |  * Result object has no members.
30 |  *
31 |  * The assert operation causes the transaction to be aborted if the
32 |  * client does not own the lock named .
33 |  *
34 |  * The error that may be returned is:
35 |  *
36 |  * "error": "not owner"
37 |  *     The client does not own the named lock.
38 |  * }
39 |  * 
40 | */ 41 | public class Assert extends Operation { 42 | 43 | private final String lock; 44 | 45 | public Assert(String lock) { 46 | super(ASSERT); 47 | this.lock = lock; 48 | } 49 | 50 | public String getLock() { 51 | return lock; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object other) { 56 | if (this == other) { 57 | return true; 58 | } 59 | if (!(other instanceof Assert)) { 60 | return false; 61 | } 62 | Assert that = (Assert) other; 63 | return Objects.equals(lock, that.getLock()); 64 | } 65 | 66 | @Override 67 | public int hashCode() { 68 | return Objects.hash(lock); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return getClass().getSimpleName() + " [" 74 | + "lock=" + lock 75 | + "]"; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/methods/RowUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods; 16 | 17 | import com.fasterxml.jackson.annotation.JsonProperty; 18 | import com.vmware.ovsdb.protocol.operation.notation.Row; 19 | 20 | import java.util.Objects; 21 | 22 | public class RowUpdate { 23 | 24 | private Row oldRow; 25 | 26 | @JsonProperty(value = "new") 27 | private Row newRow; 28 | 29 | public RowUpdate() { 30 | } 31 | 32 | public RowUpdate(Row oldRow, Row newRow) { 33 | this.oldRow = oldRow; 34 | this.newRow = newRow; 35 | } 36 | 37 | public Row getOld() { 38 | return oldRow; 39 | } 40 | 41 | public RowUpdate setOld(Row oldRow) { 42 | this.oldRow = oldRow; 43 | return this; 44 | } 45 | 46 | public Row getNew() { 47 | return newRow; 48 | } 49 | 50 | public RowUpdate setNew(Row newRow) { 51 | this.newRow = newRow; 52 | return this; 53 | } 54 | 55 | @Override 56 | public boolean equals(Object other) { 57 | if (this == other) { 58 | return true; 59 | } 60 | if (!(other instanceof RowUpdate)) { 61 | return false; 62 | } 63 | RowUpdate rowUpdate = (RowUpdate) other; 64 | return Objects.equals(oldRow, rowUpdate.getOld()) 65 | && Objects.equals(newRow, rowUpdate.getNew()); 66 | } 67 | 68 | @Override 69 | public int hashCode() { 70 | return Objects.hash(oldRow, newRow); 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | return getClass().getSimpleName() + " [" 76 | + "old=" + oldRow 77 | + ", new=" + newRow 78 | + "]"; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /json-rpc/src/test/java/com/vmware/ovsdb/jsonrpc/v1/service/domain/SillyCalculator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.service.domain; 16 | 17 | import com.vmware.ovsdb.jsonrpc.v1.annotation.JsonRpcServiceMethod; 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | /** 23 | * A silly method handler that does foolproof calculation. 24 | */ 25 | public class SillyCalculator { 26 | 27 | @JsonRpcServiceMethod 28 | public int add(int a, int b) { 29 | return a + b; 30 | } 31 | 32 | @JsonRpcServiceMethod 33 | public int sub(int a, int b) { 34 | return a - b; 35 | } 36 | 37 | @JsonRpcServiceMethod 38 | public int mul(int a, int b) { 39 | return a * b; 40 | } 41 | 42 | @JsonRpcServiceMethod(value = "list_methods") 43 | public List listMethods() { 44 | return new ArrayList<>( 45 | Arrays.asList( 46 | "list_methods", 47 | "add", 48 | "sub", 49 | "mul", 50 | "echo", 51 | "print" 52 | ) 53 | ); 54 | } 55 | 56 | @JsonRpcServiceMethod 57 | public Object[] echo(Object... objects) { 58 | return objects; 59 | } 60 | 61 | @JsonRpcServiceMethod 62 | public void print(String msg, int num) { 63 | System.out.println(msg + num); 64 | } 65 | 66 | @JsonRpcServiceMethod 67 | public int sum(Integer... nums) { 68 | return Arrays.stream(nums).mapToInt(Integer::intValue).sum(); 69 | } 70 | 71 | @JsonRpcServiceMethod(value = "error_method") 72 | public void errorMethod(String msg) { 73 | throw new RuntimeException(msg); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/deserializer/ConditionDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.databind.DeserializationContext; 19 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 20 | import com.fasterxml.jackson.databind.node.ArrayNode; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import com.vmware.ovsdb.protocol.operation.notation.Condition; 23 | import com.vmware.ovsdb.protocol.operation.notation.Function; 24 | import com.vmware.ovsdb.protocol.operation.notation.Value; 25 | 26 | import java.io.IOException; 27 | 28 | public class ConditionDeserializer extends StdDeserializer { 29 | 30 | protected ConditionDeserializer() { 31 | this(null); 32 | } 33 | 34 | protected ConditionDeserializer(Class vc) { 35 | super(vc); 36 | } 37 | 38 | @Override 39 | public Condition deserialize( 40 | JsonParser jp, DeserializationContext ctxt 41 | ) throws IOException { 42 | ArrayNode arrayNode = jp.getCodec().readTree(jp); 43 | if (arrayNode.size() != 3) { 44 | throw new IOException( 45 | " should be a 3-element JSON array. Found " 46 | + arrayNode.size() + " elements"); 47 | } 48 | String column = arrayNode.get(0).asText(); 49 | String function = arrayNode.get(1).asText(); 50 | Value value = JsonUtil.treeToValueNoException(arrayNode.get(2), Value.class); 51 | return new Condition(column, Function.fromString(function), value); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/deserializer/PairDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.core.type.TypeReference; 19 | import com.fasterxml.jackson.databind.DeserializationContext; 20 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 21 | import com.fasterxml.jackson.databind.node.ArrayNode; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import com.vmware.ovsdb.protocol.operation.notation.Atom; 24 | import com.vmware.ovsdb.protocol.operation.notation.Pair; 25 | 26 | import java.io.IOException; 27 | 28 | public class PairDeserializer extends StdDeserializer> { 29 | 30 | protected PairDeserializer() { 31 | this(null); 32 | } 33 | 34 | protected PairDeserializer(Class vc) { 35 | super(vc); 36 | } 37 | 38 | @Override 39 | public Pair deserialize( 40 | JsonParser jp, DeserializationContext ctxt 41 | ) throws IOException { 42 | ArrayNode arrayNode = jp.getCodec().readTree(jp); 43 | if (arrayNode.size() != 2) { 44 | throw new IOException( 45 | " should be a 2-element JSON array. Found " 46 | + arrayNode.size() + " elements"); 47 | } 48 | 49 | Atom key = JsonUtil.treeToValueNoException( 50 | arrayNode.get(0), 51 | new TypeReference>() {} 52 | ); 53 | Atom value = JsonUtil.treeToValueNoException( 54 | arrayNode.get(1), 55 | new TypeReference>() {} 56 | ); 57 | return new Pair<>(key, value); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/deserializer/ValueDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.databind.DeserializationContext; 19 | import com.fasterxml.jackson.databind.JsonNode; 20 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import com.vmware.ovsdb.protocol.operation.notation.Atom; 23 | import com.vmware.ovsdb.protocol.operation.notation.Map; 24 | import com.vmware.ovsdb.protocol.operation.notation.Set; 25 | import com.vmware.ovsdb.protocol.operation.notation.Value; 26 | 27 | import java.io.IOException; 28 | 29 | public class ValueDeserializer extends StdDeserializer { 30 | 31 | protected ValueDeserializer() { 32 | this(null); 33 | } 34 | 35 | protected ValueDeserializer(Class vc) { 36 | super(vc); 37 | } 38 | 39 | @Override 40 | public Value deserialize( 41 | JsonParser jp, DeserializationContext ctxt 42 | ) throws IOException { 43 | JsonNode jsonNode = jp.getCodec().readTree(jp); 44 | Atom atom = JsonUtil.treeToValueNoException(jsonNode, Atom.class); 45 | if (atom != null) { 46 | return atom; 47 | } 48 | Set set = JsonUtil.treeToValueNoException(jsonNode, Set.class); 49 | if (set != null) { 50 | return set; 51 | } 52 | Map map = JsonUtil.treeToValueNoException(jsonNode, Map.class); 53 | if (map != null) { 54 | return map; 55 | } 56 | throw new IOException(jsonNode + " is not a valid "); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ovsdb-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | ovsdb-client-library 7 | com.vmware.ovsdb 8 | 1.0.1 9 | 10 | 4.0.0 11 | 12 | OVSDB Client 13 | ovsdb-client 14 | 15 | 16 | 17 | com.vmware.ovsdb 18 | json-rpc 19 | ${project.version} 20 | 21 | 22 | com.fasterxml.jackson.core 23 | jackson-core 24 | 25 | 26 | com.fasterxml.jackson.core 27 | jackson-databind 28 | 29 | 30 | com.fasterxml.jackson.core 31 | jackson-annotations 32 | 33 | 34 | io.netty 35 | netty-all 36 | 37 | 38 | 39 | com.spotify 40 | docker-client 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-failsafe-plugin 50 | ${mvn.failsafe.plugin.version} 51 | 52 | 53 | integration-test 54 | 55 | integration-test 56 | 57 | 58 | 59 | verify 60 | 61 | verify 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/notation/NamedUuidTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.google.common.testing.EqualsTester; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import java.io.IOException; 24 | import org.junit.Test; 25 | 26 | public class NamedUuidTest { 27 | 28 | private static final String uuidName = "uuid-name"; 29 | 30 | private String json = "[\"named-uuid\",\"" + uuidName + "\"]"; 31 | 32 | private NamedUuid namedUuid = new NamedUuid(uuidName); 33 | 34 | @Test 35 | public void testSerialization() throws JsonProcessingException { 36 | assertEquals(json, JsonUtil.serialize(namedUuid)); 37 | } 38 | 39 | @Test 40 | public void testDeserialization() throws IOException { 41 | assertEquals( 42 | namedUuid, 43 | JsonUtil.deserialize(json, NamedUuid.class) 44 | ); 45 | } 46 | 47 | @Test(expected = IOException.class) 48 | public void testInvalidNamedUuid1() throws IOException { 49 | String json = "[\"id\", \"" + uuidName + "\"]"; 50 | 51 | JsonUtil.deserialize(json, NamedUuid.class); 52 | } 53 | 54 | @Test(expected = IOException.class) 55 | public void testInvalidNamedUuid2() throws IOException { 56 | String json = "[\"" + uuidName + "\"]"; 57 | 58 | JsonUtil.deserialize(json, NamedUuid.class); 59 | } 60 | 61 | @Test 62 | public void testEquals() { 63 | new EqualsTester() 64 | .addEqualityGroup(new NamedUuid("uuid-name"), new NamedUuid("uuid-name")) 65 | .testEquals(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/service/OvsdbPassiveConnectionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.service; 16 | 17 | import com.vmware.ovsdb.callback.ConnectionCallback; 18 | import io.netty.handler.ssl.SslContext; 19 | 20 | import java.util.concurrent.CompletableFuture; 21 | 22 | public interface OvsdbPassiveConnectionListener { 23 | 24 | /** 25 | * Start listening on the specified port. 26 | * 27 | * @param port port to listen. Usually it is 6640 28 | * @param connectionCallback called when there is a connection from the OVSDB server 29 | * @return a {@link CompletableFuture} that will complete with true if listening starts 30 | * successfully or false otherwise 31 | */ 32 | CompletableFuture startListening(int port, ConnectionCallback connectionCallback); 33 | 34 | /** 35 | * Start listening on the specified port with SSL enabled. 36 | * 37 | * @param port port to listen. Usually it should be 6640 38 | * @param sslContext the SSL context used for SSL connection 39 | * @param connectionCallback called when there is a connection from the OVSDB server 40 | * @return a {@link CompletableFuture} that will complete with true if listening starts 41 | * successfully or false otherwise 42 | */ 43 | CompletableFuture startListeningWithSsl( 44 | int port, SslContext sslContext, ConnectionCallback connectionCallback 45 | ); 46 | 47 | /** 48 | * Stop listening on the given port. 49 | * 50 | * @param port the port to stop listening 51 | * @return a {@link CompletableFuture} that will complete with true if listening stops 52 | * successfully or false otherwise 53 | */ 54 | CompletableFuture stopListening(int port); 55 | } 56 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/notation/UuidTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.google.common.testing.EqualsTester; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import java.io.IOException; 24 | import java.util.UUID; 25 | import org.junit.Test; 26 | 27 | public class UuidTest { 28 | 29 | private static final Uuid uuid = new Uuid(UUID.randomUUID()); 30 | 31 | private static final String json = "[\"uuid\",\"" + uuid.getUuid() + "\"]"; 32 | 33 | @Test 34 | public void testSerialization() throws JsonProcessingException { 35 | assertEquals(json, JsonUtil.serialize(uuid)); 36 | } 37 | 38 | @Test 39 | public void testDeserialization() throws IOException { 40 | assertEquals(uuid, JsonUtil.deserialize(json, Uuid.class)); 41 | } 42 | 43 | @Test(expected = IOException.class) 44 | public void testInvalidUuid1() throws IOException { 45 | String json = "[\"id\", \"" + uuid + "\"]"; 46 | 47 | JsonUtil.deserialize(json, Uuid.class); 48 | } 49 | 50 | @Test(expected = IOException.class) 51 | public void testInvalidUuid2() throws IOException { 52 | String json = "[\"" + uuid + "\"]"; 53 | 54 | JsonUtil.deserialize(json, Uuid.class); 55 | } 56 | 57 | @Test(expected = IOException.class) 58 | public void testInvalidUuid3() throws IOException { 59 | String json = "[\"uuid\", \"123\"]"; 60 | 61 | JsonUtil.deserialize(json, Uuid.class); 62 | } 63 | 64 | @Test 65 | public void testEquals() { 66 | new EqualsTester().addEqualityGroup(uuid, Uuid.of(uuid.getUuid())).testEquals(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/notation/ValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import com.google.common.collect.ImmutableMap; 20 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 21 | import org.junit.Test; 22 | 23 | import java.io.IOException; 24 | import java.util.UUID; 25 | 26 | public class ValueTest { 27 | 28 | @Test 29 | public void testAtomValue() { 30 | assertEquals(Atom.string("123"), JsonUtil.deserializeNoException("\"123\"", Value.class)); 31 | assertEquals(Atom.integer(24), JsonUtil.deserializeNoException("24", Value.class)); 32 | assertEquals(Atom.bool(true), JsonUtil.deserializeNoException("true", Value.class)); 33 | UUID uuid = UUID.randomUUID(); 34 | assertEquals( 35 | Atom.uuid(uuid), 36 | JsonUtil.deserializeNoException("[\"uuid\",\"" + uuid + "\"]", Value.class) 37 | ); 38 | assertEquals( 39 | Atom.namedUuid("uuid-name"), 40 | JsonUtil.deserializeNoException("[\"named-uuid\",\"uuid-name\"]", Value.class) 41 | ); 42 | } 43 | 44 | @Test 45 | public void testSetValue() { 46 | assertEquals( 47 | Set.of("string1"), 48 | JsonUtil.deserializeNoException("[\"set\",[\"string1\"]]", Value.class) 49 | ); 50 | } 51 | 52 | @Test 53 | public void testMapValue() { 54 | assertEquals( 55 | Map.of(ImmutableMap.of("key", "value")), 56 | JsonUtil.deserializeNoException("[\"map\",[[\"key\",\"value\"]]]", Value.class) 57 | ); 58 | } 59 | 60 | @Test(expected = IOException.class) 61 | public void testInvalidValue() throws IOException { 62 | JsonUtil.deserialize("[\"value\",123]", Value.class); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/Commit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation; 16 | 17 | import static com.vmware.ovsdb.protocol.util.OvsdbConstant.COMMIT; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | *
23 |  * {@literal
24 |  * The "commit" object contains the following members:
25 |  *
26 |  *    "op": "commit"                      required
27 |  *    "durable":                 required
28 |  *
29 |  * There is no corresponding result object.
30 |  *
31 |  * If "durable" is specified as true, then the transaction, if it
32 |  * commits, will be stored durably (to disk) before the reply is sent to
33 |  * the client.  This operation with "durable" set to false is
34 |  * effectively a no-op.
35 |  *
36 |  * The error that may be returned is:
37 |  *
38 |  * "error": "not supported"
39 |  *    When "durable" is true, this database implementation does not
40 |  *    support durable commits.
41 |  * }
42 |  * 
43 | */ 44 | public class Commit extends Operation { 45 | 46 | private final boolean durable; 47 | 48 | public Commit(boolean durable) { 49 | super(COMMIT); 50 | this.durable = durable; 51 | } 52 | 53 | public boolean isDurable() { 54 | return durable; 55 | } 56 | 57 | @Override 58 | public boolean equals(Object other) { 59 | if (this == other) { 60 | return true; 61 | } 62 | if (!(other instanceof Commit)) { 63 | return false; 64 | } 65 | Commit that = (Commit) other; 66 | return durable == that.isDurable(); 67 | } 68 | 69 | @Override 70 | public int hashCode() { 71 | 72 | return Objects.hash(durable); 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return getClass().getSimpleName() + " [" + "durable=" + durable + "]"; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/deserializer/MapDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.core.type.TypeReference; 19 | import com.fasterxml.jackson.databind.DeserializationContext; 20 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 21 | import com.fasterxml.jackson.databind.node.ArrayNode; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import com.vmware.ovsdb.protocol.operation.notation.Map; 24 | import com.vmware.ovsdb.protocol.operation.notation.Pair; 25 | import com.vmware.ovsdb.protocol.util.OvsdbConstant; 26 | 27 | import java.io.IOException; 28 | import java.util.List; 29 | 30 | public class MapDeserializer extends StdDeserializer> { 31 | 32 | protected MapDeserializer() { 33 | this(null); 34 | } 35 | 36 | protected MapDeserializer(Class vc) { 37 | super(vc); 38 | } 39 | 40 | @Override 41 | public Map deserialize( 42 | JsonParser jp, DeserializationContext ctxt 43 | ) throws IOException { 44 | ArrayNode arrayNode = jp.getCodec().readTree(jp); 45 | if (arrayNode.size() != 2) { 46 | throw new IOException( 47 | " should be a 2-element JSON array. Found " 48 | + arrayNode.size() + " elements"); 49 | } 50 | 51 | if (!OvsdbConstant.MAP.equals(arrayNode.get(0).asText())) { 52 | throw new IOException( 53 | "First element of should be \"" + OvsdbConstant.MAP 54 | + "\""); 55 | } 56 | 57 | List> pairs = JsonUtil.treeToValueNoException( 58 | arrayNode.get(1), new TypeReference>>() {} 59 | ); 60 | return new Map<>(pairs); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/deserializer/UuidDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.core.JsonProcessingException; 19 | import com.fasterxml.jackson.databind.DeserializationContext; 20 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 21 | import com.fasterxml.jackson.databind.node.ArrayNode; 22 | import com.vmware.ovsdb.protocol.operation.notation.Uuid; 23 | import com.vmware.ovsdb.protocol.util.OvsdbConstant; 24 | 25 | import java.io.IOException; 26 | import java.util.UUID; 27 | 28 | public class UuidDeserializer extends StdDeserializer { 29 | 30 | protected UuidDeserializer() { 31 | this(null); 32 | } 33 | 34 | protected UuidDeserializer(Class vc) { 35 | super(vc); 36 | } 37 | 38 | @Override 39 | public Uuid deserialize( 40 | JsonParser jp, DeserializationContext ctxt 41 | ) throws IOException, JsonProcessingException { 42 | ArrayNode arrayNode = jp.getCodec().readTree(jp); 43 | if (arrayNode.size() != 2) { 44 | throw new IOException( 45 | " should be a 2-element JSON array. Found " 46 | + arrayNode.size() + " elements"); 47 | } 48 | 49 | if (!OvsdbConstant.UUID.equals(arrayNode.get(0).asText())) { 50 | throw new IOException( 51 | "First element of should be \"" 52 | + OvsdbConstant.UUID + "\""); 53 | } 54 | 55 | String strUuid = arrayNode.get(1).asText(); 56 | UUID uuid; 57 | try { 58 | uuid = UUID.fromString(strUuid); 59 | } catch (IllegalArgumentException ex) { 60 | throw new IOException("Invalid UUID " + strUuid, ex); 61 | } 62 | return new Uuid(uuid); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/notation/MapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.google.common.collect.ImmutableList; 22 | import com.google.common.collect.ImmutableMap; 23 | import com.google.common.testing.EqualsTester; 24 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 25 | import java.io.IOException; 26 | import org.junit.Test; 27 | 28 | public class MapTest { 29 | 30 | private static final String jsonString 31 | = "[\"map\",[[\"key1\",\"value1\"],[\"key2\",\"value2\"]]]"; 32 | 33 | private static final Map map = new Map<>( 34 | ImmutableList.of( 35 | new Pair<>(Atom.string("key1"), Atom.string("value1")), 36 | new Pair<>(Atom.string("key2"), Atom.string("value2")) 37 | ) 38 | ); 39 | 40 | @Test 41 | public void testSerialization() throws JsonProcessingException { 42 | assertEquals(jsonString, JsonUtil.serialize(map)); 43 | } 44 | 45 | @Test 46 | public void testDeserialization() throws IOException { 47 | assertEquals(map, JsonUtil.deserialize(jsonString, Map.class)); 48 | } 49 | 50 | @Test(expected = IOException.class) 51 | public void testInvalidMap1() throws IOException { 52 | JsonUtil.deserialize("[[123, 456]]", Map.class); 53 | } 54 | 55 | @Test(expected = IOException.class) 56 | public void testInvalidMap2() throws IOException { 57 | JsonUtil.deserialize("[\"not-map\",[123, 456]]", Map.class); 58 | } 59 | 60 | @Test 61 | public void testEquals() { 62 | new EqualsTester() 63 | .addEqualityGroup(map, Map.of(ImmutableMap.of("key1", "value1", "key2", "value2"))) 64 | .testEquals(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import com.fasterxml.jackson.annotation.JsonFormat; 18 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 19 | import com.vmware.ovsdb.protocol.operation.notation.deserializer.PairDeserializer; 20 | 21 | import java.util.Objects; 22 | 23 | /** 24 | * Representation of {@literal }. 25 | * 26 | *
27 |  * {@literal
28 |  * 
29 |  *   A 2-element JSON array that represents a pair within a database
30 |  *   map.  The first element is an  that represents the key, and
31 |  *   the second element is an  that represents the value.
32 |  * }
33 |  * 
34 | */ 35 | @JsonFormat(shape = JsonFormat.Shape.ARRAY) 36 | @JsonDeserialize(using = PairDeserializer.class) 37 | public class Pair { 38 | 39 | private final Atom key; 40 | 41 | private final Atom value; 42 | 43 | public Pair(Atom key, Atom value) { 44 | this.key = key; 45 | this.value = value; 46 | } 47 | 48 | public Atom getKey() { 49 | return key; 50 | } 51 | 52 | public Atom getValue() { 53 | return value; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object other) { 58 | if (this == other) { 59 | return true; 60 | } 61 | if (!(other instanceof Pair)) { 62 | return false; 63 | } 64 | Pair that = (Pair) other; 65 | return Objects.equals(key, that.getKey()) 66 | && Objects.equals(value, that.getValue()); 67 | } 68 | 69 | @Override 70 | public int hashCode() { 71 | return Objects.hash(key, value); 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return getClass().getSimpleName() + " [" 77 | + "key=" + key 78 | + ", value=" + value 79 | + "]"; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/notation/PairTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import com.fasterxml.jackson.core.JsonProcessingException; 20 | import com.google.common.testing.EqualsTester; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import java.io.IOException; 23 | import java.util.UUID; 24 | 25 | import org.junit.Test; 26 | 27 | public class PairTest { 28 | 29 | @Test 30 | public void testSerialization() throws JsonProcessingException { 31 | String expectedString = "[\"string\",123]"; 32 | Pair pair = new Pair<>( 33 | Atom.string("string"), Atom.integer(123)); 34 | assertEquals(expectedString, JsonUtil.serialize(pair)); 35 | } 36 | 37 | @Test 38 | public void testDeserialization() throws IOException { 39 | String jsonString = "[\"string\",123]"; 40 | Pair pair = new Pair<>( 41 | Atom.string("string"), Atom.integer(123)); 42 | assertEquals(pair, JsonUtil.deserialize(jsonString, Pair.class)); 43 | } 44 | 45 | @Test(expected = IOException.class) 46 | public void testInvalidPair1() throws IOException { 47 | String jsonString = "[\"string\",123,true]"; 48 | JsonUtil.deserialize(jsonString, Pair.class); 49 | } 50 | 51 | @Test(expected = IOException.class) 52 | public void testInvalidPair2() throws IOException { 53 | String jsonString = "[\"string\"]"; 54 | JsonUtil.deserialize(jsonString, Pair.class); 55 | } 56 | 57 | @Test 58 | public void testEquals() { 59 | UUID uuid = UUID.randomUUID(); 60 | new EqualsTester() 61 | .addEqualityGroup( 62 | new Pair<>(Atom.string("uuid"), Atom.uuid(uuid)), 63 | new Pair<>(new Atom<>("uuid"), new Atom<>(Uuid.of(uuid))) 64 | ).testEquals(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/notation/ConditionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.google.common.testing.EqualsTester; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import java.io.IOException; 24 | import org.junit.Test; 25 | 26 | public class ConditionTest { 27 | 28 | private final String jsonString1 = "[\"name\",\"==\",\"ls1\"]"; 29 | 30 | private final Condition condition1 = new Condition( 31 | "name", Function.EQUALS, Atom.string("ls1")); 32 | 33 | private final String jsonString2 34 | = "[\"numbers\",\"includes\",[\"set\",[1,2,3,4]]]"; 35 | 36 | private final Condition condition2 = new Condition( 37 | "numbers", Function.INCLUDES, Set.of(1L, 2L, 3L, 4L) 38 | ); 39 | 40 | @Test 41 | public void testSerialization() throws JsonProcessingException { 42 | assertEquals(jsonString1, JsonUtil.serialize(condition1)); 43 | assertEquals(jsonString2, JsonUtil.serialize(condition2)); 44 | } 45 | 46 | @Test 47 | public void testDeserialization() throws IOException { 48 | assertEquals( 49 | condition1, JsonUtil.deserialize(jsonString1, Condition.class)); 50 | 51 | assertEquals( 52 | condition2, JsonUtil.deserialize(jsonString2, Condition.class)); 53 | } 54 | 55 | @Test(expected = IOException.class) 56 | public void testInvalidCondition1() throws IOException { 57 | JsonUtil.deserialize("[\"name\"]", Condition.class); 58 | } 59 | 60 | @Test 61 | public void testEquals() { 62 | new EqualsTester() 63 | .addEqualityGroup(new Condition("name", Function.EQUALS, Atom.string("name1")), 64 | new Condition("name", Function.EQUALS, new Atom<>("name1"))) 65 | .testEquals(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/schema/ColumnSchemaTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | import static org.mockito.Mockito.mock; 19 | 20 | 21 | import com.google.common.testing.EqualsTester; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import com.vmware.ovsdb.protocol.operation.notation.Atom; 24 | import java.io.IOException; 25 | import org.junit.Test; 26 | 27 | public class ColumnSchemaTest { 28 | 29 | @Test 30 | public void testDeserialization() throws IOException { 31 | BaseType stringType = new StringBaseType( 32 | Atom.string("vxlan_over_ipv4")); 33 | ColumnSchema expectedResult = new ColumnSchema( 34 | new Type(stringType), null, false); 35 | 36 | String textSchema = "{\"type\":{\"key\":{\"type\":\"string\"," 37 | + "\"enum\":\"vxlan_over_ipv4\"}},\"mutable\":false}"; 38 | assertEquals( 39 | expectedResult, 40 | JsonUtil.deserialize(textSchema, ColumnSchema.class) 41 | ); 42 | 43 | expectedResult = new ColumnSchema( 44 | new Type(new UuidBaseType("Logical_Switch", null))); 45 | textSchema = "{\"type\":{\"key\":{\"type\":\"uuid\"," 46 | + "\"refTable\":\"Logical_Switch\"}}}"; 47 | assertEquals( 48 | expectedResult, 49 | JsonUtil.deserialize(textSchema, ColumnSchema.class) 50 | ); 51 | } 52 | 53 | @Test(expected = IOException.class) 54 | public void testInvalidJson() throws IOException { 55 | String textSchema = "{\"mutable\":false}"; 56 | JsonUtil.deserialize(textSchema, ColumnSchema.class); 57 | } 58 | 59 | @Test 60 | public void testEquals() { 61 | Type type = mock(Type.class); 62 | new EqualsTester() 63 | .addEqualityGroup(new ColumnSchema(type), new ColumnSchema(type, null, null)) 64 | .addEqualityGroup(new ColumnSchema(type, true, false), new ColumnSchema(type, true, false)) 65 | .testEquals(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/util/PropertyManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.util; 16 | 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.lang.invoke.MethodHandles; 23 | import java.util.Properties; 24 | import java.util.function.Function; 25 | 26 | public class PropertyManager { 27 | 28 | private static final Logger LOGGER = LoggerFactory.getLogger( 29 | MethodHandles.lookup().lookupClass()); 30 | 31 | private static final Properties properties = new Properties(); 32 | 33 | private static final String PROPERTY_FILE_NAME = "ovsdb-client.properties"; 34 | 35 | static { 36 | ClassLoader classLoader = PropertyManager.class.getClassLoader(); 37 | if (classLoader != null) { 38 | InputStream is = classLoader.getResourceAsStream(PROPERTY_FILE_NAME); 39 | try { 40 | properties.load(is); 41 | } catch (IOException ex) { 42 | LOGGER.error("Failed to load properties", ex); 43 | } finally { 44 | try { 45 | is.close(); 46 | } catch (IOException ex) { 47 | LOGGER.error("Failed to close {}", PROPERTY_FILE_NAME); 48 | } 49 | } 50 | } 51 | } 52 | 53 | private static T getProperty(String propertyName, T defaultValue, 54 | Function converter) { 55 | String value = properties.getProperty(propertyName); 56 | try { 57 | return converter.apply(value); 58 | } catch (Throwable ex) { 59 | LOGGER.error("Failed to get property: " + propertyName, ex); 60 | } 61 | return defaultValue; 62 | } 63 | 64 | public static int getIntProperty(String propertyName, int defaultValue) { 65 | return getProperty(propertyName, defaultValue, Integer::valueOf); 66 | } 67 | 68 | public static long getLongProperty(String propertyName, long defaultValue) { 69 | return getProperty(propertyName, defaultValue, Long::valueOf); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/methods/MonitorSelectTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.google.common.testing.EqualsTester; 22 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 23 | import org.junit.Test; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | public class MonitorSelectTest { 29 | 30 | @Test 31 | public void testSerialization() throws JsonProcessingException { 32 | String expectedResult 33 | = "{\"initial\":true,\"insert\":true,\"delete\":true," 34 | + "\"modify\":true}"; 35 | MonitorSelect monitorSelect = new MonitorSelect(true, true, true, true); 36 | 37 | assertEquals(expectedResult, JsonUtil.serialize(monitorSelect)); 38 | 39 | expectedResult = "{\"initial\":false,\"insert\":true,\"delete\":true}"; 40 | monitorSelect = new MonitorSelect(false, true, true, null); 41 | 42 | assertEquals(expectedResult, JsonUtil.serialize(monitorSelect)); 43 | 44 | expectedResult = "{}"; 45 | monitorSelect = new MonitorSelect(); 46 | 47 | assertEquals(expectedResult, JsonUtil.serialize(monitorSelect)); 48 | } 49 | 50 | @Test 51 | public void testEquals() { 52 | EqualsTester equalsTester = new EqualsTester(); 53 | Boolean[] booleans = {null, true, false}; 54 | for (Boolean initial : booleans) { 55 | for (Boolean insert : booleans) { 56 | for (Boolean delete : booleans) { 57 | for (Boolean modify : booleans) { 58 | equalsTester.addEqualityGroup( 59 | new MonitorSelect(initial, insert, delete, modify), 60 | new MonitorSelect().setInitial(initial).setInsert(insert) 61 | .setDelete(delete).setModify(modify) 62 | ); 63 | } 64 | } 65 | } 66 | } 67 | equalsTester.testEquals(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/schema/AtomicTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import static com.vmware.ovsdb.protocol.schema.Constants.JSON_BOOLEAN; 18 | import static com.vmware.ovsdb.protocol.schema.Constants.JSON_INTEGER; 19 | import static com.vmware.ovsdb.protocol.schema.Constants.JSON_REAL; 20 | import static com.vmware.ovsdb.protocol.schema.Constants.JSON_STRING; 21 | import static com.vmware.ovsdb.protocol.schema.Constants.JSON_UUID; 22 | import static org.junit.Assert.assertEquals; 23 | 24 | 25 | import com.fasterxml.jackson.core.JsonProcessingException; 26 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 27 | import java.io.IOException; 28 | import org.junit.Test; 29 | 30 | public class AtomicTypeTest { 31 | 32 | @Test 33 | public void testDeserialization() throws JsonProcessingException { 34 | assertEquals( 35 | JSON_INTEGER, JsonUtil.serialize(AtomicType.INTEGER)); 36 | assertEquals( 37 | JSON_REAL, JsonUtil.serialize(AtomicType.REAL)); 38 | assertEquals( 39 | JSON_BOOLEAN, JsonUtil.serialize(AtomicType.BOOLEAN)); 40 | assertEquals( 41 | JSON_STRING, JsonUtil.serialize(AtomicType.STRING)); 42 | assertEquals( 43 | JSON_UUID, JsonUtil.serialize(AtomicType.UUID)); 44 | } 45 | 46 | @Test 47 | public void testSerialization() throws IOException { 48 | assertEquals( 49 | AtomicType.INTEGER, 50 | JsonUtil.deserialize(JSON_INTEGER, AtomicType.class) 51 | ); 52 | assertEquals( 53 | AtomicType.REAL, 54 | JsonUtil.deserialize(JSON_REAL, AtomicType.class) 55 | ); 56 | assertEquals( 57 | AtomicType.BOOLEAN, 58 | JsonUtil.deserialize(JSON_BOOLEAN, AtomicType.class) 59 | ); 60 | assertEquals( 61 | AtomicType.STRING, 62 | JsonUtil.deserialize(JSON_STRING, AtomicType.class) 63 | ); 64 | assertEquals( 65 | AtomicType.UUID, 66 | JsonUtil.deserialize(JSON_UUID, AtomicType.class) 67 | ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /json-rpc/src/main/java/com/vmware/ovsdb/jsonrpc/v1/service/JsonRpcV1Client.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.service; 16 | 17 | import com.fasterxml.jackson.databind.JsonNode; 18 | import com.vmware.ovsdb.jsonrpc.v1.exception.JsonRpcException; 19 | 20 | import java.util.concurrent.CompletableFuture; 21 | 22 | /** 23 | * Interface for a JSON-RPC 1.0 client, with which a user can send request and notification to a 24 | * remote JSON-RPC server. 25 | */ 26 | public interface JsonRpcV1Client { 27 | 28 | /** 29 | * Send a JSON-RPC request. The id must be unique among all calls. 30 | * 31 | * @param id a unique ID for the call 32 | * @param method method name 33 | * @param returnType return type of the method 34 | * @param params params of the method 35 | * @return a {@link CompletableFuture} to get the method result from 36 | * @throws JsonRpcException if fail to send the request 37 | * @see JSON-RPC 1.0 Specification 38 | */ 39 | CompletableFuture call(String id, String method, Class returnType, Object... params) 40 | throws JsonRpcException; 41 | 42 | /** 43 | * Send a JSON-RPC notification. 44 | * 45 | * @param method method name 46 | * @param params params of the method 47 | * @throws JsonRpcException if fail to send the request 48 | * @see JSON-RPC 1.0 Specification 49 | */ 50 | void notify(String method, Object... params) throws JsonRpcException; 51 | 52 | /** 53 | * Handle a response. This method should be called by the transporter when a response is 54 | * received. 55 | * 56 | * @param responseNode the response {@link JsonNode} 57 | */ 58 | void handleResponse(JsonNode responseNode) throws JsonRpcException; 59 | 60 | /** 61 | * Shutdown this client. After it is called, no other methods shall be called on this client any 62 | * more. Exceptions will be thrown for calls that have no response yet. 63 | */ 64 | void shutdown(); 65 | } 66 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/service/OvsdbClientActiveConnectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.service; 16 | 17 | import com.vmware.ovsdb.exception.OvsdbClientException; 18 | import com.vmware.ovsdb.service.impl.OvsdbActiveConnectionConnectorImpl; 19 | import com.vmware.ovsdb.testutils.PassiveOvsdbServerEmulator; 20 | import io.netty.handler.ssl.SslContext; 21 | import org.junit.After; 22 | import org.junit.Test; 23 | 24 | import java.io.IOException; 25 | 26 | public class OvsdbClientActiveConnectionTest extends OvsdbClientTest { 27 | 28 | private static final OvsdbActiveConnectionConnector activeConnector 29 | = new OvsdbActiveConnectionConnectorImpl(executorService); 30 | 31 | private static final PassiveOvsdbServerEmulator passiveOvsdbServer = 32 | new PassiveOvsdbServerEmulator(PORT); 33 | 34 | public OvsdbClientActiveConnectionTest() { 35 | super(passiveOvsdbServer); 36 | } 37 | 38 | @After 39 | public void tearDown() { 40 | super.teardown(); 41 | passiveOvsdbServer.stopListening().join(); 42 | } 43 | 44 | @Override 45 | void setUp(boolean withSsl) { 46 | if (!withSsl) { 47 | passiveOvsdbServer.startListening().join(); 48 | ovsdbClient = activeConnector.connect(HOST, PORT).join(); 49 | } else { 50 | // In passive connection test, the controller is the server and the ovsdb-server is the client 51 | SslContext serverSslCtx = sslContextPair.getServerSslCtx(); 52 | SslContext clientSslCtx = sslContextPair.getClientSslCtx(); 53 | passiveOvsdbServer.startListeningWithSsl(serverSslCtx).join(); 54 | ovsdbClient = activeConnector.connectWithSsl(HOST, PORT, clientSslCtx).join(); 55 | } 56 | } 57 | 58 | @Test(timeout = TEST_TIMEOUT_MILLIS) 59 | public void testTcpConnection() throws OvsdbClientException, IOException { 60 | super.testTcpConnection(); 61 | } 62 | 63 | @Test(timeout = TEST_TIMEOUT_MILLIS) 64 | public void testSslConnection() throws OvsdbClientException, IOException { 65 | super.testSslConnection(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/deserializer/AtomDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.databind.DeserializationContext; 19 | import com.fasterxml.jackson.databind.JsonNode; 20 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import com.vmware.ovsdb.protocol.operation.notation.Atom; 23 | import com.vmware.ovsdb.protocol.operation.notation.NamedUuid; 24 | import com.vmware.ovsdb.protocol.operation.notation.Uuid; 25 | 26 | import java.io.IOException; 27 | 28 | public class AtomDeserializer extends StdDeserializer { 29 | 30 | protected AtomDeserializer() { 31 | this(null); 32 | } 33 | 34 | protected AtomDeserializer(Class vc) { 35 | super(vc); 36 | } 37 | 38 | @Override 39 | public Atom deserialize( 40 | JsonParser jp, DeserializationContext ctxt 41 | ) throws IOException { 42 | JsonNode jsonNode = jp.getCodec().readTree(jp); 43 | if (jsonNode.isTextual()) { 44 | // 45 | return Atom.string(jsonNode.asText()); 46 | } else if (jsonNode.isIntegralNumber()) { 47 | // 48 | return Atom.integer(jsonNode.asLong()); 49 | } else if (jsonNode.isDouble()) { 50 | // 51 | return Atom.real(jsonNode.asDouble()); 52 | } else if (jsonNode.isBoolean()) { 53 | // 54 | return Atom.bool(jsonNode.asBoolean()); 55 | } else if (jsonNode.isArray()) { 56 | // 57 | Uuid uuid = JsonUtil.treeToValueNoException(jsonNode, Uuid.class); 58 | if (uuid != null) { 59 | return Atom.uuid(uuid); 60 | } 61 | // 62 | NamedUuid namedUuid = JsonUtil.treeToValueNoException(jsonNode, NamedUuid.class); 63 | if (namedUuid != null) { 64 | return Atom.namedUuid(namedUuid); 65 | } 66 | } 67 | throw new IOException(jsonNode + " is not a valid "); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/schema/BooleanBaseTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import static com.vmware.ovsdb.protocol.schema.Constants.JSON_BOOLEAN; 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import com.google.common.testing.EqualsTester; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import com.vmware.ovsdb.protocol.operation.notation.Atom; 23 | import com.vmware.ovsdb.protocol.operation.notation.Set; 24 | import org.junit.Test; 25 | 26 | import java.io.IOException; 27 | 28 | public class BooleanBaseTypeTest { 29 | 30 | @Test 31 | public void testDeserialization() throws IOException { 32 | // Test atomic type as base type 33 | BaseType expectedResult = BaseType.atomicType(AtomicType.BOOLEAN); 34 | String jsonBaseType = JSON_BOOLEAN; 35 | 36 | assertEquals( 37 | expectedResult, 38 | JsonUtil.deserialize(jsonBaseType, BaseType.class) 39 | ); 40 | 41 | // Test boolean type that has only "type" field 42 | jsonBaseType = "{\"type\":" + JSON_BOOLEAN + "}"; 43 | assertEquals( 44 | expectedResult, 45 | JsonUtil.deserialize(jsonBaseType, BaseType.class) 46 | ); 47 | 48 | // Test boolean base type with enum of single value 49 | jsonBaseType = "{\"type\":" + JSON_BOOLEAN + ", \"enum\":false}"; 50 | expectedResult = new BooleanBaseType(Atom.bool(false)); 51 | assertEquals( 52 | expectedResult, 53 | JsonUtil.deserialize(jsonBaseType, BaseType.class) 54 | ); 55 | 56 | // Test boolean base type with enum of set value 57 | jsonBaseType = "{\"type\":" + JSON_BOOLEAN + ", \"enum\":[\"set\", [true, false]]}"; 58 | Set enums = Set.of(true, false); 59 | expectedResult = new BooleanBaseType(enums); 60 | assertEquals( 61 | expectedResult, 62 | JsonUtil.deserialize(jsonBaseType, BaseType.class) 63 | ); 64 | } 65 | 66 | @Test 67 | public void testEquals() { 68 | new EqualsTester().addEqualityGroup(new BooleanBaseType(), new BooleanBaseType()).testEquals(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/service/impl/OvsdbActiveConnectionConnectorImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.service.impl; 16 | 17 | import static com.vmware.ovsdb.netty.OvsdbChannelInitializer.newOvsdbChannelInitializer; 18 | 19 | import com.vmware.ovsdb.service.OvsdbActiveConnectionConnector; 20 | import com.vmware.ovsdb.service.OvsdbClient; 21 | import io.netty.bootstrap.Bootstrap; 22 | import io.netty.channel.ChannelFuture; 23 | import io.netty.channel.ChannelOption; 24 | import io.netty.channel.EventLoopGroup; 25 | import io.netty.channel.nio.NioEventLoopGroup; 26 | import io.netty.channel.socket.nio.NioSocketChannel; 27 | import io.netty.handler.ssl.SslContext; 28 | 29 | import java.util.concurrent.CompletableFuture; 30 | import java.util.concurrent.ScheduledExecutorService; 31 | 32 | public class OvsdbActiveConnectionConnectorImpl implements OvsdbActiveConnectionConnector { 33 | 34 | private final ScheduledExecutorService executorService; 35 | 36 | public OvsdbActiveConnectionConnectorImpl(ScheduledExecutorService executorService) { 37 | this.executorService = executorService; 38 | } 39 | 40 | @Override 41 | public CompletableFuture connect(String ip, int port) { 42 | return doConnect(ip, port, null); 43 | } 44 | 45 | @Override 46 | public CompletableFuture connectWithSsl(String ip, int port, SslContext sslContext) { 47 | return doConnect(ip, port, sslContext); 48 | } 49 | 50 | private CompletableFuture doConnect(String ip, int port, SslContext sslContext) { 51 | CompletableFuture ovsdbClientFuture = new CompletableFuture<>(); 52 | EventLoopGroup group = new NioEventLoopGroup(); 53 | Bootstrap bootstrap = new Bootstrap(); 54 | bootstrap.group(group) 55 | .channel(NioSocketChannel.class) 56 | .option(ChannelOption.TCP_NODELAY, true) 57 | .handler(newOvsdbChannelInitializer(sslContext, executorService, ovsdbClientFuture)); 58 | ChannelFuture channelFuture = bootstrap.connect(ip, port); 59 | channelFuture.channel().closeFuture() 60 | .addListener(future -> group.shutdownGracefully()); 61 | return ovsdbClientFuture; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/testutils/ActiveOvsdbServerEmulator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.testutils; 16 | 17 | import io.netty.bootstrap.Bootstrap; 18 | import io.netty.channel.ChannelOption; 19 | import io.netty.channel.EventLoopGroup; 20 | import io.netty.channel.nio.NioEventLoopGroup; 21 | import io.netty.channel.socket.nio.NioSocketChannel; 22 | import io.netty.handler.ssl.SslContext; 23 | 24 | import java.util.concurrent.CompletableFuture; 25 | 26 | /** 27 | * An ovsdb-server emulator that actively connects a controller. 28 | */ 29 | public class ActiveOvsdbServerEmulator extends OvsdbServerEmulator { 30 | 31 | private final String host; 32 | 33 | private final int port; 34 | 35 | /** 36 | * Create an {@link ActiveOvsdbServerEmulator} object. 37 | * 38 | * @param host ip address of the controller that this ovsdb-server emulator will connect to 39 | * @param port port of the controller that this ovsdb-server emulator will connect to 40 | */ 41 | public ActiveOvsdbServerEmulator(String host, int port) { 42 | this.host = host; 43 | this.port = port; 44 | } 45 | 46 | /** 47 | * Connect to a server on host:port. This is a asynchronous call. 48 | */ 49 | public CompletableFuture connect() { 50 | return doConnect(null); 51 | } 52 | 53 | /** 54 | * Connect to a server on host:port. This is a synchronous call. 55 | * 56 | * @param sslCtx the {@link SslContext} for the connection 57 | */ 58 | public CompletableFuture connectWithSsl(SslContext sslCtx) { 59 | return doConnect(sslCtx); 60 | } 61 | 62 | private CompletableFuture doConnect(SslContext sslCtx) { 63 | CompletableFuture connectedFuture = new CompletableFuture<>(); 64 | EventLoopGroup group = new NioEventLoopGroup(); 65 | Bootstrap b = new Bootstrap(); 66 | b.group(group).channel(NioSocketChannel.class) 67 | .option(ChannelOption.TCP_NODELAY, true) 68 | .handler(new OvsdbChannelInitializer(sslCtx, connectedFuture, false)); 69 | b.connect(host, port).channel().closeFuture() 70 | .addListener(future -> group.shutdownGracefully()); 71 | return connectedFuture; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/Comment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation; 16 | 17 | import static com.vmware.ovsdb.protocol.util.OvsdbConstant.COMMENT; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | *
23 |  * {@literal
24 |  * The "comment" object contains the following members:
25 |  *
26 |  *    "op": "comment"                    required
27 |  *    "comment":                 required
28 |  *
29 |  * There is no corresponding result object.
30 |  *
31 |  * The operation provides information to a database administrator on the
32 |  * purpose of a transaction.  The ovsdb-server implementation, for
33 |  * example, adds comments in transactions that modify the database to
34 |  * the database journal.  This can be helpful in debugging, e.g., when
35 |  * there are multiple clients writing to a database.  An example of this
36 |  * can be seen in the ovs-vsctl tool, a command line tool that interacts
37 |  * with ovsdb-server.  When performing operations on the database, it
38 |  * includes the command that was invoked (e.g., "ovs-vsctl add-br br0")
39 |  * as a comment in the transaction, which can then be seen in the
40 |  * journal alongside the changes that were made to the tables in the
41 |  * database.
42 |  * }
43 |  * 
44 | */ 45 | public class Comment extends Operation { 46 | 47 | private final String comment; 48 | 49 | // TODO: Consider using the validation framework 50 | public Comment(String comment) { 51 | super(COMMENT); 52 | this.comment = comment; 53 | } 54 | 55 | public String getComment() { 56 | return comment; 57 | } 58 | 59 | @Override 60 | public boolean equals(Object other) { 61 | if (this == other) { 62 | return true; 63 | } 64 | if (!(other instanceof Comment)) { 65 | return false; 66 | } 67 | Comment that = (Comment) other; 68 | return Objects.equals(comment, that.getComment()); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(comment); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return getClass().getSimpleName() + " [" 79 | + "comment=" + comment 80 | + "]"; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/methods/TableUpdateTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import com.google.common.collect.ImmutableMap; 20 | import com.google.common.testing.EqualsTester; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import com.vmware.ovsdb.protocol.operation.notation.Atom; 23 | import com.vmware.ovsdb.protocol.operation.notation.Row; 24 | import org.junit.Test; 25 | 26 | import java.io.IOException; 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | import java.util.UUID; 30 | 31 | public class TableUpdateTest { 32 | 33 | @Test 34 | public void testDeserialization() throws IOException { 35 | Row old1 = new Row(ImmutableMap.of( 36 | "name", Atom.string("ls1"), 37 | "description", Atom.string("First Logical Switch"), 38 | "tunnel_key", Atom.integer(5001) 39 | )); 40 | 41 | Row new1 = new Row(ImmutableMap.of( 42 | "name", Atom.string("ls2"), 43 | "description", Atom.string("Second Logical Switch"), 44 | "tunnel_key", Atom.integer(5002) 45 | )); 46 | 47 | Map rowUpdates = ImmutableMap.of( 48 | UUID.randomUUID(), new RowUpdate(old1, null), 49 | UUID.randomUUID(), new RowUpdate(null, new1) 50 | ); 51 | TableUpdate expectedResult = new TableUpdate(rowUpdates); 52 | 53 | String textTableUpdate = JsonUtil.serialize(rowUpdates); 54 | 55 | assertEquals( 56 | expectedResult, 57 | JsonUtil.deserialize(textTableUpdate, TableUpdate.class) 58 | ); 59 | } 60 | 61 | @Test 62 | public void testEquals() { 63 | UUID uuid = UUID.randomUUID(); 64 | RowUpdate rowUpdate1 = new RowUpdate( 65 | null, new Row(ImmutableMap.of("name", Atom.string("ps1"))) 66 | ); 67 | Map rowUpdates1 = ImmutableMap.of(uuid, rowUpdate1); 68 | 69 | RowUpdate rowUpdate2 = new RowUpdate().setNew(new Row().stringColumn("name", "ps1")); 70 | Map rowUpdates2= new HashMap<>(); 71 | rowUpdates2.put(uuid, rowUpdate2); 72 | 73 | new EqualsTester() 74 | .addEqualityGroup(new TableUpdate(rowUpdates1), new TableUpdate(rowUpdates2)) 75 | .testEquals(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/deserializer/SetDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation.deserializer; 16 | 17 | import com.fasterxml.jackson.core.JsonParser; 18 | import com.fasterxml.jackson.core.type.TypeReference; 19 | import com.fasterxml.jackson.databind.DeserializationContext; 20 | import com.fasterxml.jackson.databind.JsonNode; 21 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 22 | import com.fasterxml.jackson.databind.node.ArrayNode; 23 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 24 | import com.vmware.ovsdb.protocol.operation.notation.Atom; 25 | import com.vmware.ovsdb.protocol.operation.notation.Set; 26 | import com.vmware.ovsdb.protocol.util.OvsdbConstant; 27 | 28 | import java.io.IOException; 29 | 30 | public class SetDeserializer extends StdDeserializer { 31 | 32 | protected SetDeserializer() { 33 | this(null); 34 | } 35 | 36 | protected SetDeserializer(Class vc) { 37 | super(vc); 38 | } 39 | 40 | @Override 41 | public Set deserialize( 42 | JsonParser jp, DeserializationContext ctxt 43 | ) throws IOException { 44 | JsonNode jsonNode = jp.getCodec().readTree(jp); 45 | // An that represents a set with exactly one element 46 | if (jsonNode.isValueNode()) { 47 | JsonUtil.treeToValue(jsonNode, Atom.class); 48 | return Set.of(JsonUtil.treeToValue(jsonNode, Atom.class)); 49 | } 50 | ArrayNode arrayNode = (ArrayNode) jsonNode; 51 | if (arrayNode.size() != 2) { 52 | throw new IOException( 53 | " should be a 2-element JSON array. Found " 54 | + arrayNode.size() + " elements"); 55 | } 56 | 57 | if (!OvsdbConstant.SET.equals(arrayNode.get(0).asText())) { 58 | // This may be a 59 | if (OvsdbConstant.UUID.equals(arrayNode.get(0).asText())) { 60 | return Set.of(JsonUtil.treeToValue(jsonNode, Atom.class)); 61 | } 62 | throw new IOException( 63 | "First element of should be \"" + OvsdbConstant.SET 64 | + "\""); 65 | } 66 | 67 | java.util.Set atoms = JsonUtil.treeToValueNoException( 68 | arrayNode.get(1), 69 | new TypeReference>() {} 70 | ); 71 | return new Set(atoms); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/schema/RealBaseType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import com.fasterxml.jackson.annotation.JsonInclude; 18 | import com.vmware.ovsdb.protocol.operation.notation.Value; 19 | 20 | import java.util.Objects; 21 | 22 | /** 23 | * Represent a {@literal } with a real {@literal } as it's type. 24 | * 25 | * @see BaseType 26 | * @see AtomicType 27 | */ 28 | public class RealBaseType extends BaseType { 29 | 30 | @JsonInclude(JsonInclude.Include.NON_NULL) 31 | private final Double minReal; 32 | 33 | @JsonInclude(JsonInclude.Include.NON_NULL) 34 | private final Double maxReal; 35 | 36 | /** 37 | * Create a {@link RealBaseType} object. 38 | */ 39 | public RealBaseType() { 40 | this(null, null); 41 | } 42 | 43 | /** 44 | * Create a {@link RealBaseType} object. 45 | * 46 | * @param enums value of the "enums" field 47 | */ 48 | public RealBaseType(Value enums) { 49 | super(AtomicType.REAL, enums); 50 | this.minReal = null; 51 | this.maxReal = null; 52 | } 53 | 54 | /** 55 | * Create a {@link RealBaseType} object. 56 | * 57 | * @param minReal value of the "minReal" field 58 | * @param maxReal value of the "maxReal" field 59 | */ 60 | public RealBaseType(Double minReal, Double maxReal) { 61 | super(AtomicType.REAL); 62 | this.minReal = minReal; 63 | this.maxReal = maxReal; 64 | } 65 | 66 | public Double getMinReal() { 67 | return minReal; 68 | } 69 | 70 | public Double getMaxReal() { 71 | return maxReal; 72 | } 73 | 74 | @Override 75 | public boolean equals(Object other) { 76 | if (this == other) { 77 | return true; 78 | } 79 | if (!(other instanceof RealBaseType)) { 80 | return false; 81 | } 82 | if (!super.equals(other)) { 83 | return false; 84 | } 85 | RealBaseType that = (RealBaseType) other; 86 | return Objects.equals(minReal, that.getMinReal()) 87 | && Objects.equals(maxReal, that.getMaxReal()); 88 | } 89 | 90 | @Override 91 | public int hashCode() { 92 | return Objects.hash(super.hashCode(), minReal, maxReal); 93 | } 94 | 95 | @Override 96 | public String toString() { 97 | return getClass().getSimpleName() + " [" 98 | + "minReal=" + minReal 99 | + ", maxReal=" + maxReal 100 | + "]"; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/schema/UuidBaseType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import com.fasterxml.jackson.annotation.JsonInclude; 18 | import com.vmware.ovsdb.protocol.operation.notation.Value; 19 | 20 | import java.util.Objects; 21 | 22 | /** 23 | * Represent a {@literal } with a uuid {@literal } as it's type. 24 | * 25 | * @see BaseType 26 | * @see AtomicType 27 | */ 28 | public class UuidBaseType extends BaseType { 29 | 30 | @JsonInclude(JsonInclude.Include.NON_NULL) 31 | private final String refTable; 32 | 33 | @JsonInclude(JsonInclude.Include.NON_NULL) 34 | private final String refType; 35 | 36 | /** 37 | * Create a {@link UuidBaseType} object. 38 | */ 39 | public UuidBaseType() { 40 | this(null, null); 41 | } 42 | 43 | /** 44 | * Create a {@link UuidBaseType} object. 45 | * 46 | * @param enums value of "enum" field 47 | */ 48 | public UuidBaseType(Value enums) { 49 | super(AtomicType.UUID, enums); 50 | this.refTable = null; 51 | this.refType = null; 52 | } 53 | 54 | /** 55 | * Create a {@link UuidBaseType} object. 56 | * 57 | * @param refTable value of "refTable" field 58 | * @param refType value of "refType" field 59 | */ 60 | public UuidBaseType(String refTable, String refType) { 61 | super(AtomicType.UUID); 62 | this.refTable = refTable; 63 | this.refType = refType; 64 | } 65 | 66 | public String getRefTable() { 67 | return refTable; 68 | } 69 | 70 | public String getRefType() { 71 | return refType; 72 | } 73 | 74 | @Override 75 | public boolean equals(Object other) { 76 | if (this == other) { 77 | return true; 78 | } 79 | if (!(other instanceof UuidBaseType)) { 80 | return false; 81 | } 82 | if (!super.equals(other)) { 83 | return false; 84 | } 85 | UuidBaseType that = (UuidBaseType) other; 86 | return Objects.equals(refTable, that.getRefTable()) 87 | && Objects.equals(refType, that.getRefType()); 88 | } 89 | 90 | @Override 91 | public int hashCode() { 92 | return Objects.hash(super.hashCode(), refTable, refType); 93 | } 94 | 95 | @Override 96 | public String toString() { 97 | return getClass().getSimpleName() + " [" 98 | + "refTable=" + refTable 99 | + ", refType=" + refType 100 | + "]"; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/NamedUuid.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import com.fasterxml.jackson.annotation.JsonFormat; 18 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 19 | import com.vmware.ovsdb.protocol.operation.notation.deserializer.NamedUuidDeserializer; 20 | import com.vmware.ovsdb.protocol.util.OvsdbConstant; 21 | 22 | import java.util.Objects; 23 | 24 | /** 25 | * Representation of {@literal }. 26 | * 27 | *
28 |  * {@literal
29 |  * 
30 |  *   A 2-element JSON array that represents the UUID of a row inserted
31 |  *   in an "insert" operation within the same transaction.  The first
32 |  *   element of the array must be the string "named-uuid", and the
33 |  *   second element should be the  specified as the "uuid-name" for
34 |  *   an "insert" operation within the same transaction.  For example,
35 |  *   if an "insert" operation within this transaction specifies a
36 |  *   "uuid-name" of "myrow", the following  represents the
37 |  *   UUID created by that operation:
38 |  *
39 |  *   ["named-uuid", "myrow"]
40 |  *
41 |  *   A  may be used anywhere a  is valid.  This
42 |  *   enables a single transaction to both insert a new row and then
43 |  *   refer to that row using the "uuid-name" that was associated with
44 |  *   that row when it was inserted.  Note that the "uuid-name" is only
45 |  *   meaningful within the scope of a single transaction.
46 |  * }
47 |  * 
48 | */ 49 | @JsonDeserialize(using = NamedUuidDeserializer.class) 50 | @JsonFormat(shape = JsonFormat.Shape.ARRAY) 51 | public class NamedUuid { 52 | 53 | public final String namedUuidString = OvsdbConstant.NAMED_UUID; // For serializing 54 | 55 | private final String uuidName; 56 | 57 | public NamedUuid(String uuidName) { 58 | this.uuidName = uuidName; 59 | } 60 | 61 | public String getUuidName() { 62 | return uuidName; 63 | } 64 | 65 | @Override 66 | public boolean equals(Object other) { 67 | if (this == other) { 68 | return true; 69 | } 70 | if (!(other instanceof NamedUuid)) { 71 | return false; 72 | } 73 | NamedUuid that = (NamedUuid) other; 74 | return Objects.equals(uuidName, that.uuidName); 75 | } 76 | 77 | @Override 78 | public int hashCode() { 79 | return Objects.hash(namedUuidString, uuidName); 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return uuidName; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/schema/StringBaseType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import com.fasterxml.jackson.annotation.JsonInclude; 18 | import com.vmware.ovsdb.protocol.operation.notation.Value; 19 | 20 | import java.util.Objects; 21 | 22 | /** 23 | * Represent a {@literal } with a string {@literal } as it's type. 24 | * 25 | * @see BaseType 26 | * @see AtomicType 27 | */ 28 | public class StringBaseType extends BaseType { 29 | 30 | @JsonInclude(JsonInclude.Include.NON_NULL) 31 | private final Long minLength; 32 | 33 | @JsonInclude(JsonInclude.Include.NON_NULL) 34 | private final Long maxLength; 35 | 36 | /** 37 | * Create a {@link StringBaseType} object. 38 | */ 39 | public StringBaseType() { 40 | this(null, null); 41 | } 42 | 43 | /** 44 | * Create a {@link StringBaseType} object. 45 | * 46 | * @param enums value of the "enums" field 47 | */ 48 | public StringBaseType(Value enums) { 49 | super(AtomicType.STRING, enums); 50 | this.minLength = null; 51 | this.maxLength = null; 52 | } 53 | 54 | /** 55 | * Create a {@link StringBaseType} object. 56 | * 57 | * @param minLength value of the "minLength" field 58 | * @param maxLength value of the "maxLength" field 59 | */ 60 | public StringBaseType(Long minLength, Long maxLength) { 61 | super(AtomicType.STRING); 62 | this.minLength = minLength; 63 | this.maxLength = maxLength; 64 | } 65 | 66 | public Long getMinLength() { 67 | return minLength; 68 | } 69 | 70 | public Long getMaxLength() { 71 | return maxLength; 72 | } 73 | 74 | @Override 75 | public boolean equals(Object other) { 76 | if (this == other) { 77 | return true; 78 | } 79 | if (!(other instanceof StringBaseType)) { 80 | return false; 81 | } 82 | if (!super.equals(other)) { 83 | return false; 84 | } 85 | StringBaseType that = (StringBaseType) other; 86 | return Objects.equals(minLength, that.getMinLength()) 87 | && Objects.equals(maxLength, that.getMaxLength()); 88 | } 89 | 90 | @Override 91 | public int hashCode() { 92 | return Objects.hash(super.hashCode(), minLength, maxLength); 93 | } 94 | 95 | @Override 96 | public String toString() { 97 | return getClass().getSimpleName() + " [" 98 | + "minLength=" + minLength 99 | + ", maxLength=" + maxLength 100 | + "]"; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/Atom.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 18 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 19 | import com.vmware.ovsdb.protocol.operation.notation.deserializer.AtomDeserializer; 20 | import com.vmware.ovsdb.protocol.operation.notation.serializer.AtomSerializer; 21 | 22 | import java.util.Objects; 23 | import java.util.UUID; 24 | 25 | /** 26 | * Representation of {@literal }. 27 | * 28 | *
 29 |  * {@literal
 30 |  * 
 31 |  *   A JSON value that represents a scalar value for a column, one of
 32 |  *   , , , , or .
 33 |  * }
 34 |  * 
35 | */ 36 | @JsonSerialize(using = AtomSerializer.class) 37 | @JsonDeserialize(using = AtomDeserializer.class) 38 | public class Atom extends Value { 39 | 40 | private T value; 41 | 42 | public Atom(T value) { 43 | this.value = value; 44 | } 45 | 46 | public static Atom string(String value) { 47 | return new Atom<>(value); 48 | } 49 | 50 | public static Atom integer(long value) { 51 | return new Atom<>(value); 52 | } 53 | 54 | public static Atom real(Double value) { 55 | return new Atom<>(value); 56 | } 57 | 58 | public static Atom bool(boolean value) { 59 | return new Atom<>(value); 60 | } 61 | 62 | public static Atom uuid(Uuid value) { 63 | return new Atom<>(value); 64 | } 65 | 66 | public static Atom uuid(UUID value) { 67 | return new Atom<>(new Uuid(value)); 68 | } 69 | 70 | public static Atom namedUuid(NamedUuid value) { 71 | return new Atom<>(value); 72 | } 73 | 74 | public static Atom namedUuid(String value) { 75 | return new Atom<>(new NamedUuid(value)); 76 | } 77 | 78 | public T getValue() { 79 | return value; 80 | } 81 | 82 | @Override 83 | public boolean equals(Object other) { 84 | if (this == other) { 85 | return true; 86 | } 87 | if (!(other instanceof Atom)) { 88 | return false; 89 | } 90 | Atom atom = (Atom) other; 91 | return Objects.equals(value, atom.getValue()); 92 | } 93 | 94 | @Override 95 | public int hashCode() { 96 | return Objects.hash(value); 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return value.toString(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/operation/notation/SetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | import static org.junit.Assert.assertNull; 19 | import static org.junit.Assert.assertTrue; 20 | 21 | 22 | import com.fasterxml.jackson.core.JsonProcessingException; 23 | import com.google.common.collect.ImmutableSet; 24 | import com.google.common.testing.EqualsTester; 25 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 26 | import java.io.IOException; 27 | import java.util.Collections; 28 | import java.util.HashMap; 29 | import java.util.HashSet; 30 | import java.util.UUID; 31 | 32 | import org.junit.Test; 33 | 34 | public class SetTest { 35 | 36 | private static final String jsonString = "[\"set\",[\"string2\",\"string1\"]]"; 37 | 38 | private static final Set set = Set.of("string1", "string2"); 39 | 40 | @Test 41 | public void testSerialization() throws JsonProcessingException { 42 | assertEquals(jsonString, JsonUtil.serialize(set)); 43 | } 44 | 45 | @Test 46 | public void testDeserialization() throws IOException { 47 | assertEquals(set, JsonUtil.deserialize(jsonString, Set.class)); 48 | } 49 | 50 | /** 51 | * Test the case when an {@literal } is a {@literal }. 52 | */ 53 | @Test 54 | public void testAtomSetDeserialization() throws IOException { 55 | assertEquals(Set.of("string1"), JsonUtil.deserialize("\"string1\"", Set.class)); 56 | assertEquals(Set.of(42L), JsonUtil.deserialize("42", Set.class)); 57 | assertEquals(Set.of(true), JsonUtil.deserialize("true", Set.class)); 58 | UUID uuid = UUID.randomUUID(); 59 | assertEquals(Set.of(new Uuid(uuid)), JsonUtil.deserialize("[\"uuid\", \"" + uuid + "\"]", Set.class)); 60 | assertEquals(Set.of(4.2), JsonUtil.deserialize("4.2", Set.class)); 61 | } 62 | 63 | @Test(expected = IOException.class) 64 | public void testInvalidSet1() throws IOException { 65 | JsonUtil.deserialize("[[123, 456]]", Set.class); 66 | } 67 | 68 | @Test(expected = IOException.class) 69 | public void testInvalidSet2() throws IOException { 70 | JsonUtil.deserialize("[\"not-set\",[123, 456]]", Set.class); 71 | } 72 | 73 | @Test 74 | public void testEquals() { 75 | new EqualsTester() 76 | .addEqualityGroup(new Set(), new Set(Collections.emptySet())) 77 | .addEqualityGroup(set, Set.of(ImmutableSet.of("string1", "string2"))) 78 | .testEquals(); 79 | java.util.Set nullSet = null; 80 | assertNull(Set.of(nullSet)); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /json-rpc/src/test/java/com/vmware/ovsdb/jsonrpc/v1/util/JsonUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.jsonrpc.v1.util; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | import static org.junit.Assert.assertNull; 19 | 20 | import com.fasterxml.jackson.core.JsonProcessingException; 21 | import com.fasterxml.jackson.core.type.TypeReference; 22 | import com.fasterxml.jackson.databind.JsonNode; 23 | import com.vmware.ovsdb.jsonrpc.v1.model.JsonRpcV1Request; 24 | import org.junit.Test; 25 | 26 | import java.io.IOException; 27 | import java.nio.file.Files; 28 | import java.nio.file.Path; 29 | import java.nio.file.Paths; 30 | import java.util.Collections; 31 | 32 | public class JsonUtilTest { 33 | 34 | @Test 35 | public void testTreeAndValueConversion() throws IOException { 36 | String string = "string"; 37 | 38 | assertEquals(string, JsonUtil.treeToValue(JsonUtil.toJsonNode(string), String.class)); 39 | 40 | JsonRpcV1Request request = new JsonRpcV1Request("id", "method"); 41 | assertEquals( 42 | request, JsonUtil.treeToValue(JsonUtil.toJsonNode(request), JsonRpcV1Request.class) 43 | ); 44 | 45 | JsonNode jsonNode = JsonUtil.readTree("{}"); 46 | assertNull(JsonUtil.treeToValueNoException(jsonNode, JsonRpcV1Request.class)); 47 | 48 | assertNull(JsonUtil.treeToValueNoException(jsonNode, new TypeReference() {})); 49 | } 50 | 51 | @Test 52 | public void testDeserialize() throws IOException { 53 | String jsonString = "{\"id\":\"id\", \"method\":\"method\", \"params\":[]}"; 54 | JsonRpcV1Request request = new JsonRpcV1Request("id", "method"); 55 | assertEquals( 56 | request, JsonUtil.deserialize(jsonString, JsonRpcV1Request.class) 57 | ); 58 | String tmpFile = "tempfile"; 59 | Path file = Paths.get(tmpFile); 60 | Files.write(file, Collections.singletonList(jsonString)); 61 | assertEquals( 62 | request, JsonUtil.deserialize(file.toUri().toURL(), JsonRpcV1Request.class) 63 | ); 64 | Files.delete(file); 65 | 66 | assertNull(JsonUtil.deserializeNoException("{}", JsonRpcV1Request.class)); 67 | } 68 | 69 | @Test 70 | public void testSerialize() throws JsonProcessingException { 71 | String jsonString = "{\"method\":\"method\",\"params\":[],\"id\":\"id\"}"; 72 | JsonRpcV1Request request = new JsonRpcV1Request("id", "method"); 73 | assertEquals( 74 | jsonString, JsonUtil.serialize(request) 75 | ); 76 | 77 | class WrongClass { 78 | private String field; 79 | } 80 | assertNull(JsonUtil.serializeNoException(new WrongClass())); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/protocol/schema/RealBaseTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import static com.vmware.ovsdb.protocol.schema.Constants.JSON_REAL; 18 | import static org.junit.Assert.assertEquals; 19 | 20 | import com.google.common.testing.EqualsTester; 21 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 22 | import com.vmware.ovsdb.protocol.operation.notation.Atom; 23 | import com.vmware.ovsdb.protocol.operation.notation.Set; 24 | import org.junit.Test; 25 | 26 | import java.io.IOException; 27 | 28 | public class RealBaseTypeTest { 29 | 30 | @Test 31 | public void testDeserialization() throws IOException { 32 | // Test atomic type as base type 33 | BaseType expectedResult = BaseType.atomicType(AtomicType.REAL); 34 | String jsonBaseType = JSON_REAL; 35 | 36 | assertEquals( 37 | expectedResult, 38 | JsonUtil.deserialize(jsonBaseType, BaseType.class) 39 | ); 40 | 41 | // Test real type that has only "type" field 42 | jsonBaseType = "{\"type\":" + JSON_REAL + "}"; 43 | assertEquals( 44 | expectedResult, 45 | JsonUtil.deserialize(jsonBaseType, BaseType.class) 46 | ); 47 | 48 | // Test real base type with min and max 49 | jsonBaseType = "{\"type\":" + JSON_REAL 50 | + ", \"minReal\":1.5, \"maxReal\":100.11}"; 51 | expectedResult = new RealBaseType(1.5, 100.11); 52 | 53 | assertEquals( 54 | expectedResult, 55 | JsonUtil.deserialize(jsonBaseType, BaseType.class) 56 | ); 57 | 58 | // Test real base type with enum of single value 59 | jsonBaseType = "{\"type\":" + JSON_REAL + ", \"enum\":2.4}"; 60 | expectedResult = new RealBaseType(Atom.real(2.4)); 61 | 62 | assertEquals( 63 | expectedResult, 64 | JsonUtil.deserialize(jsonBaseType, BaseType.class) 65 | ); 66 | 67 | // Test real base type with enum of set value 68 | jsonBaseType = "{\"type\":" + JSON_REAL 69 | + ", \"enum\":[\"set\", [1.3,2.7,3.9]]}"; 70 | Set enums = Set.of(1.3, 2.7, 3.9); 71 | 72 | expectedResult = new RealBaseType(enums); 73 | assertEquals(expectedResult, JsonUtil.deserialize(jsonBaseType, BaseType.class)); 74 | } 75 | 76 | @Test 77 | public void testEquals() { 78 | new EqualsTester() 79 | .addEqualityGroup(new RealBaseType(), new RealBaseType(null, null)) 80 | .addEqualityGroup(new RealBaseType(Atom.real(4.2)), new RealBaseType(Atom.real(4.2))) 81 | .addEqualityGroup(new RealBaseType(2.4, 4.2), new RealBaseType(2.4, 4.2)) 82 | .testEquals(); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/schema/IntegerBaseType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema; 16 | 17 | import com.fasterxml.jackson.annotation.JsonInclude; 18 | import com.vmware.ovsdb.protocol.operation.notation.Value; 19 | 20 | import java.util.Objects; 21 | 22 | /** 23 | * Represent a {@literal } with a integer {@literal } as it's type. 24 | * 25 | * @see BaseType 26 | * @see AtomicType 27 | */ 28 | public class IntegerBaseType extends BaseType { 29 | 30 | @JsonInclude(JsonInclude.Include.NON_NULL) 31 | private final Long minInteger; 32 | 33 | @JsonInclude(JsonInclude.Include.NON_NULL) 34 | private final Long maxInteger; 35 | 36 | /** 37 | * Create a {@link IntegerBaseType} object. 38 | */ 39 | public IntegerBaseType() { 40 | this(null, null); 41 | } 42 | 43 | /** 44 | * Create a {@link IntegerBaseType} object. 45 | * 46 | * @param enums value of the "enum" field 47 | */ 48 | public IntegerBaseType(Value enums) { 49 | super(AtomicType.INTEGER, enums); 50 | this.minInteger = null; 51 | this.maxInteger = null; 52 | } 53 | 54 | /** 55 | * Create a {@link IntegerBaseType} object. 56 | * 57 | * @param minInteger value of the "minInteger" field 58 | * @param maxInteger value of the "maxInteger" field 59 | */ 60 | public IntegerBaseType(Long minInteger, Long maxInteger) { 61 | super(AtomicType.INTEGER); 62 | this.minInteger = minInteger; 63 | this.maxInteger = maxInteger; 64 | } 65 | 66 | public Long getMinInteger() { 67 | return minInteger; 68 | } 69 | 70 | public Long getMaxInteger() { 71 | return maxInteger; 72 | } 73 | 74 | @Override 75 | public boolean equals(Object other) { 76 | if (this == other) { 77 | return true; 78 | } 79 | if (!(other instanceof IntegerBaseType)) { 80 | return false; 81 | } 82 | if (!super.equals(other)) { 83 | return false; 84 | } 85 | IntegerBaseType that = (IntegerBaseType) other; 86 | return Objects.equals(minInteger, that.getMinInteger()) 87 | && Objects.equals(maxInteger, that.getMaxInteger()); 88 | } 89 | 90 | @Override 91 | public int hashCode() { 92 | return Objects.hash(super.hashCode(), minInteger, maxInteger); 93 | } 94 | 95 | @Override 96 | public String toString() { 97 | return getClass().getSimpleName() + " [" 98 | + "minInteger=" + minInteger 99 | + ", maxInteger=" + maxInteger 100 | + "]"; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /ovsdb-client/src/test/java/com/vmware/ovsdb/service/OvsdbClientPassiveConnectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.service; 16 | 17 | import com.vmware.ovsdb.callback.ConnectionCallback; 18 | import com.vmware.ovsdb.exception.OvsdbClientException; 19 | import com.vmware.ovsdb.service.impl.OvsdbPassiveConnectionListenerImpl; 20 | import com.vmware.ovsdb.testutils.ActiveOvsdbServerEmulator; 21 | import io.netty.handler.ssl.SslContext; 22 | import org.junit.After; 23 | import org.junit.Test; 24 | 25 | import java.io.IOException; 26 | import java.util.concurrent.CompletableFuture; 27 | 28 | public class OvsdbClientPassiveConnectionTest extends OvsdbClientTest { 29 | 30 | private static final OvsdbPassiveConnectionListener passiveListener 31 | = new OvsdbPassiveConnectionListenerImpl(executorService); 32 | 33 | private static final ActiveOvsdbServerEmulator activeOvsdbServer = 34 | new ActiveOvsdbServerEmulator(HOST, PORT); 35 | 36 | public OvsdbClientPassiveConnectionTest() { 37 | super(activeOvsdbServer); 38 | } 39 | 40 | @After 41 | public void tearDown() { 42 | super.teardown(); 43 | activeOvsdbServer.disconnect().join(); 44 | passiveListener.stopListening(PORT).join(); 45 | } 46 | 47 | @Override 48 | void setUp(boolean withSsl) { 49 | CompletableFuture ovsdbClientFuture = new CompletableFuture<>(); 50 | 51 | final ConnectionCallback connectionCallback = new ConnectionCallback() { 52 | @Override 53 | public void connected(OvsdbClient ovsdbClient) { 54 | ovsdbClientFuture.complete(ovsdbClient); 55 | } 56 | 57 | @Override 58 | public void disconnected(OvsdbClient ovsdbClient) { 59 | } 60 | }; 61 | if (!withSsl) { 62 | passiveListener.startListening(PORT, connectionCallback).join(); 63 | activeOvsdbServer.connect().join(); 64 | } else { 65 | // In passive connection test, the controller is the server and the ovsdb-server is the client 66 | SslContext serverSslCtx = sslContextPair.getServerSslCtx(); 67 | SslContext clientSslCtx = sslContextPair.getClientSslCtx(); 68 | passiveListener.startListeningWithSsl(PORT, serverSslCtx, connectionCallback).join(); 69 | activeOvsdbServer.connectWithSsl(clientSslCtx).join(); 70 | } 71 | ovsdbClient = ovsdbClientFuture.join(); 72 | } 73 | 74 | @Test(timeout = TEST_TIMEOUT_MILLIS) 75 | public void testTcpConnection() 76 | throws OvsdbClientException, IOException { 77 | super.testTcpConnection(); 78 | } 79 | 80 | @Test(timeout = TEST_TIMEOUT_MILLIS) 81 | public void testSslConnection() throws OvsdbClientException, IOException { 82 | super.testSslConnection(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/operation/notation/Map.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.operation.notation; 16 | 17 | import com.fasterxml.jackson.annotation.JsonFormat; 18 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 19 | import com.vmware.ovsdb.protocol.operation.notation.deserializer.MapDeserializer; 20 | import com.vmware.ovsdb.protocol.util.OvsdbConstant; 21 | 22 | import java.util.List; 23 | import java.util.Objects; 24 | import java.util.stream.Collectors; 25 | 26 | /** 27 | * Representation of {@literal }. 28 | * 29 | *
 30 |  * {@literal
 31 |  * 
 32 |  *   A 2-element JSON array that represents a database map value.  The
 33 |  *   first element of the array must be the string "map", and the
 34 |  *   second element must be an array of zero or more s giving the
 35 |  *   values in the map.  All of the s must have the same key and
 36 |  *   value types.
 37 |  *
 38 |  *   (JSON objects are not used to represent  because JSON only
 39 |  *   allows string names in an object.)
 40 |  * }
 41 |  * 
42 | */ 43 | @JsonFormat(shape = JsonFormat.Shape.ARRAY) 44 | @JsonDeserialize(using = MapDeserializer.class) 45 | public class Map extends Value { 46 | 47 | public final String mapString = OvsdbConstant.MAP; // For serializing 48 | 49 | private List> pairs; 50 | 51 | public Map(List> pairs) { 52 | this.pairs = pairs; 53 | } 54 | 55 | /** 56 | * Create a {@link Map} object using a {@link java.util.Map} object. 57 | * 58 | * @param key the type of keys maintained by this map 59 | * @param the type of mapped values 60 | * @param map the {@link java.util.Map} object 61 | * @return a {@link Map} object 62 | */ 63 | public static Map of(java.util.Map map) { 64 | if (map == null) { 65 | return null; 66 | } 67 | return new Map<>( 68 | map.keySet().stream().map( 69 | key -> new Pair<>(new Atom<>(key), new Atom<>(map.get(key))) 70 | ).collect(Collectors.toList()) 71 | ); 72 | } 73 | 74 | public List> getPairs() { 75 | return pairs; 76 | } 77 | 78 | @Override 79 | public boolean equals(Object other) { 80 | if (this == other) { 81 | return true; 82 | } 83 | if (!(other instanceof Map)) { 84 | return false; 85 | } 86 | Map that = (Map) other; 87 | return Objects.equals(pairs, that.getPairs()); 88 | } 89 | 90 | @Override 91 | public int hashCode() { 92 | return Objects.hash(mapString, pairs); 93 | } 94 | 95 | @Override 96 | public String toString() { 97 | return getClass().getSimpleName() + pairs; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/schema/deserializer/TypeDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.schema.deserializer; 16 | 17 | import static com.vmware.ovsdb.protocol.util.OvsdbConstant.KEY; 18 | import static com.vmware.ovsdb.protocol.util.OvsdbConstant.MAX; 19 | import static com.vmware.ovsdb.protocol.util.OvsdbConstant.MIN; 20 | import static com.vmware.ovsdb.protocol.util.OvsdbConstant.UNLIMITED; 21 | import static com.vmware.ovsdb.protocol.util.OvsdbConstant.VALUE; 22 | 23 | import com.fasterxml.jackson.core.JsonParser; 24 | import com.fasterxml.jackson.databind.DeserializationContext; 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 27 | import com.vmware.ovsdb.jsonrpc.v1.util.JsonUtil; 28 | import com.vmware.ovsdb.protocol.schema.AtomicType; 29 | import com.vmware.ovsdb.protocol.schema.BaseType; 30 | import com.vmware.ovsdb.protocol.schema.Type; 31 | 32 | import java.io.IOException; 33 | 34 | public class TypeDeserializer extends StdDeserializer { 35 | 36 | protected TypeDeserializer() { 37 | this(null); 38 | } 39 | 40 | protected TypeDeserializer(Class vc) { 41 | super(vc); 42 | } 43 | 44 | @Override 45 | public Type deserialize( 46 | JsonParser jp, DeserializationContext ctxt 47 | ) throws IOException { 48 | JsonNode jsonNode = jp.getCodec().readTree(jp); 49 | AtomicType atomicType = JsonUtil.treeToValueNoException(jsonNode, AtomicType.class); 50 | // This is a , just return 51 | if (atomicType != null) { 52 | return new Type(BaseType.atomicType(atomicType)); 53 | } 54 | JsonNode keyNode = jsonNode.get(KEY); 55 | if (keyNode == null) { 56 | throw new IOException( 57 | "\"" + KEY + "\" field is missing from : " + jsonNode); 58 | } 59 | 60 | final BaseType key = JsonUtil.treeToValue(keyNode, BaseType.class); 61 | BaseType value = null; 62 | Long min = null; 63 | Long max = null; 64 | 65 | JsonNode valueNode = jsonNode.get(VALUE); 66 | if (valueNode != null) { 67 | value = JsonUtil.treeToValue(valueNode, BaseType.class); 68 | } 69 | JsonNode minNode = jsonNode.get(MIN); 70 | if (minNode != null) { 71 | min = minNode.asLong(); 72 | } 73 | JsonNode maxNode = jsonNode.get(MAX); 74 | if (maxNode != null) { 75 | if (maxNode.isTextual()) { 76 | if (!UNLIMITED.equals(maxNode.asText())) { 77 | throw new IOException( 78 | "Invalid \"" + MAX + "\" value: " + maxNode + " of : " + jsonNode); 79 | } 80 | max = Long.MAX_VALUE; 81 | } else { 82 | max = maxNode.asLong(); 83 | } 84 | } 85 | 86 | return new Type(key, value, min, max); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /ovsdb-client/src/main/java/com/vmware/ovsdb/protocol/methods/MonitorRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 VMware, Inc. All Rights Reserved. 3 | * 4 | * This product is licensed to you under the BSD-2 license (the "License"). 5 | * You may not use this product except in compliance with the BSD-2 License. 6 | * 7 | * This product may include a number of subcomponents with separate copyright 8 | * notices and license terms. Your use of these subcomponents is subject to the 9 | * terms and conditions of the subcomponent's license, as noted in the LICENSE 10 | * file. 11 | * 12 | * SPDX-License-Identifier: BSD-2-Clause 13 | */ 14 | 15 | package com.vmware.ovsdb.protocol.methods; 16 | 17 | import com.fasterxml.jackson.annotation.JsonInclude; 18 | 19 | import java.util.List; 20 | import java.util.Objects; 21 | 22 | /** 23 | * Representation of {@literal }. 24 | * 25 | *
 26 |  * {@literal } is an object with the following members:
 27 |  *
 28 |  * "columns": [{@literal }*]            optional
 29 |  * "select": {@literal }        optional
 30 |  * 
31 | */ 32 | public class MonitorRequest { 33 | 34 | @JsonInclude(JsonInclude.Include.NON_NULL) 35 | private final List columns; 36 | 37 | @JsonInclude(JsonInclude.Include.NON_NULL) 38 | private final MonitorSelect select; 39 | 40 | /** 41 | * Create an {@link MonitorRequest} object with all fields being default values. 42 | */ 43 | public MonitorRequest() { 44 | this(null, null); 45 | } 46 | 47 | /** 48 | * Create an {@link MonitorRequest} object with select being default value. 49 | * 50 | * @param columns value of the "columns" field 51 | */ 52 | public MonitorRequest(List columns) { 53 | this(columns, null); 54 | } 55 | 56 | /** 57 | * Create an {@link MonitorRequest} object with columns being default value. 58 | * 59 | * @param select value of the "select" field 60 | */ 61 | public MonitorRequest(MonitorSelect select) { 62 | this(null, select); 63 | } 64 | 65 | /** 66 | * Create an {@link MonitorRequest} object. 67 | * 68 | * @param columns value of the "columns" field 69 | * @param select value of the "select" field 70 | */ 71 | public MonitorRequest(List columns, MonitorSelect select) { 72 | this.columns = columns; 73 | this.select = select; 74 | } 75 | 76 | public List getColumns() { 77 | return columns; 78 | } 79 | 80 | public MonitorSelect getSelect() { 81 | return select; 82 | } 83 | 84 | @Override 85 | public boolean equals(Object other) { 86 | if (this == other) { 87 | return true; 88 | } 89 | if (!(other instanceof MonitorRequest)) { 90 | return false; 91 | } 92 | MonitorRequest that = (MonitorRequest) other; 93 | return Objects.equals(columns, that.getColumns()) 94 | && Objects.equals(select, that.getSelect()); 95 | } 96 | 97 | @Override 98 | public int hashCode() { 99 | return Objects.hash(columns, select); 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return getClass().getSimpleName() + " [" 105 | + "columns=" + columns 106 | + ", select=" + select 107 | + "]"; 108 | } 109 | } 110 | --------------------------------------------------------------------------------