Updated review comments.Bulk transaction support added trasaction attribute with...
[controller.git] / opendaylight / md-sal / forwardingrules-manager / src / main / java / org / opendaylight / controller / frm / group / GroupTransaction.xtend
1 package org.opendaylight.controller.frm.group
2
3 import org.opendaylight.controller.frm.AbstractTransaction
4 import org.opendaylight.controller.md.sal.common.api.data.DataModification
5 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInputBuilder
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroupBuilder
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupRef
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
15 import org.opendaylight.yangtools.yang.binding.DataObject
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri
18
19 class GroupTransaction extends AbstractTransaction {
20     
21     @Property
22     val SalGroupService groupService;
23         
24     new(DataModification<InstanceIdentifier<? extends DataObject>, DataObject> modification,SalGroupService groupService) {
25         super(modification)        
26         _groupService = groupService;
27     }
28     
29     override remove(InstanceIdentifier<?> instanceId, DataObject obj) {
30         if(obj instanceof Group) {
31             val group = (obj as Group)
32             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
33             val builder = new RemoveGroupInputBuilder(group);
34             builder.setNode(new NodeRef(nodeInstanceId));
35             builder.setTransactionUri(new Uri(modification.getIdentifier() as String));
36             builder.setGroupRef(new GroupRef(instanceId));
37             _groupService.removeGroup(builder.build());            
38         }
39     }
40     
41     override update(InstanceIdentifier<?> instanceId, DataObject originalObj, DataObject updatedObj) {
42         if(originalObj instanceof Group && updatedObj instanceof Group) {
43             val originalGroup = (originalObj as Group)
44             val updatedGroup = (updatedObj as Group)
45             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
46             val builder = new UpdateGroupInputBuilder();
47             builder.setNode(new NodeRef(nodeInstanceId));
48             builder.setGroupRef(new GroupRef(instanceId));
49             val ufb = new UpdatedGroupBuilder(updatedGroup);
50             builder.setUpdatedGroup((ufb.build()));
51             builder.setTransactionUri(new Uri(modification.getIdentifier() as String));
52             val ofb = new OriginalGroupBuilder(originalGroup);
53             builder.setOriginalGroup(ofb.build());      
54             _groupService.updateGroup(builder.build());
55            
56         }
57     }
58     
59     override add(InstanceIdentifier<?> instanceId, DataObject obj) {
60         if(obj instanceof Group) {
61             val group = (obj as Group)
62             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
63             val builder = new AddGroupInputBuilder(group);
64             builder.setNode(new NodeRef(nodeInstanceId));
65             builder.setGroupRef(new GroupRef(instanceId));
66             builder.setTransactionUri(new Uri(modification.getIdentifier() as String));
67             _groupService.addGroup(builder.build());            
68         }
69     }
70     
71     override validate() throws IllegalStateException {
72         GroupTransactionValidator.validate(this)
73     }  
74 }