ConfigVO.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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, Collections.emptyMap(), null, null, Collections.emptyMap(), Collections.emptyMap(), null, null, 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("envs")
  45. private Map<String, String> envs;
  46. /**
  47. * 启动参数配置 CMD space split
  48. */
  49. @JsonProperty("runArgs")
  50. private String runArgs;
  51. /**
  52. * 运行命令配置 ENTRYPOINT space split
  53. */
  54. @JsonProperty("runCommands")
  55. private String runCommands;
  56. /**
  57. * 挂载文件配置
  58. */
  59. @JsonProperty("mounts")
  60. private Map<String, String> mounts;
  61. /**
  62. * key:hostPath
  63. * value:mountPath
  64. */
  65. @JsonProperty("hostPath")
  66. private Map<String, String> hostPath;
  67. @JsonProperty("hostPrefix")
  68. private String hostPrefix;
  69. @JsonProperty("replicas")
  70. private Integer replicas;
  71. @JsonProperty("ingressAnnotations")
  72. private Map<String, Map<String, String>> ingressAnnotations;
  73. @JsonIgnore()
  74. public boolean isValid() {
  75. return servicePort != null && hostPrefix != null;
  76. }
  77. @JsonIgnore()
  78. public Map<String, String> getMountsConfigMaps() {
  79. if (this.mounts == null) {
  80. return Collections.emptyMap();
  81. }
  82. Map<String, String> maps = new HashMap<>();
  83. for (String key : this.mounts.keySet()) {
  84. maps.put(key.replaceAll("/", PATH_DELIMITER), this.mounts.get(key));
  85. }
  86. return maps;
  87. }
  88. }
  89. }