From: Tony Tkacik Date: Fri, 20 Jun 2014 12:55:23 +0000 (+0000) Subject: Merge "Fix checkstyle errors in sal-compatibility" X-Git-Tag: release/helium~634 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=ceec41033ab311600969e595191a952ab4e6047d;hp=61b98547c0130ca5b20cbc407df31e75f1f3fc93;p=controller.git Merge "Fix checkstyle errors in sal-compatibility" --- diff --git a/opendaylight/commons/opendaylight/pom.xml b/opendaylight/commons/opendaylight/pom.xml index 1c21351d57..990276468b 100644 --- a/opendaylight/commons/opendaylight/pom.xml +++ b/opendaylight/commons/opendaylight/pom.xml @@ -340,6 +340,11 @@ akka-remote_${scala.version} ${akka.version} + + com.typesafe.akka + akka-testkit_${scala.version} + ${akka.version} + commons-codec commons-codec diff --git a/opendaylight/distribution/opendaylight/src/main/resources/configuration/initial/01-md-sal.xml b/opendaylight/distribution/opendaylight/src/main/resources/configuration/initial/01-md-sal.xml index d872bfd47b..8b07ce3a33 100644 --- a/opendaylight/distribution/opendaylight/src/main/resources/configuration/initial/01-md-sal.xml +++ b/opendaylight/distribution/opendaylight/src/main/resources/configuration/initial/01-md-sal.xml @@ -68,6 +68,20 @@ runtime-mapping-singleton + + prefix:binding-forwarded-data-broker + binding-async-data-broker + + + dom:dom-broker-osgi-registry + dom-broker + + + binding:binding-dom-mapping-service + runtime-mapping-singleton + + + @@ -122,6 +136,14 @@ + + binding:binding-async-data-broker + + binding-data-broker + /modules/module[type='binding-forwarded-data-broker'][name='binding-async-data-broker'] + + + dom:dom-async-data-broker diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/BindingDataBroker.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/BindingDataBroker.java index c6a9efe21c..7eee5c8b62 100644 --- a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/BindingDataBroker.java +++ b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/BindingDataBroker.java @@ -13,7 +13,7 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -public interface BindingDataBroker extends AsyncDataBroker, DataObject, BindingDataChangeListener>{ +public interface BindingDataBroker extends AsyncDataBroker, DataObject, BindingDataChangeListener>, BindingService { @Override BindingDataReadTransaction newReadOnlyTransaction(); diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/BindingService.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/BindingService.java new file mode 100644 index 0000000000..ccce73c7d7 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/md/sal/binding/api/BindingService.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2014 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.md.sal.binding.api; + +import org.opendaylight.controller.sal.binding.api.BindingAwareService; + +/** + * + * Marker interface for MD-SAL services which are available for users of MD-SAL. + * + * BindingService is marker interface for infrastructure services provided by + * the SAL. These services may be session-specific, and wrapped by custom + * delegator patterns in order to introduce additional semantics / checks + * to the system. + * + * This interface extends {@link BindingAwareService}, order to be make + * new services available via + * {@link org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext} + * and via + * {@link org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext} + * + */ +public interface BindingService extends BindingAwareService { + +} diff --git a/opendaylight/md-sal/sal-binding-broker/pom.xml b/opendaylight/md-sal/sal-binding-broker/pom.xml index 2470ba5133..7fc467670d 100644 --- a/opendaylight/md-sal/sal-binding-broker/pom.xml +++ b/opendaylight/md-sal/sal-binding-broker/pom.xml @@ -142,7 +142,7 @@ org.opendaylight.controller.md.sal.binding.impl, org.opendaylight.controller.sal.binding.osgi.*, - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.binding.impl.rev131028 + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.binding.impl.rev131028.* diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingAsyncDataBrokerImplModule.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingAsyncDataBrokerImplModule.java new file mode 100644 index 0000000000..17cd67a857 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingAsyncDataBrokerImplModule.java @@ -0,0 +1,75 @@ +package org.opendaylight.controller.config.yang.md.sal.binding.impl; + +import java.util.Collection; +import java.util.Collections; + +import org.opendaylight.controller.md.sal.binding.impl.ForwardedBindingDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService; +import org.osgi.framework.BundleContext; + +public class BindingAsyncDataBrokerImplModule extends + org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractBindingAsyncDataBrokerImplModule implements + Provider { + private BundleContext bundleContext; + + public BindingAsyncDataBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public BindingAsyncDataBrokerImplModule( + final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + final org.opendaylight.controller.config.yang.md.sal.binding.impl.BindingAsyncDataBrokerImplModule oldModule, + final java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + Broker domBroker = getDomAsyncBrokerDependency(); + BindingIndependentMappingService mappingService = getBindingMappingServiceDependency(); + + // FIXME: Switch this to DOM Broker registration which would not require + // BundleContext when API are updated. + ProviderSession session = domBroker.registerProvider(this, getBundleContext()); + DOMDataBroker domDataBroker = session.getService(DOMDataBroker.class); + SchemaService schemaService = session.getService(SchemaService.class); + return new ForwardedBindingDataBroker(domDataBroker, mappingService, schemaService); + } + + // FIXME: Remove this when DOM Broker registration would not require + // BundleContext + @Deprecated + private BundleContext getBundleContext() { + return bundleContext; + } + + // FIXME: Remove this when DOM Broker registration would not require + // BundleContext + @Deprecated + void setBundleContext(final BundleContext bundleContext) { + this.bundleContext = bundleContext; + } + + @Override + public Collection getProviderFunctionality() { + return Collections.emptySet(); + } + + @Override + public void onSessionInitiated(final ProviderSession arg0) { + // intentional NOOP + } + +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingAsyncDataBrokerImplModuleFactory.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingAsyncDataBrokerImplModuleFactory.java new file mode 100644 index 0000000000..763e6ad3ca --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingAsyncDataBrokerImplModuleFactory.java @@ -0,0 +1,37 @@ +/* +* Generated file +* +* Generated from: yang module name: opendaylight-sal-binding-broker-impl yang module local name: binding-forwarded-data-broker +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Fri May 16 17:18:18 CEST 2014 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.controller.config.yang.md.sal.binding.impl; + +import org.opendaylight.controller.config.api.DependencyResolver; +import org.osgi.framework.BundleContext; + +public class BindingAsyncDataBrokerImplModuleFactory extends org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractBindingAsyncDataBrokerImplModuleFactory { + + + + + @Override + public BindingAsyncDataBrokerImplModule instantiateModule(final String instanceName, + final DependencyResolver dependencyResolver, final BindingAsyncDataBrokerImplModule oldModule, + final AutoCloseable oldInstance, final BundleContext bundleContext) { + BindingAsyncDataBrokerImplModule module = super.instantiateModule(instanceName, dependencyResolver, oldModule, oldInstance, bundleContext); + module.setBundleContext(bundleContext); + return module; + } + + @Override + public BindingAsyncDataBrokerImplModule instantiateModule(final String instanceName, + final DependencyResolver dependencyResolver, final BundleContext bundleContext) { + // TODO Auto-generated method stub + BindingAsyncDataBrokerImplModule module = super.instantiateModule(instanceName, dependencyResolver, bundleContext); + module.setBundleContext(bundleContext); + return module; + } +} diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingBrokerImplModule.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingBrokerImplModule.java index 44a508c0a0..188272fb60 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingBrokerImplModule.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingBrokerImplModule.java @@ -31,14 +31,14 @@ public final class BindingBrokerImplModule extends private BundleContext bundleContext; - public BindingBrokerImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, - org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + public BindingBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); } - public BindingBrokerImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, - org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, - BindingBrokerImplModule oldModule, java.lang.AutoCloseable oldInstance) { + public BindingBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + final BindingBrokerImplModule oldModule, final java.lang.AutoCloseable oldInstance) { super(identifier, dependencyResolver, oldModule, oldInstance); } @@ -63,23 +63,24 @@ public final class BindingBrokerImplModule extends private RootBindingAwareBroker createStandaloneBroker() { RootBindingAwareBroker broker = new RootBindingAwareBroker(getIdentifier().getInstanceName()); - broker.setDataBroker(getDataBrokerDependency()); + broker.setLegacyDataBroker(getDataBrokerDependency()); broker.setNotificationBroker(getNotificationServiceDependency()); broker.setRpcBroker(new RpcProviderRegistryImpl(broker.getIdentifier())); + // FIXME: Also set Async Data Broker return broker; } private RootBindingAwareBroker createForwardedBroker() { DomForwardedBindingBrokerImpl broker = new DomForwardedBindingBrokerImpl(getIdentifier().getInstanceName()); - broker.setDataBroker(getDataBrokerDependency()); + broker.setLegacyDataBroker(getDataBrokerDependency()); broker.setNotificationBroker(getNotificationServiceDependency()); broker.setRpcBroker(new RpcProviderRegistryImpl(broker.getIdentifier())); broker.getMountManager().setDataCommitExecutor(SingletonHolder.getDefaultCommitExecutor()); broker.getMountManager().setNotificationExecutor(SingletonHolder.getDefaultNotificationExecutor()); - + // FIXME: Also set Async Data Broker DomForwardingUtils.reuseForwardingFrom(broker, broker.getDataBroker()); broker.startForwarding(); return broker; @@ -89,7 +90,7 @@ public final class BindingBrokerImplModule extends return bundleContext; } - public void setBundleContext(BundleContext bundleContext) { + public void setBundleContext(final BundleContext bundleContext) { this.bundleContext = bundleContext; } } diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/ForwardedCompatibleDataBrokerImplModule.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/ForwardedCompatibleDataBrokerImplModule.java index 647ca85671..7467e544fd 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/ForwardedCompatibleDataBrokerImplModule.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/ForwardedCompatibleDataBrokerImplModule.java @@ -59,10 +59,9 @@ public final class ForwardedCompatibleDataBrokerImplModule extends Broker domBroker = getDomAsyncBrokerDependency(); ProviderSession session = domBroker.registerProvider(this, getBundleContext()); DOMDataBroker domDataBroker = session.getService(DOMDataBroker.class); + SchemaService schemaService = session.getService(SchemaService.class); ForwardedBackwardsCompatibleDataBroker dataBroker = new ForwardedBackwardsCompatibleDataBroker(domDataBroker, - mappingService, listeningExecutor); - - session.getService(SchemaService.class).registerSchemaServiceListener(dataBroker); + mappingService, schemaService,listeningExecutor); dataBroker.setConnector(BindingDomConnectorDeployer.createConnector(getBindingMappingServiceDependency())); dataBroker.setDomProviderContext(session); diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedDataBroker.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedDataBroker.java index 2a866a94b3..b09cd1c80a 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedDataBroker.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedDataBroker.java @@ -23,6 +23,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener; import org.opendaylight.controller.sal.binding.impl.connect.dom.BindingIndependentConnector; import org.opendaylight.controller.sal.binding.impl.forward.DomForwardedBroker; import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; +import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.yangtools.concepts.AbstractListenerRegistration; import org.opendaylight.yangtools.concepts.Delegator; import org.opendaylight.yangtools.concepts.ListenerRegistration; @@ -33,6 +34,7 @@ import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMapping import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; +import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,7 +42,7 @@ import com.google.common.base.Objects; import com.google.common.base.Optional; public abstract class AbstractForwardedDataBroker implements Delegator, DomForwardedBroker, - SchemaContextListener { + SchemaContextListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(AbstractForwardedDataBroker.class); // The Broker to whom we do all forwarding @@ -53,12 +55,14 @@ public abstract class AbstractForwardedDataBroker implements Delegator schemaListenerRegistration; protected AbstractForwardedDataBroker(final DOMDataBroker domDataBroker, - final BindingIndependentMappingService mappingService) { + final BindingIndependentMappingService mappingService,final SchemaService schemaService) { this.domDataBroker = domDataBroker; this.mappingService = mappingService; this.codec = new BindingToNormalizedNodeCodec(mappingService); + this.schemaListenerRegistration = schemaService.registerSchemaServiceListener(this); } protected BindingToNormalizedNodeCodec getCodec() { @@ -286,4 +290,9 @@ public abstract class AbstractForwardedDataBroker implements Delegator, CommitHandlerRegistrationImpl> commitHandlers = new ConcurrentHashMap<>(); - private final ListenerRegistry fakeRegistry = ListenerRegistry.create(); private final ListeningExecutorService executorService; public ForwardedBackwardsCompatibleDataBroker(final DOMDataBroker domDataBroker, - final BindingIndependentMappingService mappingService, final ListeningExecutorService executor) { - super(domDataBroker, mappingService); + final BindingIndependentMappingService mappingService, final SchemaService schemaService,final ListeningExecutorService executor) { + super(domDataBroker, mappingService,schemaService); executorService = executor; LOG.info("ForwardedBackwardsCompatibleBroker started."); } @@ -129,12 +129,6 @@ public class ForwardedBackwardsCompatibleDataBroker extends AbstractForwardedDat throw new UnsupportedOperationException("Data reader contract is not supported."); } - @Override - public void close() throws Exception { - // TODO Auto-generated method stub - - } - public ListenableFuture> commit(final ForwardedBackwardsCompatibleTransacion tx) { final List, DataObject>> subTrans = new ArrayList<>(); diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedBindingDataBroker.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedBindingDataBroker.java index fb06b130ce..5ab088e20e 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedBindingDataBroker.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/ForwardedBindingDataBroker.java @@ -18,6 +18,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -41,8 +42,8 @@ import com.google.common.util.concurrent.ListenableFuture; */ public class ForwardedBindingDataBroker extends AbstractForwardedDataBroker implements BindingDataBroker { - public ForwardedBindingDataBroker(final DOMDataBroker domDataBroker, final BindingIndependentMappingService mappingService) { - super(domDataBroker, mappingService); + public ForwardedBindingDataBroker(final DOMDataBroker domDataBroker, final BindingIndependentMappingService mappingService, final SchemaService schemaService) { + super(domDataBroker, mappingService,schemaService); } @Override diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend index 3fef544f81..00c9f1eb91 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend @@ -16,6 +16,7 @@ import org.opendaylight.yangtools.yang.binding.util.BindingReflections import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils import static extension org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification.* +import org.opendaylight.yangtools.yang.binding.RpcService class RuntimeCodeGenerator extends AbstractRuntimeCodeGenerator { @@ -28,7 +29,7 @@ class RuntimeCodeGenerator extends AbstractRuntimeCodeGenerator { val proxyName = iface.directProxyName; val potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(proxyName) if(potentialClass != null) { - return potentialClass.newInstance; + return potentialClass.newInstance as RpcService; } val supertype = iface.asCtClass val createdCls = createClass(iface.directProxyName, supertype) [ @@ -53,7 +54,7 @@ class RuntimeCodeGenerator extends AbstractRuntimeCodeGenerator { ''' ] ] - return createdCls.toClass(iface.classLoader).newInstance + return createdCls.toClass(iface.classLoader).newInstance as RpcService ] } @@ -63,7 +64,7 @@ class RuntimeCodeGenerator extends AbstractRuntimeCodeGenerator { val routerName = iface.routerName; val potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(routerName) if(potentialClass != null) { - return potentialClass.newInstance; + return potentialClass.newInstance as RpcService; } val targetCls = createClass(iface.routerName, supertype) [ @@ -106,7 +107,7 @@ class RuntimeCodeGenerator extends AbstractRuntimeCodeGenerator { ''' ] ] - return targetCls.toClass(iface.classLoader,iface.protectionDomain).newInstance + return targetCls.toClass(iface.classLoader,iface.protectionDomain).newInstance as RpcService ]; } diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RootBindingAwareBroker.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RootBindingAwareBroker.java index 75d44db9d1..8acad1b2d7 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RootBindingAwareBroker.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RootBindingAwareBroker.java @@ -7,7 +7,9 @@ */ package org.opendaylight.controller.sal.binding.impl; -import com.google.common.collect.ImmutableClassToInstanceMap; +import static com.google.common.base.Preconditions.checkState; + +import org.opendaylight.controller.md.sal.binding.api.BindingDataBroker; import org.opendaylight.controller.md.sal.binding.util.AbstractBindingSalProviderInstance; import org.opendaylight.controller.md.sal.binding.util.BindingContextUtils; import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; @@ -32,13 +34,13 @@ import org.opendaylight.yangtools.yang.binding.RpcService; import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static com.google.common.base.Preconditions.checkState; + +import com.google.common.collect.ImmutableClassToInstanceMap; public class RootBindingAwareBroker implements // Mutable, // Identifiable, // - BindingAwareBroker, AutoCloseable, - RpcProviderRegistry { + BindingAwareBroker, AutoCloseable, RpcProviderRegistry { private final static Logger LOG = LoggerFactory.getLogger(RootBindingAwareBroker.class); @@ -50,7 +52,9 @@ public class RootBindingAwareBroker implements // private NotificationProviderService notificationBroker; - private DataProviderService dataBroker; + private DataProviderService legacyDataBroker; + + private BindingDataBroker dataBroker; private MountPointManagerImpl mountManager; @@ -58,7 +62,7 @@ public class RootBindingAwareBroker implements // return mountManager; } - public void setMountManager(MountPointManagerImpl mountManager) { + public void setMountManager(final MountPointManagerImpl mountManager) { this.mountManager = mountManager; } @@ -66,11 +70,12 @@ public class RootBindingAwareBroker implements // private ImmutableClassToInstanceMap supportedProviderServices; - public RootBindingAwareBroker(String instanceName) { + public RootBindingAwareBroker(final String instanceName) { this.identifier = instanceName; mountManager = new MountPointManagerImpl(); } + @Override public String getIdentifier() { return identifier; } @@ -80,7 +85,7 @@ public class RootBindingAwareBroker implements // } public DataProviderService getDataBroker() { - return this.dataBroker; + return this.legacyDataBroker; } public NotificationProviderService getNotificationBroker() { @@ -95,16 +100,16 @@ public class RootBindingAwareBroker implements // return rpcBroker; } - public void setRpcBroker(RpcProviderRegistry rpcBroker) { + public void setRpcBroker(final RpcProviderRegistry rpcBroker) { this.rpcBroker = rpcBroker; } - public void setNotificationBroker(NotificationProviderService notificationBroker) { + public void setNotificationBroker(final NotificationProviderService notificationBroker) { this.notificationBroker = notificationBroker; } - public void setDataBroker(DataProviderService dataBroker) { - this.dataBroker = dataBroker; + public void setLegacyDataBroker(final DataProviderService dataBroker) { + this.legacyDataBroker = dataBroker; } public void start() { @@ -113,29 +118,30 @@ public class RootBindingAwareBroker implements // controllerRoot = new RootSalInstance(getRpcProviderRegistry(), getNotificationBroker(), getDataBroker()); + ImmutableClassToInstanceMap.Builder consBuilder = ImmutableClassToInstanceMap.builder(); - supportedConsumerServices = ImmutableClassToInstanceMap. builder() - .put(NotificationService.class, getRoot()) // - .put(DataBrokerService.class, getRoot()) // - .put(RpcConsumerRegistry.class, getRoot()) // - .put(MountService.class, mountManager).build(); - + consBuilder.put(NotificationService.class, getRoot()); + consBuilder.put(DataBrokerService.class, getRoot()); + consBuilder.put(RpcConsumerRegistry.class, getRoot()); + if(dataBroker != null) { + consBuilder.put(BindingDataBroker.class, dataBroker); + } + consBuilder.put(MountService.class, mountManager).build(); + supportedConsumerServices = consBuilder.build(); supportedProviderServices = ImmutableClassToInstanceMap. builder() - .putAll(supportedConsumerServices) - .put(NotificationProviderService.class, getRoot()) // - .put(DataProviderService.class, getRoot()) // - .put(RpcProviderRegistry.class, getRoot()) // + .putAll(supportedConsumerServices).put(NotificationProviderService.class, getRoot()) + .put(DataProviderService.class, getRoot()).put(RpcProviderRegistry.class, getRoot()) .put(MountProviderService.class, mountManager).build(); } @Override - public ConsumerContext registerConsumer(BindingAwareConsumer consumer, BundleContext ctx) { + public ConsumerContext registerConsumer(final BindingAwareConsumer consumer, final BundleContext ctx) { checkState(supportedConsumerServices != null, "Broker is not initialized."); return BindingContextUtils.createConsumerContextAndInitialize(consumer, supportedConsumerServices); } @Override - public ProviderContext registerProvider(BindingAwareProvider provider, BundleContext ctx) { + public ProviderContext registerProvider(final BindingAwareProvider provider, final BundleContext ctx) { checkState(supportedProviderServices != null, "Broker is not initialized."); return BindingContextUtils.createProviderContextAndInitialize(provider, supportedProviderServices); } @@ -146,34 +152,38 @@ public class RootBindingAwareBroker implements // } @Override - public RoutedRpcRegistration addRoutedRpcImplementation(Class type, T implementation) - throws IllegalStateException { + public RoutedRpcRegistration addRoutedRpcImplementation(final Class type, + final T implementation) throws IllegalStateException { return getRoot().addRoutedRpcImplementation(type, implementation); } @Override - public RpcRegistration addRpcImplementation(Class type, T implementation) + public RpcRegistration addRpcImplementation(final Class type, final T implementation) throws IllegalStateException { return getRoot().addRpcImplementation(type, implementation); } @Override - public T getRpcService(Class module) { + public T getRpcService(final Class module) { return getRoot().getRpcService(module); } + @Override public >> ListenerRegistration registerRouteChangeListener( - L arg0) { + final L arg0) { return getRoot().registerRouteChangeListener(arg0); } - public class RootSalInstance extends AbstractBindingSalProviderInstance { - public RootSalInstance(RpcProviderRegistry rpcRegistry, NotificationProviderService notificationBroker, - DataProviderService dataBroker) { + public RootSalInstance(final RpcProviderRegistry rpcRegistry, + final NotificationProviderService notificationBroker, final DataProviderService dataBroker) { super(rpcRegistry, notificationBroker, dataBroker); } } + + public void setDataBroker(final BindingDataBroker asyncDataBroker) { + dataBroker = asyncDataBroker; + } } diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang b/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang index 428025a58d..4456dea77f 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang +++ b/opendaylight/md-sal/sal-binding-broker/src/main/yang/opendaylight-binding-broker-impl.yang @@ -42,6 +42,12 @@ module opendaylight-sal-binding-broker-impl { config:provided-service sal:binding-data-consumer-broker; config:java-name-prefix ForwardedCompatibleDataBrokerImpl; } + + identity binding-forwarded-data-broker { + base config:module-type; + config:provided-service sal:binding-async-data-broker; + config:java-name-prefix BindingAsyncDataBrokerImpl; + } identity binding-rpc-broker { base config:module-type; @@ -62,6 +68,26 @@ module opendaylight-sal-binding-broker-impl { config:java-name-prefix RuntimeMapping; } + grouping dom-forwarding-component { + container dom-async-broker { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity dom:dom-broker-osgi-registry; + } + } + } + + container binding-mapping-service { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity binding-dom-mapping-service; + } + } + } + } + augment "/config:modules/config:module/config:configuration" { case binding-broker-impl { when "/config:modules/config:module/config:type = 'binding-broker-impl'"; @@ -123,22 +149,15 @@ module opendaylight-sal-binding-broker-impl { case binding-data-compatible-broker { when "/config:modules/config:module/config:type = 'binding-data-compatible-broker'"; - container dom-async-broker { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity dom:dom-broker-osgi-registry; - } - } - } - - container binding-mapping-service { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity binding-dom-mapping-service; - } - } + uses dom-forwarding-component; + } + } + + augment "/config:modules/config:module/config:configuration" { + case binding-forwarded-data-broker { + when "/config:modules/config:module/config:type = 'binding-forwarded-data-broker'"; + container binding-forwarded-data-broker { + uses dom-forwarding-component; } } } diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java index ae65c8889a..623b2fdd63 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java @@ -48,7 +48,6 @@ import org.opendaylight.controller.sal.dom.broker.impl.DataStoreStatsWrapper; import org.opendaylight.controller.sal.dom.broker.impl.HashMapDataStore; import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter; import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker; -import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProvider; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl; import org.opendaylight.yangtools.yang.common.QName; @@ -57,7 +56,6 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; import org.reflections.Reflections; import org.reflections.scanners.ResourcesScanner; @@ -70,7 +68,7 @@ import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.ListeningExecutorService; -public class BindingTestContext implements AutoCloseable, SchemaContextProvider { +public class BindingTestContext implements AutoCloseable { public static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier TREE_ROOT = org.opendaylight.yangtools.yang.data.api.InstanceIdentifier .builder().toInstance(); @@ -101,22 +99,19 @@ public class BindingTestContext implements AutoCloseable, SchemaContextProvider private MountPointManagerImpl biMountImpl; - private SchemaContext schemaContext; + private ImmutableMap newDatastores; private BackwardsCompatibleDataBroker biCompatibleBroker; - private final List schemaListeners = new ArrayList<>(); - private DataProviderService baData; private DOMDataBroker newDOMDataBroker; - @Override - public SchemaContext getSchemaContext() { - return schemaContext; - } + private final MockSchemaService mockSchemaService = new MockSchemaService(); + + public DOMDataBroker getDomAsyncDataBroker() { return newDOMDataBroker; @@ -128,6 +123,7 @@ public class BindingTestContext implements AutoCloseable, SchemaContextProvider this.startWithSchema = startWithSchema; } + @Deprecated public void startDomDataStore() { checkState(dataStore == null, "DataStore already started."); checkState(biDataImpl != null, "Dom Data Broker not present"); @@ -140,7 +136,7 @@ public class BindingTestContext implements AutoCloseable, SchemaContextProvider } else { dataStore = schemaAwareDataStore; } - + mockSchemaService.registerSchemaServiceListener(schemaAwareDataStore); biDataImpl.registerConfigurationReader(TREE_ROOT, dataStore); biDataImpl.registerOperationalReader(TREE_ROOT, dataStore); biDataImpl.registerCommitHandler(TREE_ROOT, dataStore); @@ -166,9 +162,9 @@ public class BindingTestContext implements AutoCloseable, SchemaContextProvider biCompatibleBroker = new BackwardsCompatibleDataBroker(newDOMDataBroker); - schemaListeners.add(configStore); - schemaListeners.add(operStore); - schemaListeners.add(biCompatibleBroker); + mockSchemaService.registerSchemaServiceListener(configStore); + mockSchemaService.registerSchemaServiceListener(operStore); + mockSchemaService.registerSchemaServiceListener(biCompatibleBroker); biDataLegacyBroker = biCompatibleBroker; } @@ -188,7 +184,7 @@ public class BindingTestContext implements AutoCloseable, SchemaContextProvider baBrokerImpl.getMountManager().setDataCommitExecutor(executor); baBrokerImpl.getMountManager().setNotificationExecutor(executor); baBrokerImpl.setRpcBroker(new RpcProviderRegistryImpl("test")); - baBrokerImpl.setDataBroker(baData); + baBrokerImpl.setLegacyDataBroker(baData); baBrokerImpl.setNotificationBroker(baNotifyImpl); baBrokerImpl.start(); } @@ -268,20 +264,11 @@ public class BindingTestContext implements AutoCloseable, SchemaContextProvider public void startBindingToDomMappingService() { checkState(classPool != null, "ClassPool needs to be present"); mappingServiceImpl = new RuntimeGeneratedMappingServiceImpl(classPool); + mockSchemaService.registerSchemaServiceListener(mappingServiceImpl); } public void updateYangSchema(final String[] files) { - schemaContext = getContext(files); - - if (schemaAwareDataStore != null) { - schemaAwareDataStore.onGlobalContextUpdated(schemaContext); - } - if (mappingServiceImpl != null) { - mappingServiceImpl.onGlobalContextUpdated(schemaContext); - } - for(SchemaContextListener listener : schemaListeners) { - listener.onGlobalContextUpdated(schemaContext); - } + mockSchemaService.changeSchema(getContext(files)); } public static String[] getAllYangFilesOnClasspath() { @@ -340,8 +327,7 @@ public class BindingTestContext implements AutoCloseable, SchemaContextProvider } public void startNewBindingDataBroker() { - ForwardedBackwardsCompatibleDataBroker forwarded = new ForwardedBackwardsCompatibleDataBroker(newDOMDataBroker, mappingServiceImpl, executor); - schemaListeners.add(forwarded); + ForwardedBackwardsCompatibleDataBroker forwarded = new ForwardedBackwardsCompatibleDataBroker(newDOMDataBroker, mappingServiceImpl,mockSchemaService, executor); baData = forwarded; } @@ -353,7 +339,7 @@ public class BindingTestContext implements AutoCloseable, SchemaContextProvider private void startDomBroker() { checkState(executor != null); biBrokerImpl = new BrokerImpl(); - biBrokerImpl.setRouter(new SchemaAwareRpcBroker("/", this)); + biBrokerImpl.setRouter(new SchemaAwareRpcBroker("/", mockSchemaService)); } @@ -429,4 +415,6 @@ public class BindingTestContext implements AutoCloseable, SchemaContextProvider public MountProvisionService getDomMountProviderService() { return biMountImpl; } + + } diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/MockSchemaService.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/MockSchemaService.java new file mode 100644 index 0000000000..c8acbcd994 --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/MockSchemaService.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2014 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.sal.binding.test.util; + +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProvider; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.concepts.util.ListenerRegistry; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener; + +@SuppressWarnings("deprecation") +public final class MockSchemaService implements SchemaService, SchemaContextProvider { + + private SchemaContext schemaContext; + + ListenerRegistry listeners = ListenerRegistry.create(); + + @Override + public void addModule(final Module module) { + throw new UnsupportedOperationException(); + } + + @Override + public synchronized SchemaContext getGlobalContext() { + return schemaContext; + } + + @Override + public synchronized SchemaContext getSessionContext() { + return schemaContext; + } + + @Override + public ListenerRegistration registerSchemaServiceListener( + final SchemaServiceListener listener) { + return listeners.register(listener); + } + + @Override + public void removeModule(final Module module) { + throw new UnsupportedOperationException(); + } + + @Override + public synchronized SchemaContext getSchemaContext() { + return schemaContext; + } + + public synchronized void changeSchema(final SchemaContext newContext) { + schemaContext = newContext; + for (ListenerRegistration listener : listeners) { + listener.getInstance().onGlobalContextUpdated(schemaContext); + } + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-md-sal-binding.yang b/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-md-sal-binding.yang index 38f0da3ccc..4a2ec8a063 100644 --- a/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-md-sal-binding.yang +++ b/opendaylight/md-sal/sal-binding-config/src/main/yang/opendaylight-md-sal-binding.yang @@ -22,6 +22,11 @@ module opendaylight-md-sal-binding { base "config:service-type"; config:java-class "org.opendaylight.controller.sal.binding.api.data.DataProviderService"; } + + identity binding-async-data-broker { + base "config:service-type"; + config:java-class "org.opendaylight.controller.md.sal.binding.api.BindingDataBroker"; + } identity binding-data-consumer-broker { base "config:service-type"; diff --git a/opendaylight/md-sal/sal-distributed-datastore/pom.xml b/opendaylight/md-sal/sal-distributed-datastore/pom.xml index e7fcd83328..cf28d067ab 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/pom.xml +++ b/opendaylight/md-sal/sal-distributed-datastore/pom.xml @@ -35,6 +35,11 @@ akka-remote_${scala.version} + + com.typesafe.akka + akka-testkit_${scala.version} + + @@ -92,7 +97,6 @@ org.osgi.core - org.scala-lang scala-library @@ -109,6 +113,7 @@ mockito-all test + org.slf4j slf4j-simple diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java index 1bc554f3ed..8d5b0c2f4a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2014 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.cluster.datastore; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ListenerRegistrationProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ListenerRegistrationProxy.java index 19e7f198df..c2fc8c0277 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ListenerRegistrationProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ListenerRegistrationProxy.java @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2014 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.cluster.datastore; import org.opendaylight.yangtools.concepts.ListenerRegistration; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java new file mode 100644 index 0000000000..63266d6308 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014 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.cluster.datastore; + +import akka.actor.Address; +import akka.actor.UntypedActor; +import akka.event.Logging; +import akka.event.LoggingAdapter; +import org.opendaylight.controller.cluster.datastore.messages.FindPrimary; +import org.opendaylight.controller.cluster.datastore.messages.PrimaryNotFound; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * The ShardManager has the following jobs, + * + * - Create all the local shard replicas that belong on this cluster member + * - Find the primary replica for any given shard + * - Engage in shard replica elections which decide which replica should be the primary + * + * Creation of Shard replicas + * ========================== + * When the ShardManager is constructed it reads the cluster configuration to find out which shard replicas + * belong on this member. It finds out the name of the current cluster member from the Akka Clustering Service. + * + * Replica Elections + * ================= + * The Shard Manager uses multiple cues to initiate election. + * - When a member of the cluster dies + * - When a local shard replica dies + * - When a local shard replica comes alive + */ +public class ShardManager extends UntypedActor { + + // Stores a mapping between a shard name and the address of the current primary + private final Map shardNameToPrimaryAddress = new HashMap<>(); + + // Stores a mapping between a member name and the address of the member + private final Map memberNameToAddress = new HashMap<>(); + + // Stores a mapping between the shard name and all the members on which a replica of that shard are available + private final Map> shardNameToMembers = new HashMap<>(); + + LoggingAdapter log = Logging.getLogger(getContext().system(), this); + + @Override + public void onReceive(Object message) throws Exception { + if(message instanceof FindPrimary ){ + FindPrimary msg = ((FindPrimary) message); + getSender().tell(new PrimaryNotFound(msg.getShardName()), getSelf()); + } + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java index 20a74e30da..1ee0d89e61 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2014 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.cluster.datastore; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java index c9a630445b..609dea0b36 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2014 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.cluster.datastore; import com.google.common.base.Optional; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/FindPrimary.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/FindPrimary.java new file mode 100644 index 0000000000..f2497e6517 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/FindPrimary.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2014 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.cluster.datastore.messages; + +import com.google.common.base.Preconditions; + +/** + * The FindPrimary message is used to locate the primary of any given shard + * + * TODO : Make this serializable + */ +public class FindPrimary{ + private final String shardName; + + public FindPrimary(String shardName){ + + Preconditions.checkNotNull(shardName, "shardName should not be null"); + + this.shardName = shardName; + } + + public String getShardName() { + return shardName; + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PrimaryFound.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PrimaryFound.java new file mode 100644 index 0000000000..1326898b0f --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PrimaryFound.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2014 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.cluster.datastore.messages; + +public class PrimaryFound { +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PrimaryNotFound.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PrimaryNotFound.java new file mode 100644 index 0000000000..c66e12cb39 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/PrimaryNotFound.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014 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.cluster.datastore.messages; + +import com.google.common.base.Preconditions; + +public class PrimaryNotFound { + + private final String shardName; + + public PrimaryNotFound(String shardName){ + + Preconditions.checkNotNull(shardName, "shardName should not be null"); + + this.shardName = shardName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + PrimaryNotFound that = (PrimaryNotFound) o; + + if (shardName != null ? !shardName.equals(that.shardName) : that.shardName != null) return false; + + return true; + } + + @Override + public int hashCode() { + return shardName != null ? shardName.hashCode() : 0; + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java new file mode 100644 index 0000000000..9c1ea70fdb --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardManagerTest.java @@ -0,0 +1,52 @@ +package org.opendaylight.controller.cluster.datastore; + +import akka.actor.ActorSystem; +import akka.actor.Props; +import akka.testkit.JavaTestKit; +import akka.testkit.TestActorRef; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.controller.cluster.datastore.messages.FindPrimary; +import org.opendaylight.controller.cluster.datastore.messages.PrimaryNotFound; +import scala.concurrent.duration.Duration; + +public class ShardManagerTest { + private static ActorSystem system; + + @BeforeClass + public static void setUp(){ + system = ActorSystem.create("test"); + } + + @AfterClass + public static void tearDown(){ + JavaTestKit.shutdownActorSystem(system); + system = null; + } + + @Test + public void testOnReceiveFindPrimary() throws Exception { + + new JavaTestKit(system) {{ + final Props props = Props.create(ShardManager.class); + final TestActorRef subject = TestActorRef.create(system, props, "test"); + + // can also use JavaTestKit “from the outside” + final JavaTestKit probe = new JavaTestKit(system); + + // the run() method needs to finish within 3 seconds + new Within(duration("3 seconds")) { + protected void run() { + + subject.tell(new FindPrimary("inventory"), getRef()); + + expectMsgEquals(Duration.Zero(), new PrimaryNotFound("inventory")); + + // Will wait for the rest of the 3 seconds + expectNoMsg(); + } + }; + }}; + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/FindPrimaryTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/FindPrimaryTest.java new file mode 100644 index 0000000000..7e4ec10501 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/FindPrimaryTest.java @@ -0,0 +1,21 @@ +package org.opendaylight.controller.cluster.datastore.messages; + +import org.junit.Test; + +public class FindPrimaryTest { + + @Test + public void testNewBuilderForType() throws Exception { + + } + + @Test + public void testToBuilder() throws Exception { + + } + + @Test + public void testGetDefaultInstanceForType() throws Exception { + + } +} \ No newline at end of file