Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from alb2k/develop
Browse files Browse the repository at this point in the history
v1.0.7
  • Loading branch information
alb2k authored Mar 20, 2021
2 parents 11760db + ef0fcda commit 63decf5
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
target/*
docker/*
assets/*
docs/*
.github/*
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project was created for the [Microstream hackathon](https://hackathon.micro
* [Microstream](https://microstream.one/platforms/microstream-for-java/)
* [Microprofile (config)](https://github.com/eclipse/microprofile-config)
* [Helidon MP](https://helidon.io/#getting-started)
* [MP Health](https://github.com/eclipse/microprofile-health)
* Logging via [SLF4J](http://www.slf4j.org/) and [Apache Log4j 2](https://logging.apache.org/log4)
* [OpenApi](https://www.openapis.org/)
* [OpenApi-UI](https://swagger.io/tools/swagger-ui/)
Expand Down
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,24 @@
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile-core</artifactId>
<exclusions>
<!-- Confuses logger -->
<!-- Confuses slf4j logger -->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- MP OpenAPI used e.g. for OpenApi-UI -->
<dependency>
<groupId>io.helidon.microprofile.openapi</groupId>
<artifactId>helidon-microprofile-openapi</artifactId>
</dependency>
<!-- MP Health-Checks -->
<dependency>
<groupId>io.helidon.microprofile.health</groupId>
<artifactId>helidon-microprofile-health</artifactId>
</dependency>
<!-- Logging adapter -->
<dependency>
<groupId>io.helidon.logging</groupId>
<artifactId>helidon-logging-slf4j</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package hackathon.microstream.service.system.health;

import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;

import javax.enterprise.context.ApplicationScoped;

/**
* Checks if the app is alive
*/
@Liveness
@ApplicationScoped
public class LivenessHealthCheck implements HealthCheck {
@Override
public HealthCheckResponse call() {
return HealthCheckResponse.up("liveness");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package hackathon.microstream.service.system.health;

import hackathon.microstream.storage.DBManager;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Readiness;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.ApplicationScoped;

/**
* Checks if the app is ready (for traffic)
*/
@Readiness
@ApplicationScoped
public class ReadinessHealthCheck implements HealthCheck {

private static final Logger LOG = LoggerFactory.getLogger(ReadinessHealthCheck.class);

@Override
public HealthCheckResponse call() {

boolean up = DBManager.getInstance().isReady();

var builder = HealthCheckResponse.builder()
.name("storage")
.withData("demoMode", DBManager.getInstance().isDemoMode())
.state(up);

if(up) {
var storageManagerDetails = DBManager.getInstance().getStorageManagerDetails();
builder.withData("storageManager.name", storageManagerDetails.getName());
builder.withData("storageManager.active", storageManagerDetails.isActive());
builder.withData("storageManager.initializationTime", storageManagerDetails.getInitializationTime());
builder.withData("storageManager.initializationDuration", storageManagerDetails.getInitializationDuration());
builder.withData("storageManager.operationModeTime", storageManagerDetails.getOperationModeTime());
}

return builder.build();
}
}
48 changes: 48 additions & 0 deletions src/main/java/hackathon/microstream/storage/DBManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,52 @@ public void save(Iterable<Object> instances) {
public DBContext getContext() {
return context;
}

public boolean isReady() {
return this.initialized && this.storageManager.isRunning();
}

public boolean isDemoMode() {
return demoMode;
}

public StorageManagerDetails getStorageManagerDetails() {
return this.storageManager != null ? new StorageManagerDetails(this.storageManager) : null;
}

public class StorageManagerDetails {
private String name;
private boolean active;
private long initializationTime;
private long initializationDuration;
private long operationModeTime;

public StorageManagerDetails(StorageManager storageManager) {
this.name = storageManager.getClass().getCanonicalName();
this.active = storageManager.isActive();
this.initializationTime = storageManager.initializationTime();
this.initializationDuration = storageManager.initializationDuration();
this.operationModeTime = storageManager.operationModeTime();
}

public String getName() {
return name;
}

public boolean isActive() {
return active;
}

public long getInitializationTime() {
return initializationTime;
}

public long getInitializationDuration() {
return initializationDuration;
}

public long getOperationModeTime() {
return operationModeTime;
}
}
}

0 comments on commit 63decf5

Please sign in to comment.