use of com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker in project nacos by alibaba.
the class HealthCheckExtendProvider method loadExtend.
private void loadExtend() {
Iterator<HealthCheckProcessor> processorIt = processors.iterator();
Iterator<AbstractHealthChecker> healthCheckerIt = checkers.iterator();
Set<String> origin = new HashSet<>();
for (HealthCheckType type : HealthCheckType.values()) {
origin.add(type.name());
}
Set<String> processorType = new HashSet<>(origin);
Set<String> healthCheckerType = new HashSet<>(origin);
while (processorIt.hasNext()) {
HealthCheckProcessor processor = processorIt.next();
String type = processor.getType();
if (processorType.contains(type)) {
throw new RuntimeException("More than one processor of the same type was found : [type=\"" + type + "\"]");
}
processorType.add(type);
registry.registerSingleton(lowerFirstChar(processor.getClass().getSimpleName()), processor);
}
while (healthCheckerIt.hasNext()) {
AbstractHealthChecker checker = healthCheckerIt.next();
String type = checker.getType();
if (healthCheckerType.contains(type)) {
throw new RuntimeException("More than one healthChecker of the same type was found : [type=\"" + type + "\"]");
}
healthCheckerType.add(type);
HealthCheckType.registerHealthChecker(checker.getType(), checker.getClass());
}
if (!processorType.equals(healthCheckerType)) {
throw new RuntimeException("An unmatched processor and healthChecker are detected in the extension package.");
}
if (processorType.size() > origin.size()) {
processorType.removeAll(origin);
LOGGER.debug("init health plugin : types=" + processorType);
}
}
use of com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker in project nacos by alibaba.
the class ClusterController method update.
/**
* Update cluster.
*
* @param request http request
* @return 'ok' if success
* @throws Exception if failed
*/
@PutMapping
@Secured(action = ActionTypes.WRITE)
public String update(HttpServletRequest request) throws Exception {
final String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
final String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME);
final String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
ClusterMetadata clusterMetadata = new ClusterMetadata();
clusterMetadata.setHealthyCheckPort(NumberUtils.toInt(WebUtils.required(request, "checkPort")));
clusterMetadata.setUseInstancePortForCheck(ConvertUtils.toBoolean(WebUtils.required(request, "useInstancePort4Check")));
AbstractHealthChecker healthChecker = HealthCheckerFactory.deserialize(WebUtils.required(request, "healthChecker"));
clusterMetadata.setHealthChecker(healthChecker);
clusterMetadata.setHealthyCheckType(healthChecker.getType());
clusterMetadata.setExtendData(UtilsAndCommons.parseMetadata(WebUtils.optional(request, "metadata", StringUtils.EMPTY)));
judgeClusterOperator().updateClusterMetadata(namespaceId, serviceName, clusterName, clusterMetadata);
return "ok";
}
use of com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker in project nacos by alibaba.
the class HealthController method checkers.
/**
* Get all health checkers.
*
* @return health checkers map
*/
@GetMapping("/checkers")
public ResponseEntity checkers() {
List<Class<? extends AbstractHealthChecker>> classes = HealthCheckType.getLoadedHealthCheckerClasses();
Map<String, AbstractHealthChecker> checkerMap = new HashMap<>(8);
for (Class<? extends AbstractHealthChecker> clazz : classes) {
try {
AbstractHealthChecker checker = clazz.newInstance();
checkerMap.put(checker.getType(), checker);
} catch (InstantiationException | IllegalAccessException e) {
Loggers.EVT_LOG.error("checkers error ", e);
}
}
return ResponseEntity.ok(checkerMap);
}
Aggregations