gteric 发表于 2018-1-6 17:51:40

JAVA中使用freemark生成自定义文件(json、excel、yaml、txt)

public static String layoutData(String name,int exposePort){// 编排基本信息  JSONObject layoutInfoJSON = new JSONObject();
  layoutInfoJSON.put("name", name + "layout");
  layoutInfoJSON.put("version", "v1.0");
  layoutInfoJSON.put("dmsAppName", name);
  layoutInfoJSON.put("dmsAppId", "0a2f9r8t7y6j7hg9");   //dms的应用Id
  layoutInfoJSON.put("replicas", 2);                      //副本数
  layoutInfoJSON.put("masterId", "beijing1");             //北京一区
  layoutInfoJSON.put("basicCpuScale", 1);               //pod基础设置:6核cpu
  layoutInfoJSON.put("basicMemScale", 2);               //pod基础设置:12G内存
  

  //构建微服务信息list
  //微服务1
  JSONArray msArray = new JSONArray();
  JSONObject msJsonObjectOne = new JSONObject();
  msJsonObjectOne.put("name", "tomcat");
  msJsonObjectOne.put("version", "1.0");
  msJsonObjectOne.put("type", 1);                         //微服务类型:1:service、2:job
  msJsonObjectOne.put("domain", "www.test.com");
  msJsonObjectOne.put("imageUrl", "tomcat-1");
  msJsonObjectOne.put("memRatio", 1);
  msJsonObjectOne.put("cpuRatio", 1);
  //微服务1中的ports 端口列表
  JSONArray portArray = new JSONArray();
  JSONObject portJsonObjectOne = new JSONObject();
  portJsonObjectOne.put("port", 8080);                        //容器本身的端口
  portJsonObjectOne.put("protocol", "tcp");                  //端口协议类型
  portJsonObjectOne.put("exposePort", exposePort);          //容器端口 - 外网暴露端口 注意端口占用
  
      portArray.add(portJsonObjectOne);
  msJsonObjectOne.put("ports", portArray);
  

  //微服务1中的evns 环境变量列表
  JSONArray evnArray = new JSONArray();
  JSONObject evnJsonObjectOne = new JSONObject();
  evnJsonObjectOne.put("key", "evn_key1");
  evnJsonObjectOne.put("value", "evn_value1");
  evnJsonObjectOne.put("option", "evn_option1");
  evnArray.add(evnJsonObjectOne);
  

  msJsonObjectOne.put("evns", evnArray);
  

  msArray.add(msJsonObjectOne);
  

  //把微服务放入编排信息中
  layoutInfoJSON.put("microServiceInfoList", msArray);
  

  return JSONObject.toJSONString(layoutInfoJSON);
  }
页: [1]
查看完整版本: JAVA中使用freemark生成自定义文件(json、excel、yaml、txt)