com.baidu.formula.discovery.autoconfigure.FormulaDiscoveryProperties Maven / Gradle / Ivy
package com.baidu.formula.discovery.autoconfigure;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.commons.util.InetUtils;
import lombok.Data;
/**
* @author Bowu Dong ([email protected])
*/
@Data
@ConfigurationProperties(FormulaDiscoveryProperties.PREFIX)
public class FormulaDiscoveryProperties implements DisposableBean {
public static final String PREFIX = "formula.discovery";
private static final String DEFAULT_ZONE = "zone1";
private InetUtils.HostInfo hostInfo;
private List tags = new ArrayList<>();
private boolean enabled = true;
private String ipAddress;
private String hostname;
private Integer port;
private Integer managementPort;
private boolean preferIpAddress = false;
private String app;
private String instanceId;
private String zone = DEFAULT_ZONE;
private String scheme = "http";
private String productName;
private String environment;
/**
* 用于同一产品下的资源隔离,eg workspace name.
*/
@NotNull
private String resourceIsolation;
private String region;
/**
* Map of app name's -> tag to query for in server list. This allows filtering services by a single tag.
*/
private Map serverListQueryTags = new HashMap<>();
private String defaultQueryTag;
private boolean register = true;
private boolean deregister = true;
private boolean failFast = true;
private Lifecycle lifecycle = new Lifecycle();
private Map headers = new LinkedHashMap<>();
/**
* health check
*/
private String healthCheckPath;
private String healthCheckInterval;
private String healthCheckTimeout;
/**
* 多久时间不注册失效时间
*/
private String healthCheckCriticalTimeout;
/**
* 扩展字段
*/
private Map customs;
public FormulaDiscoveryProperties(InetUtils inetUtils) {
hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
ipAddress = hostInfo.getIpAddress();
hostname = hostInfo.getHostname();
}
public String getQueryTagForService(String serviceId) {
String tag = serverListQueryTags.get(serviceId);
return tag != null ? tag : defaultQueryTag;
}
@Override
public void destroy() throws Exception {
serverListQueryTags = new HashMap<>();
}
@Data
public static class Lifecycle {
private boolean enabled = true;
}
}