Search in sources :

Example 1 with AbstractHealthChecker

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);
    }
}
Also used : HealthCheckProcessor(com.alibaba.nacos.naming.healthcheck.HealthCheckProcessor) AbstractHealthChecker(com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker) HealthCheckType(com.alibaba.nacos.api.naming.pojo.healthcheck.HealthCheckType) HashSet(java.util.HashSet)

Example 2 with AbstractHealthChecker

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";
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata) AbstractHealthChecker(com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker) Secured(com.alibaba.nacos.auth.annotation.Secured) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 3 with AbstractHealthChecker

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);
}
Also used : HashMap(java.util.HashMap) AbstractHealthChecker(com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

AbstractHealthChecker (com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker)3 HealthCheckType (com.alibaba.nacos.api.naming.pojo.healthcheck.HealthCheckType)1 Secured (com.alibaba.nacos.auth.annotation.Secured)1 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)1 HealthCheckProcessor (com.alibaba.nacos.naming.healthcheck.HealthCheckProcessor)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1