重载sendPost方法
This commit is contained in:
commit
b35fbc7819
|
@ -28,11 +28,18 @@ public class TrustieApi {
|
|||
AppConfig appConfig;
|
||||
|
||||
public void commitResultToTrustie(String jsonTestDetails){
|
||||
logger.debug("url {}, jsonTestDetails {} ", appConfig.getTrustieUrl(), jsonTestDetails);
|
||||
// logger.debug("url {}, jsonTestDetails {} ", appConfig.getTrustieUrl(), jsonTestDetails);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class GameController extends BaseController {
|
|||
@ApiOperation(value = "发布实训", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path = "/publishGame")
|
||||
public JSONObject publishGame (@ApiParam(name = "gameInfo", required = true, value = "游戏信息") @RequestParam String gameInfo) {
|
||||
logger.debug("/game/publishGame gameInfo: " + gameInfo);
|
||||
logger.debug("***/game/publishGame gameInfo: " + gameInfo);
|
||||
|
||||
// 生成脚本
|
||||
JSONObject response = generatePipelineScriptForGame(gameInfo);
|
||||
|
@ -76,7 +76,7 @@ public class GameController extends BaseController {
|
|||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("***/game/publishGame gameInfo: " + gameInfo);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class GameController extends BaseController {
|
|||
@ApiOperation(value = "生成每一个关卡的脚本", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path = "/generatePipelineScriptForChallenge")
|
||||
public JSONObject generatePipelineScriptForChallenge (@ApiParam(name = "challengeInfo", required = true, value = "关卡信息") @RequestParam String challengeInfo) {
|
||||
logger.debug("/game/generatePipelineScriptForChallenge challengeInfo: " + challengeInfo);
|
||||
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
|
@ -155,13 +155,14 @@ public class GameController extends BaseController {
|
|||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
logger.debug("/game/generatePipelineScriptForChallenge challengeInfo: " + challengeInfo);
|
||||
return response;
|
||||
}
|
||||
|
||||
@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) {
|
||||
logger.debug("/game/generatePipelineScriptForGame gameInfo: " + gameInfo );
|
||||
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
|
@ -225,7 +226,7 @@ public class GameController extends BaseController {
|
|||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("/game/generatePipelineScriptForGame gameInfo: " + gameInfo );
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -235,7 +236,7 @@ public class GameController extends BaseController {
|
|||
@ApiParam(name = "gamePipelineScript", required = true, value = "job的pipeline脚本") @RequestParam String gamePipelineScript,
|
||||
@ApiParam(name = "instanceGitURL", required = true, value = "job的gitUrl") @RequestParam String instanceGitURL) {
|
||||
JSONObject response = jenkinsController.createJobForInstance(jobNameForInstance, gamePipelineScript);
|
||||
|
||||
|
||||
try {
|
||||
jenkinsController.buildJobForInstance(jobNameForInstance, instanceGitURL, 0 + "", 0 + "");
|
||||
} catch (Exception e) {
|
||||
|
@ -247,7 +248,7 @@ public class GameController extends BaseController {
|
|||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("***/game/openGameInstance jobNameForInstance: " + jobNameForInstance);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public class JenkinsController extends BaseController{
|
|||
@RequestMapping(path="/createJobForInstance",method = RequestMethod.POST)
|
||||
public JSONObject createJobForInstance(@ApiParam(name = "jobNameForInstance", required = true, value = "job的名字,不能重复") @RequestParam String jobNameForInstance,
|
||||
@ApiParam(name = "gamePipelineScript", required = true, value = "pipeLine脚本,用base64编码") @RequestParam String gamePipelineScript){
|
||||
logger.debug("/api/createJobForInstance jobNameForInstance:" + jobNameForInstance + " pipeLine=" + gamePipelineScript);
|
||||
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
|
@ -51,72 +51,75 @@ public class JenkinsController extends BaseController{
|
|||
|
||||
jenkinsApi.createJob(jobNameForInstance, gamePipelineScript, jobParamsMap);
|
||||
|
||||
response.put("code", 0);
|
||||
response.put("msg", "create job success.");
|
||||
}catch (Exception e){
|
||||
logger.error("/api/createJobForInstance", e);
|
||||
if (e.getMessage().startsWith("A job already exists")){
|
||||
response.put("code", -2);
|
||||
response.put("msg", jobNameForInstance+" already exists");
|
||||
}
|
||||
response.put("code", -1);
|
||||
response.put("msg", e.getMessage());
|
||||
}
|
||||
response.put("code", 0);
|
||||
response.put("msg", "create job success.");
|
||||
} catch (Exception e) {
|
||||
logger.error("/api/createJobForInstance", e);
|
||||
if (e.getMessage().startsWith("A job already exists")) {
|
||||
response.put("code", -2);
|
||||
response.put("msg", jobNameForInstance + " already exists");
|
||||
}
|
||||
response.put("code", -1);
|
||||
response.put("msg", e.getMessage());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "构建一个job", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path="/buildJobForInstance",method = RequestMethod.POST)
|
||||
public JSONObject buildJobForInstance(@ApiParam(name = "jobNameForInstance", required = true, value = "job的名字") @RequestParam String jobNameForInstance,
|
||||
@ApiParam(name = "instanceGitURL", required = true, value = "学员对应当前实训版本库地址") @RequestParam String instanceGitURL,
|
||||
@ApiParam(name = "buildID", required = true, value = "本次评测ID") @RequestParam String buildID,
|
||||
@ApiParam(name = "instanceChallenge", required = true, value = "当前处在第几关") @RequestParam String instanceChallenge ){
|
||||
logger.debug("/api/buildJobForInstance jobNameForInstance:" + jobNameForInstance + ", buildID:" + buildID + ", instanceChallenge:" + instanceChallenge + ", instanceGitURL:" + instanceGitURL);
|
||||
@ApiOperation(value = "构建一个job", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path = "/buildJobForInstance", method = RequestMethod.POST)
|
||||
public JSONObject buildJobForInstance(
|
||||
@ApiParam(name = "jobNameForInstance", required = true, value = "job的名字") @RequestParam String jobNameForInstance,
|
||||
@ApiParam(name = "instanceGitURL", required = true, value = "学员对应当前实训版本库地址") @RequestParam String instanceGitURL,
|
||||
@ApiParam(name = "buildID", required = true, value = "本次评测ID") @RequestParam String buildID,
|
||||
@ApiParam(name = "instanceChallenge", required = true, value = "当前处在第几关") @RequestParam String instanceChallenge) {
|
||||
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
instanceGitURL = Base64Helper.decode(instanceGitURL);
|
||||
jenkinsApi.buildJob(jobNameForInstance, buildID, instanceChallenge, instanceGitURL);
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
instanceGitURL = Base64Helper.decode(instanceGitURL);
|
||||
jenkinsApi.buildJob(jobNameForInstance, buildID, instanceChallenge, instanceGitURL);
|
||||
|
||||
response.put("code", 0);
|
||||
response.put("msg", "run job success");
|
||||
}catch (Exception e){
|
||||
logger.error("/api/buildJobForInstance ", e);
|
||||
response.put("code", -1);
|
||||
response.put("msg", e.getMessage());
|
||||
}
|
||||
response.put("code", 0);
|
||||
response.put("msg", "run job success");
|
||||
} catch (Exception e) {
|
||||
logger.error("/api/buildJobForInstance ", e);
|
||||
response.put("code", -1);
|
||||
response.put("msg", e.getMessage());
|
||||
}
|
||||
logger.debug("***/api/buildJobForInstance jobNameForInstance:" + jobNameForInstance);
|
||||
return response;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
@ApiOperation(value = "更新一个job", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@ApiResponse(code = 200, message = "success", response = JSONObject.class)
|
||||
@RequestMapping(path = "/updateJobForInstance", method = RequestMethod.POST)
|
||||
public JSONObject updateJobForInstance(
|
||||
@ApiParam(name = "jobNameForInstance", required = true, value = "job的名字") @RequestParam String jobNameForInstance,
|
||||
@ApiParam(name = "gamePipelineScript", required = true, value = "pipeLine脚本,用base64编码") @RequestParam String gamePipelineScript) {
|
||||
logger.debug("/api/updateJobForInstance: jobNameForInstance:" + jobNameForInstance + ", gamePipelineScript:"
|
||||
+ gamePipelineScript);
|
||||
|
||||
@ApiOperation(value = "更新一个job", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@ApiResponse(code = 200, message = "success", response = JSONObject.class)
|
||||
@RequestMapping(path="/updateJobForInstance",method = RequestMethod.POST)
|
||||
public JSONObject updateJobForInstance(@ApiParam(name = "jobNameForInstance", required = true, value = "job的名字") @RequestParam String jobNameForInstance,
|
||||
@ApiParam(name = "gamePipelineScript", required = true, value = "pipeLine脚本,用base64编码") @RequestParam String gamePipelineScript){
|
||||
logger.debug("/api/updateJobForInstance: jobNameForInstance:" + jobNameForInstance + ", gamePipelineScript:" + gamePipelineScript);
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
Map jobParamsMap = new HashMap();
|
||||
jobParamsMap.put("instanceGitURL", "");
|
||||
jobParamsMap.put("instanceChallenge", "");
|
||||
jobParamsMap.put("buildID", "");
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
Map jobParamsMap = new HashMap();
|
||||
jobParamsMap.put("instanceGitURL", "");
|
||||
jobParamsMap.put("instanceChallenge", "");
|
||||
jobParamsMap.put("buildID", "");
|
||||
gamePipelineScript = Base64Helper.decode(gamePipelineScript);
|
||||
jenkinsApi.updateJob(jobNameForInstance, gamePipelineScript, jobParamsMap);
|
||||
|
||||
gamePipelineScript = Base64Helper.decode(gamePipelineScript);
|
||||
jenkinsApi.updateJob(jobNameForInstance, gamePipelineScript, jobParamsMap);
|
||||
|
||||
response.put("code", 0);
|
||||
response.put("msg", "update job success.");
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
logger.error("/api/updateJobForInstance ", e);
|
||||
response.put("code", -1);
|
||||
response.put("msg", e.getMessage());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
response.put("code", 0);
|
||||
response.put("msg", "update job success.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("/api/updateJobForInstance ", e);
|
||||
response.put("code", -1);
|
||||
response.put("msg", e.getMessage());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
|
@ -35,9 +35,8 @@ public class PipeLineController extends BaseController {
|
|||
@ApiOperation(value = "处理结果并将结果回传到BDWeb", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path = "/postTrainingGameInstanceResultToBDWeb")
|
||||
public JSONObject postTrainingGameInstanceResultToBDWeb(String buildID, String compileResult, String out, String in, String expectedOut){
|
||||
logger.debug("/pipeline/postTrainingGameInstanceResultToBDWeb buildID: " + buildID + ", compileResult: " + compileResult +
|
||||
", out: " + out + ", in: " + in + ", expectedOut: " + expectedOut);
|
||||
|
||||
|
||||
logger.debug("****/pipeline/postTrainingGameInstanceResultToBDWeb buildID: " + buildID );
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
List<String> inputs=JSON.parseArray(in, String.class);
|
||||
|
@ -68,7 +67,7 @@ public class PipeLineController extends BaseController {
|
|||
response.put("code", -1);
|
||||
response.put("msg", e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -73,7 +74,6 @@ public class HttpHelper {
|
|||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
|
||||
log.debug("sb");
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (Object key : param.keySet()) {
|
||||
stringBuffer.append(key+"="+param.get(key));
|
||||
|
@ -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,8 +110,8 @@ public class HttpHelper {
|
|||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -144,11 +144,75 @@ public class HttpHelper {
|
|||
|
||||
log.debug("POST: "+url+" DATA: " + data);
|
||||
|
||||
|
||||
OutputStream outputStream = conn.getOutputStream();
|
||||
outputStream.write(data.getBytes(Charset.forName("UTF-8")));
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
in = new BufferedReader(
|
||||
new InputStreamReader(conn.getInputStream()));
|
||||
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
result += line;
|
||||
// System.out.println(line);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("发送 POST 请求出现异常!" + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
//使用finally块来关闭输出流、输入流
|
||||
finally {
|
||||
try {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static String sendPostListParams(String url, List<String> jsonParams) {
|
||||
PrintWriter out = null;
|
||||
BufferedReader in = null;
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
URL realUrl = new URL(url);
|
||||
// 打开和URL之间的连接
|
||||
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
|
||||
|
||||
// 设置通用的请求属性
|
||||
conn.setRequestProperty("Accept", "*/*");
|
||||
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
|
||||
// conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setRequestMethod("POST");
|
||||
|
||||
// 发送POST请求必须设置如下两行
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
|
||||
// String data = jsonParams;
|
||||
|
||||
// log.debug("POST: "+url+" DATA: "+jsonParams);
|
||||
|
||||
OutputStream outputStream = conn.getOutputStream();
|
||||
for(String jsonParam:jsonParams){
|
||||
outputStream.write(jsonParam.getBytes(Charset.forName("UTF-8")));
|
||||
}
|
||||
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
in = new BufferedReader(
|
||||
new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
|
@ -175,4 +239,7 @@ public class HttpHelper {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
### 设置###
|
||||
log4j.rootLogger = debug,stdout
|
||||
|
||||
### 输出信息到控制抬 ###
|
||||
### \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
|
||||
#log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
|
||||
log4j.appender.stdout.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} %m%n
|
||||
|
||||
log4j.logger.org.springframework=INFO
|
||||
log4j.logger.org.springframework=INFO
|
||||
|
||||
|
||||
log4j.appender.logDailyFile = org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.logDailyFile.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.logDailyFile.layout.ConversionPattern = %n%-d{yyyy-MM-dd HH:mm:ss}%n[%p]-[Thread: %t]-[%C.%M()]: %m%n
|
||||
log4j.appender.logDailyFile.Threshold = DEBUG
|
||||
log4j.appender.logDailyFile.ImmediateFlush = TRUE
|
||||
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
|
||||
|
|
|
@ -0,0 +1,376 @@
|
|||
|
||||
/**
|
||||
* 文件名 : GameBridgeTest.java 版权 : <版权/公司名> 描述 : <描述>
|
||||
*
|
||||
* @author liliy 版本 : <版本> 修改时间: 2017年4月18日 修改内容: <修改内容>
|
||||
*/
|
||||
package cn.lili.test;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.educoder.jenkins.controller.GameController;
|
||||
import com.educoder.jenkins.utils.Base64Helper;
|
||||
import com.educoder.jenkins.utils.HttpHelper;
|
||||
|
||||
import sun.util.logging.resources.logging;
|
||||
|
||||
/**
|
||||
* 测试10个人同时打一个游戏 多人完成同时玩多个游戏(暂定10人同时打2个游戏,5人打游戏A,5人打游戏B。)
|
||||
*
|
||||
* @author liliy
|
||||
* @version [版本号,2017年4月18日]
|
||||
* @see [相关类/方法]
|
||||
* @since [产品/模块版本]
|
||||
*/
|
||||
class MyThread extends Thread {
|
||||
/**
|
||||
* <一句话功能简述> <功能详细描述>
|
||||
*
|
||||
* @see [类、类#方法、类#成员]
|
||||
*/
|
||||
String jsonParam;
|
||||
String path;
|
||||
String response;
|
||||
int id=-1;
|
||||
|
||||
String jobNameForInstance = "";
|
||||
String gamePipelineScript ;
|
||||
String instanceGitURL;
|
||||
String instanceChallenge;
|
||||
String buildId;
|
||||
|
||||
public MyThread(String jobNameForInstance, String gamePipelineScript, String instanceGitURL,String path) {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.jobNameForInstance = jobNameForInstance;
|
||||
this.gamePipelineScript = gamePipelineScript;
|
||||
this.instanceGitURL = instanceGitURL;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public MyThread(String jobNameForInstance, String instanceChallenge, String instanceGitURL,String buildId,String path) {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.jobNameForInstance = jobNameForInstance;
|
||||
this.instanceChallenge = instanceChallenge;
|
||||
this.instanceGitURL = instanceGitURL;
|
||||
this.buildId=buildId;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public MyThread(int id, String jsonParam, String path) {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.jsonParam = jsonParam;
|
||||
this.path = path;
|
||||
this.id = id;
|
||||
}
|
||||
public MyThread( String jsonParam, String path) {
|
||||
// TODO Auto-generated constructor stub
|
||||
this.jsonParam = jsonParam;
|
||||
this.path = path;
|
||||
|
||||
}
|
||||
public void run() {
|
||||
if(path.equals("/game/openGameInstance")){
|
||||
response = HttpHelper.sendPostListParams(GameBridgeTest.gameBridgeURL + path,
|
||||
Arrays.asList(jobNameForInstance, gamePipelineScript, instanceGitURL));
|
||||
GameBridgeTest.logger.info(jobNameForInstance+ "\t" + response);
|
||||
}else if (path.equals("/api/buildJobForInstance")) {
|
||||
String response = HttpHelper.sendPostListParams(GameBridgeTest.gameBridgeURL + path,
|
||||
Arrays.asList(jobNameForInstance, instanceGitURL, buildId, instanceChallenge));
|
||||
GameBridgeTest.logger.info(jobNameForInstance+"\t"+response);
|
||||
}
|
||||
else {
|
||||
response = HttpHelper.sendPost(GameBridgeTest.gameBridgeURL + path, jsonParam);
|
||||
GameBridgeTest.logger.info(id + "\t" + response);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GameBridgeTest {
|
||||
public static String gameBridgeURL = "http://123.59.135.74:9999/jenkins-exec";
|
||||
public final static Logger logger = LoggerFactory.getLogger(GameBridgeTest.class);
|
||||
public static int trainingID = 1;
|
||||
static {
|
||||
PropertyConfigurator.configure(
|
||||
"E:\\projects\\java\\training_project\\jenkins-exec\\src\\main\\resources\\log4j.properties");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException {
|
||||
GameBridgeTest gameBridgeTest=new GameBridgeTest();
|
||||
gameBridgeTest.generatePipelineScriptForChallenge();
|
||||
// gameBridgeTest.openGameInstance();
|
||||
// gameBridgeTest.buildJobForInstance();
|
||||
// gameBridgeTest.testopenGameInstanceAndBuildJobForInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试脚本阶段脚本生成 <一句话功能简述> <功能详细描述>
|
||||
*
|
||||
* @return
|
||||
* @throws UnsupportedEncodingException
|
||||
* @see [类、类#方法、类#成员]
|
||||
*/
|
||||
// @Test
|
||||
public void generatePipelineScriptForChallenge() throws UnsupportedEncodingException {
|
||||
int id = 1;
|
||||
String path = "/game/generatePipelineScriptForChallenge";
|
||||
logger.info(path);
|
||||
for (int i = 0; i < 10; i++, id++) {
|
||||
String jsonParam = "challengeInfo={\"challengeStage\": \"3\",\"challengeType\":\"1\",\"challengeProgramName\":\"Calculator.java\",\"trainingID\": \"1\"}";
|
||||
MyThread myThread=new MyThread(id,jsonParam, path);
|
||||
myThread.start();
|
||||
// String response = HttpHelper.sendPost(GameBridgeTest.gameBridgeURL + path, jsonParam);
|
||||
// logger.info(id + "\t" + response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试总的脚本生成 <一句话功能简述> <功能详细描述>
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
* @see [类、类#方法、类#成员]
|
||||
*/
|
||||
// @Test
|
||||
public void generatePipelineScriptForGame() throws UnsupportedEncodingException {
|
||||
|
||||
String path = "/game/generatePipelineScriptForGame";
|
||||
logger.info(path);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
String jsonParam = "gameInfo={\n" + "\t\"operationEnvironment\": \"Java\",\n"
|
||||
+ "\t\"challengePipelines\":[\n"
|
||||
+ "\t\t{\"challengeStage\":\"1\",\"challengePipeline\":\"ICAgICAgICAgICAgaWYgKGN1cnJlbnRTdGFnZSA9PSAxKSB7DQoNCiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOe8luivkeeoi+W6jw0KICAgICAgICAgICAgICAgICAgICAgICAgc2ggc2NyaXB0OiAnZWNobyAiJChqYXZhYyBDYWxjdWxhdG9yLmphdmEgMj4mMSkiID4gY29tcGlsZV9yZXN1bHRfMS5vdXQnDQogICAgICAgICAgICAgICAgICAgICAgICBjb21waWxlUmVzdWx0ID0gcmVhZEZpbGUgK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iBvdXQsIGluOmluLCBleHBlY3RlZE91dDpleHBlY3RlZE91dCkNCiAgICAgICAgICAgIH0=\"},\n"
|
||||
+ "\t\t{\"challengeStage\":\"2\",\"challengePipeline\":\"ICAgICAgICAgICAgaWYgKGN1cnJlbnRTdGFnZSA9PSAyKSB7DQoNCiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOe8luivkeeoi+W6jw0KICAgICAgICAgICAgICAgICAgICAgICAgc2ggc2NyaXB0OiAnZWNobyAiJChqYXZhYyBDYWxjdWxhdG9yLmphdmEgMj4mMSkiID4gY29tcGlsZV9yZXN1bHRfMi5vdXQnDQogICAgICAgICAgICAgICAgICAgICAgICBjb21waWxlUmVzdWx0ID0gcmVhZEZpbGUgKCdjb21waWxlX3Jlc3VsdF8yLm91dCcpDQoNCiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOWmguaenOe8luivkemUmeivrw0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNvbXBpbGVSZXN1bHQudHJpbSgpID09ICcnKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3N0R2FtZUluc3RhbmNlUmVzdWx0VG9CRFdlYihjb21waWxlUmVzdWx0OiBjb21waWxlUmVzdWx0LCBvdXQ6ICcnLCBpbjppbiwgZXhwZWN0ZWRPdXQ6ZXhwZWN0ZWRPdXQpDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gOw0KICAgICAgICAgICAgICAgICAgICAgICAgfQ0KDQoJCQkJCQlTdHJpbmdCdWlsZGVyIGluID0gbmV3IFN0cmluZ0J1aWxkZXIoJ1snKQ0KCQkJCQkJU3RyaW5nQnVpbGRlciBvdXQgPSBuZXcgU3RyaW5nQnVpbGRlcignWycpDQoJCQkJCQlTdHJpbmdCVWlsZGVyIGV4cGVjdGVkT3V0ID0gbmV3IFN0cmluZ0J1aWxkZXIoJ1snKQ0KDQoJCQkJCQlkZWYgZmlsZU51bXMgPSBzaCBzY3JpcHQ6ICdscyAtbCB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QuYXBwZW5kKCJdIik7DQoNCgkJCQkJCWV4cGVjdGVkT3V0ID0gZXhwZWN0ZWRPdXQuZGVsZXRlQ2hhckF0KGV4cGVjdGVkT3V0Lmxlbmd0aCgpIC0gMSk7DQoJCQkJCQlleHBlY3RlZE91dCA9IGV4cGVjdGVkT3V0LmFwcGVuZCgiXSIpOw0KDQogICAgICAgICAgICAgICAgICAgICAgICAvLyDnlLHkuK3pl7TlsYLliKTmlq3nu5PmnpzkuYvlkI7lj5HpgIHnu5lCRFdlYg0KICAgICAgICAgICAgICAgICAgICAgICAgcG9zdEdhbWVJbnN0YW5jZVJlc3VsdFRvQkRXZWIoY29tcGlsZVJlc3VsdDogY29tcGlsZVJlc3VsdCwgb3V0OiBvdXQsIGluOmluLCBleHBlY3RlZE91dDpleHBlY3RlZE91dCkNCiAgICAgICAgICAgIH0=\"},\n"
|
||||
+ "\t\t{\"challengeStage\":\"3\",\"challengePipeline\":\"ICAgICAgICAgICAgaWYgKGN1cnJlbnRTdGFnZSA9PSAzKSB7DQoNCiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOe8luivkeeoi+W6jw0KICAgICAgICAgICAgICAgICAgICAgICAgc2ggc2NyaXB0OiAnZWNobyAiJChqYXZhYyBDYWxjdWxhdG9yLmphdmEgMj4mMSkiID4gY29tcGlsZV9yZXN1bHRfMy5vdXQnDQogICAgICAgICAgICAgICAgICAgICAgICBjb21waWxlUmVzdWx0ID0gcmVhZEZpbGUgKCdjb21waWxlX3Jlc3VsdF8zLm91dCcpDQoNCiAgICAgICAgICAgICAgICAgICAgICAgIC8vIOWmguaenOe8luivkemUmeivrw0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGNvbXBpbGVSZXN1bHQudHJpbSgpID09ICcnKSB7DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwb3N0R2FtZUluc3RhbmNlUmVzdWx0VG9CRFdlYihjb21waWxlUmVzdWx0OiBjb21waWxlUmVzdWx0LCBvdXQ6ICcnLCBpb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W8jw0KCQkJCQkJCWluLmFwcGVuZCgiXCIiICsgaW5JICsgIlwiLCIpOw0KCQkJCQkJCW91dC5hcHBlbmQoIlwiIiArIG91dEkgKyAiXCIsIik7DQoJCQkJCQkJZXhwZWN0ZWRPdXQuYXBwZW5kKCJcIiIgKyBleHBlY3RlZE91dEkgKyAiXCIsIik7DQoNCgkJCQkJCX0NCg0KCQkJCQkJaW4gPSBpbi5kZWxldGVDaGFyQXQoaW4ubGVuZ3RoKCkgLSAxKTsNCgkJCQkJCWluID0gaW4uYXBwZW5kKCJdIik7DQoNCgkJCQkJCW91dCA9IG91dC5kZWxldGVDaGFyQXQob3V0Lmxlbmd0aCgpIC0gMSk7DQoJCQkJCQlvdXQgPSBvdXQuYXBwZW5kKCJdIik7DQoNCgkJCQkJCWV4cGVjdGVkT3V0ID0gZXhwZWN0ZWRPdXQuZGVsZXRlQ2hhckF0KGV4cGVjdGVkT3V0Lmxlbmd0aCgpIC0gMSk7DQoJCQkJCQlleHBlY3RlZE91dCA9IGV4cGVjdGVkT3V0LmFwcGVuZCgiXSIpOw0KDQogICAgICAgICAgICAgICAgICAgICAgICAvLyDnlLHkuK3pl7TlsYLliKTmlq3nu5PmnpzkuYvlkI7lj5HpgIHnu5lCRFdlYg0KICAgICAgICAgICAgICAgICAgICAgICAgcG9zdEdhbWVJbnN0YW5jZVJlc3VsdFRvQkRXZWIoY29tcGlsZVJlc3VsdDogY29tcGlsZVJlc3VsdCwgb3V0OiBvdXQsIGluOmluLCBleHBlY3RlZE91dDpleHBlY3RlZE91dCkNCiAgICAgICAgICAgIH0=\"}\n"
|
||||
+ "\t]\n" + "}";
|
||||
// String response = HttpHelper.sendPost(gameBridgeURL + path, jsonParam);
|
||||
// logger.info(response);
|
||||
MyThread myThread=new MyThread(jsonParam, path);
|
||||
myThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试10个人同时开始实训 <一句话功能简述> <功能详细描述>
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
* @see [类、类#方法、类#成员]
|
||||
*/
|
||||
// @Test
|
||||
public void openGameInstance() throws UnsupportedEncodingException {
|
||||
String path = "/game/openGameInstance";
|
||||
logger.info(path);
|
||||
int id = 1;
|
||||
for (int i = 0; i < 10; i++, id++) {
|
||||
String jobNameForInstance = "jobNameForInstance="+"junit" + id;
|
||||
String gamePipelineScript = "&"+"gamePipelineScript="+Base64Helper.encode("node () { git url: instanceGitURL }")+"&";
|
||||
String instanceGitURL ="instanceGitURL="+ Base64Helper.encode("https://bdgit.trustie.net/wangwei10061/calculator.git");
|
||||
// String response = HttpHelper.sendPostListParams(gameBridgeURL + path,
|
||||
// Arrays.asList(jobNameForInstance, gamePipelineScript, instanceGitURL));
|
||||
MyThread myThread=new MyThread( jobNameForInstance, gamePipelineScript, instanceGitURL, path);
|
||||
myThread.start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试10个人同时提交评测 <一句话功能简述> <功能详细描述>
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
* @see [类、类#方法、类#成员]
|
||||
*/
|
||||
// @Test
|
||||
public void buildJobForInstance() throws UnsupportedEncodingException {
|
||||
String path = "/api/buildJobForInstance";
|
||||
logger.info(path);
|
||||
int id = 1;
|
||||
for (int i = 0; i < 10; i++, id++) {
|
||||
String jobNameForInstance = "jobNameForInstance=junit" + id;
|
||||
String instanceGitURL = "&instanceGitURL="+Base64Helper.encode("https://bdgit.trustie.net/wangwei10061/calculator.git");
|
||||
String instanceChallenge = "&instanceChallenge=1";
|
||||
String buildId = "&buildID=" + trainingID++;
|
||||
MyThread myThread=new MyThread(jobNameForInstance, instanceChallenge, instanceGitURL, buildId, path);
|
||||
myThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 混合测试,5个人开始实训,5个人提交评测,交替进行<一句话功能简述> <功能详细描述>
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
* @see [类、类#方法、类#成员]
|
||||
*/
|
||||
// @Test
|
||||
public void testopenGameInstanceAndBuildJobForInstance() throws UnsupportedEncodingException {
|
||||
String path1 = "/api/buildJobForInstance";
|
||||
String path2 = "/game/openGameInstance";
|
||||
logger.info(path1 + " and " + path2);
|
||||
int id = 11;
|
||||
int exists = 1;
|
||||
for (int i = 0; i < 5; i++, id++, exists++) {
|
||||
/**
|
||||
* open instance
|
||||
*/
|
||||
String jobNameForInstance = "jobNameForInstance="+"junit" + id;
|
||||
String gamePipelineScript = "&"+"gamePipelineScript="+Base64Helper.encode("node () { git url: instanceGitURL }")+"&";
|
||||
String instanceGitURL ="instanceGitURL="+ Base64Helper.encode("https://bdgit.trustie.net/wangwei10061/calculator.git");
|
||||
|
||||
MyThread myThread=new MyThread( jobNameForInstance, gamePipelineScript, instanceGitURL, path2);
|
||||
myThread.start();
|
||||
// String response = HttpHelper.sendPostListParams(gameBridgeURL + path2,
|
||||
// Arrays.asList(jobNameForInstance, gamePipelineScript, instanceGitURL));
|
||||
//
|
||||
// logger.info(jobNameForInstance + "\t" + TimeHandle.getNowTime());
|
||||
|
||||
/**
|
||||
* build job
|
||||
*/
|
||||
|
||||
|
||||
jobNameForInstance = "jobNameForInstance=junit" + exists;
|
||||
instanceGitURL = "&instanceGitURL="+Base64Helper.encode("https://bdgit.trustie.net/wangwei10061/calculator.git");
|
||||
String instanceChallenge = "&instanceChallenge=1";
|
||||
String buildId = "&buildID=" + trainingID++;
|
||||
myThread=new MyThread(jobNameForInstance, instanceChallenge, instanceGitURL, buildId, path1);
|
||||
myThread.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String pipeline = "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" + "}";
|
||||
}
|
|
@ -36,9 +36,9 @@ import com.offbytwo.jenkins.model.JobWithDetails;
|
|||
*/
|
||||
|
||||
public class MyTest {
|
||||
public String url = "http://106.75.33.219:30001";
|
||||
public String username = "root";
|
||||
public String password = "root";
|
||||
// public String url = "http://106.75.33.219:30001";
|
||||
// public String username = "root";
|
||||
// public String password = "root";
|
||||
// public String url = "http://106.75.78.183:8888/";
|
||||
// public String username = "root";
|
||||
// public String password = "root";
|
||||
|
@ -46,6 +46,11 @@ public class MyTest {
|
|||
// public String url = "http://106.75.78.183:9999/jenkins";
|
||||
// public String username = "guange";
|
||||
// public String password = "123456";
|
||||
|
||||
|
||||
public String url = "http://123.59.135.74:9999/jenkins";
|
||||
public String username = "guange";
|
||||
public String password = "123456";
|
||||
public String time=TimeHandle.printNowTime().replace('/', '-').replace(":", "-");
|
||||
// public String fileName1=time+"-series.txt";
|
||||
// public String fileName2=time+"-parallel.txt";
|
||||
|
@ -91,13 +96,13 @@ public class MyTest {
|
|||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void deleteJob() throws Exception {
|
||||
int count = 20;
|
||||
int count =20;
|
||||
JenkinsServer jenkins = new JenkinsServer(new URI(url), username, password);
|
||||
Map<String, Job> jobs = jenkins.getJobs();
|
||||
for (int i = 0; i < count; i++) {
|
||||
String jobname = i + "";
|
||||
String jobname ="junit"+ i + "";
|
||||
if (jobs.containsKey(jobname)) {
|
||||
System.out.println(jobname);
|
||||
deleteOneJob(jobname);
|
||||
|
|
|
@ -1,39 +1,53 @@
|
|||
|
||||
/**
|
||||
* 文件名 : TimeHandle.java
|
||||
* 版权 : <版权/公司名>
|
||||
* 描述 : <描述>
|
||||
* @author liliy
|
||||
* 版本 : <版本>
|
||||
* 修改时间: 2017年3月24日
|
||||
* 修改内容: <修改内容>
|
||||
* 文件名 : TimeHandle.java 版权 : <版权/公司名> 描述 : <描述>
|
||||
*
|
||||
* @author liliy 版本 : <版本> 修改时间: 2017年3月24日 修改内容: <修改内容>
|
||||
*/
|
||||
package cn.lili.test;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* <一句话功能简述>
|
||||
* <功能详细描述>
|
||||
* @author liliy
|
||||
* @version [版本号,2017年3月24日]
|
||||
* @see [相关类/方法]
|
||||
* @since [产品/模块版本]
|
||||
* <一句话功能简述> <功能详细描述>
|
||||
*
|
||||
* @author liliy
|
||||
* @version [版本号,2017年3月24日]
|
||||
* @see [相关类/方法]
|
||||
* @since [产品/模块版本]
|
||||
*/
|
||||
|
||||
public class TimeHandle {
|
||||
public static void main(String[] args) {
|
||||
printNowTime();
|
||||
final Logger logger = LoggerFactory.getLogger(TimeHandle.class);
|
||||
PropertyConfigurator.configure("E:\\projects\\java\\training_project\\jenkins-exec\\src\\main\\resources\\log4j.properties");
|
||||
|
||||
for(int i=0;i<100;i++)
|
||||
{
|
||||
logger.info(getNowTime());
|
||||
}
|
||||
// printNowTime();
|
||||
}
|
||||
|
||||
// @Test
|
||||
public static String printNowTime() {
|
||||
Date now = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");// 可以方便地修改日期格式
|
||||
String hehe = dateFormat.format(now);
|
||||
System.out.print(hehe + "\t");
|
||||
return hehe;
|
||||
}
|
||||
|
||||
public static String getNowTime() {
|
||||
Date now = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");// 可以方便地修改日期格式
|
||||
String hehe = dateFormat.format(now);
|
||||
return hehe;
|
||||
}
|
||||
// @Test
|
||||
public static String printNowTime(){
|
||||
Date now = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");//可以方便地修改日期格式
|
||||
String hehe = dateFormat.format( now );
|
||||
System.out.print(hehe+"\t");
|
||||
return hehe;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,4 +8,4 @@ log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
|
|||
#log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
|
||||
log4j.appender.stdout.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} %m%n
|
||||
|
||||
log4j.logger.org.springframework=INFO
|
||||
log4j.logger.org.springframework=DEBUG
|
Loading…
Reference in New Issue