From e8bb01050ab798867d984b1ddc782bfb70658804 Mon Sep 17 00:00:00 2001 From: Fabio Massimo Ercoli Date: Wed, 28 Mar 2018 11:48:45 +0200 Subject: [PATCH] add Health Check uri to liveness and readiness probes --- .../account/core/service/HealthCheck.java | 34 +++++++++++++++++++ .../account/core/service/UserService.java | 5 ++- .../src/app/login.service.ts | 2 +- .../src/app/message/message.component.html | 9 ++--- .../post/core/service/HealthCheck.java | 33 ++++++++++++++++++ .../post/core/service/MessageService.java | 7 ---- .../message-board/script/install-all.sh | 12 +++---- 7 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 other/openshift/message-board/account-service/src/main/java/org/hibernate/demo/message/account/core/service/HealthCheck.java create mode 100644 other/openshift/message-board/message-service/src/main/java/org/hibernate/demo/message/post/core/service/HealthCheck.java diff --git a/other/openshift/message-board/account-service/src/main/java/org/hibernate/demo/message/account/core/service/HealthCheck.java b/other/openshift/message-board/account-service/src/main/java/org/hibernate/demo/message/account/core/service/HealthCheck.java new file mode 100644 index 00000000..1d66a405 --- /dev/null +++ b/other/openshift/message-board/account-service/src/main/java/org/hibernate/demo/message/account/core/service/HealthCheck.java @@ -0,0 +1,34 @@ +package org.hibernate.demo.message.account.core.service; + +import java.util.List; +import javax.ejb.Stateless; +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 org.hibernate.demo.message.account.core.entity.User; +import org.hibernate.demo.message.account.core.repo.UserRepo; + +import org.slf4j.Logger; + +@Path("/health") +@Stateless +public class HealthCheck { + + @Inject + private Logger log; + + @Inject + private UserRepo repo; + + @GET + @Produces(MediaType.APPLICATION_JSON) + public List healthCheck() { + log.info( "healthCheck invoked by OCP" ); + + return repo.findAll(); + } + +} diff --git a/other/openshift/message-board/account-service/src/main/java/org/hibernate/demo/message/account/core/service/UserService.java b/other/openshift/message-board/account-service/src/main/java/org/hibernate/demo/message/account/core/service/UserService.java index 277fd83a..9e883be6 100644 --- a/other/openshift/message-board/account-service/src/main/java/org/hibernate/demo/message/account/core/service/UserService.java +++ b/other/openshift/message-board/account-service/src/main/java/org/hibernate/demo/message/account/core/service/UserService.java @@ -13,8 +13,8 @@ import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.hibernate.demo.message.account.core.entity.User; @@ -37,9 +37,8 @@ public List findAllUsers() { } @GET - @Path( "{username}" ) @Produces(MediaType.APPLICATION_JSON) - public User findByUsername(@PathParam("username") String username) { + public User findByUsername(@QueryParam("username") String username) { return repo.findByUserName( username ); } diff --git a/other/openshift/message-board/message-board-web/src/app/login.service.ts b/other/openshift/message-board/message-board-web/src/app/login.service.ts index 550fb199..cae7a331 100644 --- a/other/openshift/message-board/message-board-web/src/app/login.service.ts +++ b/other/openshift/message-board/message-board-web/src/app/login.service.ts @@ -22,7 +22,7 @@ export class LoginService { } login(userName: String): Observable { - const url = `http://web-message-board.192.168.42.57.nip.io//users/?username=${userName}`; + const url = `account-service/user?username=${userName}`; console.log(url); return this.http.get(url).map( user => { diff --git a/other/openshift/message-board/message-board-web/src/app/message/message.component.html b/other/openshift/message-board/message-board-web/src/app/message/message.component.html index 1026a74d..bf0ae023 100644 --- a/other/openshift/message-board/message-board-web/src/app/message/message.component.html +++ b/other/openshift/message-board/message-board-web/src/app/message/message.component.html @@ -5,10 +5,11 @@ {{ user.id }} - {{ user.userName }} + [class.text-info]="user.userName != userName"> +
+ {{ user.id }} + {{ user.userName }} +
diff --git a/other/openshift/message-board/message-service/src/main/java/org/hibernate/demo/message/post/core/service/HealthCheck.java b/other/openshift/message-board/message-service/src/main/java/org/hibernate/demo/message/post/core/service/HealthCheck.java new file mode 100644 index 00000000..d1421194 --- /dev/null +++ b/other/openshift/message-board/message-service/src/main/java/org/hibernate/demo/message/post/core/service/HealthCheck.java @@ -0,0 +1,33 @@ +package org.hibernate.demo.message.post.core.service; + +import java.util.List; +import javax.ejb.Stateless; +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 org.hibernate.demo.message.post.core.entity.Message; + +import org.slf4j.Logger; + +@Path("/health") +@Stateless +public class HealthCheck { + + @Inject + private Logger log; + + @Inject + private MessageService service; + + @GET + @Produces(MediaType.APPLICATION_JSON) + public List healthCheck() { + log.info( "healthCheck invoked by OCP" ); + + return service.findMessagesByUser( "andrea" ); + } + +} diff --git a/other/openshift/message-board/message-service/src/main/java/org/hibernate/demo/message/post/core/service/MessageService.java b/other/openshift/message-board/message-service/src/main/java/org/hibernate/demo/message/post/core/service/MessageService.java index 2342ca03..dad16f69 100644 --- a/other/openshift/message-board/message-service/src/main/java/org/hibernate/demo/message/post/core/service/MessageService.java +++ b/other/openshift/message-board/message-service/src/main/java/org/hibernate/demo/message/post/core/service/MessageService.java @@ -40,13 +40,6 @@ public class MessageService { @Inject private Logger log; - @GET - @Path( "{username}" ) - @Produces( MediaType.APPLICATION_JSON ) - public List findMessagesUser( @PathParam( "username" ) String username ) { - return findMessagesByUser( username ); - } - @GET @Produces( MediaType.APPLICATION_JSON ) public List findMessagesByUser( @QueryParam( "username" ) String username ) { diff --git a/other/openshift/message-board/script/install-all.sh b/other/openshift/message-board/script/install-all.sh index 250ea851..99a9fc0c 100755 --- a/other/openshift/message-board/script/install-all.sh +++ b/other/openshift/message-board/script/install-all.sh @@ -34,13 +34,13 @@ oc new-app --image-stream=eap71-openshift:latest~./nocontent -e OPENSHIFT_KUBE_P oc start-build message-service --from-dir=./message-service --follow # Setting liveness probes -oc set probe dc/account-service --liveness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/account-service/user -oc set probe dc/message-service --liveness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/message-service/messages/fabio -oc set probe dc/message-board-web --liveness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/ +oc set probe dc/account-service --liveness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/account-service/health +oc set probe dc/message-service --liveness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/message-service/health +#oc set probe dc/message-board-web --liveness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/ # Setting readiness probes -oc set probe dc/account-service --readiness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/account-service/user -oc set probe dc/message-service --readiness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/message-service/messages/fabio -oc set probe dc/message-board-web --readiness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/ +oc set probe dc/account-service --readiness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/account-service/health +oc set probe dc/message-service --readiness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/message-service/health +#oc set probe dc/message-board-web --readiness --failure-threshold 3 --initial-delay-seconds 30 --get-url=http://:8080/ oc get pods -w \ No newline at end of file