package cn.seecoder.paas.service.model.vo; import cn.seecoder.paas.util.enums.ConfigBelongsToType; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.util.Collections; import java.util.HashMap; import java.util.Map; @Data @NoArgsConstructor @AllArgsConstructor public class ConfigVO { private Integer id; private ConfigBelongsToType configBelongs; private Integer entityId; private ConfigContent config; private static final ConfigContent EMPTY_CONFIG_CONTENT; static { EMPTY_CONFIG_CONTENT = new ConfigContent(null, null, Collections.emptyMap(), null, null, Collections.emptyMap(), Collections.emptyMap(), null, null, Collections.emptyMap(), Collections.emptyMap()); } public static ConfigVO getEmptyConfigVO(ConfigBelongsToType configBelongs, Integer entityId) { ConfigVO configVO = new ConfigVO(); configVO.setEntityId(entityId); configVO.setConfigBelongs(configBelongs); configVO.setConfig(EMPTY_CONFIG_CONTENT); return configVO; } @Data @AllArgsConstructor @NoArgsConstructor public static class ConfigContent { @JsonIgnore public static final String PATH_DELIMITER = "-spdelimiter-"; /** * 服务端口 */ @JsonProperty("servicePort") private String servicePort; /** * 服务端口 */ @JsonProperty("ingressPort") private String ingressPort; /** * 环境变量配置 */ @JsonProperty("envs") private Map envs; /** * 启动参数配置 CMD space split */ @JsonProperty("runArgs") private String runArgs; /** * 运行命令配置 ENTRYPOINT space split */ @JsonProperty("runCommands") private String runCommands; /** * 挂载文件配置 */ @JsonProperty("mounts") private Map mounts; /** * key:hostPath * value:mountPath */ @JsonProperty("hostPath") private Map hostPath; @JsonProperty("hostPrefix") private String hostPrefix; @JsonProperty("replicas") private Integer replicas; @JsonProperty("ingressAnnotations") private Map> ingressAnnotations; /** * key:pvcName * value:pvcValue */ @JsonProperty("pvcPaths") private Map pvcPaths; @JsonIgnore() public boolean isValid() { return servicePort != null && hostPrefix != null; } @JsonIgnore() public Map getMountsConfigMaps() { if (this.mounts == null) { return Collections.emptyMap(); } Map maps = new HashMap<>(); for (String key : this.mounts.keySet()) { maps.put(key.replaceAll("/", PATH_DELIMITER), this.mounts.get(key)); } return maps; } } }