From 858e7d32fe269f8dd0e0218c960f52d09ec18434 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Wed, 20 Jun 2018 14:14:46 +0200 Subject: [PATCH] use (new) INeutronCRUD.Result instead of boolean in update() JIRA: NEUTRON-158 Change-Id: Ia94844c13f823ae169ae8e2295b3d4f89c2f3b91 Signed-off-by: Michael Vorburger --- .../opendaylight/neutron/spi/INeutronCRUD.java | 6 +++--- .../api/AbstractNeutronNorthbound.java | 8 +++++--- .../AbstractTranscriberInterface.java | 17 +++++++++-------- 3 files changed, 17 insertions(+), 14 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 db67d9794..2d3eddf07 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 @@ -72,9 +72,9 @@ public interface INeutronCRUD> { * 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 } diff --git a/northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java b/northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java index 506bbadd9..a1a647a1a 100644 --- a/northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java +++ b/northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/AbstractNeutronNorthbound.java @@ -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, R extends INeutronRequest, @@ -152,7 +153,8 @@ public abstract class AbstractNeutronNorthbound, 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); 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 4c289dd14..7ac1ba3c1 100644 --- a/transcriber/src/main/java/org/opendaylight/neutron/transcriber/AbstractTranscriberInterface.java +++ b/transcriber/src/main/java/org/opendaylight/neutron/transcriber/AbstractTranscriberInterface.java @@ -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) { -- 2.36.6