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

 ##########
 File path: 
common/scala/src/main/scala/whisk/core/mesos/MesosContainerFactory.scala
 ##########
 @@ -0,0 +1,185 @@
+/*
+ * 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.Failure
+import scala.util.Success
+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 failoverTimeoutSeconds 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] = None,
+                       role: String = "*",
+                       failoverTimeoutSeconds: FiniteDuration = 0.seconds,
+                       mesosLinkLogMessage: Boolean = true)
+
+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 = 30.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
+
+  var isSubscribed = false;
+
+  val mesosClientActor = clientFactory(as, mesosConfig)
+
+  //periodically retry if subscribing did not suceed
+  as.scheduler.schedule(0.seconds, (subscribeTimeout.toSeconds + 10).seconds) {
+    if (!isSubscribed) {
+      subscribe()
+    }
+  }
 
 Review comment:
   The flag is never reset to false, so i'm assuming this should stop to try to 
subscribe after successfully subscribed? I think this should be doable with a 
retry in `subscribe` itself?

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to