Skip to content

Commit

Permalink
Merge pull request #965 from hmrc/BDOG-3264
Browse files Browse the repository at this point in the history
BDOG-3264: Show JRE vs JDK for Java versions
  • Loading branch information
BriWak authored Nov 18, 2024
2 parents 10a24c7 + 2fd0fac commit 54ed2c8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object JdkVersion:

case class JdkUsageByEnv(
env : SlugInfoFlag,
usage: Map[(Version, Vendor), Int]
usage: Map[(Version, Vendor, Kind), Int]
)

enum Vendor(val asString: String, val imgPath: String):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
val currentIndex = eventsForEnv.indexWhere(e => e.deploymentId == id)
if (currentIndex > 0) {
val previousVersion = eventsForEnv(currentIndex - 1).version
slugInfo.find(_.version == previousVersion).fold("unknown")(x => s"${x.java.version} ${x.java.vendor.asString}")
slugInfo.find(_.version == previousVersion).fold("unknown")(x => s"${x.java.version} ${x.java.vendor.asString} (${x.java.kind.asString})")
} else {
val currentVersion = eventsForEnv(currentIndex).version
slugInfo.find(_.version == currentVersion).fold("unknown")(x => s"${x.java.version} ${x.java.vendor.asString}")
slugInfo.find(_.version == currentVersion).fold("unknown")(x => s"${x.java.version} ${x.java.vendor.asString} (${x.java.kind.asString})")
}
}

