|
@@ -16,7 +16,6 @@ import cn.iselab.mooctest.site.service.ThirdPartToolAppService;
|
|
|
import com.google.gson.Gson;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
@@ -42,7 +41,7 @@ public class ThirdPartToolAppServiceImpl implements ThirdPartToolAppService {
|
|
|
private String generateReportHost = "106.14.81.62";
|
|
|
|
|
|
//@Value("${thirdPartTool.reportService.port}")
|
|
|
- private String generateReportPort= "8080";
|
|
|
+ private String generateReportPort = "8080";
|
|
|
|
|
|
@Autowired
|
|
|
private ThirdPartToolJobDao thirdPartToolJobDao;
|
|
@@ -160,7 +159,7 @@ public class ThirdPartToolAppServiceImpl implements ThirdPartToolAppService {
|
|
|
ThirdPartToolAppStatusResponse appDataJobStatus;
|
|
|
try {
|
|
|
appDataJobStatus = rt.getForObject(url, ThirdPartToolAppStatusResponse.class);
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
throw new Exception("[jobs status:running]fail to get job status:" + jobId);
|
|
|
}
|
|
|
if (null == appDataJobStatus) {
|
|
@@ -181,12 +180,16 @@ public class ThirdPartToolAppServiceImpl implements ThirdPartToolAppService {
|
|
|
Gson gson = new Gson();
|
|
|
ThirdPartToolJob thirdPartToolJob = thirdPartToolJobDao.findOne(jobId);
|
|
|
if (null == thirdPartToolJob) {
|
|
|
- throw new Exception("this job is not exist:" + jobId);
|
|
|
+ throw new Exception("[jobs status:pending]fail to run job :" + jobId);
|
|
|
}
|
|
|
if (null == thirdPartToolJob.getConfig()) {
|
|
|
- throw new Exception("this job's config is empty:" + jobId);
|
|
|
+ throw new Exception("[jobs status:pending]fail to run job :" + jobId);
|
|
|
+ }
|
|
|
+ String config = thirdPartToolJob.getConfig();
|
|
|
+ if (null == config) {
|
|
|
+ throw new Exception("[jobs status:pending]fail to get this job's config :" + jobId);
|
|
|
}
|
|
|
- ThirdPartToolAppStartConfig thirdPartToolAppStartConfig = gson.fromJson(thirdPartToolJob.getConfig(), ThirdPartToolAppStartConfig.class);
|
|
|
+ ThirdPartToolAppStartConfig thirdPartToolAppStartConfig = gson.fromJson(config, ThirdPartToolAppStartConfig.class);
|
|
|
|
|
|
ThirdPartToolAppStartCommand thirdPartToolAppStartCommand = new ThirdPartToolAppStartCommand();
|
|
|
//TODO set command
|
|
@@ -197,18 +200,21 @@ public class ThirdPartToolAppServiceImpl implements ThirdPartToolAppService {
|
|
|
RestTemplate rt = new RestTemplate();
|
|
|
HttpEntity<ThirdPartToolAppStartCommand> httpEntity = new HttpEntity<>(thirdPartToolAppStartCommand, getHeader());
|
|
|
String url = getAppAutoTestStartUrl();
|
|
|
- ThirdPartToolAppStartResponse thirdPartToolAppStartResponse = rt.postForObject(url, httpEntity, ThirdPartToolAppStartResponse.class);
|
|
|
-
|
|
|
+ ThirdPartToolAppStartResponse thirdPartToolAppStartResponse;
|
|
|
+ try {
|
|
|
+ thirdPartToolAppStartResponse = rt.postForObject(url, httpEntity, ThirdPartToolAppStartResponse.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new Exception("[jobs status:pending]fail to run job :" + jobId + ";" + e.getMessage());
|
|
|
+ }
|
|
|
if (null == thirdPartToolAppStartResponse) {
|
|
|
- throw new Exception("start job fail:" + jobId);
|
|
|
+ throw new Exception("[jobs status:pending]fail to run job :" + jobId);
|
|
|
}
|
|
|
|
|
|
if (thirdPartToolAppStartResponse.getStatusCode().equals(ThirdPartToolAppStartResponseCode.CREATE)) {
|
|
|
thirdPartToolJob.setTraceId(thirdPartToolAppStartResponse.getTraceId());
|
|
|
- thirdPartToolJob.setStatus(ThirdPartToolJobStatusConstants.RUNNING);
|
|
|
thirdPartToolJobDao.save(thirdPartToolJob);
|
|
|
} else {
|
|
|
- throw new Exception("start job fail:" + jobId);
|
|
|
+ throw new Exception("[jobs status:pending]fail to run job :" + jobId +";jobstatus:" + thirdPartToolAppStartResponse.getStatusCode());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -278,6 +284,7 @@ public class ThirdPartToolAppServiceImpl implements ThirdPartToolAppService {
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
return headers;
|
|
|
}
|
|
|
+
|
|
|
private String getGenerateReportUrl(Long orderId, Long ownerId, String reportType) {
|
|
|
String api = "/api/report/generate/order/{orderId}/owner/{ownerId}/reportType/{reportType}"
|
|
|
.replace("{orderId}", "" + orderId)
|