Search in sources :

Example 1 with EnvironmentInfo

use of com.ctrip.framework.apollo.portal.entity.vo.EnvironmentInfo in project apollo by ctripcorp.

the class SystemInfoController method checkHealth.

@PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
@GetMapping(value = "/health")
public Health checkHealth(@RequestParam String instanceId) {
    List<Env> allEnvs = portalSettings.getAllEnvs();
    ServiceDTO service = null;
    for (final Env env : allEnvs) {
        EnvironmentInfo envInfo = adaptEnv2EnvironmentInfo(env);
        if (envInfo.getAdminServices() != null) {
            for (final ServiceDTO s : envInfo.getAdminServices()) {
                if (instanceId.equals(s.getInstanceId())) {
                    service = s;
                    break;
                }
            }
        }
        if (envInfo.getConfigServices() != null) {
            for (final ServiceDTO s : envInfo.getConfigServices()) {
                if (instanceId.equals(s.getInstanceId())) {
                    service = s;
                    break;
                }
            }
        }
    }
    if (service == null) {
        throw new IllegalArgumentException("No such instance of instanceId: " + instanceId);
    }
    return restTemplate.getForObject(service.getHomepageUrl() + "/health", Health.class);
}
Also used : EnvironmentInfo(com.ctrip.framework.apollo.portal.entity.vo.EnvironmentInfo) ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) Env(com.ctrip.framework.apollo.portal.environment.Env) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with EnvironmentInfo

use of com.ctrip.framework.apollo.portal.entity.vo.EnvironmentInfo in project apollo by ctripcorp.

the class SystemInfoController method getSystemInfo.

@PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
@GetMapping
public SystemInfo getSystemInfo() {
    SystemInfo systemInfo = new SystemInfo();
    String version = Apollo.VERSION;
    if (isValidVersion(version)) {
        systemInfo.setVersion(version);
    }
    List<Env> allEnvList = portalSettings.getAllEnvs();
    for (Env env : allEnvList) {
        EnvironmentInfo environmentInfo = adaptEnv2EnvironmentInfo(env);
        systemInfo.addEnvironment(environmentInfo);
    }
    return systemInfo;
}
Also used : SystemInfo(com.ctrip.framework.apollo.portal.entity.vo.SystemInfo) EnvironmentInfo(com.ctrip.framework.apollo.portal.entity.vo.EnvironmentInfo) Env(com.ctrip.framework.apollo.portal.environment.Env) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with EnvironmentInfo

use of com.ctrip.framework.apollo.portal.entity.vo.EnvironmentInfo in project apollo by ctripcorp.

the class SystemInfoController method adaptEnv2EnvironmentInfo.

private EnvironmentInfo adaptEnv2EnvironmentInfo(final Env env) {
    EnvironmentInfo environmentInfo = new EnvironmentInfo();
    String metaServerAddresses = portalMetaDomainService.getMetaServerAddress(env);
    environmentInfo.setEnv(env);
    environmentInfo.setActive(portalSettings.isEnvActive(env));
    environmentInfo.setMetaServerAddress(metaServerAddresses);
    String selectedMetaServerAddress = portalMetaDomainService.getDomain(env);
    try {
        environmentInfo.setConfigServices(getServerAddress(selectedMetaServerAddress, CONFIG_SERVICE_URL_PATH));
        environmentInfo.setAdminServices(getServerAddress(selectedMetaServerAddress, ADMIN_SERVICE_URL_PATH));
    } catch (Throwable ex) {
        String errorMessage = "Loading config/admin services from meta server: " + selectedMetaServerAddress + " failed!";
        logger.error(errorMessage, ex);
        environmentInfo.setErrorMessage(errorMessage + " Exception: " + ex.getMessage());
    }
    return environmentInfo;
}
Also used : EnvironmentInfo(com.ctrip.framework.apollo.portal.entity.vo.EnvironmentInfo)

Aggregations

EnvironmentInfo (com.ctrip.framework.apollo.portal.entity.vo.EnvironmentInfo)3 Env (com.ctrip.framework.apollo.portal.environment.Env)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ServiceDTO (com.ctrip.framework.apollo.core.dto.ServiceDTO)1 SystemInfo (com.ctrip.framework.apollo.portal.entity.vo.SystemInfo)1