You've already forked FrameTour-BE
feat(integration): 添加渲染工作器配置管理功能
- 新增 RenderWorkerConfigManager 类实现渲染工作器配置的管理功能 - 在 RenderWorkerRepository 中集成 RenderWorkerConfigManager - 添加方法 getWorkerConfigManager 获取渲染工作器配置管理器实例 - 优化 getWorkerByAccessKey 和 getWorker 方法,使用集成服务获取工作器信息
This commit is contained in:
@@ -0,0 +1,82 @@
|
|||||||
|
package com.ycwl.basic.integration.common.manager;
|
||||||
|
|
||||||
|
import com.ycwl.basic.integration.render.dto.config.RenderWorkerConfigV2DTO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渲染工作器配置管理器
|
||||||
|
* 基于通用ConfigManager实现渲染工作器配置的管理功能
|
||||||
|
*/
|
||||||
|
public class RenderWorkerConfigManager extends ConfigManager<RenderWorkerConfigV2DTO> {
|
||||||
|
|
||||||
|
public RenderWorkerConfigManager(List<RenderWorkerConfigV2DTO> configs) {
|
||||||
|
super(configs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getConfigKey(RenderWorkerConfigV2DTO config) {
|
||||||
|
return config != null ? config.getConfigKey() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object getConfigValue(RenderWorkerConfigV2DTO config) {
|
||||||
|
return config != null ? config.getConfigValue() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取渲染工作器配置类型
|
||||||
|
*/
|
||||||
|
public String getConfigType(String key) {
|
||||||
|
RenderWorkerConfigV2DTO config = findConfigByKey(key);
|
||||||
|
return config != null ? config.getConfigType() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取渲染工作器配置描述
|
||||||
|
*/
|
||||||
|
public String getConfigDescription(String key) {
|
||||||
|
RenderWorkerConfigV2DTO config = findConfigByKey(key);
|
||||||
|
return config != null ? config.getDescription() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取渲染工作器配置ID
|
||||||
|
*/
|
||||||
|
public Long getConfigId(String key) {
|
||||||
|
RenderWorkerConfigV2DTO config = findConfigByKey(key);
|
||||||
|
return config != null ? config.getId() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取工作器ID
|
||||||
|
*/
|
||||||
|
public Long getWorkerId(String key) {
|
||||||
|
RenderWorkerConfigV2DTO config = findConfigByKey(key);
|
||||||
|
return config != null ? config.getWorkerId() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查配置是否启用
|
||||||
|
*/
|
||||||
|
public boolean isActive(String key) {
|
||||||
|
RenderWorkerConfigV2DTO config = findConfigByKey(key);
|
||||||
|
return config != null && config.getIsActive() != null && config.getIsActive() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置的创建时间
|
||||||
|
*/
|
||||||
|
public String getCreateTime(String key) {
|
||||||
|
RenderWorkerConfigV2DTO config = findConfigByKey(key);
|
||||||
|
return config != null ? config.getCreateTime() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取配置的更新时间
|
||||||
|
*/
|
||||||
|
public String getUpdateTime(String key) {
|
||||||
|
RenderWorkerConfigV2DTO config = findConfigByKey(key);
|
||||||
|
return config != null ? config.getUpdateTime() : null;
|
||||||
|
}
|
||||||
|
}
|
@@ -4,6 +4,12 @@ import com.ycwl.basic.utils.JacksonUtil;
|
|||||||
import com.ycwl.basic.mapper.RenderWorkerMapper;
|
import com.ycwl.basic.mapper.RenderWorkerMapper;
|
||||||
import com.ycwl.basic.model.pc.renderWorker.entity.RenderWorkerEntity;
|
import com.ycwl.basic.model.pc.renderWorker.entity.RenderWorkerEntity;
|
||||||
import com.ycwl.basic.model.task.req.ClientStatusReqVo;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -11,40 +17,41 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class RenderWorkerRepository {
|
public class RenderWorkerRepository {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<String, String> redisTemplate;
|
private RedisTemplate<String, String> redisTemplate;
|
||||||
public static final String RENDER_WORKER_CACHE_KEY = "render_worker:%s";
|
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";
|
public static final String RENDER_WORKER_STATUS_CACHE_KEY = "render_worker:host_status:%s";
|
||||||
|
public static final String RENDER_WORKER_CONFIG_CACHE_KEY = "render_worker:%s:config";
|
||||||
@Autowired
|
@Autowired
|
||||||
private RenderWorkerMapper mapper;
|
private RenderWorkerMapper mapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RenderWorkerIntegrationService renderWorkerIntegrationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RenderWorkerConfigIntegrationService renderWorkerConfigIntegrationService;
|
||||||
|
|
||||||
public RenderWorkerEntity getWorkerByAccessKey(String accessKey) {
|
public RenderWorkerEntity getWorkerByAccessKey(String accessKey) {
|
||||||
String key = String.format(RENDER_WORKER_CACHE_KEY, accessKey);
|
RenderWorkerV2DTO workerDTO = renderWorkerIntegrationService.getWorkerByKey(accessKey);
|
||||||
if (redisTemplate.hasKey(key)) {
|
if (workerDTO == null) {
|
||||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class);
|
return null;
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
RenderWorkerEntity renderWorker = convertToEntity(workerDTO);
|
||||||
return renderWorker;
|
return renderWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RenderWorkerEntity getWorker(Long id) {
|
public RenderWorkerEntity getWorker(Long id) {
|
||||||
String key = String.format(RENDER_WORKER_CACHE_KEY, id);
|
RenderWorkerV2DTO workerDTO = renderWorkerIntegrationService.getWorker(id);
|
||||||
if (redisTemplate.hasKey(key)) {
|
if (workerDTO == null) {
|
||||||
return JacksonUtil.parseObject(redisTemplate.opsForValue().get(key), RenderWorkerEntity.class);
|
return null;
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
RenderWorkerEntity renderWorker = convertToEntity(workerDTO);
|
||||||
return renderWorker;
|
return renderWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,4 +96,35 @@ public class RenderWorkerRepository {
|
|||||||
}
|
}
|
||||||
redisTemplate.delete(String.format(RENDER_WORKER_STATUS_CACHE_KEY, id));
|
redisTemplate.delete(String.format(RENDER_WORKER_STATUS_CACHE_KEY, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RenderWorkerEntity convertToEntity(RenderWorkerV2DTO dto) {
|
||||||
|
if (dto == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user