<commit_before>package com.ctrip.zeus.service.build.conf;

import com.ctrip.zeus.exceptions.ValidationException;
import com.ctrip.zeus.model.entity.Domain;
import com.ctrip.zeus.model.entity.Group;
import com.ctrip.zeus.model.entity.Slb;
import com.ctrip.zeus.model.entity.VirtualServer;
import com.ctrip.zeus.service.build.ConfigHandler;
import com.ctrip.zeus.util.AssertUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author:xingchaowang
 * @date: 3/8/2015.
 */
@Component("serverConf")
public class ServerConf {
    @Resource
    ConfigHandler configHandler;
    @Resource
    LocationConf locationConf;

    public static final String SSL_PATH = "/data/nginx/ssl/";
    private static final String ZONENAME = "proxy_zone";

    public String generate(Slb slb, VirtualServer vs, List<Group> groups) throws Exception {
        Long slbId = slb.getId();
        Long vsId = vs.getId();

        ConfWriter confWriter = new ConfWriter(1024, true);
        try {
            Integer.parseInt(vs.getPort());
        } catch (Exception e) {
            throw new ValidationException("virtual server [" + vs.getId() + "] port is illegal!");
        }

        confWriter.writeServerStart();
        if (vs.isSsl() && configHandler.getEnable("http.version.2", slbId, null, null, false)) {
            writeHttp2Configs(confWriter, slbId, vs);
        } else {
            confWriter.writeCommand("listen", vs.getPort());
        }
        confWriter.writeCommand("server_name", getServerNames(vs));
        confWriter.writeCommand("ignore_invalid_headers", "off");
        confWriter.writeCommand("proxy_http_version", "1.1");

        if (configHandler.getEnable("server.proxy.buffer.size", slbId, vsId, null, false)) {
            confWriter.writeCommand("proxy_buffer_size", configHandler.getStringValue("server.proxy.buffer.size", slbId, vsId, null, "8k"));
            confWriter.writeCommand("proxy_buffers", configHandler.getStringValue("server.proxy.buffers", slbId, vsId, null, "8 8k"));
            confWriter.writeCommand("proxy_busy_buffers_size", configHandler.getStringValue("server.proxy.busy.buffers.size", slbId, vsId, null, "8k"));
        }

        if (configHandler.getEnable("large.client.header.buffers", slbId, vsId, null, false)) {
            confWriter.writeCommand("large_client_header_buffers", configHandler.getStringValue("large.client.header.buffers", slbId, vsId, null, "4 8k"));
        }

        if (vs.isSsl()) {
            confWriter.writeCommand("ssl", "on");
            confWriter.writeCommand("ssl_certificate", SSL_PATH + vsId + "/ssl.crt");
            confWriter.writeCommand("ssl_certificate_key", SSL_PATH + vsId + "/ssl.key");
            confWriter.writeCommand("ssl_protocols", getProtocols(slbId, vsId));
            confWriter.writeCommand("ssl_prefer_server_ciphers", configHandler.getStringValue("ssl.prefer.server.ciphers", slbId, vsId, null, "on"));
            confWriter.writeCommand("ssl_ciphers", configHandler.getStringValue("ssl.ciphers", slbId, vsId, null, "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;"));

            confWriter.writeCommand("ssl_session_cache", configHandler.getStringValue("ssl.session.cache", slbId, vsId, null, "shared:SSL:20m"));
            confWriter.writeCommand("ssl_session_timeout", configHandler.getStringValue("ssl.session.cache.timeout", slbId, vsId, null, "180m"));

        }

        if (configHandler.getEnable("server.vs.health.check", slbId, vsId, null, false)) {
            locationConf.writeHealthCheckLocation(confWriter, slbId, vsId);
        }

        confWriter.writeCommand("req_status", ZONENAME);

        //add locations
        for (Group group : groups) {
            locationConf.write(confWriter, slb, vs, group);
        }

        if (configHandler.getEnable("server.errorPage", slbId, vsId, null, false)) {
            boolean useNew = configHandler.getEnable("server.errorPage.use.new", slbId, vsId, null, true);
            for (int sc = 400; sc <= 425; sc++) {
                locationConf.writeErrorPageLocation(confWriter, useNew, sc, slbId, vsId);
            }
            for (int sc = 500; sc <= 510; sc++) {
                locationConf.writeErrorPageLocation(confWriter, useNew, sc, slbId, vsId);
            }
        }

        confWriter.writeServerEnd();
        return confWriter.getValue();
    }<commit_msg>fix config error using default value<commit_after>package com.ctrip.zeus.service.build.conf;

import com.ctrip.zeus.exceptions.ValidationException;
import com.ctrip.zeus.model.entity.Domain;
import com.ctrip.zeus.model.entity.Group;
import com.ctrip.zeus.model.entity.Slb;
import com.ctrip.zeus.model.entity.VirtualServer;
import com.ctrip.zeus.service.build.ConfigHandler;
import com.ctrip.zeus.util.AssertUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author:xingchaowang
 * @date: 3/8/2015.
 */
@Component("serverConf")
public class ServerConf {
    @Resource
    ConfigHandler configHandler;
    @Resource
    LocationConf locationConf;

