Merge branch 'master' of https://git.trustie.net/Hjqreturn/training_project
This commit is contained in:
commit
accbdd34fd
|
@ -1,7 +1,9 @@
|
|||
package com.educoder.jenkins.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.educoder.jenkins.api.TrustieApi;
|
||||
import com.educoder.jenkins.utils.Base64Helper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by guange on 18/02/2017.
|
||||
|
@ -33,25 +36,25 @@ public class PipeLineController extends BaseController {
|
|||
@Autowired
|
||||
TrustieApi trustieApi;
|
||||
|
||||
@ApiOperation(value = "生成每一个challenge的脚本", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path = "/generateScriptPerChallenge ")
|
||||
public String generateScriptPerChallenge (@ApiParam(name = "challengeInfo", required = true, value = "关卡信息") @RequestParam String challengeInfo) {
|
||||
JSONObject info = JSONObject.parseObject(challengeInfo);
|
||||
String step = info.getString("step");
|
||||
String shixunType = info.getString("shixunType");
|
||||
@ApiOperation(value = "生成每一个关卡的脚本", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path = "/generateScriptForStage ")
|
||||
public String generateScriptForStage (@ApiParam(name = "challengeInfo", required = true, value = "关卡信息") @RequestParam String stageInfo) {
|
||||
JSONObject info = JSONObject.parseObject(stageInfo);
|
||||
String stageID = info.getString("stageID");
|
||||
String stageType = info.getString("stageType");
|
||||
String filePath = info.getString("filePath");
|
||||
String shixunId = info.getString("shixunId");
|
||||
String gameID = info.getString("gameID");
|
||||
|
||||
String pipeline = "";
|
||||
if ("in_out".equals(shixunType)) {
|
||||
if ("in_out".equals(stageType)) {
|
||||
try {
|
||||
InputStream resourceAsStream = PipeLineController.class.getResourceAsStream("/in_out.template.pipeline");
|
||||
pipeline = IOUtils.toString(resourceAsStream, Charset.forName("UTF-8"));
|
||||
String sourceClassName = filePath.substring(0, filePath.indexOf("."));
|
||||
pipeline = pipeline.replace("STEP", step);
|
||||
pipeline = pipeline.replace("STAGEID", stageID);
|
||||
pipeline = pipeline.replace("FILEPATH", filePath);
|
||||
pipeline = pipeline.replace("SOURCECLASSNAME", sourceClassName);
|
||||
pipeline = pipeline.replace("SHIXUNID", shixunId);
|
||||
pipeline = pipeline.replace("GAMEID", gameID);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
pipeline = "error";
|
||||
|
@ -62,26 +65,30 @@ public class PipeLineController extends BaseController {
|
|||
}
|
||||
|
||||
@ApiOperation(value = "生成游戏总的脚本", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path = "/generateScriptPerChallenge ")
|
||||
public String generateScript (@ApiParam(name = "gameInfo", required = true, value = "游戏信息") @RequestParam String gameInfo) {
|
||||
@RequestMapping(path = "/generatePipelineScriptForGame")
|
||||
public String generatePipelineScriptForGame (@ApiParam(name = "gameInfo", required = true, value = "游戏信息,脚本用base64编码") @RequestParam String gameInfo) {
|
||||
JSONObject info = JSONObject.parseObject(gameInfo);
|
||||
String step = info.getString("language");
|
||||
String shixunType = info.getString("fragments");
|
||||
String operationEnvironment = info.getString("operationEnvironment");
|
||||
JSONArray stagePipelines = info.getJSONArray("stagePipelines");
|
||||
|
||||
String pipeline = "";
|
||||
if ("shixunType".equals(shixunType)) {
|
||||
// try {
|
||||
//// InputStream resourceAsStream = PipeLineController.class.getResourceAsStream("/in_out.template.pipeline");
|
||||
//// pipeline = IOUtils.toString(resourceAsStream, Charset.forName("UTF-8"));
|
||||
//// String sourceClassName = filePath.substring(0, filePath.indexOf("."));
|
||||
//// pipeline = pipeline.replace("STEP", step);
|
||||
//// pipeline = pipeline.replace("FILEPATH", filePath);
|
||||
//// pipeline = pipeline.replace("SOURCECLASSNAME", sourceClassName);
|
||||
//// pipeline = pipeline.replace("SHIXUNID", shixunId);
|
||||
//// } catch (IOException e) {
|
||||
//// e.printStackTrace();
|
||||
//// pipeline = "error";
|
||||
// }
|
||||
if ("java".equals(operationEnvironment)) {
|
||||
try {
|
||||
InputStream resourceAsStream = PipeLineController.class.getResourceAsStream("/java.template.pipeline");
|
||||
pipeline = IOUtils.toString(resourceAsStream, Charset.forName("UTF-8"));
|
||||
|
||||
StringBuffer tempScript = new StringBuffer();
|
||||
for (int i = 0; i < stagePipelines.size(); i++) {
|
||||
tempScript.append(Base64Helper.decode(((JSONObject)stagePipelines.get(i)).getString("stagePipeline")));
|
||||
tempScript.append("\n");
|
||||
}
|
||||
|
||||
pipeline = pipeline.replace("STAGEPIPELINES", tempScript);
|
||||
pipeline = pipeline.replace("OPERATIONENVIRONMENT", operationEnvironment);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
pipeline = "error";
|
||||
}
|
||||
}
|
||||
|
||||
return pipeline;
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
if (nowStep == STEP) {
|
||||
// 读取输入和预期输出
|
||||
def in = readFile '/home/pdl/.jenkins/workspace/testCases/SHIXUNID_STEP_In'
|
||||
def expectedOut = readFile '/home/pdl/.jenkins/workspace/testCases/SHIXUNID_STEP_Out'
|
||||
if (currentStage == STAGEID) {
|
||||
// 读取输入和预期输出
|
||||
def in = readFile '../testCases/GAMEID_STAGEID_.in'
|
||||
def expectedOut = readFile '../testCases/GAMEID_STAGEID_.out'
|
||||
|
||||
// 编译程序
|
||||
sh script: 'echo "$(javac FILEPATH 2>&1)" > compile_result.txt'
|
||||
compileResult = readFile ('compile_result.txt')
|
||||
// 编译程序
|
||||
sh script: 'echo "$(javac FILEPATH 2>&1)" > compile_result_STAGEID.out'
|
||||
compileResult = readFile ('compile_result_STAGEID.out')
|
||||
|
||||
// 如果编译错误
|
||||
if (compileResult.trim() == '') {
|
||||
postResultToBDWeb(compileResult: compileResult, out: '', in:in, expectedOut:expectedOut)
|
||||
return ;
|
||||
}
|
||||
// 如果编译错误
|
||||
if (compileResult.trim() == '') {
|
||||
postTrainingInstanceResultToBDWeb(compileResult: compileResult, out: '', in:in, expectedOut:expectedOut)
|
||||
return ;
|
||||
}
|
||||
|
||||
// 从in.txt读入,程序运行输出重定向到out.txt
|
||||
sh script: 'echo "$(java SOURCECLASSNAME < /home/pdl/.jenkins/workspace/testCases/SHIXUNID_STEP_In 2>&1)" > out.txt'
|
||||
def out = readFile "out.txt"
|
||||
// 从in.txt读入,程序运行输出重定向到out.txt
|
||||
sh script: 'echo "$(java SOURCECLASSNAME < ../testCases/GAMEID_STAGEID.in 2>&1)" > actual_result_STAGEID.out'
|
||||
def out = readFile "actual_result_STAGEID.out"
|
||||
|
||||
// 由中间层判断结果之后发送给BDWeb
|
||||
postResultToBDWeb(compileResult: compileResult, out: out, in:in, expectedOut:expectedOut)
|
||||
}
|
||||
// 由中间层判断结果之后发送给BDWeb
|
||||
postTrainingInstanceResultToBDWeb(compileResult: compileResult, out: out, in:in, expectedOut:expectedOut)
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
node() {
|
||||
git url: gitUrl
|
||||
git url: gitURL
|
||||
|
||||
withDockerContainer(language) {
|
||||
def nowStep = Integer.parseInt(step)
|
||||
|
||||
withDockerContainer('OPERATIONENVIRONMENT') {
|
||||
def currentStage = Integer.parseInt(stageID)
|
||||
STAGEPIPELINES
|
||||
}
|
||||
}
|
||||
|
||||
// 传送运行结果到BDWeb
|
||||
def postResultToBDWeb(def arg){
|
||||
def postTrainingInstanceResultToBDWeb(def arg){
|
||||
def s = 'compileResult=' + arg.compileResult + '&out=' + arg.out +
|
||||
'&in=' + arg.in + '&expectedOut=' + arg.expectedOut
|
||||
def response = httpRequest acceptType: 'APPLICATION_JSON_UTF8', consoleLogResponseBody: true, contentType: 'APPLICATION_FORM',
|
||||
|
|
|
@ -12,14 +12,26 @@ public class PipeLineControllerTest extends SpringTestBase {
|
|||
@Autowired
|
||||
PipeLineController pipeLineController;
|
||||
|
||||
//@Test
|
||||
public void generateScriptPerChallenge() {
|
||||
@Test
|
||||
public void testGenerateScriptPerChallenge() {
|
||||
String params = "{\n" +
|
||||
" \"step\" : \"1\",\n" +
|
||||
" \"shixunType\" : \"in_out\",\n" +
|
||||
" \"stageID\" : \"2\",\n" +
|
||||
" \"stageType\" : \"in_out\",\n" +
|
||||
" \"filePath\" : \"Calculator.java\",\n" +
|
||||
" \"shixunId\" : \"1\"\n" +
|
||||
" \"gameID\" : \"1\"\n" +
|
||||
" }";
|
||||
System.out.println(pipeLineController.generateScriptPerChallenge(params));
|
||||
System.out.println(pipeLineController.generateScriptForStage(params));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateScript() {
|
||||
String params = "{\n" +
|
||||
"\t\"stagePipelines\":[\n" +
|
||||
"\t\t\t{\"stageID\":\"1\",\"stagePipeline\":\"CQkJaWYgKGN1cnJlbnRTdGFnZSA9PSAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOivu+WPlui+k+WFpeWSjOmihOacn+i+k+WHugogICAgICAgICAgICAgICAgICAgICAgICBkZWYgaW4gPSByZWFkRmlsZSAnLi4vdGVzdENhc2VzLzFfMV8uaW4nCiAgICAgICAgICAgICAgICAgICAgICAgIGRlZiBleHBlY3RlZE91dCA9IHJlYWRGaWxlICcuLi90ZXN0Q2FzZXMvMV8xXy5vdXQnCgogICAgICAgICAgICAgICAgICAgICAgICAvLyDnvJbor5HnqIvluo8KICAgICAgICAgICAgICAgICAgICAgICAgc2ggc2NyaXB0OiAnZWNobyAiJChqYXZhYyBDYWxjdWxhdG9yLmphdmEgMj4mMSkiID4gY29tcGlsZV9yZXN1bHRfMS5vdXQnCiAgICAgICAgICAgICAgICAgICAgICAgIGNvbXBpbGVSZXN1bHQgPSByZWFkRmlsZSAoJ2NvbXBpbGVfcmVzdWx0XzEub3V0JykKCiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOWmguaenOe8luivkemUmeivrwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoY29tcGlsZVJlc3VsdC50cmltKCkgPT0gJycpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zdFRyYWluaW5nSW5zdGFuY2VSZXN1bHRUb0JEV2ViKGNvbXBpbGVSZXN1bHQ6IGNvbXBpbGVSZXN1bHQsIG91dDogJycsIGluOmluLCBleHBlY3RlZE91dDpleHBlY3RlZE91dCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDsKICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAgICAgLy8g5LuOaW4udHh06K+75YWl77yM56iL5bqP6L+Q6KGM6L6T5Ye66YeN5a6a5ZCR5Yiwb3V0LnR4dAogICAgICAgICAgICAgICAgICAgICAgICBzaCBzY3JpcHQ6ICdlY2hvICIkKGphdmEgQ2FsY3VsYXRvciA8IC4uL3Rlc3RDYXNlcy8xXzEuaW4gIDI+JjEpIiA+IGFjdHVhbF9yZXN1bHRfMS5vdXQnCiAgICAgICAgICAgICAgICAgICAgICAgIGRlZiBvdXQgPSByZWFkRmlsZSAiYWN0dWFsX3Jlc3VsdF8xLm91dCIKCiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOeUseS4remXtOWxguWIpOaWree7k+aenOS5i+WQjuWPkemAgee7mUJEV2ViCiAgICAgICAgICAgICAgICAgICAgICAgIHBvc3RUcmFpbmluZ0luc3RhbmNlUmVzdWx0VG9CRFdlYihjb21waWxlUmVzdWx0OiBjb21waWxlUmVzdWx0LCBvdXQ6IG91dCwgaW46aW4sIGV4cGVjdGVkT3V0OmV4cGVjdGVkT3V0KQogICAgICAgICAgICB9\"},\n" +
|
||||
"\t\t\t{\"stageID\":\"2\",\"stagePipeline\":\"aWYgKGN1cnJlbnRTdGFnZSA9PSAyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOivu+WPlui+k+WFpeWSjOmihOacn+i+k+WHugogICAgICAgICAgICAgICAgICAgICAgICBkZWYgaW4gPSByZWFkRmlsZSAnLi4vdGVzdENhc2VzLzFfMl8uaW4nCiAgICAgICAgICAgICAgICAgICAgICAgIGRlZiBleHBlY3RlZE91dCA9IHJlYWRGaWxlICcuLi90ZXN0Q2FzZXMvMV8yXy5vdXQnCgogICAgICAgICAgICAgICAgICAgICAgICAvLyDnvJbor5HnqIvluo8KICAgICAgICAgICAgICAgICAgICAgICAgc2ggc2NyaXB0OiAnZWNobyAiJChqYXZhYyBDYWxjdWxhdG9yLmphdmEgMj4mMSkiID4gY29tcGlsZV9yZXN1bHRfMi5vdXQnCiAgICAgICAgICAgICAgICAgICAgICAgIGNvbXBpbGVSZXN1bHQgPSByZWFkRmlsZSAoJ2NvbXBpbGVfcmVzdWx0XzIub3V0JykKCiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOWmguaenOe8luivkemUmeivrwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoY29tcGlsZVJlc3VsdC50cmltKCkgPT0gJycpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcG9zdFRyYWluaW5nSW5zdGFuY2VSZXN1bHRUb0JEV2ViKGNvbXBpbGVSZXN1bHQ6IGNvbXBpbGVSZXN1bHQsIG91dDogJycsIGluOmluLCBleHBlY3RlZE91dDpleHBlY3RlZE91dCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIDsKICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAgICAgLy8g5LuOaW4udHh06K+75YWl77yM56iL5bqP6L+Q6KGM6L6T5Ye66YeN5a6a5ZCR5Yiwb3V0LnR4dAogICAgICAgICAgICAgICAgICAgICAgICBzaCBzY3JpcHQ6ICdlY2hvICIkKGphdmEgQ2FsY3VsYXRvciA8IC4uL3Rlc3RDYXNlcy8xXzIuaW4gIDI+JjEpIiA+IGFjdHVhbF9yZXN1bHRfMi5vdXQnCiAgICAgICAgICAgICAgICAgICAgICAgIGRlZiBvdXQgPSByZWFkRmlsZSAiYWN0dWFsX3Jlc3VsdF8yLm91dCIKCiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOeUseS4remXtOWxguWIpOaWree7k+aenOS5i+WQjuWPkemAgee7mUJEV2ViCiAgICAgICAgICAgICAgICAgICAgICAgIHBvc3RUcmFpbmluZ0luc3RhbmNlUmVzdWx0VG9CRFdlYihjb21waWxlUmVzdWx0OiBjb21waWxlUmVzdWx0LCBvdXQ6IG91dCwgaW46aW4sIGV4cGVjdGVkT3V0OmV4cGVjdGVkT3V0KQogICAgICAgICAgICB9\"}\n" +
|
||||
"\t],\n" +
|
||||
"\t\"operationEnvironment\":\"java\"\n" +
|
||||
"}";
|
||||
System.out.println(pipeLineController.generatePipelineScriptForGame(params));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue