X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2Fmapping%2Foperations%2FDefaultCommit.java;h=1a9f5d7393ad469f5e1c8d1cc0862589e65fe185;hp=8637c0dd7444ca816360bac9beb322bc57108293;hb=408eeef51f435abd2027f9d25ac5592066b202dd;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9 diff --git a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommit.java b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommit.java index 8637c0dd74..1a9f5d7393 100644 --- a/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommit.java +++ b/opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCommit.java @@ -8,14 +8,16 @@ package org.opendaylight.controller.netconf.impl.mapping.operations; -import com.google.common.collect.Maps; +import java.io.InputStream; +import java.util.Map; + import org.opendaylight.controller.netconf.api.NetconfDocumentedException; -import org.opendaylight.controller.netconf.api.NetconfOperationRouter; +import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouter; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationFilter; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationFilterChain; -import org.opendaylight.controller.netconf.util.mapping.AbstractNetconfOperation.OperationNameAndNamespace; +import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; +import org.opendaylight.controller.netconf.util.mapping.AbstractNetconfOperation; import org.opendaylight.controller.netconf.util.xml.XmlElement; import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.util.xml.XmlUtil; @@ -24,10 +26,10 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; -import java.io.InputStream; -import java.util.Map; +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; -public class DefaultCommit implements NetconfOperationFilter { +public class DefaultCommit extends AbstractNetconfOperation { private static final Logger logger = LoggerFactory.getLogger(DefaultCommit.class); @@ -35,13 +37,14 @@ public class DefaultCommit implements NetconfOperationFilter { private final DefaultCommitNotificationProducer notificationProducer; private final CapabilityProvider cap; - private final String netconfSessionIdForReporting; + private final NetconfOperationRouter operationRouter; public DefaultCommit(DefaultCommitNotificationProducer notifier, CapabilityProvider cap, - String netconfSessionIdForReporting) { + String netconfSessionIdForReporting, NetconfOperationRouter netconfOperationRouter) { + super(netconfSessionIdForReporting); this.notificationProducer = notifier; this.cap = cap; - this.netconfSessionIdForReporting = netconfSessionIdForReporting; + this.operationRouter = netconfOperationRouter; this.getConfigMessage = loadGetConfigMessage(); } @@ -58,40 +61,36 @@ public class DefaultCommit implements NetconfOperationFilter { } @Override - public Document doFilter(Document message, NetconfOperationRouter operationRouter, - NetconfOperationFilterChain filterChain) throws NetconfDocumentedException { - OperationNameAndNamespace operationNameAndNamespace = new OperationNameAndNamespace(message); - if (canHandle(operationNameAndNamespace)) { - if (isCommitWithoutNotification(message)) { - message = removePersisterAttributes(message); - logger.debug("Skipping commit notification"); - // fall back to filter chain - } else { - Document innerResult = filterChain.execute(message, operationRouter); - Element cfgSnapshot = getConfigSnapshot(operationRouter); - logger.debug("Config snapshot retrieved successfully {}", cfgSnapshot); - notificationProducer.sendCommitNotification("ok", cfgSnapshot, cap.getCapabilities()); - return innerResult; - } - } - return filterChain.execute(message, operationRouter); + protected String getOperationName() { + return XmlNetconfConstants.COMMIT; } @Override - public int getSoringOrder() { - return 0; + public Document handle(Document requestMessage, NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException { + Preconditions.checkArgument(subsequentOperation.isExecutionTermination() == false, + "Subsequent netconf operation expected by %s", this); + + if (isCommitWithoutNotification(requestMessage)) { + logger.debug("Skipping commit notification"); + } else { + // Send commit notification if commit was not issued by persister + requestMessage = removePersisterAttributes(requestMessage); + Element cfgSnapshot = getConfigSnapshot(operationRouter); + logger.debug("Config snapshot retrieved successfully {}", cfgSnapshot); + notificationProducer.sendCommitNotification("ok", cfgSnapshot, cap.getCapabilities()); + } + + return subsequentOperation.execute(requestMessage); } @Override - public int compareTo(NetconfOperationFilter o) { - return Integer.compare(getSoringOrder(), o.getSoringOrder()); + protected Element handle(Document document, XmlElement message, NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException { + throw new UnsupportedOperationException("Never gets called"); } - private boolean canHandle(OperationNameAndNamespace operationNameAndNamespace) { - if (operationNameAndNamespace.getOperationName().equals("commit") == false) - return false; - return operationNameAndNamespace.getNamespace().equals( - XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); + @Override + protected HandlingPriority getHandlingPriority() { + return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1); } private Document removePersisterAttributes(Document message) { @@ -117,7 +116,8 @@ public class DefaultCommit implements NetconfOperationFilter { } private Element getConfigSnapshot(NetconfOperationRouter opRouter) throws NetconfDocumentedException { - final Document responseDocument = opRouter.onNetconfMessage(getConfigMessage); + final Document responseDocument = opRouter.onNetconfMessage( + getConfigMessage, null); XmlElement dataElement; try { @@ -137,8 +137,4 @@ public class DefaultCommit implements NetconfOperationFilter { return dataElement.getDomElement(); } - @Override - public String toString() { - return "DefaultCommit{" + netconfSessionIdForReporting + '}'; - } }