A bunch of miscellaneous services to get Distributed Data Store ready for deployment 96/8396/5
authorMoiz Raja <moraja@cisco.com>
Fri, 27 Jun 2014 00:49:01 +0000 (17:49 -0700)
committerEd Warnicke <eaw@cisco.com>
Fri, 4 Jul 2014 20:26:26 +0000 (20:26 +0000)
- 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 <moraja@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/pom.xml
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ActorSystemFactory.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStore.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohort.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/NonPersistent.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractActorTest.java

index 5aea3fb..5152363 100644 (file)
       <version>${slf4j.version}</version>
       <scope>test</scope>
     </dependency>
       <version>${slf4j.version}</version>
       <scope>test</scope>
     </dependency>
+
   </dependencies>
 
   <build>
   </dependencies>
 
   <build>
             <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
             <Export-package></Export-package>
             <Private-Package></Private-Package>
             <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
             <Export-package></Export-package>
             <Private-Package></Private-Package>
+            <Import-Package>!*snappy;!org.jboss.*;*</Import-Package>
+            <Embed-Dependency>
+                !sal*;
+                !*config-api*;
+                !*testkit*;
+                akka*;
+                *leveldb*;
+                *config*;
+                *hawt*;
+                *protobuf*;
+                *netty*;
+                *uncommons*;
+                *scala*;
+            </Embed-Dependency>
+            <Embed-Transitive>true</Embed-Transitive>
           </instructions>
         </configuration>
       </plugin>
           </instructions>
         </configuration>
       </plugin>
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 (file)
index 0000000..c562e6f
--- /dev/null
@@ -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;
+    }
+}
index 4964b92..3c760f3 100644 (file)
@@ -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);
 
     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);
     }
         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 (file)
index 0000000..f19cb92
--- /dev/null
@@ -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;
+
+    }
+}
index 09ad005..221e874 100644 (file)
@@ -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.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;
 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);
 
     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) {
     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);
     }
 
         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);
     @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) {
         } 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 CreateTransaction) {
             createTransaction();
+        } else if(message instanceof NonPersistent){
+            commit((Modification) ((NonPersistent) message).payload());
         }
     }
 
         }
     }
 
@@ -109,8 +121,7 @@ public class Shard extends UntypedProcessor {
                 getSelf());
     }
 
                 getSelf());
     }
 
-    private void commit(Persistent message) {
-        Modification modification = (Modification) message.payload();
+    private void commit(Modification modification) {
         DOMStoreThreePhaseCommitCohort cohort =
             modificationToCohort.remove(modification);
         if (cohort == null) {
         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());
         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) {
     }
 
     private void updateSchemaContext(UpdateSchemaContext message) {
index e6adfbe..b10bf1d 100644 (file)
@@ -56,6 +56,7 @@ public class ThreePhaseCommitCohort extends UntypedActor {
         });
     }
 
         });
     }
 
+
     @Override
     public void onReceive(Object message) throws Exception {
         log.debug("Received message {}", message);
     @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 (file)
index 0000000..a779ed0
--- /dev/null
@@ -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);
+    }
+}
index 0aa205f..c97e07d 100644 (file)
@@ -12,6 +12,7 @@ import akka.actor.ActorPath;
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import akka.actor.ActorSystem;
 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;
 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);
     }
 
         return executeRemoteOperation(primary, message, duration);
     }
 
+    public void shutdown() {
+        shardManager.tell(PoisonPill.getInstance(), null);
+        actorSystem.shutdown();
+    }
 }
 }
index 665cb2d..039446b 100644 (file)
@@ -1,15 +1,20 @@
 package org.opendaylight.controller.config.yang.config.distributed_datastore_provider;
 
 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);
     }
 
         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);
     }
 
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
@@ -20,22 +25,8 @@ public class DistributedConfigDataStoreProviderModule extends org.opendaylight.c
 
     @Override
     public java.lang.AutoCloseable createInstance() {
 
     @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());
     }
 
 }
     }
 
 }
index e4f30ac..1a06629 100644 (file)
@@ -1,15 +1,20 @@
 package org.opendaylight.controller.config.yang.config.distributed_datastore_provider;
 
 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);
     }
 
         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);
     }
 
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
@@ -18,22 +23,10 @@ public class DistributedOperationalDataStoreProviderModule extends org.opendayli
         // add custom validation form module attributes here.
     }
 
         // 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();
-  }
-
 }
 }
index 45ef32f..214b3e9 100644 (file)
@@ -14,21 +14,22 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
 public abstract class AbstractActorTest {
 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;
+    }
 
 }
 
 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.