import javax.ws.rs.core.Response.Status;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
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.controller.md.sal.common.impl.util.compat.DataNormalizationException;
import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
if (optionalDatastoreData.isPresent() && payload.equals(optionalDatastoreData.get())) {
String errMsg = "Post Configuration via Restconf was not executed because data already exists";
LOG.trace(errMsg + ":{}", path);
+ rWTransaction.cancel();
throw new RestconfDocumentedException("Data already exists for path: " + path, ErrorType.PROTOCOL,
ErrorTag.DATA_EXISTS);
}
private CheckedFuture<Void, TransactionCommitFailedException> deleteDataViaTransaction(
final DOMDataWriteTransaction writeTransaction, final LogicalDatastoreType datastore,
YangInstanceIdentifier path) {
- LOG.info("Delete " + datastore.name() + " via Restconf: {}", path);
+ LOG.trace("Delete " + datastore.name() + " via Restconf: {}", path);
writeTransaction.delete(datastore, path);
return writeTransaction.submit();
}
try {
currentOp = currentOp.getChild(currentArg);
} catch (DataNormalizationException e) {
+ rwTx.cancel();
throw new IllegalArgumentException(
String.format("Invalid child encountered in path %s", normalizedPath), e);
}
currentArguments.add(currentArg);
YangInstanceIdentifier currentPath = YangInstanceIdentifier.create(currentArguments);
- final Optional<NormalizedNode<?, ?>> datastoreData;
+ final Boolean exists;
+
try {
- datastoreData = rwTx.read(store, currentPath).get();
- } catch (InterruptedException | ExecutionException e) {
+
+ CheckedFuture<Boolean, ReadFailedException> future = rwTx.exists(store, currentPath);
+ exists = future.checkedGet();
+ } catch (ReadFailedException e) {
LOG.error("Failed to read pre-existing data from store {} path {}", store, currentPath, e);
+ rwTx.cancel();
throw new IllegalStateException("Failed to read pre-existing data", e);
}
- if (!datastoreData.isPresent() && iterator.hasNext()) {
+ if (!exists && iterator.hasNext()) {
rwTx.merge(store, currentPath, currentOp.createDefault(currentArg));
}
}