From commits-return-5398-archive-asf-public=cust-asf.ponee.io@openwhisk.apache.org Tue Jul 31 13:56:08 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 707C9180662 for ; Tue, 31 Jul 2018 13:56:07 +0200 (CEST) Received: (qmail 18258 invoked by uid 500); 31 Jul 2018 11:56:06 -0000 Mailing-List: contact commits-help@openwhisk.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwhisk.apache.org Delivered-To: mailing list commits@openwhisk.apache.org Received: (qmail 18249 invoked by uid 99); 31 Jul 2018 11:56:06 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Jul 2018 11:56:06 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id EDC6380934; Tue, 31 Jul 2018 11:56:05 +0000 (UTC) Date: Tue, 31 Jul 2018 11:56:05 +0000 To: "commits@openwhisk.apache.org" Subject: [incubator-openwhisk] branch master updated: Refactor invoker command line parsing. (#3894) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <153303816542.17534.13296677847746877689@gitbox.apache.org> From: vvraskin@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: incubator-openwhisk X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: f8a1506b2edc5e61476e44b924962a567c283b22 X-Git-Newrev: b197332e041968e98f6cec996e4a136116a90569 X-Git-Rev: b197332e041968e98f6cec996e4a136116a90569 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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] [] // --uniqueName a unique name to dynamically assign Kafka topics from Zookeeper // --displayedName a name to identify this invoker via invoker health protocol // --id 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")