aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject git commit: Database-backed implementation of SchedulerStore.
Date Wed, 23 Jul 2014 17:20:56 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 58c0de890 -> 27378345c


Database-backed implementation of SchedulerStore.

Bugs closed: AURORA-555

Reviewed at https://reviews.apache.org/r/23107/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/27378345
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/27378345
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/27378345

Branch: refs/heads/master
Commit: 27378345c132bda84271e46cb1109c355e7f6a2a
Parents: 58c0de8
Author: Bill Farner <wfarner@apache.org>
Authored: Wed Jul 23 10:10:40 2014 -0700
Committer: Bill Farner <wfarner@apache.org>
Committed: Wed Jul 23 10:18:23 2014 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/SchedulerLifecycle.java    |  9 +--
 .../scheduler/storage/ForwardingStore.java      |  5 +-
 .../scheduler/storage/SchedulerStore.java       |  4 +-
 .../scheduler/storage/db/DbLockStore.java       |  2 +-
 .../aurora/scheduler/storage/db/DbModule.java   |  8 ++-
 .../scheduler/storage/db/DbSchedulerStore.java  | 44 ++++++++++++
 .../aurora/scheduler/storage/db/DbStorage.java  |  4 +-
 .../scheduler/storage/db/FrameworkIdMapper.java | 26 ++++++++
 .../scheduler/storage/db/MigrationModule.java   |  2 +
 .../storage/log/SnapshotStoreImpl.java          |  5 +-
 .../storage/mem/MemSchedulerStore.java          | 40 -----------
 .../scheduler/storage/mem/MemStorage.java       |  2 +-
 .../scheduler/storage/mem/MemStorageModule.java |  2 -
 .../scheduler/storage/db/FrameworkIdMapper.xml  | 32 +++++++++
 .../aurora/scheduler/storage/db/schema.sql      |  7 ++
 .../scheduler/SchedulerLifecycleTest.java       |  3 +-
 .../storage/db/DbSchedulerStoreTest.java        | 70 ++++++++++++++++++++
 .../storage/log/SnapshotStoreImplTest.java      |  3 +-
 18 files changed, 207 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/SchedulerLifecycle.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/SchedulerLifecycle.java b/src/main/java/org/apache/aurora/scheduler/SchedulerLifecycle.java
index b4139eb..a0704b4 100644
--- a/src/main/java/org/apache/aurora/scheduler/SchedulerLifecycle.java
+++ b/src/main/java/org/apache/aurora/scheduler/SchedulerLifecycle.java
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
 import javax.inject.Inject;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
@@ -251,17 +252,17 @@ public class SchedulerLifecycle implements EventSubscriber {
           }
         });
 
