BUG 7796: Implement agent RPCs for global RPC testing 74/52074/6
authorTomas Cere <tcere@cisco.com>
Thu, 16 Feb 2017 14:53:43 +0000 (15:53 +0100)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 28 Feb 2017 11:22:28 +0000 (11:22 +0000)
This implements the get-constant and it's lifecycle
control rpc's from the lowlevel mdsal test model.

Change-Id: I2da89b73d289b8fe6bf95aeaba34e7fb50032f7e
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java [new file with mode: 0644]
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/GetConstantService.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/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/MdsalLowLevelTestProvider.java
new file mode 100644 (file)
index 0000000..81f0220
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * 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 java.util.concurrent.Future;
+import org.opendaylight.controller.clustering.it.provider.impl.GetConstantService;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationRegistration;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.AddShardReplicaInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.BecomeModuleLeaderInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.BecomePrefixLeaderInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.IsClientAbortedOutput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.OdlMdsalLowlevelControlService;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.ProduceTransactionsInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.PublishNotificationsInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RegisterBoundConstantInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RegisterConstantInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RegisterDefaultConstantInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RegisterSingletonConstantInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RemoveShardReplicaInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.SubscribeYnlInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnregisterBoundConstantInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnregisterFlappingSingletonOutput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDdtlOutput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeYnlInput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeYnlOutput;
+import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsInput;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService {
+
+    private static final Logger LOG = LoggerFactory.getLogger(MdsalLowLevelTestProvider.class);
+
+    private final RpcProviderRegistry rpcRegistry;
+    private final BindingAwareBroker.RpcRegistration<OdlMdsalLowlevelControlService> registration;
+    private final ClusterSingletonServiceProvider singletonService;
+    private final DOMRpcProviderService domRpcService;
+
+    private DOMRpcImplementationRegistration<GetConstantService> globalGetConstantRegistration = null;
+
+    public MdsalLowLevelTestProvider(final RpcProviderRegistry rpcRegistry,
+                                     final DOMRpcProviderService domRpcService,
+                                     final ClusterSingletonServiceProvider singletonService) {
+        this.rpcRegistry = rpcRegistry;
+        this.domRpcService = domRpcService;
+        this.singletonService = singletonService;
+
+        registration = rpcRegistry.addRpcImplementation(OdlMdsalLowlevelControlService.class, this);
+    }
+
+    @Override
+    public Future<RpcResult<Void>> unregisterSingletonConstant() {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> publishNotifications(PublishNotificationsInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> subscribeDtcl() {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> writeTransactions(WriteTransactionsInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<IsClientAbortedOutput>> isClientAborted() {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> becomeModuleLeader(BecomeModuleLeaderInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> removeShardReplica(RemoveShardReplicaInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> subscribeYnl(SubscribeYnlInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> becomePrefixLeader(BecomePrefixLeaderInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> unregisterBoundConstant(UnregisterBoundConstantInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> registerSingletonConstant(RegisterSingletonConstantInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> registerDefaultConstant(RegisterDefaultConstantInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> unregisterConstant() {
+
+        if (globalGetConstantRegistration == null) {
+            final RpcError rpcError = RpcResultBuilder
+                    .newError(ErrorType.APPLICATION, "missing-registration", "No get-constant rpc registration present.");
+            final RpcResult<Void> result = RpcResultBuilder.<Void>failed().withRpcError(rpcError).build();
+            return Futures.immediateFuture(result);
+        }
+
+        globalGetConstantRegistration.close();
+        globalGetConstantRegistration = null;
+
+        return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
+    }
+
+    @Override
+    public Future<RpcResult<UnregisterFlappingSingletonOutput>> unregisterFlappingSingleton() {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> addShardReplica(AddShardReplicaInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> subscribeDdtl() {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> registerBoundConstant(RegisterBoundConstantInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> registerFlappingSingleton() {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<UnsubscribeDtclOutput>> unsubscribeDtcl() {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> deconfigureIdIntsShard() {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<UnsubscribeYnlOutput>> unsubscribeYnl(UnsubscribeYnlInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> produceTransactions(ProduceTransactionsInput input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<Void>> registerConstant(final RegisterConstantInput input) {
+
+        LOG.debug("Received register-constant rpc, input: {}", input);
+
+        if (input.getConstant() == null) {
+            final RpcError error = RpcResultBuilder.newError(
+                    ErrorType.RPC, "Invalid input.", "Constant value is null");
+            return Futures.immediateFuture(RpcResultBuilder.<Void>failed().withRpcError(error).build());
+        }
+
+        if (globalGetConstantRegistration != null) {
+            final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Registration present.",
+                    "There is already a get-constant rpc registered.");
+            return Futures.immediateFuture(RpcResultBuilder.<Void>failed().withRpcError(error).build());
+        }
+
+        globalGetConstantRegistration = GetConstantService.registerNew(domRpcService, input.getConstant());
+        return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
+    }
+
+    @Override
+    public Future<RpcResult<Void>> unregisterDefaultConstant() {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<UnsubscribeDdtlOutput>> unsubscribeDdtl() {
+        return null;
+    }
+}
diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/GetConstantService.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/GetConstantService.java
new file mode 100644 (file)
index 0000000..6f04b5f
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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.impl;
+
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationRegistration;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
+import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GetConstantService implements DOMRpcImplementation {
+
+    private static final Logger LOG = LoggerFactory.getLogger(GetConstantService.class);
+
+    private static final QName OUTPUT =
+            QName.create("tag:opendaylight.org,2017:controller:yang:lowlevel:target","2017-02-15", "output");
+    private static final QName CONSTANT =
+            QName.create("tag:opendaylight.org,2017:controller:yang:lowlevel:target","2017-02-15", "constant");
+    private static final QName GET_CONSTANT =
+            QName.create("tag:opendaylight.org,2017:controller:yang:lowlevel:target","2017-02-15", "get-constant");
+
+    private final String constant;
+
+    private GetConstantService(final String constant) {
+        this.constant = constant;
+    }
+
+    public static DOMRpcImplementationRegistration<GetConstantService> registerNew(
+            final DOMRpcProviderService rpcProviderService, final String constant) {
+
+        LOG.debug("Registering get-constant service, constant value: {}", constant);
+        final DOMRpcIdentifier id = DOMRpcIdentifier.create(SchemaPath.create(true, GET_CONSTANT));
+
+        return rpcProviderService.registerRpcImplementation(new GetConstantService(constant), id);
+    }
+
+    @Nonnull
+    @Override
+    public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final DOMRpcIdentifier rpc,
+                                                                  @Nullable final NormalizedNode<?, ?> input) {
+        LOG.debug("get-constant invoked, current value: {}", constant);
+
+        final LeafNode<Object> value = ImmutableLeafNodeBuilder.create()
+                .withNodeIdentifier(new NodeIdentifier(CONSTANT))
+                .withValue(constant)
+                .build();
+
+        final ContainerNode result = ImmutableContainerNodeBuilder.create()
+                .withNodeIdentifier(new NodeIdentifier(OUTPUT))
+                .withChild(value)
+                .build();
+
+        return Futures.immediateCheckedFuture(new DefaultDOMRpcResult(result));
+    }
+}
index 4a969d5..687b1a3 100644 (file)
@@ -8,6 +8,7 @@
   <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="domRpcProviderService" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService"/>
   <reference id="clusterSingletonService" interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
   <reference id="domDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"/>
 
     <argument ref="clusterSingletonService"/>
   </bean>
 
+  <bean id="lowLevelTestProvider" class="org.opendaylight.controller.clustering.it.provider.MdsalLowLevelTestProvider">
+    <argument ref="bindingRpcRegistry"/>
+    <argument ref="domRpcProviderService"/>
+    <argument ref="clusterSingletonService"/>
+  </bean>
+
 </blueprint>

©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.