This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from Sgitario/lifecycle-td-1.11
[1.11] Added lifecycle application module
- Loading branch information
Showing
7 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.quarkus.ts.openshift</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
|
||
<artifactId>lifecycle-application</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Quarkus OpenShift TS: Lifecycle Application</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-openshift</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-smallrye-health</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus.ts.openshift</groupId> | ||
<artifactId>app-metadata</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus.ts.openshift</groupId> | ||
<artifactId>common</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
25 changes: 25 additions & 0 deletions
25
lifecycle-application/src/main/java/io/quarkus/ts/openshift/lifecycle/ArgsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.ts.openshift.lifecycle; | ||
|
||
import io.quarkus.runtime.annotations.CommandLineArguments; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@Path("/args") | ||
public class ArgsResource { | ||
@Inject | ||
@CommandLineArguments | ||
String[] args; | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String get() { | ||
return Stream.of(args).collect(Collectors.joining(",")); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
lifecycle-application/src/main/java/io/quarkus/ts/openshift/lifecycle/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quarkus.ts.openshift.lifecycle; | ||
|
||
import io.quarkus.runtime.Quarkus; | ||
import io.quarkus.runtime.annotations.QuarkusMain; | ||
import org.jboss.logging.Logger; | ||
|
||
@QuarkusMain | ||
public class Main { | ||
|
||
public static final String ARGUMENTS_FROM_MAIN = "Received arguments: "; | ||
|
||
private static final Logger LOG = Logger.getLogger(Main.class); | ||
|
||
public static void main(String... args) { | ||
LOG.info(ARGUMENTS_FROM_MAIN + String.join(",", args)); | ||
Quarkus.run(args); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
lifecycle-application/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
quarkus.openshift.expose=true | ||
|
||
# We can't append arguments to the Java commend | ||
# Not sure if the quarkus.openshift.arguments will be the right property to do this or there will be a new one. | ||
# Related to https://github.com/quarkusio/quarkus/pull/15670#issuecomment-800857624. | ||
# quarkus.openshift.arguments=ARG1,ARG2 | ||
|
||
quarkus.s2i.base-jvm-image=registry.access.redhat.com/ubi8/openjdk-11:latest |
71 changes: 71 additions & 0 deletions
71
...tion/src/test/java/io/quarkus/ts/openshift/lifecycle/LifecycleApplicationOpenShiftIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.quarkus.ts.openshift.lifecycle; | ||
|
||
import io.fabric8.kubernetes.api.model.PodList; | ||
import io.fabric8.openshift.client.OpenShiftClient; | ||
import io.quarkus.ts.openshift.common.OpenShiftTest; | ||
import io.quarkus.ts.openshift.common.injection.TestResource; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.StringReader; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import static io.restassured.RestAssured.when; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@OpenShiftTest | ||
public class LifecycleApplicationOpenShiftIT { | ||
|
||
private static final String LOGGING_PROPERTY = "-Djava.util.logging.manager=org.jboss.logmanager.LogManager"; | ||
private static final String RUNTIME_LABEL = "app.openshift.io/runtime"; | ||
private static final String RUNTIME_QUARKUS = "quarkus"; | ||
private static final List<String> EXPECTED_ARGUMENTS = Arrays.asList("ARG1", "ARG2"); | ||
|
||
@TestResource | ||
private OpenShiftClient openshiftClient; | ||
|
||
@Test | ||
public void shouldArgumentsNotContainLoggingProperty() { | ||
String actualArguments = when().get("/args") | ||
.then().statusCode(200).extract().asString(); | ||
|
||
assertFalse(StringUtils.contains(actualArguments, LOGGING_PROPERTY), | ||
"Actual arguments contain unexpected properties: " + actualArguments); | ||
// Can't provide arguments to Java command: https://github.com/quarkusio/quarkus/pull/15670#issuecomment-800857624 | ||
// assertExpectedArguments(actualArguments); | ||
} | ||
|
||
@Test | ||
public void shouldPrintMessagesFromQuarkusMain() { | ||
PodList pods = openshiftClient.pods().withLabel(RUNTIME_LABEL, RUNTIME_QUARKUS).list(); | ||
assertEquals(1, pods.getItems().size(), "Found more than one pod with Quarkus runtime"); | ||
|
||
String actualLog = openshiftClient.pods().withName(pods.getItems().get(0).getMetadata().getName()).getLog(); | ||
Optional<String> argumentsLineOpt = toLines(actualLog).filter(line -> line.contains(Main.ARGUMENTS_FROM_MAIN)) | ||
.findFirst(); | ||
|
||
assertTrue(argumentsLineOpt.isPresent(), | ||
"Pod log does not contain the received arguments. Actual content: " + actualLog); | ||
String argumentsLine = argumentsLineOpt.get(); | ||
assertFalse(argumentsLine.contains(LOGGING_PROPERTY), | ||
"Pod log contain unexpected properties. Actual content: " + argumentsLine); | ||
// Can't provide arguments to Java command: https://github.com/quarkusio/quarkus/pull/15670#issuecomment-800857624 | ||
// assertExpectedArguments(argumentsLine); | ||
} | ||
|
||
private void assertExpectedArguments(String actualArguments) { | ||
EXPECTED_ARGUMENTS.forEach(arg -> assertTrue(actualArguments.contains(arg), | ||
"Expected argument " + arg + " was not found in actual arguments: " + actualArguments)); | ||
} | ||
|
||
private static final Stream<String> toLines(String str) { | ||
return new BufferedReader(new StringReader(str)).lines(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters