package com.ctrip.zeus.service.build.conf;


import com.ctrip.zeus.model.entity.Group;
import com.ctrip.zeus.model.entity.HealthCheck;
import com.ctrip.zeus.model.entity.Slb;
import com.ctrip.zeus.model.entity.VirtualServer;
import com.ctrip.zeus.util.AssertUtils;

/**
 * @author:xingchaowang
 * @date: 3/8/2015.
 */
public class HealthCheckConf {
    public static String generate(Slb slb, VirtualServer vs, Group group) throws Exception {
        HealthCheck h = group.getHealthCheck();
        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);

        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();
    }
}

@@ -262,91 +262,350 @@
 ls;%0A
-%0A/**%0A * @author:xingchaowang%0A * @date: 3/8/2015.%0A */%0Apublic class HealthCheckConf %7B
+import com.netflix.config.DynamicBooleanProperty;%0Aimport com.netflix.config.DynamicPropertyFactory;%0A%0A/**%0A * @author:xingchaowang%0A * @date: 3/8/2015.%0A */%0Apublic class HealthCheckConf %7B%0A%0A    private static DynamicBooleanProperty disableHealthCheck = DynamicPropertyFactory.getInstance().getBooleanProperty(%22build.disable.healthCheck%22, false);%0A%0A
 %0A   
@@ -694,16 +694,97 @@
 ption %7B%0A
+        if (disableHealthCheck.get())%0A        %7B%0A            return %22%22;%0A        %7D%0A
         
@@ -875,20 +875,18 @@
  return 
-null
+%22%22
 ;%0A      

add health check disable config