--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+/**
+ * BadSchema exception is thrown when the received schema is invalid
+ */
+public class BadSchemaException extends RuntimeException {
+ public BadSchemaException(String message){
+ super(message);
+ }
+
+ public BadSchemaException(String message, Throwable cause){
+ super(message, cause);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+/**
+ * This exception is thrown when a ColumnSchema cannot be found
+ */
+public class ColumnSchemaNotFoundException extends RuntimeException {
+
+ public ColumnSchemaNotFoundException(String message){
+ super(message);
+ }
+
+ public ColumnSchemaNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public static String createMessage(String columnName, String tableName){
+ String message = "Unable to locate ColumnSchema for "+ columnName + " in "+ tableName;
+ return message;
+ }
+
+}
*
* Authors : Ashwin Raveendran, Madhu Venugopal
*/
-package org.opendaylight.ovsdb.lib.jsonrpc;
+package org.opendaylight.ovsdb.lib.error;
+/**
+ * InvalidEncodingException in cases where something is not UTF-8 Encoded.
+ */
public class InvalidEncodingException extends RuntimeException {
private final String actual;
*
*/
-package org.opendaylight.ovsdb.lib;
+package org.opendaylight.ovsdb.lib.error;
+/**
+ * The ParsingException is thrown when JSON could not be successfully parsed
+ */
public class ParsingException extends RuntimeException {
public ParsingException() {
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+import org.opendaylight.ovsdb.lib.notation.Version;
+
+/**
+ * This exception is used when the a table or row is accessed though a typed interface
+ * and the version requirements are not met
+ */
+public class SchemaVersionMismatchException extends RuntimeException {
+
+ public SchemaVersionMismatchException(String message) {
+ super(message);
+ }
+
+ public SchemaVersionMismatchException(String message, Throwable cause){
+ super(message, cause);
+ }
+
+ public static String createMessage(Version currentVersion, Version requiredVersion) {
+ String message = "The schema version used to access this Table/Column does not match the required version.\n" +
+ "Current Version: " + currentVersion.toString() + "\n";
+
+ if (currentVersion.compareTo(requiredVersion) > 1) {
+ message += "Removed in Version: " + requiredVersion.toString();
+
+ } else {
+ message += "Added in Version: " + requiredVersion.toString();
+
+ }
+
+ return message;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+/**
+ * This exception is thrown when a TableSchema cannot be found
+ */
+public class TableSchemaNotFoundException extends RuntimeException {
+
+ public TableSchemaNotFoundException(String message){
+ super(message);
+ }
+
+ public TableSchemaNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public static String createMessage(String tableName, String schemaName){
+ String message = "Unable to locate TableSchema for "+ tableName + " in "+ schemaName;
+ return message;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+/**
+ * This is a generic exception thrown by the Typed Schema utilities
+ */
+public class TyperException extends RuntimeException {
+
+ public TyperException(String message){
+ super(message);
+ }
+
+ public TyperException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+/**
+ * This exception is thrown when a result does not meet any of the known formats in RFC7047
+ */
+public class UnexpectedResultException extends RuntimeException {
+ public UnexpectedResultException(String message){
+ super(message);
+ }
+
+ public UnexpectedResultException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+public class UnsupportedArgumentException extends RuntimeException {
+
+ public UnsupportedArgumentException(String message){
+ super(message);
+ }
+
+ public UnsupportedArgumentException(String message, Throwable cause){
+ super(message, cause);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Dave Tucker
+ */
+
+package org.opendaylight.ovsdb.lib.error;
+
+public class UnsupportedMethodException extends RuntimeException {
+
+ public UnsupportedMethodException(String message) {
+ super(message);
+ }
+ public UnsupportedMethodException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.TooLongFrameException;
+import org.opendaylight.ovsdb.lib.error.InvalidEncodingException;
public class ExceptionHandler extends ChannelHandlerAdapter {
import java.io.IOException;
import java.util.List;
+import org.opendaylight.ovsdb.lib.error.InvalidEncodingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.UUID;
+import org.opendaylight.ovsdb.lib.error.UnexpectedResultException;
+import org.opendaylight.ovsdb.lib.error.UnsupportedArgumentException;
import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
if (params == null) {
- throw new RuntimeException("do not understand this argument yet");
+ throw new UnsupportedArgumentException("do not understand this argument yet");
}
request.setParams(params);
}
returnCtxt.getFuture().set(result1);
} else {
- throw new RuntimeException("donno how to deal with this");
+ throw new UnexpectedResultException("Don't know how to handle this");
}
}
import java.util.Set;
-import org.opendaylight.ovsdb.lib.notation.UUID;
-
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Sets;
+import org.opendaylight.ovsdb.lib.error.TyperException;
+import org.opendaylight.ovsdb.lib.notation.UUID;
public abstract class BaseType<E extends BaseType<E>> {
}
} else {
if (!json.has(keyorval)) {
- throw new RuntimeException("Not a type");
+ throw new TyperException("Not a type");
}
for (BaseType baseTypeFactory : types) {
import java.util.Map;
import java.util.Set;
+import org.opendaylight.ovsdb.lib.error.BadSchemaException;
import org.opendaylight.ovsdb.lib.notation.Condition;
import org.opendaylight.ovsdb.lib.notation.Function;
import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
public static ColumnSchema fromJson(String name, JsonNode json) {
if (!json.isObject() || !json.has("type")) {
- //todo specific types of exception
- throw new RuntimeException("bad column schema root, expected \"type\" as child");
+ throw new BadSchemaException("bad column schema root, expected \"type\" as child");
}
return new ColumnSchema(name, ColumnType.fromJson(json.get("type")));
import java.util.Set;
+import org.opendaylight.ovsdb.lib.error.TyperException;
import org.opendaylight.ovsdb.lib.jsonrpc.JsonUtils;
import org.opendaylight.ovsdb.lib.notation.OvsDBMap;
}
}
//todo move to speicfic typed exception
- throw new RuntimeException(String.format("could not find the right column type %s",
+ throw new TyperException(String.format("could not find the right column type %s",
JsonUtils.prettyString(json)));
}
import java.util.Map;
import java.util.Set;
-import org.opendaylight.ovsdb.lib.ParsingException;
+import org.opendaylight.ovsdb.lib.error.ParsingException;
import org.opendaylight.ovsdb.lib.notation.Version;
import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
import org.slf4j.Logger;
package org.opendaylight.ovsdb.lib.schema;
import com.fasterxml.jackson.databind.JsonNode;
+import org.opendaylight.ovsdb.lib.error.BadSchemaException;
import java.util.HashMap;
import java.util.Iterator;
public GenericTableSchema fromJson(String tableName, JsonNode json) {
if (!json.isObject() || !json.has("columns")) {
- //todo specific types of exception
- throw new RuntimeException("bad tableschema root, expected \"columns\" as child");
+ throw new BadSchemaException("bad tableschema root, expected \"columns\" as child");
}
Map<String, ColumnSchema> columns = new HashMap<>();
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+
+import org.opendaylight.ovsdb.lib.error.ColumnSchemaNotFoundException;
+import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
+import org.opendaylight.ovsdb.lib.error.TableSchemaNotFoundException;
+import org.opendaylight.ovsdb.lib.error.TyperException;
import org.opendaylight.ovsdb.lib.notation.Column;
import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.notation.Version;
return false;
}
- public static Version getFromVersion (Method method) {
+ public static Version getColumnFromVersion(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
return Version.fromString(typedColumn.fromVersion());
}
- TypedTable typedTable = method.getAnnotation(TypedTable.class);
+ return Version.NULL;
+ }
+
+ public static <T> Version getTableFromVersion(final Class<T> klazz) {
+ TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
if (typedTable != null) {
return Version.fromString(typedTable.fromVersion());
}
return Version.NULL;
}
- public static Version getUntilVersion(Method method) {
+ public static Version getColumnUntilVersion(Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
return Version.fromString(typedColumn.untilVersion());
}
- TypedTable typedTable = method.getAnnotation(TypedTable.class);
+ return Version.NULL;
+ }
+
+ public static <T> Version getTableUntilVersion(final Class<T> klazz) {
+ TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
if (typedTable != null) {
return Version.fromString(typedTable.untilVersion());
}
}
}
- if (!dbSchema.getTables().contains(getTableName(klazz))) {
- return false;
- }
+ checkTableSchemaVersion(dbSchema, klazz);
+
return true;
}
- private static void checkSchemaVersion(DatabaseSchema dbSchema, Method method) {
- Version fromVersion = getFromVersion(method);
- Version untilVersion = getUntilVersion(method);
+ private static void checkColumnSchemaVersion(DatabaseSchema dbSchema, Method method) {
+ Version fromVersion = getColumnFromVersion(method);
+ Version untilVersion = getColumnUntilVersion(method);
+ Version schemaVersion = dbSchema.getVersion();
+ checkVersion(schemaVersion, fromVersion, untilVersion);
+ }
+
+ private static <T> void checkTableSchemaVersion(DatabaseSchema dbSchema, Class<T> klazz) {
+ Version fromVersion = getTableFromVersion(klazz);
+ Version untilVersion = getTableUntilVersion(klazz);
+ Version schemaVersion = dbSchema.getVersion();
+ checkVersion(schemaVersion, fromVersion, untilVersion);
+ }
+
+ private static void checkVersion(Version schemaVersion, Version fromVersion, Version untilVersion){
if (!fromVersion.equals(Version.NULL)) {
- if (dbSchema.getVersion().compareTo(fromVersion) < 0) {
- throw new RuntimeException("This row is not supported until version "
- + fromVersion + "of the Schema");
+ if (schemaVersion.compareTo(fromVersion) < 0) {
+ String message = SchemaVersionMismatchException.createMessage(schemaVersion, fromVersion);
+ throw new SchemaVersionMismatchException(message);
}
}
if (!untilVersion.equals(Version.NULL)) {
- if (dbSchema.getVersion().compareTo(untilVersion) > 0) {
- throw new RuntimeException("This row was deprecated in "
- + untilVersion + "of the Schema");
+ if (schemaVersion.compareTo(untilVersion) > 0) {
+ String message = SchemaVersionMismatchException.createMessage(schemaVersion, untilVersion);
+ throw new SchemaVersionMismatchException(message);
}
}
}
return Reflection.newProxy(klazz, new InvocationHandler() {
private Object processGetData(Method method) throws Throwable {
String columnName = getColumnName(method);
- checkSchemaVersion(dbSchema, method);
+ checkColumnSchemaVersion(dbSchema, method);
if (columnName == null) {
- throw new RuntimeException("Error processing Getter : "+ method.getName());
+ throw new TyperException("Error processing Getter : "+ method.getName());
}
GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz);
if (tableSchema == null) {
- throw new RuntimeException("Unable to locate TableSchema for "+getTableName(klazz)+ " in "+ dbSchema.getName());
+ String message = TableSchemaNotFoundException.createMessage(getTableName(klazz), dbSchema.getName());
+ throw new TableSchemaNotFoundException(message);
}
ColumnSchema<GenericTableSchema, Object> columnSchema = getColumnSchema(tableSchema, columnName, (Class<Object>) method.getReturnType());
if (columnSchema == null) {
- throw new RuntimeException("Unable to locate ColumnSchema for "+columnName+ " in "+ tableSchema.getName());
+ String message = ColumnSchemaNotFoundException.createMessage(columnName, tableSchema.getName());
+ throw new ColumnSchemaNotFoundException(message);
}
if (row == null) {
return null;
private Object processGetColumn(Method method) throws Throwable {
String columnName = getColumnName(method);
- checkSchemaVersion(dbSchema, method);
+ checkColumnSchemaVersion(dbSchema, method);
if (columnName == null) {
- throw new RuntimeException("Error processing GetColumn : "+ method.getName());
+ throw new TyperException("Error processing GetColumn : "+ method.getName());
}
GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz);
if (tableSchema == null) {
- throw new RuntimeException("Unable to locate TableSchema for "+getTableName(klazz)+ " in "+ dbSchema.getName());
+ String message = TableSchemaNotFoundException.createMessage(getTableName(klazz), dbSchema.getName());
+ throw new TableSchemaNotFoundException(message);
}
ColumnSchema<GenericTableSchema, Object> columnSchema = getColumnSchema(tableSchema, columnName, (Class<Object>) method.getReturnType());
if (columnSchema == null) {
- throw new RuntimeException("Unable to locate ColumnSchema for "+columnName+ " in "+ tableSchema.getName());
+ String message = ColumnSchemaNotFoundException.createMessage(columnName, tableSchema.getName());
+ throw new ColumnSchemaNotFoundException(message);
}
// When the row is null, that might indicate that the user maybe interested only in the ColumnSchema and not on the Data.
if (row == null) {
private Object processSetData(Object proxy, Method method, Object[] args) throws Throwable {
if (args == null || args.length != 1) {
- throw new RuntimeException("Setter method : "+method.getName() + " requires 1 argument");
+ throw new TyperException("Setter method : "+method.getName() + " requires 1 argument");
}
- checkSchemaVersion(dbSchema, method);
+ checkColumnSchemaVersion(dbSchema, method);
String columnName = getColumnName(method);
if (columnName == null) {
- throw new RuntimeException("Unable to locate Column Name for "+method.getName());
+ throw new TyperException("Unable to locate Column Name for "+method.getName());
}
GenericTableSchema tableSchema = getTableSchema(dbSchema, klazz);
ColumnSchema<GenericTableSchema, Object> columnSchema = getColumnSchema(tableSchema, columnName,
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
import org.opendaylight.ovsdb.lib.message.UpdateNotification;
import org.opendaylight.ovsdb.lib.notation.Mutator;
import org.opendaylight.ovsdb.lib.notation.UUID;
Logger logger = LoggerFactory.getLogger(IpfixTestCases.class);
Version schemaVersion;
- Version ipfixFromVersion = Version.fromString("7.3.0");
+ Version ipfixFromVersion = Version.fromString("7.1.0");
@Before
schemaVersion = ovs.getDatabaseSchema("Open_vSwitch").getVersion();
}
- @Test(expected=RuntimeException.class)
- public void testUnsupportedTable() {
+ @Test
+ public void testTableNotSupported() {
// Don't run this test if we can run the IPFIX test
Assume.assumeTrue(schemaVersion.compareTo(ipfixFromVersion) < 0);
- IPFIX ipfix = ovs.createTypedRowWrapper(IPFIX.class);
- ipfix.setTargets(ImmutableSet.of("1.1.1.1:9988"));
+ boolean isExceptionRaised = false;
+ try {
+ IPFIX ipfix = ovs.createTypedRowWrapper(IPFIX.class);
+ } catch (SchemaVersionMismatchException e) {
+ isExceptionRaised = true;
+ }
+ Assert.assertTrue(isExceptionRaised);
}
@Test