summaryrefslogtreecommitdiffstats
path: root/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java
diff options
context:
space:
mode:
authorTibor Sirovatka <tsirovat@cisco.com>2016-05-30 16:52:57 +0200
committerTibor Sirovatka <tsirovat@cisco.com>2016-06-09 08:40:25 +0200
commit744551ed3b657da9f6c8d06bfed4dba4c9fc7700 (patch)
tree364de07c9a5eb1f4f5289f1624576eb5beeb1894 /v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java
parent8014d193008a60ef3857f14d57d931973daa7cc4 (diff)
HONEYCOMB-67 Introduce exception handling into JVPP
VppApiInvocationException replaced by VPP VPPBaseCallException(s) VppInvocationException - send request failed VppCallbackException - operation had failed (negative result) Change-Id: I897afead8d65ef1240e657116a0610850c62348f Signed-off-by: Tibor Sirovatka <tsirovat@cisco.com>
Diffstat (limited to 'v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java')
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java39
1 files changed, 23 insertions, 16 deletions
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java
index 3c1ef7f28..9c3fea615 100644
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java
+++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java
@@ -16,21 +16,23 @@
package io.fd.honeycomb.v3po.translate.v3po.util;
-import static com.google.common.base.Preconditions.checkArgument;
-
import com.google.common.base.Splitter;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.openvpp.jvpp.VppBaseCallException;
+import org.openvpp.jvpp.dto.JVppReply;
+
+import javax.annotation.Nonnegative;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
-import javax.annotation.Nonnegative;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.jvpp.dto.JVppReply;
+
+import static com.google.common.base.Preconditions.checkArgument;
public final class TranslateUtils {
@@ -38,23 +40,26 @@ public final class TranslateUtils {
private TranslateUtils() {}
- public static <REP extends JVppReply<?>> REP getReply(Future<REP> future) {
+ public static <REP extends JVppReply<?>> REP getReply(Future<REP> future) throws VppBaseCallException {
try {
return future.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted", e);
} catch (ExecutionException e) {
- // Execution exception should not occur, since we are using return codes for errors
- // TODO fix when using exceptions instead of return codes
- throw new IllegalArgumentException("Future " + " should not fail with an exception", e);
+ // Execution exception could generally contains any exception
+ // when using exceptions instead of return codes just rethrow it for processing on corresponding place
+ if (e instanceof ExecutionException && ( e.getCause() instanceof VppBaseCallException)) {
+ throw (VppBaseCallException) (e.getCause());
+ }
+ throw new IllegalStateException(e);
}
}
public static <REP extends JVppReply<?>> REP getReply(@Nonnull Future<REP> future,
@Nonnull final InstanceIdentifier<?> replyType,
@Nonnegative final int timeoutInSeconds)
- throws ReadTimeoutException {
+ throws ReadTimeoutException, VppBaseCallException {
try {
checkArgument(timeoutInSeconds > 0, "Timeout cannot be < 0");
return future.get(timeoutInSeconds, TimeUnit.SECONDS);
@@ -62,9 +67,11 @@ public final class TranslateUtils {
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted", e);
} catch (ExecutionException e) {
- // Execution exception should not occur, since we are using return codes for errors
- // TODO fix when using exceptions instead of return codes
- throw new IllegalArgumentException("Future " + " should not fail with an exception", e);
+ // Execution exception could generally contains any exception
+ // when using exceptions instead of return codes just rethrow it for processing on corresponding place
+ if ( e.getCause() instanceof VppBaseCallException)
+ throw (VppBaseCallException)(e.getCause());
+ throw new IllegalStateException(e);
} catch (TimeoutException e) {
throw new ReadTimeoutException(replyType, e);
}