You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/01/04 19:30:37 UTC

[GitHub] rabbah closed pull request #3140: use pureconfig to specify names of db designdocs

rabbah closed pull request #3140: use pureconfig to specify names of db designdocs
URL: https://github.com/apache/incubator-openwhisk/pull/3140
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ansible/group_vars/all b/ansible/group_vars/all
index 5cde947173..dcf2d8a6cf 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 319e695ce9..ca1aa2a41d 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 9e07a15df5..3da0b30ef2 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 925c246eec..24dc70e551 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 dc2d4b1708..8af1d3d3d2 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 67a98f1e59..e42003e8cb 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 95e890a9e6..d619c57a8c 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 3bd6367bc3..fbb2b26eeb 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)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services