From a89a8cc77458f0f081c5f8100bbe1e6a34225b60 Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Wed, 1 Mar 2023 17:49:58 +0000 Subject: [PATCH] Strip out the broadcast id and rename to healthcheck where needed. --- src/main/bash/sdkman-availability.sh | 38 +++++-------------- .../CandidatesCacheUpdateFailureSpec.groovy | 4 +- .../specs/CandidatesCacheUpdateSpec.groovy | 4 +- .../sdkman/specs/CurrentCommandSpec.groovy | 4 +- .../groovy/sdkman/specs/SelfupdateSpec.groovy | 4 +- src/test/groovy/sdkman/steps/env.groovy | 2 +- .../sdkman/steps/initialisation_steps.groovy | 6 +-- 7 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/main/bash/sdkman-availability.sh b/src/main/bash/sdkman-availability.sh index 4f147d5f..696117b5 100644 --- a/src/main/bash/sdkman-availability.sh +++ b/src/main/bash/sdkman-availability.sh @@ -17,25 +17,24 @@ # function __sdkman_update_service_availability() { - local broadcast_live_id=$(__sdkman_determine_broadcast_id) - __sdkman_set_availability "$broadcast_live_id" - __sdkman_update_broadcast_id "$broadcast_live_id" + local healthcheck_status=$(__sdkman_determine_healthcheck_status) + __sdkman_set_availability "$healthcheck_status" } -function __sdkman_determine_broadcast_id() { +function __sdkman_determine_healthcheck_status() { if [[ "$SDKMAN_OFFLINE_MODE" == "true" || "$COMMAND" == "offline" && "$QUALIFIER" == "enable" ]]; then echo "" else - echo $(__sdkman_secure_curl_with_timeouts "${SDKMAN_CANDIDATES_API}/broadcast/latest/id") + echo $(__sdkman_secure_curl_with_timeouts "${SDKMAN_CANDIDATES_API}/healthcheck") fi } function __sdkman_set_availability() { - local broadcast_id="$1" - local detect_html="$(echo "$broadcast_id" | tr '[:upper:]' '[:lower:]' | grep 'html')" - if [[ -z "$broadcast_id" ]]; then + local healthcheck_status="$1" + local detect_html="$(echo "$healthcheck_status" | tr '[:upper:]' '[:lower:]' | grep 'html')" + if [[ -z "$healthcheck_status" ]]; then SDKMAN_AVAILABLE="false" - __sdkman_display_offline_warning "$broadcast_id" + __sdkman_display_offline_warning "$healthcheck_status" elif [[ -n "$detect_html" ]]; then SDKMAN_AVAILABLE="false" __sdkman_display_proxy_warning @@ -45,8 +44,8 @@ function __sdkman_set_availability() { } function __sdkman_display_offline_warning() { - local broadcast_id="$1" - if [[ -z "$broadcast_id" && "$COMMAND" != "offline" && "$SDKMAN_OFFLINE_MODE" != "true" ]]; then + local healthcheck_status="$1" + if [[ -z "$healthcheck_status" && "$COMMAND" != "offline" && "$SDKMAN_OFFLINE_MODE" != "true" ]]; then __sdkman_echo_red "==== INTERNET NOT REACHABLE! ===================================================" __sdkman_echo_red "" __sdkman_echo_red " Some functionality is disabled or only partially available." @@ -65,20 +64,3 @@ function __sdkman_display_proxy_warning() { __sdkman_echo_red "================================================================================" echo "" } - -function __sdkman_update_broadcast_id() { - local broadcast_live_id broadcast_id_file broadcast_old_id - - broadcast_live_id="$1" - broadcast_id_file="${SDKMAN_DIR}/var/broadcast_id" - broadcast_old_id="" - - if [[ -f "$broadcast_id_file" ]]; then - broadcast_old_id=$(< "$broadcast_id_file") - fi - - if [[ "$SDKMAN_AVAILABLE" == "true" && "$broadcast_live_id" != "$broadcast_old_id" && "$COMMAND" != "selfupdate" && "$COMMAND" != "flush" ]]; then - mkdir -p "${SDKMAN_DIR}/var" - echo "$broadcast_live_id" | tee "$broadcast_id_file" > /dev/null - fi -} diff --git a/src/test/groovy/sdkman/specs/CandidatesCacheUpdateFailureSpec.groovy b/src/test/groovy/sdkman/specs/CandidatesCacheUpdateFailureSpec.groovy index 5f2eef23..d51c208b 100644 --- a/src/test/groovy/sdkman/specs/CandidatesCacheUpdateFailureSpec.groovy +++ b/src/test/groovy/sdkman/specs/CandidatesCacheUpdateFailureSpec.groovy @@ -6,14 +6,14 @@ class CandidatesCacheUpdateFailureSpec extends SdkmanEnvSpecification { static final String CANDIDATES_API = "http://localhost:8080/2" - static final String BROADCAST_API_LATEST_ID_ENDPOINT = "$CANDIDATES_API/broadcast/latest/id" + static final String HEALTHCHECK_ENDPOINT = "$CANDIDATES_API/healthcheck" static final String CANDIDATES_ALL_ENDPOINT = "$CANDIDATES_API/candidates/all" File candidatesCache def setup() { candidatesCache = new File("${sdkmanDotDirectory}/var", "candidates") - curlStub.primeWith(BROADCAST_API_LATEST_ID_ENDPOINT, "echo dbfb025be9f97fda2052b5febcca0155") + curlStub.primeWith(HEALTHCHECK_ENDPOINT, "echo dbfb025be9f97fda2052b5febcca0155") .primeWith(CANDIDATES_ALL_ENDPOINT, "echo html") sdkmanBashEnvBuilder.withConfiguration("sdkman_debug_mode", "true") } diff --git a/src/test/groovy/sdkman/specs/CandidatesCacheUpdateSpec.groovy b/src/test/groovy/sdkman/specs/CandidatesCacheUpdateSpec.groovy index f7120091..a9131658 100644 --- a/src/test/groovy/sdkman/specs/CandidatesCacheUpdateSpec.groovy +++ b/src/test/groovy/sdkman/specs/CandidatesCacheUpdateSpec.groovy @@ -6,14 +6,14 @@ class CandidatesCacheUpdateSpec extends SdkmanEnvSpecification { static final String CANDIDATES_API = "http://localhost:8080/2" - static final String BROADCAST_API_LATEST_ID_ENDPOINT = "$CANDIDATES_API/broadcast/latest/id" + static final String HEALTHCHECK_ENDPOINT = "$CANDIDATES_API/healthcheck" static final String CANDIDATES_ALL_ENDPOINT = "$CANDIDATES_API/candidates/all" File candidatesCache def setup() { candidatesCache = new File("${sdkmanDotDirectory}/var", "candidates") - curlStub.primeWith(BROADCAST_API_LATEST_ID_ENDPOINT, "echo dbfb025be9f97fda2052b5febcca0155") + curlStub.primeWith(HEALTHCHECK_ENDPOINT, "echo dbfb025be9f97fda2052b5febcca0155") .primeWith(CANDIDATES_ALL_ENDPOINT, "echo groovy,scala") sdkmanBashEnvBuilder.withConfiguration("sdkman_debug_mode", "true") } diff --git a/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy b/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy index c1fcd1e9..ea5a296a 100644 --- a/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy +++ b/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy @@ -9,10 +9,10 @@ import static java.nio.file.Files.createSymbolicLink class CurrentCommandSpec extends SdkmanEnvSpecification { static final CANDIDATES_API = "http://localhost:8080/2" - static final BROADCAST_API_LATEST_ID_ENDPOINT = "$CANDIDATES_API/broadcast/latest/id" + static final HEALTHCHECK_ENDPOINT = "$CANDIDATES_API/healthcheck" def setup() { - curlStub.primeWith(BROADCAST_API_LATEST_ID_ENDPOINT, "echo dbfb025be9f97fda2052b5febcca0155") + curlStub.primeWith(HEALTHCHECK_ENDPOINT, "echo dbfb025be9f97fda2052b5febcca0155") } void "should display current version of all candidates installed"() { diff --git a/src/test/groovy/sdkman/specs/SelfupdateSpec.groovy b/src/test/groovy/sdkman/specs/SelfupdateSpec.groovy index 2ac64e54..4ba6a55e 100644 --- a/src/test/groovy/sdkman/specs/SelfupdateSpec.groovy +++ b/src/test/groovy/sdkman/specs/SelfupdateSpec.groovy @@ -8,11 +8,11 @@ import static java.time.temporal.ChronoUnit.DAYS class SelfupdateSpec extends SdkmanEnvSpecification { static final String CANDIDATES_API = "http://localhost:8080/2" - static final String BROADCAST_API_LATEST_ID_ENDPOINT = "$CANDIDATES_API/broadcast/latest/id" + static final String HEALTHCHECK_ENDPOINT = "$CANDIDATES_API/healthcheck" static final String VERSION_ENDPOINT = "$CANDIDATES_API/broker/download/sdkman/version/stable" def setup() { - curlStub.primeWith(BROADCAST_API_LATEST_ID_ENDPOINT, "echo dbfb025be9f97fda2052b5febcca0155") + curlStub.primeWith(HEALTHCHECK_ENDPOINT, "echo dbfb025be9f97fda2052b5febcca0155") curlStub.primeWith(VERSION_ENDPOINT, "echo 5.0.0") } diff --git a/src/test/groovy/sdkman/steps/env.groovy b/src/test/groovy/sdkman/steps/env.groovy index 8ca0a193..aff9e647 100644 --- a/src/test/groovy/sdkman/steps/env.groovy +++ b/src/test/groovy/sdkman/steps/env.groovy @@ -36,7 +36,7 @@ etcDir = "${sdkmanDirEnv}/etc" as File extDir = "${sdkmanDirEnv}/ext" as File tmpDir = "${sdkmanDir}/tmp" as File -broadcastIdFile = new File(varDir, "broadcast_id") +healthcheckFile = new File(varDir, "healthcheck") candidatesFile = new File(varDir, "candidates") versionFile = new File(varDir, "version") initScript = new File(binDir, "sdkman-init.sh") diff --git a/src/test/groovy/sdkman/steps/initialisation_steps.groovy b/src/test/groovy/sdkman/steps/initialisation_steps.groovy index ef20fc6b..5ec0f8fe 100644 --- a/src/test/groovy/sdkman/steps/initialisation_steps.groovy +++ b/src/test/groovy/sdkman/steps/initialisation_steps.groovy @@ -33,7 +33,7 @@ And(~'^the archive for candidate "([^"]*)" version "([^"]*)" is removed$') { Str } And(~'^the internet is reachable$') { -> - primeEndpointWithString("/broadcast/latest/id", "12345") + primeEndpointWithString("/healthcheck", "12345") primeEndpointWithString("/app/stable", sdkmanVersion) primeSelfupdate() @@ -49,7 +49,7 @@ And(~'^the internet is not reachable$') { -> } And(~'^offline mode is disabled with reachable internet$') { -> - primeEndpointWithString("/broadcast/latest/id", "12345") + primeEndpointWithString("/healthcheck", "12345") primeEndpointWithString("/app/stable", sdkmanVersion) offlineMode = false @@ -58,7 +58,7 @@ And(~'^offline mode is disabled with reachable internet$') { -> } And(~'^offline mode is enabled with reachable internet$') { -> - primeEndpointWithString("/broadcast/latest/id", "12345") + primeEndpointWithString("/healthcheck", "12345") primeEndpointWithString("/app/stable", sdkmanVersion) offlineMode = true