You've already forked FrameTour-BE
Merge branch 'render-worker-microservice'
# Conflicts: # src/main/java/com/ycwl/basic/integration/scenic/service/ScenicIntegrationService.java # src/main/java/com/ycwl/basic/service/task/impl/TaskTaskServiceImpl.java
This commit is contained in:
@@ -1,50 +1,50 @@
|
||||
package com.ycwl.basic.repository;
|
||||
|
||||
import com.ycwl.basic.utils.JacksonUtil;
|
||||
import com.ycwl.basic.mapper.RenderWorkerMapper;
|
||||
import com.ycwl.basic.model.pc.renderWorker.entity.RenderWorkerEntity;
|
||||
import com.ycwl.basic.model.task.req.ClientStatusReqVo;
|
||||
import com.ycwl.basic.integration.render.dto.worker.RenderWorkerV2DTO;
|
||||
import com.ycwl.basic.integration.render.service.RenderWorkerIntegrationService;
|
||||
import com.ycwl.basic.integration.render.service.RenderWorkerConfigIntegrationService;
|
||||
import com.ycwl.basic.integration.render.dto.config.RenderWorkerConfigV2DTO;
|
||||
import com.ycwl.basic.integration.common.manager.RenderWorkerConfigManager;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RenderWorkerRepository {
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
public static final String RENDER_WORKER_CACHE_KEY = "render_worker:%s";
|
||||
public static final String RENDER_WORKER_STATUS_CACHE_KEY = "render_worker:host_status:%s";
|
||||
|
||||
@Autowired
|
||||
private RenderWorkerMapper mapper;
|
||||
private RenderWorkerIntegrationService renderWorkerIntegrationService;
|
||||
|
||||
@Autowired
|
||||
private RenderWorkerConfigIntegrationService renderWorkerConfigIntegrationService;
|
||||
|
||||
public RenderWorkerEntity getWorkerByAccessKey(String accessKey) {
|
||||
String key = String.format(RENDER_WORKER_CACHE_KEY, accessKey);
|
||||
if (redisTemplate.hasKey(key)) {
|
||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class);
|
||||
}
|
||||
RenderWorkerEntity renderWorker = mapper.findByAccessKey(accessKey);
|
||||
if (renderWorker != null) {
|
||||
redisTemplate.opsForValue().set(key, JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
|
||||
redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getId()), JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
|
||||
RenderWorkerV2DTO workerDTO = renderWorkerIntegrationService.getWorkerByKey(accessKey);
|
||||
if (workerDTO == null) {
|
||||
return null;
|
||||
}
|
||||
RenderWorkerEntity renderWorker = convertToEntity(workerDTO);
|
||||
return renderWorker;
|
||||
}
|
||||
|
||||
public RenderWorkerEntity getWorker(Long id) {
|
||||
String key = String.format(RENDER_WORKER_CACHE_KEY, id);
|
||||
if (redisTemplate.hasKey(key)) {
|
||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class);
|
||||
}
|
||||
RenderWorkerEntity renderWorker = mapper.getById(id);
|
||||
if (renderWorker != null) {
|
||||
redisTemplate.opsForValue().set(key, JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
|
||||
redisTemplate.opsForValue().set(String.format(RENDER_WORKER_CACHE_KEY, renderWorker.getAccessKey()), JacksonUtil.toJSONString(renderWorker), 1, TimeUnit.HOURS);
|
||||
RenderWorkerV2DTO workerDTO = renderWorkerIntegrationService.getWorker(id);
|
||||
if (workerDTO == null) {
|
||||
return null;
|
||||
}
|
||||
RenderWorkerEntity renderWorker = convertToEntity(workerDTO);
|
||||
return renderWorker;
|
||||
}
|
||||
|
||||
@@ -54,21 +54,6 @@ public class RenderWorkerRepository {
|
||||
return;
|
||||
}
|
||||
status.setUpdateAt(new Date());
|
||||
RenderWorkerEntity worker = new RenderWorkerEntity();
|
||||
worker.setCpuCount(status.getCpu_count());
|
||||
worker.setCpuUsage(status.getCpu_usage());
|
||||
// 上报的是字节,存储的是兆
|
||||
worker.setMemoryAvailable(status.getMemory_available().divide(BigDecimal.valueOf(1024 * 1024), RoundingMode.CEILING));
|
||||
worker.setMemoryTotal(status.getMemory_total().divide(BigDecimal.valueOf(1024 * 1024), RoundingMode.CEILING));
|
||||
|
||||
worker.setPlatform(status.getPlatform());
|
||||
worker.setRuntimeVersion(status.getRuntime_version());
|
||||
worker.setSupportFeature(String.join(",", status.getSupport_feature()));
|
||||
worker.setVersion(status.getVersion());
|
||||
worker.setUpdateAt(status.getUpdateAt());
|
||||
if (!redisTemplate.hasKey(key)) {
|
||||
mapper.updateHost(id, worker);
|
||||
}
|
||||
redisTemplate.opsForValue().set(key, JacksonUtil.toJSONString(status), 1, TimeUnit.HOURS);
|
||||
}
|
||||
|
||||
@@ -81,12 +66,34 @@ public class RenderWorkerRepository {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clearCache(Long id) {
|
||||
RenderWorkerEntity worker = getWorker(id);
|
||||
redisTemplate.delete(String.format(RENDER_WORKER_CACHE_KEY, id));
|
||||
if (worker != null) {
|
||||
redisTemplate.delete(String.format(RENDER_WORKER_CACHE_KEY, worker.getAccessKey()));
|
||||
private RenderWorkerEntity convertToEntity(RenderWorkerV2DTO dto) {
|
||||
if (dto == null) {
|
||||
return null;
|
||||
}
|
||||
redisTemplate.delete(String.format(RENDER_WORKER_STATUS_CACHE_KEY, id));
|
||||
RenderWorkerEntity entity = new RenderWorkerEntity();
|
||||
entity.setId(dto.getId());
|
||||
entity.setName(dto.getName());
|
||||
entity.setAccessKey(dto.getKey());
|
||||
entity.setStatus(dto.getIsActive());
|
||||
entity.setCreateAt(dto.getCreateTime());
|
||||
entity.setUpdateAt(dto.getUpdateTime());
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取渲染工作器配置管理器
|
||||
*
|
||||
* @param workerId 工作器ID
|
||||
* @return RenderWorkerConfigManager实例,如果获取失败返回null
|
||||
*/
|
||||
public RenderWorkerConfigManager getWorkerConfigManager(Long workerId) {
|
||||
try {
|
||||
List<RenderWorkerConfigV2DTO> configList = renderWorkerConfigIntegrationService.getWorkerConfigs(workerId);
|
||||
return new RenderWorkerConfigManager(configList);
|
||||
} catch (Exception e) {
|
||||
log.error("获取渲染工作器配置管理器失败, workerId: {}", workerId, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package com.ycwl.basic.repository;
|
||||
import com.ycwl.basic.facebody.enums.FaceBodyAdapterType;
|
||||
import com.ycwl.basic.integration.common.util.ConfigValueUtil;
|
||||
import com.ycwl.basic.integration.scenic.dto.scenic.ScenicV2DTO;
|
||||
import com.ycwl.basic.integration.scenic.dto.scenic.ScenicV2ListResponse;
|
||||
import com.ycwl.basic.integration.common.response.PageResponse;
|
||||
import com.ycwl.basic.integration.scenic.dto.scenic.ScenicV2WithConfigDTO;
|
||||
import com.ycwl.basic.integration.scenic.service.ScenicIntegrationService;
|
||||
import com.ycwl.basic.integration.scenic.service.ScenicConfigIntegrationService;
|
||||
@@ -212,7 +212,7 @@ public class ScenicRepository {
|
||||
String name = scenicReqQuery.getName();
|
||||
|
||||
// 调用 zt-scenic 服务的 list 方法
|
||||
ScenicV2ListResponse response = scenicIntegrationService.listScenics(page, pageSize, status, name);
|
||||
PageResponse<ScenicV2DTO> response = scenicIntegrationService.listScenics(page, pageSize, status, name);
|
||||
|
||||
// 将 ScenicV2DTO 列表转换为 ScenicEntity 列表
|
||||
if (response != null && response.getList() != null) {
|
||||
|
Reference in New Issue
Block a user