tysonnorris commented on a change in pull request #2531: Share bookkeeping data across controllers URL: https://github.com/apache/incubator-openwhisk/pull/2531#discussion_r138950911
########## File path: core/controller/src/main/scala/whisk/core/loadBalancer/SharedDataService.scala ########## @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package whisk.core.loadBalancer + +import akka.actor.{Actor, ActorLogging, ActorRef, Props} +import akka.cluster.Cluster +import akka.cluster.ClusterEvent.{InitialStateAsEvents, MemberEvent, MemberRemoved, MemberUp, UnreachableMember} +import akka.cluster.ddata.{DistributedData, PNCounterMap, PNCounterMapKey} +import akka.cluster.ddata.Replicator._ +import whisk.common.AkkaLogging +import whisk.core.WhiskConfig +import com.typesafe.config.{Config, ConfigFactory} + +case class IncreaseCounter(key: String, value: Long) +case class DecreaseCounter(key: String, value: Long) +case class ReadCounter(key: String) +case class RemoveCounter(key: String) +case object GetMap + +/** + * Companion object to specify actor properties from the outside, e.g. name of the shared map + */ +object SharedDataService { + val requiredProperties = Map(WhiskConfig.controllerSeedNodes -> null) + + def props(storageName: String): Props = Props(new SharedDataService(storageName)) + + /** + * Add seed nodes if cluster provider is specified, otherwhise return the existing config. + * Parse akka seed nodes this way until either of these 2 issues is resolved: + * https://github.com/akka/akka/issues/23600 + * https://github.com/typesafehub/config/issues/69 + * @return Updated Config + */ + def addAkkaSeedNodesToConf(whiskConf: WhiskConfig): Config = { + val conf = ConfigFactory.load() + + val cluster = conf.getString("akka.actor.provider") + + if (cluster == "cluster") { + val seedNodes = whiskConf.controllerSeedNodes Review comment: @markusthoemmes @vvraskin the current impl launches the container system with the assumption that the config contains seed nodes, i.e. the actor system initiates clustering automatically via `implicit val actorSystem = ActorSystem("controller-actor-system", SharedDataService.addAkkaSeedNodesToConf(config))`. I'm suggesting that the more flexible approach is to explicitly initiate clustering at some time after the actorsystem is started, using `Cluster(system).joinSeedNodes(seedNodesList)`, which does change the semantics of startup slightly, but allows situations like "actor system and remoting can initialize, before clustering gossip begins", which is good form for doing things like "only allow clustering to proceed if the startup proceeds to the point where remoting can be enabled". Otherwise you are likely to have a noisey (at least) or failure (at worst) during startup in a more dynamic env, or even in a static env, if the seed nodes are not started before the nodes that attem pt to join as a cluster (esp in the case where "all the nodes are seed nodes") ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
