openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rab...@apache.org
Subject [incubator-openwhisk] branch master updated: use pureconfig to specify names of db designdocs (#3140)
Date Thu, 04 Jan 2018 19:30:36 GMT
This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new ec9988a  use pureconfig to specify names of db designdocs (#3140)
ec9988a is described below

commit ec9988a7bf9e50201a34176f0a7c245dfa3956aa
Author: David Grove <dgrove-oss@users.noreply.github.com>
AuthorDate: Thu Jan 4 14:30:33 2018 -0500

    use pureconfig to specify names of db designdocs (#3140)
    
    Specify db design document names in application.conf
    and support overrides via pureconfig conventions.
---
 ansible/group_vars/all                                |  3 ---
 ansible/roles/controller/tasks/deploy.yml             |  6 +++---
 ansible/roles/invoker/tasks/deploy.yml                |  6 +++---
 ansible/templates/whisk.properties.j2                 |  3 ---
 common/scala/src/main/resources/application.conf      |  6 ++++++
 .../scala/src/main/scala/whisk/core/WhiskConfig.scala |  3 ---
 .../scala/whisk/core/entity/WhiskActivation.scala     | 14 +++++---------
 .../src/main/scala/whisk/core/entity/WhiskStore.scala | 19 ++++++-------------
 8 files changed, 23 insertions(+), 37 deletions(-)

diff --git a/ansible/group_vars/all b/ansible/group_vars/all
index 5cde947..dcf2d8a 100644
--- a/ansible/group_vars/all
+++ b/ansible/group_vars/all
@@ -209,10 +209,7 @@ db:
   - whisk.system
   whisk:
     actions: "{{ db_prefix }}whisks"
-    actions_ddoc: "whisks.v2"
     activations: "{{ db_prefix }}activations"
-    activations_ddoc: "whisks.v2"
-    activations_filter_ddoc: "whisks-filters.v2"
     auth: "{{ db_prefix }}subjects"
 
 apigateway:
diff --git a/ansible/roles/controller/tasks/deploy.yml b/ansible/roles/controller/tasks/deploy.yml
index 319e695..ca1aa2a 100644
--- a/ansible/roles/controller/tasks/deploy.yml
+++ b/ansible/roles/controller/tasks/deploy.yml
@@ -72,9 +72,9 @@
       "DB_WHISK_AUTHS": "{{ db.whisk.auth }}"
       "DB_WHISK_ACTIONS": "{{ db.whisk.actions }}"
       "DB_WHISK_ACTIVATIONS": "{{ db.whisk.activations }}"
-      "DB_WHISK_ACTIONS_DDOC": "{{ db.whisk.actions_ddoc }}"
-      "DB_WHISK_ACTIVATIONS_DDOC": "{{ db.whisk.activations_ddoc }}"
-      "DB_WHISK_ACTIVATIONS_FILTER_DDOC": "{{ db.whisk.activations_filter_ddoc }}"
+      "CONFIG_whisk_db_actionsDdoc": "{{ db_whisk_actions_ddoc | default() }}"
+      "CONFIG_whisk_db_activationsDdoc": "{{ db_whisk_activations_ddoc | default() }}"
+      "CONFIG_whisk_db_activationsFilterDdoc": "{{ db_whisk_activations_filter_ddoc | default()
}}"
 
       "LIMITS_ACTIONS_INVOKES_PERMINUTE": "{{ limits.invocationsPerMinute }}"
       "LIMITS_ACTIONS_INVOKES_CONCURRENT": "{{ limits.concurrentInvocations }}"
diff --git a/ansible/roles/invoker/tasks/deploy.yml b/ansible/roles/invoker/tasks/deploy.yml
index 9e07a15..3da0b30 100644
--- a/ansible/roles/invoker/tasks/deploy.yml
+++ b/ansible/roles/invoker/tasks/deploy.yml
@@ -131,9 +131,9 @@
         -e DB_PASSWORD='{{ db_password }}'
         -e DB_WHISK_ACTIONS='{{ db.whisk.actions }}'
         -e DB_WHISK_ACTIVATIONS='{{ db.whisk.activations }}'
-        -e DB_WHISK_ACTIONS_DDOC='{{ db.whisk.actions_ddoc }}'
-        -e DB_WHISK_ACTIVATIONS_DDOC='{{ db.whisk.activations_ddoc }}'
-        -e DB_WHISK_ACTIVATIONS_FILTER_DDOC='{{ db.whisk.activations_filter_ddoc }}'
+        -e CONFIG_whisk_db_actionsDdoc='{{ db_whisk_actions_ddoc | default() }}'
+        -e CONFIG_whisk_db_activationsDdoc='{{ db_whisk_activations_ddoc | default() }}'
+        -e CONFIG_whisk_db_activationsFilterDdoc='{{ db_whisk_activations_filter_ddoc | default()
}}'
         -e WHISK_API_HOST_PROTO='{{ whisk_api_host_proto | default('https') }}'
         -e WHISK_API_HOST_PORT='{{ whisk_api_host_port | default('443') }}'
         -e WHISK_API_HOST_NAME='{{ whisk_api_host_name | default(groups['edge'] | first)
}}'
diff --git a/ansible/templates/whisk.properties.j2 b/ansible/templates/whisk.properties.j2
index 925c246..24dc70e 100644
--- a/ansible/templates/whisk.properties.j2
+++ b/ansible/templates/whisk.properties.j2
@@ -89,9 +89,6 @@ db.prefix={{ db_prefix }}
 db.whisk.auths={{ db.whisk.auth }}
 db.whisk.actions={{ db.whisk.actions }}
 db.whisk.activations={{ db.whisk.activations }}
