openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vvras...@apache.org
Subject [incubator-openwhisk] branch master updated: Refactor invoker command line parsing. (#3894)
Date Tue, 31 Jul 2018 11:56:05 GMT
This is an automated email from the ASF dual-hosted git repository.

vvraskin 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 b197332  Refactor invoker command line parsing. (#3894)
b197332 is described below

commit b197332e041968e98f6cec996e4a136116a90569
Author: Markus Thömmes <markusthoemmes@me.com>
AuthorDate: Tue Jul 31 13:56:01 2018 +0200

    Refactor invoker command line parsing. (#3894)
    
    * Light refactorings.
    
    * Simplify command line parsing and different options.
    
    * Always pass the invokername in.
    
    * Restore old behavior.
---
 ansible/roles/invoker/tasks/deploy.yml             |  3 +-
 .../src/main/scala/whisk/core/WhiskConfig.scala    |  4 --
 .../main/scala/whisk/core/invoker/Invoker.scala    | 49 ++++++++++++----------
 3 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/ansible/roles/invoker/tasks/deploy.yml b/ansible/roles/invoker/tasks/deploy.yml
index 0a1e793..8e49ab3 100644
--- a/ansible/roles/invoker/tasks/deploy.yml
+++ b/ansible/roles/invoker/tasks/deploy.yml
@@ -208,7 +208,6 @@
       "CONFIG_whisk_containerPool_numCore": "{{ invoker.numcore }}"
       "CONFIG_whisk_containerPool_coreShare": "{{ invoker.coreshare }}"
       "CONFIG_whisk_docker_containerFactory_useRunc": "{{ invoker.useRunc }}"
-      "INVOKER_NAME": "{{ invoker_index }}"
       "WHISK_LOGS_DIR": "{{ whisk_logs_dir }}"
       "METRICS_KAMON": "{{ metrics.kamon.enabled }}"
       "METRICS_KAMON_TAGS": "{{ metrics.kamon.tags }}"
@@ -287,7 +286,7 @@
     env: "{{ env }}"
     volumes: "{{ volumes }}"
     ports: "{{ ports_to_expose }}"
-    command: /bin/sh -c "exec /init.sh {{ invoker_index }} >> /logs/{{ invoker_name
}}_logs.log 2>&1"
+    command: /bin/sh -c "exec /init.sh --id {{ invoker_index }} --uniqueName {{ invoker_index
}} >> /logs/{{ invoker_name }}_logs.log 2>&1"
 
 - name: wait until Invoker is up and running
   uri:
