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