alter log4j.properities

This commit is contained in:
LiLi 2017-04-19 21:46:49 +08:00
commit 2f4621c42d
10 changed files with 269 additions and 31 deletions

View File

@ -32,4 +32,15 @@ public class TrustieApi {
HttpHelper.sendPost(appConfig.getTrustieUrl(), jsonTestDetails);
logger.debug("****commitResultToTrustie " + jsonTestDetails );
}
public void commitResultToTrustie(Map result){
try {
JSONObject object = new JSONObject(result);
logger.debug("commitResultToTrustie trustieUrl:" + appConfig.getTrustieUrl() + ", result: " + object);
} catch (Exception e) {
e.printStackTrace();
}
HttpHelper.sendPost(appConfig.getTrustieUrl(),
result);
}
}

View File

@ -15,7 +15,9 @@ import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by guange on 18/02/2017.
@ -52,7 +54,10 @@ public class PipeLineController extends BaseController {
testInfo.getMsg().add(caseOne);
}
String jsonTestInfo = JSON.toJSONString(testInfo);
trustieApi.commitResultToTrustie(jsonTestInfo);
Map map = new HashMap();
map.put("jsonTestDetails", jsonTestInfo);
trustieApi.commitResultToTrustie(map);
response.put("code", 0);
response.put("msg", "结果回传成功");

View File

