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

        AssertUtils.isNull(h,"Group HealthCheck config is 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");
        return b.toString();
    }
}

@@ -483,25 +483,24 @@
 heck();%0A
-%0A
         
 AssertUt
@@ -495,66 +495,67 @@
     
-AssertUtils.isNull(h,%22Group HealthCheck config is null!%22);
+if (h == null)%0A        %7B%0A            return null;%0A        %7D
 %0A   
@@ -814,16 +814,17 @@
 ll!%22);%0A%0A
+%0A
         
@@ -865,16 +865,59 @@
 r(128);%0A
+%0A        if (group.getSsl())%0A        %7B%0A    
         
@@ -977,32 +977,36 @@
                 
+   
+ 
 .append(%22 rise=%22
@@ -1037,32 +1037,36 @@
                 
+    
 .append(%22 fall=%22
@@ -1096,32 +1096,36 @@
                 
+ 
+   
 .append(%22 timeou
@@ -1142,16 +1142,336 @@
 d(1000)%0A
+                    .append(%22 type=ssl_hello%22).append(%22;%5Cn%22);%0A        %7Delse %7B%0A            b.append(%22check interval=%22).append(h.getIntervals())%0A                    .append(%22 rise=%22).append(h.getPasses())%0A                    .append(%22 fall=%22).append(h.getFails())%0A                    .append(%22 timeout=%22).append(1000)%0A    
         
@@ -1506,32 +1506,36 @@
 ).append(%22;%5Cn%22)%0A
+    
                 
@@ -1596,32 +1596,36 @@
                 
+    
 .append(%22check_h
@@ -1646,32 +1646,36 @@
                 
+  
+  
 .append(%22GET %22).
@@ -1727,32 +1727,36 @@
                 
+    
 .append(%22 Connec
@@ -1788,32 +1788,36 @@
                 
+ 
+   
 .append(%22 Host: 
@@ -1907,32 +1907,36 @@
                 
+   
+ 
 .append(%22check_h
@@ -1979,32 +1979,43 @@
 .append(%22;%5Cn%22);%0A
+        %7D%0A%0A
         return b

update health check config