|
|
@@ -12,6 +12,7 @@ import com.cec.plugins.domain.ResultData;
|
|
|
import com.cec.plugins.domain.reported.*;
|
|
|
import com.cec.plugins.enumerate.EstimateEnum;
|
|
|
import com.cec.plugins.enumerate.TaskEnum;
|
|
|
+import com.cec.plugins.service.task.ReportService;
|
|
|
import com.cec.plugins.utils.HttpUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -34,6 +35,7 @@ public class TaskService {
|
|
|
private final ProjectProperties properties;
|
|
|
private final RedisClientSource redisClientSource;
|
|
|
private final RedisClientEvaluate redisClientEvaluate;
|
|
|
+ private final ReportService reportService;
|
|
|
|
|
|
public boolean saveTaskToRedis(Map<TaskEnum, Object> map) {
|
|
|
return redisClientSource.writeRedis(map);
|
|
|
@@ -71,7 +73,7 @@ public class TaskService {
|
|
|
body.setServiceName(properties.getPlugin().getServiceName());
|
|
|
body.setPort(properties.getPlugin().getPort());
|
|
|
try {
|
|
|
- reportPlatform("/api/v1/serviceRegistration", body);
|
|
|
+ reportService.reportPlatform("/api/v1/serviceRegistration", body);
|
|
|
} catch (Exception e) {
|
|
|
log.info("注册服务失败,异常信息:{}", e.getMessage());
|
|
|
}
|
|
|
@@ -92,7 +94,7 @@ public class TaskService {
|
|
|
public void reported(TaskEnum instances, Class<? extends ReportedTypeFactory.ReportedType> reportedClass, BaseData dto) {
|
|
|
try {
|
|
|
Object data = getReportedData(reportedClass).execute();
|
|
|
- reportPlatform("/config/api/v1/receivetaskstatus", data);
|
|
|
+ reportService.reportPlatform("/config/api/v1/receivetaskstatus", data);
|
|
|
if (null != instances) {
|
|
|
// 上报完毕重置请求Id
|
|
|
redisClientSource.setCacheObject(instances.getKey(), "");
|
|
|
@@ -106,7 +108,7 @@ public class TaskService {
|
|
|
data.setInstanceId(dto.getInstanceId());
|
|
|
data.setStatus(1);
|
|
|
data.setReason("执行失败");
|
|
|
- reportPlatform("/config/api/v1/receivetaskstatus", data);
|
|
|
+ reportService.reportPlatform("/config/api/v1/receivetaskstatus", data);
|
|
|
log.info("{},上报失败数据,异常信息:{}", reportedClass.getName(), e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
@@ -122,27 +124,7 @@ public class TaskService {
|
|
|
data.setInstanceId(dto.getInstanceId());
|
|
|
data.setStatus(1);
|
|
|
data.setReason("任务资源被占用");
|
|
|
- reportPlatform("/config/api/v1/receivetaskstatus", data);
|
|
|
- }
|
|
|
-
|
|
|
- public void reportPlatform(String apiUrl, Object body) {
|
|
|
- ProjectProperties.PlatformModel platform = properties.getPlatform();
|
|
|
- String url = platform.getHttpUtl(apiUrl);
|
|
|
- try {
|
|
|
- Object execute = (new RetryTemplate(platform.getRetries(), platform.getDelayMillis()) {
|
|
|
- @Override
|
|
|
- protected Object handle() {
|
|
|
- ResultData result = HttpUtils.post(url, body);
|
|
|
- if (result.codeSucceed()) {
|
|
|
- return result;
|
|
|
- }
|
|
|
- throw new RetryException(result.getRespMsg());
|
|
|
- }
|
|
|
- }).execute();
|
|
|
- log.info("连接平台成功,请求url:{},返回结果:{}", url, Convert.toStr(execute));
|
|
|
- } catch (Exception e) {
|
|
|
- log.info("连接平台失败,请求url:{},异常信息:{}", url, e.getMessage());
|
|
|
- }
|
|
|
+ reportService.reportPlatform("/config/api/v1/receivetaskstatus", data);
|
|
|
}
|
|
|
|
|
|
private RetryTemplate getReportedData(Class<? extends ReportedTypeFactory.ReportedType> reportedClass) {
|
|
|
@@ -182,6 +164,6 @@ public class TaskService {
|
|
|
for (EstimateEnum item : EstimateEnum.values()) {
|
|
|
data.addDataItem(item.getKey(), item.getDescribe(), StrUtil.firstNonEmpty(redisClientEvaluate.getCacheStr(item.getKey()), "0"));
|
|
|
}
|
|
|
- reportPlatform("/config/api/v1/evaluateData", data);
|
|
|
+ reportService.reportPlatform("/config/api/v1/evaluateData", data);
|
|
|
}
|
|
|
}
|