BUG-2600 Dynamic schemas in netconf server
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / Commit.java
index 592d8e4f3b657933b99144f5c769adf4895a5baf..8a0830e48ad18c222b80db0d116b248af28a29ca 100644 (file)
@@ -8,18 +8,16 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.operations;
 
-import java.util.HashMap;
-import java.util.Map;
-
+import com.google.common.base.Optional;
+import org.opendaylight.controller.config.api.ConflictingVersionException;
+import org.opendaylight.controller.config.api.ValidationException;
 import org.opendaylight.controller.config.api.jmx.CommitStatus;
 import org.opendaylight.controller.config.util.ConfigRegistryClient;
 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.confignetconfconnector.transactions.TransactionProvider;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
-import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -27,7 +25,7 @@ import org.w3c.dom.Element;
 
 public class Commit extends AbstractConfigNetconfOperation {
 
-    private static final Logger logger = LoggerFactory.getLogger(Commit.class);
+    private static final Logger LOG = LoggerFactory.getLogger(Commit.class);
 
     private final TransactionProvider transactionProvider;
 
@@ -37,7 +35,7 @@ public class Commit extends AbstractConfigNetconfOperation {
         this.transactionProvider = transactionProvider;
     }
 
-    private static void checkXml(XmlElement xml) {
+    private static void checkXml(XmlElement xml) throws NetconfDocumentedException {
         xml.checkName(XmlNetconfConstants.COMMIT);
         xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
     }
@@ -48,27 +46,19 @@ public class Commit extends AbstractConfigNetconfOperation {
     }
 
     @Override
-    protected Element handle(Document document, XmlElement xml) throws NetconfDocumentedException {
-        checkXml(xml);
+    protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
 
+        checkXml(xml);
         CommitStatus status;
         try {
             status = this.transactionProvider.commitTransaction();
-        } catch (final IllegalStateException e) {
-            logger.warn("Commit failed: ", e);
-            final Map<String, String> errorInfo = new HashMap<>();
-            errorInfo.put(ErrorTag.operation_failed.name(),
-                    "Operation failed. Use 'get-config' or 'edit-config' before triggering 'commit' operation");
-            throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
-                    ErrorSeverity.error, errorInfo);
-        } catch (final NetconfDocumentedException e) {
-            throw new NetconfDocumentedException(
-                    "Unable to retrieve config snapshot after commit for persister, details: " + e.getMessage(),
-                    ErrorType.application, ErrorTag.operation_failed, ErrorSeverity.error, e.getErrorInfo());
+            LOG.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
+        } catch (ConflictingVersionException | ValidationException e) {
+            throw NetconfDocumentedException.wrap(e);
         }
-        logger.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
+        LOG.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
 
-        return document.createElement(XmlNetconfConstants.OK);
+        return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
     }
 
 }