Merge "make ConfigurationServiceFactoryImpl independent of OSGi"
[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         String plus = "addGroup - " + input;
106         OpenflowpluginGroupTestServiceProvider.LOG.info(plus);
107         return null;
108     }
109
110     /*
111      * (non-Javadoc)
112      *
113      * @see
114      * org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918
115      * .SalGroupService
116      * #removeGroup(org.opendaylight.yang.gen.v1.urn.opendaylight
117      * .group.service.rev130918.RemoveGroupInput)
118      */
119     @Override
120     public ListenableFuture<RpcResult<RemoveGroupOutput>> removeGroup(
121             RemoveGroupInput input) {
122         String plus = "removeGroup - " + input;
123         OpenflowpluginGroupTestServiceProvider.LOG.info(plus);
124         return null;
125     }
126
127     /*
128      * (non-Javadoc)
129      *
130      * @see
131      * org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918
132      * .SalGroupService
133      * #updateGroup(org.opendaylight.yang.gen.v1.urn.opendaylight
134      * .group.service.rev130918.UpdateGroupInput)
135      */
136     @Override
137     public ListenableFuture<RpcResult<UpdateGroupOutput>> updateGroup(
138             UpdateGroupInput input) {
139         String plus = "updateGroup - " + input;
140         OpenflowpluginGroupTestServiceProvider.LOG.info(plus);
141         return null;
142     }
143
144     public ObjectRegistration<OpenflowpluginGroupTestServiceProvider> register(
145             final RpcProviderRegistry rpcRegistry) {
146         RoutedRpcRegistration<SalGroupService> addRoutedRpcImplementation = rpcRegistry.addRoutedRpcImplementation(
147                         SalGroupService.class, this);
148         setGroupRegistration(addRoutedRpcImplementation);
149
150         InstanceIdentifierBuilder<Nodes> builder1 = InstanceIdentifier
151                 .<Nodes>builder(Nodes.class);
152
153         NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
154         NodeKey nodeKey = new NodeKey(nodeId);
155
156         InstanceIdentifierBuilder<Node> nodeIndentifier = builder1
157                 .<Node, NodeKey>child(Node.class, nodeKey);
158         InstanceIdentifier<Node> instance = nodeIndentifier.build();
159         groupRegistration.registerPath(NodeContext.class, instance);
160         RoutedRpcRegistration<SalGroupService> groupRegistration1 = this
161                 .getGroupRegistration();
162         return new AbstractObjectRegistration<OpenflowpluginGroupTestServiceProvider>(this) {
163             @Override
164             protected void removeRegistration() {
165                 groupRegistration1.close();
166             }
167         };
168     }
169 }