aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject aurora git commit: Model DockerParameter in the database.
Date Thu, 23 Jul 2015 20:03:12 GMT
Repository: aurora
Updated Branches:
  refs/heads/master eee70d638 -> 24088ef2e


Model DockerParameter in the database.

Bugs closed: AURORA-1407

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


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

Branch: refs/heads/master
Commit: 24088ef2e7e0f1ee972c87a52621bad29f777c16
Parents: eee70d6
Author: Bill Farner <wfarner@apache.org>
Authored: Thu Jul 23 12:53:38 2015 -0700
Committer: Bill Farner <wfarner@apache.org>
Committed: Thu Jul 23 12:53:38 2015 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/base/TaskTestUtil.java     |  9 +++-
 .../scheduler/storage/db/TaskConfigManager.java |  8 +++-
 .../scheduler/storage/db/TaskConfigMapper.java  | 22 +++++----
 .../scheduler/storage/db/TaskConfigMapper.xml   | 47 ++++++++++++++------
 .../aurora/scheduler/storage/db/schema.sql      |  7 +++
 .../storage/testing/StorageEntityUtil.java      |  8 ++++
 6 files changed, 76 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/24088ef2/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java b/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
index c16aa4c..1903315 100644
--- a/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
+++ b/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
@@ -21,6 +21,7 @@ import org.apache.aurora.gen.AssignedTask;
 import org.apache.aurora.gen.Constraint;
 import org.apache.aurora.gen.Container;
 import org.apache.aurora.gen.DockerContainer;
+import org.apache.aurora.gen.DockerParameter;
 import org.apache.aurora.gen.ExecutorConfig;
 import org.apache.aurora.gen.Identity;
 import org.apache.aurora.gen.LimitConstraint;
@@ -66,7 +67,7 @@ public final class TaskTestUtil {
             new Constraint(
                 "valueConstraint",
                 TaskConstraint.value(
-                    new ValueConstraint(false, ImmutableSet.of("value1", "value2")))),
+                    new ValueConstraint(true, ImmutableSet.of("value1", "value2")))),
             new Constraint(
                 "limitConstraint",
                 TaskConstraint.limit(new LimitConstraint(5)))))