-db.whisk.actions.ddoc={{ db.whisk.actions_ddoc }}
-db.whisk.activations.ddoc={{ db.whisk.activations_ddoc }}
-db.whisk.activations.filter.ddoc={{ db.whisk.activations_filter_ddoc }}
 db.hostsList={{ groups["db"] | map('extract', hostvars, 'ansible_host') | list | join(",")
}}
 db.instances={{ db.instances }}
 
diff --git a/common/scala/src/main/resources/application.conf b/common/scala/src/main/resources/application.conf
index dc2d4b1..8af1d3d 100644
--- a/common/scala/src/main/resources/application.conf
+++ b/common/scala/src/main/resources/application.conf
@@ -76,4 +76,10 @@ whisk {
             }
         }
     }
+    # db related configuration
+    db {
+        actions-ddoc = "whisks.v2"
+        activations-ddoc = "whisks.v2"
+        activations-filter-ddoc = "whisks-filters.v2"
+    }
 }
diff --git a/common/scala/src/main/scala/whisk/core/WhiskConfig.scala b/common/scala/src/main/scala/whisk/core/WhiskConfig.scala
index 67a98f1..e42003e 100644
--- a/common/scala/src/main/scala/whisk/core/WhiskConfig.scala
+++ b/common/scala/src/main/scala/whisk/core/WhiskConfig.scala
@@ -178,9 +178,6 @@ object WhiskConfig {
   val dbAuths = "db.whisk.auths"
   val dbWhisk = "db.whisk.actions"
   val dbActivations = "db.whisk.activations"
-  val dbWhiskDesignDoc = "db.whisk.actions.ddoc"
-  val dbActivationsDesignDoc = "db.whisk.activations.ddoc"
-  val dbActivationsFilterDesignDoc = "db.whisk.activations.filter.ddoc"
 
   // these are not private because they are needed
   // in the invoker (they are part of the environment
diff --git a/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala b/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala
index 95e890a..d619c57 100644
--- a/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala
+++ b/common/scala/src/main/scala/whisk/core/entity/WhiskActivation.scala
@@ -28,8 +28,8 @@ import whisk.common.TransactionId
 import whisk.core.database.ArtifactStore
 import whisk.core.database.DocumentFactory
 import whisk.core.database.StaleParameter
-import whisk.core.WhiskConfig
-import whisk.core.WhiskConfig.{dbActivationsDesignDoc, dbActivationsFilterDesignDoc}
+
+import pureconfig._
 
 /**
  * A WhiskActivation provides an abstraction of the meta-data
@@ -147,13 +147,9 @@ object WhiskActivation
 
   override val collectionName = "activations"
 
-  // FIXME: reading the design doc from sys.env instead of a canonical property reader
-  // because WhiskConfig requires a logger, which requires an actor system, neither of
-  // which are readily available here; rather than introduce significant refactoring,
-  // defer this fix until WhiskConfig is refactored itself, which is planned to introduce
-  // type safe properties
-  private val mainDdoc = WhiskConfig.readFromEnv(dbActivationsDesignDoc).getOrElse("whisks.v2")
-  private val filtersDdoc = WhiskConfig.readFromEnv(dbActivationsFilterDesignDoc).getOrElse("whisks-filters.v2")
+  private val dbConfig = loadConfigOrThrow[DBConfig]("whisk.db")
+  private val mainDdoc = dbConfig.activationsDdoc
+  private val filtersDdoc = dbConfig.activationsFilterDdoc
 
   /** The main view for activations, keyed by namespace, sorted by date. */
   override lazy val view = WhiskEntityQueries.view(mainDdoc, collectionName)
diff --git a/common/scala/src/main/scala/whisk/core/entity/WhiskStore.scala b/common/scala/src/main/scala/whisk/core/entity/WhiskStore.scala
index 3bd6367..fbb2b26 100644
--- a/common/scala/src/main/scala/whisk/core/entity/WhiskStore.scala
+++ b/common/scala/src/main/scala/whisk/core/entity/WhiskStore.scala
@@ -39,14 +39,13 @@ import whisk.core.WhiskConfig.dbProtocol
 import whisk.core.WhiskConfig.dbProvider
 import whisk.core.WhiskConfig.dbUsername
 import whisk.core.WhiskConfig.dbWhisk
-import whisk.core.WhiskConfig.dbWhiskDesignDoc
-import whisk.core.WhiskConfig.{dbActivationsDesignDoc, dbActivationsFilterDesignDoc}
 import whisk.core.database.ArtifactStore
 import whisk.core.database.ArtifactStoreProvider
 import whisk.core.database.DocumentRevisionProvider
 import whisk.core.database.DocumentSerializer
 import whisk.core.database.StaleParameter
 import whisk.spi.SpiLoader
+import pureconfig._
 
 package object types {
   type AuthStore = ArtifactStore[WhiskAuth]
@@ -54,6 +53,8 @@ package object types {
   type ActivationStore = ArtifactStore[WhiskActivation]
 }
 
+case class DBConfig(actionsDdoc: String, activationsDdoc: String, activationsFilterDdoc:
String)
+
 protected[core] trait WhiskDocument extends DocumentSerializer with DocumentRevisionProvider
{
 
   /**
@@ -114,8 +115,7 @@ object WhiskEntityStore {
       dbPassword -> null,
       dbHost -> null,
       dbPort -> null,
-      dbWhisk -> null,
-      dbWhiskDesignDoc -> null)
+      dbWhisk -> null)
 
   def datastore(config: WhiskConfig)(implicit system: ActorSystem, logging: Logging, materializer:
ActorMaterializer) =
     SpiLoader
@@ -138,9 +138,7 @@ object WhiskActivationStore {
       dbPassword -> null,
       dbHost -> null,
       dbPort -> null,
-      dbActivations -> null,
-      dbActivationsDesignDoc -> null,
-      dbActivationsFilterDesignDoc -> null)
+      dbActivations -> null)
 
   def datastore(config: WhiskConfig)(implicit system: ActorSystem, logging: Logging, materializer:
ActorMaterializer) =
     SpiLoader.get[ArtifactStoreProvider].makeStore[WhiskActivation](config, _.dbActivations,
true)
@@ -194,12 +192,7 @@ object WhiskEntityQueries {
   val TOP = "\ufff0"
 
   /** The design document to use for queries. */
-  // FIXME: reading the design doc from sys.env instead of a canonical property reader
-  // because WhiskConfig requires a logger, which requires an actor system, neither of
-  // which are readily available here; rather than introduce significant refactoring,
-  // defer this fix until WhiskConfig is refactored itself, which is planned to introduce
-  // type safe properties
-  val designDoc = WhiskConfig.readFromEnv(dbWhiskDesignDoc).getOrElse("whisks.v2")
+  val designDoc = loadConfigOrThrow[DBConfig]("whisk.db").actionsDdoc
 
   /** The view name for the collection, within the design document. */
   def view(ddoc: String = designDoc, collection: String) = new View(ddoc, collection)

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].

Mime
View raw message