X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FBrokerFacade.java;h=8dbc5b50ee5dbd8ac374ef7d1452384442923085;hb=c33b2b55b2eae406df001619885a0610800cb951;hp=f11e25c046feab69fe3c41f229dfdbadd496e18d;hpb=d206d27042eef2185c875f85cf6eac61a1bd77c4;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.java index f11e25c046..8dbc5b50ee 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.sal.restconf.impl; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.ListenableFuture; 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; @@ -40,6 +41,7 @@ import javax.ws.rs.core.Response.Status; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; @@ -176,31 +178,39 @@ public class BrokerFacade { private NormalizedNode readDataViaTransaction(final DOMDataReadTransaction transaction, LogicalDatastoreType datastore, YangInstanceIdentifier path) { LOG.trace("Read " + datastore.name() + " via Restconf: {}", path); - final CheckedFuture>, ReadFailedException> listenableFuture = - transaction.read(datastore, path); + final ListenableFuture>> listenableFuture = transaction.read(datastore, path); + if (listenableFuture != null) { + Optional> optional; + try { + LOG.debug("Reading result data from transaction."); + optional = listenableFuture.get(); + } catch (InterruptedException | ExecutionException e) { + throw new RestconfDocumentedException("Problem to get data from transaction.", e.getCause()); - try { - Optional> optional = listenableFuture.checkedGet(); - return optional.isPresent() ? optional.get() : null; - } catch(ReadFailedException e) { - throw new RestconfDocumentedException(e.getMessage(), e, e.getErrorList()); + } + if (optional != null) { + if (optional.isPresent()) { + return optional.get(); + } + } } + return null; } private CheckedFuture postDataViaTransaction( final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode payload, DataNormalizationOperation root) { - CheckedFuture>, ReadFailedException> futureDatastoreData = - rWTransaction.read(datastore, path); + ListenableFuture>> futureDatastoreData = rWTransaction.read(datastore, path); try { - final Optional> optionalDatastoreData = futureDatastoreData.checkedGet(); + final Optional> optionalDatastoreData = futureDatastoreData.get(); if (optionalDatastoreData.isPresent() && payload.equals(optionalDatastoreData.get())) { - LOG.trace("Post Configuration via Restconf was not executed because data already exists :{}", path); + String errMsg = "Post Configuration via Restconf was not executed because data already exists"; + LOG.trace(errMsg + ":{}", path); throw new RestconfDocumentedException("Data already exists for path: " + path, ErrorType.PROTOCOL, ErrorTag.DATA_EXISTS); } - } catch(ReadFailedException e) { - LOG.warn("Error reading from datastore with path: " + path, e); + } catch (InterruptedException | ExecutionException e) { + LOG.trace("It wasn't possible to get data loaded from datastore at path " + path); } ensureParentsByMerge(datastore, path, rWTransaction, root); @@ -241,21 +251,27 @@ public class BrokerFacade { try { currentOp = currentOp.getChild(currentArg); } catch (DataNormalizationException e) { - throw new RestconfDocumentedException( - String.format("Error normalizing data for path %s", normalizedPath), e); + throw new IllegalArgumentException( + String.format("Invalid child encountered in path %s", normalizedPath), e); } currentArguments.add(currentArg); YangInstanceIdentifier currentPath = YangInstanceIdentifier.create(currentArguments); + final Boolean exists; + try { - boolean exists = rwTx.exists(store, currentPath).checkedGet(); - if (!exists && iterator.hasNext()) { - rwTx.merge(store, currentPath, currentOp.createDefault(currentArg)); - } + CheckedFuture 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); - throw new RestconfDocumentedException("Failed to read pre-existing data", e); + throw new IllegalStateException("Failed to read pre-existing data", e); + } + + + if (!exists && iterator.hasNext()) { + rwTx.merge(store, currentPath, currentOp.createDefault(currentArg)); } } }