From cc014333c77bb30d312b785ac109033ce2131526 Mon Sep 17 00:00:00 2001 From: Kevin McAnoy Date: Fri, 19 Nov 2021 14:31:20 -0800 Subject: [PATCH] upgrade to quarkus v2. add ability to get version of a single component --- deployment/templates/deploymentconfig.yaml | 4 +-- pom.xml | 5 ++-- .../model/version/VersionManifest.java | 8 ++++-- .../lodestar/resource/VersionResource.java | 17 +++++++++--- src/main/resources/application.properties | 2 +- ...Test.java => StatusLivenessCheckTest.java} | 6 ++--- .../health/StatusReadinessCheckTest.java | 19 ++++++------- .../resource/VersionResourceTest.java | 27 +++++++++++++++++++ 8 files changed, 64 insertions(+), 24 deletions(-) rename src/test/java/com/redhat/labs/lodestar/health/{StatusLIvenessCheckTest.java => StatusLivenessCheckTest.java} (82%) diff --git a/deployment/templates/deploymentconfig.yaml b/deployment/templates/deploymentconfig.yaml index 230cb11..6b3cc9e 100644 --- a/deployment/templates/deploymentconfig.yaml +++ b/deployment/templates/deploymentconfig.yaml @@ -35,7 +35,7 @@ spec: name: status-configuration readinessProbe: httpGet: - path: /health/ready + path: /q/health/ready port: 8080 scheme: HTTP timeoutSeconds: 1 @@ -44,7 +44,7 @@ spec: failureThreshold: 3 livenessProbe: httpGet: - path: /health/live + path: /q/health/live port: 8080 scheme: HTTP timeoutSeconds: 1 diff --git a/pom.xml b/pom.xml index f089ad9..43a0698 100644 --- a/pom.xml +++ b/pom.xml @@ -14,10 +14,9 @@ 11 UTF-8 UTF-8 - 1.6.1.Final quarkus-universe-bom io.quarkus - 1.6.1.Final + 2.4.2.Final 2.22.1 1.18.12 rht-labs_lodestar-status @@ -98,7 +97,7 @@ io.quarkus quarkus-maven-plugin - ${quarkus-plugin.version} + ${quarkus.platform.version} diff --git a/src/main/java/com/redhat/labs/lodestar/model/version/VersionManifest.java b/src/main/java/com/redhat/labs/lodestar/model/version/VersionManifest.java index 2d36351..7c78aef 100644 --- a/src/main/java/com/redhat/labs/lodestar/model/version/VersionManifest.java +++ b/src/main/java/com/redhat/labs/lodestar/model/version/VersionManifest.java @@ -28,9 +28,13 @@ public class VersionManifest { @JsonbProperty("main_version") public Version getMainVersion() { + return getVersion(mainVersionKey); + } + + public Version getVersion(String component) { Optional optional = applications.stream() - .filter(a -> a.getApplication().equalsIgnoreCase(mainVersionKey)).findFirst(); - return optional.isPresent() ? optional.get() : null; + .filter(a -> a.getApplication().equalsIgnoreCase(component)).findFirst(); + return optional.orElse(new Version()); } @JsonbProperty("component_versions") diff --git a/src/main/java/com/redhat/labs/lodestar/resource/VersionResource.java b/src/main/java/com/redhat/labs/lodestar/resource/VersionResource.java index d9cfc88..9929229 100644 --- a/src/main/java/com/redhat/labs/lodestar/resource/VersionResource.java +++ b/src/main/java/com/redhat/labs/lodestar/resource/VersionResource.java @@ -3,11 +3,9 @@ import javax.annotation.security.PermitAll; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.eclipse.microprofile.metrics.annotation.Counted; import org.eclipse.microprofile.metrics.annotation.Timed; @@ -33,4 +31,15 @@ public VersionManifest getVersionManifest() { return versionManifestConfig.getVersionData(); } + @GET + @PermitAll + @Path("/manifest/{component}") + @Timed(name = "versionManifestComponentResourceTimer") + @Counted(name = "versionManifestComponentResourceCounter") + public Response getVersionManifestComponent(@PathParam("component") String component) { + VersionManifest vm = versionManifestConfig.getVersionData(); + + return Response.ok(vm.getVersion(component)).build(); + } + } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 95c6a21..cc7ad4a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,7 +7,7 @@ quarkus.log.category."com.redhat.labs.lodestar".level=${LODESTAR_STATUS_LOGGING: quarkus.http.cors=true # create the uber jar -quarkus.package.uber-jar=true +quarkus.package.type=uber-jar # open api quarkus.swagger-ui.always-include=true diff --git a/src/test/java/com/redhat/labs/lodestar/health/StatusLIvenessCheckTest.java b/src/test/java/com/redhat/labs/lodestar/health/StatusLivenessCheckTest.java similarity index 82% rename from src/test/java/com/redhat/labs/lodestar/health/StatusLIvenessCheckTest.java rename to src/test/java/com/redhat/labs/lodestar/health/StatusLivenessCheckTest.java index 7123ee3..b6b10b8 100644 --- a/src/test/java/com/redhat/labs/lodestar/health/StatusLIvenessCheckTest.java +++ b/src/test/java/com/redhat/labs/lodestar/health/StatusLivenessCheckTest.java @@ -12,7 +12,7 @@ import io.quarkus.test.junit.QuarkusTest; @QuarkusTest -public class StatusLIvenessCheckTest { +public class StatusLivenessCheckTest { @Inject @Liveness @@ -26,8 +26,8 @@ void testStatusLivenessCheckUp() { assertNotNull(response); assertEquals("STATUS LIVENESS", response.getName()); - assertNotNull(response.getState()); - assertEquals("UP", response.getState().name()); + assertNotNull(response.getStatus()); + assertEquals("UP", response.getStatus().name()); } diff --git a/src/test/java/com/redhat/labs/lodestar/health/StatusReadinessCheckTest.java b/src/test/java/com/redhat/labs/lodestar/health/StatusReadinessCheckTest.java index b6b6907..f2bb149 100644 --- a/src/test/java/com/redhat/labs/lodestar/health/StatusReadinessCheckTest.java +++ b/src/test/java/com/redhat/labs/lodestar/health/StatusReadinessCheckTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.Arrays; +import java.util.List; import javax.inject.Inject; @@ -41,8 +42,8 @@ void testStatusReadinessCheckDownVersionManifestNull() { // then assertNotNull(response); assertEquals("STATUS READINESS", response.getName()); - assertNotNull(response.getState()); - assertEquals("DOWN", response.getState().name()); + assertNotNull(response.getStatus()); + assertEquals("DOWN", response.getStatus().name()); } @@ -58,8 +59,8 @@ void testStatusReadinessCheckDownMainVersionMissing() { // then assertNotNull(response); assertEquals("STATUS READINESS", response.getName()); - assertNotNull(response.getState()); - assertEquals("DOWN", response.getState().name()); + assertNotNull(response.getStatus()); + assertEquals("DOWN", response.getStatus().name()); } @@ -68,7 +69,7 @@ void testStatusReadinessCheckDownComponentVersionEmpty() { // given VersionManifest vm = VersionManifest.builder().mainVersionKey("lodestar") - .applications(Arrays.asList(Version.builder().application("lodestar").build())) + .applications(List.of(Version.builder().application("lodestar").build())) .build(); Mockito.when(config.getVersionData()).thenReturn(vm); @@ -78,8 +79,8 @@ void testStatusReadinessCheckDownComponentVersionEmpty() { // then assertNotNull(response); assertEquals("STATUS READINESS", response.getName()); - assertNotNull(response.getState()); - assertEquals("DOWN", response.getState().name()); + assertNotNull(response.getStatus()); + assertEquals("DOWN", response.getStatus().name()); } @@ -98,8 +99,8 @@ void testStatusReadinessCheckUp() { // then assertNotNull(response); assertEquals("STATUS READINESS", response.getName()); - assertNotNull(response.getState()); - assertEquals("UP", response.getState().name()); + assertNotNull(response.getStatus()); + assertEquals("UP", response.getStatus().name()); } diff --git a/src/test/java/com/redhat/labs/lodestar/resource/VersionResourceTest.java b/src/test/java/com/redhat/labs/lodestar/resource/VersionResourceTest.java index a437d1f..03becc3 100644 --- a/src/test/java/com/redhat/labs/lodestar/resource/VersionResourceTest.java +++ b/src/test/java/com/redhat/labs/lodestar/resource/VersionResourceTest.java @@ -6,6 +6,7 @@ import com.redhat.labs.lodestar.utils.ResourceLoader; import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; @QuarkusTest @@ -23,4 +24,30 @@ public void testGetVersionManifest() { .body(is(expected)); } + @Test + public void testGetVersionComponentManifest() { + + String expected = ResourceLoader.load("data/version/get-version-manifest.json"); + + given() + .when().get("/api/v1/version/manifest/launcher") + .then() + .statusCode(200) + .body("name", equalTo("launcher")) + .body("value", equalTo("v1.1")); + } + + @Test + public void testGetVersionComponentManifestEmpty() { + + String expected = ResourceLoader.load("data/version/get-version-manifest.json"); + + given() + .when().get("/api/v1/version/manifest/nada") + .then() + .statusCode(200) + .body("name", equalTo(null)) + .body("value", equalTo(null)); + } + } \ No newline at end of file