Expand Down Expand Up @@ -142,7 +142,7 @@ <h1 class="page-heading mt-4">Deployment Timeline @service.map { s => <a id="lin
'@{e.displayStart.getOrElse(e.start).displayFormat}',
'@{e.displayEnd.getOrElse(e.end).displayFormat}',
@{java.time.Duration.between(e.displayStart.getOrElse(e.start), e.displayEnd.getOrElse(e.end)).toDays},
'@{slugInfo.find(_.version == e.version).fold("unknown")(x => s"${x.java.version} ${x.java.vendor.asString}")}',
'@{slugInfo.find(_.version == e.version).fold("unknown")(x => s"${x.java.version} ${x.java.vendor.asString} (${x.java.kind.asString})")}',
'@previousJavaVersion(e.env, e.deploymentId, events, slugInfo)',
'@{e.deploymentConfigChanged.getOrElse("")}',
'@{e.configChanged.getOrElse("")}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
@defining((jvmChanges._1, jvmChanges._2)) { case (oldJvm, newJvm) =>
@defining(oldJvm.map(_ != newJvm).getOrElse(true)){ isJvmChanged =>
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseJvmChanges" aria-expanded="false" aria-controls="collapseJvmChanges" @if(!isJvmChanged) {disabled}>
JVM: @newJvm.version @newJvm.vendor.asString
JVM: @newJvm.version @newJvm.vendor.asString (@newJvm.kind.asString)
@changesBadge(if (isJvmChanged) 1 else 0)
</button>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class DependenciesService @Inject() (
def getJdkCountsForEnv(env: SlugInfoFlag, teamName: Option[TeamName])(using HeaderCarrier): Future[JdkUsageByEnv] =
for
versions <- serviceDependenciesConnector.getJdkVersions(teamName, env)
counts = versions.groupBy(v => (v.version, v.vendor)).view.mapValues(_.length).toMap
counts = versions.groupBy(v => (v.version, v.vendor, v.kind)).view.mapValues(_.length).toMap
yield JdkUsageByEnv(env, counts)

def getSbtVersions(flag: SlugInfoFlag, teamName: Option[TeamName])(using HeaderCarrier): Future[List[SbtVersion]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

@import uk.gov.hmrc.cataloguefrontend.{routes => appRoutes}
@import uk.gov.hmrc.cataloguefrontend.connector.GitHubTeam
@import uk.gov.hmrc.cataloguefrontend.connector.model.{JdkUsageByEnv, Vendor}
@import uk.gov.hmrc.cataloguefrontend.connector.model.{JdkUsageByEnv, Vendor, Kind}

@this()

@(envdata : Seq[JdkUsageByEnv],
jdks : Seq[(Version, Vendor)],
jdks : Seq[(Version, Vendor, Kind)],
teams : Seq[GitHubTeam],
selectedTeamName: Option[TeamName]
)(implicit
Expand Down Expand Up @@ -61,8 +61,11 @@ <h1 id="jdk-header" class="page-heading mt-4">JDK Versions Across Environments</
<thead>
<tr>
<th>Environment</th>
@for((version, vendor) <- jdks) {
<th><img src="@routes.Assets.versioned(vendor.imgPath)" width="68px" alt="@vendor.asString"/>@version</th>
@for((version, vendor) <- jdks.map(j => (j._1, j._2)).distinct) {
<th title="@{jdks.filter(j => j._1 == version && j._2 == vendor).map(_._3).mkString(" and ")}">
<img src="@routes.Assets.versioned(vendor.imgPath)" width="68px" alt="@vendor.asString"/>
@version
</th>
}
</tr>

Expand All @@ -72,7 +75,9 @@ <h1 id="jdk-header" class="page-heading mt-4">JDK Versions Across Environments</
@for(d <- envdata) {
<tr>
<td><a href="@appRoutes.JdkVersionController.findLatestVersions(d.env.asString, selectedTeamName)">@d.env.displayString</a></td>
@for(jdk <- jdks) { <td>@{d.usage.getOrElse(jdk, 0)}</td>}
@for((version, vendor) <- jdks.map(j => (j._1, j._2)).distinct) {
<td>@{d.usage.getOrElse((version, vendor, Kind.JRE), 0) + d.usage.getOrElse((version, vendor, Kind.JDK), 0)}</td>
}
</tr>
}
</tbody>
Expand Down Expand Up @@ -102,11 +107,11 @@ <h1 id="jdk-header" class="page-heading mt-4">JDK Versions Across Environments</
}

function drawStackedChart(stack) {

let data = new google.visualization.DataTable();
data.addColumn('string', 'Environment');
@for((version, vendor) <- jdks) {
data.addColumn('number','@version @vendor.asString');

@for((version, vendor, kind) <- jdks) {
data.addColumn('number','@version @vendor.asString (@kind)');
}

data.addRows([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class SlugInfoServiceSpec

val res = boot.service.getJdkCountsForEnv(env = SlugInfoFlag.Latest, teamName = None).futureValue

res.usage((Version("1.181.1"), Vendor.Oracle )) shouldBe 2
res.usage((Version("1.191.1"), Vendor.OpenJDK)) shouldBe 1
res.usage((Version("1.121.1"), Vendor.OpenJDK)) shouldBe 1
res.usage((Version("1.181.1"), Vendor.Oracle, Kind.JDK)) shouldBe 2
res.usage((Version("1.191.1"), Vendor.OpenJDK, Kind.JRE)) shouldBe 1
res.usage((Version("1.121.1"), Vendor.OpenJDK, Kind.JRE)) shouldBe 1
}

"still returns a value when no matches are found for env" in {
Expand All @@ -114,7 +114,7 @@ class SlugInfoServiceSpec
when(boot.mockedServiceDependenciesConnector.getJdkVersions(teamName = None, flag = SlugInfoFlag.Latest))
.thenReturn(Future.successful(List.empty[JdkVersion]))

boot.service.getJdkCountsForEnv(env = SlugInfoFlag.Latest, teamName = None).futureValue shouldBe JdkUsageByEnv(SlugInfoFlag.Latest, Map.empty[(Version, Vendor), Int])
boot.service.getJdkCountsForEnv(env = SlugInfoFlag.Latest, teamName = None).futureValue shouldBe JdkUsageByEnv(SlugInfoFlag.Latest, Map.empty[(Version, Vendor, Kind), Int])
}
}

Expand Down

0 comments on commit 54ed2c8

Please sign in to comment.