@ -82,7 +82,7 @@ public class HttpHelper {
String data = stringBuffer.toString();
data = data.substring(0,data.length()-1);
log.debug("POST: "+url+" DATA: "+data);
log.debug("POST: "+ url + " DATA: " + data);
OutputStream outputStream = conn.getOutputStream();
outputStream.write(data.getBytes(Charset.forName("UTF-8")));
@ -101,7 +101,7 @@ public class HttpHelper {
System.out.println("发送 POST 请求出现异常!" + e);
e.printStackTrace();
}
//使用finally块来关闭输出流输入流
finally {
try {
if (out != null) {
@ -110,15 +110,15 @@ public class HttpHelper {
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
public static String sendPost(String url, String jsonTestDetails) {
PrintWriter out = null;
BufferedReader in = null;
@ -142,7 +142,8 @@ public class HttpHelper {
String data = jsonTestDetails;
// log.debug("POST: "+url+" DATA: "+data);
log.debug("POST: "+url+" DATA: " + data);
OutputStream outputStream = conn.getOutputStream();
outputStream.write(data.getBytes(Charset.forName("UTF-8")));

View File

@ -8,8 +8,8 @@ trustieUrl=http://bdweb.trustie.net/myshixuns/training_task_status
#jenkisUserName=admin
#jenkisPassWord=wang199637
jenkinsUrl=http://123.59.135.74:9999/jenkins
jenkisUserName=guange
jenkisPassWord=123456
jenkisUserName=root
jenkisPassWord=root
#jenkinsUrl=http://192.168.0.238:9999
#jenkisUserName=guange
#jenkisPassWord=123456

View File

@ -1,7 +1,7 @@
if (currentChallenge == CHALLENGESTAGE) {
// 编译程序
sh script: 'echo "$(javac CHALLENGEPROGRAMNAME 2>&1)" > compile_result_CHALLENGESTAGE.out'
sh script: 'echo "$(javac -encoding UTF-8 CHALLENGEPROGRAMNAME 2>&1)" > compile_result_CHALLENGESTAGE.out'
compileResult = readFile ('compile_result_CHALLENGESTAGE.out')
// 如果编译通过
@ -21,7 +21,7 @@
def expectedOutI = readFile '../testCases/TRAININGID/CHALLENGESTAGE/' + i + '.out'
// 从in.txt读入程序运行输出重定向到out.txt
sh script: 'echo "$(java SOURCECLASSNAME < ../testCases/TRAININGID/CHALLENGESTAGE/' + i + '.in 2>&1)" > actual_result_CHALLENGESTAGE_' + i + '.out'
sh script: 'echo "$(java -Dfile.encoding=UTF-8 SOURCECLASSNAME < ../testCases/TRAININGID/CHALLENGESTAGE/' + i + '.in 2>&1)" > actual_result_CHALLENGESTAGE_' + i + '.out'
def outI = readFile 'actual_result_CHALLENGESTAGE_' + i + '.out'
// echo到文件中会多一个换行符
outI = outI.substring(0, outI.length() - 1);

View File

@ -12,7 +12,7 @@ def postGameInstanceResultToBDWeb(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',
httpMode: 'POST', requestBody: s, url: "http://123.59.135.74:9999/jenkins-exec/pipeline/postTrainingGameInstanceResultToBDWeb?buildID=${buildID}"
httpMode: 'POST', requestBody: s, url: "http://123.59.135.74:9201/jenkins-exec/pipeline/postTrainingGameInstanceResultToBDWeb?buildID=${buildID}"
if (response.status==299){
error response.content

View File

@ -1,8 +1,7 @@
### \u8BBE\u7F6E###
### 设置###
log4j.rootLogger = debug,stdout,logDailyFile
### \u8F7ES\u4F47º\u4FE1\u5F41¯\u4F48°\u5F4E§\u4F48¶\u5F4A¬ ###
### 输出信息到控制抬 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
@ -21,3 +20,4 @@ log4j.appender.logDailyFile.Append = TRUE
log4j.appender.logDailyFile.File = ./logs/test.log
log4j.appender.logDailyFile.DatePattern = '.'yyyy-MM-dd
log4j.appender.logDailyFile.Encoding = UTF-8

File diff suppressed because one or more lines are too long

View File

@ -34,8 +34,218 @@ public class JenkinsControllerTest extends SpringTestBase {
@Test
public void testCreateJobForInstance () throws UnsupportedEncodingException {
String jobNameForInstance = "junit test case";
String gamePipelineScript = Base64Helper.encode("node () { git url: instanceGitURL }");
String instanceGitURL = Base64Helper.encode("https://git.oschina.net/hugeox/genkins-demo1.git");
String gamePipelineScript = Base64Helper.encode("node() {\n" +
"\tgit url: instanceGitURL\n" +
"\n" +
"\t//withDockerContainer('Java') {\n" +
"\t\tdef currentChallenge = Integer.parseInt(instanceChallenge)\n" +
" if (currentChallenge == 1) {\n" +
"\n" +
" // 编译程序\n" +
" sh script: 'echo \"$(javac Plus.java 2>&1)\" > compile_result_1.out'\n" +
" compileResult = readFile ('compile_result_1.out')\n" +
"\n" +
" // 如果编译通过\n" +
" if (compileResult.trim() == '') {\n" +
" compileResult = 'compile successfully'\n" +
" }\n" +
"\n" +
" StringBuilder input = new StringBuilder('[')\n" +
" StringBuilder output = new StringBuilder('[')\n" +
" StringBuilder expectedOut = new StringBuilder('[')\n" +
"\n" +
" def fileNumsStr = sh script: 'cd ../testCases/1/1 && ls -l |grep \"^-\"|wc -l', returnStdout: true\n" +
" def fileNums = Integer.parseInt(fileNumsStr.trim())\n" +
" for (int i = 1; i <= fileNums/2; i++) {\n" +
" // 读取输入和预期输出\n" +
" def inI = readFile '../testCases/1/1/' + i + '.in'\n" +
" def expectedOutI = readFile '../testCases/1/1/' + i + '.out'\n" +
"\n" +
" // 从in.txt读入程序运行输出重定向到out.txt\n" +
" sh script: 'echo \"$(java Plus < ../testCases/1/1/' + i + '.in 2>&1)\" > actual_result_1_' + i + '.out'\n" +
" def outI = readFile 'actual_result_1_' + i + '.out'\n" +
" // echo到文件中会多一个换行符\n" +
" outI = outI.substring(0, outI.length() - 1);\n" +
"\n" +
" // 拼接成json格式\n" +
" input.append(\"\\\"\" + inI + \"\\\",\");\n" +
" output.append(\"\\\"\" + base64Encode(outI) + \"\\\",\");\n" +
" expectedOut.append(\"\\\"\" + expectedOutI + \"\\\",\");\n" +
"\n" +
" }\n" +
"\n" +
" input = input.deleteCharAt(input.length() - 1);\n" +
" input = input.append(\"]\");\n" +
"\n" +
" output = output.deleteCharAt(output.length() - 1);\n" +
" output = output.append(\"]\");\n" +
"\n" +
" expectedOut = expectedOut.deleteCharAt(expectedOut.length() - 1);\n" +
" expectedOut = expectedOut.append(\"]\");\n" +
"\n" +
" // 由中间层判断结果之后发送给BDWeb\n" +
" postGameInstanceResultToBDWeb(compileResult: base64Encode(compileResult), out: output, in:input, expectedOut:expectedOut)\n" +
" }\n" +
"\t\t if (currentChallenge == 2) {\n" +
"\n" +
" // 编译程序\n" +
" sh script: 'echo \"$(javac Minus.java 2>&1)\" > compile_result_2.out'\n" +
" compileResult = readFile ('compile_result_2.out')\n" +
"\n" +
" // 如果编译通过\n" +
" if (compileResult.trim() == '') {\n" +
" compileResult = 'compile successfully'\n" +
" }\n" +
"\n" +
" StringBuilder input = new StringBuilder('[')\n" +
" StringBuilder output = new StringBuilder('[')\n" +
" StringBuilder expectedOut = new StringBuilder('[')\n" +
"\n" +
" def fileNumsStr = sh script: 'cd ../testCases/1/2 && ls -l |grep \"^-\"|wc -l', returnStdout: true\n" +
" def fileNums = Integer.parseInt(fileNumsStr.trim())\n" +
" for (int i = 1; i <= fileNums/2; i++) {\n" +
" // 读取输入和预期输出\n" +
" def inI = readFile '../testCases/1/2/' + i + '.in'\n" +
" def expectedOutI = readFile '../testCases/1/2/' + i + '.out'\n" +
"\n" +
" // 从in.txt读入程序运行输出重定向到out.txt\n" +
" sh script: 'echo \"$(java Minus < ../testCases/1/2/' + i + '.in 2>&1)\" > actual_result_2_' + i + '.out'\n" +
" def outI = readFile 'actual_result_2_' + i + '.out'\n" +
" // echo到文件中会多一个换行符\n" +
" outI = outI.substring(0, outI.length() - 1);\n" +
"\n" +
" // 拼接成json格式\n" +
" input.append(\"\\\"\" + inI + \"\\\",\");\n" +
" output.append(\"\\\"\" + base64Encode(outI) + \"\\\",\");\n" +
" expectedOut.append(\"\\\"\" + expectedOutI + \"\\\",\");\n" +
"\n" +
" }\n" +
"\n" +
" input = input.deleteCharAt(input.length() - 1);\n" +
" input = input.append(\"]\");\n" +
"\n" +
" output = output.deleteCharAt(output.length() - 1);\n" +
" output = output.append(\"]\");\n" +
"\n" +
" expectedOut = expectedOut.deleteCharAt(expectedOut.length() - 1);\n" +
" expectedOut = expectedOut.append(\"]\");\n" +
"\n" +
" // 由中间层判断结果之后发送给BDWeb\n" +
" postGameInstanceResultToBDWeb(compileResult: base64Encode(compileResult), out: output, in:input, expectedOut:expectedOut)\n" +
" }\n" +
"\t\t if (currentChallenge == 3) {\n" +
"\n" +
" // 编译程序\n" +
" sh script: 'echo \"$(javac Mul.java 2>&1)\" > compile_result_3.out'\n" +
" compileResult = readFile ('compile_result_3.out')\n" +
"\n" +
" // 如果编译通过\n" +
" if (compileResult.trim() == '') {\n" +
" compileResult = 'compile successfully'\n" +
" }\n" +
"\n" +
" StringBuilder input = new StringBuilder('[')\n" +
" StringBuilder output = new StringBuilder('[')\n" +
" StringBuilder expectedOut = new StringBuilder('[')\n" +
"\n" +
" def fileNumsStr = sh script: 'cd ../testCases/1/3 && ls -l |grep \"^-\"|wc -l', returnStdout: true\n" +
" def fileNums = Integer.parseInt(fileNumsStr.trim())\n" +
" for (int i = 1; i <= fileNums/2; i++) {\n" +
" // 读取输入和预期输出\n" +
" def inI = readFile '../testCases/1/3/' + i + '.in'\n" +
" def expectedOutI = readFile '../testCases/1/3/' + i + '.out'\n" +
"\n" +
" // 从in.txt读入程序运行输出重定向到out.txt\n" +
" sh script: 'echo \"$(java Mul < ../testCases/1/3/' + i + '.in 2>&1)\" > actual_result_3_' + i + '.out'\n" +
" def outI = readFile 'actual_result_3_' + i + '.out'\n" +
" // echo到文件中会多一个换行符\n" +
" outI = outI.substring(0, outI.length() - 1);\n" +
"\n" +
" // 拼接成json格式\n" +
" input.append(\"\\\"\" + inI + \"\\\",\");\n" +
" output.append(\"\\\"\" + base64Encode(outI) + \"\\\",\");\n" +
" expectedOut.append(\"\\\"\" + expectedOutI + \"\\\",\");\n" +
"\n" +
" }\n" +
"\n" +
" input = input.deleteCharAt(input.length() - 1);\n" +
" input = input.append(\"]\");\n" +
"\n" +
" output = output.deleteCharAt(output.length() - 1);\n" +
" output = output.append(\"]\");\n" +
"\n" +
" expectedOut = expectedOut.deleteCharAt(expectedOut.length() - 1);\n" +
" expectedOut = expectedOut.append(\"]\");\n" +
"\n" +
" // 由中间层判断结果之后发送给BDWeb\n" +
" postGameInstanceResultToBDWeb(compileResult: base64Encode(compileResult), out: output, in:input, expectedOut:expectedOut)\n" +
" }\n" +
"\t\t if (currentChallenge == 4) {\n" +
"\n" +
" // 编译程序\n" +
" sh script: 'echo \"$(javac Div.java 2>&1)\" > compile_result_4.out'\n" +
" compileResult = readFile ('compile_result_4.out')\n" +
"\n" +
" // 如果编译通过\n" +
" if (compileResult.trim() == '') {\n" +
" compileResult = 'compile successfully'\n" +
" }\n" +
"\n" +
" StringBuilder input = new StringBuilder('[')\n" +
" StringBuilder output = new StringBuilder('[')\n" +
" StringBuilder expectedOut = new StringBuilder('[')\n" +
"\n" +
" def fileNumsStr = sh script: 'cd ../testCases/1/4 && ls -l |grep \"^-\"|wc -l', returnStdout: true\n" +
" def fileNums = Integer.parseInt(fileNumsStr.trim())\n" +
" for (int i = 1; i <= fileNums/2; i++) {\n" +
" // 读取输入和预期输出\n" +
" def inI = readFile '../testCases/1/4/' + i + '.in'\n" +
" def expectedOutI = readFile '../testCases/1/4/' + i + '.out'\n" +
"\n" +
" // 从in.txt读入程序运行输出重定向到out.txt\n" +
" sh script: 'echo \"$(java Div < ../testCases/1/4/' + i + '.in 2>&1)\" > actual_result_4_' + i + '.out'\n" +
" def outI = readFile 'actual_result_4_' + i + '.out'\n" +
" // echo到文件中会多一个换行符\n" +
" outI = outI.substring(0, outI.length() - 1);\n" +
"\n" +
" // 拼接成json格式\n" +
" input.append(\"\\\"\" + inI + \"\\\",\");\n" +
" output.append(\"\\\"\" + base64Encode(outI) + \"\\\",\");\n" +
" expectedOut.append(\"\\\"\" + expectedOutI + \"\\\",\");\n" +
"\n" +
" }\n" +
"\n" +
" input = input.deleteCharAt(input.length() - 1);\n" +
" input = input.append(\"]\");\n" +
"\n" +
" output = output.deleteCharAt(output.length() - 1);\n" +
" output = output.append(\"]\");\n" +
"\n" +
" expectedOut = expectedOut.deleteCharAt(expectedOut.length() - 1);\n" +
" expectedOut = expectedOut.append(\"]\");\n" +
"\n" +
" // 由中间层判断结果之后发送给BDWeb\n" +
" postGameInstanceResultToBDWeb(compileResult: base64Encode(compileResult), out: output, in:input, expectedOut:expectedOut)\n" +
" }\n" +
"\t\t\n" +
"\t//}\n" +
"}\n" +
"\n" +
"// 传送运行结果到BDWeb\n" +
"def postGameInstanceResultToBDWeb(def arg){\n" +
" def s = 'compileResult=' + arg.compileResult + '&out=' + arg.out +\n" +
"\t\t'&in=' + arg.in + '&expectedOut=' + arg.expectedOut\n" +
"\tdef response = httpRequest acceptType: 'APPLICATION_JSON_UTF8', consoleLogResponseBody: true, contentType: 'APPLICATION_FORM',\n" +
"\t\thttpMode: 'POST', requestBody: s, url: \"http://123.59.135.74:9999/jenkins-exec/pipeline/postTrainingGameInstanceResultToBDWeb?buildID=${buildID}\"\n" +
"\n" +
"\tif (response.status==299){\n" +
"\t error response.content\n" +
"\t}\n" +
"}\n" +
"\n" +
"def base64Encode(arg) {\n" +
"\treturn arg.bytes.encodeBase64().toString()\n" +
"}");
System.out.println(jenkinsController.createJobForInstance(jobNameForInstance, gamePipelineScript));

View File

@ -4,6 +4,7 @@ import cn.guange.app.jenkins.SpringTestBase;
import com.educoder.jenkins.api.JenkinsApi;
import com.educoder.jenkins.settings.AppConfig;
import com.offbytwo.jenkins.JenkinsServer;
import com.offbytwo.jenkins.model.Job;
import com.offbytwo.jenkins.model.JobWithDetails;
import org.junit.Assert;
import org.junit.Test;
@ -13,6 +14,7 @@ import java.io.PrintStream;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class JenkinsPerformanceTest extends SpringTestBase {
@ -103,23 +105,23 @@ public class JenkinsPerformanceTest extends SpringTestBase {
System.out.println(test);
}
// @Test
@Test
public void teardown() {
try {
JenkinsServer jenkinsServer = new JenkinsServer(new URI(appConfig.getJenkinsUrl()),
appConfig.getJenkisUserName(), appConfig.getJenkisPassWord());
// Map<String, Job> jobs = jenkinsServer.getJobs();
// Set<Map.Entry<String, Job>> entries = jobs.entrySet();
// for(Map.Entry<String, Job> entry: entries) {
// if(jenkinsServer.getJob(entry.getKey()) != null) {
// jenkinsServer.deleteJob(entry.getKey());
// }
// }
for (int i = 0; i < 30; i++)
if (jenkinsServer.getJob("test_time" + i) != null) {
jenkinsServer.deleteJob("test_time" + i);
}
// Map<String, Job> jobs = jenkinsServer.getJobs();
// Set<Map.Entry<String, Job>> entries = jobs.entrySet();
// for(Map.Entry<String, Job> entry: entries) {
// if(jenkinsServer.getJob(entry.getKey()) != null) {
// jenkinsServer.deleteJob(entry.getKey());
// }
// }
//
// for (int i = 0; i < 90; i++)
// if (jenkinsServer.getJob("myshixun_" + i) != null) {
// jenkinsServer.deleteJob("myshixun_" + i);
// }
} catch (Exception e) {
e.printStackTrace();
}