b1c69012d46b903a496071bdf586595443d9b5ea
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginGroupTestServiceProvider.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.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
14 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
27 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
28 import org.opendaylight.yangtools.concepts.ObjectRegistration;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class OpenflowpluginGroupTestServiceProvider implements AutoCloseable,
36         SalGroupService {
37
38     private static final Logger LOG = LoggerFactory
39             .getLogger(OpenflowpluginGroupTestServiceProvider.class);
40     private RoutedRpcRegistration<SalGroupService> groupRegistration;
41     private NotificationProviderService notificationService;
42
43     /**
44      * Get group registration.
45      *
46      * @return {@link #groupRegistration}
47      */
48     public RoutedRpcRegistration<SalGroupService> getGroupRegistration() {
49         return groupRegistration;
50     }
51
52     /**
53      * Set {@link #groupRegistration}.
54      */
55     public void setGroupRegistration(
56             final RoutedRpcRegistration<SalGroupService> groupRegistration) {
57         this.groupRegistration = groupRegistration;
58     }
59
60     /**
61      * Get notification service.
62      *
63      * @return {@link #notificationService}
64      */
65     public NotificationProviderService getNotificationService() {
66         return notificationService;
67     }
68
69     /**
70      * Set {@link #notificationService}.
71      */
72     public void setNotificationService(
73             final NotificationProviderService notificationService) {
74         this.notificationService = notificationService;
75     }
76
77     public void start() {
78         OpenflowpluginGroupTestServiceProvider.LOG
79                 .info("SalGroupServiceProvider Started.");
80     }
81
82     /*
83      * (non-Javadoc)
84      *
85      * @see java.lang.AutoCloseable#close()
86      */
87     @Override
88     public void close() throws Exception {
89         OpenflowpluginGroupTestServiceProvider.LOG
90                 .info("SalGroupServiceProvide stopped.");
91         groupRegistration.close();
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see
98      * org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918
99      * .SalGroupService
100      * #addGroup(org.opendaylight.yang.gen.v1.urn.opendaylight.group
101      * .service.rev130918.AddGroupInput)
102      */
103     @Override
104     public ListenableFuture<RpcResult<AddGroupOutput>> addGroup(AddGroupInput input) {
105         OpenflowpluginGroupTestServiceProvider.LOG.info("addGroup - {}", input);
106         return null;
107     }
108
109     /*
110      * (non-Javadoc)
111      *
112      * @see
113      * org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918
114      * .SalGroupService
115      * #removeGroup(org.opendaylight.yang.gen.v1.urn.opendaylight
116      * .group.service.rev130918.RemoveGroupInput)
117      */
118     @Override
119     public ListenableFuture<RpcResult<RemoveGroupOutput>> removeGroup(
120             RemoveGroupInput input) {
121         OpenflowpluginGroupTestServiceProvider.LOG.info("removeGroup - {}", input);
122         return null;
123     }
124
125     /*
126      * (non-Javadoc)
127      *
128      * @see
129      * org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918
130      * .SalGroupService
131      * #updateGroup(org.opendaylight.yang.gen.v1.urn.opendaylight
132      * .group.service.rev130918.UpdateGroupInput)
133      */
134     @Override
135     public ListenableFuture<RpcResult<UpdateGroupOutput>> updateGroup(
136             UpdateGroupInput input) {
137         OpenflowpluginGroupTestServiceProvider.LOG.info("updateGroup - {}", input);
138         return null;
139     }
140
141     public ObjectRegistration<OpenflowpluginGroupTestServiceProvider> register(
142             final RpcProviderRegistry rpcRegistry) {
143         RoutedRpcRegistration<SalGroupService> addRoutedRpcImplementation = rpcRegistry.addRoutedRpcImplementation(
144                         SalGroupService.class, this);
145         setGroupRegistration(addRoutedRpcImplementation);
146
147         InstanceIdentifierBuilder<Nodes> builder1 = InstanceIdentifier
148                 .<Nodes>builder(Nodes.class);
149
150         NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
151         NodeKey nodeKey = new NodeKey(nodeId);
152
153         InstanceIdentifierBuilder<Node> nodeIndentifier = builder1
154                 .<Node, NodeKey>child(Node.class, nodeKey);
155         InstanceIdentifier<Node> instance = nodeIndentifier.build();
156         groupRegistration.registerPath(NodeContext.class, instance);
157         RoutedRpcRegistration<SalGroupService> groupRegistration1 = this
158                 .getGroupRegistration();
159         return new AbstractObjectRegistration<OpenflowpluginGroupTestServiceProvider>(this) {
160             @Override
161             protected void removeRegistration() {
162                 groupRegistration1.close();
163             }
164         };
165     }
166 }