Skip to content

Commit

Permalink
Merge pull request #23 from tombatchelor/DEMO-1-Make-OOM-Cleaner
Browse files Browse the repository at this point in the history
Demo 1 make oom cleaner
  • Loading branch information
tombatchelor authored Nov 1, 2019
2 parents 28a8b52 + e7b0ed6 commit 1caa5f6
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app_server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ MAINTAINER your_name
COPY target/Cars_Sample_App.war /usr/local/tomcat/webapps/

# This set is the leak short circuits to no-op or not, if TRUE leak occures
ENV LEAKING=TRUE
ENV LEAKING=FALSE
3 changes: 2 additions & 1 deletion app_server/src/main/java/com/supercars/Leak.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package com.supercars;

import com.supercars.rest.HealthService;
import java.util.ConcurrentModificationException;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -60,7 +61,7 @@ private static void checkShouldKill() {

if (keepAliveTime < System.currentTimeMillis()) {
logger.log(Level.SEVERE, "Out of Memory", new java.lang.OutOfMemoryError("Out of Memory"));
System.exit(-1);
HealthService.setAsUnhealthy();
}
}
}
11 changes: 11 additions & 0 deletions app_server/src/main/java/com/supercars/rest/HealthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ public class HealthService {

private final static Logger logger = Logger.getLogger(HealthService.class.getName());

private static boolean shouldSendUnhealthy = false;

@GET
@Produces(MediaType.TEXT_PLAIN)
public Response getHealth() {
logger.fine("GET Returning service health");
if (shouldSendUnhealthy) {
logger.log(Level.SEVERE, "Out of Memory", new java.lang.OutOfMemoryError("Out of Memory"));
return Response.serverError().entity("Out of Memory").build();
}
try (Connection connection = Constants.getDBConnectionStandardPool()) {
if (connection == null) {
logger.severe("Could not get DB connection");
return Response.serverError().entity("NO_DB_CONNECTION").build();
} else {
logger.fine("Got DB Connection Okay");
}
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
Expand All @@ -42,4 +49,8 @@ public Response getHealth() {
logger.fine("Service okay");
return Response.ok("OK").build();
}

public static void setAsUnhealthy() {
shouldSendUnhealthy = true;
}
}
2 changes: 1 addition & 1 deletion demo_marshaller/2_leak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: app-server
image: tombatchelor/cars:2.0-leak
image: tombatchelor/cars:2.1-leak
imagePullPolicy: Always
ports:
- name: cars-app-port
Expand Down
2 changes: 1 addition & 1 deletion demo_marshaller/2_no_leak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: app-server
image: tombatchelor/cars:2.0
image: tombatchelor/cars:2.1
imagePullPolicy: Always
ports:
- name: cars-app-port
Expand Down
2 changes: 1 addition & 1 deletion demo_marshaller/4_leak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: app-server
image: tombatchelor/cars:2.0-leak
image: tombatchelor/cars:2.1-leak
imagePullPolicy: Always
ports:
- name: cars-app-port
Expand Down
2 changes: 1 addition & 1 deletion demo_marshaller/4_no_leak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: app-server
image: tombatchelor/cars:2.0
image: tombatchelor/cars:2.1
imagePullPolicy: Always
ports:
- name: cars-app-port
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/cars_app-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ spec:
spec:
containers:
- name: app-server
image: tombatchelor/cars:2.0-leak
image: tombatchelor/cars:2.1-leak
imagePullPolicy: Always
ports:
- name: cars-app-port
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/cars_app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
spec:
containers:
- name: app-server
image: tombatchelor/cars:1.33-leak
image: tombatchelor/cars:2.1-leak
imagePullPolicy: Always
ports:
- name: cars-app-port
Expand Down

0 comments on commit 1caa5f6

Please sign in to comment.