Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bdog 3210 #943

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import uk.gov.hmrc.cataloguefrontend.serviceconfigs.{ServiceConfigsConnector, Se
import uk.gov.hmrc.cataloguefrontend.shuttering.{ShutterService, ShutterState, ShutterType}
import uk.gov.hmrc.cataloguefrontend.util.TelemetryLinks
import uk.gov.hmrc.cataloguefrontend.servicecommissioningstatus.{LifecycleStatus, ServiceCommissioningStatusConnector}
import uk.gov.hmrc.cataloguefrontend.vulnerabilities.{TotalVulnerabilityCount, VulnerabilitiesConnector, VulnerabilitySummary, CurationStatus}
import uk.gov.hmrc.cataloguefrontend.vulnerabilities.VulnerabilitiesConnector
import uk.gov.hmrc.cataloguefrontend.whatsrunningwhere.WhatsRunningWhereService
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.internalauth.client.{FrontendAuthComponents, IAAction, Predicate, Resource, Retrieval}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package uk.gov.hmrc.cataloguefrontend.dependency

import cats.data.EitherT
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import play.utils.UriEncoding
import uk.gov.hmrc.cataloguefrontend.auth.CatalogueAuthBuilders
import uk.gov.hmrc.cataloguefrontend.connector.model.{DependencyScope, given}
import uk.gov.hmrc.cataloguefrontend.dependency.view.html.{DependencyGraphsPage, DependenciesPage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,7 @@ class DeployServiceController @Inject()(
configWarnings <- EitherT
.right[Result](serviceConfigsService.configWarnings(formObject.serviceName, Seq(formObject.environment), Some(formObject.version), latest = true))
vulnerabilities <- EitherT
.right[Result]:
vulnerabilitiesConnector
.vulnerabilitySummaries(serviceQuery = Some(formObject.serviceName.asString), version = Some(formObject.version), curationStatus = Some(CurationStatus.ActionRequired))
.map:
_.flatMap:
case xs if xs.isEmpty && !releases.exists(_.version == formObject.version) => None
case xs => Some(xs)
.right[Result](vulnerabilitiesConnector.vulnerabilitySummaries(serviceQuery = Some(formObject.serviceName.asString), version = Some(formObject.version), curationStatus = Some(CurationStatus.ActionRequired)))
yield
Ok(deployServicePage(
form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
package uk.gov.hmrc.cataloguefrontend.deployments

import cats.implicits._
import play.api.Logging
import play.api.mvc._

import uk.gov.hmrc.cataloguefrontend.auth.CatalogueAuthBuilders
import uk.gov.hmrc.cataloguefrontend.connector.{RepoType, ServiceDependenciesConnector, TeamsAndRepositoriesConnector}
import uk.gov.hmrc.cataloguefrontend.deployments.view.html.DeploymentTimelinePage
import uk.gov.hmrc.cataloguefrontend.model.{Environment, ServiceName}
import uk.gov.hmrc.cataloguefrontend.connector.{GitHubProxyConnector, RepoType, ServiceDependenciesConnector, TeamsAndRepositoriesConnector}
import uk.gov.hmrc.cataloguefrontend.deployments.view.html.{DeploymentTimelinePage, DeploymentTimelineSelectPage}
import uk.gov.hmrc.cataloguefrontend.model.{Environment, ServiceName, Version}
import uk.gov.hmrc.cataloguefrontend.service.ServiceDependencies
import uk.gov.hmrc.cataloguefrontend.serviceconfigs.ServiceConfigsService
import uk.gov.hmrc.cataloguefrontend.util.DateHelper.{atStartOfDayInstant, atEndOfDayInstant}
import uk.gov.hmrc.cataloguefrontend.whatsrunningwhere.DeploymentTimelineEvent
import uk.gov.hmrc.internalauth.client.FrontendAuthComponents
Expand All @@ -32,43 +34,66 @@ import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
import java.time.LocalDate
import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal

@Singleton
class DeploymentTimelineController @Inject()(
teamsAndRepositoriesConnector: TeamsAndRepositoriesConnector,
serviceDependenciesConnector : ServiceDependenciesConnector,
deploymentGraphService : DeploymentGraphService,
deploymentTimelinePage : DeploymentTimelinePage,
override val mcc : MessagesControllerComponents,
override val auth : FrontendAuthComponents
serviceDependenciesConnector : ServiceDependenciesConnector
, teamsAndRepositoriesConnector: TeamsAndRepositoriesConnector
, gitHubProxyConnector : GitHubProxyConnector
, deploymentGraphService : DeploymentGraphService
, serviceConfigsService : ServiceConfigsService
, deploymentTimelinePage : DeploymentTimelinePage
, deploymentTimelineSelectPage : DeploymentTimelineSelectPage
, override val mcc : MessagesControllerComponents
, override val auth : FrontendAuthComponents
)(using
override val ec: ExecutionContext
) extends FrontendController(mcc)
with CatalogueAuthBuilders:
with CatalogueAuthBuilders
with Logging:

def graph(service: Option[ServiceName], to: LocalDate, from: LocalDate) =
BasicAuthAction.async { implicit request =>
val start = to.atStartOfDayInstant
val end = from.atEndOfDayInstant
BasicAuthAction.async:
implicit request =>
val start = to.atStartOfDayInstant
val end = from.atEndOfDayInstant

for
services <- teamsAndRepositoriesConnector.allRepositories(repoType = Some(RepoType.Service))
serviceNames = services.map(s => ServiceName(s.name))
data <- service match
case Some(service) if start.isBefore(end) =>
deploymentGraphService.findEvents(service, start, end).map(_.filter(_.env != Environment.Integration)) // filter as only platform teams are interested in this env
case _ =>
Future.successful(Seq.empty[DeploymentTimelineEvent])
slugInfo <- data
.groupBy(_.version)
.keys
.toList
.foldLeftM[Future, Seq[ServiceDependencies]](Seq.empty): (xs, v) =>
service
.fold(Future.successful(Option.empty[ServiceDependencies])): serviceName =>
serviceDependenciesConnector.getSlugInfo(serviceName, Some(v))
.map:
xs ++ _.toSeq
view = deploymentTimelinePage(service, start, end, data, slugInfo, serviceNames)
yield Ok(view)
}
for
services <- teamsAndRepositoriesConnector.allRepositories(repoType = Some(RepoType.Service))
serviceNames = services.map(s => ServiceName(s.name))
events <- service match
case Some(service) if start.isBefore(end) =>
deploymentGraphService.findEvents(service, start, end).map(_.filter(_.env != Environment.Integration)) // filter as only platform teams are interested in this env
case _ =>
Future.successful(Seq.empty[DeploymentTimelineEvent])
slugInfo <- events
.groupBy(_.version)
.keys
.toList
.foldLeftM[Future, Seq[ServiceDependencies]](Seq.empty): (xs, v) =>
service
.fold(Future.successful(Option.empty[ServiceDependencies])): serviceName =>
serviceDependenciesConnector.getSlugInfo(serviceName, Some(v))
.map:
xs ++ _.toSeq
yield Ok(deploymentTimelinePage(service, start, end, events, slugInfo, serviceNames))

def graphSelect(serviceName: ServiceName, deploymentId: String, fromDeploymentId: Option[String]) =
BasicAuthAction.async:
implicit request =>
for
configChanges <- serviceConfigsService.configChanges(deploymentId, fromDeploymentId)
previousVersion = configChanges.fromVersion.getOrElse(Version("0.1.0"))
deployedVersion = configChanges.toVersion
environment = configChanges.env.environment
deployedSlug <- serviceDependenciesConnector.getSlugInfo(serviceName, Some(deployedVersion))
previousSlug <- serviceDependenciesConnector.getSlugInfo(serviceName, Some(previousVersion))
gitHubCompare <- gitHubProxyConnector
.compare(serviceName.asString, v1 = previousVersion, v2 = deployedVersion)
.recover:
case NonFatal(ex) => logger.error(s"Could not call git compare ${ex.getMessage}", ex); None
jvmChanges = (previousSlug.map(_.java), deployedSlug.get.java)
deploymentChanges <- serviceConfigsService.deploymentConfigChanges(serviceName, environment)
yield
Ok(deploymentTimelineSelectPage(serviceName, environment, Some(previousVersion), deployedVersion, gitHubCompare, jvmChanges, deploymentChanges, configChanges))
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ object TimelinePalette:
"#f0b302",
"#d9ac0b",
"#e75e98",
"#7a6ab7",
"#8f924a",
"#b365a4",
"#419ce6",
Expand Down
Loading