markusthoemmes closed pull request #3196: Fixes #3195 - create config object 
for docker in the invoker and get …
URL: https://github.com/apache/incubator-openwhisk/pull/3196
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/invoker/src/main/resources/application.conf 
b/core/invoker/src/main/resources/application.conf
index 37d2f5ffa9..d7ee4fd26b 100644
--- a/core/invoker/src/main/resources/application.conf
+++ b/core/invoker/src/main/resources/application.conf
@@ -12,7 +12,11 @@ whisk {
     inspect: 1 minute
     pause: 10 seconds
     unpause: 10 seconds
+
   }
+  // Used by whisk.core.containerpool.docker.DockerContainerFactoryConfig
+  // Sets the dockerd's storage location to an alternate path, if not 
specified defaults to "/containers"
+  // docker.dataroot: /var/lib/docker
 
   # Timeouts for k8s commands. Set to "Inf" to disable timeout.
   kubernetes.timeouts {
diff --git 
a/core/invoker/src/main/scala/whisk/core/containerpool/ContainerProxy.scala 
b/core/invoker/src/main/scala/whisk/core/containerpool/ContainerProxy.scala
index 805c2a1b0c..acd03854f3 100644
--- a/core/invoker/src/main/scala/whisk/core/containerpool/ContainerProxy.scala
+++ b/core/invoker/src/main/scala/whisk/core/containerpool/ContainerProxy.scala
@@ -19,25 +19,22 @@ package whisk.core.containerpool
 
 import java.time.Instant
 
-import scala.concurrent.Future
-import scala.concurrent.duration._
-import scala.util.Success
-import scala.util.Failure
-import akka.actor.FSM
-import akka.actor.Props
-import akka.actor.Stash
 import akka.actor.Status.{Failure => FailureMessage}
+import akka.actor.{FSM, Props, Stash}
 import akka.pattern.pipe
-import spray.json._
 import spray.json.DefaultJsonProtocol._
+import spray.json._
 import whisk.common.{AkkaLogging, Counter, LoggingMarkers, TransactionId}
 import whisk.core.connector.ActivationMessage
 import whisk.core.containerpool.logging.LogCollectingException
+import whisk.core.entity.ExecManifest.ImageName
 import whisk.core.entity._
 import whisk.core.entity.size._
-import whisk.core.entity.ExecManifest.ImageName
 import whisk.http.Messages
-import akka.event.Logging.InfoLevel
+
+import scala.concurrent.Future
+import scala.concurrent.duration._
+import scala.util.{Failure, Success}
 
 // States
 sealed trait ContainerState
@@ -380,8 +377,11 @@ class ContainerProxy(
     // Adds logs to the raw activation.
     val activationWithLogs: Future[Either[ActivationLogReadingError, 
WhiskActivation]] = activation
       .flatMap { activation =>
-        val start = tid.started(this, LoggingMarkers.INVOKER_COLLECT_LOGS, 
logLevel = InfoLevel)
-        collectLogs(tid, job.msg.user, activation, container, job.action)
+        val start = tid.started(this, LoggingMarkers.INVOKER_COLLECT_LOGS)
+        val collected: Future[ActivationLogs] = try {
+          collectLogs(tid, job.msg.user, activation, container, job.action)
+        } catch { case t: Throwable => Future.failed(t) }
+        collected
           .andThen {
             case Success(_) => tid.finished(this, start)
             case Failure(t) => tid.failed(this, start, s"reading logs failed: 
$t")
diff --git 
a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerClientWithFileAccess.scala
 
b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerClientWithFileAccess.scala
index 5487f5d3a9..36aaa0d9d5 100644
--- 
a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerClientWithFileAccess.scala
+++ 
b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerClientWithFileAccess.scala
@@ -24,18 +24,12 @@ import akka.actor.ActorSystem
 import akka.stream.alpakka.file.scaladsl.FileTailSource
 import akka.stream.scaladsl.{FileIO, Source => AkkaSource}
 import akka.util.ByteString
-
-import scala.concurrent.ExecutionContext
-import scala.concurrent.Future
-import scala.concurrent.blocking
 import spray.json.DefaultJsonProtocol._
 import spray.json._
-import whisk.common.Logging
-import whisk.common.TransactionId
-import whisk.core.containerpool.ContainerId
-import whisk.core.containerpool.ContainerAddress
+import whisk.common.{Logging, TransactionId}
+import whisk.core.containerpool.{ContainerAddress, ContainerId}
 
-import scala.io.Source
+import scala.concurrent.{blocking, ExecutionContext, Future}
 import scala.concurrent.duration.FiniteDuration
 
 class DockerClientWithFileAccess(dockerHost: Option[String] = None,
diff --git 
a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala
 
b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala
index 5d3083c620..3ad17881f5 100644
--- 
a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala
+++ 
b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala
@@ -237,6 +237,10 @@ class DockerContainer(protected val id: ContainerId,
   def logs(limit: ByteSize, waitForSentinel: Boolean)(implicit transid: 
TransactionId): Source[ByteString, Any] = {
     docker
       .rawContainerLogs(id, logFileOffset.get(), if (waitForSentinel) 
Some(filePollInterval) else None)
+      .recover {
+        case _: RuntimeException =>
+          ByteString(LogLine(Instant.now.toString, "stderr", 
Messages.logFailure).toJson.compactPrint)
+      }
       // This stage only throws 'FramingException' so we cannot decide whether 
we got truncated due to a size
       // constraint (like StreamLimitReachedException below) or due to the 
file being truncated itself.
       .via(Framing.delimiter(delimiter, limit.toBytes.toInt))
@@ -261,6 +265,8 @@ class DockerContainer(protected val id: ContainerId,
           // FramingException can also mean exceeding the limits, we cannot 
decide which case happened so we resort
           // to the general error message. This will be the last element of 
the stream.
           ByteString(LogLine(Instant.now.toString, "stderr", 
Messages.logFailure).toJson.compactPrint)
+        case _: RuntimeException =>
+          ByteString(LogLine(Instant.now.toString, "stderr", 
Messages.logFailure).toJson.compactPrint)
       }
   }
 
diff --git 
a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainerFactory.scala
 
b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainerFactory.scala
index fbcd230bd0..6a7bb41beb 100644
--- 
a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainerFactory.scala
+++ 
b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainerFactory.scala
@@ -17,24 +17,19 @@
 
 package whisk.core.containerpool.docker
 
-import akka.actor.ActorSystem
-import scala.concurrent.Await
-import scala.concurrent.ExecutionContext
-import scala.concurrent.Future
-import whisk.common.Logging
-import whisk.common.TransactionId
-import whisk.core.WhiskConfig
-import whisk.core.containerpool.Container
-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 scala.concurrent.duration._
+import java.io.File
+import java.nio.file.Paths
 import java.util.concurrent.TimeoutException
+
+import akka.actor.ActorSystem
 import pureconfig._
-import whisk.core.ConfigKeys
-import whisk.core.containerpool.ContainerArgsConfig
+import whisk.common.{Logging, TransactionId}
+import whisk.core.{ConfigKeys, WhiskConfig}
+import whisk.core.containerpool.{Container, ContainerArgsConfig, 
ContainerFactory, ContainerFactoryProvider}
+import whisk.core.entity.{ByteSize, ExecManifest, InstanceId}
+
+import scala.concurrent.{Await, ExecutionContext, Future}
+import scala.concurrent.duration._
 
 class DockerContainerFactory(config: WhiskConfig,
                              instance: InstanceId,
@@ -45,9 +40,10 @@ class DockerContainerFactory(config: WhiskConfig,
   ec: ExecutionContext,
   logging: Logging)
     extends ContainerFactory {
+  private val dockerConfig = 
pureconfig.loadConfigOrThrow[DockerContainerFactoryConfig](ConfigKeys.docker)
 
   /** Initialize container clients */
-  implicit val docker = new DockerClientWithFileAccess()(ec)
+  implicit val docker = new DockerClientWithFileAccess(containersDirectory = 
dockerConfig.containerPath)(ec)
   implicit val runc = new RuncClient()(ec)
 
   /** Create a container using docker cli */
@@ -99,8 +95,8 @@ class DockerContainerFactory(config: WhiskConfig,
    * There is no checking whether container removal was successful
    * or not.
    *
-   * @throws InterruptedException     if the current thread is interrupted 
while waiting
-   * @throws TimeoutException         if after waiting for the specified time 
this `Awaitable` is still not ready
+   * @throws InterruptedException if the current thread is interrupted while 
waiting
+   * @throws TimeoutException     if after waiting for the specified time this 
`Awaitable` is still not ready
    */
   @throws(classOf[TimeoutException])
   @throws(classOf[InterruptedException])
@@ -136,3 +132,7 @@ object DockerContainerFactoryProvider extends 
ContainerFactoryProvider {
                                    parameters: Map[String, Set[String]]): 
ContainerFactory =
     new DockerContainerFactory(config, instanceId, parameters)(actorSystem, 
actorSystem.dispatcher, logging)
 }
+
+case class DockerContainerFactoryConfig(dataroot: Option[String]) {
+  val containerPath: File = Paths.get(dataroot.getOrElse("") + 
"/containers").toFile
+}
diff --git 
a/tests/src/test/scala/whisk/core/containerpool/test/ContainerProxyTests.scala 
b/tests/src/test/scala/whisk/core/containerpool/test/ContainerProxyTests.scala
index b278871d57..238450341f 100644
--- 
a/tests/src/test/scala/whisk/core/containerpool/test/ContainerProxyTests.scala
+++ 
b/tests/src/test/scala/whisk/core/containerpool/test/ContainerProxyTests.scala
@@ -507,6 +507,41 @@ class ContainerProxyTests
     }
   }
 
+  it should "complete the transaction and destroy the container if log reading 
failed terminally - v2" in {
+    val container = new TestContainer
+    val factory = createFactory(Future.successful(container))
+    val acker = createAcker
+    val store = createStore
+    val collector = LoggedFunction {
+      (transid: TransactionId,
+       user: Identity,
+       activation: WhiskActivation,
+       container: Container,
+       action: ExecutableWhiskAction) =>
+        throw new Exception
+    }
+
+    val machine =
+      childActorOf(ContainerProxy.props(factory, acker, store, collector, 
InstanceId(0), pauseGrace = timeout))
+    registerCallback(machine)
+    machine ! Run(action, message)
+    expectMsg(Transition(machine, Uninitialized, Running))
+    expectMsg(ContainerRemoved) // The message is sent as soon as the 
container decides to destroy itself
+    expectMsg(Transition(machine, Running, Removing))
+
+    awaitAssert {
+      factory.calls should have size 1
+      container.initializeCount shouldBe 1
+      container.runCount shouldBe 1
+      collector.calls should have size 1
+      container.destroyCount shouldBe 1
+      acker.calls should have size 1
+      acker.calls(0)._2.response shouldBe ActivationResponse.success()
+      store.calls should have size 1
+      store.calls(0)._2.logs shouldBe 
ActivationLogs(Vector(Messages.logFailure))
+    }
+  }
+
   it should "resend the job to the parent if resuming a container fails" in 
within(timeout) {
     val container = new TestContainer {
       override def resume()(implicit transid: TransactionId) = {


 

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

Reply via email to