Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Update to latest health API
Browse files Browse the repository at this point in the history
  • Loading branch information
heiko-braun committed Nov 25, 2016
1 parent ab7b605 commit 3ac6e99
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
@@ -1,6 +1,7 @@
package org.wildfly.swarm.examples.jaxrs.health;

import java.io.File;
import java.util.Date;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand All @@ -15,17 +16,40 @@ public class HealthCheckResource {
@Path("/health")
@Health
public HealthStatus checkDiskspace() {
File path = new File(".");

File path = new File(System.getProperty("user.home"));
long freeBytes = path.getFreeSpace();
long threshold = 1024 * 1024 * 100; // 100mb
return freeBytes>threshold ? HealthStatus.up() : HealthStatus.down().withAttribute("freebytes", freeBytes);
return freeBytes>threshold ?
HealthStatus.
named("diskspace")
.up()
.withAttribute("freebytes", freeBytes) :
HealthStatus.
named("diskspace")
.down()
.withAttribute("freebytes", freeBytes);
}

@GET
@Path("/second-health")
@Health(inheritSecurity = false)
@Health
public HealthStatus checkSomethingElse() {
return HealthStatus.up();

int tipping = (int) Math.ceil(Math.random() * 100);

if(tipping>50) {
return HealthStatus
.named("something-else")
.up()
.withAttribute("date", new Date().toString())
.withAttribute("time", System.currentTimeMillis());
} else {

return HealthStatus
.named("seomthing-else")
.down();
}
}

}
Expand Up @@ -27,14 +27,16 @@ public static void main(String[] args) throws Exception {
swarm
.fraction(LoggingFraction.createDefaultLoggingFraction())
.fraction(new MonitorFraction().securityRealm("ManagementRealm"))
.fraction(new ManagementFraction()
.securityRealm("ManagementRealm", (realm) -> {
realm.inMemoryAuthentication((authn) -> {
authn.add(new Properties() {{
put("admin", "password");
}}, true);
});
realm.inMemoryAuthorization();
.fraction(ManagementFraction
.createDefaultFraction()
.httpInterfaceManagementInterface()
.securityRealm("ManagementRealm", (realm) -> {
realm.inMemoryAuthentication((authn) -> {
authn.add(new Properties() {{
put("admin", "password");
}}, true);
});
realm.inMemoryAuthorization();
}))
.start()
.deploy(deployment);
Expand Down

0 comments on commit 3ac6e99

Please sign in to comment.