OCT REM: 1. 增加异步模式下通知平台部署命令执行结果功能
This commit is contained in:
parent
8223e294bd
commit
0c35416d7d
|
@ -4,8 +4,6 @@ import com.cmcc.magent.interceptor.MwSignRequestInterceptor;
|
|||
import com.cmcc.magent.pojo.po.RegisterAgent;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* PlatformApiService 接口定义了与平台 API 通信的核心服务功能。
|
||||
* <p>
|
||||
|
@ -27,7 +25,18 @@ public interface PlatformApiService {
|
|||
*
|
||||
* @param agent 包含代理注册信息的 {@link RegisterAgent} 对象
|
||||
* @return 平台返回的结果,通常为一个 JSON 格式的字符串
|
||||
* @throws IOException 如果在处理 JSON 时发生错误
|
||||
*/
|
||||
String registerAgent(RegisterAgent agent) throws IOException;
|
||||
String registerAgent(RegisterAgent agent);
|
||||
|
||||
/**
|
||||
* 回报部署任务结果。
|
||||
* <p>
|
||||
* 该方法用于想平台报告部署任务执行的结果。
|
||||
* </p>
|
||||
*
|
||||
* @param deploymentId 部署任务ID
|
||||
* @param status 部署任务执行结果:0(部署中),1(正常),2(不正常)
|
||||
* @return 平台返回的结果,通常为一个 JSON 格式的字符串
|
||||
*/
|
||||
String responseDeploymentResult(String deploymentId, int status);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.cmcc.magent.misc.JsonUtils;
|
|||
import com.cmcc.magent.pojo.entry.MiddlewareData;
|
||||
import com.cmcc.magent.pojo.po.RemoteFileDetails;
|
||||
import com.cmcc.magent.service.MiddlewareManagerService;
|
||||
import com.cmcc.magent.service.PlatformApiService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -62,6 +63,9 @@ public class MiddlewareManagerServiceImpl implements MiddlewareManagerService {
|
|||
@Resource
|
||||
private OssFactory ossFactory;
|
||||
|
||||
@Resource
|
||||
private PlatformApiService platformApiService;
|
||||
|
||||
/**
|
||||
* 根据命令获取对应的文件名。
|
||||
*
|
||||
|
@ -322,9 +326,10 @@ public class MiddlewareManagerServiceImpl implements MiddlewareManagerService {
|
|||
log.info("---- Task {} Finished", data.getUid());
|
||||
}).whenComplete((v, t) -> {
|
||||
if (t != null) {
|
||||
platformApiService.responseDeploymentResult(data.getUid(), 2);
|
||||
log.error("---- Task {} Finished With Exception: {}", data.getUid(), t.getMessage());
|
||||
} else {
|
||||
log.info("---- Task {} Finished: {}", data.getUid(), v);
|
||||
log.info("---- Task {} Finished: {}", data.getUid(), platformApiService.responseDeploymentResult(data.getUid(), 1));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -405,9 +410,10 @@ public class MiddlewareManagerServiceImpl implements MiddlewareManagerService {
|
|||
log.info("---- Task {} Finished", data.getUid());
|
||||
}).whenComplete((v, t) -> {
|
||||
if (t != null) {
|
||||
platformApiService.responseDeploymentResult(data.getUid(), 2);
|
||||
log.error("---- Task {} Finished With Exception: {}", data.getUid(), t.getMessage());
|
||||
} else {
|
||||
log.info("---- Task {} Finished: {}", data.getUid(), v);
|
||||
log.info("---- Task {} Finished: {}", data.getUid(), platformApiService.responseDeploymentResult(data.getUid(), 1));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,9 +6,12 @@ import com.cmcc.magent.misc.JsonUtils;
|
|||
import com.cmcc.magent.pojo.po.RegisterAgent;
|
||||
import com.cmcc.magent.service.PlatformApiService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* PlatformApiServiceImpl 是 {@link PlatformApiService} 的具体实现类。
|
||||
|
@ -26,6 +29,7 @@ import java.io.IOException;
|
|||
* @since 2025 -01-07
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PlatformApiServiceImpl implements PlatformApiService {
|
||||
@Resource
|
||||
private PlatformServiceConfig platformServiceConfig;
|
||||
|
@ -39,11 +43,49 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|||
*
|
||||
* @param agent 包含代理注册信息的 {@link RegisterAgent} 实例
|
||||
* @return 平台返回的注册结果,通常为 JSON 格式的字符串
|
||||
* @throws IOException IO 异常
|
||||
*/
|
||||
@Override
|
||||
public String registerAgent(RegisterAgent agent) throws IOException {
|
||||
String reqString = JsonUtils.getJson(agent);
|
||||
return HttpClientUtils.postJson(platformServiceConfig + "/register", null, reqString, null);
|
||||
public String registerAgent(RegisterAgent agent) {
|
||||
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
String reqString = JsonUtils.getJson(agent);
|
||||
result = HttpClientUtils.postJson(platformServiceConfig + "/register", null, reqString, null);
|
||||
} catch (IOException e) {
|
||||
log.error("Register agent client {} exception: {}", agent.getDeviceId(), e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 回报部署任务结果。
|
||||
* <p>
|
||||
* 该方法用于想平台报告部署任务执行的结果。
|
||||
* </p>
|
||||
*
|
||||
* @param deploymentId 部署任务ID
|
||||
* @param status 部署任务执行结果:0(部署中),1(正常),2(不正常)
|
||||
* @return 平台返回的结果,通常为一个 JSON 格式的字符串
|
||||
*/
|
||||
@Override
|
||||
public String responseDeploymentResult(String deploymentId, int status) {
|
||||
Map<String, String> headers = new HashMap<>(4);
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded");
|
||||
|
||||
Map<String, String> params = new HashMap<>(4);
|
||||
params.put("deploymentId", deploymentId);
|
||||
params.put("status", String.valueOf(status));
|
||||
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
result = HttpClientUtils.post(platformServiceConfig + "/innerapi/instance/update-status", headers, params, null);
|
||||
} catch (IOException e) {
|
||||
log.error("Report deployment {} result exception: {}", deploymentId, e.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ protocol.crypto-type=0
|
|||
|
||||
# Platform Service
|
||||
# Manager Platform URL
|
||||
service.platform-url=http://xajhuang.com:1300
|
||||
service.platform-url=https://172.21.44.35:50443/mw/core
|
||||
# APPID
|
||||
service.platform-appid=appid
|
||||
# cluster name
|
||||
|
|
Loading…
Reference in New Issue