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/03/08 21:32:48 UTC

[GitHub] rabbah commented on a change in pull request #2833: MesosContainerFactory

rabbah commented on a change in pull request #2833: MesosContainerFactory
URL: https://github.com/apache/incubator-openwhisk/pull/2833#discussion_r173292202
 
 

 ##########
 File path: common/scala/src/main/scala/whisk/core/mesos/MesosContainerFactory.scala
 ##########
 @@ -0,0 +1,175 @@
+/*
+ * 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.mesos
+
+import akka.actor.ActorRef
+import akka.actor.ActorSystem
+import akka.pattern.ask
+import com.adobe.api.platform.runtime.mesos.MesosClient
+import com.adobe.api.platform.runtime.mesos.Subscribe
+import com.adobe.api.platform.runtime.mesos.SubscribeComplete
+import com.adobe.api.platform.runtime.mesos.Teardown
+import java.time.Instant
+import pureconfig.loadConfigOrThrow
+import scala.concurrent.Await
+import scala.concurrent.ExecutionContext
+import scala.concurrent.Future
+import scala.concurrent.TimeoutException
+import scala.concurrent.duration._
+import scala.util.Try
+import whisk.common.Counter
+import whisk.common.Logging
+import whisk.common.TransactionId
+import whisk.core.ConfigKeys
+import whisk.core.WhiskConfig
+import whisk.core.containerpool.Container
+import whisk.core.containerpool.ContainerArgsConfig
+import whisk.core.containerpool.ContainerFactory
+import whisk.core.containerpool.ContainerFactoryProvider
+import whisk.core.entity.ByteSize
+import whisk.core.entity.ExecManifest
+import whisk.core.entity.InstanceId
+import whisk.core.entity.UUID
+
+/**
+ * Configuration for MesosClient
+ * @param masterUrl The mesos url e.g. http://leader.mesos:5050.
+ * @param masterPublicUrl A public facing mesos url (which may be different that the internal facing url) e.g. http://mymesos:5050.
+ * @param role The role used by this framework (see http://mesos.apache.org/documentation/latest/roles/#associating-frameworks-with-roles).
+ * @param failoverTimeout Timeout allowed for framework to reconnect after disconnection.
+ * @param mesosLinkLogMessage If true, display a link to mesos in the static log message, otherwise do not include a link to mesos.
+ */
+case class MesosConfig(masterUrl: String,
+                       masterPublicUrl: Option[String],
+                       role: String,
+                       failoverTimeout: FiniteDuration,
+                       mesosLinkLogMessage: Boolean)
+
+class MesosContainerFactory(config: WhiskConfig,
+                            actorSystem: ActorSystem,
+                            logging: Logging,
+                            parameters: Map[String, Set[String]],
+                            containerArgs: ContainerArgsConfig =
+                              loadConfigOrThrow[ContainerArgsConfig](ConfigKeys.containerArgs),
+                            mesosConfig: MesosConfig = loadConfigOrThrow[MesosConfig](ConfigKeys.mesos),
+                            clientFactory: (ActorSystem, MesosConfig) => ActorRef = MesosContainerFactory.createClient,
+                            taskIdGenerator: () => String = MesosContainerFactory.taskIdGenerator)
+    extends ContainerFactory {
+
+  val subscribeTimeout = 10.seconds
+  val teardownTimeout = 30.seconds
+
+  //init mesos framework:
+  implicit val as: ActorSystem = actorSystem
+  implicit val ec: ExecutionContext = actorSystem.dispatcher
+
+  //mesos master url to subscribe the framework to
+  val mesosMaster = mesosConfig.masterUrl
+  //public mesos url where developers can browse logs (till there is way to delegate log retrieval to an external system)
+  val mesosMasterPublic = mesosConfig.masterPublicUrl
+
+  val mesosClientActor = clientFactory(as, mesosConfig)
+
+  subscribe()
+
+  /** Subscribe mesos actor to mesos event stream; retry on timeout (which should be unusual) */
+  private def subscribe(): Future[Unit] = {
+    logging.info(this, s"subscribing to mesos master at ${mesosMaster}")
+    mesosClientActor
+      .ask(Subscribe)(subscribeTimeout)
+      .mapTo[SubscribeComplete]
+      .map(complete => logging.info(this, s"subscribe completed successfully...${complete}"))
+      .recoverWith {
+        case e =>
+          logging.error(this, s"subscribe failed...${e}")
+          subscribe()
 
 Review comment:
   this can recurse forever.

----------------------------------------------------------------
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