Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestServiceProvider.java
1 /**
2  * Copyright (c) 2013 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
9 package org.opendaylight.openflowplugin.test;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
15 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
28 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
29 import org.opendaylight.yangtools.concepts.ObjectRegistration;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class OpenflowpluginTestServiceProvider implements AutoCloseable,
37         SalFlowService {
38
39     private static final Logger LOG = LoggerFactory
40             .getLogger(OpenflowpluginTestServiceProvider.class);
41
42     private DataBroker dataService;
43     private RoutedRpcRegistration<SalFlowService> flowRegistration;
44     private NotificationProviderService notificationProviderService;
45
46     /**
47      * Get data service.
48      *
49      * @return {@link #dataService}
50      */
51     public DataBroker getDataService() {
52         return dataService;
53     }
54
55     /**
56      * Set {@link #dataService}.
57      */
58     public void setDataService(final DataBroker dataService) {
59         this.dataService = dataService;
60     }
61
62     /**
63      * Get flow registration.
64      *
65      * @return {@link #flowRegistration}
66      */
67     public RoutedRpcRegistration<SalFlowService> getFlowRegistration() {
68         return flowRegistration;
69     }
70
71     /**
72      * Set {@link #flowRegistration}.
73      */
74     public void setFlowRegistration(
75             final RoutedRpcRegistration<SalFlowService> flowRegistration) {
76         this.flowRegistration = flowRegistration;
77     }
78
79     /**
80      * Get notification service.
81      *
82      * @return {@link #notificationProviderService}
83      */
84     public NotificationProviderService getNotificationService() {
85         return notificationProviderService;
86     }
87
88     /**
89      * Set {@link #notificationProviderService}.
90      */
91     public void setNotificationService(final NotificationProviderService service) {
92         this.notificationProviderService = service;
93     }
94
95     public void start() {
96         OpenflowpluginTestServiceProvider.LOG
97                 .info("SalFlowServiceProvider Started.");
98     }
99
100     /*
101      * (non-Javadoc)
102      *
103      * @see java.lang.AutoCloseable#close()
104      */
105     @Override
106     public void close() throws Exception {
107         OpenflowpluginTestServiceProvider.LOG
108                 .info("SalFlowServiceProvide stopped.");
109         flowRegistration.close();
110     }
111
112     /*
113      * (non-Javadoc)
114      *
115      * @see
116      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
117      * SalFlowService
118      * #addFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.
119      * service.rev130819.AddFlowInput)
120      */
121     @Override
122     public ListenableFuture<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
123         String plus = "addFlow - " + input;
124         OpenflowpluginTestServiceProvider.LOG.info(plus);
125         return null;
126     }
127
128     /*
129      * (non-Javadoc)
130      *
131      * @see
132      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
133      * SalFlowService
134      * #removeFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
135      * .service.rev130819.RemoveFlowInput)
136      */
137     @Override
138     public ListenableFuture<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
139         String plus = "removeFlow - " + input;
140         OpenflowpluginTestServiceProvider.LOG.info(plus);
141         return null;
142     }
143
144     /*
145      * (non-Javadoc)
146      *
147      * @see
148      * org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.
149      * SalFlowService
150      * #updateFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow
151      * .service.rev130819.UpdateFlowInput)
152      */
153     @Override
154     public ListenableFuture<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
155         String plus = "updateFlow - " + input;
156         OpenflowpluginTestServiceProvider.LOG.info(plus);
157         return null;
158     }
159
160     public ObjectRegistration<OpenflowpluginTestServiceProvider> register(
161             final ProviderContext ctx) {
162         RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation = ctx
163                 .<SalFlowService>addRoutedRpcImplementation(
164                         SalFlowService.class, this);
165
166         setFlowRegistration(addRoutedRpcImplementation);
167
168         InstanceIdentifierBuilder<Nodes> builderII = InstanceIdentifier
169                 .<Nodes>builder(Nodes.class);
170
171         NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
172         NodeKey nodeKey = new NodeKey(nodeId);
173
174         InstanceIdentifierBuilder<Node> nodeIdentifier = builderII
175                 .<Node, NodeKey>child(Node.class, nodeKey);
176
177         InstanceIdentifier<Node> instance = nodeIdentifier.build();
178
179         flowRegistration.registerPath(NodeContext.class, instance);
180
181         RoutedRpcRegistration<SalFlowService> flowRegistration2 = getFlowRegistration();
182
183         return new AbstractObjectRegistration<OpenflowpluginTestServiceProvider>(this) {
184             @Override
185             protected void removeRegistration() {
186                 flowRegistration2.close();
187             }
188         };
189     }
190 }