From 54ea27361ddc5441ad76abc956f3832a8ee57462 Mon Sep 17 00:00:00 2001 From: John Green Date: Fri, 2 Feb 2024 09:32:28 +0000 Subject: [PATCH] APIS-6755: Upgrade to Play 3.0 (#78) * APIS-6755: Upgrade to Play 2.9 * APIS-6755: Upgrade to Play 3.0 --- .../connectors/ProxiedHttpClient.scala | 2 +- .../OutboundMessageRepository.scala | 6 +-- .../scheduled/LockedScheduledJob.scala | 4 +- .../scheduled/RunningOfScheduledJobs.scala | 4 +- .../scheduled/SoapMessageRetryJob.scala | 6 +-- .../services/OutboundService.scala | 6 +-- conf/application.conf | 45 ------------------- conf/prod.routes | 2 - .../OutboundMessageRepositoryISpec.scala | 4 +- project/AppDependencies.scala | 18 +++----- project/plugins.sbt | 6 +-- .../connectors/ProxiedHttpClientSpec.scala | 2 +- .../ConfirmationControllerSpec.scala | 2 +- .../controllers/OutboundControllerSpec.scala | 2 +- .../scheduled/SoapMessageRetryJobSpec.scala | 2 +- .../services/ConfirmationServiceSpec.scala | 7 +-- .../services/OutboundServiceSpec.scala | 4 +- 17 files changed, 31 insertions(+), 91 deletions(-) diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/ProxiedHttpClient.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/ProxiedHttpClient.scala index 12f6a2c..1219d2e 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/ProxiedHttpClient.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/connectors/ProxiedHttpClient.scala @@ -18,7 +18,7 @@ package uk.gov.hmrc.apiplatformoutboundsoap.connectors import javax.inject.{Inject, Singleton} -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import play.api.Configuration import play.api.libs.ws.{WSClient, WSProxyServer} diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/repositories/OutboundMessageRepository.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/repositories/OutboundMessageRepository.scala index 8ee29e5..5cf57ce 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/repositories/OutboundMessageRepository.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/repositories/OutboundMessageRepository.scala @@ -22,9 +22,9 @@ import java.util.concurrent.TimeUnit import javax.inject.{Inject, Singleton} import scala.concurrent.{ExecutionContext, Future} -import akka.NotUsed -import akka.stream.alpakka.mongodb.scaladsl.MongoSource -import akka.stream.scaladsl.Source +import org.apache.pekko.NotUsed +import org.apache.pekko.stream.connectors.mongodb.scaladsl.MongoSource +import org.apache.pekko.stream.scaladsl.Source import org.bson.codecs.configuration.CodecRegistries._ import org.mongodb.scala.ReadPreference.primaryPreferred import org.mongodb.scala.bson.collection.immutable.Document diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/LockedScheduledJob.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/LockedScheduledJob.scala index 1b2f573..673087a 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/LockedScheduledJob.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/LockedScheduledJob.scala @@ -16,11 +16,9 @@ package uk.gov.hmrc.apiplatformoutboundsoap.scheduled -import scala.concurrent.duration.{DurationInt, FiniteDuration} +import scala.concurrent.duration.{Duration, DurationInt, FiniteDuration} import scala.concurrent.{ExecutionContext, Future} -import org.joda.time.Duration - import uk.gov.hmrc.mongo.lock.{LockService, MongoLockRepository} trait LockedScheduledJob { diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/RunningOfScheduledJobs.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/RunningOfScheduledJobs.scala index 370fe27..ad2b419 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/RunningOfScheduledJobs.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/RunningOfScheduledJobs.scala @@ -19,8 +19,8 @@ package uk.gov.hmrc.apiplatformoutboundsoap.scheduled import scala.concurrent.{ExecutionContext, Future} import scala.util.{Failure, Success} -import akka.actor.Cancellable import org.apache.commons.lang3.time.StopWatch +import org.apache.pekko.actor.{Cancellable, Scheduler} import play.api.inject.ApplicationLifecycle import play.api.{Application, Logging} @@ -30,7 +30,7 @@ import play.api.{Application, Logging} trait RunningOfScheduledJobs extends Logging { implicit val ec: ExecutionContext - lazy val scheduler: akka.actor.Scheduler = application.actorSystem.scheduler + lazy val scheduler: Scheduler = application.actorSystem.scheduler val application: Application val scheduledJobs: Seq[LockedScheduledJob] diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/SoapMessageRetryJob.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/SoapMessageRetryJob.scala index f545723..e7633f4 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/SoapMessageRetryJob.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/SoapMessageRetryJob.scala @@ -17,11 +17,9 @@ package uk.gov.hmrc.apiplatformoutboundsoap.scheduled import javax.inject.{Inject, Singleton} -import scala.concurrent.duration.FiniteDuration +import scala.concurrent.duration.{Duration, FiniteDuration} import scala.concurrent.{ExecutionContext, Future} -import org.joda.time.Duration - import uk.gov.hmrc.http.HeaderCarrier import uk.gov.hmrc.mongo.lock.MongoLockRepository @@ -31,7 +29,7 @@ import uk.gov.hmrc.apiplatformoutboundsoap.services.OutboundService @Singleton class SoapMessageRetryJob @Inject() (appConfig: AppConfig, override val lockRepository: MongoLockRepository, outboundService: OutboundService) extends LockedScheduledJob { - override val releaseLockAfter: Duration = Duration.standardSeconds(appConfig.retryJobLockDuration.toSeconds) + override val releaseLockAfter: Duration = appConfig.retryJobLockDuration override def name: String = "SoapMessageRetryJob" diff --git a/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala b/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala index 861b463..39286e2 100644 --- a/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala +++ b/app/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundService.scala @@ -26,9 +26,6 @@ import javax.xml.namespace.QName import scala.concurrent.{ExecutionContext, Future} import scala.jdk.CollectionConverters._ -import akka.Done -import akka.stream.Materializer -import akka.stream.scaladsl.Sink import org.apache.axiom.om.OMAbstractFactory.{getOMFactory, getSOAP12Factory} import org.apache.axiom.om._ import org.apache.axiom.om.util.AXIOMUtil.stringToOM @@ -36,6 +33,9 @@ import org.apache.axiom.soap.SOAPEnvelope import org.apache.axis2.addressing.AddressingConstants.Final.{WSAW_NAMESPACE, WSA_NAMESPACE} import org.apache.axis2.addressing.AddressingConstants._ import org.apache.axis2.wsdl.WSDLUtil +import org.apache.pekko.Done +import org.apache.pekko.stream.Materializer +import org.apache.pekko.stream.scaladsl.Sink import play.api.Logging import play.api.cache.AsyncCacheApi diff --git a/conf/application.conf b/conf/application.conf index b344d75..eec52a5 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -19,24 +19,8 @@ include "backend.conf" appName = api-platform-outbound-soap -# An ApplicationLoader that uses Guice to bootstrap the application. -play.application.loader = "uk.gov.hmrc.play.bootstrap.ApplicationLoader" - -# Primary entry point for all HTTP requests on Play applications -play.http.requestHandler = "uk.gov.hmrc.play.bootstrap.http.RequestHandler" - # Setting this as a first module to allow the other modules to use the play built in injector properly. play.modules.enabled += "uk.gov.hmrc.apiplatformoutboundsoap.config.InjectionModule" -# Provides an implementation of AuditConnector. Use `uk.gov.hmrc.play.bootstrap.AuditModule` or create your own. -# An audit connector must be provided. -play.modules.enabled += "uk.gov.hmrc.play.audit.AuditModule" - -# Provides an implementation of MetricsFilter. Use `uk.gov.hmrc.play.graphite.GraphiteMetricsModule` or create your own. -# A metric filter must be provided -play.modules.enabled += "uk.gov.hmrc.play.bootstrap.graphite.GraphiteMetricsModule" - -# Provides an implementation and configures all filters required by a Platform frontend microservice. -play.modules.enabled += "uk.gov.hmrc.play.bootstrap.backend.BackendModule" # Default http client play.modules.enabled += "uk.gov.hmrc.play.bootstrap.HttpClientModule" @@ -77,28 +61,8 @@ controllers { confidenceLevel = 300 } -# Metrics plugin settings - graphite reporting is configured on a per env basis -metrics { - name = ${appName} - rateUnit = SECONDS - durationUnit = SECONDS - showSamples = true - jvm = true - enabled = true -} - # Microservice specific config -auditing { - enabled = true - consumer { - baseUri { - host = localhost - port = 8100 - } - } -} - mongodb { uri = "mongodb://localhost:27017/api-platform-outbound-soap" } @@ -113,15 +77,6 @@ cryptoKeystoreLocation = "KeyStore.jks" enableMessageSigning = false microservice { - metrics { - graphite { - host = graphite - port = 2003 - prefix = play.${appName}. - enabled = false - } - } - services { auth { host = localhost diff --git a/conf/prod.routes b/conf/prod.routes index 82d34fd..a055c15 100644 --- a/conf/prod.routes +++ b/conf/prod.routes @@ -1,5 +1,3 @@ # Add all the application routes to the app.routes file -> / app.Routes -> / health.Routes - -GET /admin/metrics com.kenshoo.play.metrics.MetricsController.metrics diff --git a/it/uk/gov/hmrc/apiplatformoutboundsoap/repositories/OutboundMessageRepositoryISpec.scala b/it/uk/gov/hmrc/apiplatformoutboundsoap/repositories/OutboundMessageRepositoryISpec.scala index ff89048..ed31349 100644 --- a/it/uk/gov/hmrc/apiplatformoutboundsoap/repositories/OutboundMessageRepositoryISpec.scala +++ b/it/uk/gov/hmrc/apiplatformoutboundsoap/repositories/OutboundMessageRepositoryISpec.scala @@ -21,8 +21,8 @@ import java.time.temporal.ChronoUnit import java.time.{Duration, Instant} import java.util.UUID.randomUUID -import akka.stream.Materializer -import akka.stream.scaladsl.Sink +import org.apache.pekko.stream.Materializer +import org.apache.pekko.stream.scaladsl.Sink import org.mongodb.scala.MongoWriteException import org.mongodb.scala.ReadPreference.primaryPreferred import org.mongodb.scala.bson.BsonBoolean diff --git a/project/AppDependencies.scala b/project/AppDependencies.scala index 08f35bb..5eec6fc 100644 --- a/project/AppDependencies.scala +++ b/project/AppDependencies.scala @@ -1,30 +1,24 @@ -import play.core.PlayVersion.current import play.sbt.PlayImport.caffeine import sbt._ object AppDependencies { - val bootstrapPlayVersion = "7.12.0" + val bootstrapPlayVersion = "8.4.0" val mongoVersion = "1.7.0" val compile = Seq( - "uk.gov.hmrc" %% "bootstrap-backend-play-28" % bootstrapPlayVersion, - "uk.gov.hmrc.mongo" %% "hmrc-mongo-play-28" % mongoVersion, - "com.typesafe.play" %% "play-json-joda" % "2.9.2", - "com.lightbend.akka" %% "akka-stream-alpakka-mongodb" % "3.0.4", + "uk.gov.hmrc" %% "bootstrap-backend-play-30" % bootstrapPlayVersion, + "uk.gov.hmrc.mongo" %% "hmrc-mongo-play-30" % mongoVersion, + "org.apache.pekko" %% "pekko-connectors-mongodb" % "1.0.2", "org.apache.axis2" % "axis2-kernel" % "1.8.0", "org.apache.wss4j" % "wss4j-ws-security-dom" % "2.4.1", caffeine ) val test = Seq( - "uk.gov.hmrc" %% "bootstrap-test-play-28" % bootstrapPlayVersion % "test, it", - "com.typesafe.play" %% "play-test" % current % "test, it", + "uk.gov.hmrc" %% "bootstrap-test-play-30" % bootstrapPlayVersion % "test, it", "org.mockito" %% "mockito-scala-scalatest" % "1.17.29" % "test, it", - "org.scalatest" %% "scalatest" % "3.2.17" % "test, it", - "com.vladsch.flexmark" % "flexmark-all" % "0.62.2" % "test, it", - "org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % "test, it", "org.xmlunit" % "xmlunit-core" % "2.9.0" % "test, it", - "uk.gov.hmrc.mongo" %% "hmrc-mongo-test-play-28" % mongoVersion % "it" + "uk.gov.hmrc.mongo" %% "hmrc-mongo-test-play-30" % mongoVersion % "it" ) val axiomVersion = "1.4.0" diff --git a/project/plugins.sbt b/project/plugins.sbt index b8df339..a31e7e8 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -7,8 +7,8 @@ resolvers ++= Seq( resolvers += Resolver.typesafeRepo("releases") addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.20.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.4.0") -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.21") +addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0") +addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.1") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9") addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") @@ -16,4 +16,4 @@ addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1") addDependencyTreePlugin -ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always \ No newline at end of file +ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always diff --git a/test/uk/gov/hmrc/apiplatformoutboundsoap/connectors/ProxiedHttpClientSpec.scala b/test/uk/gov/hmrc/apiplatformoutboundsoap/connectors/ProxiedHttpClientSpec.scala index 9f28781..e7b9069 100644 --- a/test/uk/gov/hmrc/apiplatformoutboundsoap/connectors/ProxiedHttpClientSpec.scala +++ b/test/uk/gov/hmrc/apiplatformoutboundsoap/connectors/ProxiedHttpClientSpec.scala @@ -16,7 +16,7 @@ package uk.gov.hmrc.apiplatformoutboundsoap.connectors -import akka.actor.ActorSystem +import org.apache.pekko.actor.ActorSystem import org.scalatest.OptionValues import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec diff --git a/test/uk/gov/hmrc/apiplatformoutboundsoap/controllers/ConfirmationControllerSpec.scala b/test/uk/gov/hmrc/apiplatformoutboundsoap/controllers/ConfirmationControllerSpec.scala index 1b88df7..3eaf6f7 100644 --- a/test/uk/gov/hmrc/apiplatformoutboundsoap/controllers/ConfirmationControllerSpec.scala +++ b/test/uk/gov/hmrc/apiplatformoutboundsoap/controllers/ConfirmationControllerSpec.scala @@ -20,7 +20,7 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import scala.xml.{Elem, NodeSeq, XML} -import akka.stream.Materializer +import org.apache.pekko.stream.Materializer import org.mockito.{ArgumentCaptor, ArgumentMatchersSugar, MockitoSugar} import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec diff --git a/test/uk/gov/hmrc/apiplatformoutboundsoap/controllers/OutboundControllerSpec.scala b/test/uk/gov/hmrc/apiplatformoutboundsoap/controllers/OutboundControllerSpec.scala index 0277360..71800b8 100644 --- a/test/uk/gov/hmrc/apiplatformoutboundsoap/controllers/OutboundControllerSpec.scala +++ b/test/uk/gov/hmrc/apiplatformoutboundsoap/controllers/OutboundControllerSpec.scala @@ -23,7 +23,7 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import scala.concurrent.Future.{failed, successful} -import akka.stream.Materializer +import org.apache.pekko.stream.Materializer import org.mockito.captor.{ArgCaptor, Captor} import org.mockito.scalatest.ResetMocksAfterEachTest import org.mockito.{ArgumentCaptor, ArgumentMatchersSugar, MockitoSugar} diff --git a/test/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/SoapMessageRetryJobSpec.scala b/test/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/SoapMessageRetryJobSpec.scala index 8428c0b..b34e9d2 100644 --- a/test/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/SoapMessageRetryJobSpec.scala +++ b/test/uk/gov/hmrc/apiplatformoutboundsoap/scheduled/SoapMessageRetryJobSpec.scala @@ -21,7 +21,7 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future.{failed, successful} import scala.concurrent.duration.Duration -import akka.Done +import org.apache.pekko.Done import org.mockito.{ArgumentMatchersSugar, MockitoSugar} import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec diff --git a/test/uk/gov/hmrc/apiplatformoutboundsoap/services/ConfirmationServiceSpec.scala b/test/uk/gov/hmrc/apiplatformoutboundsoap/services/ConfirmationServiceSpec.scala index 6481510..316c6d2 100644 --- a/test/uk/gov/hmrc/apiplatformoutboundsoap/services/ConfirmationServiceSpec.scala +++ b/test/uk/gov/hmrc/apiplatformoutboundsoap/services/ConfirmationServiceSpec.scala @@ -22,9 +22,7 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future.successful import scala.xml.Elem -import akka.stream.Materializer -import org.joda.time.DateTime -import org.joda.time.DateTimeZone.UTC +import org.apache.pekko.stream.Materializer import org.mockito.{ArgumentMatchersSugar, MockitoSugar} import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec @@ -53,8 +51,7 @@ class ConfirmationServiceSpec extends AnyWordSpec with Matchers with GuiceOneApp val appConfigMock: AppConfig = mock[AppConfig] val httpStatus: Int = 200 - val expectedCreateDateTime: DateTime = DateTime.now(UTC) - val expectedGlobalId: UUID = UUID.randomUUID + val expectedGlobalId: UUID = UUID.randomUUID val underTest: ConfirmationService = new ConfirmationService(outboundMessageRepository = outboundMessageRepositoryMock, notificationCallbackConnector = notificationCallbackConnectorMock) diff --git a/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala b/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala index fd6c043..13f696f 100644 --- a/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala +++ b/test/uk/gov/hmrc/apiplatformoutboundsoap/services/OutboundServiceSpec.scala @@ -25,10 +25,10 @@ import scala.concurrent.Future import scala.concurrent.Future.successful import scala.concurrent.duration.Duration -import akka.stream.Materializer -import akka.stream.scaladsl.Source.{fromIterator, single} import com.mongodb.client.result.InsertOneResult import org.apache.axiom.soap.SOAPEnvelope +import org.apache.pekko.stream.Materializer +import org.apache.pekko.stream.scaladsl.Source.{fromIterator, single} import org.mockito.{ArgumentCaptor, ArgumentMatchersSugar, MockitoSugar} import org.mongodb.scala.bson.BsonNumber import org.scalatest.matchers.should.Matchers