更改替换PODLABEL

This commit is contained in:
ladventure 2017-05-22 20:16:23 +08:00
parent 6e32bb1b21
commit ed0e6130ca
5 changed files with 123 additions and 21 deletions

View File

@ -71,8 +71,13 @@ public class GameController extends BaseController {
logger.debug(pipeLineConfig.getEnvironment().get(0));
}
/**
*gameInfo: trainingID(实训ID)
*
* */
@RequestMapping(path = "/publishGame")
@ApiOperation(value = "发布实训", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@ApiOperation(value = "发布实训", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public JSONObject publishGame(
@ApiParam(name = "gameInfo", required = true, value = "游戏信息") @RequestParam String gameInfo)
throws Exception {
@ -141,17 +146,18 @@ public class GameController extends BaseController {
return response;
}
/*
/**
trustie将各个关卡的pipeline连同运行环境以JSON格式传给中间层服务器
中间层服务器接收参数并将其和java.template.pipeline这一模板进行组成
生成整个Job的总脚本
* gameInfo
* */
@ApiOperation(value = "生成游戏总的脚本", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@RequestMapping(path = "/generatePipelineScriptForGame")
public JSONObject generatePipelineScriptForGame(
@ApiParam(name = "gameInfo", required = true, value = "游戏信息脚本用base64编码") @RequestParam String gameInfo)
throws Exception {
logger.debug(gameInfo);
JSONObject response = new JSONObject();
@ -208,7 +214,7 @@ public class GameController extends BaseController {
throws Exception {
logger.debug(jobNameForInstance+"\t"+gamePipelineScript+"\t"+instanceGitURL);
//替换PODLABEL为唯一值
gamePipelineScript=gamePipelineScript.replaceFirst("PODLABEL", jobNameForInstance);
JSONObject response = jenkinsController.createJobForInstance(jobNameForInstance, gamePipelineScript);
// instanceGitURL为学生fork的版本库的地址

View File

@ -83,7 +83,12 @@ public class JenkinsController extends BaseController {
jobParamsMap.put("buildID", "");
jobParamsMap.put("resubmit", "");
gamePipelineScript = Base64Helper.decode(gamePipelineScript);
/**
* 替换pipeline中的 PODLABEL为jobName保证唯一
*/
gamePipelineScript=gamePipelineScript.replaceFirst("PODLABEL", jobNameForInstance);
jenkinsApi.createJob(jobNameForInstance, gamePipelineScript, jobParamsMap);
response.put("code", 0);

View File

@ -32,7 +32,7 @@
<list>
<value>com.educoder.jenkins.model.GeneratePipelineJava</value>
<value>com.educoder.jenkins.model.GeneratePipelineJava</value>
<value>com.educoder.jenkins.model.GeneratePipelineJdbc</value>
<value>com.educoder.jenkins.model.GeneratePipelineJava</value>
</list>
</property>
@ -71,7 +71,7 @@
<list>
<value>challengeTemplateJava.pipeline</value>
<value>challengeTemplatePython.pipeline</value>
<value>challengeTemplateJava.pipeline</value>
<value>challengeTemplateJDBC.pipeline</value>
</list>
</property>
@ -85,7 +85,8 @@
</property>
<property name="replaceExecuteCommand">
<list>
<!--使用#区分源码文件和可执行文件后缀,如果可执行文件没有后缀,应该在后面加空格!! -->
<list>
<value>.java# </value>
<value>.py#.py </value>
<value>.java# </value>

View File

@ -0,0 +1,89 @@
if (currentChallenge == CHALLENGESTAGE) {
compileResult = ''
try
{
// 编译程序
sh script: 'COMPILECOMMAND CHALLENGEPROGRAMNAME > compile_result_CHALLENGESTAGE.out 2>&1'
} catch(err)
{
//resubmit是以字符串的形式传进来的
//重复构建时需要删除之前构建的成功的class并catch掉class文件不存在的异常
catchError{
sh 'rm target/stepCHALLENGESTAGE/*.class'
}
}
//获取编译结果
compileResult = readFile ('compile_result_CHALLENGESTAGE.out')
// 如果编译通过
if (compileResult.trim() == '') {
compileResult = 'compile successfully'
}
StringBuilder input = new StringBuilder('[')
StringBuilder output = new StringBuilder('[')
StringBuilder expectedOut = new StringBuilder('[')
StringBuilder isPublic = new StringBuilder('[')
//得到文件夹下的文件总数
def fileNumsStr = sh script: 'cd ../testCases/TRAININGID/CHALLENGESTAGE && ls -l |grep "^-"|wc -l', returnStdout: true
def fileNums = Integer.parseInt(fileNumsStr.trim())
for (int i = 1; i <= fileNums/3; i++) {
// 读取输入和预期输出
//由于文件的名字的命名是有规律的,所以可以直接以序号来拼接成文件名
def inI = readFile '../testCases/TRAININGID/CHALLENGESTAGE/' + i + '.in'
def expectedOutI = readFile '../testCases/TRAININGID/CHALLENGESTAGE/' + i + '.out'
def isPublicI = readFile '../testCases/TRAININGID/CHALLENGESTAGE/' + i + '.isPublic'
//取出文件执行得到结果,然后和预期输出比较就可以判断正误
// 从in.txt读入程序运行输出重定向到out.txt
//循环测试mysql是否上线
boolean mysql_isOnline=false
for(int i=0;i<10;i++)
{
try{
sh 'mysql -uroot -p123123 -e "show databases"'
mysql_isOnline=true
break;
}catch(err){
sleep 1
continue
}
}
if(mysql_isOnline){
catchError
{
sh script: 'EXECUTECOMMAND SOURCECLASSNAME < ../testCases/TRAININGID/CHALLENGESTAGE/' + i + '.in > actual_result_CHALLENGESTAGE_' + i + '.out 2>&1 '
}
}else{
echo "mysql 服务启动失败" > actual_result_CHALLENGESTAGE_' + i + '.out
}
def outI = readFile 'actual_result_CHALLENGESTAGE_' + i + '.out'
// 拼接成json格式
input.append("\"" + base64Encode(inI) + "\",");
output.append("\"" + base64Encode(outI) + "\",");
expectedOut.append("\"" + base64Encode(expectedOutI) + "\",");
isPublic.append("\"" + isPublicI + "\",");
}
input = input.deleteCharAt(input.length() - 1);
input = input.append("]");
output = output.deleteCharAt(output.length() - 1);
output = output.append("]");
expectedOut = expectedOut.deleteCharAt(expectedOut.length() - 1);
expectedOut = expectedOut.append("]");
isPublic = isPublic.deleteCharAt(isPublic.length() - 1);
isPublic = isPublic.append("]");
// 由中间层判断结果之后发送给BDWeb
postGameInstanceResultToBDWeb(compileResult: base64Encode(compileResult), out: output, in:input, expectedOut:expectedOut , isPublic:isPublic)
}

View File

@ -90,14 +90,14 @@ public class MyTest {
public void createJob() throws Exception {
int count = 10;
for (int i = 0; i < count; i++) {
String jobname ="k8s_configure" +i ;
String jobname ="test_idleTime_parall_" +i ;
System.out.println(jobname);
createOneJob(jobname);
// createOneJobFromPipelineScript(jobname);
}
}
@Test
// @Test
public void deleteJob() throws Exception {
int count =10;
@ -128,14 +128,14 @@ public class MyTest {
}
}
@Test
// @Test
public void buildJobParallel() throws Exception {
PrintStream ps=new PrintStream(new FileOutputStream(filePath,true));
// System.setOut(ps);
int count = 11;
for (int i = 1; i < count; i++) {
int count = 10;
for (int i =0; i < count; i++) {
buildOneJob("k8spara_1" +i );
buildOneJob("test_idleTime_parall_" +i );
// buildOneJob("k8s_configure" +i );
// buildOneJob("3");
}
@ -198,13 +198,14 @@ public class MyTest {
public void createOneJob(String jobName) {
try {
// String pipeLine = "podTemplate(label: 'mypod', containers: ["
// + "containerTemplate(name: 'ubuntu', image: 'ubuntu', ttyEnabled: true)]) \n "
// + "{ \n node('mypod'){ \n container('ubuntu') { \n" + "stage 'first' \n"
// + "echo 'hello Word'\n }}}";
String pipeLine = "node('ubuntu'){\n"
+ "sleep 10 \n echo 'hello'\n"
+ "}";
String pipeLine = "podTemplate(label: '"+jobName+"', containers: ["
+ "containerTemplate(name: 'ubuntu', image: 'ubuntu', ttyEnabled: true)]) \n "
+ "{ \n node('"+jobName+"'){ \n container('ubuntu') { \n"
+ "echo 'hello Word'\n "
+ "sleep 3 }}}";
// String pipeLine = "node('ubuntu'){\n"
// + "sleep 10 \n echo 'hello'\n"
// + "}";
Map<String, String> params = new HashMap<String, String>();
params.put("taskId", jobName);
JenkinsApi jenkinsApi = new JenkinsApi();