@@ -75,7 +76,11 @@ public final class TaskTestUtil {
         .setContactEmail("foo@bar.com")
         .setMetadata(ImmutableSet.of(new Metadata("key", "value")))
         .setExecutorConfig(new ExecutorConfig("name", "config"))
-        .setContainer(Container.docker(new DockerContainer("imagename"))));
+        .setContainer(Container.docker(
+            new DockerContainer("imagename")
+                .setParameters(ImmutableList.of(
+                    new DockerParameter("a", "b"),
+                    new DockerParameter("c", "d"))))));
   }
 
   public static IScheduledTask makeTask(String id, IJobKey job) {

http://git-wip-us.apache.org/repos/asf/aurora/blob/24088ef2/src/main/java/org/apache/aurora/scheduler/storage/db/TaskConfigManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/TaskConfigManager.java b/src/main/java/org/apache/aurora/scheduler/storage/db/TaskConfigManager.java
index 30a258a..27f1f33 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/TaskConfigManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/TaskConfigManager.java
@@ -23,6 +23,7 @@ import com.google.common.collect.Maps;
 import org.apache.aurora.scheduler.storage.db.views.DbTaskConfig;
 import org.apache.aurora.scheduler.storage.db.views.Pairs;
 import org.apache.aurora.scheduler.storage.entities.IConstraint;
+import org.apache.aurora.scheduler.storage.entities.IDockerContainer;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
 import org.apache.aurora.scheduler.storage.entities.IValueConstraint;
 
@@ -104,7 +105,12 @@ class TaskConfigManager {
 
     // TODO(wfarner): It would be nice if this generalized to different Container types.
     if (config.getContainer().isSetDocker()) {
-      configMapper.insertContainer(configInsert.getId(), config.getContainer().getDocker());
+      IDockerContainer container = config.getContainer().getDocker();
+      InsertResult containerInsert = new InsertResult();
+      configMapper.insertContainer(configInsert.getId(), container, containerInsert);
+      if (!container.getParameters().isEmpty()) {
+        configMapper.insertDockerParameters(containerInsert.getId(), container.getParameters());
+      }
     }
 
     return configInsert.getId();

http://git-wip-us.apache.org/repos/asf/aurora/blob/24088ef2/src/main/java/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.java b/src/main/java/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.java
index 48f1904..afb66c5 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.java
@@ -21,6 +21,7 @@ import com.twitter.common.collections.Pair;
 import org.apache.aurora.scheduler.storage.db.views.DbTaskConfig;
 import org.apache.aurora.scheduler.storage.entities.IConstraint;
 import org.apache.aurora.scheduler.storage.entities.IDockerContainer;
+import org.apache.aurora.scheduler.storage.entities.IDockerParameter;
 import org.apache.aurora.scheduler.storage.entities.IJobKey;
 import org.apache.aurora.scheduler.storage.entities.ILimitConstraint;
 import org.apache.aurora.scheduler.storage.entities.IMetadata;
@@ -52,14 +53,6 @@ interface TaskConfigMapper extends GarbageCollectedTableMapper {
   List<DbTaskConfig> selectConfigsByJob(IJobKey job);
 
   /**
-   * Looks up task config IDs by task IDs.
-   *
-   * @param taskIds Task IDs to look up.
-   * @return Task config row IDs.
-   */
-  Set<Long> selectConfigsByTaskId(@Param("taskIds") Set<String> taskIds);
-
-  /**
    * Inserts the constraint association within an {@link ITaskConfig}.
    *
    * @param configId Task config ID.
@@ -131,7 +124,18 @@ interface TaskConfigMapper extends GarbageCollectedTableMapper {
    */
   void insertContainer(
       @Param("configId") long configId,
-      @Param("container") IDockerContainer container);
+      @Param("container") IDockerContainer container,
+      @Param("result") InsertResult result);
+
+  /**
+   * Inserts docker parameters in associationw ith an {@link IDockerContainer}.
+   *
+   * @param containerId Docker container row ID.
+   * @param parameters Parameters to insert.
+   */
+  void insertDockerParameters(
+      @Param("containerId") long containerId,
+      @Param("parameters") List<IDockerParameter> parameters);
 
   /**
    * Inserts the metadata association within an {@link ITaskConfig}.

http://git-wip-us.apache.org/repos/asf/aurora/blob/24088ef2/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.xml
b/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.xml
index bbd6713..bfad339 100644
--- a/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.xml
+++ b/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.xml
@@ -93,8 +93,27 @@
     WHERE tc.task_config_id = #{id}
   </select>
 
+  <resultMap id="dockerParameterMap" type="org.apache.aurora.gen.DockerParameter">
+    <id column="id"/>
+  </resultMap>
+
+  <select id="selectDockerParameters" resultMap="dockerParameterMap">
+    SELECT
+      id,
+      name,
+      value
+    FROM task_config_docker_container_parameters
+    WHERE container_id = #{id}
+  </select>
+
   <resultMap id="dockerContainerMap" type="org.apache.aurora.gen.DockerContainer">
+    <id column="id"/>
     <result column="image" property="image"/>
+    <collection
+        property="parameters"
+        select="selectDockerParameters"
+        column="id"
+        foreignColumn="container_id"/>
   </resultMap>
 
   <resultMap id="containerMap" type="org.apache.aurora.scheduler.storage.db.views.DbContainer">
@@ -176,18 +195,6 @@
       AND j.name = #{name}
   </select>
 
-  <select id="selectConfigsByTaskId" resultType="long">
-    SELECT
-      c.id AS id
-    FROM task_configs AS c
-    INNER JOIN tasks AS t ON t.task_config_row_id = c.id
-    WHERE t.task_id IN (
-      <foreach item="taskId" collection="taskIds" separator=",">
-        #{taskId}
-      </foreach>
-    )
-  </select>
-
   <insert id="insertConstraint" useGeneratedKeys="true" keyColumn="id" keyProperty="result.id">
     INSERT INTO task_constraints (
       task_config_id,
@@ -272,7 +279,7 @@
     WHERE task_config_id = #{id}
   </select>
 
-  <insert id="insertContainer">
+  <insert id="insertContainer" useGeneratedKeys="true" keyColumn="id" keyProperty="result.id">
     INSERT INTO task_config_docker_containers (
       task_config_id,
       image
@@ -282,6 +289,20 @@
     )
   </insert>
 
+  <insert id="insertDockerParameters">
+    INSERT INTO task_config_docker_container_parameters (
+      container_id,
+      name,
+      value
+    ) VALUES (
+    <foreach item="parameter" collection="parameters" separator="),(">
+      #{containerId},
+      #{parameter.name},
+      #{parameter.value}
+    </foreach>
+    )
+  </insert>
+
   <insert id="insertMetadata">
     INSERT INTO task_config_metadata (
       task_config_id,

http://git-wip-us.apache.org/repos/asf/aurora/blob/24088ef2/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 52494af..7634047 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
@@ -254,6 +254,13 @@ CREATE TABLE task_config_docker_containers(
   UNIQUE(task_config_id)
 );
 
+CREATE TABLE task_config_docker_container_parameters(
+  id IDENTITY,
+  container_id INT NOT NULL REFERENCES task_config_docker_containers(id) ON DELETE CASCADE,
+  name VARCHAR NOT NULL,
+  value VARCHAR NOT NULL
+);
+
 CREATE TABLE task_states(
   id INT PRIMARY KEY,
   name VARCHAR NOT NULL,

http://git-wip-us.apache.org/repos/asf/aurora/blob/24088ef2/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageEntityUtil.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageEntityUtil.java
b/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageEntityUtil.java
index 0bde4d8..5e054a7 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageEntityUtil.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageEntityUtil.java
@@ -24,6 +24,8 @@ import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableSet;
 import com.google.gson.internal.Primitives;
 
+import org.apache.thrift.TUnion;
+
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
@@ -51,6 +53,12 @@ public final class StorageEntityUtil {
         assertFullyPopulated(name + " key", entry.getKey(), ignoredFields);
         assertFullyPopulated(name + "[" + entry.getKey() + "]", entry.getValue(), ignoredFields);
       }
+    } else if (object instanceof TUnion) {
+      TUnion<?, ?> union = (TUnion<?, ?>) object;
+      assertFullyPopulated(
+          name + "." + union.getSetField().getFieldName(),
+          union.getFieldValue(),
+          ignoredFields);
     } else if (!(object instanceof String) && !(object instanceof Enum)) {
       for (Field field : object.getClass().getDeclaredFields()) {
         if (!Modifier.isStatic(field.getModifiers())) {


Mime
View raw message