<groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>yang-ext</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-api</artifactId>
+ </dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
package org.opendaylight.neutron.spi;
import java.util.List;
+import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
/**
* This interface defines the methods for CRUD of NB neutron objects.
public interface INeutronCRUD<T extends INeutronObject<T>> {
/**
- * Applications call this interface method to determine if a particular
- * Neutron object exists.
+ * Applications call this interface method to determine if a particular Neutron
+ * object exists.
*
- * @param uuid
- * UUID of the Neutron object
+ * @param uuid UUID of the Neutron object
+ * @param tx the ReadTransaction within which to perform the check
* @return boolean
*/
- boolean exists(String uuid);
+ boolean exists(String uuid, ReadTransaction tx);
/**
* Applications call this interface method to return if a particular
import javax.ws.rs.core.Response;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.neutron.spi.INeutronLoadBalancerPoolCRUD;
import org.opendaylight.neutron.spi.NeutronLoadBalancerPool;
import org.opendaylight.neutron.spi.NeutronLoadBalancerPoolMember;
private static final String RESOURCE_NAME = "LoadBalancerPool";
+ private final DataBroker dataBroker;
+
@Inject
- public NeutronLoadBalancerPoolNorthbound(@OsgiService INeutronLoadBalancerPoolCRUD neutronCRUD) {
+ public NeutronLoadBalancerPoolNorthbound(
+ @OsgiService INeutronLoadBalancerPoolCRUD neutronCRUD,
+ @OsgiService DataBroker dataBroker) {
super(neutronCRUD);
+ this.dataBroker = dataBroker;
}
@Override
// sorting not supported
) {
INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
- if (!loadBalancerPoolInterface.exists(loadBalancerPoolUUID)) {
- throw new ResourceNotFoundException(uuidNoExist());
+ try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
+ if (!loadBalancerPoolInterface.exists(loadBalancerPoolUUID, tx)) {
+ throw new ResourceNotFoundException(uuidNoExist());
+ }
}
List<NeutronLoadBalancerPoolMember> members = loadBalancerPoolInterface.get(loadBalancerPoolUUID)
.getLoadBalancerPoolMembers();
@QueryParam("fields") List<String> fields) {
INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
- if (!loadBalancerPoolInterface.exists(loadBalancerPoolUUID)) {
- throw new ResourceNotFoundException(uuidNoExist());
+ try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
+ if (!loadBalancerPoolInterface.exists(loadBalancerPoolUUID, tx)) {
+ throw new ResourceNotFoundException(uuidNoExist());
+ }
}
List<NeutronLoadBalancerPoolMember> members = loadBalancerPoolInterface.get(loadBalancerPoolUUID)
.getLoadBalancerPoolMembers();
* @param <K> key type to indentify T
* @param <S> Neutron-spi class
* @param <V> parent of U
- *
- *
*/
public abstract class AbstractTranscriberInterface<
T extends DataObject & Identifiable<K> & ChildOf<? super U>,
K extends Identifier<T>, S extends INeutronObject<S>,
V extends DataObject>
implements AutoCloseable, INeutronCRUD<S> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractTranscriberInterface.class);
+
// T extends DataObject & Identifiable<K> & ChildOf<? super U> as 0th type argument
private static final int MD_LIST_CLASS_TYPE_INDEX = 0;
// U extends ChildOf<? super Neutron> & Augmentable<U> as 1st type argument
// S extends INeutronObject<S> as 3rd type argument
private static final int NEUTRON_OBJECT_TYPE_INDEX = 3;
- private static final Logger LOG = LoggerFactory.getLogger(AbstractTranscriberInterface.class);
private static final int DEDASHED_UUID_LENGTH = 32;
private static final int DEDASHED_UUID_START = 0;
private static final int DEDASHED_UUID_DIV1 = 8;
public void close() throws Exception {
}
- private boolean exists(String uuid, ReadTransaction tx) {
+ @Override
+ public boolean exists(String uuid, ReadTransaction tx) {
Preconditions.checkNotNull(tx);
final T dataObject = readMd(createInstanceIdentifier(toMd(uuid)), tx);
return dataObject != null;
}
- @Override
- public boolean exists(String uuid) {
- try (ReadOnlyTransaction tx = getDataBroker().newReadOnlyTransaction()) {
- return exists(uuid, tx);
- }
- }
-
private S get(String uuid, ReadTransaction tx) {
Preconditions.checkNotNull(tx);
final T dataObject = readMd(createInstanceIdentifier(toMd(uuid)), tx);
try {
return add(input, tx);
} catch (InterruptedException | ExecutionException e) {
+ // TODO replace all this with org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner
if (e.getCause() instanceof OptimisticLockFailedException) {
LOG.warn("Got OptimisticLockFailedException - {} {}", input, retries);
continue;