Skip to content

Commit adc0dd4

Browse files
authored
Merge pull request #245 from rdebusscher/issue218
Use MP 3.0 Health annotations. fixes #218.
2 parents e9e962e + cda2420 commit adc0dd4

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

src/main/java/org/eclipse/microprofile/starter/addon/microprofile/servers/MicroprofileServersAddon.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.microprofile.starter.core.exception.JessieConfigurationException;
3030
import org.eclipse.microprofile.starter.core.exception.JessieUnexpectedException;
3131
import org.eclipse.microprofile.starter.core.model.JessieModel;
32+
import org.eclipse.microprofile.starter.core.model.MicroProfileVersion;
3233
import org.eclipse.microprofile.starter.core.model.OptionValue;
3334
import org.eclipse.microprofile.starter.spi.MavenHelper;
3435

@@ -204,7 +205,12 @@ public void createFiles(JessieModel model) {
204205
String healthDirectory = model.getDirectory(true) + "/" + rootJava + "/health";
205206
directoryCreator.createDirectory(healthDirectory);
206207

207-
processTemplateFile(healthDirectory, "ServiceHealthCheck.java", alternatives, variables);
208+
if (alternatives.contains(MicroProfileVersion.Constants.MP3X_ALTERNATIVE)) {
209+
processTemplateFile(healthDirectory, "ServiceLiveHealthCheck.java", alternatives, variables);
210+
processTemplateFile(healthDirectory, "ServiceReadyHealthCheck.java", alternatives, variables);
211+
} else {
212+
processTemplateFile(healthDirectory, "ServiceHealthCheck.java", alternatives, variables);
213+
}
208214
}
209215

210216
if (microprofileSpecs.contains(MicroprofileSpec.CONFIG)) {

src/main/java/org/eclipse/microprofile/starter/core/model/MicroProfileVersion.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
package org.eclipse.microprofile.starter.core.model;
2424

25+
import java.util.Collection;
26+
import java.util.Collections;
2527
import java.util.HashSet;
2628
import java.util.Set;
2729

@@ -30,7 +32,7 @@ public enum MicroProfileVersion {
3032
// Order is important as it determines the order in the Dropdown on the screen.
3133
// @formatter:off
3234
NONE(null, "")
33-
, MP30("3.0", "MP 3.0")
35+
, MP30("3.0", "MP 3.0", Collections.singletonList(Constants.MP3X_ALTERNATIVE))
3436
, MP22("2.2", "MP 2.2")
3537
, MP21("2.1", "MP 2.1")
3638
, MP20("2.0", "MP 2.0", "2.0.1")
@@ -51,6 +53,13 @@ public enum MicroProfileVersion {
5153
mavenVersion = code;
5254
}
5355

56+
MicroProfileVersion(String code, String label, Collection<String> alternatives) {
57+
this.code = code;
58+
this.label = label;
59+
this.alternatives = new HashSet<>(alternatives);
60+
mavenVersion = code;
61+
}
62+
5463
MicroProfileVersion(String code, String label, String mavenVersion) {
5564
this(code, label);
5665
this.mavenVersion = mavenVersion;
@@ -82,4 +91,8 @@ public static MicroProfileVersion valueFor(String code) {
8291
}
8392
return result;
8493
}
94+
95+
public static class Constants {
96+
public static final String MP3X_ALTERNATIVE = "mp3_x";
97+
}
8598
}

src/main/resources/files.lst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ src/main/resources/files/securedURLs.ini.tpl
4141
src/main/resources/files/service-b/RestApplication.java.tpl
4242
src/main/resources/files/ServiceController.java.tpl
4343
src/main/resources/files/ServiceHealthCheck.java.tpl
44+
src/main/resources/files/mp3_x/ServiceLiveHealthCheck.java.tpl
45+
src/main/resources/files/mp3_x/ServiceReadyHealthCheck.java.tpl
4446
src/main/resources/files/Service.java.tpl
4547
src/main/resources/files/TestSecureController.java.tpl
4648
src/main/resources/files/thorntail-v2/web.xml.tpl
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package [# th:text="${java_package}"/].health;
2+
3+
import org.eclipse.microprofile.health.HealthCheck;
4+
import org.eclipse.microprofile.health.HealthCheckResponse;
5+
import org.eclipse.microprofile.health.Liveness;
6+
7+
import javax.enterprise.context.ApplicationScoped;
8+
9+
@Liveness
10+
@ApplicationScoped
11+
public class ServiceLiveHealthCheck implements HealthCheck {
12+
13+
@Override
14+
public HealthCheckResponse call() {
15+
16+
return HealthCheckResponse.named(ServiceLiveHealthCheck.class.getSimpleName()).withData("live",true).up().build();
17+
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package [# th:text="${java_package}"/].health;
2+
3+
import org.eclipse.microprofile.health.HealthCheck;
4+
import org.eclipse.microprofile.health.HealthCheckResponse;
5+
import org.eclipse.microprofile.health.Readiness;
6+
7+
import javax.enterprise.context.ApplicationScoped;
8+
9+
@Readiness
10+
@ApplicationScoped
11+
public class ServiceReadyHealthCheck implements HealthCheck {
12+
13+
@Override
14+
public HealthCheckResponse call() {
15+
16+
return HealthCheckResponse.named(ServiceReadyHealthCheck.class.getSimpleName()).withData("ready",true).up().build();
17+
18+
}
19+
}

0 commit comments

Comments
 (0)