You've already forked FrameTour-BE
feat(integration): 添加渲染工作器服务集成
- 新增 RenderWorkerConfigV2Client 和 RenderWorkerV2Client 接口 - 实现 RenderWorkerConfigIntegrationService 和 RenderWorkerIntegrationService 服务类 - 添加相关 DTO 类和 BatchConfigBuilder 工具类 - 在 IntegrationProperties 中增加 render 相关配置 - 更新 CommonResponse 类,增加 success 字段 - 新增 RenderWorkerIntegrationConfig 配置类
This commit is contained in:
@@ -23,6 +23,7 @@ The integration package (`com.ycwl.basic.integration`) is responsible for extern
|
||||
Currently implemented:
|
||||
- **Scenic Integration** (`com.ycwl.basic.integration.scenic`): ZT-Scenic microservice integration
|
||||
- **Device Integration** (`com.ycwl.basic.integration.device`): ZT-Device microservice integration
|
||||
- **Render Worker Integration** (`com.ycwl.basic.integration.render`): ZT-Render-Worker microservice integration
|
||||
|
||||
### Integration Pattern
|
||||
|
||||
@@ -241,6 +242,13 @@ integration:
|
||||
readTimeout: 10000
|
||||
retryEnabled: false
|
||||
maxRetries: 3
|
||||
render:
|
||||
enabled: true
|
||||
serviceName: zt-render-worker
|
||||
connectTimeout: 5000
|
||||
readTimeout: 10000
|
||||
retryEnabled: false
|
||||
maxRetries: 3
|
||||
```
|
||||
|
||||
### Usage Examples
|
||||
@@ -534,6 +542,11 @@ integration:
|
||||
enabled: true # Enable fallback for device service
|
||||
ttlDays: 5 # Custom TTL for device (shorter due to dynamic data)
|
||||
# cachePrefix: "device:fallback:" # Optional custom prefix
|
||||
|
||||
render:
|
||||
enabled: true # Enable fallback for render worker service
|
||||
ttlDays: 7 # Custom TTL for render worker (medium due to stable worker data)
|
||||
# cachePrefix: "render:fallback:" # Optional custom prefix
|
||||
|
||||
# Service configurations
|
||||
scenic:
|
||||
@@ -587,6 +600,205 @@ class ScenicIntegrationServiceTest {
|
||||
### Integration Testing
|
||||
Use `@SpringBootTest` with test profiles and mock external services.
|
||||
|
||||
## Render Worker Integration (ZT-Render-Worker Microservice)
|
||||
|
||||
### Key Components
|
||||
|
||||
#### Feign Clients
|
||||
- **RenderWorkerV2Client**: Main render worker operations (CRUD, listing)
|
||||
- **RenderWorkerConfigV2Client**: Render worker configuration management
|
||||
|
||||
#### Services
|
||||
- **RenderWorkerIntegrationService**: High-level render worker operations (with automatic fallback)
|
||||
- **RenderWorkerConfigIntegrationService**: Configuration management (with automatic fallback)
|
||||
|
||||
#### Configuration
|
||||
```yaml
|
||||
integration:
|
||||
render:
|
||||
enabled: true
|
||||
serviceName: zt-render-worker
|
||||
connectTimeout: 5000
|
||||
readTimeout: 10000
|
||||
retryEnabled: false
|
||||
maxRetries: 3
|
||||
```
|
||||
|
||||
### Usage Examples
|
||||
|
||||
#### Basic Render Worker Operations (with Automatic Fallback)
|
||||
```java
|
||||
@Autowired
|
||||
private RenderWorkerIntegrationService renderWorkerService;
|
||||
|
||||
// Get render worker basic info (automatically falls back to cache on failure)
|
||||
RenderWorkerV2DTO worker = renderWorkerService.getWorker(workerId);
|
||||
|
||||
// Get render worker with configuration (automatically falls back to cache on failure)
|
||||
RenderWorkerV2WithConfigDTO workerWithConfig = renderWorkerService.getWorkerWithConfig(workerId);
|
||||
|
||||
// Get render worker by key (automatically falls back to cache on failure)
|
||||
RenderWorkerV2DTO workerByKey = renderWorkerService.getWorkerByKey("video-renderer-001");
|
||||
|
||||
// Get render worker with config by key (automatically falls back to cache on failure)
|
||||
RenderWorkerV2WithConfigDTO workerWithConfigByKey = renderWorkerService.getWorkerWithConfigByKey("video-renderer-001");
|
||||
|
||||
// Create new render worker (direct operation, fails immediately on error)
|
||||
CreateRenderWorkerRequest request = new CreateRenderWorkerRequest();
|
||||
request.setName("Video Renderer");
|
||||
request.setKey("video-renderer-001");
|
||||
request.setIsActive(1);
|
||||
RenderWorkerV2DTO newWorker = renderWorkerService.createWorker(request);
|
||||
|
||||
// Update render worker (direct operation, fails immediately on error)
|
||||
UpdateRenderWorkerRequest updateRequest = new UpdateRenderWorkerRequest();
|
||||
updateRequest.setName("Updated Video Renderer");
|
||||
renderWorkerService.updateWorker(workerId, updateRequest);
|
||||
|
||||
// Delete render worker (direct operation, fails immediately on error)
|
||||
renderWorkerService.deleteWorker(workerId);
|
||||
|
||||
// List render workers (no fallback for list operations)
|
||||
List<RenderWorkerV2DTO> workers = renderWorkerService.listWorkers(1, 10, 1, null);
|
||||
|
||||
// List render workers with config (no fallback for list operations)
|
||||
List<RenderWorkerV2WithConfigDTO> workersWithConfig =
|
||||
renderWorkerService.listWorkersWithConfig(1, 10, 1, null);
|
||||
```
|
||||
|
||||
#### Configuration Management (with Automatic Fallback)
|
||||
```java
|
||||
@Autowired
|
||||
private RenderWorkerConfigIntegrationService configService;
|
||||
|
||||
// Get worker configurations (with fallback)
|
||||
List<RenderWorkerConfigV2DTO> configs = configService.getWorkerConfigs(workerId);
|
||||
|
||||
// Get flat configuration (automatically falls back to cache on failure)
|
||||
Map<String, Object> flatConfig = configService.getWorkerFlatConfig(workerId);
|
||||
|
||||
// Get specific configuration by key (with fallback)
|
||||
RenderWorkerConfigV2DTO config = configService.getWorkerConfigByKey(workerId, "render_quality");
|
||||
|
||||
// Create configuration (direct operation, fails immediately on error)
|
||||
RenderWorkerConfigV2DTO newConfig = new RenderWorkerConfigV2DTO();
|
||||
newConfig.setConfigKey("max_concurrent_tasks");
|
||||
newConfig.setConfigValue("4");
|
||||
newConfig.setConfigType("int");
|
||||
newConfig.setDescription("Maximum concurrent render tasks");
|
||||
newConfig.setIsActive(1);
|
||||
RenderWorkerConfigV2DTO created = configService.createWorkerConfig(workerId, newConfig);
|
||||
|
||||
// Update configuration (direct operation, fails immediately on error)
|
||||
Map<String, Object> updates = new HashMap<>();
|
||||
updates.put("configValue", "8");
|
||||
configService.updateWorkerConfig(workerId, configId, updates);
|
||||
|
||||
// Delete configuration (direct operation, fails immediately on error)
|
||||
configService.deleteWorkerConfig(workerId, configId);
|
||||
```
|
||||
|
||||
#### Enhanced Batch Configuration API
|
||||
```java
|
||||
// Using Builder Pattern for batch configuration
|
||||
BatchRenderWorkerConfigRequest request = configService.createBatchConfigBuilder()
|
||||
.addRenderConfig("high", "mp4", "1920x1080") // Render settings
|
||||
.addPerformanceConfig(8, 3600) // Performance settings
|
||||
.addConfig("output_path", "/data/renders", "string", "Output directory")
|
||||
.addConfig("enable_gpu", "true", "bool", "Enable GPU acceleration")
|
||||
.build();
|
||||
|
||||
// Batch update configurations (direct operation, fails immediately on error)
|
||||
configService.batchUpdateWorkerConfigs(workerId, request);
|
||||
|
||||
// Batch flat update configurations (direct operation, fails immediately on error)
|
||||
Map<String, Object> flatUpdates = new HashMap<>();
|
||||
flatUpdates.put("render_quality", "ultra");
|
||||
flatUpdates.put("max_concurrent_tasks", 12);
|
||||
flatUpdates.put("enable_preview", true);
|
||||
configService.batchFlatUpdateWorkerConfigs(workerId, flatUpdates);
|
||||
```
|
||||
|
||||
#### Render Worker Management Patterns
|
||||
```java
|
||||
// Create and configure render worker in one operation
|
||||
CreateRenderWorkerRequest workerRequest = new CreateRenderWorkerRequest();
|
||||
workerRequest.setName("4K Video Renderer");
|
||||
workerRequest.setKey("4k-video-renderer");
|
||||
RenderWorkerV2DTO worker = renderWorkerService.createWorker(workerRequest);
|
||||
|
||||
// Configure the worker for 4K video rendering
|
||||
BatchRenderWorkerConfigRequest config = configService.createBatchConfigBuilder()
|
||||
.addRenderConfig("ultra", "mp4", "3840x2160")
|
||||
.addPerformanceConfig(4, 7200) // 4 concurrent tasks, 2 hour timeout
|
||||
.addConfig("gpu_memory_limit", "8192", "int", "GPU memory limit in MB")
|
||||
.addConfig("codec", "h265", "string", "Video codec")
|
||||
.addConfig("bitrate", "50000", "int", "Video bitrate in kbps")
|
||||
.build();
|
||||
configService.batchUpdateWorkerConfigs(worker.getId(), config);
|
||||
|
||||
// Monitor worker configuration completeness (with automatic fallback)
|
||||
Map<String, Object> workerConfig = configService.getWorkerFlatConfig(worker.getId());
|
||||
boolean hasRenderConfig = workerConfig.containsKey("render_quality");
|
||||
boolean hasPerformanceConfig = workerConfig.containsKey("max_concurrent_tasks");
|
||||
// log configuration status...
|
||||
|
||||
// Get all active workers for monitoring
|
||||
List<RenderWorkerV2WithConfigDTO> activeWorkers =
|
||||
renderWorkerService.listWorkersWithConfig(1, 100, 1, null);
|
||||
|
||||
// Check worker health and configuration
|
||||
for (RenderWorkerV2WithConfigDTO activeWorker : activeWorkers) {
|
||||
Map<String, Object> config = activeWorker.getConfig();
|
||||
boolean isConfigured = config.containsKey("render_quality") &&
|
||||
config.containsKey("max_concurrent_tasks");
|
||||
// log worker status...
|
||||
}
|
||||
```
|
||||
|
||||
#### Fallback Cache Management for Render Workers
|
||||
```java
|
||||
@Autowired
|
||||
private IntegrationFallbackService fallbackService;
|
||||
|
||||
// Check fallback cache status
|
||||
boolean hasWorkerCache = fallbackService.hasFallbackCache("zt-render-worker", "worker:1001");
|
||||
boolean hasWorkerByKeyCache = fallbackService.hasFallbackCache("zt-render-worker", "worker:key:video-renderer-001");
|
||||
boolean hasConfigCache = fallbackService.hasFallbackCache("zt-render-worker", "worker:flat:config:1001");
|
||||
boolean hasConfigByKeyCache = fallbackService.hasFallbackCache("zt-render-worker", "worker:key:config:video-renderer-001");
|
||||
|
||||
// Get cache statistics
|
||||
IntegrationFallbackService.FallbackCacheStats stats =
|
||||
fallbackService.getFallbackCacheStats("zt-render-worker");
|
||||
log.info("Render worker fallback cache: {} items, TTL: {} days",
|
||||
stats.getTotalCacheCount(), stats.getFallbackTtlDays());
|
||||
|
||||
// Clear specific cache
|
||||
fallbackService.clearFallbackCache("zt-render-worker", "worker:1001");
|
||||
|
||||
// Clear all render worker caches
|
||||
fallbackService.clearAllFallbackCache("zt-render-worker");
|
||||
```
|
||||
|
||||
### Render Worker Types and Configuration
|
||||
|
||||
#### Common Configuration Keys
|
||||
- `render_quality`: Render quality level ("low", "medium", "high", "ultra")
|
||||
- `render_format`: Output format ("mp4", "avi", "mov", "webm")
|
||||
- `render_resolution`: Video resolution ("1920x1080", "3840x2160", "1280x720")
|
||||
- `max_concurrent_tasks`: Maximum concurrent render tasks (integer)
|
||||
- `task_timeout`: Task timeout in seconds (integer)
|
||||
- `output_path`: Render output directory path (string)
|
||||
- `enable_gpu`: Enable GPU acceleration (boolean)
|
||||
- `gpu_memory_limit`: GPU memory limit in MB (integer)
|
||||
- `codec`: Video codec ("h264", "h265", "vp9")
|
||||
- `bitrate`: Video bitrate in kbps (integer)
|
||||
- `enable_preview`: Enable preview generation (boolean)
|
||||
|
||||
#### Worker Status
|
||||
- **Active (isActive=1)**: Worker is available for tasks
|
||||
- **Inactive (isActive=0)**: Worker is disabled
|
||||
|
||||
## Common Development Tasks
|
||||
|
||||
### Running Integration Tests
|
||||
@@ -600,6 +812,10 @@ mvn test -Dtest="com.ycwl.basic.integration.*Test"
|
||||
# Run device integration tests
|
||||
mvn test -Dtest=DeviceIntegrationServiceTest
|
||||
mvn test -Dtest="com.ycwl.basic.integration.device.*Test"
|
||||
|
||||
# Run render worker integration tests
|
||||
mvn test -Dtest=RenderWorkerIntegrationServiceTest
|
||||
mvn test -Dtest="com.ycwl.basic.integration.render.*Test"
|
||||
```
|
||||
|
||||
### Adding New DTOs
|
||||
|
Reference in New Issue
Block a user