diff --git a/common/scala/src/main/scala/whisk/core/WhiskConfig.scala b/common/scala/src/main/scala/whisk/core/WhiskConfig.scala
index 4646dc2..7fdb10b 100644
--- a/common/scala/src/main/scala/whisk/core/WhiskConfig.scala
+++ b/common/scala/src/main/scala/whisk/core/WhiskConfig.scala
@@ -54,8 +54,6 @@ class WhiskConfig(requiredProperties: Map[String, String],
   val dockerEndpoint = this(WhiskConfig.dockerEndpoint)
   val dockerPort = this(WhiskConfig.dockerPort)
 
-  val invokerName = this(WhiskConfig.invokerName)
-
   val wskApiHost = this(WhiskConfig.wskApiProtocol) + "://" + this(WhiskConfig.wskApiHostname)
+ ":" + this(
     WhiskConfig.wskApiPort)
   val controllerBlackboxFraction = this.getAsDouble(WhiskConfig.controllerBlackboxFraction,
0.10)
@@ -154,8 +152,6 @@ object WhiskConfig {
   // passed to the user container)
   val edgeHostName = "edge.host"
 
-  val invokerName = "invoker.name"
-
   val wskApiProtocol = "whisk.api.host.proto"
   val wskApiPort = "whisk.api.host.port"
   val wskApiHostname = "whisk.api.host.name"
diff --git a/core/invoker/src/main/scala/whisk/core/invoker/Invoker.scala b/core/invoker/src/main/scala/whisk/core/invoker/Invoker.scala
index 0887727..572d04e 100644
--- a/core/invoker/src/main/scala/whisk/core/invoker/Invoker.scala
+++ b/core/invoker/src/main/scala/whisk/core/invoker/Invoker.scala
@@ -43,7 +43,7 @@ object Invoker {
    * An object which records the environment variables required for this component to run.
    */
   def requiredProperties =
-    Map(servicePort -> 8080.toString, invokerName -> "", runtimesRegistry -> "")
++
+    Map(servicePort -> 8080.toString, runtimesRegistry -> "") ++
       ExecManifest.requiredProperties ++
       kafkaHosts ++
       zookeeperHosts ++
@@ -91,49 +91,54 @@ object Invoker {
       abort("Bad configuration, cannot start.")
     }
 
+    /** Returns Some(s) if the string is not empty with trimmed whitespace, None otherwise.
*/
+    def nonEmptyString(s: String): Option[String] = {
+      val trimmed = s.trim
+      if (trimmed.nonEmpty) Some(trimmed) else None
+    }
+
     // process command line arguments
     // We accept the command line grammar of:
     // Usage: invoker [options] [<proposedInvokerId>]
     //    --uniqueName <value>   a unique name to dynamically assign Kafka topics from
Zookeeper
     //    --displayedName <value> a name to identify this invoker via invoker health
protocol
     //    --id <value>     proposed invokerId
-
     def parse(ls: List[String], c: CmdLineArgs): CmdLineArgs = {
       ls match {
-        case "--uniqueName" :: uniqueName :: tail            => parse(tail, c.copy(uniqueName
= Some(uniqueName)))
-        case "--displayedName" :: displayedName :: tail      => parse(tail, c.copy(displayedName
= Some(displayedName)))
-        case "--id" :: id :: tail if Try(id.toInt).isSuccess => parse(tail, c.copy(id
= Some(id.toInt)))
-        case id :: Nil if Try(id.toInt).isSuccess            => c.copy(id = Some(id.toInt))
-        case Nil                                             => c
-        case _                                               => abort(s"Error processing
command line arguments $ls")
+        case "--uniqueName" :: uniqueName :: tail =>
+          parse(tail, c.copy(uniqueName = nonEmptyString(uniqueName)))
+        case "--displayedName" :: displayedName :: tail =>
+          parse(tail, c.copy(displayedName = nonEmptyString(displayedName)))
+        case "--id" :: id :: tail if Try(id.toInt).isSuccess =>
+          parse(tail, c.copy(id = Some(id.toInt)))
+        case Nil => c
+        case _   => abort(s"Error processing command line arguments $ls")
       }
     }
     val cmdLineArgs = parse(args.toList, CmdLineArgs())
     logger.info(this, "Command line arguments parsed to yield " + cmdLineArgs)
-    val invokerUniqueName =
-      cmdLineArgs.uniqueName.orElse(if (config.invokerName.trim.isEmpty) None else Some(config.invokerName))
-    val assignedInvokerId = cmdLineArgs.id
-      .map { id =>
-        logger.info(this, s"invokerReg: using proposedInvokerId ${id}")
+
+    val assignedInvokerId = cmdLineArgs match {
+      // --id is defined with a valid value, use this id directly.
+      case CmdLineArgs(_, Some(id), _) =>
+        logger.info(this, s"invokerReg: using proposedInvokerId $id")
         id
-      }
-      .getOrElse {
+
+      // --uniqueName is defined with a valid value, id is empty, assign an id via zookeeper
+      case CmdLineArgs(Some(unique), None, _) =>
         if (config.zookeeperHosts.startsWith(":") || config.zookeeperHosts.endsWith(":"))
{
           abort(s"Must provide valid zookeeper host and port to use dynamicId assignment
(${config.zookeeperHosts})")
         }
-        if (invokerUniqueName.isEmpty || invokerUniqueName.get.trim.isEmpty) {
-          abort("Invoker name can't be empty to use dynamicId assignment.")
-        }
+        new InstanceIdAssigner(config.zookeeperHosts).getId(unique)
 
-        new InstanceIdAssigner(config.zookeeperHosts).getId(invokerUniqueName.get)
-      }
+      case _ => abort(s"Either --id or --uniqueName must be configured with correct values")
+    }
 
     initKamon(assignedInvokerId)
 
     val topicBaseName = "invoker"
     val topicName = topicBaseName + assignedInvokerId
-    val invokerDisplayedName = cmdLineArgs.displayedName
-    val invokerInstance = InvokerInstanceId(assignedInvokerId, invokerUniqueName, invokerDisplayedName)
+    val invokerInstance = InvokerInstanceId(assignedInvokerId, cmdLineArgs.uniqueName, cmdLineArgs.displayedName)
     val msgProvider = SpiLoader.get[MessagingProvider]
     if (msgProvider.ensureTopic(config, topic = topicName, topicConfig = topicBaseName).isFailure)
{
       abort(s"failure during msgProvider.ensureTopic for topic $topicName")


Mime
View raw message