|
@@ -1,17 +1,35 @@
|
|
|
package net.mooctest.www.android_auto_test.services.Impl;
|
|
|
|
|
|
+import net.mooctest.www.android_auto_test.common.constant.enums.SecondaryStatus;
|
|
|
import net.mooctest.www.android_auto_test.common.exceptions.HttpNotFoundException;
|
|
|
+import net.mooctest.www.android_auto_test.dao.RedisMappers.SecondaryStatusMap;
|
|
|
+import net.mooctest.www.android_auto_test.services.OssService;
|
|
|
import net.mooctest.www.android_auto_test.services.SecondaryService;
|
|
|
import net.mooctest.www.android_auto_test.utils.AddressUtil;
|
|
|
+import net.mooctest.www.android_auto_test.utils.OsUtil;
|
|
|
+import net.mooctest.www.android_auto_test.utils.PrintUtil;
|
|
|
+import net.mooctest.www.android_auto_test.vo.SecondaryResult;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
+/**
|
|
|
+ * @author henrylee
|
|
|
+ */
|
|
|
@Service
|
|
|
public class SecondaryServiceImpl implements SecondaryService {
|
|
|
|
|
|
+ public static final String TAG = Thread.currentThread() .getStackTrace()[1].getClassName();
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SecondaryStatusMap secondaryStatusMap;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OssService ossService;
|
|
|
+
|
|
|
@Override
|
|
|
- public void generateCrowdSourced(String traceId, String toolName) {
|
|
|
+ public void generateSecondaryReport(String traceId, String toolName) {
|
|
|
File traceDir = new File(AddressUtil.getTraceDir(traceId));
|
|
|
if (!traceDir.exists()) {
|
|
|
throw new HttpNotFoundException("任务不存在或信息已被清理,请重新测试");
|
|
@@ -20,6 +38,23 @@ public class SecondaryServiceImpl implements SecondaryService {
|
|
|
t.start();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public SecondaryResult getSecondaryStatus(String traceId, String toolName) {
|
|
|
+ SecondaryStatus ss = secondaryStatusMap.get(traceId, toolName);
|
|
|
+ if (ss == null){
|
|
|
+ throw new HttpNotFoundException("任务不存在或信息已被清理");
|
|
|
+ }
|
|
|
+ SecondaryResult sr = new SecondaryResult();
|
|
|
+ sr.setTraceId(traceId);
|
|
|
+ sr.setToolName(toolName);
|
|
|
+ sr.setStatusCode(ss.getCode());
|
|
|
+ sr.setDescription(ss.getDescription());
|
|
|
+ if (ss == SecondaryStatus.SUCCESS){
|
|
|
+ sr.setDownloadUrl(ossService.getDadaJsonDownloadPath(traceId, toolName + ".json"));
|
|
|
+ }
|
|
|
+ return sr;
|
|
|
+ }
|
|
|
+
|
|
|
private class RunTraceThread extends Thread{
|
|
|
private String traceId;
|
|
|
private String toolName;
|
|
@@ -30,9 +65,36 @@ public class SecondaryServiceImpl implements SecondaryService {
|
|
|
|
|
|
@Override
|
|
|
public void run(){
|
|
|
- //TODO 执行韦志宾的命令,然后生成文件,发给众测平台
|
|
|
- System.out.println("Generate " + toolName + " for trace " + traceId);
|
|
|
- System.out.println("Send Crowdsourced requirements to Mooctest.");
|
|
|
+ try {
|
|
|
+ secondaryStatusMap.put(traceId, toolName, SecondaryStatus.RUNNING);
|
|
|
+ PrintUtil.print(String.format("Generate bug report by %s.", toolName), TAG);
|
|
|
+ String command = String.format("java -jar tasks/%s.jar %s", toolName, traceId);
|
|
|
+ OsUtil.runCommand(command);
|
|
|
+ String reportName = toolName + ".json";
|
|
|
+ uploadReport(reportName);
|
|
|
+ secondaryStatusMap.put(traceId, toolName, SecondaryStatus.SUCCESS);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void uploadReport(String reportName){
|
|
|
+ PrintUtil.print(String.format("Upload %s's report.", toolName), TAG);
|
|
|
+ secondaryStatusMap.put(traceId, toolName, SecondaryStatus.UPLOADING);
|
|
|
+ String path = AddressUtil.getReportJsonPath(traceId, reportName);
|
|
|
+ File file = new File(path);
|
|
|
+ if (!file.exists()) {
|
|
|
+ secondaryStatusMap.put(traceId, toolName, SecondaryStatus.RUN_FAILED);
|
|
|
+ PrintUtil.print(String.format("Tool %s generate report failed.", toolName), TAG);
|
|
|
+ throw new RuntimeException("报告生成失败");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ ossService.uploadFileToTraceDir(file, traceId, reportName);
|
|
|
+ } catch (Exception e){
|
|
|
+ secondaryStatusMap.put(traceId, toolName, SecondaryStatus.UPLOAD_FAILED);
|
|
|
+ PrintUtil.print(String.format("Tool %s upload report failed.", toolName), TAG);
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|