Commit dfe38a42 authored by mahdisellami's avatar mahdisellami
Browse files

Added Database Health Check

parent 69cac169
......@@ -14,6 +14,8 @@ import org.tmms.classification.db.LemmaDAO;
import org.tmms.classification.db.NamedEntityRecognitionDAO;
import org.tmms.classification.db.PartOfSpeechDAO;
import org.tmms.classification.db.SentimentDAO;
import org.tmms.classification.health.DatabaseHealthCheck;
import org.tmms.classification.health.TemplateHealthCheck;
import org.tmms.classification.resources.ApiInfoResource;
import org.tmms.classification.resources.LemmaAnnotationResource;
import org.tmms.classification.resources.NamedEntityRecognitionResource;
......@@ -103,6 +105,8 @@ public class classificationserviceApplication extends Application<classification
// TemplateHealthCheck(configuration.getTemplate());
// environment.healthChecks().register("template", healthCheck);
// environment.jersey().register(helloWorldResource);
final DatabaseHealthCheck dbHealthCheck = new DatabaseHealthCheck(configuration.getDataSourceFactory());
environment.healthChecks().register("database", dbHealthCheck);
final ApiInfoResource apiInfoResource = new ApiInfoResource(environment);
environment.jersey().register(apiInfoResource);
......
package org.tmms.classification.health;
import com.codahale.metrics.health.HealthCheck;
import io.dropwizard.db.DataSourceFactory;
public class DatabaseHealthCheck extends HealthCheck {
private final DataSourceFactory database;
public DatabaseHealthCheck(DataSourceFactory database) {
this.database = database;
}
@Override
protected Result check() throws Exception {
if (database.getCheckConnectionOnConnect()) {
return Result.healthy();
} else {
return Result.unhealthy("Cannot connect to " + database.getUrl());
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment