X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Fclustering-test-app%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fit%2Fprovider%2FMdsalLowLevelTestProvider.java;h=7ada4bea61090c1aa31c384de9a66c92e34c17c9;hp=bdc2d2f22468821604e4610bd42f92dc8ced4b3e;hb=9c17a104cd90b5529b5623d1d0136d7cc332707d;hpb=d2d8e123aa7ee34c47f12b959592631c0538482b 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 index bdc2d2f224..7ada4bea61 100644 --- 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 @@ -9,22 +9,24 @@ package org.opendaylight.controller.clustering.it.provider; import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.SettableFuture; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Future; import org.opendaylight.controller.clustering.it.provider.impl.FlappingSingletonService; import org.opendaylight.controller.clustering.it.provider.impl.GetConstantService; +import org.opendaylight.controller.clustering.it.provider.impl.PublishNotificationsTask; import org.opendaylight.controller.clustering.it.provider.impl.RoutedGetConstantService; import org.opendaylight.controller.clustering.it.provider.impl.SingletonGetConstantService; -import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; -import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodecFactory; +import org.opendaylight.controller.clustering.it.provider.impl.YnlListener; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; 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.controller.sal.core.api.model.SchemaService; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; -import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration; import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.AddShardReplicaInput; @@ -54,7 +56,6 @@ 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.opendaylight.yangtools.yang.model.api.SchemaContextListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,6 +66,8 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService private final RpcProviderRegistry rpcRegistry; private final BindingAwareBroker.RpcRegistration registration; private final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer; + private final NotificationPublishService notificationPublishService; + private final NotificationService notificationService; private final SchemaService schemaService; private final ClusterSingletonServiceProvider singletonService; private final DOMRpcProviderService domRpcService; @@ -72,6 +75,8 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService private Map, DOMRpcImplementationRegistration> routedRegistrations = new HashMap<>(); + private Map> ynlRegistrations = new HashMap<>(); + private DOMRpcImplementationRegistration globalGetConstantRegistration = null; private ClusterSingletonServiceRegistration getSingletonConstantRegistration; private FlappingSingletonService flappingSingletonService; @@ -80,12 +85,16 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService final DOMRpcProviderService domRpcService, final ClusterSingletonServiceProvider singletonService, final SchemaService schemaService, - final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer) { + final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer, + final NotificationPublishService notificationPublishService, + final NotificationService notificationService) { this.rpcRegistry = rpcRegistry; this.domRpcService = domRpcService; this.singletonService = singletonService; this.schemaService = schemaService; this.bindingNormalizedNodeSerializer = bindingNormalizedNodeSerializer; + this.notificationPublishService = notificationPublishService; + this.notificationService = notificationService; registration = rpcRegistry.addRpcImplementation(OdlMdsalLowlevelControlService.class, this); } @@ -117,8 +126,16 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } @Override - public Future> publishNotifications(PublishNotificationsInput input) { - return null; + public Future> publishNotifications(final PublishNotificationsInput input) { + LOG.debug("publish-notifications, input: {}", input); + + final PublishNotificationsTask task = new PublishNotificationsTask(notificationPublishService, input.getId(), + input.getSeconds(), input.getNotificationsPerSecond()); + + final SettableFuture> settableFuture = SettableFuture.create(); + task.start(settableFuture); + + return settableFuture; } @Override @@ -147,8 +164,20 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } @Override - public Future> subscribeYnl(SubscribeYnlInput input) { - return null; + public Future> subscribeYnl(final SubscribeYnlInput input) { + + LOG.debug("subscribe-ynl, input: {}", input); + + if (ynlRegistrations.containsKey(input.getId())) { + final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Registration present.", + "There is already ynl listener registered for this id: " + input.getId()); + return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); + } + + ynlRegistrations.put(input.getId(), + notificationService.registerNotificationListener(new YnlListener(input.getId()))); + + return Futures.immediateFuture(RpcResultBuilder.success().build()); } @Override @@ -300,8 +329,23 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } @Override - public Future> unsubscribeYnl(UnsubscribeYnlInput input) { - return null; + public Future> unsubscribeYnl(final UnsubscribeYnlInput input) { + LOG.debug("Received unsubscribe-ynl, input: {}", input); + + if (!ynlRegistrations.containsKey(input.getId())) { + final RpcError rpcError = RpcResultBuilder + .newError(ErrorType.APPLICATION, "missing-registration", "No ynl listener with this id registered."); + final RpcResult result = + RpcResultBuilder.failed().withRpcError(rpcError).build(); + return Futures.immediateFuture(result); + } + + final ListenerRegistration registration = ynlRegistrations.remove(input.getId()); + final UnsubscribeYnlOutput output = registration.getInstance().getOutput(); + + registration.close(); + + return Futures.immediateFuture(RpcResultBuilder.success().withResult(output).build()); } @Override