use of io.vertigo.commons.analytics.health.HealthChecked in project vertigo by KleeGroup.
the class HealthAnalyticsUtil method createHealthCheckDefinitions.
/**
* Registers all methods annotated with @Suscriber on the object
* @param componentId componentId to check
* @param component Component to check
* @param aopPlugin Aop plugin use for unwrap
* @return List of HealthCheckDefinition
*/
public static List<HealthCheckDefinition> createHealthCheckDefinitions(final String componentId, final Component component, final AopPlugin aopPlugin) {
Assertion.checkNotNull(component);
// -- we construct a map of feature by componentId
final Map<String, String> featureByComponentId = new HashMap<>();
Home.getApp().getConfig().getModuleConfigs().forEach(moduleConfig -> moduleConfig.getComponentConfigs().forEach(componentConfig -> featureByComponentId.put(componentConfig.getId(), moduleConfig.getName())));
// 1. search all methods
return Stream.of(aopPlugin.unwrap(component).getClass().getMethods()).filter(method -> method.isAnnotationPresent(HealthChecked.class)).map(method -> {
final HealthChecked healthChecked = method.getAnnotation(HealthChecked.class);
Assertion.checkArgument(HealthMeasure.class.equals(method.getReturnType()), "health check methods of class {0} must return a HealthMeasure instead of {1}", component.getClass(), method.getReturnType());
Assertion.checkArgument(method.getName().startsWith("check"), "health check methods of class {0} must start with check", component.getClass());
Assertion.checkArgument(method.getParameterTypes().length == 0, "health check methods of class {0} must not have any parameter", component.getClass());
// -----
// 2. For each method register a listener
// we remove # because it doesn't comply with definition naming rule
final String healthCheckDefinitionName = "HCHK_" + StringUtil.camelToConstCase(componentId.replaceAll("#", "")) + "$" + StringUtil.camelToConstCase(method.getName());
return new HealthCheckDefinition(healthCheckDefinitionName, healthChecked.name(), componentId, featureByComponentId.get(componentId), healthChecked.feature(), () -> (HealthMeasure) ClassUtil.invoke(component, method));
}).collect(Collectors.toList());
}
use of io.vertigo.commons.analytics.health.HealthChecked in project vertigo by KleeGroup.
the class CachePlugin method checkIo.
/**
* @return HealthMeasure of this plugin
*/
@HealthChecked(name = "io", feature = "cache")
default HealthMeasure checkIo() {
final HealthMeasureBuilder healthMeasureBuilder = HealthMeasure.builder();
try {
put("CACHE_HEALTH_VERTIGO", "healthcheckkey", "healthcheckvalue");
get("CACHE_HEALTH_VERTIGO", "healthcheckkey");
remove("CACHE_HEALTH_VERTIGO", "healthcheckkey");
healthMeasureBuilder.withGreenStatus();
} catch (final Exception e) {
healthMeasureBuilder.withRedStatus(e.getMessage(), e);
}
return healthMeasureBuilder.build();
}
use of io.vertigo.commons.analytics.health.HealthChecked in project vertigo by KleeGroup.
the class RedisHealthChecker method checkRedisPing.
@HealthChecked(name = "ping", feature = "redisChecker")
public HealthMeasure checkRedisPing() {
final HealthMeasureBuilder healthMeasureBuilder = HealthMeasure.builder();
try (Jedis jedis = redisConnector.getResource()) {
final String result = jedis.ping();
healthMeasureBuilder.withGreenStatus(result);
} catch (final Exception e) {
healthMeasureBuilder.withRedStatus(e.getMessage(), e);
}
return healthMeasureBuilder.build();
}
Aggregations