ConfigVO.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package cn.seecoder.paas.service.model.vo;
  2. import cn.seecoder.paas.util.enums.ConfigBelongsToType;
  3. import com.fasterxml.jackson.annotation.JsonIgnore;
  4. import com.fasterxml.jackson.annotation.JsonProperty;
  5. import lombok.AllArgsConstructor;
  6. import lombok.Data;
  7. import lombok.NoArgsConstructor;
  8. import java.util.Collections;
  9. import java.util.HashMap;
  10. import java.util.Map;
  11. @Data
  12. @NoArgsConstructor
  13. @AllArgsConstructor
  14. public class ConfigVO {
  15. private Integer id;
  16. private ConfigBelongsToType configBelongs;
  17. private Integer entityId;
  18. private ConfigContent config;
  19. private static final ConfigContent EMPTY_CONFIG_CONTENT;
  20. static {
  21. EMPTY_CONFIG_CONTENT = new ConfigContent(null, null, Collections.emptyMap(), null, null, Collections.emptyMap(), Collections.emptyMap(), null, null, Collections.emptyMap(), Collections.emptyMap());
  22. }
  23. public static ConfigVO getEmptyConfigVO(ConfigBelongsToType configBelongs, Integer entityId) {
  24. ConfigVO configVO = new ConfigVO();
  25. configVO.setEntityId(entityId);
  26. configVO.setConfigBelongs(configBelongs);
  27. configVO.setConfig(EMPTY_CONFIG_CONTENT);
  28. return configVO;
  29. }
  30. @Data
  31. @AllArgsConstructor
  32. @NoArgsConstructor
  33. public static class ConfigContent {
  34. @JsonIgnore
  35. public static final String PATH_DELIMITER = "-spdelimiter-";
  36. /**
  37. * 服务端口
  38. */
  39. @JsonProperty("servicePort")
  40. private String servicePort;
  41. /**
  42. * 服务端口
  43. */
  44. @JsonProperty("ingressPort")
  45. private String ingressPort;
  46. /**
  47. * 环境变量配置
  48. */
  49. @JsonProperty("envs")
  50. private Map<String, String> envs;
  51. /**
  52. * 启动参数配置 CMD space split
  53. */
  54. @JsonProperty("runArgs")
  55. private String runArgs;
  56. /**
  57. * 运行命令配置 ENTRYPOINT space split
  58. */
  59. @JsonProperty("runCommands")
  60. private String runCommands;
  61. /**
  62. * 挂载文件配置
  63. */
  64. @JsonProperty("mounts")
  65. private Map<String, String> mounts;
  66. /**
  67. * key:hostPath
  68. * value:mountPath
  69. */
  70. @JsonProperty("hostPath")
  71. private Map<String, String> hostPath;
  72. @JsonProperty("hostPrefix")
  73. private String hostPrefix;
  74. @JsonProperty("replicas")
  75. private Integer replicas;
  76. @JsonProperty("ingressAnnotations")
  77. private Map<String, Map<String, String>> ingressAnnotations;
  78. /**
  79. * key:pvcName
  80. * value:pvcValue
  81. */
  82. @JsonProperty("pvcPaths")
  83. private Map<String, String> pvcPaths;
  84. @JsonIgnore()
  85. public boolean isValid() {
  86. return servicePort != null && hostPrefix != null;
  87. }
  88. @JsonIgnore()
  89. public Map<String, String> getMountsConfigMaps() {
  90. if (this.mounts == null) {
  91. return Collections.emptyMap();
  92. }
  93. Map<String, String> maps = new HashMap<>();
  94. for (String key : this.mounts.keySet()) {
  95. maps.put(key.replaceAll("/", PATH_DELIMITER), this.mounts.get(key));
  96. }
  97. return maps;
  98. }
  99. }
  100. }