You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ma...@apache.org on 2017/08/23 14:09:08 UTC
[incubator-openwhisk] branch master updated: Rename
CliActivationResponse & CliActivation, and change them from (#2592)
This is an automated email from the ASF dual-hosted git repository.
markusthoemmes pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new e5c4bf0 Rename CliActivationResponse & CliActivation, and change them from (#2592)
e5c4bf0 is described below
commit e5c4bf0f1e25548406266aec813ab21c5ebcebef
Author: Vincent <sh...@us.ibm.com>
AuthorDate: Wed Aug 23 10:09:05 2017 -0400
Rename CliActivationResponse & CliActivation, and change them from (#2592)
This PR renames the class CliActivation and CliActivationResponse
and makes them available to be accessed from another package, because
REST call can use both of the classes as well.
Partially-closes-bug: #2430
---
tests/src/test/scala/common/WskTestHelpers.scala | 153 +++++++++++++--------
.../test/scala/system/basic/WskActionTests.scala | 5 +-
.../test/scala/system/basic/WskBasicTests.scala | 3 +-
.../test/scala/system/basic/WskSequenceTests.scala | 5 +-
.../whisk/core/limits/ActionLimitsTests.scala | 5 +-
5 files changed, 106 insertions(+), 65 deletions(-)
diff --git a/tests/src/test/scala/common/WskTestHelpers.scala b/tests/src/test/scala/common/WskTestHelpers.scala
index 7f3d750..c8baa78 100644
--- a/tests/src/test/scala/common/WskTestHelpers.scala
+++ b/tests/src/test/scala/common/WskTestHelpers.scala
@@ -17,6 +17,10 @@
package common
+import java.time.Instant
+
+import org.scalatest.Matchers
+
import scala.collection.mutable.ListBuffer
import scala.util.Failure
import scala.util.Try
@@ -24,11 +28,93 @@ import scala.concurrent.duration.Duration
import scala.concurrent.duration.DurationInt
import scala.language.postfixOps
-import org.scalatest.Matchers
-
-import TestUtils._
import spray.json._
-import java.time.Instant
+
+import TestUtils.RunResult
+import TestUtils.CONFLICT
+
+/**
+ * An arbitrary response of a whisk action. Includes the result as a JsObject as the
+ * structure of "result" is not defined.
+ *
+ * @param result a JSON object used to save the result of the execution of the action
+ * @param status a string used to indicate the status of the action
+ * @param success a boolean value used to indicate whether the action is executed successfully or not
+ */
+case class ActivationResponse(result: Option[JsObject], status: String, success: Boolean)
+
+object ActivationResponse extends DefaultJsonProtocol {
+ implicit val serdes = jsonFormat3(ActivationResponse.apply)
+}
+
+/**
+ * Activation record as it is returned from the OpenWhisk service.
+ *
+ * @param activationId a String to save the ID of the activation
+ * @param logs a list of String to save the logs of the activation
+ * @param response an Object of ActivationResponse to save the response of the activation
+ * @param start an Instant to save the start time of activation
+ * @param end an Instant to save the end time of activation
+ * @param duration a Long to save the duration of the activation
+ * @param cases String to save the cause of failure if the activation fails
+ * @param annotations a list of JSON objects to save the annotations of the activation
+ */
+case class ActivationResult(
+ activationId: String,
+ logs: Option[List[String]],
+ response: ActivationResponse,
+ start: Instant,
+ end: Instant,
+ duration: Long,
+ cause: Option[String],
+ annotations: Option[List[JsObject]]) {
+
+ def getAnnotationValue(key: String): Option[JsValue] = {
+ Try {
+ val annotation = annotations.get.filter(x => x.getFields("key")(0) == JsString(key))
+ assert(annotation.size == 1) // only one annotation with this value
+ val value = annotation(0).getFields("value")
+ assert(value.size == 1)
+ value(0)
+ } toOption
+ }
+}
+
+object ActivationResult extends DefaultJsonProtocol {
+ private implicit val instantSerdes = new RootJsonFormat[Instant] {
+ def write(t: Instant) = t.toEpochMilli.toJson
+
+ def read(value: JsValue) = Try {
+ value match {
+ case JsNumber(i) => Instant.ofEpochMilli(i.bigDecimal.longValue)
+ case _ => deserializationError("timetsamp malformed")
+ }
+ } getOrElse deserializationError("timetsamp malformed 2")
+ }
+
+ implicit val serdes = new RootJsonFormat[ActivationResult] {
+ private val format = jsonFormat8(ActivationResult.apply)
+
+ def write(result: ActivationResult) = format.write(result)
+
+ def read(value: JsValue) = {
+ val obj = value.asJsObject
+ obj.getFields("activationId", "response", "start") match {
+ case Seq(JsString(activationId), response, start) =>
+ Try {
+ val logs = obj.fields.get("logs").map(_.convertTo[List[String]])
+ val end = obj.fields.get("end").map(_.convertTo[Instant]).getOrElse(Instant.EPOCH)
+ val duration = obj.fields.get("duration").map(_.convertTo[Long]).getOrElse(0L)
+ val cause = obj.fields.get("cause").map(_.convertTo[String])
+ val annotations = obj.fields.get("annotations").map(_.convertTo[List[JsObject]])
+ new ActivationResult(activationId, logs, response.convertTo[ActivationResponse],
+ start.convertTo[Instant], end, duration, cause, annotations)
+ } getOrElse deserializationError("Failed to deserialize the activation result.")
+ case _ => deserializationError("Failed to deserialize the activation ID, response or start.")
+ }
+ }
+ }
+}
/**
* Test fixture to ease cleaning of whisk entities created during testing.
@@ -98,55 +184,6 @@ trait WskTestHelpers extends Matchers {
}
/**
- * An arbitrary response of a whisk action. Includes the result as a JsObject as the
- * structure of "result" is not defined.
- */
- case class CliActivationResponse(result: Option[JsObject], status: String, success: Boolean)
-
- object CliActivationResponse extends DefaultJsonProtocol {
- implicit val serdes = jsonFormat3(CliActivationResponse.apply)
- }
-
- /**
- * Activation record as it is returned by the CLI.
- */
- case class CliActivation(
- activationId: String,
- logs: Option[List[String]],
- response: CliActivationResponse,
- start: Instant,
- end: Instant,
- duration: Long,
- cause: Option[String],
- annotations: Option[List[JsObject]]) {
-
- def getAnnotationValue(key: String): Option[JsValue] = {
- Try {
- val annotation = annotations.get.filter(x => x.getFields("key")(0) == JsString(key))
- assert(annotation.size == 1) // only one annotation with this value
- val value = annotation(0).getFields("value")
- assert(value.size == 1)
- value(0)
- } toOption
- }
- }
-
- object CliActivation extends DefaultJsonProtocol {
- private implicit val instantSerdes = new RootJsonFormat[Instant] {
- def write(t: Instant) = t.toEpochMilli.toJson
-
- def read(value: JsValue) = Try {
- value match {
- case JsNumber(i) => Instant.ofEpochMilli(i.bigDecimal.longValue)
- case _ => deserializationError("timetsamp malformed")
- }
- } getOrElse deserializationError("timetsamp malformed 2")
- }
-
- implicit val serdes = jsonFormat8(CliActivation.apply)
- }
-
- /**
* Extracts an activation id from a wsk command producing a RunResult with such an id.
* If id is found, polls activations until one matching id is found. If found, pass
* the activation to the post processor which then check for expected values.
@@ -157,7 +194,7 @@ trait WskTestHelpers extends Matchers {
initialWait: Duration = 1 second,
pollPeriod: Duration = 1 second,
totalWait: Duration = 30 seconds)(
- check: CliActivation => Unit)(
+ check: ActivationResult => Unit)(
implicit wskprops: WskProps): Unit = {
val activationId = wsk.extractActivationId(run)
@@ -178,14 +215,14 @@ trait WskTestHelpers extends Matchers {
initialWait: Duration,
pollPeriod: Duration,
totalWait: Duration)(
- check: CliActivation => Unit)(
+ check: ActivationResult => Unit)(
implicit wskprops: WskProps): Unit = {
val id = activationId
val activation = wsk.waitForActivation(id, initialWait, pollPeriod, totalWait)
if (activation.isLeft) {
assert(false, s"error waiting for activation $id: ${activation.left.get}")
} else try {
- check(activation.right.get.convertTo[CliActivation])
+ check(activation.right.get.convertTo[ActivationResult])
} catch {
case error: Throwable =>
println(s"check failed for activation $id: ${activation.right.get}")
@@ -205,7 +242,7 @@ trait WskTestHelpers extends Matchers {
since: Option[Instant] = None,
pollPeriod: Duration = 1 second,
totalWait: Duration = 30 seconds)(
- check: Seq[CliActivation] => Unit)(
+ check: Seq[ActivationResult] => Unit)(
implicit wskprops: WskProps): Unit = {
val activationIds = wsk.pollFor(N, Some(entity), since = since, retries = (totalWait / pollPeriod).toInt, pollPeriod = pollPeriod)
@@ -214,7 +251,7 @@ trait WskTestHelpers extends Matchers {
}
val parsed = activationIds.map { id =>
- wsk.parseJsonString(wsk.get(Some(id)).stdout).convertTo[CliActivation]
+ wsk.parseJsonString(wsk.get(Some(id)).stdout).convertTo[ActivationResult]
}
try {
check(parsed)
diff --git a/tests/src/test/scala/system/basic/WskActionTests.scala b/tests/src/test/scala/system/basic/WskActionTests.scala
index 90e92b9..6baa886 100644
--- a/tests/src/test/scala/system/basic/WskActionTests.scala
+++ b/tests/src/test/scala/system/basic/WskActionTests.scala
@@ -20,6 +20,7 @@ package system.basic
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
+import common.ActivationResult
import common.JsHelpers
import common.TestHelpers
import common.TestUtils
@@ -289,7 +290,7 @@ class WskActionTests
}
val run = wsk.action.invoke(name, Map("payload" -> testString.toJson), blocking = true)
- val activation = wsk.parseJsonString(run.stdout).convertTo[CliActivation]
+ val activation = wsk.parseJsonString(run.stdout).convertTo[ActivationResult]
withClue(s"check failed for activation: $activation") {
val wordCount = testString.split(" ").length
@@ -305,7 +306,7 @@ class WskActionTests
}
val run = wsk.action.invoke(name, Map("payload" -> testString.toJson), blocking = true)
- val activation = wsk.parseJsonString(run.stdout).convertTo[CliActivation]
+ val activation = wsk.parseJsonString(run.stdout).convertTo[ActivationResult]
withClue(s"check failed for activation: $activation") {
activation.response.status shouldBe "success"
diff --git a/tests/src/test/scala/system/basic/WskBasicTests.scala b/tests/src/test/scala/system/basic/WskBasicTests.scala
index 61b4cf0..a3892df 100644
--- a/tests/src/test/scala/system/basic/WskBasicTests.scala
+++ b/tests/src/test/scala/system/basic/WskBasicTests.scala
@@ -25,6 +25,7 @@ import scala.language.postfixOps
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
+import common.ActivationResult
import common.TestHelpers
import common.TestUtils
import common.TestUtils._
@@ -370,7 +371,7 @@ class WskBasicTests
}
val stderr = wsk.action.invoke(name, blocking = true, expectedExitCode = 246).stderr
- CliActivation.serdes.read(removeCLIHeader(stderr).parseJson).response.result shouldBe Some {
+ ActivationResult.serdes.read(removeCLIHeader(stderr).parseJson).response.result shouldBe Some {
JsObject("error" -> JsObject("msg" -> "failed activation on purpose".toJson))
}
}
diff --git a/tests/src/test/scala/system/basic/WskSequenceTests.scala b/tests/src/test/scala/system/basic/WskSequenceTests.scala
index 452b776..dccd5ce 100644
--- a/tests/src/test/scala/system/basic/WskSequenceTests.scala
+++ b/tests/src/test/scala/system/basic/WskSequenceTests.scala
@@ -27,6 +27,7 @@ import scala.util.matching.Regex
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
+import common.ActivationResult
import common.StreamLogging
import common.TestHelpers
import common.TestUtils
@@ -478,7 +479,7 @@ class WskSequenceTests
* checks duration
* checks memory
*/
- private def checkSequenceLogsAndAnnotations(activation: CliActivation, size: Int) = {
+ private def checkSequenceLogsAndAnnotations(activation: ActivationResult, size: Int) = {
activation.logs shouldBe defined
// check that the logs are what they are supposed to be (activation ids)
// check that the cause field is properly set for these activations
@@ -523,7 +524,7 @@ class WskSequenceTests
}
}
- private def extractMemoryAnnotation(activation: CliActivation): Long = {
+ private def extractMemoryAnnotation(activation: ActivationResult): Long = {
val limits = activation.getAnnotationValue("limits")
limits shouldBe defined
limits.get.asJsObject.getFields("memory")(0).convertTo[Long]
diff --git a/tests/src/test/scala/whisk/core/limits/ActionLimitsTests.scala b/tests/src/test/scala/whisk/core/limits/ActionLimitsTests.scala
index e1219eb..00f2946 100644
--- a/tests/src/test/scala/whisk/core/limits/ActionLimitsTests.scala
+++ b/tests/src/test/scala/whisk/core/limits/ActionLimitsTests.scala
@@ -26,6 +26,7 @@ import scala.language.postfixOps
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
+import common.ActivationResult
import common.TestHelpers
import common.TestUtils
import common.TestUtils.TOO_LARGE
@@ -133,7 +134,7 @@ class ActionLimitsTests extends TestHelpers with WskTestHelpers {
val allowedSize = ActivationEntityLimit.MAX_ACTIVATION_ENTITY_LIMIT.toBytes
- def checkResponse(activation: CliActivation) = {
+ def checkResponse(activation: ActivationResult) = {
val response = activation.response
response.success shouldBe false
response.status shouldBe ActivationResponse.messageForCode(ActivationResponse.ContainerError)
@@ -150,7 +151,7 @@ class ActionLimitsTests extends TestHelpers with WskTestHelpers {
val code = if (blocking) TestUtils.APP_ERROR else TestUtils.SUCCESS_EXIT
val rr = wsk.action.invoke(name, args, blocking = blocking, expectedExitCode = code)
if (blocking) {
- checkResponse(wsk.parseJsonString(rr.stderr).convertTo[CliActivation])
+ checkResponse(wsk.parseJsonString(rr.stderr).convertTo[ActivationResult])
} else {
withActivation(wsk.activation, rr, totalWait = 120 seconds) { checkResponse(_) }
}
--
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].