-        @Nullable final String frameworkId = storage.consistentRead(
-            new Work.Quiet<String>() {
+        final Optional<String> frameworkId = storage.consistentRead(
+            new Work.Quiet<Optional<String>>() {
               @Override
-              public String apply(StoreProvider storeProvider) {
+              public Optional<String> apply(StoreProvider storeProvider) {
                 return storeProvider.getSchedulerStore().fetchFrameworkId();
               }
             });
 
         // Save the prepared driver locally, but don't expose it until the registered callback
is
         // received.
-        driverRef.set(driverFactory.apply(frameworkId));
+        driverRef.set(driverFactory.apply(frameworkId.orNull()));
 
         delayedActions.onRegistrationTimeout(
             new Runnable() {

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/ForwardingStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/ForwardingStore.java b/src/main/java/org/apache/aurora/scheduler/storage/ForwardingStore.java
index 94f03f0..be8943d 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/ForwardingStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/ForwardingStore.java
@@ -16,8 +16,6 @@ package org.apache.aurora.scheduler.storage;
 import java.util.Map;
 import java.util.Set;
 
-import javax.annotation.Nullable;
-
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableSet;
 
@@ -78,8 +76,7 @@ public class ForwardingStore implements
   }
 
   @Override
-  @Nullable
-  public String fetchFrameworkId() {
+  public Optional<String> fetchFrameworkId() {
     return schedulerStore.fetchFrameworkId();
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/SchedulerStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/SchedulerStore.java b/src/main/java/org/apache/aurora/scheduler/storage/SchedulerStore.java
index 057a2e6..c822e20 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/SchedulerStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/SchedulerStore.java
@@ -13,7 +13,7 @@
  */
 package org.apache.aurora.scheduler.storage;
 
-import javax.annotation.Nullable;
+import com.google.common.base.Optional;
 
 /**
  * Stores data specific to the scheduler itself.
@@ -25,7 +25,7 @@ public interface SchedulerStore {
    *
    * @return the last saved framework id
    */
-  @Nullable String fetchFrameworkId();
+  Optional<String> fetchFrameworkId();
 
   interface Mutable extends SchedulerStore {
     /**

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/db/DbLockStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbLockStore.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbLockStore.java
index f5ed139..5d4da0a 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DbLockStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbLockStore.java
@@ -30,7 +30,7 @@ import org.apache.ibatis.exceptions.PersistenceException;
 import static java.util.Objects.requireNonNull;
 
 /**
- *  A relational database-backed lock store.
+ * A relational database-backed lock store.
  */
 class DbLockStore implements LockStore.Mutable {
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/db/DbModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbModule.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbModule.java
index 18925fd..4dbfd8a 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DbModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbModule.java
@@ -26,6 +26,7 @@ import com.twitter.common.inject.Bindings;
 import org.apache.aurora.scheduler.storage.AttributeStore;
 import org.apache.aurora.scheduler.storage.LockStore;
 import org.apache.aurora.scheduler.storage.QuotaStore;
+import org.apache.aurora.scheduler.storage.SchedulerStore;
 import org.apache.aurora.scheduler.storage.Storage;
 import org.apache.aurora.scheduler.storage.db.typehandlers.TypeHandlers;
 import org.apache.ibatis.session.AutoMappingBehavior;
@@ -48,8 +49,9 @@ import static com.google.inject.name.Names.named;
  *     <li>{@link org.apache.ibatis.session.SqlSessionFactory}</li>
  *     <li>Keys provided by the provided{@code keyFactory} for:
  *        <ul>
- *          <li>{@link org.apache.aurora.scheduler.storage.LockStore.Mutable}</li>
- *          <li>{@link org.apache.aurora.scheduler.storage.QuotaStore.Mutable}</li>
+ *          <li>{@link LockStore.Mutable}</li>
+ *          <li>{@link QuotaStore.Mutable}</li>
+ *          <li>{@link SchedulerStore.Mutable}</li>
  *        </ul>
  *     </li>
  *   </ul>
@@ -109,6 +111,7 @@ public class DbModule extends PrivateModule {
         addMapperClass(LockMapper.class);
         addMapperClass(JobKeyMapper.class);
         addMapperClass(QuotaMapper.class);
+        addMapperClass(FrameworkIdMapper.class);
         Properties props = new Properties();
         // We have no plans to take advantage of multiple DB environments. This is a required
         // property though, so we use an unnamed environment.
@@ -127,6 +130,7 @@ public class DbModule extends PrivateModule {
     bindStore(AttributeStore.Mutable.class, DbAttributeStore.class);
     bindStore(LockStore.Mutable.class, DbLockStore.class);
     bindStore(QuotaStore.Mutable.class, DbQuotaStore.class);
+    bindStore(SchedulerStore.Mutable.class, DbSchedulerStore.class);
 
     Key<Storage> storageKey = keyFactory.create(Storage.class);
     bind(storageKey).to(DbStorage.class);

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStore.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStore.java
new file mode 100644
index 0000000..fc7913e
--- /dev/null
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStore.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aurora.scheduler.storage.db;
+
+import java.util.Objects;
+
+import com.google.common.base.Optional;
+import com.google.inject.Inject;
+
+import org.apache.aurora.scheduler.storage.SchedulerStore;
+
+/**
+ * A relational database-backed scheduler store.
+ */
+class DbSchedulerStore implements SchedulerStore.Mutable {
+
+  private final FrameworkIdMapper mapper;
+
+  @Inject
+  DbSchedulerStore(FrameworkIdMapper mapper) {
+    this.mapper = Objects.requireNonNull(mapper);
+  }
+
+  @Override
+  public void saveFrameworkId(String frameworkId) {
+    mapper.insert(Objects.requireNonNull(frameworkId));
+  }
+
+  @Override
+  public Optional<String> fetchFrameworkId() {
+    return Optional.fromNullable(mapper.select());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/db/DbStorage.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbStorage.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbStorage.java
index d3764c3..0493c5f 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DbStorage.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbStorage.java
@@ -62,19 +62,21 @@ class DbStorage extends AbstractIdleService implements Storage {
   DbStorage(
       SqlSessionFactory sessionFactory,
       EnumValueMapper enumValueMapper,
+      final SchedulerStore.Mutable schedulerStore,
       final AttributeStore.Mutable attributeStore,
       final LockStore.Mutable lockStore,
       final QuotaStore.Mutable quotaStore) {
 
     this.sessionFactory = requireNonNull(sessionFactory);
     this.enumValueMapper = requireNonNull(enumValueMapper);
+    requireNonNull(schedulerStore);
     requireNonNull(attributeStore);
     requireNonNull(lockStore);
     requireNonNull(quotaStore);
     storeProvider = new MutableStoreProvider() {
       @Override
       public SchedulerStore.Mutable getSchedulerStore() {
-        throw new UnsupportedOperationException("Not yet implemented.");
+        return schedulerStore;
       }
 
       @Override

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.java b/src/main/java/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.java
new file mode 100644
index 0000000..240767c
--- /dev/null
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aurora.scheduler.storage.db;
+
+import javax.annotation.Nullable;
+
+/**
+ * MyBatis mapper class for FrameworkIdMapper.xml.
+ */
+interface FrameworkIdMapper {
+  @Nullable
+  String select();
+
+  void insert(String id);
+}

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/db/MigrationModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/MigrationModule.java b/src/main/java/org/apache/aurora/scheduler/storage/db/MigrationModule.java
index ace97e3..f327873 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/MigrationModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/MigrationModule.java
@@ -19,6 +19,7 @@ import com.twitter.common.inject.Bindings.KeyFactory;
 import org.apache.aurora.scheduler.storage.AttributeStore;
 import org.apache.aurora.scheduler.storage.LockStore;
 import org.apache.aurora.scheduler.storage.QuotaStore;
+import org.apache.aurora.scheduler.storage.SchedulerStore;
 
 import static java.util.Objects.requireNonNull;
 
@@ -52,5 +53,6 @@ public class MigrationModule extends AbstractModule {
     link(AttributeStore.Mutable.class);
     link(LockStore.Mutable.class);
     link(QuotaStore.Mutable.class);
+    link(SchedulerStore.Mutable.class);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java
b/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java
index 1757ee3..91bd706 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java
@@ -127,7 +127,7 @@ public class SnapshotStoreImpl implements SnapshotStore<Snapshot>
{
 
           snapshot.setSchedulerMetadata(
                 new SchedulerMetadata()
-                  .setFrameworkId(store.getSchedulerStore().fetchFrameworkId())
+                  .setFrameworkId(store.getSchedulerStore().fetchFrameworkId().orNull())
                   .setRevision(props.getProperty(BuildInfo.Key.GIT_REVISION.value))
                   .setTag(props.getProperty(BuildInfo.Key.GIT_TAG.value))
                   .setTimestamp(props.getProperty(BuildInfo.Key.TIMESTAMP.value))
@@ -138,7 +138,8 @@ public class SnapshotStoreImpl implements SnapshotStore<Snapshot>
{
 
         @Override
         public void restoreFromSnapshot(MutableStoreProvider store, Snapshot snapshot) {
-          if (snapshot.isSetSchedulerMetadata()) {
+          if (snapshot.isSetSchedulerMetadata()
+              && snapshot.getSchedulerMetadata().isSetFrameworkId()) {
             // No delete necessary here since this is a single value.
 
             store.getSchedulerStore()

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/mem/MemSchedulerStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/mem/MemSchedulerStore.java
b/src/main/java/org/apache/aurora/scheduler/storage/mem/MemSchedulerStore.java
deleted file mode 100644
index a78b395..0000000
--- a/src/main/java/org/apache/aurora/scheduler/storage/mem/MemSchedulerStore.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aurora.scheduler.storage.mem;
-
-import java.util.concurrent.atomic.AtomicReference;
-
-import javax.annotation.Nullable;
-
-import com.google.common.util.concurrent.Atomics;
-
-import org.apache.aurora.scheduler.storage.SchedulerStore;
-
-/**
- * An in-memory scheduler store.
- */
-class MemSchedulerStore implements SchedulerStore.Mutable {
-  private final AtomicReference<String> frameworkId = Atomics.newReference();
-
-  @Override
-  public void saveFrameworkId(String newFrameworkId) {
-    frameworkId.set(newFrameworkId);
-  }
-
-  @Nullable
-  @Override
-  public String fetchFrameworkId() {
-    return frameworkId.get();
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/mem/MemStorage.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/mem/MemStorage.java b/src/main/java/org/apache/aurora/scheduler/storage/mem/MemStorage.java
index 1e082ac..0590ea1 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/mem/MemStorage.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/mem/MemStorage.java
@@ -80,7 +80,7 @@ public class MemStorage implements Storage {
 
   @Inject
   MemStorage(
-      final SchedulerStore.Mutable schedulerStore,
+      @Delegated final SchedulerStore.Mutable schedulerStore,
       final JobStore.Mutable jobStore,
       final TaskStore.Mutable taskStore,
       @Delegated final LockStore.Mutable lockStore,

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/java/org/apache/aurora/scheduler/storage/mem/MemStorageModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/mem/MemStorageModule.java b/src/main/java/org/apache/aurora/scheduler/storage/mem/MemStorageModule.java
index 4c9d69c..31c25d0 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/mem/MemStorageModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/mem/MemStorageModule.java
@@ -20,7 +20,6 @@ import com.google.inject.PrivateModule;
 import com.twitter.common.inject.Bindings.KeyFactory;
 
 import org.apache.aurora.scheduler.storage.JobStore;
-import org.apache.aurora.scheduler.storage.SchedulerStore;
 import org.apache.aurora.scheduler.storage.Storage;
 import org.apache.aurora.scheduler.storage.Storage.Volatile;
 import org.apache.aurora.scheduler.storage.TaskStore;
@@ -70,7 +69,6 @@ public final class MemStorageModule extends PrivateModule {
     expose(exposedMemStorageKey);
     bind(MemStorage.class).in(Singleton.class);
 
-    bindStore(SchedulerStore.Mutable.class, MemSchedulerStore.class);
     bindStore(JobStore.Mutable.class, MemJobStore.class);
     bindStore(TaskStore.Mutable.class, MemTaskStore.class);
   }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/resources/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.xml
b/src/main/resources/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.xml
new file mode 100644
index 0000000..74568ab
--- /dev/null
+++ b/src/main/resources/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<!DOCTYPE mapper
+    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.apache.aurora.scheduler.storage.db.FrameworkIdMapper">
+  <insert id="insert">
+    MERGE INTO framework_id (
+      id,
+      framework_id
+    ) KEY(id) VALUES (
+      1,
+      #{id}
+    )
+  </insert>
+
+  <select id="select" resultType="String">
+    SELECT framework_id FROM framework_id
+  </select>
+</mapper>

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql b/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql
index 0bb6cd2..5358b45 100644
--- a/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql
+++ b/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql
@@ -14,6 +14,13 @@
 
 -- schema for h2 engine.
 
+CREATE TABLE framework_id(
+  id INT PRIMARY KEY,
+  framework_id VARCHAR NOT NULL,
+
+  UNIQUE(framework_id)
+);
+
 CREATE TABLE job_keys(
   id INT IDENTITY,
   role VARCHAR NOT NULL,

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/test/java/org/apache/aurora/scheduler/SchedulerLifecycleTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/SchedulerLifecycleTest.java b/src/test/java/org/apache/aurora/scheduler/SchedulerLifecycleTest.java
index 57095ce..90c8c06 100644
--- a/src/test/java/org/apache/aurora/scheduler/SchedulerLifecycleTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/SchedulerLifecycleTest.java
@@ -15,6 +15,7 @@ package org.apache.aurora.scheduler;
 
 import java.lang.Thread.UncaughtExceptionHandler;
 
+import com.google.common.base.Optional;
 import com.twitter.common.application.Lifecycle;
 import com.twitter.common.application.ShutdownRegistry;
 import com.twitter.common.base.Command;
@@ -104,7 +105,7 @@ public class SchedulerLifecycleTest extends EasyMockTest {
   private void expectLoadStorage() {
     storageUtil.storage.start(EasyMock.<Quiet>anyObject());
     storageUtil.expectOperations();
-    expect(storageUtil.schedulerStore.fetchFrameworkId()).andReturn(FRAMEWORK_ID);
+    expect(storageUtil.schedulerStore.fetchFrameworkId()).andReturn(Optional.of(FRAMEWORK_ID));
   }
 
   private void expectInitializeDriver() {

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/test/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStoreTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStoreTest.java
new file mode 100644
index 0000000..219605e
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/storage/db/DbSchedulerStoreTest.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aurora.scheduler.storage.db;
+
+import java.io.IOException;
+
+import com.google.common.base.Optional;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.twitter.common.inject.Bindings;
+
+import org.apache.aurora.scheduler.storage.Storage;
+import org.apache.aurora.scheduler.storage.Storage.MutableStoreProvider;
+import org.apache.aurora.scheduler.storage.Storage.MutateWork;
+import org.apache.aurora.scheduler.storage.Storage.StoreProvider;
+import org.apache.aurora.scheduler.storage.Storage.Work;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class DbSchedulerStoreTest {
+
+  private Storage storage;
+
+  @Before
+  public void setUp() throws IOException {
+    Injector injector = Guice.createInjector(new DbModule(Bindings.KeyFactory.PLAIN));
+    storage = injector.getInstance(Storage.class);
+    storage.prepare();
+  }
+
+  @Test
+  public void testSchedulerStore() {
+    assertEquals(Optional.<String>absent(), select());
+    save("a");
+    assertEquals(Optional.of("a"), select());
+    save("b");
+    assertEquals(Optional.of("b"), select());
+  }
+
+  private void save(final String id) {
+    storage.write(new MutateWork.NoResult.Quiet() {
+      @Override
+      public void execute(MutableStoreProvider storeProvider) {
+        storeProvider.getSchedulerStore().saveFrameworkId(id);
+      }
+    });
+  }
+
+  private Optional<String> select() {
+    return storage.consistentRead(new Work.Quiet<Optional<String>>() {
+      @Override
+      public Optional<String> apply(StoreProvider storeProvider) {
+        return storeProvider.getSchedulerStore().fetchFrameworkId();
+      }
+    });
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/27378345/src/test/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImplTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImplTest.java
index 22a4048..1564047 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImplTest.java
@@ -15,6 +15,7 @@ package org.apache.aurora.scheduler.storage.log;
 
 import java.util.Set;
 
+import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.twitter.common.testing.easymock.EasyMockTest;
@@ -93,7 +94,7 @@ public class SnapshotStoreImplTest extends EasyMockTest {
     expect(storageUtil.jobStore.fetchManagerIds()).andReturn(ImmutableSet.of("jobManager"));
     expect(storageUtil.jobStore.fetchJobs("jobManager"))
         .andReturn(ImmutableSet.of(IJobConfiguration.build(job.getJobConfiguration())));
-    expect(storageUtil.schedulerStore.fetchFrameworkId()).andReturn(frameworkId);
+    expect(storageUtil.schedulerStore.fetchFrameworkId()).andReturn(Optional.of(frameworkId));
     expect(storageUtil.lockStore.fetchLocks()).andReturn(ImmutableSet.of(lock));
 
     expectDataWipe();


Mime
View raw message