From: Tomas Cere Date: Fri, 20 Jan 2017 15:52:53 +0000 (+0100) Subject: Add singleton service based global rpc X-Git-Tag: release/carbon~311 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=61ef209240959401c9d8d33ed439451bb8801f0a;hp=244ee83be8c1180ea1845b8768503c8013b0dc7f Add singleton service based global rpc 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 --- 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 index 0000000000..ff34d87108 --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/model/src/main/yang/rpc-test.yang @@ -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 index 0000000000..75b31d406c --- /dev/null +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/BasicRpcTestProvider.java @@ -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 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 closeServiceInstance() { + rpcRegistration.close(); + rpcRegistration = null; + + return Futures.immediateFuture(null); + } + + @Override + public ServiceGroupIdentifier getIdentifier() { + return IDENTIFIER; + } + + @Override + public Future> basicGlobal() { + LOG.info("Basic test global rpc invoked"); + + return Futures.immediateFuture(RpcResultBuilder.success().build()); + } +} diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/resources/org/opendaylight/blueprint/cluster-test-app.xml b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/resources/org/opendaylight/blueprint/cluster-test-app.xml index dfb69f0e78..c6f3aed401 100644 --- a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/resources/org/opendaylight/blueprint/cluster-test-app.xml +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/resources/org/opendaylight/blueprint/cluster-test-app.xml @@ -7,6 +7,8 @@ + + @@ -33,4 +35,9 @@ + + + + + \ No newline at end of file