Instead of logging but ultimately ignoring them, as they currently are.
Stumbled across this wile working on (not directly related) NEUTRON-158.
This will also fix the problem raised in NEUTRON-157: We are,
intentionally, changing the OptimisticLockFailedException WARN log to a
DEBUG only. If it still didn't go through after RETRY_MAX (currently 2)
then it will be rethrown, and that, with this, will go back up to the
driver.
JIRA: NEUTRON-157
Change-Id: I10b7dea0b5698db40ee7cfaa63593fb6b3c573c7
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.opendaylight.infrautils</groupId>
+ <artifactId>odl-infrautils-utils</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </dependency>
<dependency>
<groupId>org.opendaylight.aaa</groupId>
<artifactId>odl-aaa-shiro</artifactId>
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.neutron.hostconfig.utils.NeutronHostconfigUtils;
import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
this.neutronHostconfig = new NeutronHostconfigUtils(dataBroker);
}
- private void processChanges(Collection<DataTreeModification<Node>> changes) {
+ private void processChanges(Collection<DataTreeModification<Node>> changes)
+ throws TransactionCommitFailedException {
LOG.info("onDataTreeChanged: Received Data Tree Changed ...", changes);
for (DataTreeModification<Node> change : changes) {
final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
@Override
public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> changes) {
Preconditions.checkNotNull(changes, "Changes may not be null!");
- processChanges(changes);
+ try {
+ processChanges(changes);
+ } catch (TransactionCommitFailedException e) {
+ LOG.error("Transaction commit failed; ignorining changes: ", changes, e);
+ }
}
private InstanceIdentifier<Node> createNodeIdentifier() {
}
}
- private void updateHostConfig(Node node, NeutronHostconfigUtils.Action action) {
+ private void updateHostConfig(Node node, NeutronHostconfigUtils.Action action)
+ throws TransactionCommitFailedException {
String hostId = getExternalId(node, OS_HOST_CONFIG_HOST_ID_KEY);
if (hostId == null) {
return;
package org.opendaylight.neutron.hostconfig.utils;
-import java.util.concurrent.ExecutionException;
-
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.Hostconfigs;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.HostconfigBuilder;
this.dataBroker = dataBroker;
}
- public void updateMdsal(Hostconfig hostConfig, Action action) {
+ public void updateMdsal(Hostconfig hostConfig, Action action) throws TransactionCommitFailedException {
InstanceIdentifier<Hostconfig> hostConfigId;
if (hostConfig == null) {
return;
}
- try {
- switch (action) {
- case ADD:
- case UPDATE:
- final WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
- hostConfigId = createInstanceIdentifier(hostConfig);
- writeTx.put(LogicalDatastoreType.OPERATIONAL, hostConfigId, hostConfig, true);
- writeTx.submit().get();
- LOG.trace("Hostconfig updated for node {}", hostConfig.getHostId());
- break;
- case DELETE:
- final WriteTransaction delTx = dataBroker.newWriteOnlyTransaction();
- hostConfigId = createInstanceIdentifier(hostConfig);
- delTx.delete(LogicalDatastoreType.OPERATIONAL, hostConfigId);
- LOG.trace("Hostconfig deleted for node {}", hostConfig.getHostId());
- delTx.submit().get();
- break;
- default:
- break;
- }
- } catch (InterruptedException | ExecutionException e) {
- LOG.warn("Hostconfig transaction commit failed to DS.", e);
+ switch (action) {
+ case ADD:
+ case UPDATE:
+ final WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
+ hostConfigId = createInstanceIdentifier(hostConfig);
+ writeTx.put(LogicalDatastoreType.OPERATIONAL, hostConfigId, hostConfig, true);
+ writeTx.submit().checkedGet();
+ LOG.trace("Hostconfig updated for node {}", hostConfig.getHostId());
+ break;
+ case DELETE:
+ final WriteTransaction delTx = dataBroker.newWriteOnlyTransaction();
+ hostConfigId = createInstanceIdentifier(hostConfig);
+ delTx.delete(LogicalDatastoreType.OPERATIONAL, hostConfigId);
+ LOG.trace("Hostconfig deleted for node {}", hostConfig.getHostId());
+ delTx.submit().checkedGet();
+ break;
+ default:
+ break;
}
}
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.neutron.hostconfig.utils.NeutronHostconfigUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> changes) {
LOG.info("onDataTreeChanged: Received Data Tree Changed ...", changes);
executorService.execute(() -> {
- for (DataTreeModification<Node> change : Preconditions.checkNotNull(changes, "Changes may not be null!")) {
- processDataTreeModification(change);
+ try {
+ for (DataTreeModification<Node> change : Preconditions.checkNotNull(changes,
+ "Changes may not be null!")) {
+ processDataTreeModification(change);
+ }
+ } catch (TransactionCommitFailedException e) {
+ LOG.error("Transaction commit failed; ignorining changes: ", changes, e);
}
});
}
- private void processDataTreeModification(DataTreeModification<Node> change) {
+ private void processDataTreeModification(DataTreeModification<Node> change)
+ throws TransactionCommitFailedException {
final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
final DataObjectModification<Node> mod = change.getRootNode();
LOG.info("onDataTreeChanged: Received Data Tree Changed Update of Type={} for Key={}",
LOG.info("Registered listener to netconf nodes {}.", dataTreeIdentifier.getRootIdentifier());
}
- private void updateHostConfig(Node node, NeutronHostconfigUtils.Action action) {
+ private void updateHostConfig(Node node, NeutronHostconfigUtils.Action action)
+ throws TransactionCommitFailedException {
for (Map.Entry<String, String> entry : HostconfigUtil.createHostconfigsDataFor(node.getNodeId(), socketInfo)
.entrySet()) {
LOG.info("Updating hostconfig for node {}. Action: {}.", node.key(), action);
<!-- <name> formatting is used by autorelease to parse and notify projects on
build failure. Please do not modify this unless you have a good reason. -->
<name>ODL :: neutron :: ${project.artifactId}</name>
+
<dependencies>
<dependency>
<groupId>org.opendaylight.neutron</groupId>
<groupId>org.opendaylight.controller</groupId>
<artifactId>sal-binding-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-common-api</artifactId>
+ </dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
- <scm>
- <connection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</connection>
- <developerConnection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</developerConnection>
- <tag>HEAD</tag>
- <url>https://wiki.opendaylight.org/view/NeutronNorthBound:Main</url>
- </scm>
</project>
import java.util.List;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
/**
* This interface defines the methods for CRUD of NB neutron objects.
* @param uuid UUID of the Neutron object
* @param tx the ReadTransaction within which to perform the check
* @return boolean
+ * @throws ReadFailedException if the read failed
*/
- boolean exists(String uuid, ReadTransaction tx);
+ boolean exists(String uuid, ReadTransaction tx) throws ReadFailedException;
/**
* Applications call this interface method to return if a particular
* UUID of the Neutron object
* @return {@link org.opendaylight.neutron.spi.INeutronObject}
* OpenStack Neutron class
+ * @throws ReadFailedException if the read failed
*/
- T get(String uuid);
+ T get(String uuid) throws ReadFailedException;
/**
* Applications call this interface method to return all Neutron objects.
*
* @return List of OpenStackNeutrons objects
+ * @throws ReadFailedRuntimeException if the read failed
*/
- List<T> getAll();
+ List<T> getAll() throws ReadFailedRuntimeException;
/**
* Applications call this interface method to add a Neutron object to the
* @param input
* OpenStackNeutron object
* @return result with indication on whether the object was added or not and if so why
+ * @throws OperationFailedException if the write (or a required implicit read) failed
*/
- Result add(T input);
+ Result add(T input) throws OperationFailedException;
/**
* Applications call this interface method to remove a Neutron object to the
* @param uuid
* identifier for the neutron object
* @return boolean on whether the object was removed or not
+ * @throws OperationFailedException if the remove (or a required implicit read) failed
*/
- boolean remove(String uuid);
+ boolean remove(String uuid) throws OperationFailedException;
/**
* Applications call this interface method to edit a Neutron object.
* @param delta
* OpenStackNeutron object containing changes to apply
* @return boolean on whether the object was updated or not
+ * @throws OperationFailedException if the update (or a required implicit read) failed
*/
- Result update(String uuid, T delta);
+ Result update(String uuid, T delta) throws OperationFailedException;
- enum Result { Success, AlreadyExists, DoesNotExist, DependencyMissing, Exception }
- // TODO The Result "Exception" should eventually be replaced by propagating exceptions, and removed
+ enum Result { Success, AlreadyExists, DoesNotExist, DependencyMissing }
}
package org.opendaylight.neutron.spi;
import java.util.List;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
/**
* This interface defines the methods for CRUD of NB OpenStack LoadBalancerPool objects.
* @param uuid
* UUID of the NeutronLoadBalancerPoolMember object
* @return boolean
+ * @throws ReadFailedException if the read failed
*/
- boolean neutronLoadBalancerPoolMemberExists(String poolUuid, String uuid);
+ boolean neutronLoadBalancerPoolMemberExists(String poolUuid, String uuid) throws ReadFailedException;
/**
* Applications call this interface method to return if a particular
* UUID of the NeutronLoadBalancerPoolMember object
* @return {@link org.opendaylight.neutron.spi.NeutronLoadBalancerPoolMember}
* OpenStackNeutronLoadBalancerPoolMember class
+ * @throws ReadFailedException if the read failed
*/
- NeutronLoadBalancerPoolMember getNeutronLoadBalancerPoolMember(String poolUuid, String uuid);
+ NeutronLoadBalancerPoolMember getNeutronLoadBalancerPoolMember(String poolUuid, String uuid)
+ throws ReadFailedException;
/**
* Applications call this interface method to return all NeutronLoadBalancerPoolMember objects.
* @param poolUuid
* UUID of the NeutronLoadBalancerPool object
* @return List of OpenStackNetworks objects
+ * @throws ReadFailedException if the read failed
*/
- List<NeutronLoadBalancerPoolMember> getAllNeutronLoadBalancerPoolMembers(String poolUuid);
+ List<NeutronLoadBalancerPoolMember> getAllNeutronLoadBalancerPoolMembers(String poolUuid)
+ throws ReadFailedException;
/**
* Applications call this interface method to add a NeutronLoadBalancerPoolMember object to the
* @param input
* OpenStackNetwork object
* @return boolean on whether the object was added or not
+ * @throws OperationFailedException if the read or write failed
*/
- boolean addNeutronLoadBalancerPoolMember(String poolUuid, NeutronLoadBalancerPoolMember input);
+ boolean addNeutronLoadBalancerPoolMember(String poolUuid, NeutronLoadBalancerPoolMember input)
+ throws OperationFailedException;
/**
* Applications call this interface method to remove a Neutron NeutronLoadBalancerPoolMember object to the
* @param uuid
* identifier for the NeutronLoadBalancerPoolMember object
* @return boolean on whether the object was removed or not
+ * @throws OperationFailedException if the read or write failed
*/
- boolean removeNeutronLoadBalancerPoolMember(String poolUuid, String uuid);
+ boolean removeNeutronLoadBalancerPoolMember(String poolUuid, String uuid) throws OperationFailedException;
/**
* Applications call this interface method to edit a NeutronLoadBalancerPoolMember object.
* @param delta
* OpenStackNeutronLoadBalancerPoolMember object containing changes to apply
* @return boolean on whether the object was updated or not
+ * @throws OperationFailedException if the read or write operation failed
*/
- boolean updateNeutronLoadBalancerPoolMember(String poolUuid, String uuid, NeutronLoadBalancerPoolMember delta);
+ boolean updateNeutronLoadBalancerPoolMember(String poolUuid, String uuid, NeutronLoadBalancerPoolMember delta)
+ throws OperationFailedException;
/**
* Applications call this interface method to see if a MAC address is in use.
* identifier of the NeutronLoadBalancerPoolMember object
* @return boolean on whether the macAddress is already associated with a
* port or not
+ * @throws ReadFailedException if the read operation failed
*/
- boolean neutronLoadBalancerPoolMemberInUse(String poolUuid, String uuid);
+ boolean neutronLoadBalancerPoolMemberInUse(String poolUuid, String uuid) throws ReadFailedException;
}
*/
package org.opendaylight.neutron.spi;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
+
/**
* This interface defines the methods for CRUD of NB OpenStack Tap Flow objects.
*/
* @param tapFlowUUID
* UUID of Tap Flow
* @return boolean on whether the object was added or not
+ * @throws ReadFailedException if the read failed
*/
- boolean tapFlowExists(String tapServiceUUID, String tapFlowUUID);
+ boolean tapFlowExists(String tapServiceUUID, String tapFlowUUID) throws ReadFailedException;
/**
* Applications call this interface method to get a NeutronTapFlow object.
* @param tapFlowUUID
* UUID of Tap Flow
* @return NeutronTapFlow object
+ * @throws ReadFailedException if the read failed
*/
-
- NeutronTapFlow getTapFlow(String tapServiceUUID, String tapFlowUUID);
+ NeutronTapFlow getTapFlow(String tapServiceUUID, String tapFlowUUID) throws ReadFailedException;
/**
* Applications call this interface method to add a NeutronTapFlow object to the
* @param input
* OpenStackNetwork object
* @return boolean on whether the object was added or not
+ * @throws OperationFailedException if the read or write failed
*/
-
- boolean addTapFlow(NeutronTapFlow input);
+ boolean addTapFlow(NeutronTapFlow input) throws ReadFailedException, OperationFailedException;
/**
* Applications call this interface method to update a NeutronTapFlow object to the
*
* @param input
* OpenStackNetwork object
- * @return boolean on whether the object was added or not
+ * @throws TransactionCommitFailedException if the write failed
*/
-
- boolean updateTapFlow(NeutronTapFlow input);
+ void updateTapFlow(NeutronTapFlow input) throws TransactionCommitFailedException;
/**
* Applications call this interface method to delete a NeutronTapFlow object.
* UUID of Tap Service
* @param tapFlowUUID
* UUID of Tap Flow
- * @return boolean on whether the object was added or not
+ * @throws TransactionCommitFailedException if the write failed
*/
-
- boolean deleteTapFlow(String tapServiceUUID, String tapFlowUUID);
+ void deleteTapFlow(String tapServiceUUID, String tapFlowUUID) throws TransactionCommitFailedException;
}
--- /dev/null
+/*
+ * Copyright (c) 2018 Red Hat, Inc. 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.spi;
+
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+
+/**
+ * {@link ReadFailedException} as an unchecked RuntimeException.
+ * See also org.opendaylight.neutron.northbound.api.DatastoreOperationFailedWebApplicationException.
+ *
+ * @author Michael Vorburger.ch
+ */
+public class ReadFailedRuntimeException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ public ReadFailedRuntimeException(ReadFailedException cause) {
+ super(cause);
+ }
+}
</dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-common-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.codehaus.enunciate</groupId>
<artifactId>enunciate-core-annotations</artifactId>
import org.opendaylight.neutron.spi.INeutronCRUD;
import org.opendaylight.neutron.spi.INeutronCRUD.Result;
import org.opendaylight.neutron.spi.INeutronObject;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
public abstract class AbstractNeutronNorthbound<T extends INeutronObject<T>, R extends INeutronRequest<T>,
I extends INeutronCRUD<T>> {
return this.neutronCRUD;
}
- protected Response show(String uuid,
- // return fields
- List<String> fields) {
- T ans = neutronCRUD.get(uuid);
- if (ans == null) {
- throw new ResourceNotFoundException(uuidNoExist());
- }
+ protected Response show(String uuid, List<String> returnFields)
+ throws DatastoreOperationFailedWebApplicationException {
+ try {
+ T ans = neutronCRUD.get(uuid);
+ if (ans == null) {
+ throw new ResourceNotFoundException(uuidNoExist());
+ }
- if (fields.size() > 0) {
- return Response.status(HttpURLConnection.HTTP_OK).entity(newNeutronRequest(ans.extractFields(fields)))
- .build();
- } else {
- return Response.status(HttpURLConnection.HTTP_OK).entity(newNeutronRequest(ans)).build();
+ if (returnFields.size() > 0) {
+ return Response.status(HttpURLConnection.HTTP_OK)
+ .entity(newNeutronRequest(ans.extractFields(returnFields))).build();
+ } else {
+ return Response.status(HttpURLConnection.HTTP_OK).entity(newNeutronRequest(ans)).build();
+ }
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
}
}
- protected Response create(final R input) {
- if (input.isSingleton()) {
- T singleton = input.getSingleton();
+ protected Response create(final R input) throws DatastoreOperationFailedWebApplicationException {
+ try {
+ if (input.isSingleton()) {
+ T singleton = input.getSingleton();
- singleton.initDefaults();
- if (neutronCRUD.add(singleton).equals(DependencyMissing)) {
- return Response.status(HTTP_MISSING_DEPENDENCY).entity(input).build();
- }
- } else {
- if (input.getBulk() == null) {
- throw new BadRequestException("Invalid requests");
- }
- for (T test : input.getBulk()) {
- test.initDefaults();
- if (neutronCRUD.add(test).equals(DependencyMissing)) {
+ singleton.initDefaults();
+ if (neutronCRUD.add(singleton).equals(DependencyMissing)) {
return Response.status(HTTP_MISSING_DEPENDENCY).entity(input).build();
}
+ } else {
+ if (input.getBulk() == null) {
+ throw new BadRequestException("Invalid requests");
+ }
+ for (T test : input.getBulk()) {
+ test.initDefaults();
+ if (neutronCRUD.add(test).equals(DependencyMissing)) {
+ return Response.status(HTTP_MISSING_DEPENDENCY).entity(input).build();
+ }
+ }
}
+ return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
}
- return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
}
protected void updateDelta(String uuid, T delta, T original) {
return false;
}
- protected Response update(String uuid, final R input) {
+ protected Response update(String uuid, final R input) throws DatastoreOperationFailedWebApplicationException {
if (!input.isSingleton()) {
throw new BadRequestException("Only singleton edit supported");
}
T delta = input.getSingleton();
- T original = neutronCRUD.get(uuid);
- if (original == null) {
- throw new ResourceNotFoundException(uuidNoExist());
- }
- if (checkRevisionNumber(original, delta)) {
- return Response.status(HttpURLConnection.HTTP_OK).build();
- }
- updateDelta(uuid, delta, original);
- /*
- * update the object and return it
- */
- Result updateResult = neutronCRUD.update(uuid, delta);
- if (updateResult.equals(DoesNotExist)) {
- throw new ResourceNotFoundException(uuidNoExist());
- } else if (updateResult.equals(DependencyMissing)) {
- return Response.status(HTTP_MISSING_DEPENDENCY).entity(input).build();
+ try {
+ T original = neutronCRUD.get(uuid);
+ if (original == null) {
+ throw new ResourceNotFoundException(uuidNoExist());
+ }
+ if (checkRevisionNumber(original, delta)) {
+ return Response.status(HttpURLConnection.HTTP_OK).build();
+ }
+ updateDelta(uuid, delta, original);
+ /*
+ * update the object and return it
+ */
+ Result updateResult = neutronCRUD.update(uuid, delta);
+ if (updateResult.equals(DoesNotExist)) {
+ throw new ResourceNotFoundException(uuidNoExist());
+ } else if (updateResult.equals(DependencyMissing)) {
+ return Response.status(HTTP_MISSING_DEPENDENCY).entity(input).build();
+ }
+ T updated = neutronCRUD.get(uuid);
+ return Response.status(HttpURLConnection.HTTP_OK).entity(newNeutronRequest(updated)).build();
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
}
- T updated = neutronCRUD.get(uuid);
- return Response.status(HttpURLConnection.HTTP_OK).entity(newNeutronRequest(updated)).build();
}
- protected Response delete(String uuid) {
- /*
- * remove it and return 204 status
- */
- if (!neutronCRUD.remove(uuid)) {
- throw new ResourceNotFoundException(uuidNoExist());
+ protected Response delete(String uuid) throws DatastoreOperationFailedWebApplicationException {
+ try {
+ // remove it and return 204 status
+ if (!neutronCRUD.remove(uuid)) {
+ throw new ResourceNotFoundException(uuidNoExist());
+ } else {
+ return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
+ }
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
}
-
- return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
}
}
--- /dev/null
+/*
+ * Copyright (c) 2018 Red Hat, Inc. 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 javax.ws.rs.WebApplicationException;
+import org.opendaylight.neutron.spi.ReadFailedRuntimeException;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
+
+/**
+ * JAX RS specific exception wrapping an ODL MDSAL datastore read/validate/write operation failure.
+ *
+ * @see ReadFailedRuntimeException
+ *
+ * @author Michael Vorburger.ch
+ */
+public class DatastoreOperationFailedWebApplicationException extends WebApplicationException {
+ private static final long serialVersionUID = 1L;
+
+ public DatastoreOperationFailedWebApplicationException(OperationFailedException cause) {
+ super(cause);
+ }
+
+}
*/
package org.opendaylight.neutron.northbound.api;
+import static java.net.HttpURLConnection.HTTP_OK;
+
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;
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.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.neutron.spi.INeutronLoadBalancerPoolCRUD;
import org.opendaylight.neutron.spi.NeutronLoadBalancerPool;
import org.opendaylight.neutron.spi.NeutronLoadBalancerPoolMember;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
import org.ops4j.pax.cdi.api.OsgiService;
/**
// sorting not supported
) {
INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
- try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
- if (!loadBalancerPoolInterface.exists(loadBalancerPoolUUID, tx)) {
- throw new ResourceNotFoundException(uuidNoExist());
+ try {
+ try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
+ if (!loadBalancerPoolInterface.exists(loadBalancerPoolUUID, tx)) {
+ throw new ResourceNotFoundException(uuidNoExist());
+ }
}
- }
- List<NeutronLoadBalancerPoolMember> members = loadBalancerPoolInterface.get(loadBalancerPoolUUID)
- .getLoadBalancerPoolMembers();
- List<NeutronLoadBalancerPoolMember> ans = new ArrayList<>();
- for (NeutronLoadBalancerPoolMember nsg : members) {
- if ((queryLoadBalancerPoolMemberID == null || queryLoadBalancerPoolMemberID.equals(nsg.getID()))
- && loadBalancerPoolUUID.equals(nsg.getPoolID())
- && (queryLoadBalancerPoolMemberTenantID == null
- || queryLoadBalancerPoolMemberTenantID.equals(nsg.getTenantID()))
- && (queryLoadBalancerPoolMemberAddress == null
- || queryLoadBalancerPoolMemberAddress.equals(nsg.getPoolMemberAddress()))
- && (queryLoadBalancerPoolMemberAdminStateUp == null
- || queryLoadBalancerPoolMemberAdminStateUp.equals(nsg.getPoolMemberAdminStateIsUp()))
- && (queryLoadBalancerPoolMemberWeight == null
- || queryLoadBalancerPoolMemberWeight.equals(nsg.getPoolMemberWeight()))
- && (queryLoadBalancerPoolMemberSubnetID == null
- || queryLoadBalancerPoolMemberSubnetID.equals(nsg.getPoolMemberSubnetID()))) {
- if (fields.size() > 0) {
- ans.add(nsg.extractFields(fields));
- } else {
- ans.add(nsg);
+ List<NeutronLoadBalancerPoolMember> members = loadBalancerPoolInterface.get(loadBalancerPoolUUID)
+ .getLoadBalancerPoolMembers();
+ List<NeutronLoadBalancerPoolMember> ans = new ArrayList<>();
+ for (NeutronLoadBalancerPoolMember nsg : members) {
+ if ((queryLoadBalancerPoolMemberID == null || queryLoadBalancerPoolMemberID.equals(nsg.getID()))
+ && loadBalancerPoolUUID.equals(nsg.getPoolID())
+ && (queryLoadBalancerPoolMemberTenantID == null
+ || queryLoadBalancerPoolMemberTenantID.equals(nsg.getTenantID()))
+ && (queryLoadBalancerPoolMemberAddress == null
+ || queryLoadBalancerPoolMemberAddress.equals(nsg.getPoolMemberAddress()))
+ && (queryLoadBalancerPoolMemberAdminStateUp == null
+ || queryLoadBalancerPoolMemberAdminStateUp.equals(nsg.getPoolMemberAdminStateIsUp()))
+ && (queryLoadBalancerPoolMemberWeight == null
+ || queryLoadBalancerPoolMemberWeight.equals(nsg.getPoolMemberWeight()))
+ && (queryLoadBalancerPoolMemberSubnetID == null
+ || queryLoadBalancerPoolMemberSubnetID.equals(nsg.getPoolMemberSubnetID()))) {
+ if (fields.size() > 0) {
+ ans.add(nsg.extractFields(fields));
+ } else {
+ ans.add(nsg);
+ }
}
}
+ return Response.status(HTTP_OK).entity(new NeutronLoadBalancerPoolMemberRequest(ans)).build();
+ } catch (ReadFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
}
- return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronLoadBalancerPoolMemberRequest(ans)).build();
}
/**
// return fields
@QueryParam("fields") List<String> fields) {
- INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
- try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
- if (!loadBalancerPoolInterface.exists(loadBalancerPoolUUID, tx)) {
- throw new ResourceNotFoundException(uuidNoExist());
- }
- }
- List<NeutronLoadBalancerPoolMember> members = loadBalancerPoolInterface.get(loadBalancerPoolUUID)
- .getLoadBalancerPoolMembers();
- for (NeutronLoadBalancerPoolMember ans : members) {
- if (!ans.getID().equals(loadBalancerPoolMemberUUID)) {
- continue;
+ try {
+ INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
+ try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
+ if (!loadBalancerPoolInterface.exists(loadBalancerPoolUUID, tx)) {
+ throw new ResourceNotFoundException(uuidNoExist());
+ }
}
+ List<NeutronLoadBalancerPoolMember> members = loadBalancerPoolInterface.get(loadBalancerPoolUUID)
+ .getLoadBalancerPoolMembers();
+ for (NeutronLoadBalancerPoolMember ans : members) {
+ if (!ans.getID().equals(loadBalancerPoolMemberUUID)) {
+ continue;
+ }
- if (fields.size() > 0) {
- return Response.status(HttpURLConnection.HTTP_OK)
- .entity(new NeutronLoadBalancerPoolMemberRequest(ans.extractFields(fields))).build();
- } else {
- return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronLoadBalancerPoolMemberRequest(ans))
- .build();
+ if (fields.size() > 0) {
+ return Response.status(HttpURLConnection.HTTP_OK)
+ .entity(new NeutronLoadBalancerPoolMemberRequest(ans.extractFields(fields))).build();
+ } else {
+ return Response.status(HttpURLConnection.HTTP_OK)
+ .entity(new NeutronLoadBalancerPoolMemberRequest(ans)).build();
+ }
}
+ throw new ResourceNotFoundException(uuidNoExist());
+ } catch (ReadFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
}
- throw new ResourceNotFoundException(uuidNoExist());
}
/**
@ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response createLoadBalancerPoolMember(@PathParam("loadBalancerPoolUUID") String loadBalancerPoolUUID,
final NeutronLoadBalancerPoolMemberRequest input) {
+ try {
+ INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
- INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
-
- if (input.isSingleton()) {
- NeutronLoadBalancerPoolMember singleton = input.getSingleton();
- singleton.setPoolID(loadBalancerPoolUUID);
- /**
- * Add the member from the neutron load balancer pool as well
- */
+ if (input.isSingleton()) {
+ NeutronLoadBalancerPoolMember singleton = input.getSingleton();
+ singleton.setPoolID(loadBalancerPoolUUID);
+ /**
+ * Add the member from the neutron load balancer pool as well
+ */
- loadBalancerPoolInterface.addNeutronLoadBalancerPoolMember(loadBalancerPoolUUID, singleton);
- } else {
- /*
- * now, each element of the bulk request can be added to the cache
- */
- for (NeutronLoadBalancerPoolMember test : input.getBulk()) {
- loadBalancerPoolInterface.addNeutronLoadBalancerPoolMember(loadBalancerPoolUUID, test);
+ loadBalancerPoolInterface.addNeutronLoadBalancerPoolMember(loadBalancerPoolUUID, singleton);
+ } else {
+ /*
+ * now, each element of the bulk request can be added to the cache
+ */
+ for (NeutronLoadBalancerPoolMember test : input.getBulk()) {
+ loadBalancerPoolInterface.addNeutronLoadBalancerPoolMember(loadBalancerPoolUUID, test);
+ }
}
+ return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
}
- return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
}
/**
public Response updateLoadBalancerPoolMember(@PathParam("loadBalancerPoolUUID") String loadBalancerPoolUUID,
@PathParam("loadBalancerPoolMemberUUID") String loadBalancerPoolMemberUUID,
final NeutronLoadBalancerPoolMemberRequest input) {
- INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
- NeutronLoadBalancerPool singletonPool = loadBalancerPoolInterface.get(loadBalancerPoolUUID);
- NeutronLoadBalancerPoolMember singleton = input.getSingleton();
- singleton.setPoolID(loadBalancerPoolUUID);
+ try {
+ INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
+ NeutronLoadBalancerPool singletonPool = loadBalancerPoolInterface.get(loadBalancerPoolUUID);
+ NeutronLoadBalancerPoolMember singleton = input.getSingleton();
+ singleton.setPoolID(loadBalancerPoolUUID);
- if (singletonPool == null) {
- throw new ResourceNotFoundException("Pool doesn't Exist");
+ if (singletonPool == null) {
+ throw new ResourceNotFoundException("Pool doesn't Exist");
+ }
+ loadBalancerPoolInterface.updateNeutronLoadBalancerPoolMember(loadBalancerPoolUUID,
+ loadBalancerPoolMemberUUID, singleton);
+ return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
}
- loadBalancerPoolInterface.updateNeutronLoadBalancerPoolMember(loadBalancerPoolUUID, loadBalancerPoolMemberUUID,
- singleton);
- return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
}
/**
@ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response deleteLoadBalancerPoolMember(@PathParam("loadBalancerPoolUUID") String loadBalancerPoolUUID,
@PathParam("loadBalancerPoolMemberUUID") String loadBalancerPoolMemberUUID) {
- INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
-
- //Verify that the LB pool member exists
- NeutronLoadBalancerPoolMember singleton = null;
- List<NeutronLoadBalancerPoolMember> members = loadBalancerPoolInterface.get(loadBalancerPoolUUID)
- .getLoadBalancerPoolMembers();
- for (NeutronLoadBalancerPoolMember member : members) {
- if (member.getID().equals(loadBalancerPoolMemberUUID)) {
- singleton = member;
- break;
+ try {
+ INeutronLoadBalancerPoolCRUD loadBalancerPoolInterface = getNeutronCRUD();
+ // Verify that the LB pool member exists
+ NeutronLoadBalancerPoolMember singleton = null;
+ List<NeutronLoadBalancerPoolMember> members = loadBalancerPoolInterface.get(loadBalancerPoolUUID)
+ .getLoadBalancerPoolMembers();
+ for (NeutronLoadBalancerPoolMember member : members) {
+ if (member.getID().equals(loadBalancerPoolMemberUUID)) {
+ singleton = member;
+ break;
+ }
+ }
+ if (singleton == null) {
+ throw new BadRequestException("LoadBalancerPoolMember UUID does not exist.");
}
- }
- if (singleton == null) {
- throw new BadRequestException("LoadBalancerPoolMember UUID does not exist.");
- }
- /**
- * Remove the member from the neutron load balancer pool
- */
- loadBalancerPoolInterface.removeNeutronLoadBalancerPoolMember(loadBalancerPoolUUID, loadBalancerPoolMemberUUID);
+ /**
+ * Remove the member from the neutron load balancer pool
+ */
+ loadBalancerPoolInterface.removeNeutronLoadBalancerPoolMember(loadBalancerPoolUUID,
+ loadBalancerPoolMemberUUID);
- return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
+ return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
+ }
}
}
import org.codehaus.enunciate.jaxrs.StatusCodes;
import org.opendaylight.neutron.spi.INeutronMeteringLabelRuleCRUD;
import org.opendaylight.neutron.spi.NeutronMeteringLabelRule;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
import org.ops4j.pax.cdi.api.OsgiService;
/**
@StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
@ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response createMeteringLabelRule(final NeutronMeteringLabelRuleRequest input) {
- INeutronMeteringLabelRuleCRUD meteringLabelRuleInterface = getNeutronCRUD();
if (input.isSingleton()) {
NeutronMeteringLabelRule singleton = input.getSingleton();
+ try {
+ // add meteringLabelRule to the cache
+ INeutronMeteringLabelRuleCRUD meteringLabelRuleInterface = getNeutronCRUD();
+ meteringLabelRuleInterface.add(singleton);
+ return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
- /*
- * add meteringLabelRule to the cache
- */
- meteringLabelRuleInterface.add(singleton);
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
+ }
} else {
-
- /*
- * only singleton meteringLabelRule creates supported
- */
+ // only singleton meteringLabelRule creates supported
throw new BadRequestException("Only singleton meteringLabelRule creates supported");
}
- return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
}
/**
import javax.ws.rs.core.Response;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.neutron.spi.INeutronTapFlowCRUD;
import org.opendaylight.neutron.spi.NeutronTapFlow;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
import org.ops4j.pax.cdi.api.OsgiService;
@Singleton
NeutronTapFlow singleton = input.getSingleton();
singleton.setTapFlowServiceID(tapServiceUUID);
- tapFlowInterface.addTapFlow(singleton);
+ try {
+ tapFlowInterface.addTapFlow(singleton);
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
+ }
} else {
throw new BadRequestException("Only Singleton tapFlow creation supported");
}
public Response showTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
@PathParam("tapFlowUUID") String tapFlowUUID,
@QueryParam("fields") List<String> fields) {
+ try {
+ INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
+ if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
+ throw new ResourceNotFoundException("Specified UUID does not Exist");
+ }
- INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
- if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
- throw new ResourceNotFoundException("Specified UUID does not Exist");
- }
-
- NeutronTapFlow tapFlow = tapFlowInterface.getTapFlow(tapServiceUUID, tapFlowUUID);
- if (fields.size() > 0) {
- return Response.status(HttpURLConnection.HTTP_OK)
- .entity(new NeutronTapFlowRequest(tapFlow.extractFields(fields))).build();
- } else {
- return Response.status(HttpURLConnection.HTTP_OK)
- .entity(new NeutronTapFlowRequest(tapFlow)).build();
+ NeutronTapFlow tapFlow = tapFlowInterface.getTapFlow(tapServiceUUID, tapFlowUUID);
+ if (fields.size() > 0) {
+ return Response.status(HttpURLConnection.HTTP_OK)
+ .entity(new NeutronTapFlowRequest(tapFlow.extractFields(fields))).build();
+ } else {
+ return Response.status(HttpURLConnection.HTTP_OK)
+ .entity(new NeutronTapFlowRequest(tapFlow)).build();
+ }
+ } catch (ReadFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
}
}
public Response updateTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
@PathParam("tapFlowUUID") String tapFlowUUID,
final NeutronTapFlowRequest input) {
+ try {
+ INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
- INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
-
- if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
- throw new ResourceNotFoundException("Specified UUID does not Exist");
- }
+ if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
+ throw new ResourceNotFoundException("Specified UUID does not Exist");
+ }
- NeutronTapFlow singleton = input.getSingleton();
- singleton.setTapFlowServiceID(tapServiceUUID);
- tapFlowInterface.updateTapFlow(singleton);
+ NeutronTapFlow singleton = input.getSingleton();
+ singleton.setTapFlowServiceID(tapServiceUUID);
+ tapFlowInterface.updateTapFlow(singleton);
- return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
+ return Response.status(HttpURLConnection.HTTP_OK).entity(input).build();
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
+ }
}
/**
@ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
public Response deleteTapFlow(@PathParam("tapServiceUUID") String tapServiceUUID,
@PathParam("tapFlowUUID") String tapFlowUUID) {
+ try {
+ INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
- INeutronTapFlowCRUD tapFlowInterface = getNeutronCRUD();
+ if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
+ throw new ResourceNotFoundException("Specified UUID does not Exist");
+ }
- if (!tapFlowInterface.tapFlowExists(tapServiceUUID, tapFlowUUID)) {
- throw new ResourceNotFoundException("Specified UUID does not Exist");
+ tapFlowInterface.deleteTapFlow(tapServiceUUID, tapFlowUUID);
+ return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
+ } catch (OperationFailedException e) {
+ throw new DatastoreOperationFailedWebApplicationException(e);
}
-
- tapFlowInterface.deleteTapFlow(tapServiceUUID, tapFlowUUID);
- return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build();
}
}
<dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>org.opendaylight.infrautils</groupId>
+ <artifactId>infrautils-artifacts</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>mdsal-artifacts</artifactId>
<artifactId>model</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.infrautils</groupId>
+ <artifactId>infrautils-util</artifactId>
+ </dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.function.Function;
import javax.annotation.PreDestroy;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.infrautils.utils.function.CheckedFunction;
import org.opendaylight.neutron.spi.INeutronAdminAttributes;
import org.opendaylight.neutron.spi.INeutronBaseAttributes;
import org.opendaylight.neutron.spi.INeutronCRUD;
import org.opendaylight.neutron.spi.INeutronObject;
import org.opendaylight.neutron.spi.NeutronObject;
+import org.opendaylight.neutron.spi.ReadFailedRuntimeException;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.attrs.rev150712.AdminAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.attrs.rev150712.BaseAttributes;
import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
protected abstract S fromMd(T dataObject);
- private <W extends DataObject> W readMd(InstanceIdentifier<W> path, ReadTransaction tx) {
+ private <W extends DataObject> W readMd(InstanceIdentifier<W> path, ReadTransaction tx) throws ReadFailedException {
Preconditions.checkNotNull(tx);
W result = null;
final CheckedFuture<Optional<W>,
ReadFailedException> future = tx.read(LogicalDatastoreType.CONFIGURATION, path);
if (future != null) {
- Optional<W> optional;
- try {
- optional = future.checkedGet();
- if (optional.isPresent()) {
- result = optional.get();
- }
- } catch (final ReadFailedException e) {
- LOG.warn("Failed to read {}", path, e);
+ Optional<W> optional = future.checkedGet();
+ if (optional.isPresent()) {
+ result = optional.get();
}
}
return result;
}
- protected <W extends DataObject> W readMd(InstanceIdentifier<W> path) {
+ protected <W extends DataObject> W readMd(InstanceIdentifier<W> path) throws ReadFailedException {
try (ReadOnlyTransaction tx = getDataBroker().newReadOnlyTransaction()) {
return readMd(path, tx);
}
}
- private void addMd(S neutronObject, WriteTransaction tx) throws InterruptedException, ExecutionException {
+ private void addMd(S neutronObject, WriteTransaction tx) throws TransactionCommitFailedException {
// TODO think about adding existence logic
updateMd(neutronObject, tx);
}
- private void updateMd(S neutronObject, WriteTransaction tx) throws InterruptedException, ExecutionException {
+ private void updateMd(S neutronObject, WriteTransaction tx) throws TransactionCommitFailedException {
Preconditions.checkNotNull(tx);
final T item = toMd(neutronObject);
tx.put(LogicalDatastoreType.CONFIGURATION, iid, item, true);
final CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
// Check if it's successfully committed, otherwise exception will be thrown.
- future.get();
+ future.checkedGet();
}
- private void removeMd(T item, WriteTransaction tx) throws InterruptedException, ExecutionException {
+ private void removeMd(T item, WriteTransaction tx) throws TransactionCommitFailedException {
Preconditions.checkNotNull(tx);
final InstanceIdentifier<T> iid = createInstanceIdentifier(item);
tx.delete(LogicalDatastoreType.CONFIGURATION, iid);
final CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
// Check if it's successfully committed, otherwise exception will be thrown.
- future.get();
+ future.checkedGet();
}
protected static Uuid toUuid(String uuid) {
}
@Override
- public boolean exists(String uuid, ReadTransaction tx) {
+ public boolean exists(String uuid, ReadTransaction tx) throws ReadFailedException {
Preconditions.checkNotNull(tx);
final T dataObject = readMd(createInstanceIdentifier(toMd(uuid)), tx);
return dataObject != null;
}
- private S get(String uuid, ReadTransaction tx) {
+ private S get(String uuid, ReadTransaction tx) throws ReadFailedException {
Preconditions.checkNotNull(tx);
final T dataObject = readMd(createInstanceIdentifier(toMd(uuid)), tx);
if (dataObject == null) {
}
@Override
- public S get(String uuid) {
+ public S get(String uuid) throws ReadFailedException {
try (ReadOnlyTransaction tx = getDataBroker().newReadOnlyTransaction()) {
return get(uuid, tx);
}
protected abstract List<T> getDataObjectList(U dataObjects);
- private List<S> getAll(ReadTransaction tx) {
+ private List<S> getAll(ReadTransaction tx) throws ReadFailedException {
Preconditions.checkNotNull(tx);
final Set<S> allNeutronObjects = new HashSet<>();
final U dataObjects = readMd(createInstanceIdentifier(), tx);
}
@Override
- public List<S> getAll() {
+ public List<S> getAll() throws ReadFailedRuntimeException {
try (ReadOnlyTransaction tx = getDataBroker().newReadOnlyTransaction()) {
- return getAll(tx);
+ try {
+ return getAll(tx);
+ } catch (ReadFailedException e) {
+ throw new ReadFailedRuntimeException(e);
+ }
}
}
- private Result add(S input, ReadWriteTransaction tx) throws InterruptedException, ExecutionException {
+ private Result add(S input, ReadWriteTransaction tx) throws OperationFailedException {
Preconditions.checkNotNull(tx);
if (exists(input.getID(), tx)) {
tx.cancel();
}
@Override
- public Result add(S input) {
+ public Result add(S input) throws OperationFailedException {
int retries = RETRY_MAX;
+ OptimisticLockFailedException lastOptimisticLockFailedException = null;
while (retries-- >= 0) {
final ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction();
try {
} else {
return Result.DependencyMissing;
}
- } catch (InterruptedException | ExecutionException e) {
+ } catch (TransactionCommitFailedException e) {
// TODO replace all this with org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner
- if (e.getCause() instanceof OptimisticLockFailedException) {
- LOG.warn("Got OptimisticLockFailedException - {} {}", input, retries);
+ if (e instanceof OptimisticLockFailedException) {
+ LOG.debug("Got OptimisticLockFailedException - {} {}", input, retries);
+ lastOptimisticLockFailedException = (OptimisticLockFailedException) e;
continue;
+ } else {
+ throw e;
}
- // TODO: rethrow exception. don't mask exception
- LOG.error("Transaction failed", e);
}
- break;
}
- // TODO remove when re-throwing, and remove Result.Exception completely
- return Result.Exception;
+ throw lastOptimisticLockFailedException;
}
- private boolean remove(String uuid, ReadWriteTransaction tx) throws InterruptedException, ExecutionException {
+ private boolean remove(String uuid, ReadWriteTransaction tx) throws OperationFailedException {
Preconditions.checkNotNull(tx);
if (!exists(uuid, tx)) {
tx.cancel();
}
@Override
- public boolean remove(String uuid) {
+ public boolean remove(String uuid) throws OperationFailedException {
int retries = RETRY_MAX;
+ OptimisticLockFailedException lastOptimisticLockFailedException = null;
while (retries-- >= 0) {
final ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction();
try {
return remove(uuid, tx);
- } catch (InterruptedException | ExecutionException e) {
- if (e.getCause() instanceof OptimisticLockFailedException) {
- LOG.warn("Got OptimisticLockFailedException - {} {}", uuid, retries);
+ } catch (TransactionCommitFailedException e) {
+ // TODO replace all this with org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner
+ if (e instanceof OptimisticLockFailedException) {
+ LOG.debug("Got OptimisticLockFailedException - {} {}", uuid, retries);
+ lastOptimisticLockFailedException = (OptimisticLockFailedException) e;
continue;
+ } else {
+ throw e;
}
- // TODO: rethrow exception. don't mask exception
- LOG.error("Transaction failed", e);
}
- break;
}
- return false;
+ throw lastOptimisticLockFailedException;
}
- private Result update(String uuid, S delta, ReadWriteTransaction tx)
- throws InterruptedException, ExecutionException {
+ private Result update(String uuid, S delta, ReadWriteTransaction tx) throws OperationFailedException {
Preconditions.checkNotNull(tx);
if (!exists(uuid, tx)) {
tx.cancel();
}
@Override
- public Result update(String uuid, S delta) {
+ public Result update(String uuid, S delta) throws OperationFailedException {
int retries = RETRY_MAX;
+ OptimisticLockFailedException lastOptimisticLockFailedException = null;
while (retries-- >= 0) {
final ReadWriteTransaction tx = getDataBroker().newReadWriteTransaction();
try {
} else {
return Result.DependencyMissing;
}
- } catch (InterruptedException | ExecutionException e) {
- if (e.getCause() instanceof OptimisticLockFailedException) {
- LOG.warn("Got OptimisticLockFailedException - {} {} {}", uuid, delta, retries);
+ } catch (TransactionCommitFailedException e) {
+ // TODO replace all this with org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner
+ if (e instanceof OptimisticLockFailedException) {
+ LOG.debug("Got OptimisticLockFailedException - {} {} {}", uuid, delta, retries);
+ lastOptimisticLockFailedException = (OptimisticLockFailedException) e;
continue;
+ } else {
+ throw e;
}
- // TODO: rethrow exception. don't mask exception
- LOG.error("Transaction failed", e);
}
- break;
}
- // TODO remove when re-throwing, and remove Result.Exception completely
- return Result.Exception;
+ throw lastOptimisticLockFailedException;
}
/**
* <p>Implementations *MUST* use the passed in transaction. They will typically call the
* {@link #exists(String, ReadTransaction)} method on ANOTHER transcriber with it.
*
- * <p>Implementations should chain {@link #ifNonNull(Object, Function)}, or perform null safe comparisons otherwise,
- * for both optional non-mandatory {@link NeutronObject} as well as mandatory properties which may well be null.
- * Both must mandatory and non-mandatory must be guarded, because modify (update) operation are allowed to contain
- * partial neutron objects with missing fields.
+ * <p>Implementations should chain {@link #ifNonNull(Object, CheckedFunction)}, or perform null safe comparisons
+ * otherwise, for both optional non-mandatory {@link NeutronObject} as well as mandatory properties which may well
+ * be null. Both must mandatory and non-mandatory must be guarded, because modify (update) operation are allowed to
+ * contain partial neutron objects with missing fields.
*
* @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
* {@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.
+ *
+ * @throws ReadFailedException in case of a data store problem
*/
- protected boolean areAllDependenciesAvailable(ReadTransaction tx, S neutronObject) {
+ protected boolean areAllDependenciesAvailable(ReadTransaction tx, S neutronObject) throws ReadFailedException {
return true;
}
/**
* Utility to perform well readable code of null-safe chains of e.g.
* {@link #exists(String, ReadTransaction)} method calls.
+ *
+ * @throws ReadFailedException in case of a data store problem
*/
- protected static final <X> boolean ifNonNull(
- @Nullable X property, Function<@NonNull X, @NonNull Boolean> function) {
+ protected static final <X> boolean ifNonNull(@Nullable X property,
+ CheckedFunction<@NonNull X, @NonNull Boolean, ReadFailedException> function) throws ReadFailedException {
if (property != null) {
Boolean result = function.apply(property);
Preconditions.checkNotNull(result, "result");
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.ExecutionException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.pools.pool.members.MemberBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.pool.attributes.SessionPersistenceBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
import org.ops4j.pax.cdi.api.OsgiServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
answer.setLoadBalancerPoolProtocol(PROTOCOL_MAP.get(pool.getProtocol()));
}
if (pool.getSessionPersistence() != null) {
- final NeutronLoadBalancerSessionPersistence sessionPersistence =
- new NeutronLoadBalancerSessionPersistence();
+ NeutronLoadBalancerSessionPersistence sessionPersistence = new NeutronLoadBalancerSessionPersistence();
sessionPersistence.setCookieName(pool.getSessionPersistence().getCookieName());
sessionPersistence.setType(pool.getSessionPersistence().getType());
}
@Override
- public boolean neutronLoadBalancerPoolMemberExists(String poolUuid, String uuid) {
+ public boolean neutronLoadBalancerPoolMemberExists(String poolUuid, String uuid) throws ReadFailedException {
final Member member = readMemberMd(createMemberInstanceIdentifier(toMd(poolUuid), toMemberMd(uuid)));
if (member == null) {
return false;
}
@Override
- public NeutronLoadBalancerPoolMember getNeutronLoadBalancerPoolMember(String poolUuid, String uuid) {
+ public NeutronLoadBalancerPoolMember getNeutronLoadBalancerPoolMember(String poolUuid, String uuid)
+ throws ReadFailedException {
final Member member = readMemberMd(createMemberInstanceIdentifier(toMd(poolUuid), toMemberMd(uuid)));
if (member == null) {
return null;
}
@Override
- public List<NeutronLoadBalancerPoolMember> getAllNeutronLoadBalancerPoolMembers(String poolUuid) {
+ public List<NeutronLoadBalancerPoolMember> getAllNeutronLoadBalancerPoolMembers(String poolUuid)
+ throws ReadFailedException {
final Set<NeutronLoadBalancerPoolMember> allLoadBalancerPoolMembers = new HashSet<>();
final Members members = readMd(createMembersInstanceIdentifier(toMd(poolUuid)));
if (members != null) {
}
@Override
- public boolean addNeutronLoadBalancerPoolMember(String poolUuid, NeutronLoadBalancerPoolMember input) {
+ public boolean addNeutronLoadBalancerPoolMember(String poolUuid, NeutronLoadBalancerPoolMember input)
+ throws OperationFailedException {
if (neutronLoadBalancerPoolMemberExists(poolUuid, input.getID())) {
return false;
}
}
@Override
- public boolean removeNeutronLoadBalancerPoolMember(String poolUuid, String uuid) {
+ public boolean removeNeutronLoadBalancerPoolMember(String poolUuid, String uuid) throws OperationFailedException {
if (!neutronLoadBalancerPoolMemberExists(poolUuid, uuid)) {
return false;
}
- return removeMemberMd(toMd(poolUuid), toMemberMd(uuid));
+ removeMemberMd(toMd(poolUuid), toMemberMd(uuid));
+ return true;
}
@Override
public boolean updateNeutronLoadBalancerPoolMember(String poolUuid, String uuid,
- NeutronLoadBalancerPoolMember delta) {
+ NeutronLoadBalancerPoolMember delta) throws OperationFailedException {
if (!neutronLoadBalancerPoolMemberExists(poolUuid, uuid)) {
return false;
}
}
@Override
- public boolean neutronLoadBalancerPoolMemberInUse(String poolUuid, String loadBalancerPoolMemberID) {
+ public boolean neutronLoadBalancerPoolMemberInUse(String poolUuid, String loadBalancerPoolMemberID)
+ throws ReadFailedException {
return !neutronLoadBalancerPoolMemberExists(poolUuid, loadBalancerPoolMemberID);
}
return memberBuilder.build();
}
- protected Member toMemberMd(String uuid) {
+ private Member toMemberMd(String uuid) {
final MemberBuilder memberBuilder = new MemberBuilder();
memberBuilder.setUuid(toUuid(uuid));
return memberBuilder.build();
}
- protected <
- T extends org.opendaylight.yangtools.yang.binding.DataObject> T readMemberMd(InstanceIdentifier<T> path) {
+ private <T extends DataObject> T readMemberMd(InstanceIdentifier<T> path) throws ReadFailedException {
T result = null;
- final ReadOnlyTransaction transaction = getDataBroker().newReadOnlyTransaction();
- final CheckedFuture<Optional<T>,
- ReadFailedException> future = transaction.read(LogicalDatastoreType.CONFIGURATION, path);
- if (future != null) {
- Optional<T> optional;
- try {
+ try (ReadOnlyTransaction transaction = getDataBroker().newReadOnlyTransaction()) {
+ final CheckedFuture<Optional<T>, ReadFailedException> future = transaction
+ .read(LogicalDatastoreType.CONFIGURATION, path);
+ if (future != null) {
+ Optional<T> optional;
optional = future.checkedGet();
if (optional.isPresent()) {
result = optional.get();
}
- } catch (final ReadFailedException e) {
- LOG.warn("Failed to read {}", path, e);
}
}
- transaction.close();
return result;
}
- protected boolean addMemberMd(Pool pool, NeutronLoadBalancerPoolMember neutronObject) {
+ private void addMemberMd(Pool pool, NeutronLoadBalancerPoolMember neutronObject)
+ throws TransactionCommitFailedException {
// TODO think about adding existence logic
- return updateMemberMd(pool, neutronObject);
+ updateMemberMd(pool, neutronObject);
}
- protected boolean updateMemberMd(Pool pool, NeutronLoadBalancerPoolMember neutronObject) {
+ private void updateMemberMd(Pool pool, NeutronLoadBalancerPoolMember neutronObject)
+ throws TransactionCommitFailedException {
final WriteTransaction transaction = getDataBroker().newWriteOnlyTransaction();
final Member item = toMemberMd(neutronObject);
final InstanceIdentifier<Member> iid = createMemberInstanceIdentifier(pool, item);
transaction.put(LogicalDatastoreType.CONFIGURATION, iid, item, true);
- final CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
- try {
- future.get();
- } catch (InterruptedException | ExecutionException e) {
- LOG.warn("Transation failed ", e);
- return false;
- }
- return true;
+ transaction.submit().checkedGet();
}
- protected boolean removeMemberMd(Pool pool, Member item) {
+ private void removeMemberMd(Pool pool, Member item) throws TransactionCommitFailedException {
final WriteTransaction transaction = getDataBroker().newWriteOnlyTransaction();
final InstanceIdentifier<Member> iid = createMemberInstanceIdentifier(pool, item);
transaction.delete(LogicalDatastoreType.CONFIGURATION, iid);
- final CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
- try {
- future.get();
- } catch (InterruptedException | ExecutionException e) {
- LOG.warn("Transation failed ", e);
- return false;
- }
- return true;
+ transaction.submit().checkedGet();
}
}
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.neutron.northbound.api.BadRequestException;
import org.opendaylight.neutron.spi.INeutronSecurityRuleCRUD;
import org.opendaylight.neutron.spi.NeutronSecurityRule;
}
@Override
- protected boolean areAllDependenciesAvailable(ReadTransaction tx, NeutronSecurityRule securityRule) {
+ protected boolean areAllDependenciesAvailable(ReadTransaction tx, NeutronSecurityRule securityRule)
+ throws ReadFailedException {
return ifNonNull(securityRule.getSecurityRuleGroupID(),
groupID -> securityGroupInterface.exists(groupID, tx))
&& ifNonNull(securityRule.getSecurityRemoteGroupID(),
package org.opendaylight.neutron.transcriber;
import com.google.common.collect.ImmutableBiMap;
-import com.google.common.util.concurrent.CheckedFuture;
import java.util.List;
-import java.util.concurrent.ExecutionException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.neutron.spi.INeutronTapFlowCRUD;
import org.opendaylight.neutron.spi.NeutronTapFlow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.tapaas.rev171024.tap.services.attributes.tap.services.TapService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.tapaas.rev171024.tap.services.attributes.tap.services.TapServiceKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
import org.ops4j.pax.cdi.api.OsgiServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@Override
- public boolean tapFlowExists(String tapServiceUUID, String tapFlowUUID) {
+ public boolean tapFlowExists(String tapServiceUUID, String tapFlowUUID) throws ReadFailedException {
final TapFlow dataObject = readMd(createTapFlowInstanceIdentifier(tapServiceUUID, toMd(tapFlowUUID)));
return dataObject != null;
}
- private boolean tapServiceExists(String tapServiceUUID) {
+ private boolean tapServiceExists(String tapServiceUUID) throws ReadFailedException {
final TapService tapService = readMd(InstanceIdentifier.create(Neutron.class).child(TapServices.class)
.child(TapService.class, new TapServiceKey(toUuid(tapServiceUUID))));
return tapService != null;
}
- private boolean updateTapFlowMd(NeutronTapFlow tapFlow) {
+ private void updateTapFlowMd(NeutronTapFlow tapFlow) throws TransactionCommitFailedException {
final WriteTransaction transaction = getDataBroker().newWriteOnlyTransaction();
final TapFlow item = toMd(tapFlow);
final InstanceIdentifier<TapFlow> iid = createTapFlowInstanceIdentifier(tapFlow.getTapFlowServiceID(), item);
transaction.put(LogicalDatastoreType.CONFIGURATION, iid, item, true);
- final CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
- try {
- future.get();
- } catch (InterruptedException | ExecutionException e) {
- LOG.warn("Transaction Failed ", e);
- return false;
- }
- return true;
+ transaction.submit().checkedGet();
}
- private boolean removeTapFlowMd(String tapServiceUUID, String tapFlowUUID) {
+ private void removeTapFlowMd(String tapServiceUUID, String tapFlowUUID) throws TransactionCommitFailedException {
final WriteTransaction transaction = getDataBroker().newWriteOnlyTransaction();
final InstanceIdentifier<TapFlow> iid = createTapFlowInstanceIdentifier(tapServiceUUID, toMd(tapFlowUUID));
transaction.delete(LogicalDatastoreType.CONFIGURATION, iid);
- final CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
- try {
- future.get();
- } catch (InterruptedException | ExecutionException e) {
- LOG.warn("Transation failed ", e);
- return false;
- }
- return true;
+ transaction.submit().checkedGet();
}
- private boolean addTapFlowMd(NeutronTapFlow tapFlow) {
- return updateTapFlowMd(tapFlow);
+ private void addTapFlowMd(NeutronTapFlow tapFlow) throws TransactionCommitFailedException {
+ updateTapFlowMd(tapFlow);
}
@Override
- public boolean updateTapFlow(NeutronTapFlow tapFlow) {
- return updateTapFlowMd(tapFlow);
+ public void updateTapFlow(NeutronTapFlow tapFlow) throws TransactionCommitFailedException {
+ updateTapFlowMd(tapFlow);
}
@Override
- public boolean addTapFlow(NeutronTapFlow tapFlow) {
+ public boolean addTapFlow(NeutronTapFlow tapFlow) throws OperationFailedException {
if (!tapServiceExists(tapFlow.getTapFlowServiceID())) {
return false;
}
}
@Override
- public NeutronTapFlow getTapFlow(String tapServiceUUID, String tapFlowUUID) {
+ public NeutronTapFlow getTapFlow(String tapServiceUUID, String tapFlowUUID) throws ReadFailedException {
final TapFlow tapFlow = readMd(createTapFlowInstanceIdentifier(tapServiceUUID, toMd(tapFlowUUID)));
if (tapFlow == null) {
return null;
}
@Override
- public boolean deleteTapFlow(String tapServiceUUID, String tapFlowUUID) {
- return removeTapFlowMd(tapServiceUUID, tapFlowUUID);
+ public void deleteTapFlow(String tapServiceUUID, String tapFlowUUID) throws TransactionCommitFailedException {
+ removeTapFlowMd(tapServiceUUID, tapFlowUUID);
}
}