@PropertySource("classpath:iotivity.properties") })
public class HealthCheck {
- private static AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
private static final Logger LOG = Logger.getLogger(HealthCheck.class);
private static void sleep() {
return true;
}
} catch (IOException e) {
- LOG.debug("checkUrl exception ", e);
+ LOG.debug("checkUrl exception: " + e.getMessage());
}
LOG.info(url+" not available...");
return false;
}
- private static void checkHost(String prop) {
- String host = ctx.getEnvironment().getRequiredProperty(prop);
+ private static void checkHost(String host) {
while (!checkSocket(host)) {
sleep();
LOG.info("can not connect to "+host+"...");
}
}
- private static void checkDsm(String prop) {
- String url = ctx.getEnvironment().getRequiredProperty(prop);
+ private static void checkDsm(String url) {
while (!checkUrl(url)) {
sleep();
LOG.info("can not connect to "+url+"...");
}
static void checkDependencies() {
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(HealthCheck.class);
ctx.refresh();
- checkHost("iotivity.zookeeper_host");
- checkHost("iotivity.kafka_host");
- checkDsm("dsm.host");
+ checkHost(ctx.getEnvironment().getRequiredProperty("iotivity.zookeeper_host"));
+ checkHost(ctx.getEnvironment().getRequiredProperty("iotivity.kafka_host"));
+ String dsmUrl = ctx.getEnvironment().getRequiredProperty("dsm.host");
+ String dsmHost = dsmUrl.replace("http://", "");
+ checkHost(dsmHost);
+ checkDsm(dsmUrl);
}
/**