|
|
@@ -53,23 +53,11 @@ public class TaskService {
|
|
|
/** 注册服务 */
|
|
|
@Async
|
|
|
public void register() {
|
|
|
- ProjectProperties.PlatformModel platform = properties.getPlatform();
|
|
|
- String url = platform.getHttpUtl("/api/v1/serviceRegistration");
|
|
|
RegistrationDto body = new RegistrationDto();
|
|
|
body.setIpAddress(properties.getPlugin().getIpAddress());
|
|
|
body.setPort(properties.getPlugin().getPort());
|
|
|
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("注册服务成功,返回结果:{}", Convert.toStr(execute));
|
|
|
+ reportPlatform("/api/v1/serviceRegistration", body);
|
|
|
} catch (Exception e) {
|
|
|
log.info("注册服务失败,异常信息:{}", e.getMessage());
|
|
|
}
|
|
|
@@ -105,26 +93,30 @@ public class TaskService {
|
|
|
public void reported(Class<? extends ReportedData.ReportedType> reportedClass) {
|
|
|
try {
|
|
|
Object data = getReportedData(reportedClass).execute();
|
|
|
- Object result = doReported((ReportedData) data).execute();
|
|
|
- log.info("{},上报数据成功,返回结果:{}", reportedClass.getName(), Convert.toStr(result));
|
|
|
+ reportPlatform("/config/api/v1/receivetaskstatus", data);
|
|
|
} catch (Exception e) {
|
|
|
log.info("{},上报数据失败,异常信息:{}", reportedClass.getName(), e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private RetryTemplate doReported(ReportedData data) {
|
|
|
- String url = properties.getPlatform().getHttpUtl("/config/api/v1/receivetaskstatus");
|
|
|
- ProjectProperties.RetryModel simulation = properties.getSimulation();
|
|
|
- return new RetryTemplate(simulation.getRetries(), simulation.getDelayMillis()) {
|
|
|
- @Override
|
|
|
- protected Object handle() {
|
|
|
- ResultData result = HttpUtils.post(url, data);
|
|
|
- if (result.codeSucceed()) {
|
|
|
- return result;
|
|
|
+ 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());
|
|
|
}
|
|
|
- throw new RetryException(result.getRespMsg());
|
|
|
- }
|
|
|
- };
|
|
|
+ }).execute();
|
|
|
+ log.info("连接平台成功,请求url:{},返回结果:{}", url, Convert.toStr(execute));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("连接平台失败,请求url:{},异常信息:{}", url, e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private RetryTemplate getReportedData(Class<? extends ReportedData.ReportedType> reportedClass) {
|