Merge "Bug 499: Added support for old DOM Broker APIs."
[controller.git] / opendaylight / md-sal / compatibility / flow-management-compatibility / src / main / java / org / opendaylight / controller / md / frm / compatibility / SampleConsumer.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.md.frm.compatibility;
9
10 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
11 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
12 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.Flows;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.Flow;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.config.rev130819.flows.FlowKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19
20 public class SampleConsumer {
21
22     ConsumerContext context;
23
24     void addFlowExample() {
25
26         DataBrokerService dataService = context.getSALService(DataBrokerService.class);
27
28         DataModificationTransaction transaction = dataService.beginTransaction();
29         Flow flow = createSampleFlow("foo", null);
30         InstanceIdentifier<Flow> path = InstanceIdentifier.builder(Flows.class).child(Flow.class, flow.getKey())
31                 .toInstance();
32         transaction.putConfigurationData(path, flow);
33
34         transaction.commit();
35
36         dataService.readConfigurationData(path);
37     }
38
39     Flow createSampleFlow(String name, NodeRef node) {
40         FlowBuilder ret = new FlowBuilder();
41         FlowKey key = new FlowKey(Long.parseLong(name), node);
42         ret.setKey(key);
43         return ret.build();
44     }
45 }