X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2FNetconfDeviceTwoPhaseCommitTransaction.java;h=34cd9aa47b7f82702a797ddc4bea96ed34f28b7d;hb=761a2b50e10129c5f6ccb59df940b5dd39d6e424;hp=9ec3aa3bb00bff78762770203ae79f7b80a94f3f;hpb=bcdc6138d215d097b13510e08735808ed931aeda;p=controller.git diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceTwoPhaseCommitTransaction.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceTwoPhaseCommitTransaction.java index 9ec3aa3bb0..34cd9aa47b 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceTwoPhaseCommitTransaction.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceTwoPhaseCommitTransaction.java @@ -11,9 +11,11 @@ import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NET import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_COMMIT_QNAME; import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_CONFIG_QNAME; import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_EDIT_CONFIG_QNAME; +import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_ERROR_OPTION_QNAME; import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_OPERATION_QNAME; import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_RUNNING_QNAME; import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_TARGET_QNAME; +import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.ROLLBACK_ON_ERROR_OPTION; import java.util.Collection; import java.util.Collections; @@ -42,17 +44,20 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransaction { +class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransaction { private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceTwoPhaseCommitTransaction.class); - private final NetconfDevice device; private final DataModification modification; - private final boolean candidateSupported = true; - - public NetconfDeviceTwoPhaseCommitTransaction(NetconfDevice device, - DataModification modification) { - super(); - this.device = device; - this.modification = modification; + private final NetconfDevice device; + private final boolean candidateSupported; + private final boolean rollbackSupported; + + public NetconfDeviceTwoPhaseCommitTransaction(final NetconfDevice device, + final DataModification modification, + final boolean candidateSupported, final boolean rollbackOnErrorSupported) { + this.device = Preconditions.checkNotNull(device); + this.modification = Preconditions.checkNotNull(modification); + this.candidateSupported = candidateSupported; + this.rollbackSupported = rollbackOnErrorSupported; } void prepare() throws InterruptedException, ExecutionException { @@ -62,25 +67,23 @@ public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransac for(Entry toUpdate : modification.getUpdatedConfigurationData().entrySet()) { sendMerge(toUpdate.getKey(),toUpdate.getValue()); } - } - private void sendMerge(InstanceIdentifier key, CompositeNode value) throws InterruptedException, ExecutionException { + private void sendMerge(final InstanceIdentifier key, final CompositeNode value) throws InterruptedException, ExecutionException { sendEditRpc(createEditStructure(key, Optional.absent(), Optional.of(value))); } - private void sendDelete(InstanceIdentifier toDelete) throws InterruptedException, ExecutionException { + private void sendDelete(final InstanceIdentifier toDelete) throws InterruptedException, ExecutionException { sendEditRpc(createEditStructure(toDelete, Optional.of("delete"), Optional. absent())); } - private void sendEditRpc(CompositeNode editStructure) throws InterruptedException, ExecutionException { + private void sendEditRpc(final CompositeNode editStructure) throws InterruptedException, ExecutionException { CompositeNodeBuilder builder = configurationRpcBuilder(); builder.setQName(NETCONF_EDIT_CONFIG_QNAME); builder.add(editStructure); RpcResult rpcResult = device.invokeRpc(NETCONF_EDIT_CONFIG_QNAME, builder.toInstance()).get(); Preconditions.checkState(rpcResult.isSuccessful(),"Rpc Result was unsuccessful"); - } private CompositeNodeBuilder configurationRpcBuilder() { @@ -92,13 +95,20 @@ public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransac } else { targetNode = ImmutableCompositeNode.create(NETCONF_RUNNING_QNAME, ImmutableList.>of()); } + Node targetWrapperNode = ImmutableCompositeNode.create(NETCONF_TARGET_QNAME, ImmutableList.>of(targetNode)); + + if(rollbackSupported) { + LOG.debug("Rollback-on-error supported, setting {} to {}", NETCONF_ERROR_OPTION_QNAME, ROLLBACK_ON_ERROR_OPTION); + ret.addLeaf(NETCONF_ERROR_OPTION_QNAME, ROLLBACK_ON_ERROR_OPTION); + } + ret.add(targetWrapperNode); return ret; } - private CompositeNode createEditStructure(InstanceIdentifier dataPath, Optional operation, - Optional lastChildOverride) { + private CompositeNode createEditStructure(final InstanceIdentifier dataPath, final Optional operation, + final Optional lastChildOverride) { List path = dataPath.getPath(); List reversed = Lists.reverse(path); CompositeNode previous = null; @@ -119,7 +129,7 @@ public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransac builder.setAttribute(NETCONF_OPERATION_QNAME, operation.get()); } if (lastChildOverride.isPresent()) { - List> children = lastChildOverride.get().getChildren(); + List> children = lastChildOverride.get().getValue(); for(Node child : children) { if(!predicates.containsKey(child.getKey())) { builder.add(child);