Add singleton service based global rpc 24/50724/3
authorTomas Cere <tcere@cisco.com>
Fri, 20 Jan 2017 15:52:53 +0000 (16:52 +0100)
committerTom Pantelis <tpanteli@brocade.com>
Mon, 23 Jan 2017 17:28:55 +0000 (17:28 +0000)
We need to have a global rpc present that we can use in csit,
use ClusterSingletonService to have it registered only on one
node in cluster.

Change-Id: Id4019ebb874a1da7919d1484ec7af7f5b3395283
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/rpc-test.yang [new file with mode: 0644]
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/BasicRpcTestProvider.java [new file with mode: 0644]
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/resources/org/opendaylight/blueprint/cluster-test-app.xml

diff --git a/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/rpc-test.yang b/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/rpc-test.yang
new file mode 100644 (file)
index 0000000..ff34d87
--- /dev/null
@@ -0,0 +1,16 @@
+module basic-rpc-test {
+    yang-version 1;
+
+    namespace "urn:opendaylight:controller:basic-rpc-test";
+    prefix "base-endpoint";
+
+    revision "2016-01-20" {
+        description
+                "Initial revision.";
+    }
+
+    rpc basic-global {
+        description "Invoke a global rpc that should only have one implementation registered on one of the nodes.
+                     It has no input/output.";
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/BasicRpcTestProvider.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/BasicRpcTestProvider.java
new file mode 100644 (file)
index 0000000..75b31d4
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.clustering.it.provider;
+
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.Future;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
+import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.controller.basic.rpc.test.rev160120.BasicRpcTestService;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BasicRpcTestProvider implements ClusterSingletonService, BasicRpcTestService {
+
+    private static final Logger LOG = LoggerFactory.getLogger(BasicRpcTestProvider.class);
+    private static final ServiceGroupIdentifier IDENTIFIER = ServiceGroupIdentifier.create("Basic-rpc-test");
+
+    private final RpcProviderRegistry rpcProviderRegistry;
+    private final ClusterSingletonServiceProvider singletonService;
+    private BindingAwareBroker.RpcRegistration<BasicRpcTestService> rpcRegistration;
+
+    public BasicRpcTestProvider(final RpcProviderRegistry rpcProviderRegistry,
+                                final ClusterSingletonServiceProvider singletonService) {
+        this.rpcProviderRegistry = rpcProviderRegistry;
+        this.singletonService = singletonService;
+
+        singletonService.registerClusterSingletonService(this);
+    }
+
+    @Override
+    public void instantiateServiceInstance() {
+        LOG.info("Basic testing rpc registered as global");
+        rpcRegistration = rpcProviderRegistry.addRpcImplementation(BasicRpcTestService.class, this);
+    }
+
+    @Override
+    public ListenableFuture<Void> closeServiceInstance() {
+        rpcRegistration.close();
+        rpcRegistration = null;
+
+        return Futures.immediateFuture(null);
+    }
+
+    @Override
+    public ServiceGroupIdentifier getIdentifier() {
+        return IDENTIFIER;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> basicGlobal() {
+        LOG.info("Basic test global rpc invoked");
+
+        return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
+    }
+}
index dfb69f0..c6f3aed 100644 (file)
@@ -7,6 +7,8 @@
   <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
   <reference id="notificationService" interface="org.opendaylight.controller.sal.binding.api.NotificationProviderService"/>
   <reference id="entityOwnershipService" interface="org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService"/>
+  <reference id="bindingRpcRegistry" interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"/>
+  <reference id="clusterSingletonService" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
 
   <bean id="purchaseCarProvider" class="org.opendaylight.controller.clustering.it.provider.PurchaseCarProvider" >
     <property name="notificationProvider" ref="notificationService"/>
@@ -33,4 +35,9 @@
 
   <odl:notification-listener ref="peopleCarListener"/>
 
+  <bean id="basicTestProvider" class="org.opendaylight.controller.clustering.it.provider.BasicRpcTestProvider">
+    <argument ref="bindingRpcRegistry"/>
+    <argument ref="clusterSingletonService"/>
+  </bean>
+
 </blueprint>
\ No newline at end of file

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.