2 * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
21 import org.opendaylight.yangtools.yang.binding.Identifier;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 public class SwitchesCmd extends MergeCommand<Switches, HwvtepGlobalAugmentationBuilder, HwvtepGlobalAugmentation> {
25 public SwitchesCmd() {
30 public List<Switches> getData(HwvtepGlobalAugmentation node) {
31 if (node != null && node.nonnullSwitches() != null) {
32 return new ArrayList<Switches>(node.nonnullSwitches().values());
38 public void setData(HwvtepGlobalAugmentationBuilder builder, List<Switches> data) {
39 builder.setSwitches(data);
43 public InstanceIdentifier<Switches> generateId(InstanceIdentifier<Node> id, Switches node) {
44 SwitchesKey switchesKey = transform(id, node).key();
45 return id.augmentation(HwvtepGlobalAugmentation.class).child(Switches.class, switchesKey);
49 public Switches transform(InstanceIdentifier<Node> nodePath, Switches src) {
50 SwitchesBuilder builder = new SwitchesBuilder(src);
51 InstanceIdentifier<Node> psNodeIid = (InstanceIdentifier<Node>) src.getSwitchRef().getValue();
52 String psNodeId = psNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
53 String nodeId = nodePath.firstKeyOf(Node.class).getNodeId().getValue();
54 int idx = nodeId.indexOf("/physicalswitch/");
56 nodeId = nodeId.substring(0, idx);
58 idx = psNodeId.indexOf("/physicalswitch/") + "/physicalswitch/".length();
59 String switchName = psNodeId.substring(idx);
60 String dstNodeId = nodeId + "/physicalswitch/" + switchName;
62 InstanceIdentifier<Node> id2 = HwvtepHAUtil.convertToInstanceIdentifier(dstNodeId);
64 builder.setSwitchRef(new HwvtepPhysicalSwitchRef(id2));
65 builder.withKey(new SwitchesKey(new HwvtepPhysicalSwitchRef(id2)));
66 return builder.build();
70 public Identifier getKey(Switches data) {
71 InstanceIdentifier<?> id = data.getSwitchRef().getValue();
72 return id.firstKeyOf(Node.class);
76 public String getDescription() {
81 public boolean areEqual(Switches switchA, Switches switchB) {
86 public Switches withoutUuid(Switches data) {