* 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
}
/*
- * 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;
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>,
/*
* 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);
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();
}
break;
}
- return false;
+ // TODO remove when re-throwing, and remove Result.Exception completely
+ return Result.Exception;
}
/**
* @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) {