Skip to content

Commit

Permalink
Merge pull request #1220 from adoptium/main
Browse files Browse the repository at this point in the history
merge main to production
  • Loading branch information
gdams authored Nov 18, 2024
2 parents 76ed61e + de9abf3 commit da9e39a
Show file tree
Hide file tree
Showing 134 changed files with 1,716 additions and 817 deletions.
21 changes: 6 additions & 15 deletions .github/actions/azure-login/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,22 @@ inputs:
AZURE_SUBSCRIPTION_ID:
description: 'Azure Subscription ID'
required: true
AZURE_CLIENT_ID:
description: 'Azure Client ID'
required: true
AZURE_CLIENT_SECRET:
description: 'Azure Client Secret'
required: true
runs:
using: composite
steps:
- name: Login to our Azure subscription.
uses: azure/login@6b2456866fc08b011acb422a92a4aa20e2c4de32 # v2.1.0
uses: azure/login@a65d910e8af852a8061c627c456678983e180302 # v2.2.0
with:
client-id: ${{ inputs.AZURE_CLIENT_ID_OIDC }}
tenant-id: ${{ inputs.AZURE_TENANT_ID }}
subscription-id: ${{ inputs.AZURE_SUBSCRIPTION_ID }}

- name: Login to Azure Container Registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
registry: adoptopenjdkacr.azurecr.io
username: ${{ inputs.AZURE_CLIENT_ID }}
password: ${{ inputs.AZURE_CLIENT_SECRET }}
shell: bash
run: az acr login --name adoptopenjdkacr

- name: Set the target Azure Kubernetes Service (AKS) cluster.
uses: azure/aks-set-context@37037e33d3a2fc08abe40c887d81c3f6e1eb93b9 # v4.0.0
uses: azure/aks-set-context@1cf43fa609aaef0617c6a12deda238b920e926b0 # v4.0.1
with:
resource-group: adopt-api
cluster-name: aksff92
resource-group: adoptium-api
cluster-name: adoptium-api
17 changes: 0 additions & 17 deletions .github/actions/do-login/action.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/actions/docker-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runs:
using: composite
steps:
- name: Build container image and push to Azure
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
file: ${{ inputs.DOCKER_FILE }}
tags: ${{ inputs.DOCKER_REPO }}:latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ jobs:
adoptopenjdk) echo "ARGS=-Padoptopenjdk,-adoptium" >> $GITHUB_ENV ;;
esac
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
- uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0
with:
java-version: '21'
distribution: 'temurin'
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
uses: github/codeql-action/init@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
- uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0
with:
java-version: '21'
distribution: 'temurin'
cache: 'maven'

