X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fmdsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fmdsal%2Fconnector%2Fops%2Fget%2FGetConfig.java;h=5f36ca5a3086f586aa3888daa97962d469fe577b;hb=23fe9ca678ada6263fec5dd996f4025e4a32fcf5;hp=f2d8abbb6180f10785f7cb00c59dcb6d6fd7d5ee;hpb=32b25203819eb02df22abfecdcc86896c068f778;p=controller.git diff --git a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/GetConfig.java b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/GetConfig.java index f2d8abbb61..5f36ca5a30 100644 --- a/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/GetConfig.java +++ b/opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/controller/netconf/mdsal/connector/ops/get/GetConfig.java @@ -10,17 +10,19 @@ package org.opendaylight.controller.netconf.mdsal.connector.ops.get; import com.google.common.base.Optional; import com.google.common.base.Preconditions; +import org.opendaylight.controller.config.util.xml.DocumentedException; +import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorSeverity; +import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorTag; +import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorType; +import org.opendaylight.controller.config.util.xml.XmlElement; +import org.opendaylight.controller.config.util.xml.XmlUtil; 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.dom.api.DOMDataReadWriteTransaction; -import org.opendaylight.controller.netconf.api.NetconfDocumentedException; -import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity; -import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag; -import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.mdsal.connector.CurrentSchemaContext; import org.opendaylight.controller.netconf.mdsal.connector.TransactionProvider; import org.opendaylight.controller.netconf.mdsal.connector.ops.Datastore; -import org.opendaylight.controller.netconf.util.xml.XmlElement; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.slf4j.Logger; @@ -33,7 +35,6 @@ public class GetConfig extends AbstractGet { private static final Logger LOG = LoggerFactory.getLogger(GetConfig.class); private static final String OPERATION_NAME = "get-config"; - private final TransactionProvider transactionProvider; public GetConfig(final String netconfSessionIdForReporting, final CurrentSchemaContext schemaContext, final TransactionProvider transactionProvider) { @@ -42,17 +43,23 @@ public class GetConfig extends AbstractGet { } @Override - protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws NetconfDocumentedException { + protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws DocumentedException { GetConfigExecution getConfigExecution = null; try { getConfigExecution = GetConfigExecution.fromXml(operationElement, OPERATION_NAME); - } catch (final NetconfDocumentedException e) { + } catch (final DocumentedException e) { LOG.warn("Get request processing failed on session: {}", getNetconfSessionIdForReporting(), e); throw e; } - final YangInstanceIdentifier dataRoot = ROOT; + final Optional dataRootOptional = getDataRootFromFilter(operationElement); + if (!dataRootOptional.isPresent()) { + return XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.absent()); + } + + final YangInstanceIdentifier dataRoot = dataRootOptional.get(); + // Proper exception should be thrown Preconditions.checkState(getConfigExecution.getDatastore().isPresent(), "Source element missing from request"); @@ -61,22 +68,26 @@ public class GetConfig extends AbstractGet { final Optional> normalizedNodeOptional = rwTx.read(LogicalDatastoreType.CONFIGURATION, dataRoot).checkedGet(); if (getConfigExecution.getDatastore().get() == Datastore.running) { transactionProvider.abortRunningTransaction(rwTx); - rwTx = null; } - return (Element) transformNormalizedNode(document, normalizedNodeOptional.get(), dataRoot); + + if (!normalizedNodeOptional.isPresent()) { + return XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.absent()); + } + + return serializeNodeWithParentStructure(document, dataRoot, normalizedNodeOptional.get()); } catch (ReadFailedException e) { LOG.warn("Unable to read data: {}", dataRoot, e); throw new IllegalStateException("Unable to read data " + dataRoot, e); } } - private DOMDataReadWriteTransaction getTransaction(Datastore datastore) throws NetconfDocumentedException{ + private DOMDataReadWriteTransaction getTransaction(Datastore datastore) throws DocumentedException{ if (datastore == Datastore.candidate) { return transactionProvider.getOrCreateTransaction(); } else if (datastore == Datastore.running) { return transactionProvider.createRunningTransaction(); } - throw new NetconfDocumentedException("Incorrect Datastore: ", ErrorType.protocol, ErrorTag.bad_element, ErrorSeverity.error); + throw new DocumentedException("Incorrect Datastore: ", ErrorType.protocol, ErrorTag.bad_element, ErrorSeverity.error); } @Override