From 42a5db236f6663510b6ce1579c94a8b746452b28 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Wed, 6 Jun 2018 17:00:14 +0200 Subject: [PATCH] introduce INeutronCRUD.Result, instead of boolean and for now use it in add(T input), later remove() & update(). A future follow-up change will extend INeutronCRUD.Result with a 4th additional enum value to signal "DependencyMissing" to callers. JIRA: NEUTRON-158 Change-Id: I5f312008b899862e4957c0ab950b4939fd5b7369 Signed-off-by: Michael Vorburger --- .../org/opendaylight/neutron/spi/INeutronCRUD.java | 8 ++++++-- .../transcriber/AbstractTranscriberInterface.java | 11 ++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronCRUD.java b/neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronCRUD.java index a88fc2e7c..b3f1a3a29 100644 --- a/neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronCRUD.java +++ b/neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronCRUD.java @@ -48,9 +48,9 @@ public interface INeutronCRUD> { * * @param input * OpenStackNeutron object - * @return boolean on whether the object was added or not + * @return result with indication on whether the object was added or not and if so why */ - boolean add(T input); + Result add(T input); /** * Applications call this interface method to remove a Neutron object to the @@ -72,4 +72,8 @@ public interface INeutronCRUD> { * @return boolean on whether the object was updated or not */ boolean update(String uuid, T delta); + + // TODO The Exception Result should eventually be replaced by propagating exceptions, and removed + enum Result { Success, AlreadyExists, Exception } + } diff --git a/transcriber/src/main/java/org/opendaylight/neutron/transcriber/AbstractTranscriberInterface.java b/transcriber/src/main/java/org/opendaylight/neutron/transcriber/AbstractTranscriberInterface.java index 9caa30df7..9f31fd81a 100644 --- a/transcriber/src/main/java/org/opendaylight/neutron/transcriber/AbstractTranscriberInterface.java +++ b/transcriber/src/main/java/org/opendaylight/neutron/transcriber/AbstractTranscriberInterface.java @@ -481,18 +481,18 @@ public abstract class AbstractTranscriberInterface< } } - private boolean add(S input, ReadWriteTransaction tx) throws InterruptedException, ExecutionException { + private Result add(S input, ReadWriteTransaction tx) throws InterruptedException, ExecutionException { Preconditions.checkNotNull(tx); if (exists(input.getID(), tx)) { tx.cancel(); - return false; + return Result.AlreadyExists; } addMd(input, tx); - return true; + return Result.Success; } @Override - public boolean add(S input) { + public Result add(S input) { int retries = RETRY_MAX; while (retries-- >= 0) { final ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction(); @@ -508,7 +508,8 @@ public abstract class AbstractTranscriberInterface< } break; } - return false; + // TODO remove when re-throwing, and remove Result.Exception completely + return Result.Exception; } private boolean remove(String uuid, ReadWriteTransaction tx) throws InterruptedException, ExecutionException { -- 2.36.6