AppHealthCheck.java
/*
* Copyright © 2022-2025 The CTAN Team and individual authors
*
* This file is distributed under the 3-clause BSD license.
* See file LICENSE for details.
*/
package org.ctan.site.health;
import java.io.File;
import org.ctan.site.CtanConfiguration;
import com.codahale.metrics.health.HealthCheck;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* The class <code>AppHealthCheck</code> contains the health check for the
* application. It checks that
* <ul>
* <li>the configuration is not null.</li>
* <li>the sub-configuration <code>ctan</code> is not null.</li>
* <li>the sub-configuration <code>index</code> is not null.</li>
* <li>the attribute <code>directory</code> of the sub-configuration
* <code>index</code> is not null.</li>
* <li>the attribute <code>directory</code> of the sub-configuration
* <code>index</code> points to an existing directory.</li>
* </ul>
*
* @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
*/
@SuppressFBWarnings(value = "EI_EXPOSE_REP2")
public class AppHealthCheck extends HealthCheck {
/**
* The field <code>config</code> contains the configuration.
*/
private CtanConfiguration config;
/**
* This is the constructor for the class <code>AppHealthCheck</code>.
*
* @param config the configuration
*/
public AppHealthCheck(CtanConfiguration config) {
this.config = config;
}
/**
* {@inheritDoc}
*
* @see com.codahale.metrics.health.HealthCheck#check()
*/
@Override
protected Result check() throws Exception {
if (config == null) {
return Result.unhealthy("Missing configuration");
} else if (config.getCtan() == null) {
return Result.unhealthy("Missing CTAN config");
}
var index = config.getIndex();
if (index == null) {
return Result.unhealthy("Missing index config");
}
var directory = index.getDirectory();
if (directory == null) {
return Result.unhealthy("Missing index.directory config");
}
var dir = new File(directory);
if (!dir.isDirectory()) {
return Result.unhealthy("index.directory not found");
}
return Result.healthy();
}
}