    public static final String SSL_PATH = "/data/nginx/ssl/";
    private static final String ZONENAME = "proxy_zone";

    public String generate(Slb slb, VirtualServer vs, List<Group> groups) throws Exception {
        Long slbId = slb.getId();
        Long vsId = vs.getId();

        ConfWriter confWriter = new ConfWriter(1024, true);
        try {
            Integer.parseInt(vs.getPort());
        } catch (Exception e) {
            throw new ValidationException("virtual server [" + vs.getId() + "] port is illegal!");
        }

        confWriter.writeServerStart();
        if (vs.isSsl() && configHandler.getEnable("http.version.2", slbId, null, null, false)) {
            writeHttp2Configs(confWriter, slbId, vs);
        } else {
            confWriter.writeCommand("listen", vs.getPort());
        }
        confWriter.writeCommand("server_name", getServerNames(vs));
        confWriter.writeCommand("ignore_invalid_headers", "off");
        confWriter.writeCommand("proxy_http_version", "1.1");

        if (configHandler.getEnable("server.proxy.buffer.size", slbId, vsId, null, false)) {
            confWriter.writeCommand("proxy_buffer_size", configHandler.getStringValue("server.proxy.buffer.size", slbId, vsId, null, "8k"));
            confWriter.writeCommand("proxy_buffers", configHandler.getStringValue("server.proxy.buffers", slbId, vsId, null, "8 8k"));
            confWriter.writeCommand("proxy_busy_buffers_size", configHandler.getStringValue("server.proxy.busy.buffers.size", slbId, vsId, null, "8k"));
        }

        if (configHandler.getEnable("large.client.header.buffers", slbId, vsId, null, false)) {
            confWriter.writeCommand("large_client_header_buffers", configHandler.getStringValue("large.client.header.buffers", slbId, vsId, null, "4 8k"));
        }

        if (vs.isSsl()) {
            confWriter.writeCommand("ssl", "on");
            confWriter.writeCommand("ssl_certificate", SSL_PATH + vsId + "/ssl.crt");
            confWriter.writeCommand("ssl_certificate_key", SSL_PATH + vsId + "/ssl.key");
            confWriter.writeCommand("ssl_protocols", getProtocols(slbId, vsId));
            confWriter.writeCommand("ssl_prefer_server_ciphers", configHandler.getStringValue("ssl.prefer.server.ciphers", slbId, vsId, null, "on"));
            confWriter.writeCommand("ssl_ciphers", configHandler.getStringValue("ssl.ciphers", slbId, vsId, null, "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5"));

            confWriter.writeCommand("ssl_session_cache", configHandler.getStringValue("ssl.session.cache", slbId, vsId, null, "shared:SSL:20m"));
            confWriter.writeCommand("ssl_session_timeout", configHandler.getStringValue("ssl.session.cache.timeout", slbId, vsId, null, "180m"));

        }

        if (configHandler.getEnable("server.vs.health.check", slbId, vsId, null, false)) {
            locationConf.writeHealthCheckLocation(confWriter, slbId, vsId);
        }

        confWriter.writeCommand("req_status", ZONENAME);

        //add locations
        for (Group group : groups) {
            locationConf.write(confWriter, slb, vs, group);
        }

        if (configHandler.getEnable("server.errorPage", slbId, vsId, null, false)) {
            boolean useNew = configHandler.getEnable("server.errorPage.use.new", slbId, vsId, null, true);
            for (int sc = 400; sc <= 425; sc++) {
                locationConf.writeErrorPageLocation(confWriter, useNew, sc, slbId, vsId);
            }
            for (int sc = 500; sc <= 510; sc++) {
                locationConf.writeErrorPageLocation(confWriter, useNew, sc, slbId, vsId);
            }
        }

        confWriter.writeServerEnd();
        return confWriter.getValue();
    }
{'fraction_non_alphanumeric': 0.1338749165368351, 'fraction_numerical': 0.012463832628533273, 'mean_word_length': 3.3711089494163424, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4332275', 'n_tokens_mistral': 2847, 'n_tokens_neox': 2721, 'n_words': 483}