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=9b3446c93b4c365fdf83191be64e2429b7f6ba22;hp=81f0220b1a81560a59c14350d60e91609ea13ef5;hb=db89afdefb3cfa4454dfdc6008e1d54d3ede66fb;hpb=271e66acd1391895c006806dfe76ae6d09017a83 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 81f0220b1a..9b3446c93b 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,13 +9,23 @@ package org.opendaylight.controller.clustering.it.provider; import com.google.common.util.concurrent.Futures; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.Future; import org.opendaylight.controller.clustering.it.provider.impl.GetConstantService; +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.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; 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; @@ -36,10 +46,13 @@ import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.l 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.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; 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; @@ -49,24 +62,55 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService private final RpcProviderRegistry rpcRegistry; private final BindingAwareBroker.RpcRegistration registration; + private final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer; + private final SchemaService schemaService; private final ClusterSingletonServiceProvider singletonService; private final DOMRpcProviderService domRpcService; + private Map, DOMRpcImplementationRegistration> routedRegistrations = + new HashMap<>(); + private DOMRpcImplementationRegistration globalGetConstantRegistration = null; + private ClusterSingletonServiceRegistration getSingletonConstantRegistration; public MdsalLowLevelTestProvider(final RpcProviderRegistry rpcRegistry, final DOMRpcProviderService domRpcService, - final ClusterSingletonServiceProvider singletonService) { + final ClusterSingletonServiceProvider singletonService, + final SchemaService schemaService, + final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer) { this.rpcRegistry = rpcRegistry; this.domRpcService = domRpcService; this.singletonService = singletonService; + this.schemaService = schemaService; + this.bindingNormalizedNodeSerializer = bindingNormalizedNodeSerializer; registration = rpcRegistry.addRpcImplementation(OdlMdsalLowlevelControlService.class, this); } @Override public Future> unregisterSingletonConstant() { - return null; + LOG.debug("unregister-singleton-constant"); + + if (getSingletonConstantRegistration == null) { + LOG.debug("No get-singleton-constant registration present."); + final RpcError rpcError = RpcResultBuilder + .newError(ErrorType.APPLICATION, "missing-registration", "No get-singleton-constant rpc registration present."); + final RpcResult result = RpcResultBuilder.failed().withRpcError(rpcError).build(); + return Futures.immediateFuture(result); + } + + try { + getSingletonConstantRegistration.close(); + getSingletonConstantRegistration = null; + + return Futures.immediateFuture(RpcResultBuilder.success().build()); + } catch (final Exception e) { + LOG.debug("There was a problem closing the singleton constant service", e); + final RpcError rpcError = RpcResultBuilder + .newError(ErrorType.APPLICATION, "error-closing", "There was a problem closing get-singleton-constant"); + final RpcResult result = RpcResultBuilder.failed().withRpcError(rpcError).build(); + return Futures.immediateFuture(result); + } } @Override @@ -110,13 +154,39 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } @Override - public Future> unregisterBoundConstant(UnregisterBoundConstantInput input) { - return null; + public Future> unregisterBoundConstant(final UnregisterBoundConstantInput input) { + LOG.debug("unregister-bound-constant, {}", input); + + final DOMRpcImplementationRegistration registration = + routedRegistrations.remove(input.getContext()); + + if (registration == null) { + LOG.debug("No get-contexted-constant registration for context: {}", input.getContext()); + final RpcError rpcError = RpcResultBuilder + .newError(ErrorType.APPLICATION, "missing-registration", "No get-constant rpc registration present."); + final RpcResult result = RpcResultBuilder.failed().withRpcError(rpcError).build(); + return Futures.immediateFuture(result); + } + + registration.close(); + return Futures.immediateFuture(RpcResultBuilder.success().build()); } @Override - public Future> registerSingletonConstant(RegisterSingletonConstantInput input) { - return null; + public Future> registerSingletonConstant(final RegisterSingletonConstantInput input) { + + LOG.debug("Received register-singleton-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.failed().withRpcError(error).build()); + } + + getSingletonConstantRegistration = + SingletonGetConstantService.registerNew(singletonService, domRpcService, input.getConstant()); + + return Futures.immediateFuture(RpcResultBuilder.success().build()); } @Override @@ -156,8 +226,33 @@ public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService } @Override - public Future> registerBoundConstant(RegisterBoundConstantInput input) { - return null; + public Future> registerBoundConstant(final RegisterBoundConstantInput input) { + LOG.debug("register-bound-constant: {}", input); + + if (input.getContext() == null) { + final RpcError error = RpcResultBuilder.newError( + ErrorType.RPC, "Invalid input.", "Context value is null"); + return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); + } + + if (input.getConstant() == null) { + final RpcError error = RpcResultBuilder.newError( + ErrorType.RPC, "Invalid input.", "Constant value is null"); + return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); + } + + if (routedRegistrations.containsKey(input.getContext())) { + final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Registration present.", + "There is already a rpc registered for context: " + input.getContext()); + return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); + } + + final DOMRpcImplementationRegistration registration = + RoutedGetConstantService.registerNew(bindingNormalizedNodeSerializer, domRpcService, + input.getConstant(), input.getContext()); + + routedRegistrations.put(input.getContext(), registration); + return Futures.immediateFuture(RpcResultBuilder.success().build()); } @Override