From: Moiz Raja Date: Fri, 27 Jun 2014 00:49:01 +0000 (-0700) Subject: A bunch of miscellaneous services to get Distributed Data Store ready for deployment X-Git-Tag: release/helium~530^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=1af23ad8e572896323ed5d1c723d977a16eb7e6d A bunch of miscellaneous services to get Distributed Data Store ready for deployment - Shard can work with both Persistent and NonPersistent messages which change the state of the InMemoryDataStore - OSGi related changes so that the DistributedDataStore can load properly in the controller - Other changes so that there are no startup errors (like creating a single actor system) Change-Id: Ic9b211e2007002fa800b980e8c94463241e36b59 Signed-off-by: Moiz Raja --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/pom.xml b/opendaylight/md-sal/sal-distributed-datastore/pom.xml index 5aea3fb959..5152363ab2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/pom.xml +++ b/opendaylight/md-sal/sal-distributed-datastore/pom.xml @@ -136,6 +136,7 @@ ${slf4j.version} test + @@ -150,6 +151,21 @@ ${project.groupId}.${project.artifactId} + !*snappy;!org.jboss.*;* + + !sal*; + !*config-api*; + !*testkit*; + akka*; + *leveldb*; + *config*; + *hawt*; + *protobuf*; + *netty*; + *uncommons*; + *scala*; + + true diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ActorSystemFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ActorSystemFactory.java new file mode 100644 index 0000000000..c562e6f50f --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ActorSystemFactory.java @@ -0,0 +1,22 @@ +/* + * 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.ActorSystem; +import com.typesafe.config.ConfigFactory; + +public class ActorSystemFactory { + private static final ActorSystem actorSystem = + ActorSystem.create("opendaylight-cluster", ConfigFactory + .load().getConfig("ODLCluster")); + + public static final ActorSystem getInstance(){ + return actorSystem; + } +} 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 4964b92ab7..3c760f35b8 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 @@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory; /** * */ -public class DistributedDataStore implements DOMStore, SchemaContextListener { +public class DistributedDataStore implements DOMStore, SchemaContextListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(DistributedDataStore.class); @@ -95,4 +95,9 @@ public class DistributedDataStore implements DOMStore, SchemaContextListener { actorContext.getShardManager().tell( new UpdateSchemaContext(schemaContext), null); } + + @Override public void close() throws Exception { + actorContext.shutdown(); + + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java new file mode 100644 index 0000000000..f19cb9284c --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java @@ -0,0 +1,22 @@ +/* + * 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.api.model.SchemaService; + +public class DistributedDataStoreFactory { + public static DistributedDataStore createInstance(String name, SchemaService schemaService){ + final DistributedDataStore dataStore = + new DistributedDataStore(ActorSystemFactory.getInstance(), name); + schemaService + .registerSchemaServiceListener(dataStore); + return dataStore; + + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java index 09ad00598f..221e874fd5 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java @@ -25,6 +25,7 @@ import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionC import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChainReply; import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply; import org.opendaylight.controller.cluster.datastore.messages.ForwardedCommitTransaction; +import org.opendaylight.controller.cluster.datastore.messages.NonPersistent; import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener; import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListenerReply; import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext; @@ -63,8 +64,16 @@ public class Shard extends UntypedProcessor { private final LoggingAdapter log = Logging.getLogger(getContext().system(), this); + // By default persistent will be true and can be turned off using the system + // property persistent + private final boolean persistent; + private Shard(String name) { - log.info("Creating shard : {}", name ); + + String setting = System.getProperty("shard.persistent"); + this.persistent = !"false".equals(setting); + + log.info("Creating shard : {} persistent : {}", name , persistent); store = new InMemoryDOMDataStore(name, storeExecutor); } @@ -80,6 +89,7 @@ public class Shard extends UntypedProcessor { }); } + @Override public void onReceive(Object message) throws Exception { log.debug("Received message {}", message); @@ -93,9 +103,11 @@ public class Shard extends UntypedProcessor { } else if (message instanceof ForwardedCommitTransaction) { handleForwardedCommit((ForwardedCommitTransaction) message); } else if (message instanceof Persistent) { - commit((Persistent) message); + commit((Modification) ((Persistent) message).payload()); } else if (message instanceof CreateTransaction) { createTransaction(); + } else if(message instanceof NonPersistent){ + commit((Modification) ((NonPersistent) message).payload()); } } @@ -109,8 +121,7 @@ public class Shard extends UntypedProcessor { getSelf()); } - private void commit(Persistent message) { - Modification modification = (Modification) message.payload(); + private void commit(Modification modification) { DOMStoreThreePhaseCommitCohort cohort = modificationToCohort.remove(modification); if (cohort == null) { @@ -138,8 +149,13 @@ public class Shard extends UntypedProcessor { log.info("received forwarded transaction"); modificationToCohort .put(message.getModification(), message.getCohort()); - getSelf().forward(Persistent.create(message.getModification()), - getContext()); + if(persistent) { + getSelf().forward(Persistent.create(message.getModification()), + getContext()); + } else { + getSelf().forward(NonPersistent.create(message.getModification()), + getContext()); + } } private void updateSchemaContext(UpdateSchemaContext message) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohort.java index e6adfbee66..b10bf1d9fc 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohort.java @@ -56,6 +56,7 @@ public class ThreePhaseCommitCohort extends UntypedActor { }); } + @Override public void onReceive(Object message) throws Exception { log.debug("Received message {}", message); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/NonPersistent.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/NonPersistent.java new file mode 100644 index 0000000000..a779ed0854 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/NonPersistent.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.cluster.datastore.messages; + +/** + * A NonPersistent message is to be used when we want to trigger state update + * for an actor without actually persisting the data to disk. This could be + * useful for test purposes. + */ +public class NonPersistent { + private final Object payload; + + public NonPersistent(Object payload){ + this.payload = payload; + } + + public Object payload() { + return payload; + } + + public static NonPersistent create(Object payload){ + return new NonPersistent(payload); + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java index 0aa205fa06..c97e07db6d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java @@ -12,6 +12,7 @@ import akka.actor.ActorPath; import akka.actor.ActorRef; import akka.actor.ActorSelection; import akka.actor.ActorSystem; +import akka.actor.PoisonPill; import akka.util.Timeout; import org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException; import org.opendaylight.controller.cluster.datastore.exceptions.TimeoutException; @@ -144,4 +145,8 @@ public class ActorContext { return executeRemoteOperation(primary, message, duration); } + public void shutdown() { + shardManager.tell(PoisonPill.getInstance(), null); + actorSystem.shutdown(); + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java index 665cb2d441..039446baf3 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java @@ -1,15 +1,20 @@ package org.opendaylight.controller.config.yang.config.distributed_datastore_provider; -import akka.actor.ActorSystem; -import com.typesafe.config.ConfigFactory; -import org.opendaylight.controller.cluster.datastore.DistributedDataStore; +import org.opendaylight.controller.cluster.datastore.DistributedDataStoreFactory; -public class DistributedConfigDataStoreProviderModule extends org.opendaylight.controller.config.yang.config.distributed_datastore_provider.AbstractDistributedConfigDataStoreProviderModule { - public DistributedConfigDataStoreProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { +public class DistributedConfigDataStoreProviderModule extends + org.opendaylight.controller.config.yang.config.distributed_datastore_provider.AbstractDistributedConfigDataStoreProviderModule { + public DistributedConfigDataStoreProviderModule( + org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); } - public DistributedConfigDataStoreProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedConfigDataStoreProviderModule oldModule, java.lang.AutoCloseable oldInstance) { + public DistributedConfigDataStoreProviderModule( + org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedConfigDataStoreProviderModule oldModule, + java.lang.AutoCloseable oldInstance) { super(identifier, dependencyResolver, oldModule, oldInstance); } @@ -20,22 +25,8 @@ public class DistributedConfigDataStoreProviderModule extends org.opendaylight.c @Override public java.lang.AutoCloseable createInstance() { - final ActorSystem actorSystem = ActorSystem.create("opendaylight-cluster-system", ConfigFactory - .load().getConfig("ODLCluster")); - - - final DistributedDataStore configDatastore = new DistributedDataStore(actorSystem, "config"); - getSchemaServiceDependency().registerSchemaServiceListener(configDatastore); - - final class AutoCloseableDistributedDataStore implements AutoCloseable { - - @Override - public void close() throws Exception { - actorSystem.shutdown(); - } - } - - return new AutoCloseableDistributedDataStore(); + return DistributedDataStoreFactory + .createInstance("config", getSchemaServiceDependency()); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java index e4f30ac723..1a06629bb7 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java @@ -1,15 +1,20 @@ package org.opendaylight.controller.config.yang.config.distributed_datastore_provider; -import akka.actor.ActorSystem; -import com.typesafe.config.ConfigFactory; -import org.opendaylight.controller.cluster.datastore.DistributedDataStore; +import org.opendaylight.controller.cluster.datastore.DistributedDataStoreFactory; -public class DistributedOperationalDataStoreProviderModule extends org.opendaylight.controller.config.yang.config.distributed_datastore_provider.AbstractDistributedOperationalDataStoreProviderModule { - public DistributedOperationalDataStoreProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { +public class DistributedOperationalDataStoreProviderModule extends + org.opendaylight.controller.config.yang.config.distributed_datastore_provider.AbstractDistributedOperationalDataStoreProviderModule { + public DistributedOperationalDataStoreProviderModule( + org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); } - public DistributedOperationalDataStoreProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedOperationalDataStoreProviderModule oldModule, java.lang.AutoCloseable oldInstance) { + public DistributedOperationalDataStoreProviderModule( + org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + org.opendaylight.controller.config.yang.config.distributed_datastore_provider.DistributedOperationalDataStoreProviderModule oldModule, + java.lang.AutoCloseable oldInstance) { super(identifier, dependencyResolver, oldModule, oldInstance); } @@ -18,22 +23,10 @@ public class DistributedOperationalDataStoreProviderModule extends org.opendayli // add custom validation form module attributes here. } - @Override - public java.lang.AutoCloseable createInstance() { - final ActorSystem actorSystem = ActorSystem.create("opendaylight-cluster", ConfigFactory - .load().getConfig("ODLCluster")); - final DistributedDataStore operationalStore = new DistributedDataStore(actorSystem, "operational"); - getSchemaServiceDependency().registerSchemaServiceListener(operationalStore); - - final class AutoCloseableDistributedDataStore implements AutoCloseable { - - @Override - public void close() throws Exception { - actorSystem.shutdown(); - } + @Override + public java.lang.AutoCloseable createInstance() { + return DistributedDataStoreFactory + .createInstance("operational", getSchemaServiceDependency()); } - return new AutoCloseableDistributedDataStore(); - } - } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractActorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractActorTest.java index 45ef32f7ad..214b3e9d3d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractActorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractActorTest.java @@ -14,21 +14,22 @@ import org.junit.AfterClass; import org.junit.BeforeClass; public abstract class AbstractActorTest { - private static ActorSystem system; + private static ActorSystem system; - @BeforeClass - public static void setUpClass(){ - system = ActorSystem.create("test"); - } + @BeforeClass + public static void setUpClass() { + System.setProperty("shard.persistent", "false"); + system = ActorSystem.create("test"); + } - @AfterClass - public static void tearDownClass(){ - JavaTestKit.shutdownActorSystem(system); - system = null; - } + @AfterClass + public static void tearDownClass() { + JavaTestKit.shutdownActorSystem(system); + system = null; + } - protected ActorSystem getSystem(){ - return system; - } + protected ActorSystem getSystem() { + return system; + } }