X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2FNetconfDeviceTwoPhaseCommitTransaction.java;h=83700c892bafa70588d1ea8e8f0d617f8f03fe1c;hp=216a27aaaa0afb39409d196b6ae5067a86ff23d8;hb=1862f90478212a06a9534ed0674f27212972177f;hpb=1dd1433d1e2f30855b098cca7cc48039a9747df8 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 216a27aaaa..83700c892b 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 @@ -1,12 +1,27 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.connect.netconf; +import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_OPERATION_QNAME; +import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_CANDIDATE_QNAME; +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_RUNNING_QNAME; +import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_TARGET_QNAME; + +import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Map.Entry; -import java.util.Set; -import org.eclipse.xtext.xbase.lib.IterableExtensions; -import org.opendaylight.controller.md.sal.common.api.data.DataModification; import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction; +import org.opendaylight.controller.md.sal.common.api.data.DataModification; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.data.api.CompositeNode; @@ -19,18 +34,14 @@ import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder; import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.*; - public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransaction { - private NetconfDevice device; + private final NetconfDevice device; private final DataModification modification; - private boolean candidateSupported = true; + private final boolean candidateSupported = true; public NetconfDeviceTwoPhaseCommitTransaction(NetconfDevice device, DataModification modification) { @@ -41,7 +52,7 @@ public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransac public void prepare() { for (InstanceIdentifier toRemove : modification.getRemovedConfigurationData()) { - sendRemove(toRemove); + sendDelete(toRemove); } for(Entry toUpdate : modification.getUpdatedConfigurationData().entrySet()) { sendMerge(toUpdate.getKey(),toUpdate.getValue()); @@ -53,23 +64,23 @@ public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransac sendEditRpc(createEditStructure(key, Optional.absent(), Optional.of(value))); } - private void sendRemove(InstanceIdentifier toRemove) { - sendEditRpc(createEditStructure(toRemove, Optional.of("remove"), Optional. absent())); + private void sendDelete(InstanceIdentifier toDelete) { + sendEditRpc(createEditStructure(toDelete, Optional.of("delete"), Optional. absent())); } private void sendEditRpc(CompositeNode editStructure) { CompositeNodeBuilder builder = configurationRpcBuilder(); builder.setQName(NETCONF_EDIT_CONFIG_QNAME); builder.add(editStructure); - + RpcResult rpcResult = device.invokeRpc(NETCONF_EDIT_CONFIG_QNAME, builder.toInstance()); Preconditions.checkState(rpcResult.isSuccessful(),"Rpc Result was unsuccessful"); - + } private CompositeNodeBuilder configurationRpcBuilder() { CompositeNodeBuilder ret = ImmutableCompositeNode.builder(); - + Node targetNode; if(candidateSupported) { targetNode = ImmutableCompositeNode.create(NETCONF_CANDIDATE_QNAME, ImmutableList.>of()); @@ -81,7 +92,7 @@ public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransac return ret; } - private CompositeNode createEditStructure(InstanceIdentifier dataPath, Optional action, + private CompositeNode createEditStructure(InstanceIdentifier dataPath, Optional operation, Optional lastChildOverride) { List path = dataPath.getPath(); List reversed = Lists.reverse(path); @@ -90,19 +101,26 @@ public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransac for (PathArgument arg : reversed) { CompositeNodeBuilder builder = ImmutableCompositeNode.builder(); builder.setQName(arg.getNodeType()); - + Map predicates = Collections.emptyMap(); if (arg instanceof NodeIdentifierWithPredicates) { - for (Entry entry : ((NodeIdentifierWithPredicates) arg).getKeyValues().entrySet()) { - builder.addLeaf(entry.getKey(), entry.getValue()); - } + predicates = ((NodeIdentifierWithPredicates) arg).getKeyValues(); } + for (Entry entry : predicates.entrySet()) { + builder.addLeaf(entry.getKey(), entry.getValue()); + } + if (isLast) { - if (action.isPresent()) { - builder.setAttribute(NETCONF_ACTION_QNAME, action.get()); + if (operation.isPresent()) { + builder.setAttribute(NETCONF_OPERATION_QNAME, operation.get()); } if (lastChildOverride.isPresent()) { List> children = lastChildOverride.get().getChildren(); - builder.addAll(children); + for(Node child : children) { + if(!predicates.containsKey(child.getKey())) { + builder.add(child); + } + } + } } else { builder.add(previous);