introduce INeutronCRUD.Result, instead of boolean 30/72730/1
authorMichael Vorburger <vorburger@redhat.com>
Wed, 6 Jun 2018 15:00:14 +0000 (17:00 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Wed, 6 Jun 2018 15:00:49 +0000 (17:00 +0200)
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 <vorburger@redhat.com>
neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronCRUD.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/AbstractTranscriberInterface.java

index a88fc2e7c120fce99a45bec621fb155430ede768..b3f1a3a298d551089363c2d1e76d15c855cc1a88 100644 (file)
@@ -48,9 +48,9 @@ public interface INeutronCRUD<T extends INeutronObject<T>> {
      *
      * @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<T extends INeutronObject<T>> {
      * @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 }
+
 }
index 9caa30df7bfa252eac1c5fe3d651159d18524635..9f31fd81a35fcbd6f1e27ed8a5d37e052976e1c8 100644 (file)
@@ -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 {