- if: matrix.build-mode == 'manual'
run: |
./mvnw --batch-mode clean -Dmaven.test.skip=true install -Padoptium,-adoptopenjdk
./mvnw --batch-mode clean install -Padoptium,-adoptopenjdk
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
uses: github/codeql-action/analyze@ea9e4e37992a54ee68a9622e985e60c8e8f12d9f # v3.27.4
with:
category: "/language:${{matrix.language}}"
4 changes: 1 addition & 3 deletions .github/workflows/deploy-adoptium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ jobs:
if: startsWith(github.repository, 'adoptium/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Login to Azure
uses: ./.github/actions/azure-login
with:
AZURE_CLIENT_ID_OIDC: ${{ secrets.AZURE_CLIENT_ID_OIDC }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}

- name: Detect Branch
run: |
Expand Down
16 changes: 1 addition & 15 deletions .github/workflows/deploy-adoptopenjdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ jobs:
if: startsWith(github.repository, 'adoptium/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Login to Azure
uses: ./.github/actions/azure-login
with:
AZURE_CLIENT_ID_OIDC: ${{ secrets.AZURE_CLIENT_ID_OIDC }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}

- name: Detect Branch
run: |
Expand All @@ -43,15 +41,3 @@ jobs:
uses: ./.github/actions/kubectl-redeploy
with:
NAMESPACE: ${{ env.NAMESPACE }}

# if the branch is production, redeploy the k8s service on digitalocean too
- name: Login to DigitalOcean
uses: ./.github/actions/do-login
with:
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Redeploy Kubernetes Updater and Frontend
if: startsWith(github.ref, 'refs/heads/production')
uses: ./.github/actions/kubectl-redeploy
with:
NAMESPACE: adoptopenjdk-do
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
contents: write # for Git to git push

steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
- uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0
with:
java-version: '21'
distribution: 'temurin'
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/semgrep_diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ********************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made
# available under the terms of the Apache Software License 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: Apache-2.0
# ********************************************************************************

---
name: Semgrep Differential Scan
on:
pull_request:

permissions:
contents: read
statuses: write

jobs:
semgrep-diff:
uses: adoptium/.github/.github/workflows/semgrep_diff.yml@main
4 changes: 2 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar
19 changes: 17 additions & 2 deletions adoptium-api-v3-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@

<dependencies>
<dependency>
<groupId>org.litote.kmongo</groupId>
<artifactId>kmongo-coroutine</artifactId>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-kotlin-coroutine</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jakarta-jsonp</artifactId>
</dependency>
<dependency>
<groupId>net.adoptium.api</groupId>
Expand All @@ -41,6 +45,17 @@
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.adoptium.api.v3
import jakarta.enterprise.context.ApplicationScoped
import jakarta.inject.Inject
import net.adoptium.api.v3.config.APIConfig
import net.adoptium.api.v3.dataSources.VersionSupplier
import net.adoptium.api.v3.dataSources.persitence.ApiPersistence
import net.adoptium.api.v3.models.DbStatsEntry
import net.adoptium.api.v3.models.DockerDownloadStatsDbEntry
Expand All @@ -13,7 +14,6 @@ import net.adoptium.api.v3.models.JvmImpl
import net.adoptium.api.v3.models.MonthlyDownloadDiff
import net.adoptium.api.v3.models.StatsSource
import net.adoptium.api.v3.models.TotalStats
import net.adoptium.api.v3.models.Versions
import org.eclipse.microprofile.openapi.annotations.media.Schema
import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit
Expand All @@ -29,12 +29,16 @@ class StatEntry(
@ApplicationScoped
class DownloadStatsInterface {

@Schema(hidden = true)
private var versionSupplier: VersionSupplier

@Schema(hidden = true)
private val dataStore: ApiPersistence

@Inject
constructor(dataStore: ApiPersistence) {
constructor(dataStore: ApiPersistence, versionSupplier: VersionSupplier) {
this.dataStore = dataStore
this.versionSupplier = versionSupplier
}

suspend fun getTrackingStats(
Expand Down Expand Up @@ -115,8 +119,8 @@ class DownloadStatsInterface {
return stats.groupBy { it.dateTime.toLocalDate() }
.map { grouped ->
StatEntry(
grouped.value.map { it.dateTime }.maxOrNull()!!,
grouped.value.map { it.count }.sum()
grouped.value.maxOf { it.dateTime },
grouped.value.sumOf { it.count }
)
}
.sortedBy { it.dateTime }
Expand Down Expand Up @@ -157,7 +161,7 @@ class DownloadStatsInterface {
private fun calculateMonthlyDiff(
stats: Collection<StatEntry>
): List<MonthlyDownloadDiff> {
val toTwoChar = { value: Int -> if (value < 10) "0" + value else value.toString() } // Returns in MM format
val toTwoChar = { value: Int -> if (value < 10) "0$value" else value.toString() } // Returns in MM format

return stats
.windowed(2, 1, false) {
Expand Down Expand Up @@ -240,38 +244,28 @@ class DownloadStatsInterface {
return stats
.groupBy { it.getId() }
.map { grouped -> grouped.value.maxByOrNull { it.date } }
.map { it!!.getMetric() }
.sum()
.sumOf { it!!.getMetric() }
}

private fun formTotalDownloads(stats: List<GitHubDownloadStatsDbEntry>, jvmImpl: JvmImpl): Long {
return stats
.groupBy { it.getId() }
.map { grouped -> grouped.value.maxByOrNull { it.date } }
.map { (it!!.jvmImplDownloads?.get(jvmImpl) ?: 0) }
.sum()
.sumOf { (it!!.jvmImplDownloads?.get(jvmImpl) ?: 0) }
}

suspend fun getTotalDownloadStats(): DownloadStats {
val dockerStats = getAllDockerStats()

val githubStats = getGithubStats()

val dockerPulls = dockerStats
.map { it.pulls }
.sum()
val dockerPulls = dockerStats.sumOf { it.pulls }

val githubDownloads = githubStats
.map { it.downloads }
.sum()
val githubDownloads = githubStats.sumOf { it.downloads }

val dockerBreakdown = dockerStats
.map { Pair(it.repo, it.pulls) }
.toMap()
val dockerBreakdown = dockerStats.associate { Pair(it.repo, it.pulls) }

val githubBreakdown = githubStats
.map { Pair(it.feature_version, it.downloads) }
.toMap()
val githubBreakdown = githubStats.associate { Pair(it.feature_version, it.downloads) }

val totalStats = TotalStats(dockerPulls, githubDownloads, dockerPulls + githubDownloads)
return DownloadStats(TimeSource.now(), totalStats, githubBreakdown, dockerBreakdown)
Expand All @@ -284,7 +278,7 @@ class DownloadStatsInterface {
}

private suspend fun getGithubStats(): List<GitHubDownloadStatsDbEntry> {
return Versions.versions
return versionSupplier.getAllVersions()
.mapNotNull { featureVersion ->
dataStore.getLatestGithubStatsForFeatureVersion(featureVersion)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package net.adoptium.api.v3
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinModule

object JsonMapper {
val mapper: ObjectMapper = ObjectMapper()
val mapper: ObjectMapper = com.fasterxml.jackson.module.kotlin.jacksonObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.registerModule(KotlinModule.Builder().build())
.registerModule(JavaTimeModule())
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.adoptium.api.v3.dataSources

import net.adoptium.api.v3.dataSources.models.AdoptRepos
import net.adoptium.api.v3.dataSources.persitence.mongo.UpdatedInfo
import net.adoptium.api.v3.models.ReleaseInfo

interface APIDataStore {
Expand All @@ -9,4 +10,5 @@ interface APIDataStore {
fun setAdoptRepos(binaryRepos: AdoptRepos)
fun getReleaseInfo(): ReleaseInfo
fun loadDataFromDb(forceUpdate: Boolean): AdoptRepos
fun getUpdateInfo(): UpdatedInfo
}
Loading

0 comments on commit da9e39a

Please sign in to comment.