Fixup Augmentable and Identifiable methods changing
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / ha / commands / SwitchesCmd.java
1 /*
2  * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
9
10 import java.util.List;
11 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
19 import org.opendaylight.yangtools.yang.binding.Identifier;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21
22 public class SwitchesCmd extends MergeCommand<Switches, HwvtepGlobalAugmentationBuilder, HwvtepGlobalAugmentation> {
23     public SwitchesCmd() {
24     }
25
26     @Override
27     public List<Switches> getData(HwvtepGlobalAugmentation node) {
28         if (node != null) {
29             return node.getSwitches();
30         }
31         return null;
32     }
33
34     @Override
35     public void setData(HwvtepGlobalAugmentationBuilder builder, List<Switches> data) {
36         builder.setSwitches(data);
37     }
38
39     @Override
40     public InstanceIdentifier<Switches> generateId(InstanceIdentifier<Node> id, Switches node) {
41         SwitchesKey switchesKey = transform(id, node).key();
42         return id.augmentation(HwvtepGlobalAugmentation.class).child(Switches.class, switchesKey);
43     }
44
45     @Override
46     public Switches transform(InstanceIdentifier<Node> nodePath, Switches src) {
47         SwitchesBuilder builder = new SwitchesBuilder(src);
48         InstanceIdentifier<Node> psNodeIid = (InstanceIdentifier<Node>) src.getSwitchRef().getValue();
49         String psNodeId = psNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
50         String nodeId = nodePath.firstKeyOf(Node.class).getNodeId().getValue();
51         int idx = nodeId.indexOf("/physicalswitch/");
52         if (idx > 0) {
53             nodeId = nodeId.substring(0, idx);
54         }
55         idx = psNodeId.indexOf("/physicalswitch/") + "/physicalswitch/".length();
56         String switchName = psNodeId.substring(idx);
57         String dstNodeId = nodeId + "/physicalswitch/" + switchName;
58
59         InstanceIdentifier<Node> id2 = HwvtepHAUtil.convertToInstanceIdentifier(dstNodeId);
60
61         builder.setSwitchRef(new HwvtepPhysicalSwitchRef(id2));
62         builder.withKey(new SwitchesKey(new HwvtepPhysicalSwitchRef(id2)));
63         return builder.build();
64     }
65
66     @Override
67     public Identifier getKey(Switches data) {
68         InstanceIdentifier<?> id = data.getSwitchRef().getValue();
69         return id.firstKeyOf(Node.class);
70     }
71
72     @Override
73     public String getDescription() {
74         return "Switches";
75     }
76
77     @Override
78     public boolean areEqual(Switches switchA, Switches switchB) {
79         return true;
80     }
81
82     @Override
83     public Switches withoutUuid(Switches data) {
84         return data;
85     }
86 }