Skip to content

Commit

Permalink
add Health Check uri to liveness and readiness probes
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Mar 28, 2018
1 parent 14058b7 commit e8bb010
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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<User> healthCheck() {
log.info( "healthCheck invoked by OCP" );

return repo.findAll();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,9 +37,8 @@ public List<User> 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 );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class LoginService {
}

login(userName: String): Observable<User> {
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<User>(url).map(
user => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<a *ngFor="let user of users"
routerLink="/message/{{user.userName}}" (click)="onSelect(user)"
[class.text-danger]="user.userName === userName"
[class.text-info]="user.userName != userName"> <span
class="badge" [class.badge-danger]="user.userName === userName"
[class.badge-info]="user.userName != userName">{{ user.id }}</span>
{{ user.userName }}
[class.text-info]="user.userName != userName">
<div>
<span class="badge" [class.badge-danger]="user.userName === userName" [class.badge-info]="user.userName != userName">{{ user.id }}</span>
{{ user.userName }}
</div>
</a>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Message> healthCheck() {
log.info( "healthCheck invoked by OCP" );

return service.findMessagesByUser( "andrea" );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ public class MessageService {
@Inject
private Logger log;

@GET
@Path( "{username}" )
@Produces( MediaType.APPLICATION_JSON )
public List<Message> findMessagesUser( @PathParam( "username" ) String username ) {
return findMessagesByUser( username );
}

@GET
@Produces( MediaType.APPLICATION_JSON )
public List<Message> findMessagesByUser( @QueryParam( "username" ) String username ) {
Expand Down
12 changes: 6 additions & 6 deletions other/openshift/message-board/script/install-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e8bb010

Please sign in to comment.