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/11/07 09:50:20 UTC
[GitHub] chetanmeh closed pull request #4074: Prepare for switch to Scala
2.12.7
chetanmeh closed pull request #4074: Prepare for switch to Scala 2.12.7
URL: https://github.com/apache/incubator-openwhisk/pull/4074
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/common/scala/src/main/scala/whisk/common/Logging.scala b/common/scala/src/main/scala/whisk/common/Logging.scala
index 19642f9b97..9995a3ecf7 100644
--- a/common/scala/src/main/scala/whisk/common/Logging.scala
+++ b/common/scala/src/main/scala/whisk/common/Logging.scala
@@ -111,6 +111,7 @@ class PrintStreamLogging(outputStream: PrintStream = Console.out) extends Loggin
case InfoLevel => "INFO"
case WarningLevel => "WARN"
case ErrorLevel => "ERROR"
+ case LogLevel(_) => "UNKNOWN"
}
val logMessage = Seq(message).collect {
diff --git a/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala b/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala
index 8518a953c1..49a62906b0 100644
--- a/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala
+++ b/common/scala/src/main/scala/whisk/core/database/CouchDbRestStore.scala
@@ -555,10 +555,10 @@ class CouchDbRestStore[DocumentAbstraction <: DocumentSerializer](dbProtocol: St
}
private def reportFailure[T, U](f: Future[T], onFailure: Throwable => U): Future[T] = {
- f.onFailure({
+ f.failed.foreach {
case _: ArtifactStoreException => // These failures are intentional and shouldn't trigger the catcher.
case x => onFailure(x)
- })
+ }
f
}
}
diff --git a/common/scala/src/main/scala/whisk/core/database/StoreUtils.scala b/common/scala/src/main/scala/whisk/core/database/StoreUtils.scala
index d901fde769..21ac05aa0c 100644
--- a/common/scala/src/main/scala/whisk/core/database/StoreUtils.scala
+++ b/common/scala/src/main/scala/whisk/core/database/StoreUtils.scala
@@ -38,11 +38,11 @@ private[database] object StoreUtils {
implicit transid: TransactionId,
logging: Logging,
ec: ExecutionContext): Future[T] = {
- f.onFailure({
+ f.failed.foreach {
case _: ArtifactStoreException => // These failures are intentional and shouldn't trigger the catcher.
case x =>
transid.failed(this, start, s"${failureMessage(x)} [${x.getClass.getSimpleName}]", ErrorLevel)
- })
+ }
f
}
diff --git a/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala b/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala
index 24dc040008..a03dd8e43d 100644
--- a/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala
+++ b/common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStore.scala
@@ -238,9 +238,9 @@ class CosmosDBArtifactStore[DocumentAbstraction <: DocumentSerializer](protected
.runWith(Sink.seq)
.map(_.toList)
- f.onSuccess({
- case out => transid.finished(this, start, s"[QUERY] '$collName' completed: matched ${out.size}")
- })
+ f.foreach { out =>
+ transid.finished(this, start, s"[QUERY] '$collName' completed: matched ${out.size}")
+ }
reportFailure(f, start, failure => s"[QUERY] '$collName' internal error, failure: '${failure.getMessage}'")
}
diff --git a/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala b/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala
index f01064c181..39f94c87fd 100644
--- a/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala
+++ b/common/scala/src/main/scala/whisk/core/database/memory/MemoryArtifactStore.scala
@@ -36,7 +36,7 @@ import whisk.http.Messages
import scala.collection.concurrent.TrieMap
import scala.concurrent.{ExecutionContext, Future}
import scala.reflect.ClassTag
-import scala.util.Try
+import scala.util.{Failure, Success, Try}
object MemoryArtifactStoreProvider extends ArtifactStoreProvider {
override def makeStore[D <: DocumentSerializer: ClassTag](useBatching: Boolean)(
@@ -130,15 +130,12 @@ class MemoryArtifactStore[DocumentAbstraction <: DocumentSerializer](dbName: Str
}
val f = Future.fromTry(t)
-
- f.onFailure({
- case _: DocumentConflictException =>
+ f.onComplete {
+ case Success(_) => transid.finished(this, start, s"[PUT] '$dbName' completed document: '$docinfoStr'")
+ case Failure(_: DocumentConflictException) =>
transid.finished(this, start, s"[PUT] '$dbName', document: '$docinfoStr'; conflict.")
- })
-
- f.onSuccess({
- case _ => transid.finished(this, start, s"[PUT] '$dbName' completed document: '$docinfoStr'")
- })
+ case Failure(_) =>
+ }
reportFailure(f, start, failure => s"[PUT] '$dbName' internal error, failure: '${failure.getMessage}'")
}
@@ -239,9 +236,7 @@ class MemoryArtifactStore[DocumentAbstraction <: DocumentSerializer](dbName: Str
}.toList
val f = Future.sequence(r).map(_.flatten)
- f.onSuccess({
- case _ => transid.finished(this, start, s"[QUERY] '$dbName' completed: matched ${out.size}")
- })
+ f.foreach(_ => transid.finished(this, start, s"[QUERY] '$dbName' completed: matched ${out.size}"))
reportFailure(f, start, failure => s"[QUERY] '$dbName' internal error, failure: '${failure.getMessage}'")
}
@@ -270,10 +265,8 @@ class MemoryArtifactStore[DocumentAbstraction <: DocumentSerializer](dbName: Str
} else {
val storedName = attachmentUri.path.toString()
val f = attachmentStore.readAttachment(doc.id, storedName, sink)
- f.onSuccess {
- case _ =>
- transid.finished(this, start, s"[ATT_GET] '$dbName' completed: found attachment '$name' of document '$doc'")
- }
+ f.foreach(_ =>
+ transid.finished(this, start, s"[ATT_GET] '$dbName' completed: found attachment '$name' of document '$doc'"))
f
}
}
diff --git a/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala b/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala
index e02f49b843..df9056e284 100644
--- a/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala
+++ b/common/scala/src/main/scala/whisk/core/database/s3/S3AttachmentStore.scala
@@ -87,11 +87,9 @@ class S3AttachmentStore(client: S3Client, bucket: String, prefix: String)(implic
.runWith(combinedSink(client.multipartUpload(bucket, objectKey(docId, name), contentType)))
.map(r => AttachResult(r.digest, r.length))
- f.onSuccess({
- case _ =>
- transid
- .finished(this, start, s"[ATT_PUT] '$prefix' completed uploading attachment '$name' of document 'id: $docId'")
- })
+ f.foreach(_ =>
+ transid
+ .finished(this, start, s"[ATT_PUT] '$prefix' completed uploading attachment '$name' of document 'id: $docId'"))
reportFailure(
f,
@@ -147,10 +145,8 @@ class S3AttachmentStore(client: S3Client, bucket: String, prefix: String)(implic
.runWith(Sink.seq)
.map(_ => true)
- f.onSuccess {
- case _ =>
- transid.finished(this, start, s"[ATTS_DELETE] completed: deleting attachments of document 'id: $docId'")
- }
+ f.foreach(_ =>
+ transid.finished(this, start, s"[ATTS_DELETE] completed: deleting attachments of document 'id: $docId'"))
reportFailure(
f,
@@ -167,10 +163,8 @@ class S3AttachmentStore(client: S3Client, bucket: String, prefix: String)(implic
.deleteObject(bucket, objectKey(docId, name))
.map(_ => true)
- f.onSuccess {
- case _ =>
- transid.finished(this, start, s"[ATT_DELETE] completed: deleting attachment '$name' of document 'id: $docId'")
- }
+ f.foreach(_ =>
+ transid.finished(this, start, s"[ATT_DELETE] completed: deleting attachment '$name' of document 'id: $docId'"))
reportFailure(
f,
diff --git a/common/scala/src/main/scala/whisk/core/entity/Limits.scala b/common/scala/src/main/scala/whisk/core/entity/Limits.scala
index 5937df7c74..0e775e4994 100644
--- a/common/scala/src/main/scala/whisk/core/entity/Limits.scala
+++ b/common/scala/src/main/scala/whisk/core/entity/Limits.scala
@@ -82,5 +82,5 @@ protected[core] object ActionLimits extends ArgNormalizer[ActionLimits] with Def
protected[core] object TriggerLimits extends ArgNormalizer[TriggerLimits] with DefaultJsonProtocol {
- override protected[core] implicit val serdes = jsonFormat0(TriggerLimits.apply)
+ override protected[core] implicit val serdes = jsonFormat0(TriggerLimits.apply _)
}
diff --git a/common/scala/src/main/scala/whisk/core/mesos/MesosContainerFactory.scala b/common/scala/src/main/scala/whisk/core/mesos/MesosContainerFactory.scala
index 474361a2e5..b29bbd82c7 100644
--- a/common/scala/src/main/scala/whisk/core/mesos/MesosContainerFactory.scala
+++ b/common/scala/src/main/scala/whisk/core/mesos/MesosContainerFactory.scala
@@ -76,7 +76,7 @@ class MesosContainerFactory(config: WhiskConfig,
loadConfigOrThrow[ContainerArgsConfig](ConfigKeys.containerArgs),
mesosConfig: MesosConfig = loadConfigOrThrow[MesosConfig](ConfigKeys.mesos),
clientFactory: (ActorSystem, MesosConfig) => ActorRef = MesosContainerFactory.createClient,
- taskIdGenerator: () => String = MesosContainerFactory.taskIdGenerator)
+ taskIdGenerator: () => String = MesosContainerFactory.taskIdGenerator _)
extends ContainerFactory {
val subscribeTimeout = 10.seconds
diff --git a/core/controller/src/main/scala/whisk/core/controller/BasicAuthenticationDirective.scala b/core/controller/src/main/scala/whisk/core/controller/BasicAuthenticationDirective.scala
index c0e06c5724..83233ee5d3 100644
--- a/core/controller/src/main/scala/whisk/core/controller/BasicAuthenticationDirective.scala
+++ b/core/controller/src/main/scala/whisk/core/controller/BasicAuthenticationDirective.scala
@@ -53,7 +53,7 @@ object BasicAuthenticationDirective extends AuthenticationDirectiveProvider {
logging.debug(this, s"authentication not valid")
None
}
- future onFailure { case t => logging.error(this, s"authentication error: $t") }
+ future.failed.foreach(t => logging.error(this, s"authentication error: $t"))
future
}.toOption
} getOrElse {
diff --git a/tests/src/test/scala/actionContainers/ActionContainer.scala b/tests/src/test/scala/actionContainers/ActionContainer.scala
index 153b6d2e72..d582659666 100644
--- a/tests/src/test/scala/actionContainers/ActionContainer.scala
+++ b/tests/src/test/scala/actionContainers/ActionContainer.scala
@@ -240,7 +240,6 @@ object ActionContainer {
}
private def concurrentSyncPost(host: String, port: Int, endPoint: String, contents: Seq[JsValue])(
implicit logging: Logging,
- ec: ExecutionContext,
as: ActorSystem): Seq[(Int, Option[JsObject])] = {
implicit val transid = TransactionId.testing
diff --git a/tests/src/test/scala/common/RunCliCmd.scala b/tests/src/test/scala/common/RunCliCmd.scala
index aee4439711..e3e7e44743 100644
--- a/tests/src/test/scala/common/RunCliCmd.scala
+++ b/tests/src/test/scala/common/RunCliCmd.scala
@@ -19,7 +19,7 @@ package common
import java.io.File
-import scala.collection.JavaConversions.mapAsJavaMap
+import scala.collection.JavaConverters._
import scala.collection.mutable.Buffer
import org.scalatest.Matchers
import TestUtils._
@@ -48,7 +48,7 @@ trait RunCliCmd extends Matchers {
env: Map[String, String],
fileStdin: Option[File],
params: Seq[String]): RunResult = {
- TestUtils.runCmd(expectedExitCode, dir, TestUtils.logger, env, fileStdin.getOrElse(null), params: _*)
+ TestUtils.runCmd(expectedExitCode, dir, TestUtils.logger, env.asJava, fileStdin.getOrElse(null), params: _*)
}
/**
diff --git a/tests/src/test/scala/whisk/core/connector/test/TestConnector.scala b/tests/src/test/scala/whisk/core/connector/test/TestConnector.scala
index 8b428e5736..67faeab0b5 100644
--- a/tests/src/test/scala/whisk/core/connector/test/TestConnector.scala
+++ b/tests/src/test/scala/whisk/core/connector/test/TestConnector.scala
@@ -22,7 +22,7 @@ import java.util.concurrent.LinkedBlockingQueue
import scala.concurrent.Future
import scala.concurrent.duration._
-import scala.collection.JavaConversions._
+import scala.collection.JavaConverters._
import org.apache.kafka.clients.producer.RecordMetadata
import org.apache.kafka.common.TopicPartition
@@ -41,7 +41,7 @@ class TestConnector(topic: String, override val maxPeek: Int, allowMoreThanMax:
val msgs = new ArrayList[Message]
queue.synchronized {
queue.drainTo(msgs, if (allowMoreThanMax) Int.MaxValue else maxPeek)
- msgs map { m =>
+ msgs.asScala map { m =>
offset += 1
(topic, -1, offset, m.serialize.getBytes)
}
@@ -87,7 +87,7 @@ class TestConnector(topic: String, override val maxPeek: Int, allowMoreThanMax:
def sendBulk(topic: String, msgs: Seq[Message]): Future[RecordMetadata] = {
queue.synchronized {
- if (queue.addAll(msgs)) {
+ if (queue.addAll(msgs.asJava)) {
logging.info(this, s"put: ${msgs.length} messages")
Future.successful(new RecordMetadata(new TopicPartition(topic, 0), 0, queue.size, -1, Long.box(-1L), -1, -1))
} else {
diff --git a/tests/src/test/scala/whisk/core/containerpool/docker/test/ProcessRunnerTests.scala b/tests/src/test/scala/whisk/core/containerpool/docker/test/ProcessRunnerTests.scala
index 4abe61fd5a..e3b5fdcd10 100644
--- a/tests/src/test/scala/whisk/core/containerpool/docker/test/ProcessRunnerTests.scala
+++ b/tests/src/test/scala/whisk/core/containerpool/docker/test/ProcessRunnerTests.scala
@@ -25,7 +25,6 @@ import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.JUnitRunner
-import scala.concurrent.ExecutionContext.Implicits.global
import whisk.core.containerpool.docker.ProcessRunner
import scala.concurrent.ExecutionContext
diff --git a/tests/src/test/scala/whisk/core/containerpool/kubernetes/test/KubernetesClientTests.scala b/tests/src/test/scala/whisk/core/containerpool/kubernetes/test/KubernetesClientTests.scala
index 3336e831b1..78f2d8a906 100644
--- a/tests/src/test/scala/whisk/core/containerpool/kubernetes/test/KubernetesClientTests.scala
+++ b/tests/src/test/scala/whisk/core/containerpool/kubernetes/test/KubernetesClientTests.scala
@@ -26,7 +26,6 @@ import akka.stream.scaladsl.{Concat, Sink, Source}
import scala.concurrent.Await
import scala.concurrent.ExecutionContext
-import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.duration._
import org.junit.runner.RunWith
@@ -79,7 +78,7 @@ class KubernetesClientTests
/** Returns a KubernetesClient with a mocked result for 'executeProcess' */
def kubernetesClient(fixture: => Future[String]) = {
- new KubernetesClient()(global) {
+ new KubernetesClient()(executionContext) {
override def executeProcess(args: Seq[String], timeout: Duration)(implicit ec: ExecutionContext,
as: ActorSystem) =
fixture
@@ -89,7 +88,7 @@ class KubernetesClientTests
def kubernetesContainer(id: ContainerId) =
new KubernetesContainer(id, ContainerAddress("ip"), "ip", "docker://" + id.asString)(kubernetesClient {
Future.successful("")
- }, actorSystem, global, logging)
+ }, actorSystem, executionContext, logging)
behavior of "KubernetesClient"
@@ -178,6 +177,7 @@ class KubernetesClientTests
object KubernetesClientTests {
import scala.language.implicitConversions
+ import scala.concurrent.ExecutionContext.Implicits.global
implicit def strToDate(str: String): Option[Instant] =
KubernetesClient.parseK8STimestamp(str).toOption
diff --git a/tests/src/test/scala/whisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala b/tests/src/test/scala/whisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala
index d5187ed833..6500859f7c 100644
--- a/tests/src/test/scala/whisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala
+++ b/tests/src/test/scala/whisk/core/containerpool/mesos/test/MesosContainerFactoryTest.scala
@@ -127,7 +127,7 @@ class MesosContainerFactoryTest
containerArgsConfig,
mesosConfig,
(_, _) => testActor,
- testTaskId)
+ testTaskId _)
expectMsg(Subscribe)
factory.createContainer(
@@ -173,7 +173,7 @@ class MesosContainerFactoryTest
containerArgsConfig,
mesosConfig,
(system, mesosConfig) => probe.testActor,
- testTaskId)
+ testTaskId _)
probe.expectMsg(Subscribe)
//emulate successful subscribe
@@ -244,7 +244,7 @@ class MesosContainerFactoryTest
new ContainerArgsConfig("bridge", Seq.empty, Map("extra1" -> Set("e1", "e2"), "extra2" -> Set("e3", "e4"))),
mesosConfig,
(system, mesosConfig) => probe.testActor,
- testTaskId)
+ testTaskId _)
probe.expectMsg(Subscribe)
//emulate successful subscribe
----------------------------------------------------------------
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