markusthoemmes commented on a change in pull request #2228: Hook up reactive pool into invoker startup URL: https://github.com/apache/incubator-openwhisk/pull/2228#discussion_r116379674
########## File path: core/invoker/src/main/scala/whisk/core/invoker/InvokerReactive.scala ########## @@ -0,0 +1,181 @@ +/* + * Copyright 2015-2016 IBM Corporation + * + * Licensed 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.invoker + +import scala.concurrent.Await +import scala.concurrent.Future +import scala.concurrent.duration._ +import scala.util.Failure +import scala.util.Success + +import akka.actor.ActorRef +import akka.actor.ActorRefFactory +import akka.actor.ActorSystem +import spray.json._ +import spray.json.DefaultJsonProtocol._ +import whisk.common.Logging +import whisk.common.LoggingMarkers +import whisk.common.TransactionId +import whisk.core.WhiskConfig +import whisk.core.connector.ActivationMessage +import whisk.core.connector.CompletionMessage +import whisk.core.connector.MessageProducer +import whisk.core.container.{ ContainerPool => OldContainerPool } +import whisk.core.container.Interval +import whisk.core.containerpool.ContainerProxy +import whisk.core.containerpool.PrewarmingConfig +import whisk.core.containerpool.Run +import whisk.core.containerpool.docker.DockerClientWithFileAccess +import whisk.core.containerpool.docker.DockerContainer +import whisk.core.containerpool.docker.RuncClient +import whisk.core.dispatcher.MessageHandler +import whisk.core.entity._ +import whisk.core.entity.ExecManifest.ImageName +import whisk.core.entity.size._ + +class InvokerReactive( + config: WhiskConfig, + instance: Int, + activationFeed: ActorRef, + producer: MessageProducer)(implicit actorSystem: ActorSystem, logging: Logging) + extends MessageHandler(s"invoker$instance") { + + implicit val ec = actorSystem.dispatcher + + private val entityStore = WhiskEntityStore.datastore(config) + private val activationStore = WhiskActivationStore.datastore(config) + + implicit val docker = new DockerClientWithFileAccess()(ec) + implicit val runc = new RuncClient(ec) + + /** Cleans up all running wsk_ containers */ + def cleanup() = { + val cleaning = docker.ps(Seq("name" -> "wsk_"))(TransactionId.invokerNanny).flatMap { containers => + val removals = containers.map { id => + runc.resume(id)(TransactionId.invokerNanny).recoverWith { + case _ => Future.successful(()) + }.flatMap { + _ => docker.rm(id)(TransactionId.invokerNanny) + } + } + Future.sequence(removals) + } + + Await.ready(cleaning, 30.seconds) + } + cleanup() + sys.addShutdownHook(cleanup()) + + val containerFactory = (tid: TransactionId, name: String, actionImage: ImageName, userProvidedImage: Boolean, memory: ByteSize) => { Review comment: Easier to pass the method along. With a `def` you need to explicitly cast it via `containerFactory _` ---------------------------------------------------------------- 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
