Added paths and mediatypes from Restconf draft 02
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / restconf / impl / BrokerFacade.xtend
1 package org.opendaylight.controller.sal.restconf.impl
2
3 import org.opendaylight.controller.md.sal.common.api.data.DataReader
4 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession
5 import org.opendaylight.controller.sal.core.api.data.DataBrokerService
6 import org.opendaylight.yangtools.yang.common.QName
7 import org.opendaylight.yangtools.yang.common.RpcResult
8 import org.opendaylight.yangtools.yang.data.api.CompositeNode
9 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
10 import static org.opendaylight.controller.sal.restconf.impl.BrokerFacade.*
11
12 class BrokerFacade implements DataReader<InstanceIdentifier, CompositeNode> {
13
14     val static BrokerFacade INSTANCE = new BrokerFacade
15
16     @Property
17     private ConsumerSession context;
18
19     @Property
20     private DataBrokerService dataService;
21     
22     private new() {
23         if (INSTANCE != null) {
24             throw new IllegalStateException("Already instantiated");
25         }
26     }
27     
28     def static BrokerFacade getInstance() {
29         return INSTANCE
30     }
31
32     override readConfigurationData(InstanceIdentifier path) {
33         return dataService.readConfigurationData(path);
34     }
35
36     override readOperationalData(InstanceIdentifier path) {
37         return dataService.readOperationalData(path);
38     }
39
40     def RpcResult<CompositeNode> invokeRpc(QName type, CompositeNode payload) {
41         val future = context.rpc(type, payload);
42         return future.get;
43     }
44
45     def commitConfigurationDataPut(InstanceIdentifier path, CompositeNode payload) {
46         val transaction = dataService.beginTransaction;
47         transaction.putConfigurationData(path, payload);
48         return transaction.commit()
49     }
50
51     def commitOperationalDataPut(InstanceIdentifier path, CompositeNode payload) {
52         val transaction = dataService.beginTransaction;
53         transaction.putOperationalData(path, payload);
54         return transaction.commit()
55     }
56     
57 }