From: Robert Varga Date: Mon, 14 Apr 2014 13:12:45 +0000 (+0200) Subject: BUG-509: Fail forwarning write if read fails. X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~238 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=7d88a2f500e76ee1e59628eff09d69494be74cfa BUG-509: Fail forwarning write if read fails. This primarily gets rid of e.printStackTrace(), but as part of that it defines an important thing: if a read fails while we're building up the path, we should not try to continue with the operation. Change-Id: I48cb6cd304a98684a6984d26b6fc8dd5d14963c5 Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java index 4f9c429e50..e39ebfbc71 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java @@ -108,27 +108,30 @@ public class AbstractForwardedTransaction currentArguments = new ArrayList<>(); - DataNormalizationOperation currentOp = codec.getDataNormalizer().getRootOperation(); - Iterator iterator = normalizedPath.getPath().iterator(); - while (iterator.hasNext()) { - PathArgument currentArg = iterator.next(); - currentOp = currentOp.getChild(currentArg); - currentArguments.add(currentArg); - org.opendaylight.yangtools.yang.data.api.InstanceIdentifier currentPath = new org.opendaylight.yangtools.yang.data.api.InstanceIdentifier( - currentArguments); - boolean isPresent = writeTransaction.read(store, currentPath).get().isPresent(); - if (isPresent == false && iterator.hasNext()) { - writeTransaction.put(store, currentPath, currentOp.createDefault(currentArg)); - } + List currentArguments = new ArrayList<>(); + DataNormalizationOperation currentOp = codec.getDataNormalizer().getRootOperation(); + Iterator iterator = normalizedPath.getPath().iterator(); + while (iterator.hasNext()) { + PathArgument currentArg = iterator.next(); + currentOp = currentOp.getChild(currentArg); + currentArguments.add(currentArg); + org.opendaylight.yangtools.yang.data.api.InstanceIdentifier currentPath = new org.opendaylight.yangtools.yang.data.api.InstanceIdentifier( + currentArguments); + + final Optional> d; + try { + d = writeTransaction.read(store, currentPath).get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Failed to read pre-existing data from store {} path {}", store, currentPath, e); + throw new IllegalStateException("Failed to read pre-existing data", e); + } + + if (!d.isPresent() && iterator.hasNext()) { + writeTransaction.put(store, currentPath, currentOp.createDefault(currentArg)); } - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); } //LOG .info("Tx: {} : Putting data {}",getDelegate().getIdentifier(),normalized.getKey()); writeTransaction.put(store, normalized.getKey(), normalized.getValue()); - } protected void doMerge(final DOMDataWriteTransaction writeTransaction, final LogicalDatastoreType store,