Merge "Add test for generated code checking list of dependencies."
[controller.git] / opendaylight / md-sal / forwardingrules-manager / src / main / java / org / opendaylight / controller / frm / flow / FlowTransaction.xtend
1 package org.opendaylight.controller.frm.flow
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.flow.inventory.rev130819.tables.Table
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow
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.opendaylight.flow.service.rev130819.SalFlowService
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef
19
20 class FlowTransaction extends AbstractTransaction {
21     
22     @Property
23     val SalFlowService salFlowService;
24     
25     new(DataModification<InstanceIdentifier<? extends DataObject>, DataObject> modification,SalFlowService salFlowService) {
26         super(modification)
27         _salFlowService = salFlowService;
28     }
29     
30     override remove(InstanceIdentifier<?> instanceId, DataObject obj) {
31         if(obj instanceof Flow) {
32             val flow = (obj as Flow)
33             val tableInstanceId = instanceId.firstIdentifierOf(Table);
34             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
35             val builder = new RemoveFlowInputBuilder(flow);
36             builder.setFlowRef(new FlowRef(instanceId));
37             builder.setNode(new NodeRef(nodeInstanceId));
38             builder.setFlowTable(new FlowTableRef(tableInstanceId));
39             _salFlowService.removeFlow(builder.build());            
40         }
41     }
42     
43     override update(InstanceIdentifier<?> instanceId, DataObject originalObj, DataObject updatedObj) {
44         if(originalObj instanceof Flow && updatedObj instanceof Flow) {
45             val originalFlow = (originalObj as Flow)
46             val updatedFlow = (updatedObj as Flow)
47             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
48             val builder = new UpdateFlowInputBuilder();
49             builder.setNode(new NodeRef(nodeInstanceId));
50             builder.setFlowRef(new FlowRef(instanceId));
51             val ufb = new UpdatedFlowBuilder(updatedFlow);
52             builder.setUpdatedFlow((ufb.build()));
53             val ofb = new OriginalFlowBuilder(originalFlow);
54             builder.setOriginalFlow(ofb.build());      
55             _salFlowService.updateFlow(builder.build());
56            
57         }
58     }
59     
60     override add(InstanceIdentifier<?> instanceId, DataObject obj) {
61         if(obj instanceof Flow) {
62             val flow = (obj as Flow)
63             val tableInstanceId = instanceId.firstIdentifierOf(Table);
64             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
65             val builder = new AddFlowInputBuilder(flow);
66             builder.setNode(new NodeRef(nodeInstanceId));
67             builder.setFlowRef(new FlowRef(instanceId));
68             builder.setFlowTable(new FlowTableRef(tableInstanceId));
69             _salFlowService.addFlow(builder.build());            
70         }
71     }
72     
73     override validate() throws IllegalStateException {
74         FlowTransactionValidator.validate(this)
75     }  
76 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.