update health check config

This commit is contained in:
fanqq 2015-06-12 13:53:57 +08:00
parent e792c9a0bf
commit 6355fed45c

View file

@ -14,24 +14,38 @@ import com.ctrip.zeus.util.AssertUtils;
public class HealthCheckConf {
public static String generate(Slb slb, VirtualServer vs, Group group) throws Exception {
HealthCheck h = group.getHealthCheck();
AssertUtils.isNull(h,"Group HealthCheck config is null!");
if (h == null)
{
return null;
}
AssertUtils.isNull(h.getIntervals(),"Group HealthCheck Intervals config is null!");
AssertUtils.isNull(h.getFails(),"Group HealthCheck Fails config is null!");
AssertUtils.isNull(h.getPasses(),"Group HealthCheck Passes config is null!");
StringBuilder b = new StringBuilder(128);
b.append("check interval=").append(h.getIntervals())
.append(" rise=").append(h.getPasses())
.append(" fall=").append(h.getFails())
.append(" timeout=").append(1000)
.append(" type=http").append(";\n")
.append("check_keepalive_requests 100").append(";\n")
.append("check_http_send \"")
.append("GET ").append(h.getUri()).append(" HTTP/1.0\\r\\n")
.append(" Connection: keep-alive\\r\\n")
.append(" Host: ").append(vs.getDomains().get(0).getName()).append("\\r\\n\\r\\n\"").append(";\n")
.append("check_http_expect_alive http_2xx http_3xx").append(";\n");
if (group.getSsl())
{
b.append("check interval=").append(h.getIntervals())
.append(" rise=").append(h.getPasses())
.append(" fall=").append(h.getFails())
.append(" timeout=").append(1000)
.append(" type=ssl_hello").append(";\n");
}else {
b.append("check interval=").append(h.getIntervals())
.append(" rise=").append(h.getPasses())
.append(" fall=").append(h.getFails())
.append(" timeout=").append(1000)
.append(" type=http").append(";\n")
.append("check_keepalive_requests 100").append(";\n")
.append("check_http_send \"")
.append("GET ").append(h.getUri()).append(" HTTP/1.0\\r\\n")
.append(" Connection: keep-alive\\r\\n")
.append(" Host: ").append(vs.getDomains().get(0).getName()).append("\\r\\n\\r\\n\"").append(";\n")
.append("check_http_expect_alive http_2xx http_3xx").append(";\n");
}
return b.toString();
}
}