You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

DataTransferController.java 5.6 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.educoder.bridge.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.educoder.bridge.exception.GameException;
  4. import com.educoder.bridge.service.GameService;
  5. import com.educoder.bridge.settings.AppConfig;
  6. import com.educoder.bridge.utils.Base64Util;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiOperation;
  9. import io.swagger.annotations.ApiParam;
  10. import org.apache.commons.io.FileUtils;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.http.MediaType;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import java.nio.charset.Charset;
  21. /**
  22. * created by weishao at 2017/8/7
  23. * 数据迁移控制器,用于保证已经发布的实训不受影响
  24. */
  25. @Api(value = "数据迁移控制器", hidden = true)
  26. @RestController
  27. @RequestMapping("/dataTransfer")
  28. public class DataTransferController extends BaseController{
  29. @Autowired
  30. private GameService gameService;
  31. @Autowired
  32. private AppConfig appConfig;
  33. private static final Logger logger = LoggerFactory.getLogger(DataTransferController.class);
  34. @RequestMapping(path = "/transfer")
  35. @ApiOperation(value = "数据迁移,写测试用例,生成模板脚本,tpi评测脚本", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
  36. public JSONObject transfer(
  37. @ApiParam(name = "gameInfo", required = true, value = "实训的相关配置,base64编码") @RequestParam String gameInfo,
  38. @ApiParam(name = "tpiList", required = true, value = "实训实例的信息,包括tpiID与instanceGitURL") @RequestParam String tpiList) {
  39. logger.debug("/dataTransfer/transfer: gameInfo: " + gameInfo + ", tpiList: " + tpiList);
  40. JSONObject result = new JSONObject();
  41. // // 将字符串解码后转换为JSON对象
  42. // gameInfo = Base64Util.decode(gameInfo);
  43. // JSONObject info = JSONObject.parseObject(gameInfo);
  44. //
  45. // tpiList = Base64Util.decode(tpiList);
  46. // JSONArray list = JSONObject.parseArray(tpiList);
  47. //
  48. // try {
  49. // transferTPM(info);
  50. //
  51. // for (int i = 0; i < list.size(); i++) {
  52. // try {
  53. // transferTPI(info.getString("tpmID"), list.getJSONObject(i).getString("tpiID"),
  54. // list.getJSONObject(i).getString("instanceGitURL"));
  55. // } catch (GameException e) {
  56. // logger.error("TPI 转换失败,tpiID:{}", list.getJSONObject(i).getString("tpiID"));
  57. // continue;
  58. // }
  59. // }
  60. // }catch (GameException e) {
  61. //
  62. // logger.error("TPM 转换失败,tpmID:{}", info.getString("tpmID"));
  63. // result.put("code", -1);
  64. // result.put("msg", "转换失败");
  65. // }
  66. result.put("code", 0);
  67. result.put("msg", "转换成功");
  68. return result;
  69. }
  70. @RequestMapping(path = "/transferTPI")
  71. @ApiOperation(value = "数据迁移,单个tpi迁移", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
  72. public JSONObject transferATPI(
  73. @ApiParam(name = "tpmID", required = true, value = "tpmID") @RequestParam String tpmID,
  74. @ApiParam(name = "tpiID", required = true, value = "tpiID") @RequestParam String tpiID,
  75. @ApiParam(name = "instanceGitURL", required = true, value = "TPI版本库地址,base64编码") @RequestParam String instanceGitURL)
  76. throws GameException {
  77. JSONObject result = new JSONObject();
  78. instanceGitURL = Base64Util.decode(instanceGitURL);
  79. transferTPI (tpmID, tpiID, instanceGitURL);
  80. result.put("code", 0);
  81. result.put("msg", "转换成功");
  82. return result;
  83. }
  84. /**
  85. * 转换tpm
  86. * @param gameInfo
  87. */
  88. private void transferTPM (JSONObject gameInfo) throws GameException {
  89. logger.debug("DataTransferController: transferTPM: gameInfo: " + gameInfo);
  90. // 将测试用例写入工作目录下的文件中
  91. // gameService.generateTestCasesForGame(gameInfo.getString("tpmID"),
  92. // gameInfo.getJSONArray("testCases"));
  93. //
  94. // // 生成Tpm评测脚本到工作目录下指定文件
  95. // gameService.generateTpmEvaluateShellScript(gameInfo);
  96. }
  97. /**
  98. * 转换tpi
  99. * @param tpmID
  100. * @param tpiID
  101. * @param instanceGitURL
  102. */
  103. private void transferTPI (String tpmID, String tpiID, String instanceGitURL) throws GameException {
  104. logger.debug("DataTransferController: transferTPI: tpmID: " + tpmID + ", tpiID: " + tpiID + ", instanceGitURL: " + instanceGitURL);
  105. // String repoName = StringUtil.getRepoName(instanceGitURL);
  106. // String path = appConfig.getWorkspace() + File.separator + "myshixun_" + tpiID;
  107. // // 删除旧数据
  108. // if (!StringUtils.isEmpty(tpiID)) {
  109. // ShellUtil.execute("rm -rf " + path);
  110. // }
  111. // // 克隆版本库
  112. // gameService.gitClone(path, instanceGitURL, "origin", repoName);
  113. //
  114. // //根据实训模板评测脚本生成Tpi脚本到工作目录
  115. // gameService.generateTpiEvaluateShellScript(appConfig.getWorkspace() + "/shell/" + tpmID + "/evaluate.sh",
  116. // appConfig.getWorkspace() + "/myshixun_" + tpiID + "/" + repoName + "/");
  117. }
  118. }

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...