use (new) INeutronCRUD.Result instead of boolean in update() 47/73247/2
authorMichael Vorburger <vorburger@redhat.com>
Wed, 20 Jun 2018 12:14:46 +0000 (14:14 +0200)
committerMichael Vorburger <vorburger@redhat.com>
Mon, 25 Jun 2018 11:59:04 +0000 (13:59 +0200)
JIRA: NEUTRON-158
Change-Id: Ia94844c13f823ae169ae8e2295b3d4f89c2f3b91
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
neutron-spi/src/main/java/org/opendaylight/neutron/spi/INeutronCRUD.java
northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java
transcriber/src/main/java/org/opendaylight/neutron/transcriber/AbstractTranscriberInterface.java

index db67d97947675b56b46b5bc822f37332662d29d4..2d3eddf07351010fd249e7bdae1a2db1e5fe7763 100644 (file)
@@ -72,9 +72,9 @@ public interface INeutronCRUD<T extends INeutronObject<T>> {
      *            OpenStackNeutron object containing changes to apply
      * @return boolean on whether the object was updated or not
      */
-    boolean update(String uuid, T delta);
+    Result update(String uuid, T delta);
 
-    // TODO The Exception Result should eventually be replaced by propagating exceptions, and removed
-    enum Result { Success, AlreadyExists, DependencyMissing, Exception }
+    enum Result { Success, AlreadyExists, DoesNotExist, DependencyMissing, Exception }
+    // TODO The Result "Exception" should eventually be replaced by propagating exceptions, and removed
 
 }
index 506bbadd9377e07fa83974749ab11223c3ff8fc1..a1a647a1aa78cbf9ce1031549387478f1b05a297 100644 (file)
@@ -1,14 +1,14 @@
 /*
- * Copyright (c) 2015 Intel Corporation and others.  All rights reserved.
+ * Copyright (c) 2018 Intel Corporation and others.  All rights reserved.
  *
  * 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
  */
-
 package org.opendaylight.neutron.northbound.api;
 
 import static org.opendaylight.neutron.spi.INeutronCRUD.Result.DependencyMissing;
+import static org.opendaylight.neutron.spi.INeutronCRUD.Result.DoesNotExist;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
@@ -18,6 +18,7 @@ import java.util.List;
 import java.util.Objects;
 import javax.ws.rs.core.Response;
 import org.opendaylight.neutron.spi.INeutronCRUD;
+import org.opendaylight.neutron.spi.INeutronCRUD.Result;
 import org.opendaylight.neutron.spi.INeutronObject;
 
 public abstract class AbstractNeutronNorthbound<T extends INeutronObject<T>, R extends INeutronRequest<T>,
@@ -152,7 +153,8 @@ public abstract class AbstractNeutronNorthbound<T extends INeutronObject<T>, R e
         /*
          * update the object and return it
          */
-        if (!neutronCRUD.update(uuid, delta)) {
+        Result updateResult = neutronCRUD.update(uuid, delta);
+        if (updateResult.equals(DoesNotExist)) {
             throw new ResourceNotFoundException(uuidNoExist());
         }
         T updated = neutronCRUD.get(uuid);
index 4c289dd141fc4d60a8b886afd54e7351a8c694d9..7ac1ba3c1a0f43b0de41aebe265358e82a8cb4b3 100644 (file)
@@ -545,19 +545,19 @@ public abstract class AbstractTranscriberInterface<
         return false;
     }
 
-    private boolean update(String uuid, S delta, ReadWriteTransaction tx)
+    private Result update(String uuid, S delta, ReadWriteTransaction tx)
             throws InterruptedException, ExecutionException {
         Preconditions.checkNotNull(tx);
         if (!exists(uuid, tx)) {
             tx.cancel();
-            return false;
+            return Result.DoesNotExist;
         }
         updateMd(delta, tx);
-        return true;
+        return Result.Success;
     }
 
     @Override
-    public boolean update(String uuid, S delta) {
+    public Result update(String uuid, S delta) {
         int retries = RETRY_MAX;
         while (retries-- >= 0) {
             final ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction();
@@ -573,7 +573,8 @@ public abstract class AbstractTranscriberInterface<
             }
             break;
         }
-        return false;
+        // TODO remove when re-throwing, and remove Result.Exception completely
+        return Result.Exception;
     }
 
     /**
@@ -589,9 +590,9 @@ public abstract class AbstractTranscriberInterface<
      * @param tx the transaction within which to perform reads to check for dependencies
      * @param neutronObject the incoming main neutron object in which there may be references to dependencies
      *
-     * @return true if all dependencies are available and
-     *         {@link #add(INeutronObject)} operation can proceed; false if there
-     *         are unmet dependencies, which will cause the add to abort, and a respective
+     * @return true if all dependencies are available and the
+     *         {@link #add(INeutronObject)} (or {@link #update(String, INeutronObject)} operation can proceed; false if
+     *         there are unmet dependencies, which will cause the add to abort, and a respective
      *         error code returned to the caller.
      */
     protected boolean areAllDependenciesAvailable(ReadTransaction tx, S neutronObject) {