diff --git a/README.md b/README.md index 186d8fc714a..a5cb50ee02d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Run `yarn test` in `fronts-client` folder. See [fronts-client](/fronts-client) f ### Pressing fronts - Before fronts can appear on site, they have to be pressed by Facia-Press which lives on the frontend account. -- The fronts tool sends events to an sqs queue which Facia-Press listens. You can read more about Facia-Press [here](https://github.com/guardian/frontend/blob/ad74a1da567f047b7b824650e6e1be0f0262952b/docs/02-architecture/01-applications-architecture.md). +- The fronts tool sends events to an SNS topic, which is subscribed to by a queue (in frontend account) to which Facia-Press listens. You can read more about Facia-Press [here](https://github.com/guardian/frontend/blob/ad74a1da567f047b7b824650e6e1be0f0262952b/docs/02-architecture/01-applications-architecture.md). - If you are adding a new kind of content to a front or changing the front configuration, you should check that the front can still be pressed. @@ -57,9 +57,8 @@ Run `yarn test` in `fronts-client` folder. See [fronts-client](/fronts-client) f - You can remove this property from the front in the fronts config page. - Select the front your are trying to view on the config page, click on the edit-metadata link, and deselect the `is hidden`-property. -- If you are developing locally and do not have frontend credentials from janus, the fronts tool won't have permissions to push events to the sqs queue that Facia-Press reads from. To test that a front is pressed, you will have to deploy your changes to code, and test the code from there. - - +- Since the SNS topic lives in the fronts account, CODE fronts should be pressed automatically when running locally. +- ## Different tools in this codebase ### The Fronts Tool diff --git a/app/Components.scala b/app/Components.scala index 2e081ee4b50..61e919cd61b 100644 --- a/app/Components.scala +++ b/app/Components.scala @@ -77,9 +77,8 @@ class AppComponents(context: Context, val config: ApplicationConfiguration) val containers = new Containers(fixedContainers) val containerService = new ContainerService(containers) val collectionService = new CollectionService(frontsApi, containerService) - val faciaPressQueue = new FaciaPressQueue(config) val faciaPressTopic = new FaciaPressTopic(config) - val faciaPress = new FaciaPress(faciaPressQueue, faciaPressTopic, configAgent) + val faciaPress = new FaciaPress(faciaPressTopic, configAgent) val updateActions = new UpdateActions(faciaApiIO, frontsApi, config, configAgent, structuredLogger) val updateManager = new UpdateManager(updateActions, configAgent, s3FrontsApi) val cloudwatch = new CloudWatch(config, awsEndpoints) @@ -93,7 +92,7 @@ class AppComponents(context: Context, val config: ApplicationConfiguration) val defaults = new DefaultsController(acl, isDev, this) val faciaCapiProxy = new FaciaContentApiProxy(capi, this) val faciaTool = new FaciaToolController(acl, frontsApi, collectionService, faciaApiIO, updateActions, breakingNewsUpdate, - structuredLogger, faciaPress, faciaPressQueue, faciaPressTopic, configAgent, s3FrontsApi, this) + structuredLogger, faciaPress, faciaPressTopic, configAgent, s3FrontsApi, this) val front = new FrontController(acl, structuredLogger, updateManager, press, this) val pandaAuth = new PandaAuthController(this) val status = new StatusController(this) diff --git a/app/conf/Configuration.scala b/app/conf/Configuration.scala index c762b343457..2cae51d668c 100644 --- a/app/conf/Configuration.scala +++ b/app/conf/Configuration.scala @@ -227,7 +227,6 @@ class ApplicationConfiguration(val playConfiguration: PlayConfiguration, val isP object faciatool { lazy val breakingNewsFront = "breaking-news" - lazy val frontPressToolQueue = getString("frontpress.sqs.tool_queue_url") lazy val frontPressToolTopic = getString("faciatool.sns.tool_topic_arn") lazy val publishEventsQueue = getMandatoryString("publish_events.queue_url") lazy val showTestContainers = getBoolean("faciatool.show_test_containers").getOrElse(false) diff --git a/app/controllers/FaciaToolController.scala b/app/controllers/FaciaToolController.scala index 80a62404b99..83c6340e5bf 100644 --- a/app/controllers/FaciaToolController.scala +++ b/app/controllers/FaciaToolController.scala @@ -20,21 +20,21 @@ import scala.concurrent.{ExecutionContext, Future} import permissions.CollectionPermissions class FaciaToolController( - val acl: Acl, - val frontsApi: FrontsApi, - val collectionService: CollectionService, - val faciaApiIO: FaciaApiIO, - val updateActions: UpdateActions, - breakingNewsUpdate: BreakingNewsUpdate, - val structuredLogger: StructuredLogger, - val faciaPress: FaciaPress, - val faciaPressQueue: FaciaPressQueue, - val FaciaPressTopic: FaciaPressTopic, - val configAgent: ConfigAgent, - val s3FrontsApi: S3FrontsApi, - val deps: BaseFaciaControllerComponents - )(implicit ec: ExecutionContext) - extends BaseFaciaController(deps) with BreakingNewsEditCollectionsCheck with ModifyCollectionsPermissionsCheck with Logging { + val acl: Acl, + val frontsApi: FrontsApi, + val collectionService: CollectionService, + val faciaApiIO: FaciaApiIO, + val updateActions: UpdateActions, + breakingNewsUpdate: BreakingNewsUpdate, + val structuredLogger: StructuredLogger, + val faciaPress: FaciaPress, + val faciaPressTopic: FaciaPressTopic, + val configAgent: ConfigAgent, + val s3FrontsApi: S3FrontsApi, + val deps: BaseFaciaControllerComponents +)( + implicit ec: ExecutionContext +) extends BaseFaciaController(deps) with BreakingNewsEditCollectionsCheck with ModifyCollectionsPermissionsCheck with Logging { private val collectionPermissions = CollectionPermissions(configAgent.get) @@ -246,14 +246,12 @@ class FaciaToolController( } def pressLivePath(path: String) = AccessAPIAuthAction { request => - faciaPressQueue.enqueue(PressJob(FrontPath(path), Live, forceConfigUpdate = Option(true))) - FaciaPressTopic.publish(PressJob(FrontPath(path), Live, forceConfigUpdate = Option(true))) + faciaPressTopic.publish(PressJob(FrontPath(path), Live, forceConfigUpdate = Option(true))) NoCache(Ok) } def pressDraftPath(path: String) = AccessAPIAuthAction { request => - faciaPressQueue.enqueue(PressJob(FrontPath(path), Draft, forceConfigUpdate = Option(true))) - FaciaPressTopic.publish(PressJob(FrontPath(path), Draft, forceConfigUpdate = Option(true))) + faciaPressTopic.publish(PressJob(FrontPath(path), Draft, forceConfigUpdate = Option(true))) NoCache(Ok) } diff --git a/app/services/FaciaPress.scala b/app/services/FaciaPress.scala index aa1107093ce..fa772386a05 100644 --- a/app/services/FaciaPress.scala +++ b/app/services/FaciaPress.scala @@ -29,28 +29,6 @@ object PressCommand { def forOneId(id: String): PressCommand = PressCommand(Set(id)) } -class FaciaPressQueue(val config: ApplicationConfiguration) { - val maybeQueue = config.faciatool.frontPressToolQueue map { queueUrl => - val credentials = config.aws.frontendAccountCredentials - JsonMessageQueue[PressJob]( - AmazonSQSAsyncClientBuilder.standard() - .withCredentials(credentials) - .withRegion(Regions.EU_WEST_1).build(), - queueUrl - ) - } - - def enqueue(job: PressJob): Future[SendMessageResult] = { - maybeQueue match { - case Some(queue) => - queue.send(job) - - case None => - Future.failed(new RuntimeException("`facia.press.queue_url` property not in config, could not enqueue job.")) - } - } -} - class FaciaPressTopic(val config: ApplicationConfiguration) { val maybeTopic = config.faciatool.frontPressToolTopic map { topicArn => val credentials = config.aws.cmsFrontsAccountCredentials @@ -73,37 +51,35 @@ class FaciaPressTopic(val config: ApplicationConfiguration) { } -class FaciaPress(val faciaPressQueue: FaciaPressQueue, val faciaPressTopic: FaciaPressTopic, val configAgent: ConfigAgent) extends Logging { - def press(pressCommand: PressCommand): Future[List[SendMessageResult]] = { +class FaciaPress(val faciaPressTopic: FaciaPressTopic, val configAgent: ConfigAgent) extends Logging { + def press(pressCommand: PressCommand): Future[List[PublishResult]] = { configAgent.refreshAndReturn() flatMap { _ => val paths: Set[String] = for { id <- pressCommand.collectionIds path <- configAgent.getConfigsUsingCollectionId(id) } yield path - def sendEvents(pressType: PressType) = { - val result = Future.traverse(paths.filter(_ => pressType match { + def sendEvents(pressType: PressType) = Future.traverse( + paths.filter(_ => pressType match { case Live => pressCommand.live case Draft => pressCommand.draft - })) { path => + }) + ) { path => val event = PressJob(FrontPath(path), pressType, forceConfigUpdate = pressCommand.forceConfigUpdate) - faciaPressTopic.publish(event).onComplete { // fire & forget (but log) - case Failure(error) => logger.error(s"Error publishing to the SNS topic, $pressType event: $event", error) - case Success(_) => logger.info(s"Published to the SNS topic, $pressType event: $event") + val publishResultFuture = faciaPressTopic.publish(event) + + publishResultFuture.onComplete { + case Failure(error) => + logger.error(s"Error publishing to the SNS topic, $pressType event: $event", error) + EnqueuePressFailure.increment() + case Success(_) => + logger.info(s"Published to the SNS topic, $pressType event: $event") + EnqueuePressSuccess.increment() } - faciaPressQueue.enqueue(event) - } - result.onComplete { - case Failure(error) => - EnqueuePressFailure.increment() - logger.error(s"Error manually pressing $pressType collection through update from tool", error) - case Success(_) => - EnqueuePressSuccess.increment() + publishResultFuture } - result - } for { live <- sendEvents(Live) diff --git a/conf/application.conf b/conf/application.conf index 37f8172ba99..19d8218d6b4 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -112,11 +112,6 @@ PROD { permissions.cache: "permissions-cache/PROD" } -frontpress.sqs.tool_queue_url="https://sqs.eu-west-1.amazonaws.com/642631414762/frontend-CODE-FrontPressToolJobQueue-MY0QBVOOIECN" -PROD { - frontpress.sqs.tool_queue_url="https://sqs.eu-west-1.amazonaws.com/642631414762/frontend-PROD-FrontPressToolJobQueue-1V3225WE1LWQI" -} - publish_events.queue_url="https://sqs.eu-west-1.amazonaws.com/163592447864/publish-events-CODE" PROD { publish_events.queue_url="https://sqs.eu-west-1.amazonaws.com/163592447864/publish-events-PROD"