mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
Compare commits
55
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b64a0f034 | ||
|
|
9025b72241 | ||
|
|
7c4e44875f | ||
|
|
74146870c5 | ||
|
|
1b40075d2a | ||
|
|
165cf79b35 | ||
|
|
49338df3e2 | ||
|
|
9cd3e613a5 | ||
|
|
b1296a0050 | ||
|
|
699b28af14 | ||
|
|
e1036f1b37 | ||
|
|
8187020096 | ||
|
|
b80971e85e | ||
|
|
f7140d4577 | ||
|
|
6659c213c3 | ||
|
|
a38465d04c | ||
|
|
319aa61dab | ||
|
|
4e21b3de78 | ||
|
|
a24561797f | ||
|
|
638ab0d6f4 | ||
|
|
68d86af501 | ||
|
|
13c0826f2f | ||
|
|
9f540c8449 | ||
|
|
965ec4f51b | ||
|
|
a1e508cd8d | ||
|
|
600bfbf671 | ||
|
|
019de6dc7a | ||
|
|
8dd9b7cccf | ||
|
|
3b2c75d2bd | ||
|
|
379d585cc7 | ||
|
|
0247bf2873 | ||
|
|
41cbbefb0b | ||
|
|
ffd91383c6 | ||
|
|
19df3fcc5d | ||
|
|
a3d727034a | ||
|
|
c557ec0062 | ||
|
|
63817fe7ee | ||
|
|
afdca513ac | ||
|
|
14e95186d6 | ||
|
|
960acc031e | ||
|
|
6cf78754b2 | ||
|
|
01e8cc4600 | ||
|
|
e7084c5b7e | ||
|
|
16a29b57f9 | ||
|
|
a1966e9692 | ||
|
|
f10c6305dc | ||
|
|
cd28ce7786 | ||
|
|
2941cdf95e | ||
|
|
688a91039d | ||
|
|
167ab29eb6 | ||
|
|
a4cf55a741 | ||
|
|
30ad65bb5f | ||
|
|
0d8e1f8a17 | ||
|
|
a0874d201c | ||
|
|
add122484c |
No files matched your search
@@ -112,3 +112,6 @@ test/s3/retention/weed-server.pid
|
|||||||
test/s3/retention/weed-test.log
|
test/s3/retention/weed-test.log
|
||||||
/test/s3/versioning/test-volume-data
|
/test/s3/versioning/test-volume-data
|
||||||
test/s3/versioning/weed-test.log
|
test/s3/versioning/weed-test.log
|
||||||
|
/docker/admin_integration/data
|
||||||
|
docker/agent_pub_record
|
||||||
|
docker/admin_integration/weed-local
|
||||||
@@ -0,0 +1,413 @@
|
|||||||
|
# SeaweedFS Task Distribution System Design
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
This document describes the design of a distributed task management system for SeaweedFS that handles Erasure Coding (EC) and vacuum operations through a scalable admin server and worker process architecture.
|
||||||
|
|
||||||
|
## System Architecture
|
||||||
|
|
||||||
|
### High-Level Components
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
|
||||||
|
│ Master │◄──►│ Admin Server │◄──►│ Workers │
|
||||||
|
│ │ │ │ │ │
|
||||||
|
│ - Volume Info │ │ - Task Discovery │ │ - Task Exec │
|
||||||
|
│ - Shard Status │ │ - Task Assign │ │ - Progress │
|
||||||
|
│ - Heartbeats │ │ - Progress Track │ │ - Error Report │
|
||||||
|
└─────────────────┘ └──────────────────┘ └─────────────────┘
|
||||||
|
│ │ │
|
||||||
|
│ │ │
|
||||||
|
▼ ▼ ▼
|
||||||
|
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
|
||||||
|
│ Volume Servers │ │ Volume Monitor │ │ Task Execution │
|
||||||
|
│ │ │ │ │ │
|
||||||
|
│ - Store Volumes │ │ - Health Check │ │ - EC Convert │
|
||||||
|
│ - EC Shards │ │ - Usage Stats │ │ - Vacuum Clean │
|
||||||
|
│ - Report Status │ │ - State Sync │ │ - Status Report │
|
||||||
|
└─────────────────┘ └──────────────────┘ └─────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## 1. Admin Server Design
|
||||||
|
|
||||||
|
### 1.1 Core Responsibilities
|
||||||
|
|
||||||
|
- **Task Discovery**: Scan volumes to identify EC and vacuum candidates
|
||||||
|
- **Worker Management**: Track available workers and their capabilities
|
||||||
|
- **Task Assignment**: Match tasks to optimal workers
|
||||||
|
- **Progress Tracking**: Monitor in-progress tasks for capacity planning
|
||||||
|
- **State Reconciliation**: Sync with master server for volume state updates
|
||||||
|
|
||||||
|
### 1.2 Task Discovery Engine
|
||||||
|
|
||||||
|
```go
|
||||||
|
type TaskDiscoveryEngine struct {
|
||||||
|
masterClient MasterClient
|
||||||
|
volumeScanner VolumeScanner
|
||||||
|
taskDetectors map[TaskType]TaskDetector
|
||||||
|
scanInterval time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
type VolumeCandidate struct {
|
||||||
|
VolumeID uint32
|
||||||
|
Server string
|
||||||
|
Collection string
|
||||||
|
TaskType TaskType
|
||||||
|
Priority TaskPriority
|
||||||
|
Reason string
|
||||||
|
DetectedAt time.Time
|
||||||
|
Parameters map[string]interface{}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**EC Detection Logic**:
|
||||||
|
- Find volumes >= 95% full and idle for > 1 hour
|
||||||
|
- Exclude volumes already in EC format
|
||||||
|
- Exclude volumes with ongoing operations
|
||||||
|
- Prioritize by collection and age
|
||||||
|
|
||||||
|
**Vacuum Detection Logic**:
|
||||||
|
- Find volumes with garbage ratio > 30%
|
||||||
|
- Exclude read-only volumes
|
||||||
|
- Exclude volumes with recent vacuum operations
|
||||||
|
- Prioritize by garbage percentage
|
||||||
|
|
||||||
|
### 1.3 Worker Registry & Management
|
||||||
|
|
||||||
|
```go
|
||||||
|
type WorkerRegistry struct {
|
||||||
|
workers map[string]*Worker
|
||||||
|
capabilities map[TaskType][]*Worker
|
||||||
|
lastHeartbeat map[string]time.Time
|
||||||
|
taskAssignment map[string]*Task
|
||||||
|
mutex sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
type Worker struct {
|
||||||
|
ID string
|
||||||
|
Address string
|
||||||
|
Capabilities []TaskType
|
||||||
|
MaxConcurrent int
|
||||||
|
CurrentLoad int
|
||||||
|
Status WorkerStatus
|
||||||
|
LastSeen time.Time
|
||||||
|
Performance WorkerMetrics
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 1.4 Task Assignment Algorithm
|
||||||
|
|
||||||
|
```go
|
||||||
|
type TaskScheduler struct {
|
||||||
|
registry *WorkerRegistry
|
||||||
|
taskQueue *PriorityQueue
|
||||||
|
inProgressTasks map[string]*InProgressTask
|
||||||
|
volumeReservations map[uint32]*VolumeReservation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Worker Selection Criteria:
|
||||||
|
// 1. Has required capability (EC or Vacuum)
|
||||||
|
// 2. Available capacity (CurrentLoad < MaxConcurrent)
|
||||||
|
// 3. Best performance history for task type
|
||||||
|
// 4. Lowest current load
|
||||||
|
// 5. Geographically close to volume server (optional)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. Worker Process Design
|
||||||
|
|
||||||
|
### 2.1 Worker Architecture
|
||||||
|
|
||||||
|
```go
|
||||||
|
type MaintenanceWorker struct {
|
||||||
|
id string
|
||||||
|
config *WorkerConfig
|
||||||
|
adminClient AdminClient
|
||||||
|
taskExecutors map[TaskType]TaskExecutor
|
||||||
|
currentTasks map[string]*RunningTask
|
||||||
|
registry *TaskRegistry
|
||||||
|
heartbeatTicker *time.Ticker
|
||||||
|
requestTicker *time.Ticker
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.2 Task Execution Framework
|
||||||
|
|
||||||
|
```go
|
||||||
|
type TaskExecutor interface {
|
||||||
|
Execute(ctx context.Context, task *Task) error
|
||||||
|
EstimateTime(task *Task) time.Duration
|
||||||
|
ValidateResources(task *Task) error
|
||||||
|
GetProgress() float64
|
||||||
|
Cancel() error
|
||||||
|
}
|
||||||
|
|
||||||
|
type ErasureCodingExecutor struct {
|
||||||
|
volumeClient VolumeServerClient
|
||||||
|
progress float64
|
||||||
|
cancelled bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type VacuumExecutor struct {
|
||||||
|
volumeClient VolumeServerClient
|
||||||
|
progress float64
|
||||||
|
cancelled bool
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2.3 Worker Capabilities & Registration
|
||||||
|
|
||||||
|
```go
|
||||||
|
type WorkerCapabilities struct {
|
||||||
|
SupportedTasks []TaskType
|
||||||
|
MaxConcurrent int
|
||||||
|
ResourceLimits ResourceLimits
|
||||||
|
PreferredServers []string // Affinity for specific volume servers
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResourceLimits struct {
|
||||||
|
MaxMemoryMB int64
|
||||||
|
MaxDiskSpaceMB int64
|
||||||
|
MaxNetworkMbps int64
|
||||||
|
MaxCPUPercent float64
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. Task Lifecycle Management
|
||||||
|
|
||||||
|
### 3.1 Task States
|
||||||
|
|
||||||
|
```go
|
||||||
|
type TaskState string
|
||||||
|
|
||||||
|
const (
|
||||||
|
TaskStatePending TaskState = "pending"
|
||||||
|
TaskStateAssigned TaskState = "assigned"
|
||||||
|
TaskStateInProgress TaskState = "in_progress"
|
||||||
|
TaskStateCompleted TaskState = "completed"
|
||||||
|
TaskStateFailed TaskState = "failed"
|
||||||
|
TaskStateCancelled TaskState = "cancelled"
|
||||||
|
TaskStateStuck TaskState = "stuck" // Taking too long
|
||||||
|
TaskStateDuplicate TaskState = "duplicate" // Detected duplicate
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3.2 Progress Tracking & Monitoring
|
||||||
|
|
||||||
|
```go
|
||||||
|
type InProgressTask struct {
|
||||||
|
Task *Task
|
||||||
|
WorkerID string
|
||||||
|
StartedAt time.Time
|
||||||
|
LastUpdate time.Time
|
||||||
|
Progress float64
|
||||||
|
EstimatedEnd time.Time
|
||||||
|
VolumeReserved bool // Reserved for capacity planning
|
||||||
|
}
|
||||||
|
|
||||||
|
type TaskMonitor struct {
|
||||||
|
inProgressTasks map[string]*InProgressTask
|
||||||
|
timeoutChecker *time.Ticker
|
||||||
|
stuckDetector *time.Ticker
|
||||||
|
duplicateChecker *time.Ticker
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. Volume Capacity Reconciliation
|
||||||
|
|
||||||
|
### 4.1 Volume State Tracking
|
||||||
|
|
||||||
|
```go
|
||||||
|
type VolumeStateManager struct {
|
||||||
|
masterClient MasterClient
|
||||||
|
inProgressTasks map[uint32]*InProgressTask // VolumeID -> Task
|
||||||
|
committedChanges map[uint32]*VolumeChange // Changes not yet in master
|
||||||
|
reconcileInterval time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
type VolumeChange struct {
|
||||||
|
VolumeID uint32
|
||||||
|
ChangeType ChangeType // "ec_encoding", "vacuum_completed"
|
||||||
|
OldCapacity int64
|
||||||
|
NewCapacity int64
|
||||||
|
TaskID string
|
||||||
|
CompletedAt time.Time
|
||||||
|
ReportedToMaster bool
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 Shard Assignment Integration
|
||||||
|
|
||||||
|
When the master needs to assign shards, it must consider:
|
||||||
|
1. **Current volume state** from its own records
|
||||||
|
2. **In-progress capacity changes** from admin server
|
||||||
|
3. **Committed but unreported changes** from admin server
|
||||||
|
|
||||||
|
```go
|
||||||
|
type CapacityOracle struct {
|
||||||
|
adminServer AdminServerClient
|
||||||
|
masterState *MasterVolumeState
|
||||||
|
updateFreq time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *CapacityOracle) GetAdjustedCapacity(volumeID uint32) int64 {
|
||||||
|
baseCapacity := o.masterState.GetCapacity(volumeID)
|
||||||
|
|
||||||
|
// Adjust for in-progress tasks
|
||||||
|
if task := o.adminServer.GetInProgressTask(volumeID); task != nil {
|
||||||
|
switch task.Type {
|
||||||
|
case TaskTypeErasureCoding:
|
||||||
|
// EC reduces effective capacity
|
||||||
|
return baseCapacity / 2 // Simplified
|
||||||
|
case TaskTypeVacuum:
|
||||||
|
// Vacuum may increase available space
|
||||||
|
return baseCapacity + int64(float64(baseCapacity) * 0.3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust for completed but unreported changes
|
||||||
|
if change := o.adminServer.GetPendingChange(volumeID); change != nil {
|
||||||
|
return change.NewCapacity
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseCapacity
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5. Error Handling & Recovery
|
||||||
|
|
||||||
|
### 5.1 Worker Failure Scenarios
|
||||||
|
|
||||||
|
```go
|
||||||
|
type FailureHandler struct {
|
||||||
|
taskRescheduler *TaskRescheduler
|
||||||
|
workerMonitor *WorkerMonitor
|
||||||
|
alertManager *AlertManager
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failure Scenarios:
|
||||||
|
// 1. Worker becomes unresponsive (heartbeat timeout)
|
||||||
|
// 2. Task execution fails (reported by worker)
|
||||||
|
// 3. Task gets stuck (progress timeout)
|
||||||
|
// 4. Duplicate task detection
|
||||||
|
// 5. Resource exhaustion
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5.2 Recovery Strategies
|
||||||
|
|
||||||
|
**Worker Timeout Recovery**:
|
||||||
|
- Mark worker as inactive after 3 missed heartbeats
|
||||||
|
- Reschedule all assigned tasks to other workers
|
||||||
|
- Cleanup any partial state
|
||||||
|
|
||||||
|
**Task Stuck Recovery**:
|
||||||
|
- Detect tasks with no progress for > 2x estimated time
|
||||||
|
- Cancel stuck task and mark volume for cleanup
|
||||||
|
- Reschedule if retry count < max_retries
|
||||||
|
|
||||||
|
**Duplicate Task Prevention**:
|
||||||
|
```go
|
||||||
|
type DuplicateDetector struct {
|
||||||
|
activeFingerprints map[string]bool // VolumeID+TaskType
|
||||||
|
recentCompleted *LRUCache // Recently completed tasks
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DuplicateDetector) IsTaskDuplicate(task *Task) bool {
|
||||||
|
fingerprint := fmt.Sprintf("%d-%s", task.VolumeID, task.Type)
|
||||||
|
return d.activeFingerprints[fingerprint] ||
|
||||||
|
d.recentCompleted.Contains(fingerprint)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 6. Simulation & Testing Framework
|
||||||
|
|
||||||
|
### 6.1 Failure Simulation
|
||||||
|
|
||||||
|
```go
|
||||||
|
type TaskSimulator struct {
|
||||||
|
scenarios map[string]SimulationScenario
|
||||||
|
}
|
||||||
|
|
||||||
|
type SimulationScenario struct {
|
||||||
|
Name string
|
||||||
|
WorkerCount int
|
||||||
|
VolumeCount int
|
||||||
|
FailurePatterns []FailurePattern
|
||||||
|
Duration time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
type FailurePattern struct {
|
||||||
|
Type FailureType // "worker_timeout", "task_stuck", "duplicate"
|
||||||
|
Probability float64 // 0.0 to 1.0
|
||||||
|
Timing TimingSpec // When during task execution
|
||||||
|
Duration time.Duration
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6.2 Test Scenarios
|
||||||
|
|
||||||
|
**Scenario 1: Worker Timeout During EC**
|
||||||
|
- Start EC task on 30GB volume
|
||||||
|
- Kill worker at 50% progress
|
||||||
|
- Verify task reassignment
|
||||||
|
- Verify no duplicate EC operations
|
||||||
|
|
||||||
|
**Scenario 2: Stuck Vacuum Task**
|
||||||
|
- Start vacuum on high-garbage volume
|
||||||
|
- Simulate worker hanging at 75% progress
|
||||||
|
- Verify timeout detection and cleanup
|
||||||
|
- Verify volume state consistency
|
||||||
|
|
||||||
|
**Scenario 3: Duplicate Task Prevention**
|
||||||
|
- Submit same EC task from multiple sources
|
||||||
|
- Verify only one task executes
|
||||||
|
- Verify proper conflict resolution
|
||||||
|
|
||||||
|
**Scenario 4: Master-Admin State Divergence**
|
||||||
|
- Create in-progress EC task
|
||||||
|
- Simulate master restart
|
||||||
|
- Verify state reconciliation
|
||||||
|
- Verify shard assignment accounts for in-progress work
|
||||||
|
|
||||||
|
## 7. Performance & Scalability
|
||||||
|
|
||||||
|
### 7.1 Metrics & Monitoring
|
||||||
|
|
||||||
|
```go
|
||||||
|
type SystemMetrics struct {
|
||||||
|
TasksPerSecond float64
|
||||||
|
WorkerUtilization float64
|
||||||
|
AverageTaskTime time.Duration
|
||||||
|
FailureRate float64
|
||||||
|
QueueDepth int
|
||||||
|
VolumeStatesSync bool
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7.2 Scalability Considerations
|
||||||
|
|
||||||
|
- **Horizontal Worker Scaling**: Add workers without admin server changes
|
||||||
|
- **Admin Server HA**: Master-slave admin servers for fault tolerance
|
||||||
|
- **Task Partitioning**: Partition tasks by collection or datacenter
|
||||||
|
- **Batch Operations**: Group similar tasks for efficiency
|
||||||
|
|
||||||
|
## 8. Implementation Plan
|
||||||
|
|
||||||
|
### Phase 1: Core Infrastructure
|
||||||
|
1. Admin server basic framework
|
||||||
|
2. Worker registration and heartbeat
|
||||||
|
3. Simple task assignment
|
||||||
|
4. Basic progress tracking
|
||||||
|
|
||||||
|
### Phase 2: Advanced Features
|
||||||
|
1. Volume state reconciliation
|
||||||
|
2. Sophisticated worker selection
|
||||||
|
3. Failure detection and recovery
|
||||||
|
4. Duplicate prevention
|
||||||
|
|
||||||
|
### Phase 3: Optimization & Monitoring
|
||||||
|
1. Performance metrics
|
||||||
|
2. Load balancing algorithms
|
||||||
|
3. Capacity planning integration
|
||||||
|
4. Comprehensive monitoring
|
||||||
|
|
||||||
|
This design provides a robust, scalable foundation for distributed task management in SeaweedFS while maintaining consistency with the existing architecture patterns.
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
# Install required packages
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
ca-certificates \
|
||||||
|
fuse \
|
||||||
|
curl \
|
||||||
|
jq
|
||||||
|
|
||||||
|
# Copy our locally built binary
|
||||||
|
COPY weed-local /usr/bin/weed
|
||||||
|
RUN chmod +x /usr/bin/weed
|
||||||
|
|
||||||
|
# Create working directory
|
||||||
|
WORKDIR /data
|
||||||
|
|
||||||
|
# Default command
|
||||||
|
ENTRYPOINT ["/usr/bin/weed"]
|
||||||
@@ -0,0 +1,438 @@
|
|||||||
|
# SeaweedFS EC Worker Testing Environment
|
||||||
|
|
||||||
|
This Docker Compose setup provides a comprehensive testing environment for SeaweedFS Erasure Coding (EC) workers using **official SeaweedFS commands**.
|
||||||
|
|
||||||
|
## 📂 Directory Structure
|
||||||
|
|
||||||
|
The testing environment is located in `docker/admin_integration/` and includes:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker/admin_integration/
|
||||||
|
├── Makefile # Main management interface
|
||||||
|
├── docker-compose-ec-test.yml # Docker compose configuration
|
||||||
|
├── EC-TESTING-README.md # This documentation
|
||||||
|
└── run-ec-test.sh # Quick start script
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🏗️ Architecture
|
||||||
|
|
||||||
|
The testing environment uses **official SeaweedFS commands** and includes:
|
||||||
|
|
||||||
|
- **1 Master Server** (port 9333) - Coordinates the cluster with 50MB volume size limit
|
||||||
|
- **6 Volume Servers** (ports 8080-8085) - Distributed across 2 data centers and 3 racks for diversity
|
||||||
|
- **1 Filer** (port 8888) - Provides file system interface
|
||||||
|
- **1 Admin Server** (port 23646) - Detects volumes needing EC and manages workers using official `admin` command
|
||||||
|
- **3 EC Workers** - Execute erasure coding tasks using official `worker` command with task-specific working directories
|
||||||
|
- **1 Load Generator** - Continuously writes and deletes files using SeaweedFS shell commands
|
||||||
|
- **1 Monitor** - Tracks cluster health and EC progress using shell scripts
|
||||||
|
|
||||||
|
## ✨ New Features
|
||||||
|
|
||||||
|
### **Task-Specific Working Directories**
|
||||||
|
Each worker now creates dedicated subdirectories for different task types:
|
||||||
|
- `/work/erasure_coding/` - For EC encoding tasks
|
||||||
|
- `/work/vacuum/` - For vacuum cleanup tasks
|
||||||
|
- `/work/balance/` - For volume balancing tasks
|
||||||
|
|
||||||
|
This provides:
|
||||||
|
- **Organization**: Each task type gets isolated working space
|
||||||
|
- **Debugging**: Easy to find files/logs related to specific task types
|
||||||
|
- **Cleanup**: Can clean up task-specific artifacts easily
|
||||||
|
- **Concurrent Safety**: Different task types won't interfere with each other's files
|
||||||
|
|
||||||
|
## 🚀 Quick Start
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- Docker and Docker Compose installed
|
||||||
|
- GNU Make installed
|
||||||
|
- At least 4GB RAM available for containers
|
||||||
|
- Ports 8080-8085, 8888, 9333, 23646 available
|
||||||
|
|
||||||
|
### Start the Environment
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Navigate to the admin integration directory
|
||||||
|
cd docker/admin_integration/
|
||||||
|
|
||||||
|
# Show available commands
|
||||||
|
make help
|
||||||
|
|
||||||
|
# Start the complete testing environment
|
||||||
|
make start
|
||||||
|
```
|
||||||
|
|
||||||
|
The `make start` command will:
|
||||||
|
1. Start all services using official SeaweedFS images
|
||||||
|
2. Configure workers with task-specific working directories
|
||||||
|
3. Wait for services to be ready
|
||||||
|
4. Display monitoring URLs and run health checks
|
||||||
|
|
||||||
|
### Alternative Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Quick start aliases
|
||||||
|
make up # Same as 'make start'
|
||||||
|
|
||||||
|
# Development mode (higher load for faster testing)
|
||||||
|
make dev-start
|
||||||
|
|
||||||
|
# Build images without starting
|
||||||
|
make build
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📋 Available Make Targets
|
||||||
|
|
||||||
|
Run `make help` to see all available targets:
|
||||||
|
|
||||||
|
### **🚀 Main Operations**
|
||||||
|
- `make start` - Start the complete EC testing environment
|
||||||
|
- `make stop` - Stop all services
|
||||||
|
- `make restart` - Restart all services
|
||||||
|
- `make clean` - Complete cleanup (containers, volumes, images)
|
||||||
|
|
||||||
|
### **📊 Monitoring & Status**
|
||||||
|
- `make health` - Check health of all services
|
||||||
|
- `make status` - Show status of all containers
|
||||||
|
- `make urls` - Display all monitoring URLs
|
||||||
|
- `make monitor` - Open monitor dashboard in browser
|
||||||
|
- `make monitor-status` - Show monitor status via API
|
||||||
|
- `make volume-status` - Show volume status from master
|
||||||
|
- `make admin-status` - Show admin server status
|
||||||
|
- `make cluster-status` - Show complete cluster status
|
||||||
|
|
||||||
|
### **📋 Logs Management**
|
||||||
|
- `make logs` - Show logs from all services
|
||||||
|
- `make logs-admin` - Show admin server logs
|
||||||
|
- `make logs-workers` - Show all worker logs
|
||||||
|
- `make logs-worker1/2/3` - Show specific worker logs
|
||||||
|
- `make logs-load` - Show load generator logs
|
||||||
|
- `make logs-monitor` - Show monitor logs
|
||||||
|
- `make backup-logs` - Backup all logs to files
|
||||||
|
|
||||||
|
### **⚖️ Scaling & Testing**
|
||||||
|
- `make scale-workers WORKERS=5` - Scale workers to 5 instances
|
||||||
|
- `make scale-load RATE=25` - Increase load generation rate
|
||||||
|
- `make test-ec` - Run focused EC test scenario
|
||||||
|
|
||||||
|
### **🔧 Development & Debug**
|
||||||
|
- `make shell-admin` - Open shell in admin container
|
||||||
|
- `make shell-worker1` - Open shell in worker container
|
||||||
|
- `make debug` - Show debug information
|
||||||
|
- `make troubleshoot` - Run troubleshooting checks
|
||||||
|
|
||||||
|
## 📊 Monitoring URLs
|
||||||
|
|
||||||
|
| Service | URL | Description |
|
||||||
|
|---------|-----|-------------|
|
||||||
|
| Master UI | http://localhost:9333 | Cluster status and topology |
|
||||||
|
| Filer | http://localhost:8888 | File operations |
|
||||||
|
| Admin Server | http://localhost:9900/status | Task management |
|
||||||
|
| Monitor | http://localhost:9999/status | Complete cluster monitoring |
|
||||||
|
| Volume Servers | http://localhost:8080-8085/status | Individual volume server stats |
|
||||||
|
|
||||||
|
Quick access: `make urls` or `make monitor`
|
||||||
|
|
||||||
|
## 🔄 How EC Testing Works
|
||||||
|
|
||||||
|
### 1. Continuous Load Generation
|
||||||
|
- **Write Rate**: 10 files/second (1-5MB each)
|
||||||
|
- **Delete Rate**: 2 files/second
|
||||||
|
- **Target**: Fill volumes to 50MB limit quickly
|
||||||
|
|
||||||
|
### 2. Volume Detection
|
||||||
|
- Admin server scans master every 30 seconds
|
||||||
|
- Identifies volumes >40MB (80% of 50MB limit)
|
||||||
|
- Queues EC tasks for eligible volumes
|
||||||
|
|
||||||
|
### 3. EC Worker Assignment
|
||||||
|
- **Worker 1**: EC specialist (max 2 concurrent tasks)
|
||||||
|
- **Worker 2**: EC + Vacuum hybrid (max 2 concurrent tasks)
|
||||||
|
- **Worker 3**: EC + Vacuum hybrid (max 1 concurrent task)
|
||||||
|
|
||||||
|
### 4. Comprehensive EC Process
|
||||||
|
Each EC task follows 6 phases:
|
||||||
|
1. **Copy Volume Data** (5-15%) - Stream .dat/.idx files locally
|
||||||
|
2. **Mark Read-Only** (20-25%) - Ensure data consistency
|
||||||
|
3. **Local Encoding** (30-60%) - Create 14 shards (10+4 Reed-Solomon)
|
||||||
|
4. **Calculate Placement** (65-70%) - Smart rack-aware distribution
|
||||||
|
5. **Distribute Shards** (75-90%) - Upload to optimal servers
|
||||||
|
6. **Verify & Cleanup** (95-100%) - Validate and clean temporary files
|
||||||
|
|
||||||
|
### 5. Real-Time Monitoring
|
||||||
|
- Volume analysis and EC candidate detection
|
||||||
|
- Worker health and task progress
|
||||||
|
- No data loss verification
|
||||||
|
- Performance metrics
|
||||||
|
|
||||||
|
## 📋 Key Features Tested
|
||||||
|
|
||||||
|
### ✅ EC Implementation Features
|
||||||
|
- [x] Local volume data copying with progress tracking
|
||||||
|
- [x] Local Reed-Solomon encoding (10+4 shards)
|
||||||
|
- [x] Intelligent shard placement with rack awareness
|
||||||
|
- [x] Load balancing across available servers
|
||||||
|
- [x] Backup server selection for redundancy
|
||||||
|
- [x] Detailed step-by-step progress tracking
|
||||||
|
- [x] Comprehensive error handling and recovery
|
||||||
|
|
||||||
|
### ✅ Infrastructure Features
|
||||||
|
- [x] Multi-datacenter topology (dc1, dc2)
|
||||||
|
- [x] Rack diversity (rack1, rack2, rack3)
|
||||||
|
- [x] Volume size limits (50MB)
|
||||||
|
- [x] Worker capability matching
|
||||||
|
- [x] Health monitoring and alerting
|
||||||
|
- [x] Continuous workload simulation
|
||||||
|
|
||||||
|
## 🛠️ Common Usage Patterns
|
||||||
|
|
||||||
|
### Basic Testing Workflow
|
||||||
|
```bash
|
||||||
|
# Start environment
|
||||||
|
make start
|
||||||
|
|
||||||
|
# Watch progress
|
||||||
|
make monitor-status
|
||||||
|
|
||||||
|
# Check for EC candidates
|
||||||
|
make volume-status
|
||||||
|
|
||||||
|
# View worker activity
|
||||||
|
make logs-workers
|
||||||
|
|
||||||
|
# Stop when done
|
||||||
|
make stop
|
||||||
|
```
|
||||||
|
|
||||||
|
### High-Load Testing
|
||||||
|
```bash
|
||||||
|
# Start with higher load
|
||||||
|
make dev-start
|
||||||
|
|
||||||
|
# Scale up workers and load
|
||||||
|
make scale-workers WORKERS=5
|
||||||
|
make scale-load RATE=50
|
||||||
|
|
||||||
|
# Monitor intensive EC activity
|
||||||
|
make logs-admin
|
||||||
|
```
|
||||||
|
|
||||||
|
### Debugging Issues
|
||||||
|
```bash
|
||||||
|
# Check port conflicts and system state
|
||||||
|
make troubleshoot
|
||||||
|
|
||||||
|
# View specific service logs
|
||||||
|
make logs-admin
|
||||||
|
make logs-worker1
|
||||||
|
|
||||||
|
# Get shell access for debugging
|
||||||
|
make shell-admin
|
||||||
|
make shell-worker1
|
||||||
|
|
||||||
|
# Check detailed status
|
||||||
|
make debug
|
||||||
|
```
|
||||||
|
|
||||||
|
### Development Iteration
|
||||||
|
```bash
|
||||||
|
# Quick restart after code changes
|
||||||
|
make restart
|
||||||
|
|
||||||
|
# Rebuild and restart
|
||||||
|
make clean
|
||||||
|
make start
|
||||||
|
|
||||||
|
# Monitor specific components
|
||||||
|
make logs-monitor
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📈 Expected Results
|
||||||
|
|
||||||
|
### Successful EC Testing Shows:
|
||||||
|
1. **Volume Growth**: Steady increase in volume sizes toward 50MB limit
|
||||||
|
2. **EC Detection**: Admin server identifies volumes >40MB for EC
|
||||||
|
3. **Task Assignment**: Workers receive and execute EC tasks
|
||||||
|
4. **Shard Distribution**: 14 shards distributed across 6 volume servers
|
||||||
|
5. **No Data Loss**: All files remain accessible during and after EC
|
||||||
|
6. **Performance**: EC tasks complete within estimated timeframes
|
||||||
|
|
||||||
|
### Sample Monitor Output:
|
||||||
|
```bash
|
||||||
|
# Check current status
|
||||||
|
make monitor-status
|
||||||
|
|
||||||
|
# Output example:
|
||||||
|
{
|
||||||
|
"monitor": {
|
||||||
|
"uptime": "15m30s",
|
||||||
|
"master_addr": "master:9333",
|
||||||
|
"admin_addr": "admin:9900"
|
||||||
|
},
|
||||||
|
"stats": {
|
||||||
|
"VolumeCount": 12,
|
||||||
|
"ECTasksDetected": 3,
|
||||||
|
"WorkersActive": 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 Configuration
|
||||||
|
|
||||||
|
### Environment Variables
|
||||||
|
|
||||||
|
You can customize the environment by setting variables:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# High load testing
|
||||||
|
WRITE_RATE=25 DELETE_RATE=5 make start
|
||||||
|
|
||||||
|
# Extended test duration
|
||||||
|
TEST_DURATION=7200 make start # 2 hours
|
||||||
|
```
|
||||||
|
|
||||||
|
### Scaling Examples
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Scale workers
|
||||||
|
make scale-workers WORKERS=6
|
||||||
|
|
||||||
|
# Increase load generation
|
||||||
|
make scale-load RATE=30
|
||||||
|
|
||||||
|
# Combined scaling
|
||||||
|
make scale-workers WORKERS=4
|
||||||
|
make scale-load RATE=40
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🧹 Cleanup Options
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Stop services only
|
||||||
|
make stop
|
||||||
|
|
||||||
|
# Remove containers but keep volumes
|
||||||
|
make down
|
||||||
|
|
||||||
|
# Remove data volumes only
|
||||||
|
make clean-volumes
|
||||||
|
|
||||||
|
# Remove built images only
|
||||||
|
make clean-images
|
||||||
|
|
||||||
|
# Complete cleanup (everything)
|
||||||
|
make clean
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🐛 Troubleshooting
|
||||||
|
|
||||||
|
### Quick Diagnostics
|
||||||
|
```bash
|
||||||
|
# Run complete troubleshooting
|
||||||
|
make troubleshoot
|
||||||
|
|
||||||
|
# Check specific components
|
||||||
|
make health
|
||||||
|
make debug
|
||||||
|
make status
|
||||||
|
```
|
||||||
|
|
||||||
|
### Common Issues
|
||||||
|
|
||||||
|
**Services not starting:**
|
||||||
|
```bash
|
||||||
|
# Check port availability
|
||||||
|
make troubleshoot
|
||||||
|
|
||||||
|
# View startup logs
|
||||||
|
make logs-master
|
||||||
|
make logs-admin
|
||||||
|
```
|
||||||
|
|
||||||
|
**No EC tasks being created:**
|
||||||
|
```bash
|
||||||
|
# Check volume status
|
||||||
|
make volume-status
|
||||||
|
|
||||||
|
# Increase load to fill volumes faster
|
||||||
|
make scale-load RATE=30
|
||||||
|
|
||||||
|
# Check admin detection
|
||||||
|
make logs-admin
|
||||||
|
```
|
||||||
|
|
||||||
|
**Workers not responding:**
|
||||||
|
```bash
|
||||||
|
# Check worker registration
|
||||||
|
make admin-status
|
||||||
|
|
||||||
|
# View worker logs
|
||||||
|
make logs-workers
|
||||||
|
|
||||||
|
# Restart workers
|
||||||
|
make restart
|
||||||
|
```
|
||||||
|
|
||||||
|
### Performance Tuning
|
||||||
|
|
||||||
|
**For faster testing:**
|
||||||
|
```bash
|
||||||
|
make dev-start # Higher default load
|
||||||
|
make scale-load RATE=50 # Very high load
|
||||||
|
```
|
||||||
|
|
||||||
|
**For stress testing:**
|
||||||
|
```bash
|
||||||
|
make scale-workers WORKERS=8
|
||||||
|
make scale-load RATE=100
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📚 Technical Details
|
||||||
|
|
||||||
|
### Network Architecture
|
||||||
|
- Custom bridge network (172.20.0.0/16)
|
||||||
|
- Service discovery via container names
|
||||||
|
- Health checks for all services
|
||||||
|
|
||||||
|
### Storage Layout
|
||||||
|
- Each volume server: max 100 volumes
|
||||||
|
- Data centers: dc1, dc2
|
||||||
|
- Racks: rack1, rack2, rack3
|
||||||
|
- Volume limit: 50MB per volume
|
||||||
|
|
||||||
|
### EC Algorithm
|
||||||
|
- Reed-Solomon RS(10,4)
|
||||||
|
- 10 data shards + 4 parity shards
|
||||||
|
- Rack-aware distribution
|
||||||
|
- Backup server redundancy
|
||||||
|
|
||||||
|
### Make Integration
|
||||||
|
- Color-coded output for better readability
|
||||||
|
- Comprehensive help system (`make help`)
|
||||||
|
- Parallel execution support
|
||||||
|
- Error handling and cleanup
|
||||||
|
- Cross-platform compatibility
|
||||||
|
|
||||||
|
## 🎯 Quick Reference
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Essential commands
|
||||||
|
make help # Show all available targets
|
||||||
|
make start # Start complete environment
|
||||||
|
make health # Check all services
|
||||||
|
make monitor # Open dashboard
|
||||||
|
make logs-admin # View admin activity
|
||||||
|
make clean # Complete cleanup
|
||||||
|
|
||||||
|
# Monitoring
|
||||||
|
make volume-status # Check for EC candidates
|
||||||
|
make admin-status # Check task queue
|
||||||
|
make monitor-status # Full cluster status
|
||||||
|
|
||||||
|
# Scaling & Testing
|
||||||
|
make test-ec # Run focused EC test
|
||||||
|
make scale-load RATE=X # Increase load
|
||||||
|
make troubleshoot # Diagnose issues
|
||||||
|
```
|
||||||
|
|
||||||
|
This environment provides a realistic testing scenario for SeaweedFS EC workers with actual data operations, comprehensive monitoring, and easy management through Make targets.
|
||||||
@@ -0,0 +1,346 @@
|
|||||||
|
# SeaweedFS Admin Integration Test Makefile
|
||||||
|
# Tests the admin server and worker functionality using official weed commands
|
||||||
|
|
||||||
|
.PHONY: help build build-and-restart restart-workers start stop restart logs clean status test admin-ui worker-logs master-logs admin-logs vacuum-test vacuum-demo vacuum-status vacuum-data vacuum-data-high vacuum-data-low vacuum-continuous vacuum-clean vacuum-help
|
||||||
|
.DEFAULT_GOAL := help
|
||||||
|
|
||||||
|
COMPOSE_FILE := docker-compose-ec-test.yml
|
||||||
|
PROJECT_NAME := admin_integration
|
||||||
|
|
||||||
|
build: ## Build SeaweedFS with latest changes and create Docker image
|
||||||
|
@echo "🔨 Building SeaweedFS with latest changes..."
|
||||||
|
@echo "1️⃣ Generating admin templates..."
|
||||||
|
@cd ../../ && make admin-generate
|
||||||
|
@echo "2️⃣ Building Docker image with latest changes..."
|
||||||
|
@cd ../ && make build
|
||||||
|
@echo "3️⃣ Copying binary for local docker-compose..."
|
||||||
|
@cp ../weed ./weed-local
|
||||||
|
@echo "✅ Build complete! Updated image: chrislusf/seaweedfs:local"
|
||||||
|
@echo "💡 Run 'make restart' to apply changes to running services"
|
||||||
|
|
||||||
|
build-and-restart: build ## Build with latest changes and restart services
|
||||||
|
@echo "🔄 Recreating services with new image..."
|
||||||
|
@echo "1️⃣ Recreating admin server with new image..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) up -d admin
|
||||||
|
@sleep 5
|
||||||
|
@echo "2️⃣ Recreating workers to reconnect..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) up -d worker1 worker2 worker3
|
||||||
|
@echo "✅ All services recreated with latest changes!"
|
||||||
|
@echo "🌐 Admin UI: http://localhost:23646/"
|
||||||
|
@echo "💡 Workers will reconnect to the new admin server"
|
||||||
|
|
||||||
|
restart-workers: ## Restart all workers to reconnect to admin server
|
||||||
|
@echo "🔄 Restarting workers to reconnect to admin server..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) restart worker1 worker2 worker3
|
||||||
|
@echo "✅ Workers restarted and will reconnect to admin server"
|
||||||
|
|
||||||
|
help: ## Show this help message
|
||||||
|
@echo "SeaweedFS Admin Integration Test"
|
||||||
|
@echo "================================"
|
||||||
|
@echo "Tests admin server task distribution to workers using official weed commands"
|
||||||
|
@echo ""
|
||||||
|
@echo "🏗️ Cluster Management:"
|
||||||
|
@grep -E '^(start|stop|restart|clean|status|build):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-18s %s\n", $$1, $$2}'
|
||||||
|
@echo ""
|
||||||
|
@echo "🧪 Testing:"
|
||||||
|
@grep -E '^(test|demo|validate|quick-test):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-18s %s\n", $$1, $$2}'
|
||||||
|
@echo ""
|
||||||
|
@echo "🗑️ Vacuum Testing:"
|
||||||
|
@grep -E '^vacuum-.*:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-18s %s\n", $$1, $$2}'
|
||||||
|
@echo ""
|
||||||
|
@echo "📜 Monitoring:"
|
||||||
|
@grep -E '^(logs|admin-logs|worker-logs|master-logs|admin-ui):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-18s %s\n", $$1, $$2}'
|
||||||
|
@echo ""
|
||||||
|
@echo "🚀 Quick Start:"
|
||||||
|
@echo " make start # Start cluster"
|
||||||
|
@echo " make vacuum-test # Test vacuum tasks"
|
||||||
|
@echo " make vacuum-help # Vacuum testing guide"
|
||||||
|
@echo ""
|
||||||
|
@echo "💡 For detailed vacuum testing: make vacuum-help"
|
||||||
|
|
||||||
|
start: ## Start the complete SeaweedFS cluster with admin and workers
|
||||||
|
@echo "🚀 Starting SeaweedFS cluster with admin and workers..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) up -d
|
||||||
|
@echo "✅ Cluster started!"
|
||||||
|
@echo ""
|
||||||
|
@echo "📊 Access points:"
|
||||||
|
@echo " • Admin UI: http://localhost:23646/"
|
||||||
|
@echo " • Master UI: http://localhost:9333/"
|
||||||
|
@echo " • Filer: http://localhost:8888/"
|
||||||
|
@echo ""
|
||||||
|
@echo "📈 Services starting up..."
|
||||||
|
@echo " • Master server: ✓"
|
||||||
|
@echo " • Volume servers: Starting (6 servers)..."
|
||||||
|
@echo " • Filer: Starting..."
|
||||||
|
@echo " • Admin server: Starting..."
|
||||||
|
@echo " • Workers: Starting (3 workers)..."
|
||||||
|
@echo ""
|
||||||
|
@echo "⏳ Use 'make status' to check startup progress"
|
||||||
|
@echo "💡 Use 'make logs' to watch the startup process"
|
||||||
|
|
||||||
|
start-staged: ## Start services in proper order with delays
|
||||||
|
@echo "🚀 Starting SeaweedFS cluster in stages..."
|
||||||
|
@echo ""
|
||||||
|
@echo "Stage 1: Starting Master server..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) up -d master
|
||||||
|
@sleep 10
|
||||||
|
@echo ""
|
||||||
|
@echo "Stage 2: Starting Volume servers..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) up -d volume1 volume2 volume3 volume4 volume5 volume6
|
||||||
|
@sleep 15
|
||||||
|
@echo ""
|
||||||
|
@echo "Stage 3: Starting Filer..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) up -d filer
|
||||||
|
@sleep 10
|
||||||
|
@echo ""
|
||||||
|
@echo "Stage 4: Starting Admin server..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) up -d admin
|
||||||
|
@sleep 15
|
||||||
|
@echo ""
|
||||||
|
@echo "Stage 5: Starting Workers..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) up -d worker1 worker2 worker3
|
||||||
|
@sleep 10
|
||||||
|
@echo ""
|
||||||
|
@echo "Stage 6: Starting Load generator and Monitor..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) up -d load_generator monitor
|
||||||
|
@echo ""
|
||||||
|
@echo "✅ All services started!"
|
||||||
|
@echo ""
|
||||||
|
@echo "📊 Access points:"
|
||||||
|
@echo " • Admin UI: http://localhost:23646/"
|
||||||
|
@echo " • Master UI: http://localhost:9333/"
|
||||||
|
@echo " • Filer: http://localhost:8888/"
|
||||||
|
@echo ""
|
||||||
|
@echo "⏳ Services are initializing... Use 'make status' to check progress"
|
||||||
|
|
||||||
|
stop: ## Stop all services
|
||||||
|
@echo "🛑 Stopping SeaweedFS cluster..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) down
|
||||||
|
@echo "✅ Cluster stopped"
|
||||||
|
|
||||||
|
restart: stop start ## Restart the entire cluster
|
||||||
|
|
||||||
|
clean: ## Stop and remove all containers, networks, and volumes
|
||||||
|
@echo "🧹 Cleaning up SeaweedFS test environment..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) down -v --remove-orphans
|
||||||
|
@docker system prune -f
|
||||||
|
@rm -rf data/
|
||||||
|
@echo "✅ Environment cleaned"
|
||||||
|
|
||||||
|
status: ## Check the status of all services
|
||||||
|
@echo "📊 SeaweedFS Cluster Status"
|
||||||
|
@echo "=========================="
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) ps
|
||||||
|
@echo ""
|
||||||
|
@echo "📋 Service Health:"
|
||||||
|
@echo "Master:"
|
||||||
|
@curl -s http://localhost:9333/cluster/status | jq '.IsLeader' 2>/dev/null || echo " ❌ Master not ready"
|
||||||
|
@echo "Admin:"
|
||||||
|
@curl -s http://localhost:23646/ | grep -q "Admin" && echo " ✅ Admin ready" || echo " ❌ Admin not ready"
|
||||||
|
|
||||||
|
logs: ## Show logs from all services
|
||||||
|
@echo "📜 Following logs from all services..."
|
||||||
|
@echo "💡 Press Ctrl+C to stop following logs"
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) logs -f
|
||||||
|
|
||||||
|
admin-logs: ## Show logs from admin server only
|
||||||
|
@echo "📜 Admin server logs:"
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) logs -f admin
|
||||||
|
|
||||||
|
worker-logs: ## Show logs from all workers
|
||||||
|
@echo "📜 Worker logs:"
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) logs -f worker1 worker2 worker3
|
||||||
|
|
||||||
|
master-logs: ## Show logs from master server
|
||||||
|
@echo "📜 Master server logs:"
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) logs -f master
|
||||||
|
|
||||||
|
admin-ui: ## Open admin UI in browser (macOS)
|
||||||
|
@echo "🌐 Opening admin UI in browser..."
|
||||||
|
@open http://localhost:23646/ || echo "💡 Manually open: http://localhost:23646/"
|
||||||
|
|
||||||
|
test: ## Run integration test to verify task assignment and completion
|
||||||
|
@echo "🧪 Running Admin-Worker Integration Test"
|
||||||
|
@echo "========================================"
|
||||||
|
@echo ""
|
||||||
|
@echo "1️⃣ Checking cluster health..."
|
||||||
|
@sleep 5
|
||||||
|
@curl -s http://localhost:9333/cluster/status | jq '.IsLeader' > /dev/null && echo "✅ Master healthy" || echo "❌ Master not ready"
|
||||||
|
@curl -s http://localhost:23646/ | grep -q "Admin" && echo "✅ Admin healthy" || echo "❌ Admin not ready"
|
||||||
|
@echo ""
|
||||||
|
@echo "2️⃣ Checking worker registration..."
|
||||||
|
@sleep 10
|
||||||
|
@echo "💡 Check admin UI for connected workers: http://localhost:23646/"
|
||||||
|
@echo ""
|
||||||
|
@echo "3️⃣ Generating load to trigger EC tasks..."
|
||||||
|
@echo "📝 Creating test files to fill volumes..."
|
||||||
|
@echo "Creating large files with random data to trigger EC (targeting ~60MB total to exceed 50MB limit)..."
|
||||||
|
@for i in {1..12}; do \
|
||||||
|
echo "Creating 5MB random file $$i..."; \
|
||||||
|
docker run --rm --network admin_integration_seaweed_net -v /tmp:/tmp --entrypoint sh chrislusf/seaweedfs:local -c "dd if=/dev/urandom of=/tmp/largefile$$i.dat bs=1M count=5 2>/dev/null && weed upload -master=master:9333 /tmp/largefile$$i.dat && rm /tmp/largefile$$i.dat"; \
|
||||||
|
sleep 3; \
|
||||||
|
done
|
||||||
|
@echo ""
|
||||||
|
@echo "4️⃣ Waiting for volumes to process large files and reach 50MB limit..."
|
||||||
|
@echo "This may take a few minutes as we're uploading 60MB of data..."
|
||||||
|
@sleep 60
|
||||||
|
@echo ""
|
||||||
|
@echo "5️⃣ Checking for EC task creation and assignment..."
|
||||||
|
@echo "💡 Monitor the admin UI to see:"
|
||||||
|
@echo " • Tasks being created for volumes needing EC"
|
||||||
|
@echo " • Workers picking up tasks"
|
||||||
|
@echo " • Task progress (pending → running → completed)"
|
||||||
|
@echo " • EC shards being distributed"
|
||||||
|
@echo ""
|
||||||
|
@echo "✅ Integration test setup complete!"
|
||||||
|
@echo "📊 Monitor progress at: http://localhost:23646/"
|
||||||
|
|
||||||
|
quick-test: ## Quick verification that core services are running
|
||||||
|
@echo "⚡ Quick Health Check"
|
||||||
|
@echo "===================="
|
||||||
|
@echo "Master: $$(curl -s http://localhost:9333/cluster/status | jq -r '.IsLeader // "not ready"')"
|
||||||
|
@echo "Admin: $$(curl -s http://localhost:23646/ | grep -q "Admin" && echo "ready" || echo "not ready")"
|
||||||
|
@echo "Workers: $$(docker-compose -f $(COMPOSE_FILE) ps worker1 worker2 worker3 | grep -c Up) running"
|
||||||
|
|
||||||
|
validate: ## Validate integration test configuration
|
||||||
|
@echo "🔍 Validating Integration Test Configuration"
|
||||||
|
@echo "==========================================="
|
||||||
|
@chmod +x test-integration.sh
|
||||||
|
@./test-integration.sh
|
||||||
|
|
||||||
|
demo: start ## Start cluster and run demonstration
|
||||||
|
@echo "🎭 SeaweedFS Admin-Worker Demo"
|
||||||
|
@echo "============================="
|
||||||
|
@echo ""
|
||||||
|
@echo "⏳ Waiting for services to start..."
|
||||||
|
@sleep 45
|
||||||
|
@echo ""
|
||||||
|
@echo "🎯 Demo Overview:"
|
||||||
|
@echo " • 1 Master server (coordinates cluster)"
|
||||||
|
@echo " • 6 Volume servers (50MB volume limit)"
|
||||||
|
@echo " • 1 Admin server (task management)"
|
||||||
|
@echo " • 3 Workers (execute EC tasks)"
|
||||||
|
@echo " • Load generator (creates files continuously)"
|
||||||
|
@echo ""
|
||||||
|
@echo "📊 Watch the process:"
|
||||||
|
@echo " 1. Visit: http://localhost:23646/"
|
||||||
|
@echo " 2. Observe workers connecting"
|
||||||
|
@echo " 3. Watch tasks being created and assigned"
|
||||||
|
@echo " 4. See tasks progress from pending → completed"
|
||||||
|
@echo ""
|
||||||
|
@echo "🔄 The demo will:"
|
||||||
|
@echo " • Fill volumes to 50MB limit"
|
||||||
|
@echo " • Admin detects volumes needing EC"
|
||||||
|
@echo " • Workers receive and execute EC tasks"
|
||||||
|
@echo " • Tasks complete with shard distribution"
|
||||||
|
@echo ""
|
||||||
|
@echo "💡 Use 'make worker-logs' to see worker activity"
|
||||||
|
@echo "💡 Use 'make admin-logs' to see admin task management"
|
||||||
|
|
||||||
|
# Vacuum Testing Targets
|
||||||
|
vacuum-test: ## Create test data with garbage and verify vacuum detection
|
||||||
|
@echo "🧪 SeaweedFS Vacuum Task Testing"
|
||||||
|
@echo "================================"
|
||||||
|
@echo ""
|
||||||
|
@echo "1️⃣ Checking cluster health..."
|
||||||
|
@curl -s http://localhost:9333/cluster/status | jq '.IsLeader' > /dev/null && echo "✅ Master ready" || (echo "❌ Master not ready. Run 'make start' first." && exit 1)
|
||||||
|
@curl -s http://localhost:23646/ | grep -q "Admin" && echo "✅ Admin ready" || (echo "❌ Admin not ready. Run 'make start' first." && exit 1)
|
||||||
|
@echo ""
|
||||||
|
@echo "2️⃣ Creating test data with garbage..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) exec vacuum-tester go run create_vacuum_test_data.go -files=25 -delete=0.5 -size=200
|
||||||
|
@echo ""
|
||||||
|
@echo "3️⃣ Configuration Instructions:"
|
||||||
|
@echo " Visit: http://localhost:23646/maintenance/config/vacuum"
|
||||||
|
@echo " Set for testing:"
|
||||||
|
@echo " • Enable Vacuum Tasks: ✅ Checked"
|
||||||
|
@echo " • Garbage Threshold: 0.20 (20%)"
|
||||||
|
@echo " • Scan Interval: [30] [Seconds]"
|
||||||
|
@echo " • Min Volume Age: [0] [Minutes]"
|
||||||
|
@echo " • Max Concurrent: 2"
|
||||||
|
@echo ""
|
||||||
|
@echo "4️⃣ Monitor vacuum tasks at: http://localhost:23646/maintenance"
|
||||||
|
@echo ""
|
||||||
|
@echo "💡 Use 'make vacuum-status' to check volume garbage ratios"
|
||||||
|
|
||||||
|
vacuum-demo: ## Run automated vacuum testing demonstration
|
||||||
|
@echo "🎭 Vacuum Task Demo"
|
||||||
|
@echo "=================="
|
||||||
|
@echo ""
|
||||||
|
@echo "⚠️ This demo requires user interaction for configuration"
|
||||||
|
@echo "💡 Make sure cluster is running with 'make start'"
|
||||||
|
@echo ""
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) exec vacuum-tester sh -c "chmod +x demo_vacuum_testing.sh && ./demo_vacuum_testing.sh"
|
||||||
|
|
||||||
|
vacuum-status: ## Check current volume status and garbage ratios
|
||||||
|
@echo "📊 Current Volume Status"
|
||||||
|
@echo "======================="
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) exec vacuum-tester sh -c "chmod +x check_volumes.sh && ./check_volumes.sh"
|
||||||
|
|
||||||
|
vacuum-data: ## Create test data with configurable parameters
|
||||||
|
@echo "📁 Creating vacuum test data..."
|
||||||
|
@echo "Usage: make vacuum-data [FILES=20] [DELETE=0.4] [SIZE=100]"
|
||||||
|
@echo ""
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) exec vacuum-tester go run create_vacuum_test_data.go \
|
||||||
|
-files=$${FILES:-20} \
|
||||||
|
-delete=$${DELETE:-0.4} \
|
||||||
|
-size=$${SIZE:-100}
|
||||||
|
|
||||||
|
vacuum-data-high: ## Create high garbage ratio test data (should trigger vacuum)
|
||||||
|
@echo "📁 Creating high garbage test data (70% garbage)..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) exec vacuum-tester go run create_vacuum_test_data.go -files=30 -delete=0.7 -size=150
|
||||||
|
|
||||||
|
vacuum-data-low: ## Create low garbage ratio test data (should NOT trigger vacuum)
|
||||||
|
@echo "📁 Creating low garbage test data (15% garbage)..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) exec vacuum-tester go run create_vacuum_test_data.go -files=30 -delete=0.15 -size=150
|
||||||
|
|
||||||
|
vacuum-continuous: ## Generate garbage continuously for testing
|
||||||
|
@echo "🔄 Generating continuous garbage for vacuum testing..."
|
||||||
|
@echo "Creating 5 rounds of test data with 30-second intervals..."
|
||||||
|
@for i in {1..5}; do \
|
||||||
|
echo "Round $$i: Creating garbage..."; \
|
||||||
|
docker-compose -f $(COMPOSE_FILE) exec vacuum-tester go run create_vacuum_test_data.go -files=10 -delete=0.6 -size=100; \
|
||||||
|
echo "Waiting 30 seconds..."; \
|
||||||
|
sleep 30; \
|
||||||
|
done
|
||||||
|
@echo "✅ Continuous test complete. Check vacuum task activity!"
|
||||||
|
|
||||||
|
vacuum-clean: ## Clean up vacuum test data (removes all volumes!)
|
||||||
|
@echo "🧹 Cleaning up vacuum test data..."
|
||||||
|
@echo "⚠️ WARNING: This will delete ALL volumes!"
|
||||||
|
@read -p "Are you sure? (y/N): " confirm && [ "$$confirm" = "y" ] || exit 1
|
||||||
|
@echo "Stopping cluster..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) down
|
||||||
|
@echo "Removing volume data..."
|
||||||
|
@rm -rf data/volume*/
|
||||||
|
@echo "Restarting cluster..."
|
||||||
|
@docker-compose -f $(COMPOSE_FILE) up -d
|
||||||
|
@echo "✅ Clean up complete. Fresh volumes ready for testing."
|
||||||
|
|
||||||
|
vacuum-help: ## Show vacuum testing help and examples
|
||||||
|
@echo "🧪 Vacuum Testing Commands (Docker-based)"
|
||||||
|
@echo "=========================================="
|
||||||
|
@echo ""
|
||||||
|
@echo "Quick Start:"
|
||||||
|
@echo " make start # Start SeaweedFS cluster with vacuum-tester"
|
||||||
|
@echo " make vacuum-test # Create test data and instructions"
|
||||||
|
@echo " make vacuum-status # Check volume status"
|
||||||
|
@echo ""
|
||||||
|
@echo "Data Generation:"
|
||||||
|
@echo " make vacuum-data-high # High garbage (should trigger)"
|
||||||
|
@echo " make vacuum-data-low # Low garbage (should NOT trigger)"
|
||||||
|
@echo " make vacuum-continuous # Continuous garbage generation"
|
||||||
|
@echo ""
|
||||||
|
@echo "Monitoring:"
|
||||||
|
@echo " make vacuum-status # Quick volume status check"
|
||||||
|
@echo " make vacuum-demo # Full guided demonstration"
|
||||||
|
@echo ""
|
||||||
|
@echo "Configuration:"
|
||||||
|
@echo " Visit: http://localhost:23646/maintenance/config/vacuum"
|
||||||
|
@echo " Monitor: http://localhost:23646/maintenance"
|
||||||
|
@echo ""
|
||||||
|
@echo "Custom Parameters:"
|
||||||
|
@echo " make vacuum-data FILES=50 DELETE=0.8 SIZE=200"
|
||||||
|
@echo ""
|
||||||
|
@echo "💡 All commands now run inside Docker containers"
|
||||||
|
@echo "Documentation:"
|
||||||
|
@echo " See: VACUUM_TEST_README.md for complete guide"
|
||||||
Executable
+32
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "📊 Quick Volume Status Check"
|
||||||
|
echo "============================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check if master is running
|
||||||
|
MASTER_URL="${MASTER_HOST:-master:9333}"
|
||||||
|
if ! curl -s http://$MASTER_URL/cluster/status > /dev/null; then
|
||||||
|
echo "❌ Master server not available at $MASTER_URL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "🔍 Fetching volume status from master..."
|
||||||
|
curl -s "http://$MASTER_URL/vol/status" | jq -r '
|
||||||
|
if .Volumes and .Volumes.DataCenters then
|
||||||
|
.Volumes.DataCenters | to_entries[] | .value | to_entries[] | .value | to_entries[] | .value | if . then .[] else empty end |
|
||||||
|
"Volume \(.Id):
|
||||||
|
Size: \(.Size | if . < 1024 then "\(.) B" elif . < 1048576 then "\(. / 1024 | floor) KB" elif . < 1073741824 then "\(. / 1048576 * 100 | floor / 100) MB" else "\(. / 1073741824 * 100 | floor / 100) GB" end)
|
||||||
|
Files: \(.FileCount) active, \(.DeleteCount) deleted
|
||||||
|
Garbage: \(.DeletedByteCount | if . < 1024 then "\(.) B" elif . < 1048576 then "\(. / 1024 | floor) KB" elif . < 1073741824 then "\(. / 1048576 * 100 | floor / 100) MB" else "\(. / 1073741824 * 100 | floor / 100) GB" end) (\(if .Size > 0 then (.DeletedByteCount / .Size * 100 | floor) else 0 end)%)
|
||||||
|
Status: \(if (.DeletedByteCount / .Size * 100) > 30 then "🎯 NEEDS VACUUM" else "✅ OK" end)
|
||||||
|
"
|
||||||
|
else
|
||||||
|
"No volumes found"
|
||||||
|
end'
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "💡 Legend:"
|
||||||
|
echo " 🎯 NEEDS VACUUM: >30% garbage ratio"
|
||||||
|
echo " ✅ OK: <30% garbage ratio"
|
||||||
|
echo ""
|
||||||
@@ -0,0 +1,280 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
master = flag.String("master", "master:9333", "SeaweedFS master server address")
|
||||||
|
fileCount = flag.Int("files", 20, "Number of files to create")
|
||||||
|
deleteRatio = flag.Float64("delete", 0.4, "Ratio of files to delete (0.0-1.0)")
|
||||||
|
fileSizeKB = flag.Int("size", 100, "Size of each file in KB")
|
||||||
|
)
|
||||||
|
|
||||||
|
type AssignResult struct {
|
||||||
|
Fid string `json:"fid"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
PublicUrl string `json:"publicUrl"`
|
||||||
|
Count int `json:"count"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
fmt.Println("🧪 Creating fake data for vacuum task testing...")
|
||||||
|
fmt.Printf("Master: %s\n", *master)
|
||||||
|
fmt.Printf("Files to create: %d\n", *fileCount)
|
||||||
|
fmt.Printf("Delete ratio: %.1f%%\n", *deleteRatio*100)
|
||||||
|
fmt.Printf("File size: %d KB\n", *fileSizeKB)
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
if *fileCount == 0 {
|
||||||
|
// Just check volume status
|
||||||
|
fmt.Println("📊 Checking volume status...")
|
||||||
|
checkVolumeStatus()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 1: Create test files
|
||||||
|
fmt.Println("📁 Step 1: Creating test files...")
|
||||||
|
fids := createTestFiles()
|
||||||
|
|
||||||
|
// Step 2: Delete some files to create garbage
|
||||||
|
fmt.Println("🗑️ Step 2: Deleting files to create garbage...")
|
||||||
|
deleteFiles(fids)
|
||||||
|
|
||||||
|
// Step 3: Check volume status
|
||||||
|
fmt.Println("📊 Step 3: Checking volume status...")
|
||||||
|
checkVolumeStatus()
|
||||||
|
|
||||||
|
// Step 4: Configure vacuum for testing
|
||||||
|
fmt.Println("⚙️ Step 4: Instructions for testing...")
|
||||||
|
printTestingInstructions()
|
||||||
|
}
|
||||||
|
|
||||||
|
func createTestFiles() []string {
|
||||||
|
var fids []string
|
||||||
|
|
||||||
|
for i := 0; i < *fileCount; i++ {
|
||||||
|
// Generate random file content
|
||||||
|
fileData := make([]byte, *fileSizeKB*1024)
|
||||||
|
rand.Read(fileData)
|
||||||
|
|
||||||
|
// Get file ID assignment
|
||||||
|
assign, err := assignFileId()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to assign file ID for file %d: %v", i, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload file
|
||||||
|
err = uploadFile(assign, fileData, fmt.Sprintf("test_file_%d.dat", i))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to upload file %d: %v", i, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fids = append(fids, assign.Fid)
|
||||||
|
|
||||||
|
if (i+1)%5 == 0 {
|
||||||
|
fmt.Printf(" Created %d/%d files...\n", i+1, *fileCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("✅ Created %d files successfully\n\n", len(fids))
|
||||||
|
return fids
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteFiles(fids []string) {
|
||||||
|
deleteCount := int(float64(len(fids)) * *deleteRatio)
|
||||||
|
|
||||||
|
for i := 0; i < deleteCount; i++ {
|
||||||
|
err := deleteFile(fids[i])
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to delete file %s: %v", fids[i], err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i+1)%5 == 0 {
|
||||||
|
fmt.Printf(" Deleted %d/%d files...\n", i+1, deleteCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("✅ Deleted %d files (%.1f%% of total)\n\n", deleteCount, *deleteRatio*100)
|
||||||
|
}
|
||||||
|
|
||||||
|
func assignFileId() (*AssignResult, error) {
|
||||||
|
resp, err := http.Get(fmt.Sprintf("http://%s/dir/assign", *master))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var result AssignResult
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&result)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Error != "" {
|
||||||
|
return nil, fmt.Errorf("assignment error: %s", result.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func uploadFile(assign *AssignResult, data []byte, filename string) error {
|
||||||
|
url := fmt.Sprintf("http://%s/%s", assign.Url, assign.Fid)
|
||||||
|
|
||||||
|
body := &bytes.Buffer{}
|
||||||
|
body.Write(data)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", url, body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Content-Type", "application/octet-stream")
|
||||||
|
if filename != "" {
|
||||||
|
req.Header.Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename))
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{Timeout: 30 * time.Second}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {
|
||||||
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
return fmt.Errorf("upload failed with status %d: %s", resp.StatusCode, string(body))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteFile(fid string) error {
|
||||||
|
url := fmt.Sprintf("http://%s/%s", *master, fid)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("DELETE", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{Timeout: 10 * time.Second}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkVolumeStatus() {
|
||||||
|
// Get volume list from master
|
||||||
|
resp, err := http.Get(fmt.Sprintf("http://%s/vol/status", *master))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to get volume status: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var volumes map[string]interface{}
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&volumes)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to decode volume status: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("📊 Volume Status Summary:")
|
||||||
|
|
||||||
|
if vols, ok := volumes["Volumes"].([]interface{}); ok {
|
||||||
|
for _, vol := range vols {
|
||||||
|
if v, ok := vol.(map[string]interface{}); ok {
|
||||||
|
id := int(v["Id"].(float64))
|
||||||
|
size := uint64(v["Size"].(float64))
|
||||||
|
fileCount := int(v["FileCount"].(float64))
|
||||||
|
deleteCount := int(v["DeleteCount"].(float64))
|
||||||
|
deletedBytes := uint64(v["DeletedByteCount"].(float64))
|
||||||
|
|
||||||
|
garbageRatio := 0.0
|
||||||
|
if size > 0 {
|
||||||
|
garbageRatio = float64(deletedBytes) / float64(size) * 100
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf(" Volume %d:\n", id)
|
||||||
|
fmt.Printf(" Size: %s\n", formatBytes(size))
|
||||||
|
fmt.Printf(" Files: %d (active), %d (deleted)\n", fileCount, deleteCount)
|
||||||
|
fmt.Printf(" Garbage: %s (%.1f%%)\n", formatBytes(deletedBytes), garbageRatio)
|
||||||
|
|
||||||
|
if garbageRatio > 30 {
|
||||||
|
fmt.Printf(" 🎯 This volume should trigger vacuum (>30%% garbage)\n")
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatBytes(bytes uint64) string {
|
||||||
|
if bytes < 1024 {
|
||||||
|
return fmt.Sprintf("%d B", bytes)
|
||||||
|
} else if bytes < 1024*1024 {
|
||||||
|
return fmt.Sprintf("%.1f KB", float64(bytes)/1024)
|
||||||
|
} else if bytes < 1024*1024*1024 {
|
||||||
|
return fmt.Sprintf("%.1f MB", float64(bytes)/(1024*1024))
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("%.1f GB", float64(bytes)/(1024*1024*1024))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func printTestingInstructions() {
|
||||||
|
fmt.Println("🧪 Testing Instructions:")
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println("1. Configure Vacuum for Testing:")
|
||||||
|
fmt.Println(" Visit: http://localhost:23646/maintenance/config/vacuum")
|
||||||
|
fmt.Println(" Set:")
|
||||||
|
fmt.Printf(" - Garbage Percentage Threshold: 20 (20%% - lower than default 30)\n")
|
||||||
|
fmt.Printf(" - Scan Interval: [30] [Seconds] (faster than default)\n")
|
||||||
|
fmt.Printf(" - Min Volume Age: [0] [Minutes] (no age requirement)\n")
|
||||||
|
fmt.Printf(" - Max Concurrent: 2\n")
|
||||||
|
fmt.Printf(" - Min Interval: 1m (faster repeat)\n")
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
fmt.Println("2. Monitor Vacuum Tasks:")
|
||||||
|
fmt.Println(" Visit: http://localhost:23646/maintenance")
|
||||||
|
fmt.Println(" Watch for vacuum tasks to appear in the queue")
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
fmt.Println("3. Manual Vacuum (Optional):")
|
||||||
|
fmt.Println(" curl -X POST 'http://localhost:9333/vol/vacuum?garbageThreshold=0.20'")
|
||||||
|
fmt.Println(" (Note: Master API still uses 0.0-1.0 decimal format)")
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
fmt.Println("4. Check Logs:")
|
||||||
|
fmt.Println(" Look for messages like:")
|
||||||
|
fmt.Println(" - 'Vacuum detector found X volumes needing vacuum'")
|
||||||
|
fmt.Println(" - 'Applied vacuum configuration'")
|
||||||
|
fmt.Println(" - 'Worker executing task: vacuum'")
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
fmt.Println("5. Verify Results:")
|
||||||
|
fmt.Println(" Re-run this script with -files=0 to check volume status")
|
||||||
|
fmt.Println(" Garbage ratios should decrease after vacuum operations")
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
fmt.Printf("🚀 Quick test command:\n")
|
||||||
|
fmt.Printf(" go run create_vacuum_test_data.go -files=0\n")
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
+105
@@ -0,0 +1,105 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "🧪 SeaweedFS Vacuum Task Testing Demo"
|
||||||
|
echo "======================================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check if SeaweedFS is running
|
||||||
|
echo "📋 Checking SeaweedFS status..."
|
||||||
|
MASTER_URL="${MASTER_HOST:-master:9333}"
|
||||||
|
ADMIN_URL="${ADMIN_HOST:-admin:23646}"
|
||||||
|
|
||||||
|
if ! curl -s http://$MASTER_URL/cluster/status > /dev/null; then
|
||||||
|
echo "❌ SeaweedFS master not running at $MASTER_URL"
|
||||||
|
echo " Please ensure Docker cluster is running: make start"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! curl -s http://volume1:8080/status > /dev/null; then
|
||||||
|
echo "❌ SeaweedFS volume servers not running"
|
||||||
|
echo " Please ensure Docker cluster is running: make start"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! curl -s http://$ADMIN_URL/ > /dev/null; then
|
||||||
|
echo "❌ SeaweedFS admin server not running at $ADMIN_URL"
|
||||||
|
echo " Please ensure Docker cluster is running: make start"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ All SeaweedFS components are running"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Phase 1: Create test data
|
||||||
|
echo "📁 Phase 1: Creating test data with garbage..."
|
||||||
|
go run create_vacuum_test_data.go -master=$MASTER_URL -files=15 -delete=0.5 -size=150
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Phase 2: Check initial status
|
||||||
|
echo "📊 Phase 2: Checking initial volume status..."
|
||||||
|
go run create_vacuum_test_data.go -master=$MASTER_URL -files=0
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Phase 3: Configure vacuum
|
||||||
|
echo "⚙️ Phase 3: Vacuum configuration instructions..."
|
||||||
|
echo " 1. Visit: http://localhost:23646/maintenance/config/vacuum"
|
||||||
|
echo " 2. Set these values for testing:"
|
||||||
|
echo " - Enable Vacuum Tasks: ✅ Checked"
|
||||||
|
echo " - Garbage Threshold: 0.30"
|
||||||
|
echo " - Scan Interval: [30] [Seconds]"
|
||||||
|
echo " - Min Volume Age: [0] [Minutes]"
|
||||||
|
echo " - Max Concurrent: 2"
|
||||||
|
echo " 3. Click 'Save Configuration'"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
read -p " Press ENTER after configuring vacuum settings..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Phase 4: Monitor tasks
|
||||||
|
echo "🎯 Phase 4: Monitoring vacuum tasks..."
|
||||||
|
echo " Visit: http://localhost:23646/maintenance"
|
||||||
|
echo " You should see vacuum tasks appear within 30 seconds"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo " Waiting 60 seconds for vacuum detection and execution..."
|
||||||
|
for i in {60..1}; do
|
||||||
|
printf "\r Countdown: %02d seconds" $i
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Phase 5: Check results
|
||||||
|
echo "📈 Phase 5: Checking results after vacuum..."
|
||||||
|
go run create_vacuum_test_data.go -master=$MASTER_URL -files=0
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Phase 6: Create more garbage for continuous testing
|
||||||
|
echo "🔄 Phase 6: Creating additional garbage for continuous testing..."
|
||||||
|
echo " Running 3 rounds of garbage creation..."
|
||||||
|
|
||||||
|
for round in {1..3}; do
|
||||||
|
echo " Round $round: Creating garbage..."
|
||||||
|
go run create_vacuum_test_data.go -master=$MASTER_URL -files=8 -delete=0.6 -size=100
|
||||||
|
echo " Waiting 30 seconds before next round..."
|
||||||
|
sleep 30
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "📊 Final volume status:"
|
||||||
|
go run create_vacuum_test_data.go -master=$MASTER_URL -files=0
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "🎉 Demo Complete!"
|
||||||
|
echo ""
|
||||||
|
echo "🔍 Things to check:"
|
||||||
|
echo " 1. Maintenance Queue: http://localhost:23646/maintenance"
|
||||||
|
echo " 2. Volume Status: http://localhost:9333/vol/status"
|
||||||
|
echo " 3. Admin Dashboard: http://localhost:23646"
|
||||||
|
echo ""
|
||||||
|
echo "💡 Next Steps:"
|
||||||
|
echo " - Try different garbage thresholds (0.10, 0.50, 0.80)"
|
||||||
|
echo " - Adjust scan intervals (10s, 1m, 5m)"
|
||||||
|
echo " - Monitor logs for vacuum operations"
|
||||||
|
echo " - Test with multiple volumes"
|
||||||
|
echo ""
|
||||||
@@ -0,0 +1,240 @@
|
|||||||
|
name: admin_integration
|
||||||
|
|
||||||
|
networks:
|
||||||
|
seaweed_net:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
|
services:
|
||||||
|
master:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
ports:
|
||||||
|
- "9333:9333"
|
||||||
|
- "19333:19333"
|
||||||
|
command: "master -ip=master -mdir=/data -volumeSizeLimitMB=50"
|
||||||
|
environment:
|
||||||
|
- WEED_MASTER_VOLUME_GROWTH_COPY_1=1
|
||||||
|
- WEED_MASTER_VOLUME_GROWTH_COPY_2=2
|
||||||
|
- WEED_MASTER_VOLUME_GROWTH_COPY_OTHER=1
|
||||||
|
volumes:
|
||||||
|
- ./data/master:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
volume1:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
- "18080:18080"
|
||||||
|
command: "volume -mserver=master:9333 -ip=volume1 -dir=/data -max=10"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
volumes:
|
||||||
|
- ./data/volume1:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
volume2:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
ports:
|
||||||
|
- "8081:8080"
|
||||||
|
- "18081:18080"
|
||||||
|
command: "volume -mserver=master:9333 -ip=volume2 -dir=/data -max=10"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
volumes:
|
||||||
|
- ./data/volume2:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
volume3:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
ports:
|
||||||
|
- "8082:8080"
|
||||||
|
- "18082:18080"
|
||||||
|
command: "volume -mserver=master:9333 -ip=volume3 -dir=/data -max=10"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
volumes:
|
||||||
|
- ./data/volume3:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
volume4:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
ports:
|
||||||
|
- "8083:8080"
|
||||||
|
- "18083:18080"
|
||||||
|
command: "volume -mserver=master:9333 -ip=volume4 -dir=/data -max=10"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
volumes:
|
||||||
|
- ./data/volume4:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
volume5:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
ports:
|
||||||
|
- "8084:8080"
|
||||||
|
- "18084:18080"
|
||||||
|
command: "volume -mserver=master:9333 -ip=volume5 -dir=/data -max=10"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
volumes:
|
||||||
|
- ./data/volume5:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
volume6:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
ports:
|
||||||
|
- "8085:8080"
|
||||||
|
- "18085:18080"
|
||||||
|
command: "volume -mserver=master:9333 -ip=volume6 -dir=/data -max=10"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
volumes:
|
||||||
|
- ./data/volume6:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
filer:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
ports:
|
||||||
|
- "8888:8888"
|
||||||
|
- "18888:18888"
|
||||||
|
command: "filer -master=master:9333 -ip=filer"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
volumes:
|
||||||
|
- ./data/filer:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
admin:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
ports:
|
||||||
|
- "23646:23646" # HTTP admin interface (default port)
|
||||||
|
- "33646:33646" # gRPC worker communication (23646 + 10000)
|
||||||
|
command: "admin -port=23646 -masters=master:9333 -dataDir=/data"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
- filer
|
||||||
|
volumes:
|
||||||
|
- ./data/admin:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
worker1:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
command: "worker -admin=admin:23646 -capabilities=erasure_coding,vacuum -maxConcurrent=2"
|
||||||
|
depends_on:
|
||||||
|
- admin
|
||||||
|
volumes:
|
||||||
|
- ./data/worker1:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
environment:
|
||||||
|
- WORKER_ID=worker-1
|
||||||
|
|
||||||
|
worker2:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
command: "worker -admin=admin:23646 -capabilities=erasure_coding,vacuum -maxConcurrent=2"
|
||||||
|
depends_on:
|
||||||
|
- admin
|
||||||
|
volumes:
|
||||||
|
- ./data/worker2:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
environment:
|
||||||
|
- WORKER_ID=worker-2
|
||||||
|
|
||||||
|
worker3:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
command: "worker -admin=admin:23646 -capabilities=erasure_coding,vacuum -maxConcurrent=2"
|
||||||
|
depends_on:
|
||||||
|
- admin
|
||||||
|
volumes:
|
||||||
|
- ./data/worker3:/data
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
environment:
|
||||||
|
- WORKER_ID=worker-3
|
||||||
|
|
||||||
|
load_generator:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
entrypoint: ["/bin/sh"]
|
||||||
|
command: >
|
||||||
|
-c "
|
||||||
|
echo 'Starting load generator...';
|
||||||
|
sleep 30;
|
||||||
|
echo 'Generating continuous load with 50MB volume limit...';
|
||||||
|
while true; do
|
||||||
|
echo 'Writing test files...';
|
||||||
|
echo 'Test file content at $(date)' | /usr/bin/weed upload -server=master:9333;
|
||||||
|
sleep 5;
|
||||||
|
echo 'Deleting some files...';
|
||||||
|
/usr/bin/weed shell -master=master:9333 <<< 'fs.rm /test_file_*' || true;
|
||||||
|
sleep 10;
|
||||||
|
done
|
||||||
|
"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
- filer
|
||||||
|
- admin
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
monitor:
|
||||||
|
image: alpine:latest
|
||||||
|
entrypoint: ["/bin/sh"]
|
||||||
|
command: >
|
||||||
|
-c "
|
||||||
|
apk add --no-cache curl jq;
|
||||||
|
echo 'Starting cluster monitor...';
|
||||||
|
sleep 30;
|
||||||
|
while true; do
|
||||||
|
echo '=== Cluster Status $(date) ===';
|
||||||
|
echo 'Master status:';
|
||||||
|
curl -s http://master:9333/cluster/status | jq '.IsLeader, .Peers' || echo 'Master not ready';
|
||||||
|
echo;
|
||||||
|
echo 'Admin status:';
|
||||||
|
curl -s http://admin:23646/ | grep -o 'Admin.*Interface' || echo 'Admin not ready';
|
||||||
|
echo;
|
||||||
|
echo 'Volume count by server:';
|
||||||
|
curl -s http://master:9333/vol/status | jq '.Volumes | length' || echo 'Volumes not ready';
|
||||||
|
echo;
|
||||||
|
sleep 60;
|
||||||
|
done
|
||||||
|
"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
- admin
|
||||||
|
- filer
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
|
||||||
|
vacuum-tester:
|
||||||
|
image: chrislusf/seaweedfs:local
|
||||||
|
entrypoint: ["/bin/sh"]
|
||||||
|
command: >
|
||||||
|
-c "
|
||||||
|
echo 'Installing dependencies for vacuum testing...';
|
||||||
|
apk add --no-cache jq curl go bash;
|
||||||
|
echo 'Vacuum tester ready...';
|
||||||
|
echo 'Use: docker-compose exec vacuum-tester sh';
|
||||||
|
echo 'Available commands: go, weed, curl, jq, bash, sh';
|
||||||
|
sleep infinity
|
||||||
|
"
|
||||||
|
depends_on:
|
||||||
|
- master
|
||||||
|
- admin
|
||||||
|
- filer
|
||||||
|
volumes:
|
||||||
|
- .:/testing
|
||||||
|
working_dir: /testing
|
||||||
|
networks:
|
||||||
|
- seaweed_net
|
||||||
|
environment:
|
||||||
|
- MASTER_HOST=master:9333
|
||||||
|
- ADMIN_HOST=admin:23646
|
||||||
Executable
+73
@@ -0,0 +1,73 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🧪 Testing SeaweedFS Admin-Worker Integration"
|
||||||
|
echo "============================================="
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
echo -e "${BLUE}1. Validating docker-compose configuration...${NC}"
|
||||||
|
if docker-compose -f docker-compose-ec-test.yml config > /dev/null; then
|
||||||
|
echo -e "${GREEN}✅ Docker compose configuration is valid${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ Docker compose configuration is invalid${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${BLUE}2. Checking if required ports are available...${NC}"
|
||||||
|
for port in 9333 8080 8081 8082 8083 8084 8085 8888 23646; do
|
||||||
|
if lsof -i :$port > /dev/null 2>&1; then
|
||||||
|
echo -e "${YELLOW}⚠️ Port $port is in use${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}✅ Port $port is available${NC}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "${BLUE}3. Testing worker command syntax...${NC}"
|
||||||
|
# Test that the worker command in docker-compose has correct syntax
|
||||||
|
if docker-compose -f docker-compose-ec-test.yml config | grep -q "workingDir=/work"; then
|
||||||
|
echo -e "${GREEN}✅ Worker working directory option is properly configured${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ Worker working directory option is missing${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${BLUE}4. Verifying admin server configuration...${NC}"
|
||||||
|
if docker-compose -f docker-compose-ec-test.yml config | grep -q "admin:23646"; then
|
||||||
|
echo -e "${GREEN}✅ Admin server port configuration is correct${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ Admin server port configuration is incorrect${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${BLUE}5. Checking service dependencies...${NC}"
|
||||||
|
if docker-compose -f docker-compose-ec-test.yml config | grep -q "depends_on"; then
|
||||||
|
echo -e "${GREEN}✅ Service dependencies are configured${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}⚠️ Service dependencies may not be configured${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}🎉 Integration test configuration is ready!${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}To start the integration test:${NC}"
|
||||||
|
echo " make start # Start all services"
|
||||||
|
echo " make health # Check service health"
|
||||||
|
echo " make logs # View logs"
|
||||||
|
echo " make stop # Stop all services"
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}Key features verified:${NC}"
|
||||||
|
echo " ✅ Official SeaweedFS images are used"
|
||||||
|
echo " ✅ Worker working directories are configured"
|
||||||
|
echo " ✅ Admin-worker communication on correct ports"
|
||||||
|
echo " ✅ Task-specific directories will be created"
|
||||||
|
echo " ✅ Load generator will trigger EC tasks"
|
||||||
|
echo " ✅ Monitor will track progress"
|
||||||
@@ -0,0 +1,350 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FieldType defines the type of a configuration field
|
||||||
|
type FieldType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
FieldTypeBool FieldType = "bool"
|
||||||
|
FieldTypeInt FieldType = "int"
|
||||||
|
FieldTypeDuration FieldType = "duration"
|
||||||
|
FieldTypeInterval FieldType = "interval"
|
||||||
|
FieldTypeString FieldType = "string"
|
||||||
|
FieldTypeFloat FieldType = "float"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FieldUnit defines the unit for display purposes
|
||||||
|
type FieldUnit string
|
||||||
|
|
||||||
|
const (
|
||||||
|
UnitSeconds FieldUnit = "seconds"
|
||||||
|
UnitMinutes FieldUnit = "minutes"
|
||||||
|
UnitHours FieldUnit = "hours"
|
||||||
|
UnitDays FieldUnit = "days"
|
||||||
|
UnitCount FieldUnit = "count"
|
||||||
|
UnitNone FieldUnit = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// Field defines a configuration field with all its metadata
|
||||||
|
type Field struct {
|
||||||
|
// Field identification
|
||||||
|
Name string `json:"name"`
|
||||||
|
JSONName string `json:"json_name"`
|
||||||
|
Type FieldType `json:"type"`
|
||||||
|
|
||||||
|
// Default value and validation
|
||||||
|
DefaultValue interface{} `json:"default_value"`
|
||||||
|
MinValue interface{} `json:"min_value,omitempty"`
|
||||||
|
MaxValue interface{} `json:"max_value,omitempty"`
|
||||||
|
Required bool `json:"required"`
|
||||||
|
|
||||||
|
// UI display
|
||||||
|
DisplayName string `json:"display_name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
HelpText string `json:"help_text"`
|
||||||
|
Placeholder string `json:"placeholder"`
|
||||||
|
Unit FieldUnit `json:"unit"`
|
||||||
|
|
||||||
|
// Form rendering
|
||||||
|
InputType string `json:"input_type"` // "checkbox", "number", "text", "interval", etc.
|
||||||
|
CSSClasses string `json:"css_classes,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDisplayValue returns the value formatted for display in the specified unit
|
||||||
|
func (f *Field) GetDisplayValue(value interface{}) interface{} {
|
||||||
|
if (f.Type == FieldTypeDuration || f.Type == FieldTypeInterval) && f.Unit != UnitSeconds {
|
||||||
|
if duration, ok := value.(time.Duration); ok {
|
||||||
|
switch f.Unit {
|
||||||
|
case UnitMinutes:
|
||||||
|
return int(duration.Minutes())
|
||||||
|
case UnitHours:
|
||||||
|
return int(duration.Hours())
|
||||||
|
case UnitDays:
|
||||||
|
return int(duration.Hours() / 24)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if seconds, ok := value.(int); ok {
|
||||||
|
switch f.Unit {
|
||||||
|
case UnitMinutes:
|
||||||
|
return seconds / 60
|
||||||
|
case UnitHours:
|
||||||
|
return seconds / 3600
|
||||||
|
case UnitDays:
|
||||||
|
return seconds / (24 * 3600)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIntervalDisplayValue returns the value and unit for interval fields
|
||||||
|
func (f *Field) GetIntervalDisplayValue(value interface{}) (int, string) {
|
||||||
|
if f.Type != FieldTypeInterval {
|
||||||
|
return 0, "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
seconds := 0
|
||||||
|
if duration, ok := value.(time.Duration); ok {
|
||||||
|
seconds = int(duration.Seconds())
|
||||||
|
} else if s, ok := value.(int); ok {
|
||||||
|
seconds = s
|
||||||
|
}
|
||||||
|
|
||||||
|
return SecondsToIntervalValueUnit(seconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SecondsToIntervalValueUnit converts seconds to the most appropriate interval unit
|
||||||
|
func SecondsToIntervalValueUnit(totalSeconds int) (int, string) {
|
||||||
|
if totalSeconds == 0 {
|
||||||
|
return 0, "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if totalSeconds%(24*3600) == 0 {
|
||||||
|
return totalSeconds / (24 * 3600), "days"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if totalSeconds%3600 == 0 {
|
||||||
|
return totalSeconds / 3600, "hours"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return totalSeconds / 60, "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntervalValueUnitToSeconds converts interval value and unit to seconds
|
||||||
|
func IntervalValueUnitToSeconds(value int, unit string) int {
|
||||||
|
switch unit {
|
||||||
|
case "days":
|
||||||
|
return value * 24 * 3600
|
||||||
|
case "hours":
|
||||||
|
return value * 3600
|
||||||
|
case "minutes":
|
||||||
|
return value * 60
|
||||||
|
default:
|
||||||
|
return value * 60 // Default to minutes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseDisplayValue converts a display value back to the storage format
|
||||||
|
func (f *Field) ParseDisplayValue(displayValue interface{}) interface{} {
|
||||||
|
if (f.Type == FieldTypeDuration || f.Type == FieldTypeInterval) && f.Unit != UnitSeconds {
|
||||||
|
if val, ok := displayValue.(int); ok {
|
||||||
|
switch f.Unit {
|
||||||
|
case UnitMinutes:
|
||||||
|
return val * 60
|
||||||
|
case UnitHours:
|
||||||
|
return val * 3600
|
||||||
|
case UnitDays:
|
||||||
|
return val * 24 * 3600
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return displayValue
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseIntervalFormData parses form data for interval fields (value + unit)
|
||||||
|
func (f *Field) ParseIntervalFormData(valueStr, unitStr string) (int, error) {
|
||||||
|
if f.Type != FieldTypeInterval {
|
||||||
|
return 0, fmt.Errorf("field %s is not an interval field", f.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
value := 0
|
||||||
|
if valueStr != "" {
|
||||||
|
var err error
|
||||||
|
value, err = fmt.Sscanf(valueStr, "%d", &value)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("invalid interval value: %s", valueStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return IntervalValueUnitToSeconds(value, unitStr), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidateValue validates a value against the field constraints
|
||||||
|
func (f *Field) ValidateValue(value interface{}) error {
|
||||||
|
if f.Required && (value == nil || value == "" || value == 0) {
|
||||||
|
return fmt.Errorf("%s is required", f.DisplayName)
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.MinValue != nil {
|
||||||
|
if !f.compareValues(value, f.MinValue, ">=") {
|
||||||
|
return fmt.Errorf("%s must be >= %v", f.DisplayName, f.MinValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.MaxValue != nil {
|
||||||
|
if !f.compareValues(value, f.MaxValue, "<=") {
|
||||||
|
return fmt.Errorf("%s must be <= %v", f.DisplayName, f.MaxValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// compareValues compares two values based on the operator
|
||||||
|
func (f *Field) compareValues(a, b interface{}, op string) bool {
|
||||||
|
switch f.Type {
|
||||||
|
case FieldTypeInt:
|
||||||
|
aVal, aOk := a.(int)
|
||||||
|
bVal, bOk := b.(int)
|
||||||
|
if !aOk || !bOk {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
switch op {
|
||||||
|
case ">=":
|
||||||
|
return aVal >= bVal
|
||||||
|
case "<=":
|
||||||
|
return aVal <= bVal
|
||||||
|
}
|
||||||
|
case FieldTypeFloat:
|
||||||
|
aVal, aOk := a.(float64)
|
||||||
|
bVal, bOk := b.(float64)
|
||||||
|
if !aOk || !bOk {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
switch op {
|
||||||
|
case ">=":
|
||||||
|
return aVal >= bVal
|
||||||
|
case "<=":
|
||||||
|
return aVal <= bVal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schema provides common functionality for configuration schemas
|
||||||
|
type Schema struct {
|
||||||
|
Fields []*Field `json:"fields"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFieldByName returns a field by its JSON name
|
||||||
|
func (s *Schema) GetFieldByName(jsonName string) *Field {
|
||||||
|
for _, field := range s.Fields {
|
||||||
|
if field.JSONName == jsonName {
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyDefaults applies default values to a configuration struct using reflection
|
||||||
|
func (s *Schema) ApplyDefaults(config interface{}) error {
|
||||||
|
configValue := reflect.ValueOf(config)
|
||||||
|
if configValue.Kind() == reflect.Ptr {
|
||||||
|
configValue = configValue.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if configValue.Kind() != reflect.Struct {
|
||||||
|
return fmt.Errorf("config must be a struct or pointer to struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
configType := configValue.Type()
|
||||||
|
|
||||||
|
for i := 0; i < configValue.NumField(); i++ {
|
||||||
|
field := configValue.Field(i)
|
||||||
|
fieldType := configType.Field(i)
|
||||||
|
|
||||||
|
// Get JSON tag name
|
||||||
|
jsonTag := fieldType.Tag.Get("json")
|
||||||
|
if jsonTag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove options like ",omitempty"
|
||||||
|
if commaIdx := strings.Index(jsonTag, ","); commaIdx > 0 {
|
||||||
|
jsonTag = jsonTag[:commaIdx]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find corresponding schema field
|
||||||
|
schemaField := s.GetFieldByName(jsonTag)
|
||||||
|
if schemaField == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply default if field is zero value
|
||||||
|
if field.CanSet() && isZeroValue(field) {
|
||||||
|
defaultValue := reflect.ValueOf(schemaField.DefaultValue)
|
||||||
|
if defaultValue.Type().ConvertibleTo(field.Type()) {
|
||||||
|
field.Set(defaultValue.Convert(field.Type()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidateConfig validates a configuration against the schema
|
||||||
|
func (s *Schema) ValidateConfig(config interface{}) []error {
|
||||||
|
var errors []error
|
||||||
|
|
||||||
|
configValue := reflect.ValueOf(config)
|
||||||
|
if configValue.Kind() == reflect.Ptr {
|
||||||
|
configValue = configValue.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if configValue.Kind() != reflect.Struct {
|
||||||
|
errors = append(errors, fmt.Errorf("config must be a struct or pointer to struct"))
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
|
configType := configValue.Type()
|
||||||
|
|
||||||
|
for i := 0; i < configValue.NumField(); i++ {
|
||||||
|
field := configValue.Field(i)
|
||||||
|
fieldType := configType.Field(i)
|
||||||
|
|
||||||
|
// Get JSON tag name
|
||||||
|
jsonTag := fieldType.Tag.Get("json")
|
||||||
|
if jsonTag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove options like ",omitempty"
|
||||||
|
if commaIdx := strings.Index(jsonTag, ","); commaIdx > 0 {
|
||||||
|
jsonTag = jsonTag[:commaIdx]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find corresponding schema field
|
||||||
|
schemaField := s.GetFieldByName(jsonTag)
|
||||||
|
if schemaField == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate field value
|
||||||
|
fieldValue := field.Interface()
|
||||||
|
if err := schemaField.ValidateValue(fieldValue); err != nil {
|
||||||
|
errors = append(errors, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
|
// isZeroValue checks if a reflect.Value represents a zero value
|
||||||
|
func isZeroValue(v reflect.Value) bool {
|
||||||
|
switch v.Kind() {
|
||||||
|
case reflect.Bool:
|
||||||
|
return !v.Bool()
|
||||||
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
|
return v.Int() == 0
|
||||||
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||||
|
return v.Uint() == 0
|
||||||
|
case reflect.Float32, reflect.Float64:
|
||||||
|
return v.Float() == 0
|
||||||
|
case reflect.String:
|
||||||
|
return v.String() == ""
|
||||||
|
case reflect.Slice, reflect.Map, reflect.Array:
|
||||||
|
return v.IsNil() || v.Len() == 0
|
||||||
|
case reflect.Interface, reflect.Ptr:
|
||||||
|
return v.IsNil()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -852,6 +852,15 @@ func (as *AdminServer) CancelMaintenanceTask(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, gin.H{"success": true, "message": "Task cancelled"})
|
c.JSON(http.StatusOK, gin.H{"success": true, "message": "Task cancelled"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cancelMaintenanceTask cancels a pending maintenance task
|
||||||
|
func (as *AdminServer) cancelMaintenanceTask(taskID string) error {
|
||||||
|
if as.maintenanceManager == nil {
|
||||||
|
return fmt.Errorf("maintenance manager not initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
return as.maintenanceManager.CancelTask(taskID)
|
||||||
|
}
|
||||||
|
|
||||||
// GetMaintenanceWorkersAPI returns all maintenance workers
|
// GetMaintenanceWorkersAPI returns all maintenance workers
|
||||||
func (as *AdminServer) GetMaintenanceWorkersAPI(c *gin.Context) {
|
func (as *AdminServer) GetMaintenanceWorkersAPI(c *gin.Context) {
|
||||||
workers, err := as.getMaintenanceWorkers()
|
workers, err := as.getMaintenanceWorkers()
|
||||||
@@ -951,17 +960,36 @@ func (as *AdminServer) getMaintenanceQueueData() (*maintenance.MaintenanceQueueD
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMaintenanceQueueStats returns statistics for the maintenance queue (exported for handlers)
|
||||||
|
func (as *AdminServer) GetMaintenanceQueueStats() (*maintenance.QueueStats, error) {
|
||||||
|
return as.getMaintenanceQueueStats()
|
||||||
|
}
|
||||||
|
|
||||||
// getMaintenanceQueueStats returns statistics for the maintenance queue
|
// getMaintenanceQueueStats returns statistics for the maintenance queue
|
||||||
func (as *AdminServer) getMaintenanceQueueStats() (*maintenance.QueueStats, error) {
|
func (as *AdminServer) getMaintenanceQueueStats() (*maintenance.QueueStats, error) {
|
||||||
// This would integrate with the maintenance queue to get real statistics
|
if as.maintenanceManager == nil {
|
||||||
// For now, return mock data
|
return &maintenance.QueueStats{
|
||||||
return &maintenance.QueueStats{
|
PendingTasks: 0,
|
||||||
PendingTasks: 5,
|
RunningTasks: 0,
|
||||||
RunningTasks: 2,
|
CompletedToday: 0,
|
||||||
CompletedToday: 15,
|
FailedToday: 0,
|
||||||
FailedToday: 1,
|
TotalTasks: 0,
|
||||||
TotalTasks: 23,
|
}, nil
|
||||||
}, nil
|
}
|
||||||
|
|
||||||
|
// Get real statistics from maintenance manager
|
||||||
|
stats := as.maintenanceManager.GetStats()
|
||||||
|
|
||||||
|
// Convert MaintenanceStats to QueueStats
|
||||||
|
queueStats := &maintenance.QueueStats{
|
||||||
|
PendingTasks: stats.TasksByStatus[maintenance.TaskStatusPending],
|
||||||
|
RunningTasks: stats.TasksByStatus[maintenance.TaskStatusAssigned] + stats.TasksByStatus[maintenance.TaskStatusInProgress],
|
||||||
|
CompletedToday: stats.CompletedToday,
|
||||||
|
FailedToday: stats.FailedToday,
|
||||||
|
TotalTasks: stats.TotalTasks,
|
||||||
|
}
|
||||||
|
|
||||||
|
return queueStats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getMaintenanceTasks returns all maintenance tasks
|
// getMaintenanceTasks returns all maintenance tasks
|
||||||
@@ -1000,15 +1028,6 @@ func (as *AdminServer) getMaintenanceTask(taskID string) (*MaintenanceTask, erro
|
|||||||
return nil, fmt.Errorf("task %s not found", taskID)
|
return nil, fmt.Errorf("task %s not found", taskID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// cancelMaintenanceTask cancels a pending maintenance task
|
|
||||||
func (as *AdminServer) cancelMaintenanceTask(taskID string) error {
|
|
||||||
if as.maintenanceManager == nil {
|
|
||||||
return fmt.Errorf("maintenance manager not initialized")
|
|
||||||
}
|
|
||||||
|
|
||||||
return as.maintenanceManager.CancelTask(taskID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// getMaintenanceWorkers returns all maintenance workers
|
// getMaintenanceWorkers returns all maintenance workers
|
||||||
func (as *AdminServer) getMaintenanceWorkers() ([]*maintenance.MaintenanceWorker, error) {
|
func (as *AdminServer) getMaintenanceWorkers() ([]*maintenance.MaintenanceWorker, error) {
|
||||||
if as.maintenanceManager == nil {
|
if as.maintenanceManager == nil {
|
||||||
@@ -1112,7 +1131,26 @@ func (as *AdminServer) getMaintenanceConfig() (*maintenance.MaintenanceConfigDat
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to load maintenance configuration: %v", err)
|
glog.Errorf("Failed to load maintenance configuration: %v", err)
|
||||||
// Fallback to default configuration
|
// Fallback to default configuration
|
||||||
config = DefaultMaintenanceConfig()
|
config = maintenance.DefaultMaintenanceConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply schema defaults for any zero values
|
||||||
|
configUpdated := false
|
||||||
|
schema := maintenance.GetMaintenanceConfigSchema()
|
||||||
|
if err := schema.ApplyDefaults(config); err == nil {
|
||||||
|
configUpdated = true
|
||||||
|
glog.V(1).Infof("Applied schema defaults to configuration")
|
||||||
|
} else {
|
||||||
|
glog.Errorf("Failed to apply schema defaults: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the corrected configuration if any updates were made
|
||||||
|
if configUpdated {
|
||||||
|
if saveErr := as.configPersistence.SaveMaintenanceConfig(config); saveErr != nil {
|
||||||
|
glog.Errorf("Failed to save corrected configuration: %v", saveErr)
|
||||||
|
} else {
|
||||||
|
glog.V(1).Infof("Updated configuration with meaningful defaults and saved to persistent storage")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get system stats from maintenance manager if available
|
// Get system stats from maintenance manager if available
|
||||||
@@ -1151,6 +1189,24 @@ func (as *AdminServer) getMaintenanceConfig() (*maintenance.MaintenanceConfigDat
|
|||||||
|
|
||||||
// updateMaintenanceConfig updates maintenance configuration
|
// updateMaintenanceConfig updates maintenance configuration
|
||||||
func (as *AdminServer) updateMaintenanceConfig(config *maintenance.MaintenanceConfig) error {
|
func (as *AdminServer) updateMaintenanceConfig(config *maintenance.MaintenanceConfig) error {
|
||||||
|
// Apply meaningful defaults for zero values before saving using schema
|
||||||
|
schema := maintenance.GetMaintenanceConfigSchema()
|
||||||
|
|
||||||
|
// Apply schema defaults
|
||||||
|
if err := schema.ApplyDefaults(config); err != nil {
|
||||||
|
glog.Errorf("Failed to apply schema defaults: %v", err)
|
||||||
|
return fmt.Errorf("failed to apply schema defaults: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate configuration using schema
|
||||||
|
if validationErrors := schema.ValidateConfig(config); len(validationErrors) > 0 {
|
||||||
|
var errorMessages []string
|
||||||
|
for _, err := range validationErrors {
|
||||||
|
errorMessages = append(errorMessages, err.Error())
|
||||||
|
}
|
||||||
|
return fmt.Errorf("configuration validation failed: %v", errorMessages)
|
||||||
|
}
|
||||||
|
|
||||||
// Save configuration to persistent storage
|
// Save configuration to persistent storage
|
||||||
if err := as.configPersistence.SaveMaintenanceConfig(config); err != nil {
|
if err := as.configPersistence.SaveMaintenanceConfig(config); err != nil {
|
||||||
return fmt.Errorf("failed to save maintenance configuration: %w", err)
|
return fmt.Errorf("failed to save maintenance configuration: %w", err)
|
||||||
@@ -1265,14 +1321,11 @@ func (as *AdminServer) GetMaintenanceWorkersData() (*MaintenanceWorkersData, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StartWorkerGrpcServer starts the worker gRPC server
|
// StartWorkerGrpcServer starts the worker gRPC server
|
||||||
func (s *AdminServer) StartWorkerGrpcServer(httpPort int) error {
|
func (s *AdminServer) StartWorkerGrpcServer(grpcPort int) error {
|
||||||
if s.workerGrpcServer != nil {
|
if s.workerGrpcServer != nil {
|
||||||
return fmt.Errorf("worker gRPC server is already running")
|
return fmt.Errorf("worker gRPC server is already running")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate gRPC port (HTTP port + 10000)
|
|
||||||
grpcPort := httpPort + 10000
|
|
||||||
|
|
||||||
s.workerGrpcServer = NewWorkerGrpcServer(s)
|
s.workerGrpcServer = NewWorkerGrpcServer(s)
|
||||||
return s.workerGrpcServer.StartWithTLS(grpcPort)
|
return s.workerGrpcServer.StartWithTLS(grpcPort)
|
||||||
}
|
}
|
||||||
@@ -1412,7 +1465,7 @@ func (s *AdminServer) UpdateTopicRetention(namespace, name string, enabled bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create gRPC connection
|
// Create gRPC connection
|
||||||
conn, err := grpc.Dial(brokerAddress, s.grpcDialOption)
|
conn, err := grpc.NewClient(brokerAddress, s.grpcDialOption)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to connect to broker: %w", err)
|
return fmt.Errorf("failed to connect to broker: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
func (s *AdminServer) GetClusterCollections() (*ClusterCollectionsData, error) {
|
func (s *AdminServer) GetClusterCollections() (*ClusterCollectionsData, error) {
|
||||||
var collections []CollectionInfo
|
var collections []CollectionInfo
|
||||||
var totalVolumes int
|
var totalVolumes int
|
||||||
|
var totalEcVolumes int
|
||||||
var totalFiles int64
|
var totalFiles int64
|
||||||
var totalSize int64
|
var totalSize int64
|
||||||
collectionMap := make(map[string]*CollectionInfo)
|
collectionMap := make(map[string]*CollectionInfo)
|
||||||
@@ -28,6 +29,7 @@ func (s *AdminServer) GetClusterCollections() (*ClusterCollectionsData, error) {
|
|||||||
for _, rack := range dc.RackInfos {
|
for _, rack := range dc.RackInfos {
|
||||||
for _, node := range rack.DataNodeInfos {
|
for _, node := range rack.DataNodeInfos {
|
||||||
for _, diskInfo := range node.DiskInfos {
|
for _, diskInfo := range node.DiskInfos {
|
||||||
|
// Process regular volumes
|
||||||
for _, volInfo := range diskInfo.VolumeInfos {
|
for _, volInfo := range diskInfo.VolumeInfos {
|
||||||
// Extract collection name from volume info
|
// Extract collection name from volume info
|
||||||
collectionName := volInfo.Collection
|
collectionName := volInfo.Collection
|
||||||
@@ -69,12 +71,13 @@ func (s *AdminServer) GetClusterCollections() (*ClusterCollectionsData, error) {
|
|||||||
totalSize += int64(volInfo.Size)
|
totalSize += int64(volInfo.Size)
|
||||||
} else {
|
} else {
|
||||||
newCollection := CollectionInfo{
|
newCollection := CollectionInfo{
|
||||||
Name: collectionName,
|
Name: collectionName,
|
||||||
DataCenter: dc.Id,
|
DataCenter: dc.Id,
|
||||||
VolumeCount: 1,
|
VolumeCount: 1,
|
||||||
FileCount: int64(volInfo.FileCount),
|
EcVolumeCount: 0,
|
||||||
TotalSize: int64(volInfo.Size),
|
FileCount: int64(volInfo.FileCount),
|
||||||
DiskTypes: []string{diskType},
|
TotalSize: int64(volInfo.Size),
|
||||||
|
DiskTypes: []string{diskType},
|
||||||
}
|
}
|
||||||
collectionMap[collectionName] = &newCollection
|
collectionMap[collectionName] = &newCollection
|
||||||
totalVolumes++
|
totalVolumes++
|
||||||
@@ -82,6 +85,63 @@ func (s *AdminServer) GetClusterCollections() (*ClusterCollectionsData, error) {
|
|||||||
totalSize += int64(volInfo.Size)
|
totalSize += int64(volInfo.Size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process EC volumes
|
||||||
|
ecVolumeMap := make(map[uint32]bool) // Track unique EC volumes to avoid double counting
|
||||||
|
for _, ecShardInfo := range diskInfo.EcShardInfos {
|
||||||
|
// Extract collection name from EC shard info
|
||||||
|
collectionName := ecShardInfo.Collection
|
||||||
|
if collectionName == "" {
|
||||||
|
collectionName = "default" // Default collection for EC volumes without explicit collection
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only count each EC volume once (not per shard)
|
||||||
|
if !ecVolumeMap[ecShardInfo.Id] {
|
||||||
|
ecVolumeMap[ecShardInfo.Id] = true
|
||||||
|
|
||||||
|
// Get disk type from disk info, default to hdd if empty
|
||||||
|
diskType := diskInfo.Type
|
||||||
|
if diskType == "" {
|
||||||
|
diskType = "hdd"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get or create collection info
|
||||||
|
if collection, exists := collectionMap[collectionName]; exists {
|
||||||
|
collection.EcVolumeCount++
|
||||||
|
|
||||||
|
// Update data center if this collection spans multiple DCs
|
||||||
|
if collection.DataCenter != dc.Id && collection.DataCenter != "multi" {
|
||||||
|
collection.DataCenter = "multi"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add disk type if not already present
|
||||||
|
diskTypeExists := false
|
||||||
|
for _, existingDiskType := range collection.DiskTypes {
|
||||||
|
if existingDiskType == diskType {
|
||||||
|
diskTypeExists = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !diskTypeExists {
|
||||||
|
collection.DiskTypes = append(collection.DiskTypes, diskType)
|
||||||
|
}
|
||||||
|
|
||||||
|
totalEcVolumes++
|
||||||
|
} else {
|
||||||
|
newCollection := CollectionInfo{
|
||||||
|
Name: collectionName,
|
||||||
|
DataCenter: dc.Id,
|
||||||
|
VolumeCount: 0,
|
||||||
|
EcVolumeCount: 1,
|
||||||
|
FileCount: 0,
|
||||||
|
TotalSize: 0,
|
||||||
|
DiskTypes: []string{diskType},
|
||||||
|
}
|
||||||
|
collectionMap[collectionName] = &newCollection
|
||||||
|
totalEcVolumes++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,6 +172,7 @@ func (s *AdminServer) GetClusterCollections() (*ClusterCollectionsData, error) {
|
|||||||
Collections: []CollectionInfo{},
|
Collections: []CollectionInfo{},
|
||||||
TotalCollections: 0,
|
TotalCollections: 0,
|
||||||
TotalVolumes: 0,
|
TotalVolumes: 0,
|
||||||
|
TotalEcVolumes: 0,
|
||||||
TotalFiles: 0,
|
TotalFiles: 0,
|
||||||
TotalSize: 0,
|
TotalSize: 0,
|
||||||
LastUpdated: time.Now(),
|
LastUpdated: time.Now(),
|
||||||
@@ -122,8 +183,203 @@ func (s *AdminServer) GetClusterCollections() (*ClusterCollectionsData, error) {
|
|||||||
Collections: collections,
|
Collections: collections,
|
||||||
TotalCollections: len(collections),
|
TotalCollections: len(collections),
|
||||||
TotalVolumes: totalVolumes,
|
TotalVolumes: totalVolumes,
|
||||||
|
TotalEcVolumes: totalEcVolumes,
|
||||||
TotalFiles: totalFiles,
|
TotalFiles: totalFiles,
|
||||||
TotalSize: totalSize,
|
TotalSize: totalSize,
|
||||||
LastUpdated: time.Now(),
|
LastUpdated: time.Now(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCollectionDetails retrieves detailed information for a specific collection including volumes and EC volumes
|
||||||
|
func (s *AdminServer) GetCollectionDetails(collectionName string, page int, pageSize int, sortBy string, sortOrder string) (*CollectionDetailsData, error) {
|
||||||
|
// Set defaults
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
if pageSize < 1 || pageSize > 1000 {
|
||||||
|
pageSize = 25
|
||||||
|
}
|
||||||
|
if sortBy == "" {
|
||||||
|
sortBy = "volume_id"
|
||||||
|
}
|
||||||
|
if sortOrder == "" {
|
||||||
|
sortOrder = "asc"
|
||||||
|
}
|
||||||
|
|
||||||
|
var regularVolumes []VolumeWithTopology
|
||||||
|
var ecVolumes []EcVolumeWithShards
|
||||||
|
var totalFiles int64
|
||||||
|
var totalSize int64
|
||||||
|
dataCenters := make(map[string]bool)
|
||||||
|
diskTypes := make(map[string]bool)
|
||||||
|
|
||||||
|
// Get regular volumes for this collection
|
||||||
|
regularVolumeData, err := s.GetClusterVolumes(1, 10000, "volume_id", "asc", collectionName) // Get all volumes
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
regularVolumes = regularVolumeData.Volumes
|
||||||
|
totalSize = regularVolumeData.TotalSize
|
||||||
|
|
||||||
|
// Calculate total files from regular volumes
|
||||||
|
for _, vol := range regularVolumes {
|
||||||
|
totalFiles += int64(vol.FileCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect data centers and disk types from regular volumes
|
||||||
|
for _, vol := range regularVolumes {
|
||||||
|
dataCenters[vol.DataCenter] = true
|
||||||
|
diskTypes[vol.DiskType] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get EC volumes for this collection
|
||||||
|
ecVolumeData, err := s.GetClusterEcVolumes(1, 10000, "volume_id", "asc", collectionName) // Get all EC volumes
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ecVolumes = ecVolumeData.EcVolumes
|
||||||
|
|
||||||
|
// Collect data centers from EC volumes
|
||||||
|
for _, ecVol := range ecVolumes {
|
||||||
|
for _, dc := range ecVol.DataCenters {
|
||||||
|
dataCenters[dc] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combine all volumes for sorting and pagination
|
||||||
|
type VolumeForSorting struct {
|
||||||
|
Type string // "regular" or "ec"
|
||||||
|
RegularVolume *VolumeWithTopology
|
||||||
|
EcVolume *EcVolumeWithShards
|
||||||
|
}
|
||||||
|
|
||||||
|
var allVolumes []VolumeForSorting
|
||||||
|
for i := range regularVolumes {
|
||||||
|
allVolumes = append(allVolumes, VolumeForSorting{
|
||||||
|
Type: "regular",
|
||||||
|
RegularVolume: ®ularVolumes[i],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for i := range ecVolumes {
|
||||||
|
allVolumes = append(allVolumes, VolumeForSorting{
|
||||||
|
Type: "ec",
|
||||||
|
EcVolume: &ecVolumes[i],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort all volumes
|
||||||
|
sort.Slice(allVolumes, func(i, j int) bool {
|
||||||
|
var less bool
|
||||||
|
switch sortBy {
|
||||||
|
case "volume_id":
|
||||||
|
var idI, idJ uint32
|
||||||
|
if allVolumes[i].Type == "regular" {
|
||||||
|
idI = allVolumes[i].RegularVolume.Id
|
||||||
|
} else {
|
||||||
|
idI = allVolumes[i].EcVolume.VolumeID
|
||||||
|
}
|
||||||
|
if allVolumes[j].Type == "regular" {
|
||||||
|
idJ = allVolumes[j].RegularVolume.Id
|
||||||
|
} else {
|
||||||
|
idJ = allVolumes[j].EcVolume.VolumeID
|
||||||
|
}
|
||||||
|
less = idI < idJ
|
||||||
|
case "type":
|
||||||
|
// Sort by type first (regular before ec), then by volume ID
|
||||||
|
if allVolumes[i].Type == allVolumes[j].Type {
|
||||||
|
var idI, idJ uint32
|
||||||
|
if allVolumes[i].Type == "regular" {
|
||||||
|
idI = allVolumes[i].RegularVolume.Id
|
||||||
|
} else {
|
||||||
|
idI = allVolumes[i].EcVolume.VolumeID
|
||||||
|
}
|
||||||
|
if allVolumes[j].Type == "regular" {
|
||||||
|
idJ = allVolumes[j].RegularVolume.Id
|
||||||
|
} else {
|
||||||
|
idJ = allVolumes[j].EcVolume.VolumeID
|
||||||
|
}
|
||||||
|
less = idI < idJ
|
||||||
|
} else {
|
||||||
|
less = allVolumes[i].Type < allVolumes[j].Type // "ec" < "regular"
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// Default to volume ID sort
|
||||||
|
var idI, idJ uint32
|
||||||
|
if allVolumes[i].Type == "regular" {
|
||||||
|
idI = allVolumes[i].RegularVolume.Id
|
||||||
|
} else {
|
||||||
|
idI = allVolumes[i].EcVolume.VolumeID
|
||||||
|
}
|
||||||
|
if allVolumes[j].Type == "regular" {
|
||||||
|
idJ = allVolumes[j].RegularVolume.Id
|
||||||
|
} else {
|
||||||
|
idJ = allVolumes[j].EcVolume.VolumeID
|
||||||
|
}
|
||||||
|
less = idI < idJ
|
||||||
|
}
|
||||||
|
|
||||||
|
if sortOrder == "desc" {
|
||||||
|
return !less
|
||||||
|
}
|
||||||
|
return less
|
||||||
|
})
|
||||||
|
|
||||||
|
// Apply pagination
|
||||||
|
totalVolumesAndEc := len(allVolumes)
|
||||||
|
totalPages := (totalVolumesAndEc + pageSize - 1) / pageSize
|
||||||
|
startIndex := (page - 1) * pageSize
|
||||||
|
endIndex := startIndex + pageSize
|
||||||
|
if endIndex > totalVolumesAndEc {
|
||||||
|
endIndex = totalVolumesAndEc
|
||||||
|
}
|
||||||
|
|
||||||
|
if startIndex >= totalVolumesAndEc {
|
||||||
|
startIndex = 0
|
||||||
|
endIndex = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract paginated results
|
||||||
|
var paginatedRegularVolumes []VolumeWithTopology
|
||||||
|
var paginatedEcVolumes []EcVolumeWithShards
|
||||||
|
|
||||||
|
for i := startIndex; i < endIndex; i++ {
|
||||||
|
if allVolumes[i].Type == "regular" {
|
||||||
|
paginatedRegularVolumes = append(paginatedRegularVolumes, *allVolumes[i].RegularVolume)
|
||||||
|
} else {
|
||||||
|
paginatedEcVolumes = append(paginatedEcVolumes, *allVolumes[i].EcVolume)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert maps to slices
|
||||||
|
var dcList []string
|
||||||
|
for dc := range dataCenters {
|
||||||
|
dcList = append(dcList, dc)
|
||||||
|
}
|
||||||
|
sort.Strings(dcList)
|
||||||
|
|
||||||
|
var diskTypeList []string
|
||||||
|
for diskType := range diskTypes {
|
||||||
|
diskTypeList = append(diskTypeList, diskType)
|
||||||
|
}
|
||||||
|
sort.Strings(diskTypeList)
|
||||||
|
|
||||||
|
return &CollectionDetailsData{
|
||||||
|
CollectionName: collectionName,
|
||||||
|
RegularVolumes: paginatedRegularVolumes,
|
||||||
|
EcVolumes: paginatedEcVolumes,
|
||||||
|
TotalVolumes: len(regularVolumes),
|
||||||
|
TotalEcVolumes: len(ecVolumes),
|
||||||
|
TotalFiles: totalFiles,
|
||||||
|
TotalSize: totalSize,
|
||||||
|
DataCenters: dcList,
|
||||||
|
DiskTypes: diskTypeList,
|
||||||
|
LastUpdated: time.Now(),
|
||||||
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
TotalPages: totalPages,
|
||||||
|
SortBy: sortBy,
|
||||||
|
SortOrder: sortOrder,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,721 @@
|
|||||||
|
package dash
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetClusterEcShards retrieves cluster EC shards data with pagination, sorting, and filtering
|
||||||
|
func (s *AdminServer) GetClusterEcShards(page int, pageSize int, sortBy string, sortOrder string, collection string) (*ClusterEcShardsData, error) {
|
||||||
|
// Set defaults
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
if pageSize < 1 || pageSize > 1000 {
|
||||||
|
pageSize = 100
|
||||||
|
}
|
||||||
|
if sortBy == "" {
|
||||||
|
sortBy = "volume_id"
|
||||||
|
}
|
||||||
|
if sortOrder == "" {
|
||||||
|
sortOrder = "asc"
|
||||||
|
}
|
||||||
|
|
||||||
|
var ecShards []EcShardWithInfo
|
||||||
|
volumeShardsMap := make(map[uint32]map[int]bool) // volumeId -> set of shards present
|
||||||
|
volumesWithAllShards := 0
|
||||||
|
volumesWithMissingShards := 0
|
||||||
|
|
||||||
|
// Get detailed EC shard information via gRPC
|
||||||
|
err := s.WithMasterClient(func(client master_pb.SeaweedClient) error {
|
||||||
|
resp, err := client.VolumeList(context.Background(), &master_pb.VolumeListRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.TopologyInfo != nil {
|
||||||
|
for _, dc := range resp.TopologyInfo.DataCenterInfos {
|
||||||
|
for _, rack := range dc.RackInfos {
|
||||||
|
for _, node := range rack.DataNodeInfos {
|
||||||
|
for _, diskInfo := range node.DiskInfos {
|
||||||
|
// Process EC shard information
|
||||||
|
for _, ecShardInfo := range diskInfo.EcShardInfos {
|
||||||
|
volumeId := ecShardInfo.Id
|
||||||
|
|
||||||
|
// Initialize volume shards map if needed
|
||||||
|
if volumeShardsMap[volumeId] == nil {
|
||||||
|
volumeShardsMap[volumeId] = make(map[int]bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create individual shard entries for each shard this server has
|
||||||
|
shardBits := ecShardInfo.EcIndexBits
|
||||||
|
for shardId := 0; shardId < erasure_coding.TotalShardsCount; shardId++ {
|
||||||
|
if (shardBits & (1 << uint(shardId))) != 0 {
|
||||||
|
// Mark this shard as present for this volume
|
||||||
|
volumeShardsMap[volumeId][shardId] = true
|
||||||
|
|
||||||
|
ecShard := EcShardWithInfo{
|
||||||
|
VolumeID: volumeId,
|
||||||
|
ShardID: uint32(shardId),
|
||||||
|
Collection: ecShardInfo.Collection,
|
||||||
|
Size: 0, // EC shards don't have individual size in the API response
|
||||||
|
Server: node.Id,
|
||||||
|
DataCenter: dc.Id,
|
||||||
|
Rack: rack.Id,
|
||||||
|
DiskType: diskInfo.Type,
|
||||||
|
ModifiedTime: 0, // Not available in current API
|
||||||
|
EcIndexBits: ecShardInfo.EcIndexBits,
|
||||||
|
ShardCount: getShardCount(ecShardInfo.EcIndexBits),
|
||||||
|
}
|
||||||
|
ecShards = append(ecShards, ecShard)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate volume-level completeness (across all servers)
|
||||||
|
volumeCompleteness := make(map[uint32]bool)
|
||||||
|
volumeMissingShards := make(map[uint32][]int)
|
||||||
|
|
||||||
|
for volumeId, shardsPresent := range volumeShardsMap {
|
||||||
|
var missingShards []int
|
||||||
|
shardCount := len(shardsPresent)
|
||||||
|
|
||||||
|
// Find which shards are missing for this volume across ALL servers
|
||||||
|
for shardId := 0; shardId < erasure_coding.TotalShardsCount; shardId++ {
|
||||||
|
if !shardsPresent[shardId] {
|
||||||
|
missingShards = append(missingShards, shardId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isComplete := (shardCount == erasure_coding.TotalShardsCount)
|
||||||
|
volumeCompleteness[volumeId] = isComplete
|
||||||
|
volumeMissingShards[volumeId] = missingShards
|
||||||
|
|
||||||
|
if isComplete {
|
||||||
|
volumesWithAllShards++
|
||||||
|
} else {
|
||||||
|
volumesWithMissingShards++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update completeness info for each shard based on volume-level completeness
|
||||||
|
for i := range ecShards {
|
||||||
|
volumeId := ecShards[i].VolumeID
|
||||||
|
ecShards[i].IsComplete = volumeCompleteness[volumeId]
|
||||||
|
ecShards[i].MissingShards = volumeMissingShards[volumeId]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter by collection if specified
|
||||||
|
if collection != "" {
|
||||||
|
var filteredShards []EcShardWithInfo
|
||||||
|
for _, shard := range ecShards {
|
||||||
|
if shard.Collection == collection {
|
||||||
|
filteredShards = append(filteredShards, shard)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ecShards = filteredShards
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort the results
|
||||||
|
sortEcShards(ecShards, sortBy, sortOrder)
|
||||||
|
|
||||||
|
// Calculate statistics for conditional display
|
||||||
|
dataCenters := make(map[string]bool)
|
||||||
|
racks := make(map[string]bool)
|
||||||
|
collections := make(map[string]bool)
|
||||||
|
|
||||||
|
for _, shard := range ecShards {
|
||||||
|
dataCenters[shard.DataCenter] = true
|
||||||
|
racks[shard.Rack] = true
|
||||||
|
if shard.Collection != "" {
|
||||||
|
collections[shard.Collection] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
totalShards := len(ecShards)
|
||||||
|
totalPages := (totalShards + pageSize - 1) / pageSize
|
||||||
|
startIndex := (page - 1) * pageSize
|
||||||
|
endIndex := startIndex + pageSize
|
||||||
|
if endIndex > totalShards {
|
||||||
|
endIndex = totalShards
|
||||||
|
}
|
||||||
|
|
||||||
|
if startIndex >= totalShards {
|
||||||
|
startIndex = 0
|
||||||
|
endIndex = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
paginatedShards := ecShards[startIndex:endIndex]
|
||||||
|
|
||||||
|
// Build response
|
||||||
|
data := &ClusterEcShardsData{
|
||||||
|
EcShards: paginatedShards,
|
||||||
|
TotalShards: totalShards,
|
||||||
|
TotalVolumes: len(volumeShardsMap),
|
||||||
|
LastUpdated: time.Now(),
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
CurrentPage: page,
|
||||||
|
TotalPages: totalPages,
|
||||||
|
PageSize: pageSize,
|
||||||
|
|
||||||
|
// Sorting
|
||||||
|
SortBy: sortBy,
|
||||||
|
SortOrder: sortOrder,
|
||||||
|
|
||||||
|
// Statistics
|
||||||
|
DataCenterCount: len(dataCenters),
|
||||||
|
RackCount: len(racks),
|
||||||
|
CollectionCount: len(collections),
|
||||||
|
|
||||||
|
// Conditional display flags
|
||||||
|
ShowDataCenterColumn: len(dataCenters) > 1,
|
||||||
|
ShowRackColumn: len(racks) > 1,
|
||||||
|
ShowCollectionColumn: len(collections) > 1 || collection != "",
|
||||||
|
|
||||||
|
// Filtering
|
||||||
|
FilterCollection: collection,
|
||||||
|
|
||||||
|
// EC specific statistics
|
||||||
|
ShardsPerVolume: make(map[uint32]int), // This will be recalculated below
|
||||||
|
VolumesWithAllShards: volumesWithAllShards,
|
||||||
|
VolumesWithMissingShards: volumesWithMissingShards,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recalculate ShardsPerVolume for the response
|
||||||
|
for volumeId, shardsPresent := range volumeShardsMap {
|
||||||
|
data.ShardsPerVolume[volumeId] = len(shardsPresent)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set single values when only one exists
|
||||||
|
if len(dataCenters) == 1 {
|
||||||
|
for dc := range dataCenters {
|
||||||
|
data.SingleDataCenter = dc
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(racks) == 1 {
|
||||||
|
for rack := range racks {
|
||||||
|
data.SingleRack = rack
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(collections) == 1 {
|
||||||
|
for col := range collections {
|
||||||
|
data.SingleCollection = col
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetClusterEcVolumes retrieves cluster EC volumes data grouped by volume ID with shard locations
|
||||||
|
func (s *AdminServer) GetClusterEcVolumes(page int, pageSize int, sortBy string, sortOrder string, collection string) (*ClusterEcVolumesData, error) {
|
||||||
|
// Set defaults
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
if pageSize < 1 || pageSize > 1000 {
|
||||||
|
pageSize = 100
|
||||||
|
}
|
||||||
|
if sortBy == "" {
|
||||||
|
sortBy = "volume_id"
|
||||||
|
}
|
||||||
|
if sortOrder == "" {
|
||||||
|
sortOrder = "asc"
|
||||||
|
}
|
||||||
|
|
||||||
|
volumeData := make(map[uint32]*EcVolumeWithShards)
|
||||||
|
totalShards := 0
|
||||||
|
|
||||||
|
// Get detailed EC shard information via gRPC
|
||||||
|
err := s.WithMasterClient(func(client master_pb.SeaweedClient) error {
|
||||||
|
resp, err := client.VolumeList(context.Background(), &master_pb.VolumeListRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.TopologyInfo != nil {
|
||||||
|
for _, dc := range resp.TopologyInfo.DataCenterInfos {
|
||||||
|
for _, rack := range dc.RackInfos {
|
||||||
|
for _, node := range rack.DataNodeInfos {
|
||||||
|
for _, diskInfo := range node.DiskInfos {
|
||||||
|
// Process EC shard information
|
||||||
|
for _, ecShardInfo := range diskInfo.EcShardInfos {
|
||||||
|
volumeId := ecShardInfo.Id
|
||||||
|
|
||||||
|
// Initialize volume data if needed
|
||||||
|
if volumeData[volumeId] == nil {
|
||||||
|
volumeData[volumeId] = &EcVolumeWithShards{
|
||||||
|
VolumeID: volumeId,
|
||||||
|
Collection: ecShardInfo.Collection,
|
||||||
|
TotalShards: 0,
|
||||||
|
IsComplete: false,
|
||||||
|
MissingShards: []int{},
|
||||||
|
ShardLocations: make(map[int]string),
|
||||||
|
ShardSizes: make(map[int]int64),
|
||||||
|
DataCenters: []string{},
|
||||||
|
Servers: []string{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
volume := volumeData[volumeId]
|
||||||
|
|
||||||
|
// Track data centers and servers
|
||||||
|
dcExists := false
|
||||||
|
for _, existingDc := range volume.DataCenters {
|
||||||
|
if existingDc == dc.Id {
|
||||||
|
dcExists = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dcExists {
|
||||||
|
volume.DataCenters = append(volume.DataCenters, dc.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
serverExists := false
|
||||||
|
for _, existingServer := range volume.Servers {
|
||||||
|
if existingServer == node.Id {
|
||||||
|
serverExists = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !serverExists {
|
||||||
|
volume.Servers = append(volume.Servers, node.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process each shard this server has for this volume
|
||||||
|
shardBits := ecShardInfo.EcIndexBits
|
||||||
|
for shardId := 0; shardId < erasure_coding.TotalShardsCount; shardId++ {
|
||||||
|
if (shardBits & (1 << uint(shardId))) != 0 {
|
||||||
|
// Record shard location
|
||||||
|
volume.ShardLocations[shardId] = node.Id
|
||||||
|
totalShards++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect shard size information from volume servers
|
||||||
|
for volumeId, volume := range volumeData {
|
||||||
|
// Group servers by volume to minimize gRPC calls
|
||||||
|
serverHasVolume := make(map[string]bool)
|
||||||
|
for _, server := range volume.Servers {
|
||||||
|
serverHasVolume[server] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query each server for shard sizes
|
||||||
|
for server := range serverHasVolume {
|
||||||
|
err := s.WithVolumeServerClient(pb.ServerAddress(server), func(client volume_server_pb.VolumeServerClient) error {
|
||||||
|
resp, err := client.VolumeEcShardsInfo(context.Background(), &volume_server_pb.VolumeEcShardsInfoRequest{
|
||||||
|
VolumeId: volumeId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
glog.V(1).Infof("Failed to get EC shard info from %s for volume %d: %v", server, volumeId, err)
|
||||||
|
return nil // Continue with other servers, don't fail the entire request
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update shard sizes
|
||||||
|
for _, shardInfo := range resp.EcShardInfos {
|
||||||
|
volume.ShardSizes[int(shardInfo.ShardId)] = shardInfo.Size
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
glog.V(1).Infof("Failed to connect to volume server %s: %v", server, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate completeness for each volume
|
||||||
|
completeVolumes := 0
|
||||||
|
incompleteVolumes := 0
|
||||||
|
|
||||||
|
for _, volume := range volumeData {
|
||||||
|
volume.TotalShards = len(volume.ShardLocations)
|
||||||
|
|
||||||
|
// Find missing shards
|
||||||
|
var missingShards []int
|
||||||
|
for shardId := 0; shardId < erasure_coding.TotalShardsCount; shardId++ {
|
||||||
|
if _, exists := volume.ShardLocations[shardId]; !exists {
|
||||||
|
missingShards = append(missingShards, shardId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
volume.MissingShards = missingShards
|
||||||
|
volume.IsComplete = (len(missingShards) == 0)
|
||||||
|
|
||||||
|
if volume.IsComplete {
|
||||||
|
completeVolumes++
|
||||||
|
} else {
|
||||||
|
incompleteVolumes++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert map to slice
|
||||||
|
var ecVolumes []EcVolumeWithShards
|
||||||
|
for _, volume := range volumeData {
|
||||||
|
// Filter by collection if specified
|
||||||
|
if collection == "" || volume.Collection == collection {
|
||||||
|
ecVolumes = append(ecVolumes, *volume)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort the results
|
||||||
|
sortEcVolumes(ecVolumes, sortBy, sortOrder)
|
||||||
|
|
||||||
|
// Calculate statistics for conditional display
|
||||||
|
dataCenters := make(map[string]bool)
|
||||||
|
collections := make(map[string]bool)
|
||||||
|
|
||||||
|
for _, volume := range ecVolumes {
|
||||||
|
for _, dc := range volume.DataCenters {
|
||||||
|
dataCenters[dc] = true
|
||||||
|
}
|
||||||
|
if volume.Collection != "" {
|
||||||
|
collections[volume.Collection] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
totalVolumes := len(ecVolumes)
|
||||||
|
totalPages := (totalVolumes + pageSize - 1) / pageSize
|
||||||
|
startIndex := (page - 1) * pageSize
|
||||||
|
endIndex := startIndex + pageSize
|
||||||
|
if endIndex > totalVolumes {
|
||||||
|
endIndex = totalVolumes
|
||||||
|
}
|
||||||
|
|
||||||
|
if startIndex >= totalVolumes {
|
||||||
|
startIndex = 0
|
||||||
|
endIndex = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
paginatedVolumes := ecVolumes[startIndex:endIndex]
|
||||||
|
|
||||||
|
// Build response
|
||||||
|
data := &ClusterEcVolumesData{
|
||||||
|
EcVolumes: paginatedVolumes,
|
||||||
|
TotalVolumes: totalVolumes,
|
||||||
|
LastUpdated: time.Now(),
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
Page: page,
|
||||||
|
PageSize: pageSize,
|
||||||
|
TotalPages: totalPages,
|
||||||
|
|
||||||
|
// Sorting
|
||||||
|
SortBy: sortBy,
|
||||||
|
SortOrder: sortOrder,
|
||||||
|
|
||||||
|
// Filtering
|
||||||
|
Collection: collection,
|
||||||
|
|
||||||
|
// Conditional display flags
|
||||||
|
ShowDataCenterColumn: len(dataCenters) > 1,
|
||||||
|
ShowRackColumn: false, // We don't track racks in this view for simplicity
|
||||||
|
ShowCollectionColumn: len(collections) > 1 || collection != "",
|
||||||
|
|
||||||
|
// Statistics
|
||||||
|
CompleteVolumes: completeVolumes,
|
||||||
|
IncompleteVolumes: incompleteVolumes,
|
||||||
|
TotalShards: totalShards,
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// sortEcVolumes sorts EC volumes based on the specified field and order
|
||||||
|
func sortEcVolumes(volumes []EcVolumeWithShards, sortBy string, sortOrder string) {
|
||||||
|
sort.Slice(volumes, func(i, j int) bool {
|
||||||
|
var less bool
|
||||||
|
switch sortBy {
|
||||||
|
case "volume_id":
|
||||||
|
less = volumes[i].VolumeID < volumes[j].VolumeID
|
||||||
|
case "collection":
|
||||||
|
if volumes[i].Collection == volumes[j].Collection {
|
||||||
|
less = volumes[i].VolumeID < volumes[j].VolumeID
|
||||||
|
} else {
|
||||||
|
less = volumes[i].Collection < volumes[j].Collection
|
||||||
|
}
|
||||||
|
case "total_shards":
|
||||||
|
if volumes[i].TotalShards == volumes[j].TotalShards {
|
||||||
|
less = volumes[i].VolumeID < volumes[j].VolumeID
|
||||||
|
} else {
|
||||||
|
less = volumes[i].TotalShards < volumes[j].TotalShards
|
||||||
|
}
|
||||||
|
case "completeness":
|
||||||
|
// Complete volumes first, then by volume ID
|
||||||
|
if volumes[i].IsComplete == volumes[j].IsComplete {
|
||||||
|
less = volumes[i].VolumeID < volumes[j].VolumeID
|
||||||
|
} else {
|
||||||
|
less = volumes[i].IsComplete && !volumes[j].IsComplete
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
less = volumes[i].VolumeID < volumes[j].VolumeID
|
||||||
|
}
|
||||||
|
|
||||||
|
if sortOrder == "desc" {
|
||||||
|
return !less
|
||||||
|
}
|
||||||
|
return less
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// getShardCount returns the number of shards represented by the bitmap
|
||||||
|
func getShardCount(ecIndexBits uint32) int {
|
||||||
|
count := 0
|
||||||
|
for i := 0; i < erasure_coding.TotalShardsCount; i++ {
|
||||||
|
if (ecIndexBits & (1 << uint(i))) != 0 {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// getMissingShards returns a slice of missing shard IDs for a volume
|
||||||
|
func getMissingShards(ecIndexBits uint32) []int {
|
||||||
|
var missing []int
|
||||||
|
for i := 0; i < erasure_coding.TotalShardsCount; i++ {
|
||||||
|
if (ecIndexBits & (1 << uint(i))) == 0 {
|
||||||
|
missing = append(missing, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return missing
|
||||||
|
}
|
||||||
|
|
||||||
|
// sortEcShards sorts EC shards based on the specified field and order
|
||||||
|
func sortEcShards(shards []EcShardWithInfo, sortBy string, sortOrder string) {
|
||||||
|
sort.Slice(shards, func(i, j int) bool {
|
||||||
|
var less bool
|
||||||
|
switch sortBy {
|
||||||
|
case "shard_id":
|
||||||
|
less = shards[i].ShardID < shards[j].ShardID
|
||||||
|
case "server":
|
||||||
|
if shards[i].Server == shards[j].Server {
|
||||||
|
less = shards[i].ShardID < shards[j].ShardID // Secondary sort by shard ID
|
||||||
|
} else {
|
||||||
|
less = shards[i].Server < shards[j].Server
|
||||||
|
}
|
||||||
|
case "data_center":
|
||||||
|
if shards[i].DataCenter == shards[j].DataCenter {
|
||||||
|
less = shards[i].ShardID < shards[j].ShardID // Secondary sort by shard ID
|
||||||
|
} else {
|
||||||
|
less = shards[i].DataCenter < shards[j].DataCenter
|
||||||
|
}
|
||||||
|
case "rack":
|
||||||
|
if shards[i].Rack == shards[j].Rack {
|
||||||
|
less = shards[i].ShardID < shards[j].ShardID // Secondary sort by shard ID
|
||||||
|
} else {
|
||||||
|
less = shards[i].Rack < shards[j].Rack
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
less = shards[i].ShardID < shards[j].ShardID
|
||||||
|
}
|
||||||
|
|
||||||
|
if sortOrder == "desc" {
|
||||||
|
return !less
|
||||||
|
}
|
||||||
|
return less
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetEcVolumeDetails retrieves detailed information about a specific EC volume
|
||||||
|
func (s *AdminServer) GetEcVolumeDetails(volumeID uint32, sortBy string, sortOrder string) (*EcVolumeDetailsData, error) {
|
||||||
|
// Set defaults
|
||||||
|
if sortBy == "" {
|
||||||
|
sortBy = "shard_id"
|
||||||
|
}
|
||||||
|
if sortOrder == "" {
|
||||||
|
sortOrder = "asc"
|
||||||
|
}
|
||||||
|
|
||||||
|
var shards []EcShardWithInfo
|
||||||
|
var collection string
|
||||||
|
dataCenters := make(map[string]bool)
|
||||||
|
servers := make(map[string]bool)
|
||||||
|
|
||||||
|
// Get detailed EC shard information for the specific volume via gRPC
|
||||||
|
err := s.WithMasterClient(func(client master_pb.SeaweedClient) error {
|
||||||
|
resp, err := client.VolumeList(context.Background(), &master_pb.VolumeListRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.TopologyInfo != nil {
|
||||||
|
for _, dc := range resp.TopologyInfo.DataCenterInfos {
|
||||||
|
for _, rack := range dc.RackInfos {
|
||||||
|
for _, node := range rack.DataNodeInfos {
|
||||||
|
for _, diskInfo := range node.DiskInfos {
|
||||||
|
// Process EC shard information for this specific volume
|
||||||
|
for _, ecShardInfo := range diskInfo.EcShardInfos {
|
||||||
|
if ecShardInfo.Id == volumeID {
|
||||||
|
collection = ecShardInfo.Collection
|
||||||
|
dataCenters[dc.Id] = true
|
||||||
|
servers[node.Id] = true
|
||||||
|
|
||||||
|
// Create individual shard entries for each shard this server has
|
||||||
|
shardBits := ecShardInfo.EcIndexBits
|
||||||
|
for shardId := 0; shardId < erasure_coding.TotalShardsCount; shardId++ {
|
||||||
|
if (shardBits & (1 << uint(shardId))) != 0 {
|
||||||
|
ecShard := EcShardWithInfo{
|
||||||
|
VolumeID: ecShardInfo.Id,
|
||||||
|
ShardID: uint32(shardId),
|
||||||
|
Collection: ecShardInfo.Collection,
|
||||||
|
Size: 0, // EC shards don't have individual size in the API response
|
||||||
|
Server: node.Id,
|
||||||
|
DataCenter: dc.Id,
|
||||||
|
Rack: rack.Id,
|
||||||
|
DiskType: diskInfo.Type,
|
||||||
|
ModifiedTime: 0, // Not available in current API
|
||||||
|
EcIndexBits: ecShardInfo.EcIndexBits,
|
||||||
|
ShardCount: getShardCount(ecShardInfo.EcIndexBits),
|
||||||
|
}
|
||||||
|
shards = append(shards, ecShard)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(shards) == 0 {
|
||||||
|
return nil, fmt.Errorf("EC volume %d not found", volumeID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect shard size information from volume servers
|
||||||
|
shardSizeMap := make(map[string]map[uint32]uint64) // server -> shardId -> size
|
||||||
|
for _, shard := range shards {
|
||||||
|
server := shard.Server
|
||||||
|
if _, exists := shardSizeMap[server]; !exists {
|
||||||
|
// Query this server for shard sizes
|
||||||
|
err := s.WithVolumeServerClient(pb.ServerAddress(server), func(client volume_server_pb.VolumeServerClient) error {
|
||||||
|
resp, err := client.VolumeEcShardsInfo(context.Background(), &volume_server_pb.VolumeEcShardsInfoRequest{
|
||||||
|
VolumeId: volumeID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
glog.V(1).Infof("Failed to get EC shard info from %s for volume %d: %v", server, volumeID, err)
|
||||||
|
return nil // Continue with other servers, don't fail the entire request
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store shard sizes for this server
|
||||||
|
shardSizeMap[server] = make(map[uint32]uint64)
|
||||||
|
for _, shardInfo := range resp.EcShardInfos {
|
||||||
|
shardSizeMap[server][shardInfo.ShardId] = uint64(shardInfo.Size)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
glog.V(1).Infof("Failed to connect to volume server %s: %v", server, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update shard sizes in the shards array
|
||||||
|
for i := range shards {
|
||||||
|
server := shards[i].Server
|
||||||
|
shardId := shards[i].ShardID
|
||||||
|
if serverSizes, exists := shardSizeMap[server]; exists {
|
||||||
|
if size, exists := serverSizes[shardId]; exists {
|
||||||
|
shards[i].Size = size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate completeness based on unique shard IDs
|
||||||
|
foundShards := make(map[int]bool)
|
||||||
|
for _, shard := range shards {
|
||||||
|
foundShards[int(shard.ShardID)] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
totalUniqueShards := len(foundShards)
|
||||||
|
isComplete := (totalUniqueShards == erasure_coding.TotalShardsCount)
|
||||||
|
|
||||||
|
// Calculate missing shards
|
||||||
|
var missingShards []int
|
||||||
|
for i := 0; i < erasure_coding.TotalShardsCount; i++ {
|
||||||
|
if !foundShards[i] {
|
||||||
|
missingShards = append(missingShards, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update completeness info for each shard
|
||||||
|
for i := range shards {
|
||||||
|
shards[i].IsComplete = isComplete
|
||||||
|
shards[i].MissingShards = missingShards
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort shards based on parameters
|
||||||
|
sortEcShards(shards, sortBy, sortOrder)
|
||||||
|
|
||||||
|
// Convert maps to slices
|
||||||
|
var dcList []string
|
||||||
|
for dc := range dataCenters {
|
||||||
|
dcList = append(dcList, dc)
|
||||||
|
}
|
||||||
|
var serverList []string
|
||||||
|
for server := range servers {
|
||||||
|
serverList = append(serverList, server)
|
||||||
|
}
|
||||||
|
|
||||||
|
data := &EcVolumeDetailsData{
|
||||||
|
VolumeID: volumeID,
|
||||||
|
Collection: collection,
|
||||||
|
Shards: shards,
|
||||||
|
TotalShards: totalUniqueShards,
|
||||||
|
IsComplete: isComplete,
|
||||||
|
MissingShards: missingShards,
|
||||||
|
DataCenters: dcList,
|
||||||
|
Servers: serverList,
|
||||||
|
LastUpdated: time.Now(),
|
||||||
|
SortBy: sortBy,
|
||||||
|
SortOrder: sortOrder,
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
+156
-6
@@ -135,6 +135,84 @@ type ClusterVolumesData struct {
|
|||||||
FilterCollection string `json:"filter_collection"`
|
FilterCollection string `json:"filter_collection"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClusterEcShardsData represents the data for the cluster EC shards page
|
||||||
|
type ClusterEcShardsData struct {
|
||||||
|
Username string `json:"username"`
|
||||||
|
EcShards []EcShardWithInfo `json:"ec_shards"`
|
||||||
|
TotalShards int `json:"total_shards"`
|
||||||
|
TotalVolumes int `json:"total_volumes"`
|
||||||
|
LastUpdated time.Time `json:"last_updated"`
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
CurrentPage int `json:"current_page"`
|
||||||
|
TotalPages int `json:"total_pages"`
|
||||||
|
PageSize int `json:"page_size"`
|
||||||
|
|
||||||
|
// Sorting
|
||||||
|
SortBy string `json:"sort_by"`
|
||||||
|
SortOrder string `json:"sort_order"`
|
||||||
|
|
||||||
|
// Statistics
|
||||||
|
DataCenterCount int `json:"datacenter_count"`
|
||||||
|
RackCount int `json:"rack_count"`
|
||||||
|
CollectionCount int `json:"collection_count"`
|
||||||
|
|
||||||
|
// Conditional display flags
|
||||||
|
ShowDataCenterColumn bool `json:"show_datacenter_column"`
|
||||||
|
ShowRackColumn bool `json:"show_rack_column"`
|
||||||
|
ShowCollectionColumn bool `json:"show_collection_column"`
|
||||||
|
|
||||||
|
// Single values when only one exists
|
||||||
|
SingleDataCenter string `json:"single_datacenter"`
|
||||||
|
SingleRack string `json:"single_rack"`
|
||||||
|
SingleCollection string `json:"single_collection"`
|
||||||
|
|
||||||
|
// Filtering
|
||||||
|
FilterCollection string `json:"filter_collection"`
|
||||||
|
|
||||||
|
// EC specific statistics
|
||||||
|
ShardsPerVolume map[uint32]int `json:"shards_per_volume"` // VolumeID -> shard count
|
||||||
|
VolumesWithAllShards int `json:"volumes_with_all_shards"` // Volumes with all 14 shards
|
||||||
|
VolumesWithMissingShards int `json:"volumes_with_missing_shards"` // Volumes missing shards
|
||||||
|
}
|
||||||
|
|
||||||
|
// EcShardWithInfo represents an EC shard with its topology information
|
||||||
|
type EcShardWithInfo struct {
|
||||||
|
VolumeID uint32 `json:"volume_id"`
|
||||||
|
ShardID uint32 `json:"shard_id"`
|
||||||
|
Collection string `json:"collection"`
|
||||||
|
Size uint64 `json:"size"`
|
||||||
|
Server string `json:"server"`
|
||||||
|
DataCenter string `json:"datacenter"`
|
||||||
|
Rack string `json:"rack"`
|
||||||
|
DiskType string `json:"disk_type"`
|
||||||
|
ModifiedTime int64 `json:"modified_time"`
|
||||||
|
|
||||||
|
// EC specific fields
|
||||||
|
EcIndexBits uint32 `json:"ec_index_bits"` // Bitmap of which shards this server has
|
||||||
|
ShardCount int `json:"shard_count"` // Number of shards this server has for this volume
|
||||||
|
IsComplete bool `json:"is_complete"` // True if this volume has all 14 shards
|
||||||
|
MissingShards []int `json:"missing_shards"` // List of missing shard IDs
|
||||||
|
}
|
||||||
|
|
||||||
|
// EcVolumeDetailsData represents the data for the EC volume details page
|
||||||
|
type EcVolumeDetailsData struct {
|
||||||
|
Username string `json:"username"`
|
||||||
|
VolumeID uint32 `json:"volume_id"`
|
||||||
|
Collection string `json:"collection"`
|
||||||
|
Shards []EcShardWithInfo `json:"shards"`
|
||||||
|
TotalShards int `json:"total_shards"`
|
||||||
|
IsComplete bool `json:"is_complete"`
|
||||||
|
MissingShards []int `json:"missing_shards"`
|
||||||
|
DataCenters []string `json:"datacenters"`
|
||||||
|
Servers []string `json:"servers"`
|
||||||
|
LastUpdated time.Time `json:"last_updated"`
|
||||||
|
|
||||||
|
// Sorting
|
||||||
|
SortBy string `json:"sort_by"`
|
||||||
|
SortOrder string `json:"sort_order"`
|
||||||
|
}
|
||||||
|
|
||||||
type VolumeDetailsData struct {
|
type VolumeDetailsData struct {
|
||||||
Volume VolumeWithTopology `json:"volume"`
|
Volume VolumeWithTopology `json:"volume"`
|
||||||
Replicas []VolumeWithTopology `json:"replicas"`
|
Replicas []VolumeWithTopology `json:"replicas"`
|
||||||
@@ -145,12 +223,13 @@ type VolumeDetailsData struct {
|
|||||||
|
|
||||||
// Collection management structures
|
// Collection management structures
|
||||||
type CollectionInfo struct {
|
type CollectionInfo struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
DataCenter string `json:"datacenter"`
|
DataCenter string `json:"datacenter"`
|
||||||
VolumeCount int `json:"volume_count"`
|
VolumeCount int `json:"volume_count"`
|
||||||
FileCount int64 `json:"file_count"`
|
EcVolumeCount int `json:"ec_volume_count"`
|
||||||
TotalSize int64 `json:"total_size"`
|
FileCount int64 `json:"file_count"`
|
||||||
DiskTypes []string `json:"disk_types"`
|
TotalSize int64 `json:"total_size"`
|
||||||
|
DiskTypes []string `json:"disk_types"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClusterCollectionsData struct {
|
type ClusterCollectionsData struct {
|
||||||
@@ -158,6 +237,7 @@ type ClusterCollectionsData struct {
|
|||||||
Collections []CollectionInfo `json:"collections"`
|
Collections []CollectionInfo `json:"collections"`
|
||||||
TotalCollections int `json:"total_collections"`
|
TotalCollections int `json:"total_collections"`
|
||||||
TotalVolumes int `json:"total_volumes"`
|
TotalVolumes int `json:"total_volumes"`
|
||||||
|
TotalEcVolumes int `json:"total_ec_volumes"`
|
||||||
TotalFiles int64 `json:"total_files"`
|
TotalFiles int64 `json:"total_files"`
|
||||||
TotalSize int64 `json:"total_size"`
|
TotalSize int64 `json:"total_size"`
|
||||||
LastUpdated time.Time `json:"last_updated"`
|
LastUpdated time.Time `json:"last_updated"`
|
||||||
@@ -376,3 +456,73 @@ type MaintenanceWorkersData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Maintenance system types are now in weed/admin/maintenance package
|
// Maintenance system types are now in weed/admin/maintenance package
|
||||||
|
|
||||||
|
// EcVolumeWithShards represents an EC volume with its shard distribution
|
||||||
|
type EcVolumeWithShards struct {
|
||||||
|
VolumeID uint32 `json:"volume_id"`
|
||||||
|
Collection string `json:"collection"`
|
||||||
|
TotalShards int `json:"total_shards"`
|
||||||
|
IsComplete bool `json:"is_complete"`
|
||||||
|
MissingShards []int `json:"missing_shards"`
|
||||||
|
ShardLocations map[int]string `json:"shard_locations"` // shardId -> server
|
||||||
|
ShardSizes map[int]int64 `json:"shard_sizes"` // shardId -> size in bytes
|
||||||
|
DataCenters []string `json:"data_centers"`
|
||||||
|
Servers []string `json:"servers"`
|
||||||
|
ModifiedTime int64 `json:"modified_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClusterEcVolumesData represents the response for clustered EC volumes view
|
||||||
|
type ClusterEcVolumesData struct {
|
||||||
|
EcVolumes []EcVolumeWithShards `json:"ec_volumes"`
|
||||||
|
TotalVolumes int `json:"total_volumes"`
|
||||||
|
LastUpdated time.Time `json:"last_updated"`
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
Page int `json:"page"`
|
||||||
|
PageSize int `json:"page_size"`
|
||||||
|
TotalPages int `json:"total_pages"`
|
||||||
|
|
||||||
|
// Sorting
|
||||||
|
SortBy string `json:"sort_by"`
|
||||||
|
SortOrder string `json:"sort_order"`
|
||||||
|
|
||||||
|
// Filtering
|
||||||
|
Collection string `json:"collection"`
|
||||||
|
|
||||||
|
// Conditional display flags
|
||||||
|
ShowDataCenterColumn bool `json:"show_datacenter_column"`
|
||||||
|
ShowRackColumn bool `json:"show_rack_column"`
|
||||||
|
ShowCollectionColumn bool `json:"show_collection_column"`
|
||||||
|
|
||||||
|
// Statistics
|
||||||
|
CompleteVolumes int `json:"complete_volumes"`
|
||||||
|
IncompleteVolumes int `json:"incomplete_volumes"`
|
||||||
|
TotalShards int `json:"total_shards"`
|
||||||
|
|
||||||
|
// User context
|
||||||
|
Username string `json:"username"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collection detail page structures
|
||||||
|
type CollectionDetailsData struct {
|
||||||
|
Username string `json:"username"`
|
||||||
|
CollectionName string `json:"collection_name"`
|
||||||
|
RegularVolumes []VolumeWithTopology `json:"regular_volumes"`
|
||||||
|
EcVolumes []EcVolumeWithShards `json:"ec_volumes"`
|
||||||
|
TotalVolumes int `json:"total_volumes"`
|
||||||
|
TotalEcVolumes int `json:"total_ec_volumes"`
|
||||||
|
TotalFiles int64 `json:"total_files"`
|
||||||
|
TotalSize int64 `json:"total_size"`
|
||||||
|
DataCenters []string `json:"data_centers"`
|
||||||
|
DiskTypes []string `json:"disk_types"`
|
||||||
|
LastUpdated time.Time `json:"last_updated"`
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
Page int `json:"page"`
|
||||||
|
PageSize int `json:"page_size"`
|
||||||
|
TotalPages int `json:"total_pages"`
|
||||||
|
|
||||||
|
// Sorting
|
||||||
|
SortBy string `json:"sort_by"`
|
||||||
|
SortOrder string `json:"sort_order"`
|
||||||
|
}
|
||||||
@@ -319,14 +319,35 @@ func (s *WorkerGrpcServer) handleHeartbeat(conn *WorkerConnection, heartbeat *wo
|
|||||||
|
|
||||||
// handleTaskRequest processes task requests from workers
|
// handleTaskRequest processes task requests from workers
|
||||||
func (s *WorkerGrpcServer) handleTaskRequest(conn *WorkerConnection, request *worker_pb.TaskRequest) {
|
func (s *WorkerGrpcServer) handleTaskRequest(conn *WorkerConnection, request *worker_pb.TaskRequest) {
|
||||||
|
glog.Infof("DEBUG handleTaskRequest: Worker %s requesting tasks with capabilities %v", conn.workerID, conn.capabilities)
|
||||||
|
|
||||||
if s.adminServer.maintenanceManager == nil {
|
if s.adminServer.maintenanceManager == nil {
|
||||||
|
glog.Infof("DEBUG handleTaskRequest: maintenance manager is nil")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get next task from maintenance manager
|
// Get next task from maintenance manager
|
||||||
task := s.adminServer.maintenanceManager.GetNextTask(conn.workerID, conn.capabilities)
|
task := s.adminServer.maintenanceManager.GetNextTask(conn.workerID, conn.capabilities)
|
||||||
|
glog.Infof("DEBUG handleTaskRequest: GetNextTask returned task: %v", task != nil)
|
||||||
|
|
||||||
if task != nil {
|
if task != nil {
|
||||||
|
glog.Infof("DEBUG handleTaskRequest: Assigning task %s (type: %s) to worker %s", task.ID, task.Type, conn.workerID)
|
||||||
|
|
||||||
|
// Add master client address to task parameters
|
||||||
|
taskParams := make(map[string]interface{})
|
||||||
|
// Copy existing parameters
|
||||||
|
for k, v := range task.Parameters {
|
||||||
|
taskParams[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add master_client parameter for tasks that need it (especially EC tasks)
|
||||||
|
if currentMaster := s.adminServer.masterClient.GetMaster(context.Background()); currentMaster != "" {
|
||||||
|
taskParams["master_client"] = string(currentMaster)
|
||||||
|
glog.V(2).Infof("Added master_client parameter to task %s: %s", task.ID, currentMaster)
|
||||||
|
} else {
|
||||||
|
glog.Warningf("No master address available for task %s", task.ID)
|
||||||
|
}
|
||||||
|
|
||||||
// Send task assignment
|
// Send task assignment
|
||||||
assignment := &worker_pb.AdminMessage{
|
assignment := &worker_pb.AdminMessage{
|
||||||
Timestamp: time.Now().Unix(),
|
Timestamp: time.Now().Unix(),
|
||||||
@@ -338,7 +359,7 @@ func (s *WorkerGrpcServer) handleTaskRequest(conn *WorkerConnection, request *wo
|
|||||||
VolumeId: task.VolumeID,
|
VolumeId: task.VolumeID,
|
||||||
Server: task.Server,
|
Server: task.Server,
|
||||||
Collection: task.Collection,
|
Collection: task.Collection,
|
||||||
Parameters: convertTaskParameters(task.Parameters),
|
Parameters: convertTaskParameters(taskParams),
|
||||||
},
|
},
|
||||||
Priority: int32(task.Priority),
|
Priority: int32(task.Priority),
|
||||||
CreatedTime: time.Now().Unix(),
|
CreatedTime: time.Now().Unix(),
|
||||||
@@ -348,10 +369,12 @@ func (s *WorkerGrpcServer) handleTaskRequest(conn *WorkerConnection, request *wo
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case conn.outgoing <- assignment:
|
case conn.outgoing <- assignment:
|
||||||
glog.V(2).Infof("Assigned task %s to worker %s", task.ID, conn.workerID)
|
glog.Infof("DEBUG handleTaskRequest: Successfully assigned task %s to worker %s", task.ID, conn.workerID)
|
||||||
case <-time.After(time.Second):
|
case <-time.After(time.Second):
|
||||||
glog.Warningf("Failed to send task assignment to worker %s", conn.workerID)
|
glog.Warningf("Failed to send task assignment to worker %s", conn.workerID)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
glog.Infof("DEBUG handleTaskRequest: No tasks available for worker %s", conn.workerID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ func (h *AdminHandlers) SetupRoutes(r *gin.Engine, authRequired bool, username,
|
|||||||
protected.GET("/cluster/volumes", h.clusterHandlers.ShowClusterVolumes)
|
protected.GET("/cluster/volumes", h.clusterHandlers.ShowClusterVolumes)
|
||||||
protected.GET("/cluster/volumes/:id/:server", h.clusterHandlers.ShowVolumeDetails)
|
protected.GET("/cluster/volumes/:id/:server", h.clusterHandlers.ShowVolumeDetails)
|
||||||
protected.GET("/cluster/collections", h.clusterHandlers.ShowClusterCollections)
|
protected.GET("/cluster/collections", h.clusterHandlers.ShowClusterCollections)
|
||||||
|
protected.GET("/cluster/collections/:name", h.clusterHandlers.ShowCollectionDetails)
|
||||||
|
protected.GET("/cluster/ec-shards", h.clusterHandlers.ShowClusterEcShards)
|
||||||
|
protected.GET("/cluster/ec-volumes/:id", h.clusterHandlers.ShowEcVolumeDetails)
|
||||||
|
|
||||||
// Message Queue management routes
|
// Message Queue management routes
|
||||||
protected.GET("/mq/brokers", h.mqHandlers.ShowBrokers)
|
protected.GET("/mq/brokers", h.mqHandlers.ShowBrokers)
|
||||||
@@ -198,6 +201,9 @@ func (h *AdminHandlers) SetupRoutes(r *gin.Engine, authRequired bool, username,
|
|||||||
r.GET("/cluster/volumes", h.clusterHandlers.ShowClusterVolumes)
|
r.GET("/cluster/volumes", h.clusterHandlers.ShowClusterVolumes)
|
||||||
r.GET("/cluster/volumes/:id/:server", h.clusterHandlers.ShowVolumeDetails)
|
r.GET("/cluster/volumes/:id/:server", h.clusterHandlers.ShowVolumeDetails)
|
||||||
r.GET("/cluster/collections", h.clusterHandlers.ShowClusterCollections)
|
r.GET("/cluster/collections", h.clusterHandlers.ShowClusterCollections)
|
||||||
|
r.GET("/cluster/collections/:name", h.clusterHandlers.ShowCollectionDetails)
|
||||||
|
r.GET("/cluster/ec-shards", h.clusterHandlers.ShowClusterEcShards)
|
||||||
|
r.GET("/cluster/ec-volumes/:id", h.clusterHandlers.ShowEcVolumeDetails)
|
||||||
|
|
||||||
// Message Queue management routes
|
// Message Queue management routes
|
||||||
r.GET("/mq/brokers", h.mqHandlers.ShowBrokers)
|
r.GET("/mq/brokers", h.mqHandlers.ShowBrokers)
|
||||||
|
|||||||
@@ -161,6 +161,123 @@ func (h *ClusterHandlers) ShowClusterCollections(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShowCollectionDetails renders the collection detail page
|
||||||
|
func (h *ClusterHandlers) ShowCollectionDetails(c *gin.Context) {
|
||||||
|
collectionName := c.Param("name")
|
||||||
|
if collectionName == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Collection name is required"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse query parameters
|
||||||
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||||
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "25"))
|
||||||
|
sortBy := c.DefaultQuery("sort_by", "volume_id")
|
||||||
|
sortOrder := c.DefaultQuery("sort_order", "asc")
|
||||||
|
|
||||||
|
// Get collection details data (volumes and EC volumes)
|
||||||
|
collectionDetailsData, err := h.adminServer.GetCollectionDetails(collectionName, page, pageSize, sortBy, sortOrder)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get collection details: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set username
|
||||||
|
username := c.GetString("username")
|
||||||
|
if username == "" {
|
||||||
|
username = "admin"
|
||||||
|
}
|
||||||
|
collectionDetailsData.Username = username
|
||||||
|
|
||||||
|
// Render HTML template
|
||||||
|
c.Header("Content-Type", "text/html")
|
||||||
|
collectionDetailsComponent := app.CollectionDetails(*collectionDetailsData)
|
||||||
|
layoutComponent := layout.Layout(c, collectionDetailsComponent)
|
||||||
|
err = layoutComponent.Render(c.Request.Context(), c.Writer)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to render template: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShowClusterEcShards handles the cluster EC shards page (individual shards view)
|
||||||
|
func (h *ClusterHandlers) ShowClusterEcShards(c *gin.Context) {
|
||||||
|
// Parse query parameters
|
||||||
|
page, _ := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||||
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "100"))
|
||||||
|
sortBy := c.DefaultQuery("sort_by", "volume_id")
|
||||||
|
sortOrder := c.DefaultQuery("sort_order", "asc")
|
||||||
|
collection := c.DefaultQuery("collection", "")
|
||||||
|
|
||||||
|
// Get data from admin server
|
||||||
|
data, err := h.adminServer.GetClusterEcVolumes(page, pageSize, sortBy, sortOrder, collection)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set username
|
||||||
|
username := c.GetString("username")
|
||||||
|
if username == "" {
|
||||||
|
username = "admin"
|
||||||
|
}
|
||||||
|
data.Username = username
|
||||||
|
|
||||||
|
// Render template
|
||||||
|
c.Header("Content-Type", "text/html")
|
||||||
|
ecVolumesComponent := app.ClusterEcVolumes(*data)
|
||||||
|
layoutComponent := layout.Layout(c, ecVolumesComponent)
|
||||||
|
err = layoutComponent.Render(c.Request.Context(), c.Writer)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShowEcVolumeDetails renders the EC volume details page
|
||||||
|
func (h *ClusterHandlers) ShowEcVolumeDetails(c *gin.Context) {
|
||||||
|
volumeIDStr := c.Param("id")
|
||||||
|
|
||||||
|
if volumeIDStr == "" {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Volume ID is required"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
volumeID, err := strconv.Atoi(volumeIDStr)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid volume ID"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse sorting parameters
|
||||||
|
sortBy := c.DefaultQuery("sort_by", "shard_id")
|
||||||
|
sortOrder := c.DefaultQuery("sort_order", "asc")
|
||||||
|
|
||||||
|
// Get EC volume details
|
||||||
|
ecVolumeDetails, err := h.adminServer.GetEcVolumeDetails(uint32(volumeID), sortBy, sortOrder)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get EC volume details: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set username
|
||||||
|
username := c.GetString("username")
|
||||||
|
if username == "" {
|
||||||
|
username = "admin"
|
||||||
|
}
|
||||||
|
ecVolumeDetails.Username = username
|
||||||
|
|
||||||
|
// Render HTML template
|
||||||
|
c.Header("Content-Type", "text/html")
|
||||||
|
ecVolumeDetailsComponent := app.EcVolumeDetails(*ecVolumeDetails)
|
||||||
|
layoutComponent := layout.Layout(c, ecVolumeDetailsComponent)
|
||||||
|
err = layoutComponent.Render(c.Request.Context(), c.Writer)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to render template: " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ShowClusterMasters renders the cluster masters page
|
// ShowClusterMasters renders the cluster masters page
|
||||||
func (h *ClusterHandlers) ShowClusterMasters(c *gin.Context) {
|
func (h *ClusterHandlers) ShowClusterMasters(c *gin.Context) {
|
||||||
// Get cluster masters data
|
// Get cluster masters data
|
||||||
|
|||||||
@@ -1,16 +1,24 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/admin/maintenance"
|
"github.com/seaweedfs/seaweedfs/weed/admin/maintenance"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/admin/view/app"
|
"github.com/seaweedfs/seaweedfs/weed/admin/view/app"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/admin/view/components"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/admin/view/layout"
|
"github.com/seaweedfs/seaweedfs/weed/admin/view/layout"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/balance"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/erasure_coding"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/vacuum"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,19 +38,31 @@ func NewMaintenanceHandlers(adminServer *dash.AdminServer) *MaintenanceHandlers
|
|||||||
func (h *MaintenanceHandlers) ShowMaintenanceQueue(c *gin.Context) {
|
func (h *MaintenanceHandlers) ShowMaintenanceQueue(c *gin.Context) {
|
||||||
data, err := h.getMaintenanceQueueData()
|
data, err := h.getMaintenanceQueueData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
glog.Infof("DEBUG ShowMaintenanceQueue: error getting data: %v", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glog.Infof("DEBUG ShowMaintenanceQueue: got data with %d tasks", len(data.Tasks))
|
||||||
|
if data.Stats != nil {
|
||||||
|
glog.Infof("DEBUG ShowMaintenanceQueue: stats = {pending: %d, running: %d, completed: %d}",
|
||||||
|
data.Stats.PendingTasks, data.Stats.RunningTasks, data.Stats.CompletedToday)
|
||||||
|
} else {
|
||||||
|
glog.Infof("DEBUG ShowMaintenanceQueue: stats is nil")
|
||||||
|
}
|
||||||
|
|
||||||
// Render HTML template
|
// Render HTML template
|
||||||
c.Header("Content-Type", "text/html")
|
c.Header("Content-Type", "text/html")
|
||||||
maintenanceComponent := app.MaintenanceQueue(data)
|
maintenanceComponent := app.MaintenanceQueue(data)
|
||||||
layoutComponent := layout.Layout(c, maintenanceComponent)
|
layoutComponent := layout.Layout(c, maintenanceComponent)
|
||||||
err = layoutComponent.Render(c.Request.Context(), c.Writer)
|
err = layoutComponent.Render(c.Request.Context(), c.Writer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
glog.Infof("DEBUG ShowMaintenanceQueue: render error: %v", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to render template: " + err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to render template: " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glog.Infof("DEBUG ShowMaintenanceQueue: template rendered successfully")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowMaintenanceWorkers displays the maintenance workers page
|
// ShowMaintenanceWorkers displays the maintenance workers page
|
||||||
@@ -66,41 +86,52 @@ func (h *MaintenanceHandlers) ShowMaintenanceWorkers(c *gin.Context) {
|
|||||||
|
|
||||||
// ShowMaintenanceConfig displays the maintenance configuration page
|
// ShowMaintenanceConfig displays the maintenance configuration page
|
||||||
func (h *MaintenanceHandlers) ShowMaintenanceConfig(c *gin.Context) {
|
func (h *MaintenanceHandlers) ShowMaintenanceConfig(c *gin.Context) {
|
||||||
|
// DEBUG: Log that this method is being called
|
||||||
|
glog.Infof("DEBUG: MaintenanceHandlers.ShowMaintenanceConfig called")
|
||||||
|
|
||||||
config, err := h.getMaintenanceConfig()
|
config, err := h.getMaintenanceConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
glog.Errorf("DEBUG: Error getting maintenance config: %v", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render HTML template
|
// Get the schema for dynamic form rendering
|
||||||
|
schema := maintenance.GetMaintenanceConfigSchema()
|
||||||
|
glog.Infof("DEBUG: Got schema with %d fields", len(schema.Fields))
|
||||||
|
|
||||||
|
// Render HTML template using schema-driven approach
|
||||||
c.Header("Content-Type", "text/html")
|
c.Header("Content-Type", "text/html")
|
||||||
configComponent := app.MaintenanceConfig(config)
|
configComponent := app.MaintenanceConfigSchema(config, schema)
|
||||||
layoutComponent := layout.Layout(c, configComponent)
|
layoutComponent := layout.Layout(c, configComponent)
|
||||||
|
glog.Infof("DEBUG: About to render MaintenanceConfigSchema template")
|
||||||
err = layoutComponent.Render(c.Request.Context(), c.Writer)
|
err = layoutComponent.Render(c.Request.Context(), c.Writer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
glog.Errorf("DEBUG: Template render error: %v", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to render template: " + err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to render template: " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
glog.Infof("DEBUG: MaintenanceConfigSchema template rendered successfully")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowTaskConfig displays the configuration page for a specific task type
|
// ShowTaskConfig displays the configuration page for a specific task type
|
||||||
func (h *MaintenanceHandlers) ShowTaskConfig(c *gin.Context) {
|
func (h *MaintenanceHandlers) ShowTaskConfig(c *gin.Context) {
|
||||||
taskTypeName := c.Param("taskType")
|
taskTypeName := c.Param("taskType")
|
||||||
|
|
||||||
// Get the task type
|
// Get the schema for this task type
|
||||||
taskType := maintenance.GetMaintenanceTaskType(taskTypeName)
|
schema := tasks.GetTaskConfigSchema(taskTypeName)
|
||||||
if taskType == "" {
|
if schema == nil {
|
||||||
c.JSON(http.StatusNotFound, gin.H{"error": "Task type not found"})
|
c.JSON(http.StatusNotFound, gin.H{"error": "Task type not found or no schema available"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the UI provider for this task type
|
// Get the UI provider for current configuration
|
||||||
uiRegistry := tasks.GetGlobalUIRegistry()
|
uiRegistry := tasks.GetGlobalUIRegistry()
|
||||||
typesRegistry := tasks.GetGlobalTypesRegistry()
|
typesRegistry := tasks.GetGlobalTypesRegistry()
|
||||||
|
|
||||||
var provider types.TaskUIProvider
|
var provider types.TaskUIProvider
|
||||||
for workerTaskType := range typesRegistry.GetAllDetectors() {
|
for workerTaskType := range typesRegistry.GetAllDetectors() {
|
||||||
if string(workerTaskType) == string(taskType) {
|
if string(workerTaskType) == taskTypeName {
|
||||||
provider = uiRegistry.GetProvider(workerTaskType)
|
provider = uiRegistry.GetProvider(workerTaskType)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -111,73 +142,25 @@ func (h *MaintenanceHandlers) ShowTaskConfig(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get templ UI provider first - temporarily disabled
|
// Get current configuration
|
||||||
// templUIProvider := getTemplUIProvider(taskType)
|
currentConfig := provider.GetCurrentConfig()
|
||||||
var configSections []components.ConfigSectionData
|
|
||||||
|
|
||||||
// Temporarily disabled templ UI provider
|
// Apply schema defaults to ensure all fields have values
|
||||||
// if templUIProvider != nil {
|
if err := schema.ApplyDefaults(currentConfig); err != nil {
|
||||||
// // Use the new templ-based UI provider
|
glog.Errorf("Failed to apply schema defaults for %s: %v", taskTypeName, err)
|
||||||
// currentConfig := templUIProvider.GetCurrentConfig()
|
|
||||||
// sections, err := templUIProvider.RenderConfigSections(currentConfig)
|
|
||||||
// if err != nil {
|
|
||||||
// c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to render configuration sections: " + err.Error()})
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// configSections = sections
|
|
||||||
// } else {
|
|
||||||
// Fallback to basic configuration for providers that haven't been migrated yet
|
|
||||||
configSections = []components.ConfigSectionData{
|
|
||||||
{
|
|
||||||
Title: "Configuration Settings",
|
|
||||||
Icon: "fas fa-cogs",
|
|
||||||
Description: "Configure task detection and scheduling parameters",
|
|
||||||
Fields: []interface{}{
|
|
||||||
components.CheckboxFieldData{
|
|
||||||
FormFieldData: components.FormFieldData{
|
|
||||||
Name: "enabled",
|
|
||||||
Label: "Enable Task",
|
|
||||||
Description: "Whether this task type should be enabled",
|
|
||||||
},
|
|
||||||
Checked: true,
|
|
||||||
},
|
|
||||||
components.NumberFieldData{
|
|
||||||
FormFieldData: components.FormFieldData{
|
|
||||||
Name: "max_concurrent",
|
|
||||||
Label: "Max Concurrent Tasks",
|
|
||||||
Description: "Maximum number of concurrent tasks",
|
|
||||||
Required: true,
|
|
||||||
},
|
|
||||||
Value: 2,
|
|
||||||
Step: "1",
|
|
||||||
Min: floatPtr(1),
|
|
||||||
},
|
|
||||||
components.DurationFieldData{
|
|
||||||
FormFieldData: components.FormFieldData{
|
|
||||||
Name: "scan_interval",
|
|
||||||
Label: "Scan Interval",
|
|
||||||
Description: "How often to scan for tasks",
|
|
||||||
Required: true,
|
|
||||||
},
|
|
||||||
Value: "30m",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
// } // End of disabled templ UI provider else block
|
|
||||||
|
|
||||||
// Create task configuration data using templ components
|
|
||||||
configData := &app.TaskConfigTemplData{
|
|
||||||
TaskType: taskType,
|
|
||||||
TaskName: provider.GetDisplayName(),
|
|
||||||
TaskIcon: provider.GetIcon(),
|
|
||||||
Description: provider.GetDescription(),
|
|
||||||
ConfigSections: configSections,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render HTML template using templ components
|
// Create task configuration data
|
||||||
|
configData := &maintenance.TaskConfigData{
|
||||||
|
TaskType: maintenance.MaintenanceTaskType(taskTypeName),
|
||||||
|
TaskName: schema.DisplayName,
|
||||||
|
TaskIcon: schema.Icon,
|
||||||
|
Description: schema.Description,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render HTML template using schema-based approach
|
||||||
c.Header("Content-Type", "text/html")
|
c.Header("Content-Type", "text/html")
|
||||||
taskConfigComponent := app.TaskConfigTempl(configData)
|
taskConfigComponent := app.TaskConfigSchema(configData, schema, currentConfig)
|
||||||
layoutComponent := layout.Layout(c, taskConfigComponent)
|
layoutComponent := layout.Layout(c, taskConfigComponent)
|
||||||
err := layoutComponent.Render(c.Request.Context(), c.Writer)
|
err := layoutComponent.Render(c.Request.Context(), c.Writer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -186,19 +169,10 @@ func (h *MaintenanceHandlers) ShowTaskConfig(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateTaskConfig updates configuration for a specific task type
|
// UpdateTaskConfig updates task configuration from form
|
||||||
func (h *MaintenanceHandlers) UpdateTaskConfig(c *gin.Context) {
|
func (h *MaintenanceHandlers) UpdateTaskConfig(c *gin.Context) {
|
||||||
taskTypeName := c.Param("taskType")
|
taskTypeName := c.Param("taskType")
|
||||||
|
taskType := types.TaskType(taskTypeName)
|
||||||
// Get the task type
|
|
||||||
taskType := maintenance.GetMaintenanceTaskType(taskTypeName)
|
|
||||||
if taskType == "" {
|
|
||||||
c.JSON(http.StatusNotFound, gin.H{"error": "Task type not found"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to get templ UI provider first - temporarily disabled
|
|
||||||
// templUIProvider := getTemplUIProvider(taskType)
|
|
||||||
|
|
||||||
// Parse form data
|
// Parse form data
|
||||||
err := c.Request.ParseForm()
|
err := c.Request.ParseForm()
|
||||||
@@ -207,31 +181,51 @@ func (h *MaintenanceHandlers) UpdateTaskConfig(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert form data to map
|
// Get the task configuration schema
|
||||||
formData := make(map[string][]string)
|
schema := tasks.GetTaskConfigSchema(taskTypeName)
|
||||||
for key, values := range c.Request.PostForm {
|
if schema == nil {
|
||||||
formData[key] = values
|
c.JSON(http.StatusNotFound, gin.H{"error": "Schema not found for task type: " + taskTypeName})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new config instance based on task type and apply schema defaults
|
||||||
var config interface{}
|
var config interface{}
|
||||||
|
switch taskType {
|
||||||
|
case types.TaskTypeVacuum:
|
||||||
|
config = &vacuum.Config{}
|
||||||
|
case types.TaskTypeBalance:
|
||||||
|
config = &balance.Config{}
|
||||||
|
case types.TaskTypeErasureCoding:
|
||||||
|
config = &erasure_coding.Config{}
|
||||||
|
default:
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Unsupported task type: " + taskTypeName})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Temporarily disabled templ UI provider
|
// Apply schema defaults first
|
||||||
// if templUIProvider != nil {
|
if err := schema.ApplyDefaults(config); err != nil {
|
||||||
// // Use the new templ-based UI provider
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to apply defaults: " + err.Error()})
|
||||||
// config, err = templUIProvider.ParseConfigForm(formData)
|
return
|
||||||
// if err != nil {
|
}
|
||||||
// c.JSON(http.StatusBadRequest, gin.H{"error": "Failed to parse configuration: " + err.Error()})
|
|
||||||
// return
|
// Parse form data using schema-based approach
|
||||||
// }
|
err = h.parseTaskConfigFromForm(c.Request.PostForm, schema, config)
|
||||||
// // Apply configuration using templ provider
|
if err != nil {
|
||||||
// err = templUIProvider.ApplyConfig(config)
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Failed to parse configuration: " + err.Error()})
|
||||||
// if err != nil {
|
return
|
||||||
// c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to apply configuration: " + err.Error()})
|
}
|
||||||
// return
|
|
||||||
// }
|
// Validate the configuration
|
||||||
// } else {
|
if validationErrors := schema.ValidateConfig(config); len(validationErrors) > 0 {
|
||||||
// Fallback to old UI provider for tasks that haven't been migrated yet
|
errorMessages := make([]string, len(validationErrors))
|
||||||
// Fallback to old UI provider for tasks that haven't been migrated yet
|
for i, err := range validationErrors {
|
||||||
|
errorMessages[i] = err.Error()
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Configuration validation failed", "details": errorMessages})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply configuration using UIProvider
|
||||||
uiRegistry := tasks.GetGlobalUIRegistry()
|
uiRegistry := tasks.GetGlobalUIRegistry()
|
||||||
typesRegistry := tasks.GetGlobalTypesRegistry()
|
typesRegistry := tasks.GetGlobalTypesRegistry()
|
||||||
|
|
||||||
@@ -248,25 +242,123 @@ func (h *MaintenanceHandlers) UpdateTaskConfig(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse configuration from form using old provider
|
// Apply configuration using provider
|
||||||
config, err = provider.ParseConfigForm(formData)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Failed to parse configuration: " + err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply configuration using old provider
|
|
||||||
err = provider.ApplyConfig(config)
|
err = provider.ApplyConfig(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to apply configuration: " + err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to apply configuration: " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// } // End of disabled templ UI provider else block
|
|
||||||
|
|
||||||
// Redirect back to task configuration page
|
// Redirect back to task configuration page
|
||||||
c.Redirect(http.StatusSeeOther, "/maintenance/config/"+taskTypeName)
|
c.Redirect(http.StatusSeeOther, "/maintenance/config/"+taskTypeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parseTaskConfigFromForm parses form data using schema definitions
|
||||||
|
func (h *MaintenanceHandlers) parseTaskConfigFromForm(formData map[string][]string, schema *tasks.TaskConfigSchema, config interface{}) error {
|
||||||
|
configValue := reflect.ValueOf(config)
|
||||||
|
if configValue.Kind() == reflect.Ptr {
|
||||||
|
configValue = configValue.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if configValue.Kind() != reflect.Struct {
|
||||||
|
return fmt.Errorf("config must be a struct or pointer to struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
configType := configValue.Type()
|
||||||
|
|
||||||
|
for i := 0; i < configValue.NumField(); i++ {
|
||||||
|
field := configValue.Field(i)
|
||||||
|
fieldType := configType.Field(i)
|
||||||
|
|
||||||
|
// Get JSON tag name
|
||||||
|
jsonTag := fieldType.Tag.Get("json")
|
||||||
|
if jsonTag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove options like ",omitempty"
|
||||||
|
if commaIdx := strings.Index(jsonTag, ","); commaIdx > 0 {
|
||||||
|
jsonTag = jsonTag[:commaIdx]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find corresponding schema field
|
||||||
|
schemaField := schema.GetFieldByName(jsonTag)
|
||||||
|
if schemaField == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse value based on field type
|
||||||
|
if err := h.parseFieldFromForm(formData, schemaField, field); err != nil {
|
||||||
|
return fmt.Errorf("error parsing field %s: %w", schemaField.DisplayName, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseFieldFromForm parses a single field value from form data
|
||||||
|
func (h *MaintenanceHandlers) parseFieldFromForm(formData map[string][]string, schemaField *config.Field, fieldValue reflect.Value) error {
|
||||||
|
if !fieldValue.CanSet() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch schemaField.Type {
|
||||||
|
case config.FieldTypeBool:
|
||||||
|
// Checkbox fields - present means true, absent means false
|
||||||
|
_, exists := formData[schemaField.JSONName]
|
||||||
|
fieldValue.SetBool(exists)
|
||||||
|
|
||||||
|
case config.FieldTypeInt:
|
||||||
|
if values, ok := formData[schemaField.JSONName]; ok && len(values) > 0 {
|
||||||
|
if intVal, err := strconv.Atoi(values[0]); err != nil {
|
||||||
|
return fmt.Errorf("invalid integer value: %s", values[0])
|
||||||
|
} else {
|
||||||
|
fieldValue.SetInt(int64(intVal))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case config.FieldTypeFloat:
|
||||||
|
if values, ok := formData[schemaField.JSONName]; ok && len(values) > 0 {
|
||||||
|
if floatVal, err := strconv.ParseFloat(values[0], 64); err != nil {
|
||||||
|
return fmt.Errorf("invalid float value: %s", values[0])
|
||||||
|
} else {
|
||||||
|
fieldValue.SetFloat(floatVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case config.FieldTypeString:
|
||||||
|
if values, ok := formData[schemaField.JSONName]; ok && len(values) > 0 {
|
||||||
|
fieldValue.SetString(values[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
case config.FieldTypeInterval:
|
||||||
|
// Parse interval fields with value + unit
|
||||||
|
valueKey := schemaField.JSONName + "_value"
|
||||||
|
unitKey := schemaField.JSONName + "_unit"
|
||||||
|
|
||||||
|
if valueStrs, ok := formData[valueKey]; ok && len(valueStrs) > 0 {
|
||||||
|
value, err := strconv.Atoi(valueStrs[0])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid interval value: %s", valueStrs[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
unit := "minutes" // default
|
||||||
|
if unitStrs, ok := formData[unitKey]; ok && len(unitStrs) > 0 {
|
||||||
|
unit = unitStrs[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to seconds
|
||||||
|
seconds := config.IntervalValueUnitToSeconds(value, unit)
|
||||||
|
fieldValue.SetInt(int64(seconds))
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unsupported field type: %s", schemaField.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateMaintenanceConfig updates maintenance configuration from form
|
// UpdateMaintenanceConfig updates maintenance configuration from form
|
||||||
func (h *MaintenanceHandlers) UpdateMaintenanceConfig(c *gin.Context) {
|
func (h *MaintenanceHandlers) UpdateMaintenanceConfig(c *gin.Context) {
|
||||||
var config maintenance.MaintenanceConfig
|
var config maintenance.MaintenanceConfig
|
||||||
@@ -302,36 +394,50 @@ func (h *MaintenanceHandlers) getMaintenanceQueueData() (*maintenance.Maintenanc
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &maintenance.MaintenanceQueueData{
|
data := &maintenance.MaintenanceQueueData{
|
||||||
Tasks: tasks,
|
Tasks: tasks,
|
||||||
Workers: workers,
|
Workers: workers,
|
||||||
Stats: stats,
|
Stats: stats,
|
||||||
LastUpdated: time.Now(),
|
LastUpdated: time.Now(),
|
||||||
}, nil
|
}
|
||||||
|
|
||||||
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MaintenanceHandlers) getMaintenanceQueueStats() (*maintenance.QueueStats, error) {
|
func (h *MaintenanceHandlers) getMaintenanceQueueStats() (*maintenance.QueueStats, error) {
|
||||||
// This would integrate with the maintenance queue to get real statistics
|
// Use the exported method from AdminServer
|
||||||
// For now, return mock data
|
return h.adminServer.GetMaintenanceQueueStats()
|
||||||
return &maintenance.QueueStats{
|
|
||||||
PendingTasks: 5,
|
|
||||||
RunningTasks: 2,
|
|
||||||
CompletedToday: 15,
|
|
||||||
FailedToday: 1,
|
|
||||||
TotalTasks: 23,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MaintenanceHandlers) getMaintenanceTasks() ([]*maintenance.MaintenanceTask, error) {
|
func (h *MaintenanceHandlers) getMaintenanceTasks() ([]*maintenance.MaintenanceTask, error) {
|
||||||
// This would integrate with the maintenance queue to get real tasks
|
// Call the maintenance manager directly to get all tasks
|
||||||
// For now, return mock data
|
if h.adminServer == nil {
|
||||||
return []*maintenance.MaintenanceTask{}, nil
|
return []*maintenance.MaintenanceTask{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
manager := h.adminServer.GetMaintenanceManager()
|
||||||
|
if manager == nil {
|
||||||
|
return []*maintenance.MaintenanceTask{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get ALL tasks using empty parameters - this should match what the API returns
|
||||||
|
allTasks := manager.GetTasks("", "", 0)
|
||||||
|
return allTasks, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MaintenanceHandlers) getMaintenanceWorkers() ([]*maintenance.MaintenanceWorker, error) {
|
func (h *MaintenanceHandlers) getMaintenanceWorkers() ([]*maintenance.MaintenanceWorker, error) {
|
||||||
// This would integrate with the maintenance system to get real workers
|
// Get workers from the admin server's maintenance manager
|
||||||
// For now, return mock data
|
if h.adminServer == nil {
|
||||||
return []*maintenance.MaintenanceWorker{}, nil
|
return []*maintenance.MaintenanceWorker{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if h.adminServer.GetMaintenanceManager() == nil {
|
||||||
|
return []*maintenance.MaintenanceWorker{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get workers from the maintenance manager
|
||||||
|
workers := h.adminServer.GetMaintenanceManager().GetWorkers()
|
||||||
|
return workers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MaintenanceHandlers) getMaintenanceConfig() (*maintenance.MaintenanceConfigData, error) {
|
func (h *MaintenanceHandlers) getMaintenanceConfig() (*maintenance.MaintenanceConfigData, error) {
|
||||||
@@ -343,41 +449,3 @@ func (h *MaintenanceHandlers) updateMaintenanceConfig(config *maintenance.Mainte
|
|||||||
// Delegate to AdminServer's real persistence method
|
// Delegate to AdminServer's real persistence method
|
||||||
return h.adminServer.UpdateMaintenanceConfigData(config)
|
return h.adminServer.UpdateMaintenanceConfigData(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// floatPtr is a helper function to create float64 pointers
|
|
||||||
func floatPtr(f float64) *float64 {
|
|
||||||
return &f
|
|
||||||
}
|
|
||||||
|
|
||||||
// Global templ UI registry - temporarily disabled
|
|
||||||
// var globalTemplUIRegistry *types.UITemplRegistry
|
|
||||||
|
|
||||||
// initTemplUIRegistry initializes the global templ UI registry - temporarily disabled
|
|
||||||
func initTemplUIRegistry() {
|
|
||||||
// Temporarily disabled due to missing types
|
|
||||||
// if globalTemplUIRegistry == nil {
|
|
||||||
// globalTemplUIRegistry = types.NewUITemplRegistry()
|
|
||||||
// // Register vacuum templ UI provider using shared instances
|
|
||||||
// vacuumDetector, vacuumScheduler := vacuum.GetSharedInstances()
|
|
||||||
// vacuum.RegisterUITempl(globalTemplUIRegistry, vacuumDetector, vacuumScheduler)
|
|
||||||
// // Register erasure coding templ UI provider using shared instances
|
|
||||||
// erasureCodingDetector, erasureCodingScheduler := erasure_coding.GetSharedInstances()
|
|
||||||
// erasure_coding.RegisterUITempl(globalTemplUIRegistry, erasureCodingDetector, erasureCodingScheduler)
|
|
||||||
// // Register balance templ UI provider using shared instances
|
|
||||||
// balanceDetector, balanceScheduler := balance.GetSharedInstances()
|
|
||||||
// balance.RegisterUITempl(globalTemplUIRegistry, balanceDetector, balanceScheduler)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// getTemplUIProvider gets the templ UI provider for a task type - temporarily disabled
|
|
||||||
func getTemplUIProvider(taskType maintenance.MaintenanceTaskType) interface{} {
|
|
||||||
// initTemplUIRegistry()
|
|
||||||
// Convert maintenance task type to worker task type
|
|
||||||
// typesRegistry := tasks.GetGlobalTypesRegistry()
|
|
||||||
// for workerTaskType := range typesRegistry.GetAllDetectors() {
|
|
||||||
// if string(workerTaskType) == string(taskType) {
|
|
||||||
// return globalTemplUIRegistry.GetProvider(workerTaskType)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
package maintenance
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Type aliases for backward compatibility
|
||||||
|
type ConfigFieldType = config.FieldType
|
||||||
|
type ConfigFieldUnit = config.FieldUnit
|
||||||
|
type ConfigField = config.Field
|
||||||
|
|
||||||
|
// Constant aliases for backward compatibility
|
||||||
|
const (
|
||||||
|
FieldTypeBool = config.FieldTypeBool
|
||||||
|
FieldTypeInt = config.FieldTypeInt
|
||||||
|
FieldTypeDuration = config.FieldTypeDuration
|
||||||
|
FieldTypeInterval = config.FieldTypeInterval
|
||||||
|
FieldTypeString = config.FieldTypeString
|
||||||
|
FieldTypeFloat = config.FieldTypeFloat
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
UnitSeconds = config.UnitSeconds
|
||||||
|
UnitMinutes = config.UnitMinutes
|
||||||
|
UnitHours = config.UnitHours
|
||||||
|
UnitDays = config.UnitDays
|
||||||
|
UnitCount = config.UnitCount
|
||||||
|
UnitNone = config.UnitNone
|
||||||
|
)
|
||||||
|
|
||||||
|
// Function aliases for backward compatibility
|
||||||
|
var (
|
||||||
|
SecondsToIntervalValueUnit = config.SecondsToIntervalValueUnit
|
||||||
|
IntervalValueUnitToSeconds = config.IntervalValueUnitToSeconds
|
||||||
|
)
|
||||||
|
|
||||||
|
// MaintenanceConfigSchema defines the schema for maintenance configuration
|
||||||
|
type MaintenanceConfigSchema struct {
|
||||||
|
config.Schema // Embed common schema functionality
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMaintenanceConfigSchema returns the schema for maintenance configuration
|
||||||
|
func GetMaintenanceConfigSchema() *MaintenanceConfigSchema {
|
||||||
|
return &MaintenanceConfigSchema{
|
||||||
|
Schema: config.Schema{
|
||||||
|
Fields: []*config.Field{
|
||||||
|
{
|
||||||
|
Name: "enabled",
|
||||||
|
JSONName: "enabled",
|
||||||
|
Type: config.FieldTypeBool,
|
||||||
|
DefaultValue: false,
|
||||||
|
Required: false,
|
||||||
|
DisplayName: "Enable Maintenance System",
|
||||||
|
Description: "When enabled, the system will automatically scan for and execute maintenance tasks",
|
||||||
|
HelpText: "Toggle this to enable or disable the entire maintenance system",
|
||||||
|
InputType: "checkbox",
|
||||||
|
CSSClasses: "form-check-input",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "scan_interval_seconds",
|
||||||
|
JSONName: "scan_interval_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 30 * 60, // 30 minutes in seconds
|
||||||
|
MinValue: 1 * 60, // 1 minute
|
||||||
|
MaxValue: 24 * 60 * 60, // 24 hours
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Scan Interval",
|
||||||
|
Description: "How often to scan for maintenance tasks",
|
||||||
|
HelpText: "The system will check for new maintenance tasks at this interval",
|
||||||
|
Placeholder: "30",
|
||||||
|
Unit: config.UnitMinutes,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "worker_timeout_seconds",
|
||||||
|
JSONName: "worker_timeout_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 5 * 60, // 5 minutes
|
||||||
|
MinValue: 1 * 60, // 1 minute
|
||||||
|
MaxValue: 60 * 60, // 1 hour
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Worker Timeout",
|
||||||
|
Description: "How long to wait for worker heartbeat before considering it inactive",
|
||||||
|
HelpText: "Workers that don't send heartbeats within this time are considered offline",
|
||||||
|
Placeholder: "5",
|
||||||
|
Unit: config.UnitMinutes,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "task_timeout_seconds",
|
||||||
|
JSONName: "task_timeout_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 2 * 60 * 60, // 2 hours
|
||||||
|
MinValue: 10 * 60, // 10 minutes
|
||||||
|
MaxValue: 24 * 60 * 60, // 24 hours
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Task Timeout",
|
||||||
|
Description: "Maximum time allowed for a task to complete",
|
||||||
|
HelpText: "Tasks that exceed this duration will be marked as failed",
|
||||||
|
Placeholder: "2",
|
||||||
|
Unit: config.UnitHours,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "retry_delay_seconds",
|
||||||
|
JSONName: "retry_delay_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 15 * 60, // 15 minutes
|
||||||
|
MinValue: 1 * 60, // 1 minute
|
||||||
|
MaxValue: 24 * 60 * 60, // 24 hours
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Retry Delay",
|
||||||
|
Description: "How long to wait before retrying a failed task",
|
||||||
|
HelpText: "Failed tasks will be retried after this delay",
|
||||||
|
Placeholder: "15",
|
||||||
|
Unit: config.UnitMinutes,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "max_retries",
|
||||||
|
JSONName: "max_retries",
|
||||||
|
Type: config.FieldTypeInt,
|
||||||
|
DefaultValue: 3,
|
||||||
|
MinValue: 0,
|
||||||
|
MaxValue: 10,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Max Retries",
|
||||||
|
Description: "Maximum number of times to retry a failed task",
|
||||||
|
HelpText: "Tasks that fail more than this many times will be marked as permanently failed",
|
||||||
|
Placeholder: "3",
|
||||||
|
Unit: config.UnitCount,
|
||||||
|
InputType: "number",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "cleanup_interval_seconds",
|
||||||
|
JSONName: "cleanup_interval_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 24 * 60 * 60, // 24 hours
|
||||||
|
MinValue: 1 * 60 * 60, // 1 hour
|
||||||
|
MaxValue: 7 * 24 * 60 * 60, // 7 days
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Cleanup Interval",
|
||||||
|
Description: "How often to run maintenance cleanup operations",
|
||||||
|
HelpText: "Removes old task records and temporary files at this interval",
|
||||||
|
Placeholder: "24",
|
||||||
|
Unit: config.UnitHours,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "task_retention_seconds",
|
||||||
|
JSONName: "task_retention_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 7 * 24 * 60 * 60, // 7 days
|
||||||
|
MinValue: 1 * 24 * 60 * 60, // 1 day
|
||||||
|
MaxValue: 30 * 24 * 60 * 60, // 30 days
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Task Retention",
|
||||||
|
Description: "How long to keep completed task records",
|
||||||
|
HelpText: "Task history older than this duration will be automatically deleted",
|
||||||
|
Placeholder: "7",
|
||||||
|
Unit: config.UnitDays,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "global_max_concurrent",
|
||||||
|
JSONName: "global_max_concurrent",
|
||||||
|
Type: config.FieldTypeInt,
|
||||||
|
DefaultValue: 10,
|
||||||
|
MinValue: 1,
|
||||||
|
MaxValue: 100,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Global Max Concurrent Tasks",
|
||||||
|
Description: "Maximum number of maintenance tasks that can run simultaneously across all workers",
|
||||||
|
HelpText: "Limits the total number of maintenance operations to control system load",
|
||||||
|
Placeholder: "10",
|
||||||
|
Unit: config.UnitCount,
|
||||||
|
InputType: "number",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -259,31 +259,44 @@ func (s *MaintenanceIntegration) convertToExistingFormat(result *types.TaskDetec
|
|||||||
|
|
||||||
// CanScheduleWithTaskSchedulers determines if a task can be scheduled using task schedulers with dynamic type conversion
|
// CanScheduleWithTaskSchedulers determines if a task can be scheduled using task schedulers with dynamic type conversion
|
||||||
func (s *MaintenanceIntegration) CanScheduleWithTaskSchedulers(task *MaintenanceTask, runningTasks []*MaintenanceTask, availableWorkers []*MaintenanceWorker) bool {
|
func (s *MaintenanceIntegration) CanScheduleWithTaskSchedulers(task *MaintenanceTask, runningTasks []*MaintenanceTask, availableWorkers []*MaintenanceWorker) bool {
|
||||||
|
glog.Infof("DEBUG CanScheduleWithTaskSchedulers: Checking task %s (type: %s)", task.ID, task.Type)
|
||||||
|
|
||||||
// Convert existing types to task types using mapping
|
// Convert existing types to task types using mapping
|
||||||
taskType, exists := s.revTaskTypeMap[task.Type]
|
taskType, exists := s.revTaskTypeMap[task.Type]
|
||||||
if !exists {
|
if !exists {
|
||||||
glog.V(2).Infof("Unknown task type %s for scheduling, falling back to existing logic", task.Type)
|
glog.Infof("DEBUG CanScheduleWithTaskSchedulers: Unknown task type %s for scheduling, falling back to existing logic", task.Type)
|
||||||
return false // Fallback to existing logic for unknown types
|
return false // Fallback to existing logic for unknown types
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glog.Infof("DEBUG CanScheduleWithTaskSchedulers: Mapped task type %s to %s", task.Type, taskType)
|
||||||
|
|
||||||
// Convert task objects
|
// Convert task objects
|
||||||
taskObject := s.convertTaskToTaskSystem(task)
|
taskObject := s.convertTaskToTaskSystem(task)
|
||||||
if taskObject == nil {
|
if taskObject == nil {
|
||||||
glog.V(2).Infof("Failed to convert task %s for scheduling", task.ID)
|
glog.Infof("DEBUG CanScheduleWithTaskSchedulers: Failed to convert task %s for scheduling", task.ID)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glog.Infof("DEBUG CanScheduleWithTaskSchedulers: Successfully converted task %s", task.ID)
|
||||||
|
|
||||||
runningTaskObjects := s.convertTasksToTaskSystem(runningTasks)
|
runningTaskObjects := s.convertTasksToTaskSystem(runningTasks)
|
||||||
workerObjects := s.convertWorkersToTaskSystem(availableWorkers)
|
workerObjects := s.convertWorkersToTaskSystem(availableWorkers)
|
||||||
|
|
||||||
|
glog.Infof("DEBUG CanScheduleWithTaskSchedulers: Converted %d running tasks and %d workers", len(runningTaskObjects), len(workerObjects))
|
||||||
|
|
||||||
// Get the appropriate scheduler
|
// Get the appropriate scheduler
|
||||||
scheduler := s.taskRegistry.GetScheduler(taskType)
|
scheduler := s.taskRegistry.GetScheduler(taskType)
|
||||||
if scheduler == nil {
|
if scheduler == nil {
|
||||||
glog.V(2).Infof("No scheduler found for task type %s", taskType)
|
glog.Infof("DEBUG CanScheduleWithTaskSchedulers: No scheduler found for task type %s", taskType)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return scheduler.CanScheduleNow(taskObject, runningTaskObjects, workerObjects)
|
glog.Infof("DEBUG CanScheduleWithTaskSchedulers: Found scheduler for task type %s", taskType)
|
||||||
|
|
||||||
|
canSchedule := scheduler.CanScheduleNow(taskObject, runningTaskObjects, workerObjects)
|
||||||
|
glog.Infof("DEBUG CanScheduleWithTaskSchedulers: Scheduler decision for task %s: %v", task.ID, canSchedule)
|
||||||
|
|
||||||
|
return canSchedule
|
||||||
}
|
}
|
||||||
|
|
||||||
// convertTaskToTaskSystem converts existing task to task system format using dynamic mapping
|
// convertTaskToTaskSystem converts existing task to task system format using dynamic mapping
|
||||||
|
|||||||
@@ -18,11 +18,12 @@ type MaintenanceManager struct {
|
|||||||
running bool
|
running bool
|
||||||
stopChan chan struct{}
|
stopChan chan struct{}
|
||||||
// Error handling and backoff
|
// Error handling and backoff
|
||||||
errorCount int
|
errorCount int
|
||||||
lastError error
|
lastError error
|
||||||
lastErrorTime time.Time
|
lastErrorTime time.Time
|
||||||
backoffDelay time.Duration
|
backoffDelay time.Duration
|
||||||
mutex sync.RWMutex
|
mutex sync.RWMutex
|
||||||
|
scanInProgress bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMaintenanceManager creates a new maintenance manager
|
// NewMaintenanceManager creates a new maintenance manager
|
||||||
@@ -170,25 +171,48 @@ func (mm *MaintenanceManager) cleanupLoop() {
|
|||||||
|
|
||||||
// performScan executes a maintenance scan with error handling and backoff
|
// performScan executes a maintenance scan with error handling and backoff
|
||||||
func (mm *MaintenanceManager) performScan() {
|
func (mm *MaintenanceManager) performScan() {
|
||||||
mm.mutex.Lock()
|
defer func() {
|
||||||
defer mm.mutex.Unlock()
|
// Always reset scan in progress flag when done
|
||||||
|
mm.mutex.Lock()
|
||||||
|
mm.scanInProgress = false
|
||||||
|
mm.mutex.Unlock()
|
||||||
|
}()
|
||||||
|
|
||||||
glog.V(2).Infof("Starting maintenance scan")
|
glog.Infof("Starting maintenance scan...")
|
||||||
|
|
||||||
results, err := mm.scanner.ScanForMaintenanceTasks()
|
results, err := mm.scanner.ScanForMaintenanceTasks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
mm.mutex.Lock()
|
||||||
mm.handleScanError(err)
|
mm.handleScanError(err)
|
||||||
|
mm.mutex.Unlock()
|
||||||
|
glog.Warningf("Maintenance scan failed: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan succeeded, reset error tracking
|
// Scan succeeded, reset error tracking and add tasks
|
||||||
|
mm.mutex.Lock()
|
||||||
mm.resetErrorTracking()
|
mm.resetErrorTracking()
|
||||||
|
|
||||||
if len(results) > 0 {
|
if len(results) > 0 {
|
||||||
|
// Count tasks by type for logging
|
||||||
|
taskCounts := make(map[MaintenanceTaskType]int)
|
||||||
|
for _, result := range results {
|
||||||
|
taskCounts[result.TaskType]++
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release the mutex before calling AddTasksFromResults to avoid holding
|
||||||
|
// the manager mutex while trying to acquire the queue mutex
|
||||||
|
mm.mutex.Unlock()
|
||||||
mm.queue.AddTasksFromResults(results)
|
mm.queue.AddTasksFromResults(results)
|
||||||
glog.V(1).Infof("Maintenance scan completed: added %d tasks", len(results))
|
|
||||||
|
// Log detailed scan results
|
||||||
|
glog.Infof("Maintenance scan completed: found %d tasks", len(results))
|
||||||
|
for taskType, count := range taskCounts {
|
||||||
|
glog.Infof(" - %s: %d tasks", taskType, count)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
glog.V(2).Infof("Maintenance scan completed: no tasks needed")
|
mm.mutex.Unlock()
|
||||||
|
glog.Infof("Maintenance scan completed: no maintenance tasks needed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,6 +358,16 @@ func (mm *MaintenanceManager) TriggerScan() error {
|
|||||||
return fmt.Errorf("maintenance manager is not running")
|
return fmt.Errorf("maintenance manager is not running")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent multiple concurrent scans
|
||||||
|
mm.mutex.Lock()
|
||||||
|
if mm.scanInProgress {
|
||||||
|
mm.mutex.Unlock()
|
||||||
|
glog.V(1).Infof("Scan already in progress, ignoring trigger request")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
mm.scanInProgress = true
|
||||||
|
mm.mutex.Unlock()
|
||||||
|
|
||||||
go mm.performScan()
|
go mm.performScan()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package maintenance
|
package maintenance
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -24,11 +26,18 @@ func (mq *MaintenanceQueue) SetIntegration(integration *MaintenanceIntegration)
|
|||||||
glog.V(1).Infof("Maintenance queue configured with integration")
|
glog.V(1).Infof("Maintenance queue configured with integration")
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTask adds a new maintenance task to the queue
|
// AddTask adds a new maintenance task to the queue with deduplication
|
||||||
func (mq *MaintenanceQueue) AddTask(task *MaintenanceTask) {
|
func (mq *MaintenanceQueue) AddTask(task *MaintenanceTask) {
|
||||||
mq.mutex.Lock()
|
mq.mutex.Lock()
|
||||||
defer mq.mutex.Unlock()
|
defer mq.mutex.Unlock()
|
||||||
|
|
||||||
|
// Check for duplicate tasks (same type + volume + not completed)
|
||||||
|
if mq.hasDuplicateTask(task) {
|
||||||
|
glog.V(1).Infof("Task skipped (duplicate): %s for volume %d on %s (already queued or running)",
|
||||||
|
task.Type, task.VolumeID, task.Server)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
task.ID = generateTaskID()
|
task.ID = generateTaskID()
|
||||||
task.Status = TaskStatusPending
|
task.Status = TaskStatusPending
|
||||||
task.CreatedAt = time.Now()
|
task.CreatedAt = time.Now()
|
||||||
@@ -45,7 +54,28 @@ func (mq *MaintenanceQueue) AddTask(task *MaintenanceTask) {
|
|||||||
return mq.pendingTasks[i].ScheduledAt.Before(mq.pendingTasks[j].ScheduledAt)
|
return mq.pendingTasks[i].ScheduledAt.Before(mq.pendingTasks[j].ScheduledAt)
|
||||||
})
|
})
|
||||||
|
|
||||||
glog.V(2).Infof("Added maintenance task %s: %s for volume %d", task.ID, task.Type, task.VolumeID)
|
scheduleInfo := ""
|
||||||
|
if !task.ScheduledAt.IsZero() && time.Until(task.ScheduledAt) > time.Minute {
|
||||||
|
scheduleInfo = fmt.Sprintf(", scheduled for %v", task.ScheduledAt.Format("15:04:05"))
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.Infof("Task queued: %s (%s) volume %d on %s, priority %s%s, reason: %s",
|
||||||
|
task.ID, task.Type, task.VolumeID, task.Server, task.Priority, scheduleInfo, task.Reason)
|
||||||
|
}
|
||||||
|
|
||||||
|
// hasDuplicateTask checks if a similar task already exists (same type, volume, and not completed)
|
||||||
|
func (mq *MaintenanceQueue) hasDuplicateTask(newTask *MaintenanceTask) bool {
|
||||||
|
for _, existingTask := range mq.tasks {
|
||||||
|
if existingTask.Type == newTask.Type &&
|
||||||
|
existingTask.VolumeID == newTask.VolumeID &&
|
||||||
|
existingTask.Server == newTask.Server &&
|
||||||
|
(existingTask.Status == TaskStatusPending ||
|
||||||
|
existingTask.Status == TaskStatusAssigned ||
|
||||||
|
existingTask.Status == TaskStatusInProgress) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTasksFromResults converts detection results to tasks and adds them to the queue
|
// AddTasksFromResults converts detection results to tasks and adds them to the queue
|
||||||
@@ -67,57 +97,89 @@ func (mq *MaintenanceQueue) AddTasksFromResults(results []*TaskDetectionResult)
|
|||||||
|
|
||||||
// GetNextTask returns the next available task for a worker
|
// GetNextTask returns the next available task for a worker
|
||||||
func (mq *MaintenanceQueue) GetNextTask(workerID string, capabilities []MaintenanceTaskType) *MaintenanceTask {
|
func (mq *MaintenanceQueue) GetNextTask(workerID string, capabilities []MaintenanceTaskType) *MaintenanceTask {
|
||||||
mq.mutex.Lock()
|
// Use read lock for initial checks and search
|
||||||
defer mq.mutex.Unlock()
|
mq.mutex.RLock()
|
||||||
|
|
||||||
worker, exists := mq.workers[workerID]
|
worker, exists := mq.workers[workerID]
|
||||||
if !exists {
|
if !exists {
|
||||||
|
mq.mutex.RUnlock()
|
||||||
|
glog.V(2).Infof("Task assignment failed for worker %s: worker not registered", workerID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if worker has capacity
|
// Check if worker has capacity
|
||||||
if worker.CurrentLoad >= worker.MaxConcurrent {
|
if worker.CurrentLoad >= worker.MaxConcurrent {
|
||||||
|
mq.mutex.RUnlock()
|
||||||
|
glog.V(2).Infof("Task assignment failed for worker %s: at capacity (%d/%d)", workerID, worker.CurrentLoad, worker.MaxConcurrent)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
var selectedTask *MaintenanceTask
|
||||||
|
var selectedIndex int = -1
|
||||||
|
|
||||||
// Find the next suitable task
|
// Find the next suitable task (using read lock)
|
||||||
for i, task := range mq.pendingTasks {
|
for i, task := range mq.pendingTasks {
|
||||||
// Check if it's time to execute the task
|
// Check if it's time to execute the task
|
||||||
if task.ScheduledAt.After(now) {
|
if task.ScheduledAt.After(now) {
|
||||||
|
glog.V(3).Infof("Task %s skipped for worker %s: scheduled for future (%v)", task.ID, workerID, task.ScheduledAt)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if worker can handle this task type
|
// Check if worker can handle this task type
|
||||||
if !mq.workerCanHandle(task.Type, capabilities) {
|
if !mq.workerCanHandle(task.Type, capabilities) {
|
||||||
|
glog.V(3).Infof("Task %s (%s) skipped for worker %s: capability mismatch (worker has: %v)", task.ID, task.Type, workerID, capabilities)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check scheduling logic - use simplified system if available, otherwise fallback
|
// Check if this task type needs a cooldown period
|
||||||
if !mq.canScheduleTaskNow(task) {
|
if !mq.canScheduleTaskNow(task) {
|
||||||
|
glog.V(3).Infof("Task %s (%s) skipped for worker %s: scheduling constraints not met", task.ID, task.Type, workerID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign task to worker
|
// Found a suitable task
|
||||||
task.Status = TaskStatusAssigned
|
selectedTask = task
|
||||||
task.WorkerID = workerID
|
selectedIndex = i
|
||||||
startTime := now
|
break
|
||||||
task.StartedAt = &startTime
|
|
||||||
|
|
||||||
// Remove from pending tasks
|
|
||||||
mq.pendingTasks = append(mq.pendingTasks[:i], mq.pendingTasks[i+1:]...)
|
|
||||||
|
|
||||||
// Update worker
|
|
||||||
worker.CurrentTask = task
|
|
||||||
worker.CurrentLoad++
|
|
||||||
worker.Status = "busy"
|
|
||||||
|
|
||||||
glog.V(2).Infof("Assigned task %s to worker %s", task.ID, workerID)
|
|
||||||
return task
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
// Release read lock
|
||||||
|
mq.mutex.RUnlock()
|
||||||
|
|
||||||
|
// If no task found, return nil
|
||||||
|
if selectedTask == nil {
|
||||||
|
glog.V(2).Infof("No suitable tasks available for worker %s (checked %d pending tasks)", workerID, len(mq.pendingTasks))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now acquire write lock to actually assign the task
|
||||||
|
mq.mutex.Lock()
|
||||||
|
defer mq.mutex.Unlock()
|
||||||
|
|
||||||
|
// Re-check that the task is still available (it might have been assigned to another worker)
|
||||||
|
if selectedIndex >= len(mq.pendingTasks) || mq.pendingTasks[selectedIndex].ID != selectedTask.ID {
|
||||||
|
glog.V(2).Infof("Task %s no longer available for worker %s: assigned to another worker", selectedTask.ID, workerID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign the task
|
||||||
|
selectedTask.Status = TaskStatusAssigned
|
||||||
|
selectedTask.WorkerID = workerID
|
||||||
|
selectedTask.StartedAt = &now
|
||||||
|
|
||||||
|
// Remove from pending tasks
|
||||||
|
mq.pendingTasks = append(mq.pendingTasks[:selectedIndex], mq.pendingTasks[selectedIndex+1:]...)
|
||||||
|
|
||||||
|
// Update worker load
|
||||||
|
if worker, exists := mq.workers[workerID]; exists {
|
||||||
|
worker.CurrentLoad++
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.Infof("Task assigned: %s (%s) → worker %s (volume %d, server %s)",
|
||||||
|
selectedTask.ID, selectedTask.Type, workerID, selectedTask.VolumeID, selectedTask.Server)
|
||||||
|
|
||||||
|
return selectedTask
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompleteTask marks a task as completed
|
// CompleteTask marks a task as completed
|
||||||
@@ -127,12 +189,19 @@ func (mq *MaintenanceQueue) CompleteTask(taskID string, error string) {
|
|||||||
|
|
||||||
task, exists := mq.tasks[taskID]
|
task, exists := mq.tasks[taskID]
|
||||||
if !exists {
|
if !exists {
|
||||||
|
glog.Warningf("Attempted to complete non-existent task: %s", taskID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
completedTime := time.Now()
|
completedTime := time.Now()
|
||||||
task.CompletedAt = &completedTime
|
task.CompletedAt = &completedTime
|
||||||
|
|
||||||
|
// Calculate task duration
|
||||||
|
var duration time.Duration
|
||||||
|
if task.StartedAt != nil {
|
||||||
|
duration = completedTime.Sub(*task.StartedAt)
|
||||||
|
}
|
||||||
|
|
||||||
if error != "" {
|
if error != "" {
|
||||||
task.Status = TaskStatusFailed
|
task.Status = TaskStatusFailed
|
||||||
task.Error = error
|
task.Error = error
|
||||||
@@ -148,14 +217,17 @@ func (mq *MaintenanceQueue) CompleteTask(taskID string, error string) {
|
|||||||
task.ScheduledAt = time.Now().Add(15 * time.Minute) // Retry delay
|
task.ScheduledAt = time.Now().Add(15 * time.Minute) // Retry delay
|
||||||
|
|
||||||
mq.pendingTasks = append(mq.pendingTasks, task)
|
mq.pendingTasks = append(mq.pendingTasks, task)
|
||||||
glog.V(2).Infof("Retrying task %s (attempt %d/%d)", taskID, task.RetryCount, task.MaxRetries)
|
glog.Warningf("Task failed, scheduling retry: %s (%s) attempt %d/%d, worker %s, duration %v, error: %s",
|
||||||
|
taskID, task.Type, task.RetryCount, task.MaxRetries, task.WorkerID, duration, error)
|
||||||
} else {
|
} else {
|
||||||
glog.Errorf("Task %s failed permanently after %d retries: %s", taskID, task.MaxRetries, error)
|
glog.Errorf("Task failed permanently: %s (%s) worker %s, duration %v, after %d retries: %s",
|
||||||
|
taskID, task.Type, task.WorkerID, duration, task.MaxRetries, error)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
task.Status = TaskStatusCompleted
|
task.Status = TaskStatusCompleted
|
||||||
task.Progress = 100
|
task.Progress = 100
|
||||||
glog.V(2).Infof("Task %s completed successfully", taskID)
|
glog.Infof("Task completed: %s (%s) worker %s, duration %v, volume %d",
|
||||||
|
taskID, task.Type, task.WorkerID, duration, task.VolumeID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update worker
|
// Update worker
|
||||||
@@ -176,8 +248,23 @@ func (mq *MaintenanceQueue) UpdateTaskProgress(taskID string, progress float64)
|
|||||||
defer mq.mutex.RUnlock()
|
defer mq.mutex.RUnlock()
|
||||||
|
|
||||||
if task, exists := mq.tasks[taskID]; exists {
|
if task, exists := mq.tasks[taskID]; exists {
|
||||||
|
oldProgress := task.Progress
|
||||||
task.Progress = progress
|
task.Progress = progress
|
||||||
task.Status = TaskStatusInProgress
|
task.Status = TaskStatusInProgress
|
||||||
|
|
||||||
|
// Log progress at significant milestones or changes
|
||||||
|
if progress == 0 {
|
||||||
|
glog.V(1).Infof("Task started: %s (%s) worker %s, volume %d",
|
||||||
|
taskID, task.Type, task.WorkerID, task.VolumeID)
|
||||||
|
} else if progress >= 100 {
|
||||||
|
glog.V(1).Infof("Task progress: %s (%s) worker %s, %.1f%% complete",
|
||||||
|
taskID, task.Type, task.WorkerID, progress)
|
||||||
|
} else if progress-oldProgress >= 25 { // Log every 25% increment
|
||||||
|
glog.V(1).Infof("Task progress: %s (%s) worker %s, %.1f%% complete",
|
||||||
|
taskID, task.Type, task.WorkerID, progress)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
glog.V(2).Infof("Progress update for unknown task: %s (%.1f%%)", taskID, progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,12 +273,25 @@ func (mq *MaintenanceQueue) RegisterWorker(worker *MaintenanceWorker) {
|
|||||||
mq.mutex.Lock()
|
mq.mutex.Lock()
|
||||||
defer mq.mutex.Unlock()
|
defer mq.mutex.Unlock()
|
||||||
|
|
||||||
|
isNewWorker := true
|
||||||
|
if existingWorker, exists := mq.workers[worker.ID]; exists {
|
||||||
|
isNewWorker = false
|
||||||
|
glog.Infof("Worker reconnected: %s at %s (capabilities: %v, max concurrent: %d)",
|
||||||
|
worker.ID, worker.Address, worker.Capabilities, worker.MaxConcurrent)
|
||||||
|
|
||||||
|
// Preserve current load when reconnecting
|
||||||
|
worker.CurrentLoad = existingWorker.CurrentLoad
|
||||||
|
} else {
|
||||||
|
glog.Infof("Worker registered: %s at %s (capabilities: %v, max concurrent: %d)",
|
||||||
|
worker.ID, worker.Address, worker.Capabilities, worker.MaxConcurrent)
|
||||||
|
}
|
||||||
|
|
||||||
worker.LastHeartbeat = time.Now()
|
worker.LastHeartbeat = time.Now()
|
||||||
worker.Status = "active"
|
worker.Status = "active"
|
||||||
worker.CurrentLoad = 0
|
if isNewWorker {
|
||||||
|
worker.CurrentLoad = 0
|
||||||
|
}
|
||||||
mq.workers[worker.ID] = worker
|
mq.workers[worker.ID] = worker
|
||||||
|
|
||||||
glog.V(1).Infof("Registered maintenance worker %s at %s", worker.ID, worker.Address)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateWorkerHeartbeat updates worker heartbeat
|
// UpdateWorkerHeartbeat updates worker heartbeat
|
||||||
@@ -200,7 +300,15 @@ func (mq *MaintenanceQueue) UpdateWorkerHeartbeat(workerID string) {
|
|||||||
defer mq.mutex.Unlock()
|
defer mq.mutex.Unlock()
|
||||||
|
|
||||||
if worker, exists := mq.workers[workerID]; exists {
|
if worker, exists := mq.workers[workerID]; exists {
|
||||||
|
lastSeen := worker.LastHeartbeat
|
||||||
worker.LastHeartbeat = time.Now()
|
worker.LastHeartbeat = time.Now()
|
||||||
|
|
||||||
|
// Log if worker was offline for a while
|
||||||
|
if time.Since(lastSeen) > 2*time.Minute {
|
||||||
|
glog.Infof("Worker %s heartbeat resumed after %v", workerID, time.Since(lastSeen))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
glog.V(2).Infof("Heartbeat from unknown worker: %s", workerID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,10 +419,23 @@ func (mq *MaintenanceQueue) GetWorkers() []*MaintenanceWorker {
|
|||||||
func generateTaskID() string {
|
func generateTaskID() string {
|
||||||
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
|
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
for i := range b {
|
randBytes := make([]byte, 8)
|
||||||
b[i] = charset[i%len(charset)]
|
|
||||||
|
// Generate random bytes
|
||||||
|
if _, err := rand.Read(randBytes); err != nil {
|
||||||
|
// Fallback to timestamp-based ID if crypto/rand fails
|
||||||
|
timestamp := time.Now().UnixNano()
|
||||||
|
return fmt.Sprintf("task-%d", timestamp)
|
||||||
}
|
}
|
||||||
return string(b)
|
|
||||||
|
// Convert random bytes to charset
|
||||||
|
for i := range b {
|
||||||
|
b[i] = charset[int(randBytes[i])%len(charset)]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add timestamp suffix to ensure uniqueness
|
||||||
|
timestamp := time.Now().Unix() % 10000 // last 4 digits of timestamp
|
||||||
|
return fmt.Sprintf("%s-%04d", string(b), timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanupOldTasks removes old completed and failed tasks
|
// CleanupOldTasks removes old completed and failed tasks
|
||||||
@@ -427,19 +548,31 @@ func (mq *MaintenanceQueue) workerCanHandle(taskType MaintenanceTaskType, capabi
|
|||||||
|
|
||||||
// canScheduleTaskNow determines if a task can be scheduled using task schedulers or fallback logic
|
// canScheduleTaskNow determines if a task can be scheduled using task schedulers or fallback logic
|
||||||
func (mq *MaintenanceQueue) canScheduleTaskNow(task *MaintenanceTask) bool {
|
func (mq *MaintenanceQueue) canScheduleTaskNow(task *MaintenanceTask) bool {
|
||||||
|
glog.Infof("DEBUG canScheduleTaskNow: Checking if task %s (type: %s) can be scheduled", task.ID, task.Type)
|
||||||
|
|
||||||
|
// TEMPORARY FIX: Skip integration task scheduler which is being overly restrictive
|
||||||
|
// Use fallback logic directly for now
|
||||||
|
glog.Infof("DEBUG canScheduleTaskNow: Using fallback logic (bypassing integration scheduler)")
|
||||||
|
canExecute := mq.canExecuteTaskType(task.Type)
|
||||||
|
glog.Infof("DEBUG canScheduleTaskNow: Fallback decision for task %s (%s): %v", task.ID, task.Type, canExecute)
|
||||||
|
return canExecute
|
||||||
|
|
||||||
|
// NOTE: Original integration code disabled temporarily
|
||||||
// Try task scheduling logic first
|
// Try task scheduling logic first
|
||||||
if mq.integration != nil {
|
/*
|
||||||
// Get all running tasks and available workers
|
if mq.integration != nil {
|
||||||
runningTasks := mq.getRunningTasks()
|
glog.Infof("DEBUG canScheduleTaskNow: Using integration task scheduler")
|
||||||
availableWorkers := mq.getAvailableWorkers()
|
// Get all running tasks and available workers
|
||||||
|
runningTasks := mq.getRunningTasks()
|
||||||
|
availableWorkers := mq.getAvailableWorkers()
|
||||||
|
|
||||||
canSchedule := mq.integration.CanScheduleWithTaskSchedulers(task, runningTasks, availableWorkers)
|
glog.Infof("DEBUG canScheduleTaskNow: Running tasks: %d, Available workers: %d", len(runningTasks), len(availableWorkers))
|
||||||
glog.V(3).Infof("Task scheduler decision for task %s (%s): %v", task.ID, task.Type, canSchedule)
|
|
||||||
return canSchedule
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to hardcoded logic
|
canSchedule := mq.integration.CanScheduleWithTaskSchedulers(task, runningTasks, availableWorkers)
|
||||||
return mq.canExecuteTaskType(task.Type)
|
glog.Infof("DEBUG canScheduleTaskNow: Task scheduler decision for task %s (%s): %v", task.ID, task.Type, canSchedule)
|
||||||
|
return canSchedule
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// canExecuteTaskType checks if we can execute more tasks of this type (concurrency limits) - fallback logic
|
// canExecuteTaskType checks if we can execute more tasks of this type (concurrency limits) - fallback logic
|
||||||
|
|||||||
@@ -0,0 +1,349 @@
|
|||||||
|
package maintenance
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Test suite for canScheduleTaskNow() function and related scheduling logic
|
||||||
|
//
|
||||||
|
// This test suite ensures that:
|
||||||
|
// 1. The fallback scheduling logic works correctly when no integration is present
|
||||||
|
// 2. Task concurrency limits are properly enforced per task type
|
||||||
|
// 3. Different task types don't interfere with each other's concurrency limits
|
||||||
|
// 4. Custom policies with higher concurrency limits work correctly
|
||||||
|
// 5. Edge cases (nil tasks, empty task types) are handled gracefully
|
||||||
|
// 6. Helper functions (GetRunningTaskCount, canExecuteTaskType, etc.) work correctly
|
||||||
|
//
|
||||||
|
// Background: The canScheduleTaskNow() function is critical for task assignment.
|
||||||
|
// It was previously failing due to an overly restrictive integration scheduler,
|
||||||
|
// so we implemented a temporary fix that bypasses the integration and uses
|
||||||
|
// fallback logic based on simple concurrency limits per task type.
|
||||||
|
|
||||||
|
func TestCanScheduleTaskNow_FallbackLogic(t *testing.T) {
|
||||||
|
// Test the current implementation which uses fallback logic
|
||||||
|
mq := &MaintenanceQueue{
|
||||||
|
tasks: make(map[string]*MaintenanceTask),
|
||||||
|
pendingTasks: []*MaintenanceTask{},
|
||||||
|
workers: make(map[string]*MaintenanceWorker),
|
||||||
|
policy: nil, // No policy for default behavior
|
||||||
|
integration: nil, // No integration to force fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
task := &MaintenanceTask{
|
||||||
|
ID: "test-task-1",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusPending,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should return true with fallback logic (no running tasks, default max concurrent = 1)
|
||||||
|
result := mq.canScheduleTaskNow(task)
|
||||||
|
if !result {
|
||||||
|
t.Errorf("Expected canScheduleTaskNow to return true with fallback logic, got false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCanScheduleTaskNow_FallbackWithRunningTasks(t *testing.T) {
|
||||||
|
// Test fallback logic when there are already running tasks
|
||||||
|
mq := &MaintenanceQueue{
|
||||||
|
tasks: map[string]*MaintenanceTask{
|
||||||
|
"running-task": {
|
||||||
|
ID: "running-task",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusInProgress,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pendingTasks: []*MaintenanceTask{},
|
||||||
|
workers: make(map[string]*MaintenanceWorker),
|
||||||
|
policy: nil,
|
||||||
|
integration: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
task := &MaintenanceTask{
|
||||||
|
ID: "test-task-2",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusPending,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should return false because max concurrent is 1 and we have 1 running task
|
||||||
|
result := mq.canScheduleTaskNow(task)
|
||||||
|
if result {
|
||||||
|
t.Errorf("Expected canScheduleTaskNow to return false when at capacity, got true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCanScheduleTaskNow_DifferentTaskTypes(t *testing.T) {
|
||||||
|
// Test that different task types don't interfere with each other
|
||||||
|
mq := &MaintenanceQueue{
|
||||||
|
tasks: map[string]*MaintenanceTask{
|
||||||
|
"running-ec-task": {
|
||||||
|
ID: "running-ec-task",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusInProgress,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pendingTasks: []*MaintenanceTask{},
|
||||||
|
workers: make(map[string]*MaintenanceWorker),
|
||||||
|
policy: nil,
|
||||||
|
integration: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test vacuum task when EC task is running
|
||||||
|
vacuumTask := &MaintenanceTask{
|
||||||
|
ID: "vacuum-task",
|
||||||
|
Type: MaintenanceTaskType("vacuum"),
|
||||||
|
Status: TaskStatusPending,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should return true because vacuum and erasure_coding are different task types
|
||||||
|
result := mq.canScheduleTaskNow(vacuumTask)
|
||||||
|
if !result {
|
||||||
|
t.Errorf("Expected canScheduleTaskNow to return true for different task type, got false")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test another EC task when one is already running
|
||||||
|
ecTask := &MaintenanceTask{
|
||||||
|
ID: "ec-task",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusPending,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should return false because max concurrent for EC is 1 and we have 1 running
|
||||||
|
result = mq.canScheduleTaskNow(ecTask)
|
||||||
|
if result {
|
||||||
|
t.Errorf("Expected canScheduleTaskNow to return false for same task type at capacity, got true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCanScheduleTaskNow_WithIntegration(t *testing.T) {
|
||||||
|
// Test with a real MaintenanceIntegration (will use fallback logic in current implementation)
|
||||||
|
policy := &MaintenancePolicy{
|
||||||
|
TaskPolicies: make(map[MaintenanceTaskType]*TaskPolicy),
|
||||||
|
GlobalMaxConcurrent: 10,
|
||||||
|
DefaultRepeatInterval: 24,
|
||||||
|
DefaultCheckInterval: 1,
|
||||||
|
}
|
||||||
|
mq := NewMaintenanceQueue(policy)
|
||||||
|
|
||||||
|
// Create a basic integration (this would normally be more complex)
|
||||||
|
integration := NewMaintenanceIntegration(mq, policy)
|
||||||
|
mq.SetIntegration(integration)
|
||||||
|
|
||||||
|
task := &MaintenanceTask{
|
||||||
|
ID: "test-task-3",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusPending,
|
||||||
|
}
|
||||||
|
|
||||||
|
// With our current implementation (fallback logic), this should return true
|
||||||
|
result := mq.canScheduleTaskNow(task)
|
||||||
|
if !result {
|
||||||
|
t.Errorf("Expected canScheduleTaskNow to return true with fallback logic, got false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetRunningTaskCount(t *testing.T) {
|
||||||
|
// Test the helper function used by fallback logic
|
||||||
|
mq := &MaintenanceQueue{
|
||||||
|
tasks: map[string]*MaintenanceTask{
|
||||||
|
"task1": {
|
||||||
|
ID: "task1",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusInProgress,
|
||||||
|
},
|
||||||
|
"task2": {
|
||||||
|
ID: "task2",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusAssigned,
|
||||||
|
},
|
||||||
|
"task3": {
|
||||||
|
ID: "task3",
|
||||||
|
Type: MaintenanceTaskType("vacuum"),
|
||||||
|
Status: TaskStatusInProgress,
|
||||||
|
},
|
||||||
|
"task4": {
|
||||||
|
ID: "task4",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusCompleted,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pendingTasks: []*MaintenanceTask{},
|
||||||
|
workers: make(map[string]*MaintenanceWorker),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should count 2 running EC tasks (in_progress + assigned)
|
||||||
|
ecCount := mq.GetRunningTaskCount(MaintenanceTaskType("erasure_coding"))
|
||||||
|
if ecCount != 2 {
|
||||||
|
t.Errorf("Expected 2 running EC tasks, got %d", ecCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should count 1 running vacuum task
|
||||||
|
vacuumCount := mq.GetRunningTaskCount(MaintenanceTaskType("vacuum"))
|
||||||
|
if vacuumCount != 1 {
|
||||||
|
t.Errorf("Expected 1 running vacuum task, got %d", vacuumCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should count 0 running balance tasks
|
||||||
|
balanceCount := mq.GetRunningTaskCount(MaintenanceTaskType("balance"))
|
||||||
|
if balanceCount != 0 {
|
||||||
|
t.Errorf("Expected 0 running balance tasks, got %d", balanceCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCanExecuteTaskType(t *testing.T) {
|
||||||
|
// Test the fallback logic helper function
|
||||||
|
mq := &MaintenanceQueue{
|
||||||
|
tasks: map[string]*MaintenanceTask{
|
||||||
|
"running-task": {
|
||||||
|
ID: "running-task",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusInProgress,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pendingTasks: []*MaintenanceTask{},
|
||||||
|
workers: make(map[string]*MaintenanceWorker),
|
||||||
|
policy: nil, // Will use default max concurrent = 1
|
||||||
|
integration: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should return false for EC (1 running, max = 1)
|
||||||
|
result := mq.canExecuteTaskType(MaintenanceTaskType("erasure_coding"))
|
||||||
|
if result {
|
||||||
|
t.Errorf("Expected canExecuteTaskType to return false for EC at capacity, got true")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should return true for vacuum (0 running, max = 1)
|
||||||
|
result = mq.canExecuteTaskType(MaintenanceTaskType("vacuum"))
|
||||||
|
if !result {
|
||||||
|
t.Errorf("Expected canExecuteTaskType to return true for vacuum, got false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetMaxConcurrentForTaskType_DefaultBehavior(t *testing.T) {
|
||||||
|
// Test the default behavior when no policy or integration is set
|
||||||
|
mq := &MaintenanceQueue{
|
||||||
|
tasks: make(map[string]*MaintenanceTask),
|
||||||
|
pendingTasks: []*MaintenanceTask{},
|
||||||
|
workers: make(map[string]*MaintenanceWorker),
|
||||||
|
policy: nil,
|
||||||
|
integration: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should return default value of 1
|
||||||
|
maxConcurrent := mq.getMaxConcurrentForTaskType(MaintenanceTaskType("erasure_coding"))
|
||||||
|
if maxConcurrent != 1 {
|
||||||
|
t.Errorf("Expected default max concurrent to be 1, got %d", maxConcurrent)
|
||||||
|
}
|
||||||
|
|
||||||
|
maxConcurrent = mq.getMaxConcurrentForTaskType(MaintenanceTaskType("vacuum"))
|
||||||
|
if maxConcurrent != 1 {
|
||||||
|
t.Errorf("Expected default max concurrent to be 1, got %d", maxConcurrent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test edge cases and error conditions
|
||||||
|
func TestCanScheduleTaskNow_NilTask(t *testing.T) {
|
||||||
|
mq := &MaintenanceQueue{
|
||||||
|
tasks: make(map[string]*MaintenanceTask),
|
||||||
|
pendingTasks: []*MaintenanceTask{},
|
||||||
|
workers: make(map[string]*MaintenanceWorker),
|
||||||
|
policy: nil,
|
||||||
|
integration: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
// This should panic with a nil task, so we expect and catch the panic
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r == nil {
|
||||||
|
t.Errorf("Expected canScheduleTaskNow to panic with nil task, but it didn't")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// This should panic
|
||||||
|
mq.canScheduleTaskNow(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCanScheduleTaskNow_EmptyTaskType(t *testing.T) {
|
||||||
|
mq := &MaintenanceQueue{
|
||||||
|
tasks: make(map[string]*MaintenanceTask),
|
||||||
|
pendingTasks: []*MaintenanceTask{},
|
||||||
|
workers: make(map[string]*MaintenanceWorker),
|
||||||
|
policy: nil,
|
||||||
|
integration: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
task := &MaintenanceTask{
|
||||||
|
ID: "empty-type-task",
|
||||||
|
Type: MaintenanceTaskType(""), // Empty task type
|
||||||
|
Status: TaskStatusPending,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should handle empty task type gracefully
|
||||||
|
result := mq.canScheduleTaskNow(task)
|
||||||
|
if !result {
|
||||||
|
t.Errorf("Expected canScheduleTaskNow to handle empty task type, got false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCanScheduleTaskNow_WithPolicy(t *testing.T) {
|
||||||
|
// Test with a policy that allows higher concurrency
|
||||||
|
policy := &MaintenancePolicy{
|
||||||
|
TaskPolicies: map[MaintenanceTaskType]*TaskPolicy{
|
||||||
|
MaintenanceTaskType("erasure_coding"): {
|
||||||
|
Enabled: true,
|
||||||
|
MaxConcurrent: 3,
|
||||||
|
Configuration: make(map[string]interface{}),
|
||||||
|
},
|
||||||
|
MaintenanceTaskType("vacuum"): {
|
||||||
|
Enabled: true,
|
||||||
|
MaxConcurrent: 2,
|
||||||
|
Configuration: make(map[string]interface{}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
GlobalMaxConcurrent: 10,
|
||||||
|
DefaultRepeatInterval: 24,
|
||||||
|
DefaultCheckInterval: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
mq := &MaintenanceQueue{
|
||||||
|
tasks: map[string]*MaintenanceTask{
|
||||||
|
"running-task-1": {
|
||||||
|
ID: "running-task-1",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusInProgress,
|
||||||
|
},
|
||||||
|
"running-task-2": {
|
||||||
|
ID: "running-task-2",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusAssigned,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pendingTasks: []*MaintenanceTask{},
|
||||||
|
workers: make(map[string]*MaintenanceWorker),
|
||||||
|
policy: policy,
|
||||||
|
integration: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
task := &MaintenanceTask{
|
||||||
|
ID: "test-task-policy",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusPending,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should return true because we have 2 running EC tasks but max is 3
|
||||||
|
result := mq.canScheduleTaskNow(task)
|
||||||
|
if !result {
|
||||||
|
t.Errorf("Expected canScheduleTaskNow to return true with policy allowing 3 concurrent, got false")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add one more running task to reach the limit
|
||||||
|
mq.tasks["running-task-3"] = &MaintenanceTask{
|
||||||
|
ID: "running-task-3",
|
||||||
|
Type: MaintenanceTaskType("erasure_coding"),
|
||||||
|
Status: TaskStatusInProgress,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should return false because we now have 3 running EC tasks (at limit)
|
||||||
|
result = mq.canScheduleTaskNow(task)
|
||||||
|
if result {
|
||||||
|
t.Errorf("Expected canScheduleTaskNow to return false when at policy limit, got true")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,8 +62,19 @@ func (ms *MaintenanceScanner) ScanForMaintenanceTasks() ([]*TaskDetectionResult,
|
|||||||
// getVolumeHealthMetrics collects health information for all volumes
|
// getVolumeHealthMetrics collects health information for all volumes
|
||||||
func (ms *MaintenanceScanner) getVolumeHealthMetrics() ([]*VolumeHealthMetrics, error) {
|
func (ms *MaintenanceScanner) getVolumeHealthMetrics() ([]*VolumeHealthMetrics, error) {
|
||||||
var metrics []*VolumeHealthMetrics
|
var metrics []*VolumeHealthMetrics
|
||||||
|
var volumeSizeLimitMB uint64
|
||||||
|
|
||||||
err := ms.adminClient.WithMasterClient(func(client master_pb.SeaweedClient) error {
|
err := ms.adminClient.WithMasterClient(func(client master_pb.SeaweedClient) error {
|
||||||
|
// First, get volume size limit from master configuration
|
||||||
|
configResp, err := client.GetMasterConfiguration(context.Background(), &master_pb.GetMasterConfigurationRequest{})
|
||||||
|
if err != nil {
|
||||||
|
glog.Warningf("Failed to get volume size limit from master: %v", err)
|
||||||
|
volumeSizeLimitMB = 30000 // Default to 30GB if we can't get from master
|
||||||
|
} else {
|
||||||
|
volumeSizeLimitMB = uint64(configResp.VolumeSizeLimitMB)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now get volume list
|
||||||
resp, err := client.VolumeList(context.Background(), &master_pb.VolumeListRequest{})
|
resp, err := client.VolumeList(context.Background(), &master_pb.VolumeListRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -73,6 +84,8 @@ func (ms *MaintenanceScanner) getVolumeHealthMetrics() ([]*VolumeHealthMetrics,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volumeSizeLimitBytes := volumeSizeLimitMB * 1024 * 1024 // Convert MB to bytes
|
||||||
|
|
||||||
for _, dc := range resp.TopologyInfo.DataCenterInfos {
|
for _, dc := range resp.TopologyInfo.DataCenterInfos {
|
||||||
for _, rack := range dc.RackInfos {
|
for _, rack := range dc.RackInfos {
|
||||||
for _, node := range rack.DataNodeInfos {
|
for _, node := range rack.DataNodeInfos {
|
||||||
@@ -94,11 +107,14 @@ func (ms *MaintenanceScanner) getVolumeHealthMetrics() ([]*VolumeHealthMetrics,
|
|||||||
// Calculate derived metrics
|
// Calculate derived metrics
|
||||||
if metric.Size > 0 {
|
if metric.Size > 0 {
|
||||||
metric.GarbageRatio = float64(metric.DeletedBytes) / float64(metric.Size)
|
metric.GarbageRatio = float64(metric.DeletedBytes) / float64(metric.Size)
|
||||||
// Calculate fullness ratio (would need volume size limit)
|
// Calculate fullness ratio using actual volume size limit from master
|
||||||
// metric.FullnessRatio = float64(metric.Size) / float64(volumeSizeLimit)
|
metric.FullnessRatio = float64(metric.Size) / float64(volumeSizeLimitBytes)
|
||||||
}
|
}
|
||||||
metric.Age = time.Since(metric.LastModified)
|
metric.Age = time.Since(metric.LastModified)
|
||||||
|
|
||||||
|
glog.V(3).Infof("Volume %d: size=%d, limit=%d, fullness=%.2f",
|
||||||
|
metric.VolumeID, metric.Size, volumeSizeLimitBytes, metric.FullnessRatio)
|
||||||
|
|
||||||
metrics = append(metrics, metric)
|
metrics = append(metrics, metric)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,9 +137,10 @@ func (mp *MaintenancePolicy) GetTaskPolicy(taskType MaintenanceTaskType) *TaskPo
|
|||||||
|
|
||||||
policy, exists := mp.TaskPolicies[taskType]
|
policy, exists := mp.TaskPolicies[taskType]
|
||||||
if !exists {
|
if !exists {
|
||||||
// Create generic default policy using global settings - no hardcoded fallbacks
|
// Create default policy - enabled by default for registered task types
|
||||||
|
// This provides a better user experience where available tasks are enabled by default
|
||||||
policy = &TaskPolicy{
|
policy = &TaskPolicy{
|
||||||
Enabled: false, // Conservative default - require explicit enabling
|
Enabled: true, // Default to enabled for registered task types
|
||||||
MaxConcurrent: 1, // Conservative default concurrency
|
MaxConcurrent: 1, // Conservative default concurrency
|
||||||
RepeatInterval: mp.DefaultRepeatInterval, // Use configured default, 0 if not set
|
RepeatInterval: mp.DefaultRepeatInterval, // Use configured default, 0 if not set
|
||||||
CheckInterval: mp.DefaultCheckInterval, // Use configured default, 0 if not set
|
CheckInterval: mp.DefaultCheckInterval, // Use configured default, 0 if not set
|
||||||
@@ -282,21 +283,37 @@ type MaintenanceConfig struct {
|
|||||||
|
|
||||||
// Default configuration values
|
// Default configuration values
|
||||||
func DefaultMaintenanceConfig() *MaintenanceConfig {
|
func DefaultMaintenanceConfig() *MaintenanceConfig {
|
||||||
return &MaintenanceConfig{
|
config := &MaintenanceConfig{
|
||||||
Enabled: false, // Disabled by default for safety
|
|
||||||
ScanIntervalSeconds: 30 * 60, // 30 minutes
|
|
||||||
WorkerTimeoutSeconds: 5 * 60, // 5 minutes
|
|
||||||
TaskTimeoutSeconds: 2 * 60 * 60, // 2 hours
|
|
||||||
RetryDelaySeconds: 15 * 60, // 15 minutes
|
|
||||||
MaxRetries: 3,
|
|
||||||
CleanupIntervalSeconds: 24 * 60 * 60, // 24 hours
|
|
||||||
TaskRetentionSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
||||||
Policy: &MaintenancePolicy{
|
Policy: &MaintenancePolicy{
|
||||||
GlobalMaxConcurrent: 4,
|
|
||||||
DefaultRepeatInterval: 6,
|
DefaultRepeatInterval: 6,
|
||||||
DefaultCheckInterval: 12,
|
DefaultCheckInterval: 12,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply defaults from schema
|
||||||
|
schema := GetMaintenanceConfigSchema()
|
||||||
|
if err := schema.ApplyDefaults(config); err != nil {
|
||||||
|
// Fallback to hardcoded defaults if schema fails
|
||||||
|
config.Enabled = false
|
||||||
|
config.ScanIntervalSeconds = 30 * 60 // 30 minutes
|
||||||
|
config.WorkerTimeoutSeconds = 5 * 60 // 5 minutes
|
||||||
|
config.TaskTimeoutSeconds = 2 * 60 * 60 // 2 hours
|
||||||
|
config.RetryDelaySeconds = 15 * 60 // 15 minutes
|
||||||
|
config.MaxRetries = 3
|
||||||
|
config.CleanupIntervalSeconds = 24 * 60 * 60 // 24 hours
|
||||||
|
config.TaskRetentionSeconds = 7 * 24 * 60 * 60 // 7 days
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply policy defaults from schema
|
||||||
|
if config.Policy != nil {
|
||||||
|
if globalMaxField := schema.GetFieldByName("global_max_concurrent"); globalMaxField != nil {
|
||||||
|
if defaultVal, ok := globalMaxField.DefaultValue.(int); ok {
|
||||||
|
config.Policy.GlobalMaxConcurrent = defaultVal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaintenanceQueueData represents data for the queue visualization UI
|
// MaintenanceQueueData represents data for the queue visualization UI
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
|
|
||||||
@@ -396,10 +397,19 @@ func NewMaintenanceWorkerCommand(workerID, address, adminServer string) *Mainten
|
|||||||
|
|
||||||
// Run starts the maintenance worker as a standalone service
|
// Run starts the maintenance worker as a standalone service
|
||||||
func (mwc *MaintenanceWorkerCommand) Run() error {
|
func (mwc *MaintenanceWorkerCommand) Run() error {
|
||||||
// Generate worker ID if not provided
|
// Generate or load persistent worker ID if not provided
|
||||||
if mwc.workerService.workerID == "" {
|
if mwc.workerService.workerID == "" {
|
||||||
hostname, _ := os.Hostname()
|
// Get current working directory for worker ID persistence
|
||||||
mwc.workerService.workerID = fmt.Sprintf("worker-%s-%d", hostname, time.Now().Unix())
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get working directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
workerID, err := worker.GenerateOrLoadWorkerID(wd)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to generate or load worker ID: %w", err)
|
||||||
|
}
|
||||||
|
mwc.workerService.workerID = workerID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the worker service
|
// Start the worker service
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
z-index: 100;
|
z-index: 100;
|
||||||
padding: 48px 0 0;
|
padding: 48px 0 0;
|
||||||
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
|
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
|
||||||
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-heading {
|
.sidebar-heading {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
<div id="collections-content">
|
<div id="collections-content">
|
||||||
<!-- Summary Cards -->
|
<!-- Summary Cards -->
|
||||||
<div class="row mb-4">
|
<div class="row mb-4">
|
||||||
<div class="col-xl-3 col-md-6 mb-4">
|
<div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4">
|
||||||
<div class="card border-left-primary shadow h-100 py-2">
|
<div class="card border-left-primary shadow h-100 py-2">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row no-gutters align-items-center">
|
<div class="row no-gutters align-items-center">
|
||||||
@@ -42,13 +42,13 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xl-3 col-md-6 mb-4">
|
<div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4">
|
||||||
<div class="card border-left-info shadow h-100 py-2">
|
<div class="card border-left-info shadow h-100 py-2">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row no-gutters align-items-center">
|
<div class="row no-gutters align-items-center">
|
||||||
<div class="col mr-2">
|
<div class="col mr-2">
|
||||||
<div class="text-xs font-weight-bold text-info text-uppercase mb-1">
|
<div class="text-xs font-weight-bold text-info text-uppercase mb-1">
|
||||||
Total Volumes
|
Regular Volumes
|
||||||
</div>
|
</div>
|
||||||
<div class="h5 mb-0 font-weight-bold text-gray-800">
|
<div class="h5 mb-0 font-weight-bold text-gray-800">
|
||||||
{fmt.Sprintf("%d", data.TotalVolumes)}
|
{fmt.Sprintf("%d", data.TotalVolumes)}
|
||||||
@@ -62,7 +62,27 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xl-3 col-md-6 mb-4">
|
<div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4">
|
||||||
|
<div class="card border-left-success shadow h-100 py-2">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row no-gutters align-items-center">
|
||||||
|
<div class="col mr-2">
|
||||||
|
<div class="text-xs font-weight-bold text-success text-uppercase mb-1">
|
||||||
|
EC Volumes
|
||||||
|
</div>
|
||||||
|
<div class="h5 mb-0 font-weight-bold text-gray-800">
|
||||||
|
{fmt.Sprintf("%d", data.TotalEcVolumes)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<i class="fas fa-th-large fa-2x text-gray-300"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4">
|
||||||
<div class="card border-left-warning shadow h-100 py-2">
|
<div class="card border-left-warning shadow h-100 py-2">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row no-gutters align-items-center">
|
<div class="row no-gutters align-items-center">
|
||||||
@@ -76,19 +96,19 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<i class="fas fa-file fa-2x text-gray-300"></i>
|
<i class="fas fa-file fa-2x text-gray-300"></i>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-xl-3 col-md-6 mb-4">
|
<div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4">
|
||||||
<div class="card border-left-secondary shadow h-100 py-2">
|
<div class="card border-left-secondary shadow h-100 py-2">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row no-gutters align-items-center">
|
<div class="row no-gutters align-items-center">
|
||||||
<div class="col mr-2">
|
<div class="col mr-2">
|
||||||
<div class="text-xs font-weight-bold text-secondary text-uppercase mb-1">
|
<div class="text-xs font-weight-bold text-secondary text-uppercase mb-1">
|
||||||
Total Storage Size
|
Total Storage Size (Logical)
|
||||||
</div>
|
</div>
|
||||||
<div class="h5 mb-0 font-weight-bold text-gray-800">
|
<div class="h5 mb-0 font-weight-bold text-gray-800">
|
||||||
{formatBytes(data.TotalSize)}
|
{formatBytes(data.TotalSize)}
|
||||||
@@ -117,9 +137,10 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Collection Name</th>
|
<th>Collection Name</th>
|
||||||
<th>Volumes</th>
|
<th>Regular Volumes</th>
|
||||||
|
<th>EC Volumes</th>
|
||||||
<th>Files</th>
|
<th>Files</th>
|
||||||
<th>Size</th>
|
<th>Size (Logical)</th>
|
||||||
<th>Disk Types</th>
|
<th>Disk Types</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -128,7 +149,7 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
for _, collection := range data.Collections {
|
for _, collection := range data.Collections {
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href={templ.SafeURL(fmt.Sprintf("/cluster/volumes?collection=%s", collection.Name))} class="text-decoration-none">
|
<a href={templ.SafeURL(fmt.Sprintf("/cluster/collections/%s", collection.Name))} class="text-decoration-none">
|
||||||
<strong>{collection.Name}</strong>
|
<strong>{collection.Name}</strong>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -136,7 +157,23 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
<a href={templ.SafeURL(fmt.Sprintf("/cluster/volumes?collection=%s", collection.Name))} class="text-decoration-none">
|
<a href={templ.SafeURL(fmt.Sprintf("/cluster/volumes?collection=%s", collection.Name))} class="text-decoration-none">
|
||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<i class="fas fa-database me-2 text-muted"></i>
|
<i class="fas fa-database me-2 text-muted"></i>
|
||||||
{fmt.Sprintf("%d", collection.VolumeCount)}
|
if collection.VolumeCount > 0 {
|
||||||
|
{fmt.Sprintf("%d", collection.VolumeCount)}
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">0</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href={templ.SafeURL(fmt.Sprintf("/cluster/ec-shards?collection=%s", collection.Name))} class="text-decoration-none">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<i class="fas fa-th-large me-2 text-muted"></i>
|
||||||
|
if collection.EcVolumeCount > 0 {
|
||||||
|
{fmt.Sprintf("%d", collection.EcVolumeCount)}
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">0</span>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -171,6 +208,7 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
data-name={collection.Name}
|
data-name={collection.Name}
|
||||||
data-datacenter={collection.DataCenter}
|
data-datacenter={collection.DataCenter}
|
||||||
data-volume-count={fmt.Sprintf("%d", collection.VolumeCount)}
|
data-volume-count={fmt.Sprintf("%d", collection.VolumeCount)}
|
||||||
|
data-ec-volume-count={fmt.Sprintf("%d", collection.EcVolumeCount)}
|
||||||
data-file-count={fmt.Sprintf("%d", collection.FileCount)}
|
data-file-count={fmt.Sprintf("%d", collection.FileCount)}
|
||||||
data-total-size={fmt.Sprintf("%d", collection.TotalSize)}
|
data-total-size={fmt.Sprintf("%d", collection.TotalSize)}
|
||||||
data-disk-types={formatDiskTypes(collection.DiskTypes)}>
|
data-disk-types={formatDiskTypes(collection.DiskTypes)}>
|
||||||
@@ -223,6 +261,7 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
name: button.getAttribute('data-name'),
|
name: button.getAttribute('data-name'),
|
||||||
datacenter: button.getAttribute('data-datacenter'),
|
datacenter: button.getAttribute('data-datacenter'),
|
||||||
volumeCount: parseInt(button.getAttribute('data-volume-count')),
|
volumeCount: parseInt(button.getAttribute('data-volume-count')),
|
||||||
|
ecVolumeCount: parseInt(button.getAttribute('data-ec-volume-count')),
|
||||||
fileCount: parseInt(button.getAttribute('data-file-count')),
|
fileCount: parseInt(button.getAttribute('data-file-count')),
|
||||||
totalSize: parseInt(button.getAttribute('data-total-size')),
|
totalSize: parseInt(button.getAttribute('data-total-size')),
|
||||||
diskTypes: button.getAttribute('data-disk-types')
|
diskTypes: button.getAttribute('data-disk-types')
|
||||||
@@ -260,19 +299,25 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
'<div class="col-md-6">' +
|
'<div class="col-md-6">' +
|
||||||
'<h6 class="text-primary"><i class="fas fa-chart-bar me-1"></i>Storage Statistics</h6>' +
|
'<h6 class="text-primary"><i class="fas fa-chart-bar me-1"></i>Storage Statistics</h6>' +
|
||||||
'<table class="table table-sm">' +
|
'<table class="table table-sm">' +
|
||||||
'<tr><td><strong>Total Volumes:</strong></td><td>' +
|
'<tr><td><strong>Regular Volumes:</strong></td><td>' +
|
||||||
'<div class="d-flex align-items-center">' +
|
'<div class="d-flex align-items-center">' +
|
||||||
'<i class="fas fa-database me-2 text-muted"></i>' +
|
'<i class="fas fa-database me-2 text-muted"></i>' +
|
||||||
'<span>' + collection.volumeCount.toLocaleString() + '</span>' +
|
'<span>' + collection.volumeCount.toLocaleString() + '</span>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</td></tr>' +
|
'</td></tr>' +
|
||||||
|
'<tr><td><strong>EC Volumes:</strong></td><td>' +
|
||||||
|
'<div class="d-flex align-items-center">' +
|
||||||
|
'<i class="fas fa-th-large me-2 text-muted"></i>' +
|
||||||
|
'<span>' + collection.ecVolumeCount.toLocaleString() + '</span>' +
|
||||||
|
'</div>' +
|
||||||
|
'</td></tr>' +
|
||||||
'<tr><td><strong>Total Files:</strong></td><td>' +
|
'<tr><td><strong>Total Files:</strong></td><td>' +
|
||||||
'<div class="d-flex align-items-center">' +
|
'<div class="d-flex align-items-center">' +
|
||||||
'<i class="fas fa-file me-2 text-muted"></i>' +
|
'<i class="fas fa-file me-2 text-muted"></i>' +
|
||||||
'<span>' + collection.fileCount.toLocaleString() + '</span>' +
|
'<span>' + collection.fileCount.toLocaleString() + '</span>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</td></tr>' +
|
'</td></tr>' +
|
||||||
'<tr><td><strong>Total Size:</strong></td><td>' +
|
'<tr><td><strong>Total Size (Logical):</strong></td><td>' +
|
||||||
'<div class="d-flex align-items-center">' +
|
'<div class="d-flex align-items-center">' +
|
||||||
'<i class="fas fa-hdd me-2 text-muted"></i>' +
|
'<i class="fas fa-hdd me-2 text-muted"></i>' +
|
||||||
'<span>' + formatBytes(collection.totalSize) + '</span>' +
|
'<span>' + formatBytes(collection.totalSize) + '</span>' +
|
||||||
@@ -288,6 +333,9 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
'<a href="/cluster/volumes?collection=' + encodeURIComponent(collection.name) + '" class="btn btn-outline-primary">' +
|
'<a href="/cluster/volumes?collection=' + encodeURIComponent(collection.name) + '" class="btn btn-outline-primary">' +
|
||||||
'<i class="fas fa-database me-1"></i>View Volumes' +
|
'<i class="fas fa-database me-1"></i>View Volumes' +
|
||||||
'</a>' +
|
'</a>' +
|
||||||
|
'<a href="/cluster/ec-shards?collection=' + encodeURIComponent(collection.name) + '" class="btn btn-outline-secondary">' +
|
||||||
|
'<i class="fas fa-th-large me-1"></i>View EC Volumes' +
|
||||||
|
'</a>' +
|
||||||
'<a href="/files?collection=' + encodeURIComponent(collection.name) + '" class="btn btn-outline-info">' +
|
'<a href="/files?collection=' + encodeURIComponent(collection.name) + '" class="btn btn-outline-info">' +
|
||||||
'<i class="fas fa-folder me-1"></i>Browse Files' +
|
'<i class="fas fa-folder me-1"></i>Browse Files' +
|
||||||
'</a>' +
|
'</a>' +
|
||||||
@@ -295,6 +343,7 @@ templ ClusterCollections(data dash.ClusterCollectionsData) {
|
|||||||
'</div>' +
|
'</div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
|
'</div>' +
|
||||||
'<div class="modal-footer">' +
|
'<div class="modal-footer">' +
|
||||||
'<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>' +
|
'<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func ClusterCollections(data dash.ClusterCollectionsData) templ.Component {
|
|||||||
templ_7745c5c3_Var1 = templ.NopComponent
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom\"><h1 class=\"h2\"><i class=\"fas fa-layer-group me-2\"></i>Cluster Collections</h1><div class=\"btn-toolbar mb-2 mb-md-0\"><div class=\"btn-group me-2\"><button type=\"button\" class=\"btn btn-sm btn-outline-primary\" onclick=\"exportCollections()\"><i class=\"fas fa-download me-1\"></i>Export</button></div></div></div><div id=\"collections-content\"><!-- Summary Cards --><div class=\"row mb-4\"><div class=\"col-xl-3 col-md-6 mb-4\"><div class=\"card border-left-primary shadow h-100 py-2\"><div class=\"card-body\"><div class=\"row no-gutters align-items-center\"><div class=\"col mr-2\"><div class=\"text-xs font-weight-bold text-primary text-uppercase mb-1\">Total Collections</div><div class=\"h5 mb-0 font-weight-bold text-gray-800\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom\"><h1 class=\"h2\"><i class=\"fas fa-layer-group me-2\"></i>Cluster Collections</h1><div class=\"btn-toolbar mb-2 mb-md-0\"><div class=\"btn-group me-2\"><button type=\"button\" class=\"btn btn-sm btn-outline-primary\" onclick=\"exportCollections()\"><i class=\"fas fa-download me-1\"></i>Export</button></div></div></div><div id=\"collections-content\"><!-- Summary Cards --><div class=\"row mb-4\"><div class=\"col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4\"><div class=\"card border-left-primary shadow h-100 py-2\"><div class=\"card-body\"><div class=\"row no-gutters align-items-center\"><div class=\"col mr-2\"><div class=\"text-xs font-weight-bold text-primary text-uppercase mb-1\">Total Collections</div><div class=\"h5 mb-0 font-weight-bold text-gray-800\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ func ClusterCollections(data dash.ClusterCollectionsData) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</div></div><div class=\"col-auto\"><i class=\"fas fa-layer-group fa-2x text-gray-300\"></i></div></div></div></div></div><div class=\"col-xl-3 col-md-6 mb-4\"><div class=\"card border-left-info shadow h-100 py-2\"><div class=\"card-body\"><div class=\"row no-gutters align-items-center\"><div class=\"col mr-2\"><div class=\"text-xs font-weight-bold text-info text-uppercase mb-1\">Total Volumes</div><div class=\"h5 mb-0 font-weight-bold text-gray-800\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</div></div><div class=\"col-auto\"><i class=\"fas fa-layer-group fa-2x text-gray-300\"></i></div></div></div></div></div><div class=\"col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4\"><div class=\"card border-left-info shadow h-100 py-2\"><div class=\"card-body\"><div class=\"row no-gutters align-items-center\"><div class=\"col mr-2\"><div class=\"text-xs font-weight-bold text-info text-uppercase mb-1\">Regular Volumes</div><div class=\"h5 mb-0 font-weight-bold text-gray-800\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -60,284 +60,350 @@ func ClusterCollections(data dash.ClusterCollectionsData) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</div></div><div class=\"col-auto\"><i class=\"fas fa-database fa-2x text-gray-300\"></i></div></div></div></div></div><div class=\"col-xl-3 col-md-6 mb-4\"><div class=\"card border-left-warning shadow h-100 py-2\"><div class=\"card-body\"><div class=\"row no-gutters align-items-center\"><div class=\"col mr-2\"><div class=\"text-xs font-weight-bold text-warning text-uppercase mb-1\">Total Files</div><div class=\"h5 mb-0 font-weight-bold text-gray-800\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</div></div><div class=\"col-auto\"><i class=\"fas fa-database fa-2x text-gray-300\"></i></div></div></div></div></div><div class=\"col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4\"><div class=\"card border-left-success shadow h-100 py-2\"><div class=\"card-body\"><div class=\"row no-gutters align-items-center\"><div class=\"col mr-2\"><div class=\"text-xs font-weight-bold text-success text-uppercase mb-1\">EC Volumes</div><div class=\"h5 mb-0 font-weight-bold text-gray-800\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var4 string
|
var templ_7745c5c3_Var4 string
|
||||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalFiles))
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalEcVolumes))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 74, Col: 71}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 74, Col: 75}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</div></div><div class=\"col-auto\"><i class=\"fas fa-file fa-2x text-gray-300\"></i></div></div></div></div></div><div class=\"col-xl-3 col-md-6 mb-4\"><div class=\"card border-left-secondary shadow h-100 py-2\"><div class=\"card-body\"><div class=\"row no-gutters align-items-center\"><div class=\"col mr-2\"><div class=\"text-xs font-weight-bold text-secondary text-uppercase mb-1\">Total Storage Size</div><div class=\"h5 mb-0 font-weight-bold text-gray-800\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</div></div><div class=\"col-auto\"><i class=\"fas fa-th-large fa-2x text-gray-300\"></i></div></div></div></div></div><div class=\"col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4\"><div class=\"card border-left-warning shadow h-100 py-2\"><div class=\"card-body\"><div class=\"row no-gutters align-items-center\"><div class=\"col mr-2\"><div class=\"text-xs font-weight-bold text-warning text-uppercase mb-1\">Total Files</div><div class=\"h5 mb-0 font-weight-bold text-gray-800\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var5 string
|
var templ_7745c5c3_Var5 string
|
||||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(formatBytes(data.TotalSize))
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalFiles))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 94, Col: 64}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 94, Col: 71}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</div></div><div class=\"col-auto\"><i class=\"fas fa-hdd fa-2x text-gray-300\"></i></div></div></div></div></div></div><!-- Collections Table --><div class=\"card shadow mb-4\"><div class=\"card-header py-3\"><h6 class=\"m-0 font-weight-bold text-primary\"><i class=\"fas fa-layer-group me-2\"></i>Collection Details</h6></div><div class=\"card-body\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</div></div><div class=\"col-auto\"><i class=\"fas fa-file fa-2x text-gray-300\"></i></div></div></div></div></div><div class=\"col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4\"><div class=\"card border-left-secondary shadow h-100 py-2\"><div class=\"card-body\"><div class=\"row no-gutters align-items-center\"><div class=\"col mr-2\"><div class=\"text-xs font-weight-bold text-secondary text-uppercase mb-1\">Total Storage Size (Logical)</div><div class=\"h5 mb-0 font-weight-bold text-gray-800\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var6 string
|
||||||
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(formatBytes(data.TotalSize))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 114, Col: 64}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</div></div><div class=\"col-auto\"><i class=\"fas fa-hdd fa-2x text-gray-300\"></i></div></div></div></div></div></div><!-- Collections Table --><div class=\"card shadow mb-4\"><div class=\"card-header py-3\"><h6 class=\"m-0 font-weight-bold text-primary\"><i class=\"fas fa-layer-group me-2\"></i>Collection Details</h6></div><div class=\"card-body\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if len(data.Collections) > 0 {
|
if len(data.Collections) > 0 {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<div class=\"table-responsive\"><table class=\"table table-hover\" id=\"collectionsTable\"><thead><tr><th>Collection Name</th><th>Volumes</th><th>Files</th><th>Size</th><th>Disk Types</th><th>Actions</th></tr></thead> <tbody>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<div class=\"table-responsive\"><table class=\"table table-hover\" id=\"collectionsTable\"><thead><tr><th>Collection Name</th><th>Regular Volumes</th><th>EC Volumes</th><th>Files</th><th>Size (Logical)</th><th>Disk Types</th><th>Actions</th></tr></thead> <tbody>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
for _, collection := range data.Collections {
|
for _, collection := range data.Collections {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<tr><td><a href=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<tr><td><a href=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var6 templ.SafeURL
|
var templ_7745c5c3_Var7 templ.SafeURL
|
||||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("/cluster/volumes?collection=%s", collection.Name)))
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("/cluster/collections/%s", collection.Name)))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 131, Col: 130}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 152, Col: 123}
|
||||||
}
|
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "\" class=\"text-decoration-none\"><strong>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
var templ_7745c5c3_Var7 string
|
|
||||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(collection.Name)
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 132, Col: 68}
|
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</strong></a></td><td><a href=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" class=\"text-decoration-none\"><strong>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var8 templ.SafeURL
|
var templ_7745c5c3_Var8 string
|
||||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("/cluster/volumes?collection=%s", collection.Name)))
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(collection.Name)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 136, Col: 130}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 153, Col: 68}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\" class=\"text-decoration-none\"><div class=\"d-flex align-items-center\"><i class=\"fas fa-database me-2 text-muted\"></i> ")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "</strong></a></td><td><a href=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var9 string
|
var templ_7745c5c3_Var9 templ.SafeURL
|
||||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.VolumeCount))
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("/cluster/volumes?collection=%s", collection.Name)))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 139, Col: 90}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 157, Col: 130}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</div></a></td><td><div class=\"d-flex align-items-center\"><i class=\"fas fa-file me-2 text-muted\"></i> ")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "\" class=\"text-decoration-none\"><div class=\"d-flex align-items-center\"><i class=\"fas fa-database me-2 text-muted\"></i> ")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var10 string
|
if collection.VolumeCount > 0 {
|
||||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.FileCount))
|
var templ_7745c5c3_Var10 string
|
||||||
if templ_7745c5c3_Err != nil {
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.VolumeCount))
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 146, Col: 88}
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 161, Col: 94}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<span class=\"text-muted\">0</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</div></a></td><td><a href=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</div></td><td><div class=\"d-flex align-items-center\"><i class=\"fas fa-hdd me-2 text-muted\"></i> ")
|
var templ_7745c5c3_Var11 templ.SafeURL
|
||||||
|
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("/cluster/ec-shards?collection=%s", collection.Name)))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 169, Col: 132}
|
||||||
}
|
|
||||||
var templ_7745c5c3_Var11 string
|
|
||||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(formatBytes(collection.TotalSize))
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 152, Col: 82}
|
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</div></td><td>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "\" class=\"text-decoration-none\"><div class=\"d-flex align-items-center\"><i class=\"fas fa-th-large me-2 text-muted\"></i> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if collection.EcVolumeCount > 0 {
|
||||||
|
var templ_7745c5c3_Var12 string
|
||||||
|
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.EcVolumeCount))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 173, Col: 96}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<span class=\"text-muted\">0</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</div></a></td><td><div class=\"d-flex align-items-center\"><i class=\"fas fa-file me-2 text-muted\"></i> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var13 string
|
||||||
|
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.FileCount))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 183, Col: 88}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "</div></td><td><div class=\"d-flex align-items-center\"><i class=\"fas fa-hdd me-2 text-muted\"></i> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var14 string
|
||||||
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(formatBytes(collection.TotalSize))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 189, Col: 82}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</div></td><td>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
for i, diskType := range collection.DiskTypes {
|
for i, diskType := range collection.DiskTypes {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "<span class=\"me-1\"></span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<span class=\"me-1\"></span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " ")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, " ")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var12 = []any{fmt.Sprintf("badge bg-%s me-1", getDiskTypeColor(diskType))}
|
var templ_7745c5c3_Var15 = []any{fmt.Sprintf("badge bg-%s me-1", getDiskTypeColor(diskType))}
|
||||||
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var12...)
|
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var15...)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "<span class=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "<span class=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var13 string
|
var templ_7745c5c3_Var16 string
|
||||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var12).String())
|
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var15).String())
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 1, Col: 0}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 1, Col: 0}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var14 string
|
var templ_7745c5c3_Var17 string
|
||||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(diskType)
|
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(diskType)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 160, Col: 131}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 197, Col: 131}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</span> ")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "</span> ")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(collection.DiskTypes) == 0 {
|
if len(collection.DiskTypes) == 0 {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<span class=\"text-muted\">Unknown</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "<span class=\"text-muted\">Unknown</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</td><td><button type=\"button\" class=\"btn btn-outline-primary btn-sm\" title=\"View Details\" data-action=\"view-details\" data-name=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</td><td><button type=\"button\" class=\"btn btn-outline-primary btn-sm\" title=\"View Details\" data-action=\"view-details\" data-name=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
var templ_7745c5c3_Var15 string
|
|
||||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(collection.Name)
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 171, Col: 78}
|
|
||||||
}
|
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "\" data-datacenter=\"")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
var templ_7745c5c3_Var16 string
|
|
||||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(collection.DataCenter)
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 172, Col: 90}
|
|
||||||
}
|
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "\" data-volume-count=\"")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
var templ_7745c5c3_Var17 string
|
|
||||||
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.VolumeCount))
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 173, Col: 112}
|
|
||||||
}
|
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "\" data-file-count=\"")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var18 string
|
var templ_7745c5c3_Var18 string
|
||||||
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.FileCount))
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(collection.Name)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 174, Col: 108}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 208, Col: 78}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "\" data-total-size=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "\" data-datacenter=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var19 string
|
var templ_7745c5c3_Var19 string
|
||||||
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.TotalSize))
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(collection.DataCenter)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 175, Col: 108}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 209, Col: 90}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "\" data-disk-types=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\" data-volume-count=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var20 string
|
var templ_7745c5c3_Var20 string
|
||||||
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(formatDiskTypes(collection.DiskTypes))
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.VolumeCount))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 176, Col: 106}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 210, Col: 112}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "\"><i class=\"fas fa-eye\"></i></button></td></tr>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "\" data-ec-volume-count=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var21 string
|
||||||
|
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.EcVolumeCount))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 211, Col: 117}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "\" data-file-count=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var22 string
|
||||||
|
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.FileCount))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 212, Col: 108}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "\" data-total-size=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var23 string
|
||||||
|
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", collection.TotalSize))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 213, Col: 108}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "\" data-disk-types=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var24 string
|
||||||
|
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(formatDiskTypes(collection.DiskTypes))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 214, Col: 106}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "\"><i class=\"fas fa-eye\"></i></button></td></tr>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "</tbody></table></div>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "</tbody></table></div>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<div class=\"text-center py-5\"><i class=\"fas fa-layer-group fa-3x text-muted mb-3\"></i><h5 class=\"text-muted\">No Collections Found</h5><p class=\"text-muted\">No collections are currently configured in the cluster.</p></div>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "<div class=\"text-center py-5\"><i class=\"fas fa-layer-group fa-3x text-muted mb-3\"></i><h5 class=\"text-muted\">No Collections Found</h5><p class=\"text-muted\">No collections are currently configured in the cluster.</p></div>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "</div></div><!-- Last Updated --><div class=\"row\"><div class=\"col-12\"><small class=\"text-muted\"><i class=\"fas fa-clock me-1\"></i> Last updated: ")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "</div></div><!-- Last Updated --><div class=\"row\"><div class=\"col-12\"><small class=\"text-muted\"><i class=\"fas fa-clock me-1\"></i> Last updated: ")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var21 string
|
var templ_7745c5c3_Var25 string
|
||||||
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(data.LastUpdated.Format("2006-01-02 15:04:05"))
|
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(data.LastUpdated.Format("2006-01-02 15:04:05"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 200, Col: 81}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_collections.templ`, Line: 238, Col: 81}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "</small></div></div></div><!-- JavaScript for cluster collections functionality --><script>\n document.addEventListener('DOMContentLoaded', function() {\n // Handle collection action buttons\n document.addEventListener('click', function(e) {\n const button = e.target.closest('[data-action]');\n if (!button) return;\n \n const action = button.getAttribute('data-action');\n \n switch(action) {\n case 'view-details':\n const collectionData = {\n name: button.getAttribute('data-name'),\n datacenter: button.getAttribute('data-datacenter'),\n volumeCount: parseInt(button.getAttribute('data-volume-count')),\n fileCount: parseInt(button.getAttribute('data-file-count')),\n totalSize: parseInt(button.getAttribute('data-total-size')),\n diskTypes: button.getAttribute('data-disk-types')\n };\n showCollectionDetails(collectionData);\n break;\n }\n });\n });\n \n function showCollectionDetails(collection) {\n const modalHtml = '<div class=\"modal fade\" id=\"collectionDetailsModal\" tabindex=\"-1\">' +\n '<div class=\"modal-dialog modal-lg\">' +\n '<div class=\"modal-content\">' +\n '<div class=\"modal-header\">' +\n '<h5 class=\"modal-title\"><i class=\"fas fa-layer-group me-2\"></i>Collection Details: ' + collection.name + '</h5>' +\n '<button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\"></button>' +\n '</div>' +\n '<div class=\"modal-body\">' +\n '<div class=\"row\">' +\n '<div class=\"col-md-6\">' +\n '<h6 class=\"text-primary\"><i class=\"fas fa-info-circle me-1\"></i>Basic Information</h6>' +\n '<table class=\"table table-sm\">' +\n '<tr><td><strong>Collection Name:</strong></td><td><code>' + collection.name + '</code></td></tr>' +\n '<tr><td><strong>Data Center:</strong></td><td>' +\n (collection.datacenter ? '<span class=\"badge bg-light text-dark\">' + collection.datacenter + '</span>' : '<span class=\"text-muted\">N/A</span>') +\n '</td></tr>' +\n '<tr><td><strong>Disk Types:</strong></td><td>' +\n (collection.diskTypes ? collection.diskTypes.split(', ').map(type => \n '<span class=\"badge bg-' + getDiskTypeBadgeColor(type) + ' me-1\">' + type + '</span>'\n ).join('') : '<span class=\"text-muted\">Unknown</span>') +\n '</td></tr>' +\n '</table>' +\n '</div>' +\n '<div class=\"col-md-6\">' +\n '<h6 class=\"text-primary\"><i class=\"fas fa-chart-bar me-1\"></i>Storage Statistics</h6>' +\n '<table class=\"table table-sm\">' +\n '<tr><td><strong>Total Volumes:</strong></td><td>' +\n '<div class=\"d-flex align-items-center\">' +\n '<i class=\"fas fa-database me-2 text-muted\"></i>' +\n '<span>' + collection.volumeCount.toLocaleString() + '</span>' +\n '</div>' +\n '</td></tr>' +\n '<tr><td><strong>Total Files:</strong></td><td>' +\n '<div class=\"d-flex align-items-center\">' +\n '<i class=\"fas fa-file me-2 text-muted\"></i>' +\n '<span>' + collection.fileCount.toLocaleString() + '</span>' +\n '</div>' +\n '</td></tr>' +\n '<tr><td><strong>Total Size:</strong></td><td>' +\n '<div class=\"d-flex align-items-center\">' +\n '<i class=\"fas fa-hdd me-2 text-muted\"></i>' +\n '<span>' + formatBytes(collection.totalSize) + '</span>' +\n '</div>' +\n '</td></tr>' +\n '</table>' +\n '</div>' +\n '</div>' +\n '<div class=\"row mt-3\">' +\n '<div class=\"col-12\">' +\n '<h6 class=\"text-primary\"><i class=\"fas fa-link me-1\"></i>Quick Actions</h6>' +\n '<div class=\"d-grid gap-2 d-md-flex\">' +\n '<a href=\"/cluster/volumes?collection=' + encodeURIComponent(collection.name) + '\" class=\"btn btn-outline-primary\">' +\n '<i class=\"fas fa-database me-1\"></i>View Volumes' +\n '</a>' +\n '<a href=\"/files?collection=' + encodeURIComponent(collection.name) + '\" class=\"btn btn-outline-info\">' +\n '<i class=\"fas fa-folder me-1\"></i>Browse Files' +\n '</a>' +\n '</div>' +\n '</div>' +\n '</div>' +\n '</div>' +\n '<div class=\"modal-footer\">' +\n '<button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modaLine truncated
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "</small></div></div></div><!-- JavaScript for cluster collections functionality --><script>\n document.addEventListener('DOMContentLoaded', function() {\n // Handle collection action buttons\n document.addEventListener('click', function(e) {\n const button = e.target.closest('[data-action]');\n if (!button) return;\n \n const action = button.getAttribute('data-action');\n \n switch(action) {\n case 'view-details':\n const collectionData = {\n name: button.getAttribute('data-name'),\n datacenter: button.getAttribute('data-datacenter'),\n volumeCount: parseInt(button.getAttribute('data-volume-count')),\n ecVolumeCount: parseInt(button.getAttribute('data-ec-volume-count')),\n fileCount: parseInt(button.getAttribute('data-file-count')),\n totalSize: parseInt(button.getAttribute('data-total-size')),\n diskTypes: button.getAttribute('data-disk-types')\n };\n showCollectionDetails(collectionData);\n break;\n }\n });\n });\n \n function showCollectionDetails(collection) {\n const modalHtml = '<div class=\"modal fade\" id=\"collectionDetailsModal\" tabindex=\"-1\">' +\n '<div class=\"modal-dialog modal-lg\">' +\n '<div class=\"modal-content\">' +\n '<div class=\"modal-header\">' +\n '<h5 class=\"modal-title\"><i class=\"fas fa-layer-group me-2\"></i>Collection Details: ' + collection.name + '</h5>' +\n '<button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\"></button>' +\n '</div>' +\n '<div class=\"modal-body\">' +\n '<div class=\"row\">' +\n '<div class=\"col-md-6\">' +\n '<h6 class=\"text-primary\"><i class=\"fas fa-info-circle me-1\"></i>Basic Information</h6>' +\n '<table class=\"table table-sm\">' +\n '<tr><td><strong>Collection Name:</strong></td><td><code>' + collection.name + '</code></td></tr>' +\n '<tr><td><strong>Data Center:</strong></td><td>' +\n (collection.datacenter ? '<span class=\"badge bg-light text-dark\">' + collection.datacenter + '</span>' : '<span class=\"text-muted\">N/A</span>') +\n '</td></tr>' +\n '<tr><td><strong>Disk Types:</strong></td><td>' +\n (collection.diskTypes ? collection.diskTypes.split(', ').map(type => \n '<span class=\"badge bg-' + getDiskTypeBadgeColor(type) + ' me-1\">' + type + '</span>'\n ).join('') : '<span class=\"text-muted\">Unknown</span>') +\n '</td></tr>' +\n '</table>' +\n '</div>' +\n '<div class=\"col-md-6\">' +\n '<h6 class=\"text-primary\"><i class=\"fas fa-chart-bar me-1\"></i>Storage Statistics</h6>' +\n '<table class=\"table table-sm\">' +\n '<tr><td><strong>Regular Volumes:</strong></td><td>' +\n '<div class=\"d-flex align-items-center\">' +\n '<i class=\"fas fa-database me-2 text-muted\"></i>' +\n '<span>' + collection.volumeCount.toLocaleString() + '</span>' +\n '</div>' +\n '</td></tr>' +\n '<tr><td><strong>EC Volumes:</strong></td><td>' +\n '<div class=\"d-flex align-items-center\">' +\n '<i class=\"fas fa-th-large me-2 text-muted\"></i>' +\n '<span>' + collection.ecVolumeCount.toLocaleString() + '</span>' +\n '</div>' +\n '</td></tr>' +\n '<tr><td><strong>Total Files:</strong></td><td>' +\n '<div class=\"d-flex align-items-center\">' +\n '<i class=\"fas fa-file me-2 text-muted\"></i>' +\n '<span>' + collection.fileCount.toLocaleString() + '</span>' +\n '</div>' +\n '</td></tr>' +\n '<tr><td><strong>Total Size (Logical):</strong></td><td>' +\n '<div class=\"d-flex align-items-center\">' +\n '<i class=\"fas fa-hdd me-2 text-muted\"></i>' +\n '<span>' + formatBytes(collection.totalSize) + '</span>' +\n '</div>' +\n '</td></tr>' +\n '</table>' +\n '</div>' +\n '</div>' +\n '<div class=\"row mt-3\">' +\n '<div class=\"col-12\">' +\n '<h6 class=\"text-primary\"><i class=\"fas fa-link me-1\"></i>Quick Actions</h6>' +\n '<div class=\"d-grid gap-2 d-md-flex\">' +\n '<a href=\"/cluster/volumes?collection=' + encodeURIComponent(collection.name) + '\" class=\"btn btn-outline-primary\">' +\n '<i class=\"fas fa-database me-1\"></i>View Volumes' +\n '</a>' +\n Line truncated
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,455 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||||
|
)
|
||||||
|
|
||||||
|
templ ClusterEcShards(data dash.ClusterEcShardsData) {
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<div>
|
||||||
|
<h1 class="h2">
|
||||||
|
<i class="fas fa-th-large me-2"></i>EC Shards
|
||||||
|
</h1>
|
||||||
|
if data.FilterCollection != "" {
|
||||||
|
<div class="d-flex align-items-center mt-2">
|
||||||
|
if data.FilterCollection == "default" {
|
||||||
|
<span class="badge bg-secondary text-white me-2">
|
||||||
|
<i class="fas fa-filter me-1"></i>Collection: default
|
||||||
|
</span>
|
||||||
|
} else {
|
||||||
|
<span class="badge bg-info text-white me-2">
|
||||||
|
<i class="fas fa-filter me-1"></i>Collection: {data.FilterCollection}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
<a href="/cluster/ec-shards" class="btn btn-sm btn-outline-secondary">
|
||||||
|
<i class="fas fa-times me-1"></i>Clear Filter
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
<div class="btn-group me-2">
|
||||||
|
<select class="form-select form-select-sm me-2" id="pageSizeSelect" onchange="changePageSize()" style="width: auto;">
|
||||||
|
<option value="50" if data.PageSize == 50 { selected="selected" }>50 per page</option>
|
||||||
|
<option value="100" if data.PageSize == 100 { selected="selected" }>100 per page</option>
|
||||||
|
<option value="200" if data.PageSize == 200 { selected="selected" }>200 per page</option>
|
||||||
|
<option value="500" if data.PageSize == 500 { selected="selected" }>500 per page</option>
|
||||||
|
</select>
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-primary" onclick="exportEcShards()">
|
||||||
|
<i class="fas fa-download me-1"></i>Export
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Statistics Cards -->
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-primary">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">Total Shards</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.TotalShards)}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-puzzle-piece fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-info">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">EC Volumes</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.TotalVolumes)}</h4>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-database fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-success">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">Healthy Volumes</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.VolumesWithAllShards)}</h4>
|
||||||
|
<small>Complete (14/14 shards)</small>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-check-circle fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-warning">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">Degraded Volumes</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.VolumesWithMissingShards)}</h4>
|
||||||
|
<small>Incomplete/Critical</small>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-exclamation-triangle fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Shards Table -->
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover" id="ecShardsTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('volume_id')" class="text-dark text-decoration-none">
|
||||||
|
Volume ID
|
||||||
|
if data.SortBy == "volume_id" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
|
||||||
|
if data.ShowCollectionColumn {
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('collection')" class="text-dark text-decoration-none">
|
||||||
|
Collection
|
||||||
|
if data.SortBy == "collection" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
}
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('server')" class="text-dark text-decoration-none">
|
||||||
|
Server
|
||||||
|
if data.SortBy == "server" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
if data.ShowDataCenterColumn {
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('datacenter')" class="text-dark text-decoration-none">
|
||||||
|
Data Center
|
||||||
|
if data.SortBy == "datacenter" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
}
|
||||||
|
if data.ShowRackColumn {
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('rack')" class="text-dark text-decoration-none">
|
||||||
|
Rack
|
||||||
|
if data.SortBy == "rack" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
}
|
||||||
|
<th class="text-dark">Distribution</th>
|
||||||
|
<th class="text-dark">Status</th>
|
||||||
|
<th class="text-dark">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
for _, shard := range data.EcShards {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<span class="fw-bold">{fmt.Sprintf("%d", shard.VolumeID)}</span>
|
||||||
|
</td>
|
||||||
|
if data.ShowCollectionColumn {
|
||||||
|
<td>
|
||||||
|
if shard.Collection != "" {
|
||||||
|
<a href="/cluster/ec-shards?collection={shard.Collection}" class="text-decoration-none">
|
||||||
|
<span class="badge bg-info text-white">{shard.Collection}</span>
|
||||||
|
</a>
|
||||||
|
} else {
|
||||||
|
<a href="/cluster/ec-shards?collection=default" class="text-decoration-none">
|
||||||
|
<span class="badge bg-secondary text-white">default</span>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
}
|
||||||
|
<td>
|
||||||
|
<code class="small">{shard.Server}</code>
|
||||||
|
</td>
|
||||||
|
if data.ShowDataCenterColumn {
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-outline-primary">{shard.DataCenter}</span>
|
||||||
|
</td>
|
||||||
|
}
|
||||||
|
if data.ShowRackColumn {
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-outline-secondary">{shard.Rack}</span>
|
||||||
|
</td>
|
||||||
|
}
|
||||||
|
<td>
|
||||||
|
@displayShardDistribution(shard, data.EcShards)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@displayVolumeStatus(shard)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-primary"
|
||||||
|
onclick="showShardDetails(event)"
|
||||||
|
data-volume-id={ fmt.Sprintf("%d", shard.VolumeID) }
|
||||||
|
title="View EC volume details">
|
||||||
|
<i class="fas fa-info-circle"></i>
|
||||||
|
</button>
|
||||||
|
if !shard.IsComplete {
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-warning"
|
||||||
|
onclick="repairVolume(event)"
|
||||||
|
data-volume-id={ fmt.Sprintf("%d", shard.VolumeID) }
|
||||||
|
title="Repair missing shards">
|
||||||
|
<i class="fas fa-wrench"></i>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pagination -->
|
||||||
|
if data.TotalPages > 1 {
|
||||||
|
<nav aria-label="EC Shards pagination">
|
||||||
|
<ul class="pagination justify-content-center">
|
||||||
|
if data.CurrentPage > 1 {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.CurrentPage-1) }>
|
||||||
|
<i class="fas fa-chevron-left"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
|
||||||
|
<!-- First page -->
|
||||||
|
if data.CurrentPage > 3 {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(1)">1</a>
|
||||||
|
</li>
|
||||||
|
if data.CurrentPage > 4 {
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">...</span>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<!-- Current page and neighbors -->
|
||||||
|
if data.CurrentPage > 1 && data.CurrentPage-1 >= 1 {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.CurrentPage-1) }>{fmt.Sprintf("%d", data.CurrentPage-1)}</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
|
||||||
|
<li class="page-item active">
|
||||||
|
<span class="page-link">{fmt.Sprintf("%d", data.CurrentPage)}</span>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
if data.CurrentPage < data.TotalPages && data.CurrentPage+1 <= data.TotalPages {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.CurrentPage+1) }>{fmt.Sprintf("%d", data.CurrentPage+1)}</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
|
||||||
|
<!-- Last page -->
|
||||||
|
if data.CurrentPage < data.TotalPages-2 {
|
||||||
|
if data.CurrentPage < data.TotalPages-3 {
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">...</span>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.TotalPages) }>{fmt.Sprintf("%d", data.TotalPages)}</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.CurrentPage < data.TotalPages {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.CurrentPage+1) }>
|
||||||
|
<i class="fas fa-chevron-right"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
<!-- JavaScript -->
|
||||||
|
<script>
|
||||||
|
function sortBy(field) {
|
||||||
|
const currentSort = "{data.SortBy}";
|
||||||
|
const currentOrder = "{data.SortOrder}";
|
||||||
|
let newOrder = 'asc';
|
||||||
|
|
||||||
|
if (currentSort === field && currentOrder === 'asc') {
|
||||||
|
newOrder = 'desc';
|
||||||
|
}
|
||||||
|
|
||||||
|
updateUrl({
|
||||||
|
sortBy: field,
|
||||||
|
sortOrder: newOrder,
|
||||||
|
page: 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function goToPage(event) {
|
||||||
|
// Get data from the link element (not any child elements)
|
||||||
|
const link = event.target.closest('a');
|
||||||
|
const page = link.getAttribute('data-page');
|
||||||
|
updateUrl({ page: page });
|
||||||
|
}
|
||||||
|
|
||||||
|
function changePageSize() {
|
||||||
|
const pageSize = document.getElementById('pageSizeSelect').value;
|
||||||
|
updateUrl({ pageSize: pageSize, page: 1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateUrl(params) {
|
||||||
|
const url = new URL(window.location);
|
||||||
|
Object.keys(params).forEach(key => {
|
||||||
|
if (params[key]) {
|
||||||
|
url.searchParams.set(key, params[key]);
|
||||||
|
} else {
|
||||||
|
url.searchParams.delete(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportEcShards() {
|
||||||
|
const url = new URL('/api/cluster/ec-shards/export', window.location.origin);
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
params.forEach((value, key) => {
|
||||||
|
url.searchParams.set(key, value);
|
||||||
|
});
|
||||||
|
window.open(url.toString(), '_blank');
|
||||||
|
}
|
||||||
|
|
||||||
|
function showShardDetails(event) {
|
||||||
|
// Get data from the button element (not the icon inside it)
|
||||||
|
const button = event.target.closest('button');
|
||||||
|
const volumeId = button.getAttribute('data-volume-id');
|
||||||
|
|
||||||
|
// Navigate to the EC volume details page
|
||||||
|
window.location.href = `/cluster/ec-volumes/${volumeId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function repairVolume(event) {
|
||||||
|
// Get data from the button element (not the icon inside it)
|
||||||
|
const button = event.target.closest('button');
|
||||||
|
const volumeId = button.getAttribute('data-volume-id');
|
||||||
|
if (confirm(`Are you sure you want to repair missing shards for volume ${volumeId}?`)) {
|
||||||
|
fetch(`/api/cluster/volumes/${volumeId}/repair`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
alert('Repair initiated successfully');
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert('Failed to initiate repair: ' + data.error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
alert('Error: ' + error.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
|
||||||
|
// displayShardDistribution shows the distribution summary for a volume's shards
|
||||||
|
templ displayShardDistribution(shard dash.EcShardWithInfo, allShards []dash.EcShardWithInfo) {
|
||||||
|
<div class="small">
|
||||||
|
<i class="fas fa-sitemap me-1"></i>
|
||||||
|
{ calculateDistributionSummary(shard.VolumeID, allShards) }
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
// displayVolumeStatus shows an improved status display
|
||||||
|
templ displayVolumeStatus(shard dash.EcShardWithInfo) {
|
||||||
|
if shard.IsComplete {
|
||||||
|
<span class="badge bg-success"><i class="fas fa-check me-1"></i>Complete</span>
|
||||||
|
} else {
|
||||||
|
if len(shard.MissingShards) > 10 {
|
||||||
|
<span class="badge bg-danger"><i class="fas fa-skull me-1"></i>Critical ({fmt.Sprintf("%d", len(shard.MissingShards))} missing)</span>
|
||||||
|
} else if len(shard.MissingShards) > 6 {
|
||||||
|
<span class="badge bg-warning"><i class="fas fa-exclamation-triangle me-1"></i>Degraded ({fmt.Sprintf("%d", len(shard.MissingShards))} missing)</span>
|
||||||
|
} else if len(shard.MissingShards) > 2 {
|
||||||
|
<span class="badge bg-warning"><i class="fas fa-info-circle me-1"></i>Incomplete ({fmt.Sprintf("%d", len(shard.MissingShards))} missing)</span>
|
||||||
|
} else {
|
||||||
|
<span class="badge bg-info"><i class="fas fa-info-circle me-1"></i>Minor Issues ({fmt.Sprintf("%d", len(shard.MissingShards))} missing)</span>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculateDistributionSummary calculates and formats the distribution summary
|
||||||
|
func calculateDistributionSummary(volumeID uint32, allShards []dash.EcShardWithInfo) string {
|
||||||
|
dataCenters := make(map[string]bool)
|
||||||
|
racks := make(map[string]bool)
|
||||||
|
servers := make(map[string]bool)
|
||||||
|
|
||||||
|
for _, s := range allShards {
|
||||||
|
if s.VolumeID == volumeID {
|
||||||
|
dataCenters[s.DataCenter] = true
|
||||||
|
racks[s.Rack] = true
|
||||||
|
servers[s.Server] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%d DCs, %d racks, %d servers", len(dataCenters), len(racks), len(servers))
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,840 @@
|
|||||||
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
|
// templ: version: v0.3.906
|
||||||
|
package app
|
||||||
|
|
||||||
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
|
|
||||||
|
import "github.com/a-h/templ"
|
||||||
|
import templruntime "github.com/a-h/templ/runtime"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ClusterEcShards(data dash.ClusterEcShardsData) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var1 == nil {
|
||||||
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom\"><div><h1 class=\"h2\"><i class=\"fas fa-th-large me-2\"></i>EC Shards</h1>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.FilterCollection != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<div class=\"d-flex align-items-center mt-2\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.FilterCollection == "default" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<span class=\"badge bg-secondary text-white me-2\"><i class=\"fas fa-filter me-1\"></i>Collection: default</span> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<span class=\"badge bg-info text-white me-2\"><i class=\"fas fa-filter me-1\"></i>Collection: ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var2 string
|
||||||
|
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(data.FilterCollection)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 22, Col: 96}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</span> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<a href=\"/cluster/ec-shards\" class=\"btn btn-sm btn-outline-secondary\"><i class=\"fas fa-times me-1\"></i>Clear Filter</a></div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "</div><div class=\"btn-toolbar mb-2 mb-md-0\"><div class=\"btn-group me-2\"><select class=\"form-select form-select-sm me-2\" id=\"pageSizeSelect\" onchange=\"changePageSize()\" style=\"width: auto;\"><option value=\"50\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.PageSize == 50 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " selected=\"selected\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, ">50 per page</option> <option value=\"100\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.PageSize == 100 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, " selected=\"selected\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, ">100 per page</option> <option value=\"200\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.PageSize == 200 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, " selected=\"selected\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, ">200 per page</option> <option value=\"500\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.PageSize == 500 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, " selected=\"selected\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, ">500 per page</option></select> <button type=\"button\" class=\"btn btn-sm btn-outline-primary\" onclick=\"exportEcShards()\"><i class=\"fas fa-download me-1\"></i>Export</button></div></div></div><!-- Statistics Cards --><div class=\"row mb-4\"><div class=\"col-md-3\"><div class=\"card text-bg-primary\"><div class=\"card-body\"><div class=\"d-flex justify-content-between\"><div><h6 class=\"card-title\">Total Shards</h6><h4 class=\"mb-0\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var3 string
|
||||||
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalShards))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 54, Col: 81}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</h4></div><div class=\"align-self-center\"><i class=\"fas fa-puzzle-piece fa-2x\"></i></div></div></div></div></div><div class=\"col-md-3\"><div class=\"card text-bg-info\"><div class=\"card-body\"><div class=\"d-flex justify-content-between\"><div><h6 class=\"card-title\">EC Volumes</h6><h4 class=\"mb-0\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var4 string
|
||||||
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalVolumes))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 69, Col: 82}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "</h4></div><div class=\"align-self-center\"><i class=\"fas fa-database fa-2x\"></i></div></div></div></div></div><div class=\"col-md-3\"><div class=\"card text-bg-success\"><div class=\"card-body\"><div class=\"d-flex justify-content-between\"><div><h6 class=\"card-title\">Healthy Volumes</h6><h4 class=\"mb-0\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var5 string
|
||||||
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.VolumesWithAllShards))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 84, Col: 90}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</h4><small>Complete (14/14 shards)</small></div><div class=\"align-self-center\"><i class=\"fas fa-check-circle fa-2x\"></i></div></div></div></div></div><div class=\"col-md-3\"><div class=\"card text-bg-warning\"><div class=\"card-body\"><div class=\"d-flex justify-content-between\"><div><h6 class=\"card-title\">Degraded Volumes</h6><h4 class=\"mb-0\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var6 string
|
||||||
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.VolumesWithMissingShards))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 100, Col: 94}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</h4><small>Incomplete/Critical</small></div><div class=\"align-self-center\"><i class=\"fas fa-exclamation-triangle fa-2x\"></i></div></div></div></div></div></div><!-- Shards Table --><div class=\"table-responsive\"><table class=\"table table-striped table-hover\" id=\"ecShardsTable\"><thead><tr><th><a href=\"#\" onclick=\"sortBy('volume_id')\" class=\"text-dark text-decoration-none\">Volume ID ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "volume_id" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "</a></th>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.ShowCollectionColumn {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "<th><a href=\"#\" onclick=\"sortBy('collection')\" class=\"text-dark text-decoration-none\">Collection ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "collection" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "</a></th>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "<th><a href=\"#\" onclick=\"sortBy('server')\" class=\"text-dark text-decoration-none\">Server ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "server" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "</a></th>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.ShowDataCenterColumn {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "<th><a href=\"#\" onclick=\"sortBy('datacenter')\" class=\"text-dark text-decoration-none\">Data Center ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "datacenter" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "</a></th>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if data.ShowRackColumn {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "<th><a href=\"#\" onclick=\"sortBy('rack')\" class=\"text-dark text-decoration-none\">Rack ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "rack" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "</a></th>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "<th class=\"text-dark\">Distribution</th><th class=\"text-dark\">Status</th><th class=\"text-dark\">Actions</th></tr></thead> <tbody>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, shard := range data.EcShards {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "<tr><td><span class=\"fw-bold\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var7 string
|
||||||
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", shard.VolumeID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 203, Col: 84}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "</span></td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.ShowCollectionColumn {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "<td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if shard.Collection != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "<a href=\"/cluster/ec-shards?collection={shard.Collection}\" class=\"text-decoration-none\"><span class=\"badge bg-info text-white\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var8 string
|
||||||
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(shard.Collection)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 209, Col: 96}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "</span></a>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "<a href=\"/cluster/ec-shards?collection=default\" class=\"text-decoration-none\"><span class=\"badge bg-secondary text-white\">default</span></a>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "</td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "<td><code class=\"small\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var9 string
|
||||||
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(shard.Server)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 219, Col: 61}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "</code></td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.ShowDataCenterColumn {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "<td><span class=\"badge bg-outline-primary\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var10 string
|
||||||
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(shard.DataCenter)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 223, Col: 88}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "</span></td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if data.ShowRackColumn {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "<td><span class=\"badge bg-outline-secondary\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var11 string
|
||||||
|
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(shard.Rack)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 228, Col: 84}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "</span></td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "<td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = displayShardDistribution(shard, data.EcShards).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = displayVolumeStatus(shard).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "</td><td><div class=\"btn-group\" role=\"group\"><button type=\"button\" class=\"btn btn-sm btn-outline-primary\" onclick=\"showShardDetails(event)\" data-volume-id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var12 string
|
||||||
|
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", shard.VolumeID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 241, Col: 90}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "\" title=\"View EC volume details\"><i class=\"fas fa-info-circle\"></i></button> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if !shard.IsComplete {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "<button type=\"button\" class=\"btn btn-sm btn-outline-warning\" onclick=\"repairVolume(event)\" data-volume-id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var13 string
|
||||||
|
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", shard.VolumeID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 248, Col: 94}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "\" title=\"Repair missing shards\"><i class=\"fas fa-wrench\"></i></button>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "</div></td></tr>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "</tbody></table></div><!-- Pagination -->")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.TotalPages > 1 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "<nav aria-label=\"EC Shards pagination\"><ul class=\"pagination justify-content-center\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.CurrentPage > 1 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "<li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(event)\" data-page=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var14 string
|
||||||
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.CurrentPage-1))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 267, Col: 129}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "\"><i class=\"fas fa-chevron-left\"></i></a></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "<!-- First page -->")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.CurrentPage > 3 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "<li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(1)\">1</a></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.CurrentPage > 4 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "<li class=\"page-item disabled\"><span class=\"page-link\">...</span></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 72, "<!-- Current page and neighbors -->")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.CurrentPage > 1 && data.CurrentPage-1 >= 1 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 73, "<li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(event)\" data-page=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var15 string
|
||||||
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.CurrentPage-1))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 288, Col: 129}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, "\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var16 string
|
||||||
|
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.CurrentPage-1))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 288, Col: 170}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 75, "</a></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 76, "<li class=\"page-item active\"><span class=\"page-link\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var17 string
|
||||||
|
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.CurrentPage))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 293, Col: 80}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "</span></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.CurrentPage < data.TotalPages && data.CurrentPage+1 <= data.TotalPages {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 78, "<li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(event)\" data-page=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var18 string
|
||||||
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.CurrentPage+1))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 298, Col: 129}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 79, "\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var19 string
|
||||||
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.CurrentPage+1))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 298, Col: 170}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 80, "</a></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 81, "<!-- Last page -->")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.CurrentPage < data.TotalPages-2 {
|
||||||
|
if data.CurrentPage < data.TotalPages-3 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 82, "<li class=\"page-item disabled\"><span class=\"page-link\">...</span></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 83, " <li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(event)\" data-page=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var20 string
|
||||||
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalPages))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 310, Col: 126}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 84, "\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var21 string
|
||||||
|
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalPages))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 310, Col: 164}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 85, "</a></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if data.CurrentPage < data.TotalPages {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 86, "<li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(event)\" data-page=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var22 string
|
||||||
|
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.CurrentPage+1))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 316, Col: 129}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 87, "\"><i class=\"fas fa-chevron-right\"></i></a></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 88, "</ul></nav>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 89, "<!-- JavaScript --><script>\n function sortBy(field) {\n const currentSort = \"{data.SortBy}\";\n const currentOrder = \"{data.SortOrder}\";\n let newOrder = 'asc';\n \n if (currentSort === field && currentOrder === 'asc') {\n newOrder = 'desc';\n }\n \n updateUrl({\n sortBy: field,\n sortOrder: newOrder,\n page: 1\n });\n }\n\n function goToPage(event) {\n // Get data from the link element (not any child elements)\n const link = event.target.closest('a');\n const page = link.getAttribute('data-page');\n updateUrl({ page: page });\n }\n\n function changePageSize() {\n const pageSize = document.getElementById('pageSizeSelect').value;\n updateUrl({ pageSize: pageSize, page: 1 });\n }\n\n function updateUrl(params) {\n const url = new URL(window.location);\n Object.keys(params).forEach(key => {\n if (params[key]) {\n url.searchParams.set(key, params[key]);\n } else {\n url.searchParams.delete(key);\n }\n });\n window.location.href = url.toString();\n }\n\n function exportEcShards() {\n const url = new URL('/api/cluster/ec-shards/export', window.location.origin);\n const params = new URLSearchParams(window.location.search);\n params.forEach((value, key) => {\n url.searchParams.set(key, value);\n });\n window.open(url.toString(), '_blank');\n }\n\n function showShardDetails(event) {\n // Get data from the button element (not the icon inside it)\n const button = event.target.closest('button');\n const volumeId = button.getAttribute('data-volume-id');\n \n // Navigate to the EC volume details page\n window.location.href = `/cluster/ec-volumes/${volumeId}`;\n }\n\n function repairVolume(event) {\n // Get data from the button element (not the icon inside it)\n const button = event.target.closest('button');\n const volumeId = button.getAttribute('data-volume-id');\n if (confirm(`Are you sure you want to repair missing shards for volume ${volumeId}?`)) {\n fetch(`/api/cluster/volumes/${volumeId}/repair`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n }\n })\n .then(response => response.json())\n .then(data => {\n if (data.success) {\n alert('Repair initiated successfully');\n location.reload();\n } else {\n alert('Failed to initiate repair: ' + data.error);\n }\n })\n .catch(error => {\n alert('Error: ' + error.message);\n });\n }\n }\n </script>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// displayShardDistribution shows the distribution summary for a volume's shards
|
||||||
|
func displayShardDistribution(shard dash.EcShardWithInfo, allShards []dash.EcShardWithInfo) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var23 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var23 == nil {
|
||||||
|
templ_7745c5c3_Var23 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 90, "<div class=\"small\"><i class=\"fas fa-sitemap me-1\"></i> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var24 string
|
||||||
|
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(calculateDistributionSummary(shard.VolumeID, allShards))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 418, Col: 65}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 91, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// displayVolumeStatus shows an improved status display
|
||||||
|
func displayVolumeStatus(shard dash.EcShardWithInfo) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var25 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var25 == nil {
|
||||||
|
templ_7745c5c3_Var25 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
if shard.IsComplete {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 92, "<span class=\"badge bg-success\"><i class=\"fas fa-check me-1\"></i>Complete</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if len(shard.MissingShards) > 10 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 93, "<span class=\"badge bg-danger\"><i class=\"fas fa-skull me-1\"></i>Critical (")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var26 string
|
||||||
|
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(shard.MissingShards)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 428, Col: 129}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 94, " missing)</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else if len(shard.MissingShards) > 6 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 95, "<span class=\"badge bg-warning\"><i class=\"fas fa-exclamation-triangle me-1\"></i>Degraded (")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var27 string
|
||||||
|
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(shard.MissingShards)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 430, Col: 145}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 96, " missing)</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else if len(shard.MissingShards) > 2 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 97, "<span class=\"badge bg-warning\"><i class=\"fas fa-info-circle me-1\"></i>Incomplete (")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var28 string
|
||||||
|
templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(shard.MissingShards)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 432, Col: 138}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 98, " missing)</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 99, "<span class=\"badge bg-info\"><i class=\"fas fa-info-circle me-1\"></i>Minor Issues (")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var29 string
|
||||||
|
templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(shard.MissingShards)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/cluster_ec_shards.templ`, Line: 434, Col: 137}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 100, " missing)</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculateDistributionSummary calculates and formats the distribution summary
|
||||||
|
func calculateDistributionSummary(volumeID uint32, allShards []dash.EcShardWithInfo) string {
|
||||||
|
dataCenters := make(map[string]bool)
|
||||||
|
racks := make(map[string]bool)
|
||||||
|
servers := make(map[string]bool)
|
||||||
|
|
||||||
|
for _, s := range allShards {
|
||||||
|
if s.VolumeID == volumeID {
|
||||||
|
dataCenters[s.DataCenter] = true
|
||||||
|
racks[s.Rack] = true
|
||||||
|
servers[s.Server] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%d DCs, %d racks, %d servers", len(dataCenters), len(racks), len(servers))
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = templruntime.GeneratedTemplate
|
||||||
@@ -0,0 +1,766 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||||
|
)
|
||||||
|
|
||||||
|
templ ClusterEcVolumes(data dash.ClusterEcVolumesData) {
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>EC Volumes - SeaweedFS</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h2 class="mb-4">
|
||||||
|
<i class="fas fa-database me-2"></i>EC Volumes
|
||||||
|
<small class="text-muted">({fmt.Sprintf("%d", data.TotalVolumes)} volumes)</small>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Statistics Cards -->
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-primary">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">Total Volumes</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.TotalVolumes)}</h4>
|
||||||
|
<small>EC encoded volumes</small>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-cubes fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-info">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">Total Shards</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.TotalShards)}</h4>
|
||||||
|
<small>Distributed shards</small>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-puzzle-piece fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-success">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">Complete Volumes</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.CompleteVolumes)}</h4>
|
||||||
|
<small>All shards present</small>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-check-circle fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-warning">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">Incomplete Volumes</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.IncompleteVolumes)}</h4>
|
||||||
|
<small>Missing shards</small>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-exclamation-triangle fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- EC Storage Information Note -->
|
||||||
|
<div class="alert alert-info mb-4" role="alert">
|
||||||
|
<i class="fas fa-info-circle me-2"></i>
|
||||||
|
<strong>EC Storage Note:</strong>
|
||||||
|
EC volumes use erasure coding (10+4) which stores data across 14 shards with redundancy.
|
||||||
|
Physical storage is approximately 1.4x the original logical data size due to 4 parity shards.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Volumes Table -->
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<span class="me-3">
|
||||||
|
Showing {fmt.Sprintf("%d", (data.Page-1)*data.PageSize + 1)} to {fmt.Sprintf("%d", func() int {
|
||||||
|
end := data.Page * data.PageSize
|
||||||
|
if end > data.TotalVolumes {
|
||||||
|
return data.TotalVolumes
|
||||||
|
}
|
||||||
|
return end
|
||||||
|
}())} of {fmt.Sprintf("%d", data.TotalVolumes)} volumes
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<label for="pageSize" class="form-label me-2 mb-0">Show:</label>
|
||||||
|
<select id="pageSize" class="form-select form-select-sm" style="width: auto;" onchange="changePageSize(this.value)">
|
||||||
|
<option value="5" if data.PageSize == 5 { selected }>5</option>
|
||||||
|
<option value="10" if data.PageSize == 10 { selected }>10</option>
|
||||||
|
<option value="25" if data.PageSize == 25 { selected }>25</option>
|
||||||
|
<option value="50" if data.PageSize == 50 { selected }>50</option>
|
||||||
|
<option value="100" if data.PageSize == 100 { selected }>100</option>
|
||||||
|
</select>
|
||||||
|
<span class="ms-2">per page</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
if data.Collection != "" {
|
||||||
|
<div>
|
||||||
|
if data.Collection == "default" {
|
||||||
|
<span class="badge bg-secondary text-white">Collection: default</span>
|
||||||
|
} else {
|
||||||
|
<span class="badge bg-info text-white">Collection: {data.Collection}</span>
|
||||||
|
}
|
||||||
|
<a href="/cluster/ec-shards" class="btn btn-sm btn-outline-secondary ms-2">Clear Filter</a>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover" id="ecVolumesTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('volume_id')" class="text-dark text-decoration-none">
|
||||||
|
Volume ID
|
||||||
|
if data.SortBy == "volume_id" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
if data.ShowCollectionColumn {
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('collection')" class="text-dark text-decoration-none">
|
||||||
|
Collection
|
||||||
|
if data.SortBy == "collection" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
}
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('total_shards')" class="text-dark text-decoration-none">
|
||||||
|
Shard Count
|
||||||
|
if data.SortBy == "total_shards" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
<th class="text-dark">Shard Size</th>
|
||||||
|
<th class="text-dark">Shard Locations</th>
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('completeness')" class="text-dark text-decoration-none">
|
||||||
|
Status
|
||||||
|
if data.SortBy == "completeness" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
if data.ShowDataCenterColumn {
|
||||||
|
<th class="text-dark">Data Centers</th>
|
||||||
|
}
|
||||||
|
<th class="text-dark">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
for _, volume := range data.EcVolumes {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<strong>{fmt.Sprintf("%d", volume.VolumeID)}</strong>
|
||||||
|
</td>
|
||||||
|
if data.ShowCollectionColumn {
|
||||||
|
<td>
|
||||||
|
if volume.Collection != "" {
|
||||||
|
<a href="/cluster/ec-shards?collection={volume.Collection}" class="text-decoration-none">
|
||||||
|
<span class="badge bg-info text-white">{volume.Collection}</span>
|
||||||
|
</a>
|
||||||
|
} else {
|
||||||
|
<a href="/cluster/ec-shards?collection=default" class="text-decoration-none">
|
||||||
|
<span class="badge bg-secondary text-white">default</span>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
}
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-primary">{fmt.Sprintf("%d/14", volume.TotalShards)}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@displayShardSizes(volume.ShardSizes)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@displayVolumeDistribution(volume)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@displayEcVolumeStatus(volume)
|
||||||
|
</td>
|
||||||
|
if data.ShowDataCenterColumn {
|
||||||
|
<td>
|
||||||
|
for i, dc := range volume.DataCenters {
|
||||||
|
if i > 0 {
|
||||||
|
<span>, </span>
|
||||||
|
}
|
||||||
|
<span class="badge bg-primary text-white">{dc}</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
}
|
||||||
|
<td>
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-primary"
|
||||||
|
onclick="showVolumeDetails(event)"
|
||||||
|
data-volume-id={ fmt.Sprintf("%d", volume.VolumeID) }
|
||||||
|
title="View EC volume details">
|
||||||
|
<i class="fas fa-info-circle"></i>
|
||||||
|
</button>
|
||||||
|
if !volume.IsComplete {
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-warning"
|
||||||
|
onclick="repairVolume(event)"
|
||||||
|
data-volume-id={ fmt.Sprintf("%d", volume.VolumeID) }
|
||||||
|
title="Repair missing shards">
|
||||||
|
<i class="fas fa-wrench"></i>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pagination -->
|
||||||
|
if data.TotalPages > 1 {
|
||||||
|
<nav aria-label="EC Volumes pagination">
|
||||||
|
<ul class="pagination justify-content-center">
|
||||||
|
if data.Page > 1 {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page="1">First</a>
|
||||||
|
</li>
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.Page-1) }>Previous</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 1; i <= data.TotalPages; i++ {
|
||||||
|
if i == data.Page {
|
||||||
|
<li class="page-item active">
|
||||||
|
<span class="page-link">{fmt.Sprintf("%d", i)}</span>
|
||||||
|
</li>
|
||||||
|
} else if i <= 3 || i > data.TotalPages-3 || (i >= data.Page-2 && i <= data.Page+2) {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", i) }>{fmt.Sprintf("%d", i)}</a>
|
||||||
|
</li>
|
||||||
|
} else if i == 4 && data.Page > 6 {
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">...</span>
|
||||||
|
</li>
|
||||||
|
} else if i == data.TotalPages-3 && data.Page < data.TotalPages-5 {
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">...</span>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Page < data.TotalPages {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.Page+1) }>Next</a>
|
||||||
|
</li>
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.TotalPages) }>Last</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script>
|
||||||
|
// Sorting functionality
|
||||||
|
function sortBy(field) {
|
||||||
|
const currentSort = new URLSearchParams(window.location.search).get('sort_by');
|
||||||
|
const currentOrder = new URLSearchParams(window.location.search).get('sort_order') || 'asc';
|
||||||
|
|
||||||
|
let newOrder = 'asc';
|
||||||
|
if (currentSort === field && currentOrder === 'asc') {
|
||||||
|
newOrder = 'desc';
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.set('sort_by', field);
|
||||||
|
url.searchParams.set('sort_order', newOrder);
|
||||||
|
url.searchParams.set('page', '1'); // Reset to first page
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pagination functionality
|
||||||
|
function goToPage(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const page = event.target.closest('a').getAttribute('data-page');
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.set('page', page);
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Page size functionality
|
||||||
|
function changePageSize(newPageSize) {
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.set('page_size', newPageSize);
|
||||||
|
url.searchParams.set('page', '1'); // Reset to first page when changing page size
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Volume details
|
||||||
|
function showVolumeDetails(event) {
|
||||||
|
const volumeId = event.target.closest('button').getAttribute('data-volume-id');
|
||||||
|
window.location.href = `/cluster/ec-volumes/${volumeId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Repair volume
|
||||||
|
function repairVolume(event) {
|
||||||
|
const volumeId = event.target.closest('button').getAttribute('data-volume-id');
|
||||||
|
if (confirm(`Are you sure you want to repair missing shards for volume ${volumeId}?`)) {
|
||||||
|
// TODO: Implement repair functionality
|
||||||
|
alert('Repair functionality will be implemented soon.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
}
|
||||||
|
|
||||||
|
// displayShardLocationsHTML renders shard locations as proper HTML
|
||||||
|
templ displayShardLocationsHTML(shardLocations map[int]string) {
|
||||||
|
if len(shardLocations) == 0 {
|
||||||
|
<span class="text-muted">No shards</span>
|
||||||
|
} else {
|
||||||
|
for i, serverInfo := range groupShardsByServer(shardLocations) {
|
||||||
|
if i > 0 {
|
||||||
|
<br/>
|
||||||
|
}
|
||||||
|
<strong>
|
||||||
|
<a href={ templ.URL("/cluster/volume-servers/" + serverInfo.Server) } class="text-primary text-decoration-none">
|
||||||
|
{ serverInfo.Server }
|
||||||
|
</a>:
|
||||||
|
</strong> { serverInfo.ShardRanges }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// displayShardSizes renders shard sizes in a compact format
|
||||||
|
templ displayShardSizes(shardSizes map[int]int64) {
|
||||||
|
if len(shardSizes) == 0 {
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
} else {
|
||||||
|
@renderShardSizesContent(shardSizes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// renderShardSizesContent renders the content of shard sizes
|
||||||
|
templ renderShardSizesContent(shardSizes map[int]int64) {
|
||||||
|
if areAllShardSizesSame(shardSizes) {
|
||||||
|
// All shards have the same size, show just the common size
|
||||||
|
<span class="text-success">{getCommonShardSize(shardSizes)}</span>
|
||||||
|
} else {
|
||||||
|
// Shards have different sizes, show individual sizes
|
||||||
|
<div class="shard-sizes" style="max-width: 300px;">
|
||||||
|
{ formatIndividualShardSizes(shardSizes) }
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServerShardInfo represents server and its shard ranges with sizes
|
||||||
|
type ServerShardInfo struct {
|
||||||
|
Server string
|
||||||
|
ShardRanges string
|
||||||
|
}
|
||||||
|
|
||||||
|
// groupShardsByServer groups shards by server and formats ranges
|
||||||
|
func groupShardsByServer(shardLocations map[int]string) []ServerShardInfo {
|
||||||
|
if len(shardLocations) == 0 {
|
||||||
|
return []ServerShardInfo{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group shards by server
|
||||||
|
serverShards := make(map[string][]int)
|
||||||
|
for shardId, server := range shardLocations {
|
||||||
|
serverShards[server] = append(serverShards[server], shardId)
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverInfos []ServerShardInfo
|
||||||
|
for server, shards := range serverShards {
|
||||||
|
// Sort shards for each server
|
||||||
|
for i := 0; i < len(shards); i++ {
|
||||||
|
for j := i + 1; j < len(shards); j++ {
|
||||||
|
if shards[i] > shards[j] {
|
||||||
|
shards[i], shards[j] = shards[j], shards[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format shard ranges compactly
|
||||||
|
shardRanges := formatShardRanges(shards)
|
||||||
|
serverInfos = append(serverInfos, ServerShardInfo{
|
||||||
|
Server: server,
|
||||||
|
ShardRanges: shardRanges,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by server name
|
||||||
|
for i := 0; i < len(serverInfos); i++ {
|
||||||
|
for j := i + 1; j < len(serverInfos); j++ {
|
||||||
|
if serverInfos[i].Server > serverInfos[j].Server {
|
||||||
|
serverInfos[i], serverInfos[j] = serverInfos[j], serverInfos[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverInfos
|
||||||
|
}
|
||||||
|
|
||||||
|
// groupShardsByServerWithSizes groups shards by server and formats ranges with sizes
|
||||||
|
func groupShardsByServerWithSizes(shardLocations map[int]string, shardSizes map[int]int64) []ServerShardInfo {
|
||||||
|
if len(shardLocations) == 0 {
|
||||||
|
return []ServerShardInfo{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group shards by server
|
||||||
|
serverShards := make(map[string][]int)
|
||||||
|
for shardId, server := range shardLocations {
|
||||||
|
serverShards[server] = append(serverShards[server], shardId)
|
||||||
|
}
|
||||||
|
|
||||||
|
var serverInfos []ServerShardInfo
|
||||||
|
for server, shards := range serverShards {
|
||||||
|
// Sort shards for each server
|
||||||
|
for i := 0; i < len(shards); i++ {
|
||||||
|
for j := i + 1; j < len(shards); j++ {
|
||||||
|
if shards[i] > shards[j] {
|
||||||
|
shards[i], shards[j] = shards[j], shards[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format shard ranges compactly with sizes
|
||||||
|
shardRanges := formatShardRangesWithSizes(shards, shardSizes)
|
||||||
|
serverInfos = append(serverInfos, ServerShardInfo{
|
||||||
|
Server: server,
|
||||||
|
ShardRanges: shardRanges,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by server name
|
||||||
|
for i := 0; i < len(serverInfos); i++ {
|
||||||
|
for j := i + 1; j < len(serverInfos); j++ {
|
||||||
|
if serverInfos[i].Server > serverInfos[j].Server {
|
||||||
|
serverInfos[i], serverInfos[j] = serverInfos[j], serverInfos[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverInfos
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to format shard ranges compactly (e.g., "0-3,7,9-11")
|
||||||
|
func formatShardRanges(shards []int) string {
|
||||||
|
if len(shards) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var ranges []string
|
||||||
|
start := shards[0]
|
||||||
|
end := shards[0]
|
||||||
|
|
||||||
|
for i := 1; i < len(shards); i++ {
|
||||||
|
if shards[i] == end+1 {
|
||||||
|
end = shards[i]
|
||||||
|
} else {
|
||||||
|
if start == end {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d", start))
|
||||||
|
} else {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d-%d", start, end))
|
||||||
|
}
|
||||||
|
start = shards[i]
|
||||||
|
end = shards[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the last range
|
||||||
|
if start == end {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d", start))
|
||||||
|
} else {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d-%d", start, end))
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(ranges, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to format shard ranges with sizes (e.g., "0(1.2MB),1-3(2.5MB),7(800KB)")
|
||||||
|
func formatShardRangesWithSizes(shards []int, shardSizes map[int]int64) string {
|
||||||
|
if len(shards) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var ranges []string
|
||||||
|
start := shards[0]
|
||||||
|
end := shards[0]
|
||||||
|
var totalSize int64
|
||||||
|
|
||||||
|
for i := 1; i < len(shards); i++ {
|
||||||
|
if shards[i] == end+1 {
|
||||||
|
end = shards[i]
|
||||||
|
totalSize += shardSizes[shards[i]]
|
||||||
|
} else {
|
||||||
|
// Add current range with size
|
||||||
|
if start == end {
|
||||||
|
size := shardSizes[start]
|
||||||
|
if size > 0 {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d(%s)", start, bytesToHumanReadable(size)))
|
||||||
|
} else {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d", start))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Calculate total size for the range
|
||||||
|
rangeSize := shardSizes[start]
|
||||||
|
for j := start + 1; j <= end; j++ {
|
||||||
|
rangeSize += shardSizes[j]
|
||||||
|
}
|
||||||
|
if rangeSize > 0 {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d-%d(%s)", start, end, bytesToHumanReadable(rangeSize)))
|
||||||
|
} else {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d-%d", start, end))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
start = shards[i]
|
||||||
|
end = shards[i]
|
||||||
|
totalSize = shardSizes[shards[i]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the last range
|
||||||
|
if start == end {
|
||||||
|
size := shardSizes[start]
|
||||||
|
if size > 0 {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d(%s)", start, bytesToHumanReadable(size)))
|
||||||
|
} else {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d", start))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Calculate total size for the range
|
||||||
|
rangeSize := shardSizes[start]
|
||||||
|
for j := start + 1; j <= end; j++ {
|
||||||
|
rangeSize += shardSizes[j]
|
||||||
|
}
|
||||||
|
if rangeSize > 0 {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d-%d(%s)", start, end, bytesToHumanReadable(rangeSize)))
|
||||||
|
} else {
|
||||||
|
ranges = append(ranges, fmt.Sprintf("%d-%d", start, end))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(ranges, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to convert bytes to human readable format
|
||||||
|
func bytesToHumanReadable(bytes int64) string {
|
||||||
|
const unit = 1024
|
||||||
|
if bytes < unit {
|
||||||
|
return fmt.Sprintf("%dB", bytes)
|
||||||
|
}
|
||||||
|
div, exp := int64(unit), 0
|
||||||
|
for n := bytes / unit; n >= unit; n /= unit {
|
||||||
|
div *= unit
|
||||||
|
exp++
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%.1f%cB", float64(bytes)/float64(div), "KMGTPE"[exp])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to format missing shards
|
||||||
|
func formatMissingShards(missingShards []int) string {
|
||||||
|
if len(missingShards) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
var shardStrs []string
|
||||||
|
for _, shard := range missingShards {
|
||||||
|
shardStrs = append(shardStrs, fmt.Sprintf("%d", shard))
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(shardStrs, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to check if all shard sizes are the same
|
||||||
|
func areAllShardSizesSame(shardSizes map[int]int64) bool {
|
||||||
|
if len(shardSizes) <= 1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
var firstSize int64 = -1
|
||||||
|
for _, size := range shardSizes {
|
||||||
|
if firstSize == -1 {
|
||||||
|
firstSize = size
|
||||||
|
} else if size != firstSize {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to get the common shard size (when all shards are the same size)
|
||||||
|
func getCommonShardSize(shardSizes map[int]int64) string {
|
||||||
|
for _, size := range shardSizes {
|
||||||
|
return bytesToHumanReadable(size)
|
||||||
|
}
|
||||||
|
return "-"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to format individual shard sizes
|
||||||
|
func formatIndividualShardSizes(shardSizes map[int]int64) string {
|
||||||
|
if len(shardSizes) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group shards by size for more compact display
|
||||||
|
sizeGroups := make(map[int64][]int)
|
||||||
|
for shardId, size := range shardSizes {
|
||||||
|
sizeGroups[size] = append(sizeGroups[size], shardId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are only 1-2 different sizes, show them grouped
|
||||||
|
if len(sizeGroups) <= 3 {
|
||||||
|
var groupStrs []string
|
||||||
|
for size, shardIds := range sizeGroups {
|
||||||
|
// Sort shard IDs
|
||||||
|
for i := 0; i < len(shardIds); i++ {
|
||||||
|
for j := i + 1; j < len(shardIds); j++ {
|
||||||
|
if shardIds[i] > shardIds[j] {
|
||||||
|
shardIds[i], shardIds[j] = shardIds[j], shardIds[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var idRanges []string
|
||||||
|
if len(shardIds) <= 4 {
|
||||||
|
// Show individual IDs if few shards
|
||||||
|
for _, id := range shardIds {
|
||||||
|
idRanges = append(idRanges, fmt.Sprintf("%d", id))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Show count if many shards
|
||||||
|
idRanges = append(idRanges, fmt.Sprintf("%d shards", len(shardIds)))
|
||||||
|
}
|
||||||
|
groupStrs = append(groupStrs, fmt.Sprintf("%s: %s", strings.Join(idRanges, ","), bytesToHumanReadable(size)))
|
||||||
|
}
|
||||||
|
return strings.Join(groupStrs, " | ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// If too many different sizes, show summary
|
||||||
|
return fmt.Sprintf("%d different sizes", len(sizeGroups))
|
||||||
|
}
|
||||||
|
|
||||||
|
// displayVolumeDistribution shows the distribution summary for a volume
|
||||||
|
templ displayVolumeDistribution(volume dash.EcVolumeWithShards) {
|
||||||
|
<div class="small">
|
||||||
|
<i class="fas fa-sitemap me-1"></i>
|
||||||
|
{ calculateVolumeDistributionSummary(volume) }
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
// displayEcVolumeStatus shows an improved status display for EC volumes
|
||||||
|
templ displayEcVolumeStatus(volume dash.EcVolumeWithShards) {
|
||||||
|
if volume.IsComplete {
|
||||||
|
<span class="badge bg-success"><i class="fas fa-check me-1"></i>Complete</span>
|
||||||
|
} else {
|
||||||
|
if len(volume.MissingShards) > 10 {
|
||||||
|
<span class="badge bg-danger"><i class="fas fa-skull me-1"></i>Critical ({fmt.Sprintf("%d", len(volume.MissingShards))} missing)</span>
|
||||||
|
} else if len(volume.MissingShards) > 6 {
|
||||||
|
<span class="badge bg-warning"><i class="fas fa-exclamation-triangle me-1"></i>Degraded ({fmt.Sprintf("%d", len(volume.MissingShards))} missing)</span>
|
||||||
|
} else if len(volume.MissingShards) > 2 {
|
||||||
|
<span class="badge bg-warning"><i class="fas fa-info-circle me-1"></i>Incomplete ({fmt.Sprintf("%d", len(volume.MissingShards))} missing)</span>
|
||||||
|
} else {
|
||||||
|
<span class="badge bg-info"><i class="fas fa-info-circle me-1"></i>Minor Issues ({fmt.Sprintf("%d", len(volume.MissingShards))} missing)</span>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculateVolumeDistributionSummary calculates and formats the distribution summary for a volume
|
||||||
|
func calculateVolumeDistributionSummary(volume dash.EcVolumeWithShards) string {
|
||||||
|
dataCenters := make(map[string]bool)
|
||||||
|
servers := make(map[string]bool)
|
||||||
|
|
||||||
|
// Count unique servers from shard locations
|
||||||
|
for _, server := range volume.ShardLocations {
|
||||||
|
servers[server] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the DataCenters field if available
|
||||||
|
for _, dc := range volume.DataCenters {
|
||||||
|
dataCenters[dc] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the Servers field if available
|
||||||
|
for _, server := range volume.Servers {
|
||||||
|
servers[server] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we don't have rack information, estimate it from servers
|
||||||
|
// This is a simple approximation - in practice you'd want better rack detection
|
||||||
|
rackCount := len(servers) // Assuming each server might be in a different rack
|
||||||
|
if len(dataCenters) > 0 {
|
||||||
|
// More conservative estimate if we have DC info
|
||||||
|
rackCount = (len(servers) + len(dataCenters) - 1) / len(dataCenters)
|
||||||
|
if rackCount == 0 {
|
||||||
|
rackCount = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%d DCs, %d racks, %d servers", len(dataCenters), rackCount, len(servers))
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -277,7 +277,7 @@ templ ClusterVolumes(data dash.ClusterVolumesData) {
|
|||||||
@getSortIcon("size", data.SortBy, data.SortOrder)
|
@getSortIcon("size", data.SortBy, data.SortOrder)
|
||||||
</a>
|
</a>
|
||||||
</th>
|
</th>
|
||||||
<th>Storage Usage</th>
|
<th>Volume Utilization</th>
|
||||||
<th>
|
<th>
|
||||||
<a href="#" onclick="sortTable('filecount')" class="text-decoration-none text-dark">
|
<a href="#" onclick="sortTable('filecount')" class="text-decoration-none text-dark">
|
||||||
File Count
|
File Count
|
||||||
|
|||||||
@@ -399,7 +399,7 @@ func ClusterVolumes(data dash.ClusterVolumesData) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "</a></th><th>Storage Usage</th><th><a href=\"#\" onclick=\"sortTable('filecount')\" class=\"text-decoration-none text-dark\">File Count")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "</a></th><th>Volume Utilization</th><th><a href=\"#\" onclick=\"sortTable('filecount')\" class=\"text-decoration-none text-dark\">File Count")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,371 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
templ CollectionDetails(data dash.CollectionDetailsData) {
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<div>
|
||||||
|
<h1 class="h2">
|
||||||
|
<i class="fas fa-layer-group me-2"></i>Collection Details: {data.CollectionName}
|
||||||
|
</h1>
|
||||||
|
<nav aria-label="breadcrumb">
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
<li class="breadcrumb-item"><a href="/admin" class="text-decoration-none">Dashboard</a></li>
|
||||||
|
<li class="breadcrumb-item"><a href="/cluster/collections" class="text-decoration-none">Collections</a></li>
|
||||||
|
<li class="breadcrumb-item active" aria-current="page">{data.CollectionName}</li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
<div class="btn-group me-2">
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="history.back()">
|
||||||
|
<i class="fas fa-arrow-left me-1"></i>Back
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-primary" onclick="window.location.reload()">
|
||||||
|
<i class="fas fa-refresh me-1"></i>Refresh
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Collection Summary -->
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-primary">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">Regular Volumes</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.TotalVolumes)}</h4>
|
||||||
|
<small>Traditional volumes</small>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-database fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-info">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">EC Volumes</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.TotalEcVolumes)}</h4>
|
||||||
|
<small>Erasure coded volumes</small>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-th-large fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-success">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">Total Files</h6>
|
||||||
|
<h4 class="mb-0">{fmt.Sprintf("%d", data.TotalFiles)}</h4>
|
||||||
|
<small>Files stored</small>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-file fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card text-bg-warning">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<div>
|
||||||
|
<h6 class="card-title">Total Size (Logical)</h6>
|
||||||
|
<h4 class="mb-0">{util.BytesToHumanReadable(uint64(data.TotalSize))}</h4>
|
||||||
|
<small>Data stored (regular volumes only)</small>
|
||||||
|
</div>
|
||||||
|
<div class="align-self-center">
|
||||||
|
<i class="fas fa-hdd fa-2x"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Size Information Note -->
|
||||||
|
<div class="alert alert-info" role="alert">
|
||||||
|
<i class="fas fa-info-circle me-2"></i>
|
||||||
|
<strong>Size Information:</strong>
|
||||||
|
Logical size represents the actual data stored (regular volumes only).
|
||||||
|
EC volumes show shard counts instead of size - physical storage for EC volumes is approximately 1.4x the original data due to erasure coding redundancy.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pagination Info -->
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<span class="me-3">
|
||||||
|
Showing {fmt.Sprintf("%d", (data.Page-1)*data.PageSize + 1)} to {fmt.Sprintf("%d", func() int {
|
||||||
|
end := data.Page * data.PageSize
|
||||||
|
totalItems := data.TotalVolumes + data.TotalEcVolumes
|
||||||
|
if end > totalItems {
|
||||||
|
return totalItems
|
||||||
|
}
|
||||||
|
return end
|
||||||
|
}())} of {fmt.Sprintf("%d", data.TotalVolumes + data.TotalEcVolumes)} items
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<label for="pageSize" class="form-label me-2 mb-0">Show:</label>
|
||||||
|
<select id="pageSize" class="form-select form-select-sm" style="width: auto;" onchange="changePageSize(this.value)">
|
||||||
|
<option value="10" if data.PageSize == 10 { selected }>10</option>
|
||||||
|
<option value="25" if data.PageSize == 25 { selected }>25</option>
|
||||||
|
<option value="50" if data.PageSize == 50 { selected }>50</option>
|
||||||
|
<option value="100" if data.PageSize == 100 { selected }>100</option>
|
||||||
|
</select>
|
||||||
|
<span class="ms-2">per page</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Volumes Table -->
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover" id="volumesTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('volume_id')" class="text-dark text-decoration-none">
|
||||||
|
Volume ID
|
||||||
|
if data.SortBy == "volume_id" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('type')" class="text-dark text-decoration-none">
|
||||||
|
Type
|
||||||
|
if data.SortBy == "type" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
<th class="text-dark">Logical Size / Shard Count</th>
|
||||||
|
<th class="text-dark">Files</th>
|
||||||
|
<th class="text-dark">Status</th>
|
||||||
|
<th class="text-dark">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
// Display regular volumes
|
||||||
|
for _, volume := range data.RegularVolumes {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<strong>{fmt.Sprintf("%d", volume.Id)}</strong>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-primary">
|
||||||
|
<i class="fas fa-database me-1"></i>Regular
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{util.BytesToHumanReadable(volume.Size)}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{fmt.Sprintf("%d", volume.FileCount)}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
if volume.ReadOnly {
|
||||||
|
<span class="badge bg-warning">Read Only</span>
|
||||||
|
} else {
|
||||||
|
<span class="badge bg-success">Read/Write</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-primary"
|
||||||
|
onclick="showVolumeDetails(event)"
|
||||||
|
data-volume-id={ fmt.Sprintf("%d", volume.Id) }
|
||||||
|
data-server={ volume.Server }
|
||||||
|
title="View volume details">
|
||||||
|
<i class="fas fa-info-circle"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display EC volumes
|
||||||
|
for _, ecVolume := range data.EcVolumes {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<strong>{fmt.Sprintf("%d", ecVolume.VolumeID)}</strong>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-info">
|
||||||
|
<i class="fas fa-th-large me-1"></i>EC
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-primary">{fmt.Sprintf("%d/14", ecVolume.TotalShards)}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
if ecVolume.IsComplete {
|
||||||
|
<span class="badge bg-success">
|
||||||
|
<i class="fas fa-check me-1"></i>Complete
|
||||||
|
</span>
|
||||||
|
} else {
|
||||||
|
<span class="badge bg-warning">
|
||||||
|
<i class="fas fa-exclamation-triangle me-1"></i>
|
||||||
|
Missing {fmt.Sprintf("%d", len(ecVolume.MissingShards))} shards
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-info"
|
||||||
|
onclick="showEcVolumeDetails(event)"
|
||||||
|
data-volume-id={ fmt.Sprintf("%d", ecVolume.VolumeID) }
|
||||||
|
title="View EC volume details">
|
||||||
|
<i class="fas fa-info-circle"></i>
|
||||||
|
</button>
|
||||||
|
if !ecVolume.IsComplete {
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-warning"
|
||||||
|
onclick="repairEcVolume(event)"
|
||||||
|
data-volume-id={ fmt.Sprintf("%d", ecVolume.VolumeID) }
|
||||||
|
title="Repair missing shards">
|
||||||
|
<i class="fas fa-wrench"></i>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pagination -->
|
||||||
|
if data.TotalPages > 1 {
|
||||||
|
<nav aria-label="Collection volumes pagination">
|
||||||
|
<ul class="pagination justify-content-center">
|
||||||
|
if data.Page > 1 {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page="1">First</a>
|
||||||
|
</li>
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.Page-1) }>Previous</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 1; i <= data.TotalPages; i++ {
|
||||||
|
if i == data.Page {
|
||||||
|
<li class="page-item active">
|
||||||
|
<span class="page-link">{fmt.Sprintf("%d", i)}</span>
|
||||||
|
</li>
|
||||||
|
} else if i <= 3 || i > data.TotalPages-3 || (i >= data.Page-2 && i <= data.Page+2) {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", i) }>{fmt.Sprintf("%d", i)}</a>
|
||||||
|
</li>
|
||||||
|
} else if i == 4 && data.Page > 6 {
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">...</span>
|
||||||
|
</li>
|
||||||
|
} else if i == data.TotalPages-3 && data.Page < data.TotalPages-5 {
|
||||||
|
<li class="page-item disabled">
|
||||||
|
<span class="page-link">...</span>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Page < data.TotalPages {
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.Page+1) }>Next</a>
|
||||||
|
</li>
|
||||||
|
<li class="page-item">
|
||||||
|
<a class="page-link" href="#" onclick="goToPage(event)" data-page={ fmt.Sprintf("%d", data.TotalPages) }>Last</a>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Sorting functionality
|
||||||
|
function sortBy(field) {
|
||||||
|
const currentSort = new URLSearchParams(window.location.search).get('sort_by');
|
||||||
|
const currentOrder = new URLSearchParams(window.location.search).get('sort_order') || 'asc';
|
||||||
|
|
||||||
|
let newOrder = 'asc';
|
||||||
|
if (currentSort === field && currentOrder === 'asc') {
|
||||||
|
newOrder = 'desc';
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.set('sort_by', field);
|
||||||
|
url.searchParams.set('sort_order', newOrder);
|
||||||
|
url.searchParams.set('page', '1'); // Reset to first page
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pagination functionality
|
||||||
|
function goToPage(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const page = event.target.closest('a').getAttribute('data-page');
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.set('page', page);
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Page size functionality
|
||||||
|
function changePageSize(newPageSize) {
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.set('page_size', newPageSize);
|
||||||
|
url.searchParams.set('page', '1'); // Reset to first page when changing page size
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Volume details
|
||||||
|
function showVolumeDetails(event) {
|
||||||
|
const volumeId = event.target.closest('button').getAttribute('data-volume-id');
|
||||||
|
const server = event.target.closest('button').getAttribute('data-server');
|
||||||
|
window.location.href = `/cluster/volumes/${volumeId}/${server}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// EC Volume details
|
||||||
|
function showEcVolumeDetails(event) {
|
||||||
|
const volumeId = event.target.closest('button').getAttribute('data-volume-id');
|
||||||
|
window.location.href = `/cluster/ec-volumes/${volumeId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Repair EC Volume
|
||||||
|
function repairEcVolume(event) {
|
||||||
|
const volumeId = event.target.closest('button').getAttribute('data-volume-id');
|
||||||
|
if (confirm(`Are you sure you want to repair missing shards for EC volume ${volumeId}?`)) {
|
||||||
|
// TODO: Implement repair functionality
|
||||||
|
alert('Repair functionality will be implemented soon.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
}
|
||||||
@@ -0,0 +1,567 @@
|
|||||||
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
|
// templ: version: v0.3.906
|
||||||
|
package app
|
||||||
|
|
||||||
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
|
|
||||||
|
import "github.com/a-h/templ"
|
||||||
|
import templruntime "github.com/a-h/templ/runtime"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CollectionDetails(data dash.CollectionDetailsData) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var1 == nil {
|
||||||
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom\"><div><h1 class=\"h2\"><i class=\"fas fa-layer-group me-2\"></i>Collection Details: ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var2 string
|
||||||
|
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(data.CollectionName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 13, Col: 83}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</h1><nav aria-label=\"breadcrumb\"><ol class=\"breadcrumb\"><li class=\"breadcrumb-item\"><a href=\"/admin\" class=\"text-decoration-none\">Dashboard</a></li><li class=\"breadcrumb-item\"><a href=\"/cluster/collections\" class=\"text-decoration-none\">Collections</a></li><li class=\"breadcrumb-item active\" aria-current=\"page\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var3 string
|
||||||
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(data.CollectionName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 19, Col: 80}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</li></ol></nav></div><div class=\"btn-toolbar mb-2 mb-md-0\"><div class=\"btn-group me-2\"><button type=\"button\" class=\"btn btn-sm btn-outline-secondary\" onclick=\"history.back()\"><i class=\"fas fa-arrow-left me-1\"></i>Back</button> <button type=\"button\" class=\"btn btn-sm btn-outline-primary\" onclick=\"window.location.reload()\"><i class=\"fas fa-refresh me-1\"></i>Refresh</button></div></div></div><!-- Collection Summary --><div class=\"row mb-4\"><div class=\"col-md-3\"><div class=\"card text-bg-primary\"><div class=\"card-body\"><div class=\"d-flex justify-content-between\"><div><h6 class=\"card-title\">Regular Volumes</h6><h4 class=\"mb-0\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var4 string
|
||||||
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalVolumes))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 43, Col: 61}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</h4><small>Traditional volumes</small></div><div class=\"align-self-center\"><i class=\"fas fa-database fa-2x\"></i></div></div></div></div></div><div class=\"col-md-3\"><div class=\"card text-bg-info\"><div class=\"card-body\"><div class=\"d-flex justify-content-between\"><div><h6 class=\"card-title\">EC Volumes</h6><h4 class=\"mb-0\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var5 string
|
||||||
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalEcVolumes))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 59, Col: 63}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</h4><small>Erasure coded volumes</small></div><div class=\"align-self-center\"><i class=\"fas fa-th-large fa-2x\"></i></div></div></div></div></div><div class=\"col-md-3\"><div class=\"card text-bg-success\"><div class=\"card-body\"><div class=\"d-flex justify-content-between\"><div><h6 class=\"card-title\">Total Files</h6><h4 class=\"mb-0\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var6 string
|
||||||
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalFiles))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 75, Col: 59}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</h4><small>Files stored</small></div><div class=\"align-self-center\"><i class=\"fas fa-file fa-2x\"></i></div></div></div></div></div><div class=\"col-md-3\"><div class=\"card text-bg-warning\"><div class=\"card-body\"><div class=\"d-flex justify-content-between\"><div><h6 class=\"card-title\">Total Size (Logical)</h6><h4 class=\"mb-0\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var7 string
|
||||||
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(util.BytesToHumanReadable(uint64(data.TotalSize)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 91, Col: 74}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "</h4><small>Data stored (regular volumes only)</small></div><div class=\"align-self-center\"><i class=\"fas fa-hdd fa-2x\"></i></div></div></div></div></div></div><!-- Size Information Note --><div class=\"alert alert-info\" role=\"alert\"><i class=\"fas fa-info-circle me-2\"></i> <strong>Size Information:</strong> Logical size represents the actual data stored (regular volumes only). EC volumes show shard counts instead of size - physical storage for EC volumes is approximately 1.4x the original data due to erasure coding redundancy.</div><!-- Pagination Info --><div class=\"d-flex justify-content-between align-items-center mb-3\"><div class=\"d-flex align-items-center\"><span class=\"me-3\">Showing ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var8 string
|
||||||
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", (data.Page-1)*data.PageSize+1))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 115, Col: 63}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " to ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var9 string
|
||||||
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", func() int {
|
||||||
|
end := data.Page * data.PageSize
|
||||||
|
totalItems := data.TotalVolumes + data.TotalEcVolumes
|
||||||
|
if end > totalItems {
|
||||||
|
return totalItems
|
||||||
|
}
|
||||||
|
return end
|
||||||
|
}()))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 122, Col: 8}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, " of ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var10 string
|
||||||
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalVolumes+data.TotalEcVolumes))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 122, Col: 72}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, " items</span><div class=\"d-flex align-items-center\"><label for=\"pageSize\" class=\"form-label me-2 mb-0\">Show:</label> <select id=\"pageSize\" class=\"form-select form-select-sm\" style=\"width: auto;\" onchange=\"changePageSize(this.value)\"><option value=\"10\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.PageSize == 10 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, ">10</option> <option value=\"25\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.PageSize == 25 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, ">25</option> <option value=\"50\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.PageSize == 50 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, ">50</option> <option value=\"100\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.PageSize == 100 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, ">100</option></select> <span class=\"ms-2\">per page</span></div></div></div><!-- Volumes Table --><div class=\"table-responsive\"><table class=\"table table-striped table-hover\" id=\"volumesTable\"><thead><tr><th><a href=\"#\" onclick=\"sortBy('volume_id')\" class=\"text-dark text-decoration-none\">Volume ID ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "volume_id" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "</a></th><th><a href=\"#\" onclick=\"sortBy('type')\" class=\"text-dark text-decoration-none\">Type ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "type" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "</a></th><th class=\"text-dark\">Logical Size / Shard Count</th><th class=\"text-dark\">Files</th><th class=\"text-dark\">Status</th><th class=\"text-dark\">Actions</th></tr></thead> <tbody>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, volume := range data.RegularVolumes {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "<tr><td><strong>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var11 string
|
||||||
|
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", volume.Id))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 182, Col: 44}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "</strong></td><td><span class=\"badge bg-primary\"><i class=\"fas fa-database me-1\"></i>Regular</span></td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var12 string
|
||||||
|
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(util.BytesToHumanReadable(volume.Size))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 190, Col: 46}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var13 string
|
||||||
|
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", volume.FileCount))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 193, Col: 43}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if volume.ReadOnly {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "<span class=\"badge bg-warning\">Read Only</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<span class=\"badge bg-success\">Read/Write</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "</td><td><div class=\"btn-group\" role=\"group\"><button type=\"button\" class=\"btn btn-sm btn-outline-primary\" onclick=\"showVolumeDetails(event)\" data-volume-id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var14 string
|
||||||
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", volume.Id))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 206, Col: 55}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "\" data-server=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var15 string
|
||||||
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(volume.Server)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 207, Col: 37}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "\" title=\"View volume details\"><i class=\"fas fa-info-circle\"></i></button></div></td></tr>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, ecVolume := range data.EcVolumes {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "<tr><td><strong>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var16 string
|
||||||
|
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", ecVolume.VolumeID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 220, Col: 52}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "</strong></td><td><span class=\"badge bg-info\"><i class=\"fas fa-th-large me-1\"></i>EC</span></td><td><span class=\"badge bg-primary\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var17 string
|
||||||
|
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d/14", ecVolume.TotalShards))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 228, Col: 81}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "</span></td><td><span class=\"text-muted\">-</span></td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if ecVolume.IsComplete {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "<span class=\"badge bg-success\"><i class=\"fas fa-check me-1\"></i>Complete</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "<span class=\"badge bg-warning\"><i class=\"fas fa-exclamation-triangle me-1\"></i> Missing ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var18 string
|
||||||
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(ecVolume.MissingShards)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 241, Col: 64}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, " shards</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "</td><td><div class=\"btn-group\" role=\"group\"><button type=\"button\" class=\"btn btn-sm btn-outline-info\" onclick=\"showEcVolumeDetails(event)\" data-volume-id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var19 string
|
||||||
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", ecVolume.VolumeID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 249, Col: 63}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "\" title=\"View EC volume details\"><i class=\"fas fa-info-circle\"></i></button> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if !ecVolume.IsComplete {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "<button type=\"button\" class=\"btn btn-sm btn-outline-warning\" onclick=\"repairEcVolume(event)\" data-volume-id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var20 string
|
||||||
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", ecVolume.VolumeID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 256, Col: 64}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "\" title=\"Repair missing shards\"><i class=\"fas fa-wrench\"></i></button>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "</div></td></tr>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "</tbody></table></div><!-- Pagination -->")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.TotalPages > 1 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "<nav aria-label=\"Collection volumes pagination\"><ul class=\"pagination justify-content-center\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.Page > 1 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "<li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(event)\" data-page=\"1\">First</a></li><li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(event)\" data-page=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var21 string
|
||||||
|
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.Page-1))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 278, Col: 104}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "\">Previous</a></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := 1; i <= data.TotalPages; i++ {
|
||||||
|
if i == data.Page {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "<li class=\"page-item active\"><span class=\"page-link\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var22 string
|
||||||
|
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", i))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 285, Col: 52}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "</span></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else if i <= 3 || i > data.TotalPages-3 || (i >= data.Page-2 && i <= data.Page+2) {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "<li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(event)\" data-page=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var23 string
|
||||||
|
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", i))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 289, Col: 95}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var24 string
|
||||||
|
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", i))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 289, Col: 119}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "</a></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else if i == 4 && data.Page > 6 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "<li class=\"page-item disabled\"><span class=\"page-link\">...</span></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else if i == data.TotalPages-3 && data.Page < data.TotalPages-5 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "<li class=\"page-item disabled\"><span class=\"page-link\">...</span></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if data.Page < data.TotalPages {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "<li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(event)\" data-page=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var25 string
|
||||||
|
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.Page+1))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 304, Col: 104}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "\">Next</a></li><li class=\"page-item\"><a class=\"page-link\" href=\"#\" onclick=\"goToPage(event)\" data-page=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var26 string
|
||||||
|
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalPages))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/collection_details.templ`, Line: 307, Col: 108}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "\">Last</a></li>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "</ul></nav>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "<script>\n\t\t// Sorting functionality\n\t\tfunction sortBy(field) {\n\t\t\tconst currentSort = new URLSearchParams(window.location.search).get('sort_by');\n\t\t\tconst currentOrder = new URLSearchParams(window.location.search).get('sort_order') || 'asc';\n\t\t\t\n\t\t\tlet newOrder = 'asc';\n\t\t\tif (currentSort === field && currentOrder === 'asc') {\n\t\t\t\tnewOrder = 'desc';\n\t\t\t}\n\t\t\t\n\t\t\tconst url = new URL(window.location);\n\t\t\turl.searchParams.set('sort_by', field);\n\t\t\turl.searchParams.set('sort_order', newOrder);\n\t\t\turl.searchParams.set('page', '1'); // Reset to first page\n\t\t\twindow.location.href = url.toString();\n\t\t}\n\n\t\t// Pagination functionality\n\t\tfunction goToPage(event) {\n\t\t\tevent.preventDefault();\n\t\t\tconst page = event.target.closest('a').getAttribute('data-page');\n\t\t\tconst url = new URL(window.location);\n\t\t\turl.searchParams.set('page', page);\n\t\t\twindow.location.href = url.toString();\n\t\t}\n\n\t\t// Page size functionality\n\t\tfunction changePageSize(newPageSize) {\n\t\t\tconst url = new URL(window.location);\n\t\t\turl.searchParams.set('page_size', newPageSize);\n\t\t\turl.searchParams.set('page', '1'); // Reset to first page when changing page size\n\t\t\twindow.location.href = url.toString();\n\t\t}\n\n\t\t// Volume details\n\t\tfunction showVolumeDetails(event) {\n\t\t\tconst volumeId = event.target.closest('button').getAttribute('data-volume-id');\n\t\t\tconst server = event.target.closest('button').getAttribute('data-server');\n\t\t\twindow.location.href = `/cluster/volumes/${volumeId}/${server}`;\n\t\t}\n\n\t\t// EC Volume details\n\t\tfunction showEcVolumeDetails(event) {\n\t\t\tconst volumeId = event.target.closest('button').getAttribute('data-volume-id');\n\t\t\twindow.location.href = `/cluster/ec-volumes/${volumeId}`;\n\t\t}\n\n\t\t// Repair EC Volume\n\t\tfunction repairEcVolume(event) {\n\t\t\tconst volumeId = event.target.closest('button').getAttribute('data-volume-id');\n\t\t\tif (confirm(`Are you sure you want to repair missing shards for EC volume ${volumeId}?`)) {\n\t\t\t\t// TODO: Implement repair functionality\n\t\t\t\talert('Repair functionality will be implemented soon.');\n\t\t\t}\n\t\t}\n\t</script>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = templruntime.GeneratedTemplate
|
||||||
@@ -0,0 +1,313 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||||
|
)
|
||||||
|
|
||||||
|
templ EcVolumeDetails(data dash.EcVolumeDetailsData) {
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<div>
|
||||||
|
<h1 class="h2">
|
||||||
|
<i class="fas fa-th-large me-2"></i>EC Volume Details
|
||||||
|
</h1>
|
||||||
|
<nav aria-label="breadcrumb">
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
<li class="breadcrumb-item"><a href="/admin" class="text-decoration-none">Dashboard</a></li>
|
||||||
|
<li class="breadcrumb-item"><a href="/cluster/ec-shards" class="text-decoration-none">EC Volumes</a></li>
|
||||||
|
<li class="breadcrumb-item active" aria-current="page">Volume {fmt.Sprintf("%d", data.VolumeID)}</li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<div class="btn-toolbar mb-2 mb-md-0">
|
||||||
|
<div class="btn-group me-2">
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="history.back()">
|
||||||
|
<i class="fas fa-arrow-left me-1"></i>Back
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-primary" onclick="window.location.reload()">
|
||||||
|
<i class="fas fa-refresh me-1"></i>Refresh
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- EC Volume Summary -->
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="card-title mb-0">
|
||||||
|
<i class="fas fa-info-circle me-2"></i>Volume Information
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<table class="table table-borderless">
|
||||||
|
<tr>
|
||||||
|
<td><strong>Volume ID:</strong></td>
|
||||||
|
<td>{fmt.Sprintf("%d", data.VolumeID)}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Collection:</strong></td>
|
||||||
|
<td>
|
||||||
|
if data.Collection != "" {
|
||||||
|
<span class="badge bg-info">{data.Collection}</span>
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">default</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Status:</strong></td>
|
||||||
|
<td>
|
||||||
|
if data.IsComplete {
|
||||||
|
<span class="badge bg-success">
|
||||||
|
<i class="fas fa-check me-1"></i>Complete ({data.TotalShards}/14 shards)
|
||||||
|
</span>
|
||||||
|
} else {
|
||||||
|
<span class="badge bg-warning">
|
||||||
|
<i class="fas fa-exclamation-triangle me-1"></i>Incomplete ({data.TotalShards}/14 shards)
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
if !data.IsComplete {
|
||||||
|
<tr>
|
||||||
|
<td><strong>Missing Shards:</strong></td>
|
||||||
|
<td>
|
||||||
|
for i, shardID := range data.MissingShards {
|
||||||
|
if i > 0 {
|
||||||
|
<span>, </span>
|
||||||
|
}
|
||||||
|
<span class="badge bg-danger">{fmt.Sprintf("%02d", shardID)}</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
<tr>
|
||||||
|
<td><strong>Data Centers:</strong></td>
|
||||||
|
<td>
|
||||||
|
for i, dc := range data.DataCenters {
|
||||||
|
if i > 0 {
|
||||||
|
<span>, </span>
|
||||||
|
}
|
||||||
|
<span class="badge bg-primary">{dc}</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Servers:</strong></td>
|
||||||
|
<td>
|
||||||
|
<span class="text-muted">{fmt.Sprintf("%d servers", len(data.Servers))}</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Last Updated:</strong></td>
|
||||||
|
<td>
|
||||||
|
<span class="text-muted">{data.LastUpdated.Format("2006-01-02 15:04:05")}</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="card-title mb-0">
|
||||||
|
<i class="fas fa-chart-pie me-2"></i>Shard Distribution
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row text-center">
|
||||||
|
<div class="col-4">
|
||||||
|
<div class="border rounded p-3">
|
||||||
|
<h3 class="text-primary mb-1">{fmt.Sprintf("%d", data.TotalShards)}</h3>
|
||||||
|
<small class="text-muted">Total Shards</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<div class="border rounded p-3">
|
||||||
|
<h3 class="text-success mb-1">{fmt.Sprintf("%d", len(data.DataCenters))}</h3>
|
||||||
|
<small class="text-muted">Data Centers</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<div class="border rounded p-3">
|
||||||
|
<h3 class="text-info mb-1">{fmt.Sprintf("%d", len(data.Servers))}</h3>
|
||||||
|
<small class="text-muted">Servers</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Shard Distribution Visualization -->
|
||||||
|
<div class="mt-3">
|
||||||
|
<h6>Present Shards:</h6>
|
||||||
|
<div class="d-flex flex-wrap gap-1">
|
||||||
|
for _, shard := range data.Shards {
|
||||||
|
<span class="badge bg-success me-1 mb-1">{fmt.Sprintf("%02d", shard.ShardID)}</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
if len(data.MissingShards) > 0 {
|
||||||
|
<h6 class="mt-2">Missing Shards:</h6>
|
||||||
|
<div class="d-flex flex-wrap gap-1">
|
||||||
|
for _, shardID := range data.MissingShards {
|
||||||
|
<span class="badge bg-secondary me-1 mb-1">{fmt.Sprintf("%02d", shardID)}</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Shard Details Table -->
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="card-title mb-0">
|
||||||
|
<i class="fas fa-list me-2"></i>Shard Details
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
if len(data.Shards) > 0 {
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('shard_id')" class="text-dark text-decoration-none">
|
||||||
|
Shard ID
|
||||||
|
if data.SortBy == "shard_id" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('server')" class="text-dark text-decoration-none">
|
||||||
|
Server
|
||||||
|
if data.SortBy == "server" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('data_center')" class="text-dark text-decoration-none">
|
||||||
|
Data Center
|
||||||
|
if data.SortBy == "data_center" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<a href="#" onclick="sortBy('rack')" class="text-dark text-decoration-none">
|
||||||
|
Rack
|
||||||
|
if data.SortBy == "rack" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
<i class="fas fa-sort-up ms-1"></i>
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort-down ms-1"></i>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</th>
|
||||||
|
<th class="text-dark">Disk Type</th>
|
||||||
|
<th class="text-dark">Shard Size</th>
|
||||||
|
<th class="text-dark">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
for _, shard := range data.Shards {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-primary">{fmt.Sprintf("%02d", shard.ShardID)}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href={ templ.URL("/cluster/volume-servers/" + shard.Server) } class="text-primary text-decoration-none">
|
||||||
|
<code class="small">{shard.Server}</code>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-primary text-white">{shard.DataCenter}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-secondary text-white">{shard.Rack}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="text-dark">{shard.DiskType}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="text-success">{bytesToHumanReadableUint64(shard.Size)}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href={ templ.SafeURL(fmt.Sprintf("http://%s/ui/index.html", shard.Server)) } target="_blank" class="btn btn-sm btn-primary">
|
||||||
|
<i class="fas fa-external-link-alt me-1"></i>Volume Server
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
} else {
|
||||||
|
<div class="text-center py-4">
|
||||||
|
<i class="fas fa-exclamation-triangle fa-3x text-warning mb-3"></i>
|
||||||
|
<h5>No EC shards found</h5>
|
||||||
|
<p class="text-muted">This volume may not be EC encoded yet.</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// Sorting functionality
|
||||||
|
function sortBy(field) {
|
||||||
|
const currentSort = new URLSearchParams(window.location.search).get('sort_by');
|
||||||
|
const currentOrder = new URLSearchParams(window.location.search).get('sort_order') || 'asc';
|
||||||
|
|
||||||
|
let newOrder = 'asc';
|
||||||
|
if (currentSort === field && currentOrder === 'asc') {
|
||||||
|
newOrder = 'desc';
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.set('sort_by', field);
|
||||||
|
url.searchParams.set('sort_order', newOrder);
|
||||||
|
window.location.href = url.toString();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to convert bytes to human readable format (uint64 version)
|
||||||
|
func bytesToHumanReadableUint64(bytes uint64) string {
|
||||||
|
const unit = 1024
|
||||||
|
if bytes < unit {
|
||||||
|
return fmt.Sprintf("%dB", bytes)
|
||||||
|
}
|
||||||
|
div, exp := uint64(unit), 0
|
||||||
|
for n := bytes / unit; n >= unit; n /= unit {
|
||||||
|
div *= unit
|
||||||
|
exp++
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%.1f%cB", float64(bytes)/float64(div), "KMGTPE"[exp])
|
||||||
|
}
|
||||||
@@ -0,0 +1,560 @@
|
|||||||
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
|
// templ: version: v0.3.906
|
||||||
|
package app
|
||||||
|
|
||||||
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
|
|
||||||
|
import "github.com/a-h/templ"
|
||||||
|
import templruntime "github.com/a-h/templ/runtime"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EcVolumeDetails(data dash.EcVolumeDetailsData) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var1 == nil {
|
||||||
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom\"><div><h1 class=\"h2\"><i class=\"fas fa-th-large me-2\"></i>EC Volume Details</h1><nav aria-label=\"breadcrumb\"><ol class=\"breadcrumb\"><li class=\"breadcrumb-item\"><a href=\"/admin\" class=\"text-decoration-none\">Dashboard</a></li><li class=\"breadcrumb-item\"><a href=\"/cluster/ec-shards\" class=\"text-decoration-none\">EC Volumes</a></li><li class=\"breadcrumb-item active\" aria-current=\"page\">Volume ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var2 string
|
||||||
|
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.VolumeID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 18, Col: 115}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</li></ol></nav></div><div class=\"btn-toolbar mb-2 mb-md-0\"><div class=\"btn-group me-2\"><button type=\"button\" class=\"btn btn-sm btn-outline-secondary\" onclick=\"history.back()\"><i class=\"fas fa-arrow-left me-1\"></i>Back</button> <button type=\"button\" class=\"btn btn-sm btn-outline-primary\" onclick=\"window.location.reload()\"><i class=\"fas fa-refresh me-1\"></i>Refresh</button></div></div></div><!-- EC Volume Summary --><div class=\"row mb-4\"><div class=\"col-md-6\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"card-title mb-0\"><i class=\"fas fa-info-circle me-2\"></i>Volume Information</h5></div><div class=\"card-body\"><table class=\"table table-borderless\"><tr><td><strong>Volume ID:</strong></td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var3 string
|
||||||
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.VolumeID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 47, Col: 65}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</td></tr><tr><td><strong>Collection:</strong></td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.Collection != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<span class=\"badge bg-info\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var4 string
|
||||||
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(data.Collection)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 53, Col: 80}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<span class=\"text-muted\">default</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "</td></tr><tr><td><strong>Status:</strong></td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.IsComplete {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<span class=\"badge bg-success\"><i class=\"fas fa-check me-1\"></i>Complete (")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var5 string
|
||||||
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(data.TotalShards)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 64, Col: 100}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "/14 shards)</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<span class=\"badge bg-warning\"><i class=\"fas fa-exclamation-triangle me-1\"></i>Incomplete (")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var6 string
|
||||||
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(data.TotalShards)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 68, Col: 117}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "/14 shards)</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</td></tr>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if !data.IsComplete {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "<tr><td><strong>Missing Shards:</strong></td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for i, shardID := range data.MissingShards {
|
||||||
|
if i > 0 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "<span>, </span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " <span class=\"badge bg-danger\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var7 string
|
||||||
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%02d", shardID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 81, Col: 99}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "</td></tr>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<tr><td><strong>Data Centers:</strong></td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for i, dc := range data.DataCenters {
|
||||||
|
if i > 0 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<span>, </span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, " <span class=\"badge bg-primary\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var8 string
|
||||||
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(dc)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 93, Col: 70}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "</td></tr><tr><td><strong>Servers:</strong></td><td><span class=\"text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var9 string
|
||||||
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d servers", len(data.Servers)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 100, Col: 102}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "</span></td></tr><tr><td><strong>Last Updated:</strong></td><td><span class=\"text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var10 string
|
||||||
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(data.LastUpdated.Format("2006-01-02 15:04:05"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 106, Col: 104}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</span></td></tr></table></div></div></div><div class=\"col-md-6\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"card-title mb-0\"><i class=\"fas fa-chart-pie me-2\"></i>Shard Distribution</h5></div><div class=\"card-body\"><div class=\"row text-center\"><div class=\"col-4\"><div class=\"border rounded p-3\"><h3 class=\"text-primary mb-1\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var11 string
|
||||||
|
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.TotalShards))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 125, Col: 98}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</h3><small class=\"text-muted\">Total Shards</small></div></div><div class=\"col-4\"><div class=\"border rounded p-3\"><h3 class=\"text-success mb-1\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var12 string
|
||||||
|
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(data.DataCenters)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 131, Col: 103}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "</h3><small class=\"text-muted\">Data Centers</small></div></div><div class=\"col-4\"><div class=\"border rounded p-3\"><h3 class=\"text-info mb-1\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var13 string
|
||||||
|
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(data.Servers)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 137, Col: 96}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "</h3><small class=\"text-muted\">Servers</small></div></div></div><!-- Shard Distribution Visualization --><div class=\"mt-3\"><h6>Present Shards:</h6><div class=\"d-flex flex-wrap gap-1\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, shard := range data.Shards {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<span class=\"badge bg-success me-1 mb-1\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var14 string
|
||||||
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%02d", shard.ShardID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 148, Col: 108}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if len(data.MissingShards) > 0 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "<h6 class=\"mt-2\">Missing Shards:</h6><div class=\"d-flex flex-wrap gap-1\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, shardID := range data.MissingShards {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<span class=\"badge bg-secondary me-1 mb-1\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var15 string
|
||||||
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%02d", shardID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 155, Col: 108}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "</div></div></div></div></div><!-- Shard Details Table --><div class=\"card\"><div class=\"card-header\"><h5 class=\"card-title mb-0\"><i class=\"fas fa-list me-2\"></i>Shard Details</h5></div><div class=\"card-body\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if len(data.Shards) > 0 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "<div class=\"table-responsive\"><table class=\"table table-striped table-hover\"><thead><tr><th><a href=\"#\" onclick=\"sortBy('shard_id')\" class=\"text-dark text-decoration-none\">Shard ID ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "shard_id" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "</a></th><th><a href=\"#\" onclick=\"sortBy('server')\" class=\"text-dark text-decoration-none\">Server ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "server" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "</a></th><th><a href=\"#\" onclick=\"sortBy('data_center')\" class=\"text-dark text-decoration-none\">Data Center ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "data_center" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "</a></th><th><a href=\"#\" onclick=\"sortBy('rack')\" class=\"text-dark text-decoration-none\">Rack ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.SortBy == "rack" {
|
||||||
|
if data.SortOrder == "asc" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "<i class=\"fas fa-sort-up ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "<i class=\"fas fa-sort-down ms-1\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "<i class=\"fas fa-sort ms-1 text-muted\"></i>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "</a></th><th class=\"text-dark\">Disk Type</th><th class=\"text-dark\">Shard Size</th><th class=\"text-dark\">Actions</th></tr></thead> <tbody>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, shard := range data.Shards {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "<tr><td><span class=\"badge bg-primary\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var16 string
|
||||||
|
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%02d", shard.ShardID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 243, Col: 110}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "</span></td><td><a href=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var17 templ.SafeURL
|
||||||
|
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinURLErrs(templ.URL("/cluster/volume-servers/" + shard.Server))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 246, Col: 106}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "\" class=\"text-primary text-decoration-none\"><code class=\"small\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var18 string
|
||||||
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(shard.Server)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 247, Col: 81}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "</code></a></td><td><span class=\"badge bg-primary text-white\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var19 string
|
||||||
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(shard.DataCenter)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 251, Col: 103}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "</span></td><td><span class=\"badge bg-secondary text-white\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var20 string
|
||||||
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(shard.Rack)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 254, Col: 99}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "</span></td><td><span class=\"text-dark\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var21 string
|
||||||
|
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(shard.DiskType)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 257, Col: 83}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "</span></td><td><span class=\"text-success\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var22 string
|
||||||
|
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(bytesToHumanReadableUint64(shard.Size))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 260, Col: 110}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "</span></td><td><a href=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var23 templ.SafeURL
|
||||||
|
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("http://%s/ui/index.html", shard.Server)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/ec_volume_details.templ`, Line: 263, Col: 121}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "\" target=\"_blank\" class=\"btn btn-sm btn-primary\"><i class=\"fas fa-external-link-alt me-1\"></i>Volume Server</a></td></tr>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "</tbody></table></div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "<div class=\"text-center py-4\"><i class=\"fas fa-exclamation-triangle fa-3x text-warning mb-3\"></i><h5>No EC shards found</h5><p class=\"text-muted\">This volume may not be EC encoded yet.</p></div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "</div></div><script>\n // Sorting functionality\n function sortBy(field) {\n const currentSort = new URLSearchParams(window.location.search).get('sort_by');\n const currentOrder = new URLSearchParams(window.location.search).get('sort_order') || 'asc';\n \n let newOrder = 'asc';\n if (currentSort === field && currentOrder === 'asc') {\n newOrder = 'desc';\n }\n \n const url = new URL(window.location);\n url.searchParams.set('sort_by', field);\n url.searchParams.set('sort_order', newOrder);\n window.location.href = url.toString();\n }\n </script>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to convert bytes to human readable format (uint64 version)
|
||||||
|
func bytesToHumanReadableUint64(bytes uint64) string {
|
||||||
|
const unit = 1024
|
||||||
|
if bytes < unit {
|
||||||
|
return fmt.Sprintf("%dB", bytes)
|
||||||
|
}
|
||||||
|
div, exp := uint64(unit), 0
|
||||||
|
for n := bytes / unit; n >= unit; n /= unit {
|
||||||
|
div *= unit
|
||||||
|
exp++
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%.1f%cB", float64(bytes)/float64(div), "KMGTPE"[exp])
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = templruntime.GeneratedTemplate
|
||||||
@@ -47,63 +47,70 @@ templ MaintenanceConfig(data *maintenance.MaintenanceConfigData) {
|
|||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="scanInterval" class="form-label">Scan Interval (minutes)</label>
|
<label for="scanInterval" class="form-label">Scan Interval (minutes)</label>
|
||||||
<input type="number" class="form-control" id="scanInterval"
|
<input type="number" class="form-control" id="scanInterval"
|
||||||
value={fmt.Sprintf("%.0f", float64(data.Config.ScanIntervalSeconds)/60)} min="1" max="1440">
|
value={fmt.Sprintf("%.0f", float64(data.Config.ScanIntervalSeconds)/60)}
|
||||||
|
placeholder="30 (default)" min="1" max="1440">
|
||||||
<small class="form-text text-muted">
|
<small class="form-text text-muted">
|
||||||
How often to scan for maintenance tasks (1-1440 minutes).
|
How often to scan for maintenance tasks (1-1440 minutes). <strong>Default: 30 minutes</strong>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="workerTimeout" class="form-label">Worker Timeout (minutes)</label>
|
<label for="workerTimeout" class="form-label">Worker Timeout (minutes)</label>
|
||||||
<input type="number" class="form-control" id="workerTimeout"
|
<input type="number" class="form-control" id="workerTimeout"
|
||||||
value={fmt.Sprintf("%.0f", float64(data.Config.WorkerTimeoutSeconds)/60)} min="1" max="60">
|
value={fmt.Sprintf("%.0f", float64(data.Config.WorkerTimeoutSeconds)/60)}
|
||||||
|
placeholder="5 (default)" min="1" max="60">
|
||||||
<small class="form-text text-muted">
|
<small class="form-text text-muted">
|
||||||
How long to wait for worker heartbeat before considering it inactive (1-60 minutes).
|
How long to wait for worker heartbeat before considering it inactive (1-60 minutes). <strong>Default: 5 minutes</strong>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="taskTimeout" class="form-label">Task Timeout (hours)</label>
|
<label for="taskTimeout" class="form-label">Task Timeout (hours)</label>
|
||||||
<input type="number" class="form-control" id="taskTimeout"
|
<input type="number" class="form-control" id="taskTimeout"
|
||||||
value={fmt.Sprintf("%.0f", float64(data.Config.TaskTimeoutSeconds)/3600)} min="1" max="24">
|
value={fmt.Sprintf("%.0f", float64(data.Config.TaskTimeoutSeconds)/3600)}
|
||||||
|
placeholder="2 (default)" min="1" max="24">
|
||||||
<small class="form-text text-muted">
|
<small class="form-text text-muted">
|
||||||
Maximum time allowed for a single task to complete (1-24 hours).
|
Maximum time allowed for a single task to complete (1-24 hours). <strong>Default: 2 hours</strong>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="globalMaxConcurrent" class="form-label">Global Concurrent Limit</label>
|
<label for="globalMaxConcurrent" class="form-label">Global Concurrent Limit</label>
|
||||||
<input type="number" class="form-control" id="globalMaxConcurrent"
|
<input type="number" class="form-control" id="globalMaxConcurrent"
|
||||||
value={fmt.Sprintf("%d", data.Config.Policy.GlobalMaxConcurrent)} min="1" max="20">
|
value={fmt.Sprintf("%d", data.Config.Policy.GlobalMaxConcurrent)}
|
||||||
|
placeholder="4 (default)" min="1" max="20">
|
||||||
<small class="form-text text-muted">
|
<small class="form-text text-muted">
|
||||||
Maximum number of maintenance tasks that can run simultaneously across all workers (1-20).
|
Maximum number of maintenance tasks that can run simultaneously across all workers (1-20). <strong>Default: 4</strong>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="maxRetries" class="form-label">Default Max Retries</label>
|
<label for="maxRetries" class="form-label">Default Max Retries</label>
|
||||||
<input type="number" class="form-control" id="maxRetries"
|
<input type="number" class="form-control" id="maxRetries"
|
||||||
value={fmt.Sprintf("%d", data.Config.MaxRetries)} min="0" max="10">
|
value={fmt.Sprintf("%d", data.Config.MaxRetries)}
|
||||||
|
placeholder="3 (default)" min="0" max="10">
|
||||||
<small class="form-text text-muted">
|
<small class="form-text text-muted">
|
||||||
Default number of times to retry failed tasks (0-10).
|
Default number of times to retry failed tasks (0-10). <strong>Default: 3</strong>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="retryDelay" class="form-label">Retry Delay (minutes)</label>
|
<label for="retryDelay" class="form-label">Retry Delay (minutes)</label>
|
||||||
<input type="number" class="form-control" id="retryDelay"
|
<input type="number" class="form-control" id="retryDelay"
|
||||||
value={fmt.Sprintf("%.0f", float64(data.Config.RetryDelaySeconds)/60)} min="1" max="120">
|
value={fmt.Sprintf("%.0f", float64(data.Config.RetryDelaySeconds)/60)}
|
||||||
|
placeholder="15 (default)" min="1" max="120">
|
||||||
<small class="form-text text-muted">
|
<small class="form-text text-muted">
|
||||||
Time to wait before retrying failed tasks (1-120 minutes).
|
Time to wait before retrying failed tasks (1-120 minutes). <strong>Default: 15 minutes</strong>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="taskRetention" class="form-label">Task Retention (days)</label>
|
<label for="taskRetention" class="form-label">Task Retention (days)</label>
|
||||||
<input type="number" class="form-control" id="taskRetention"
|
<input type="number" class="form-control" id="taskRetention"
|
||||||
value={fmt.Sprintf("%.0f", float64(data.Config.TaskRetentionSeconds)/(24*3600))} min="1" max="30">
|
value={fmt.Sprintf("%.0f", float64(data.Config.TaskRetentionSeconds)/(24*3600))}
|
||||||
|
placeholder="7 (default)" min="1" max="30">
|
||||||
<small class="form-text text-muted">
|
<small class="form-text text-muted">
|
||||||
How long to keep completed/failed task records (1-30 days).
|
How long to keep completed/failed task records (1-30 days). <strong>Default: 7 days</strong>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -143,7 +150,7 @@ templ MaintenanceConfig(data *maintenance.MaintenanceConfigData) {
|
|||||||
<i class={menuItem.Icon + " me-2"}></i>
|
<i class={menuItem.Icon + " me-2"}></i>
|
||||||
{menuItem.DisplayName}
|
{menuItem.DisplayName}
|
||||||
</h6>
|
</h6>
|
||||||
if data.Config.Policy.IsTaskEnabled(menuItem.TaskType) {
|
if menuItem.IsEnabled {
|
||||||
<span class="badge bg-success">Enabled</span>
|
<span class="badge bg-success">Enabled</span>
|
||||||
} else {
|
} else {
|
||||||
<span class="badge bg-secondary">Disabled</span>
|
<span class="badge bg-secondary">Disabled</span>
|
||||||
@@ -200,44 +207,60 @@ templ MaintenanceConfig(data *maintenance.MaintenanceConfigData) {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
function saveConfiguration() {
|
function saveConfiguration() {
|
||||||
const config = {
|
// First, get current configuration to preserve existing values
|
||||||
enabled: document.getElementById('enabled').checked,
|
fetch('/api/maintenance/config')
|
||||||
scan_interval_seconds: parseInt(document.getElementById('scanInterval').value) * 60, // Convert to seconds
|
.then(response => response.json())
|
||||||
policy: {
|
.then(currentConfig => {
|
||||||
vacuum_enabled: document.getElementById('vacuumEnabled').checked,
|
// Update only the fields from the form
|
||||||
vacuum_garbage_ratio: parseFloat(document.getElementById('vacuumGarbageRatio').value) / 100,
|
const updatedConfig = {
|
||||||
replication_fix_enabled: document.getElementById('replicationFixEnabled').checked,
|
...currentConfig.config, // Preserve existing config
|
||||||
}
|
enabled: document.getElementById('enabled').checked,
|
||||||
};
|
scan_interval_seconds: parseInt(document.getElementById('scanInterval').value) * 60, // Convert to seconds
|
||||||
|
worker_timeout_seconds: parseInt(document.getElementById('workerTimeout').value) * 60, // Convert to seconds
|
||||||
|
task_timeout_seconds: parseInt(document.getElementById('taskTimeout').value) * 3600, // Convert to seconds
|
||||||
|
retry_delay_seconds: parseInt(document.getElementById('retryDelay').value) * 60, // Convert to seconds
|
||||||
|
max_retries: parseInt(document.getElementById('maxRetries').value),
|
||||||
|
task_retention_seconds: parseInt(document.getElementById('taskRetention').value) * 24 * 3600, // Convert to seconds
|
||||||
|
policy: {
|
||||||
|
...currentConfig.config.policy, // Preserve existing policy
|
||||||
|
global_max_concurrent: parseInt(document.getElementById('globalMaxConcurrent').value)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
fetch('/api/maintenance/config', {
|
// Send the updated configuration
|
||||||
method: 'PUT',
|
return fetch('/api/maintenance/config', {
|
||||||
headers: {
|
method: 'PUT',
|
||||||
'Content-Type': 'application/json',
|
headers: {
|
||||||
},
|
'Content-Type': 'application/json',
|
||||||
body: JSON.stringify(config)
|
},
|
||||||
})
|
body: JSON.stringify(updatedConfig)
|
||||||
.then(response => response.json())
|
});
|
||||||
.then(data => {
|
})
|
||||||
if (data.success) {
|
.then(response => response.json())
|
||||||
alert('Configuration saved successfully');
|
.then(data => {
|
||||||
} else {
|
if (data.success) {
|
||||||
alert('Failed to save configuration: ' + (data.error || 'Unknown error'));
|
alert('Configuration saved successfully');
|
||||||
}
|
location.reload(); // Reload to show updated values
|
||||||
})
|
} else {
|
||||||
.catch(error => {
|
alert('Failed to save configuration: ' + (data.error || 'Unknown error'));
|
||||||
alert('Error: ' + error.message);
|
}
|
||||||
});
|
})
|
||||||
|
.catch(error => {
|
||||||
|
alert('Error: ' + error.message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetToDefaults() {
|
function resetToDefaults() {
|
||||||
if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {
|
if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {
|
||||||
// Reset form to defaults
|
// Reset form to defaults (matching DefaultMaintenanceConfig values)
|
||||||
document.getElementById('enabled').checked = false;
|
document.getElementById('enabled').checked = false;
|
||||||
document.getElementById('scanInterval').value = '30';
|
document.getElementById('scanInterval').value = '30';
|
||||||
document.getElementById('vacuumEnabled').checked = false;
|
document.getElementById('workerTimeout').value = '5';
|
||||||
document.getElementById('vacuumGarbageRatio').value = '30';
|
document.getElementById('taskTimeout').value = '2';
|
||||||
document.getElementById('replicationFixEnabled').checked = false;
|
document.getElementById('globalMaxConcurrent').value = '4';
|
||||||
|
document.getElementById('maxRetries').value = '3';
|
||||||
|
document.getElementById('retryDelay').value = '15';
|
||||||
|
document.getElementById('taskRetention').value = '7';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -0,0 +1,425 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/maintenance"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
templ MaintenanceConfigSchema(data *maintenance.MaintenanceConfigData, schema *maintenance.MaintenanceConfigSchema) {
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<h2 class="mb-0">
|
||||||
|
<i class="fas fa-cogs me-2"></i>
|
||||||
|
Maintenance Configuration
|
||||||
|
</h2>
|
||||||
|
<div class="btn-group">
|
||||||
|
<a href="/maintenance/tasks" class="btn btn-outline-primary">
|
||||||
|
<i class="fas fa-tasks me-1"></i>
|
||||||
|
View Tasks
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="mb-0">System Settings</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form id="maintenanceConfigForm">
|
||||||
|
<!-- Dynamically render all schema fields in order -->
|
||||||
|
for _, field := range schema.Fields {
|
||||||
|
@ConfigField(field, getMaintenanceFieldValue(data.Config, field.JSONName))
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="d-flex gap-2">
|
||||||
|
<button type="button" class="btn btn-primary" onclick="saveConfiguration()">
|
||||||
|
<i class="fas fa-save me-1"></i>
|
||||||
|
Save Configuration
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-secondary" onclick="resetToDefaults()">
|
||||||
|
<i class="fas fa-undo me-1"></i>
|
||||||
|
Reset to Defaults
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Task Configuration Cards -->
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="mb-0">
|
||||||
|
<i class="fas fa-broom me-2"></i>
|
||||||
|
Volume Vacuum
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text">Reclaims disk space by removing deleted files from volumes.</p>
|
||||||
|
<a href="/maintenance/config/vacuum" class="btn btn-primary">Configure</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="mb-0">
|
||||||
|
<i class="fas fa-balance-scale me-2"></i>
|
||||||
|
Volume Balance
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text">Redistributes volumes across servers to optimize storage utilization.</p>
|
||||||
|
<a href="/maintenance/config/balance" class="btn btn-primary">Configure</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="mb-0">
|
||||||
|
<i class="fas fa-shield-alt me-2"></i>
|
||||||
|
Erasure Coding
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="card-text">Converts volumes to erasure coded format for improved durability.</p>
|
||||||
|
<a href="/maintenance/config/erasure_coding" class="btn btn-primary">Configure</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function saveConfiguration() {
|
||||||
|
const form = document.getElementById('maintenanceConfigForm');
|
||||||
|
const formData = new FormData(form);
|
||||||
|
|
||||||
|
// Convert form data to JSON, handling interval fields specially
|
||||||
|
const config = {};
|
||||||
|
|
||||||
|
for (let [key, value] of formData.entries()) {
|
||||||
|
if (key.endsWith('_value')) {
|
||||||
|
// This is an interval value part
|
||||||
|
const baseKey = key.replace('_value', '');
|
||||||
|
const unitKey = baseKey + '_unit';
|
||||||
|
const unitValue = formData.get(unitKey);
|
||||||
|
|
||||||
|
if (unitValue) {
|
||||||
|
// Convert to seconds based on unit
|
||||||
|
const numValue = parseInt(value) || 0;
|
||||||
|
let seconds = numValue;
|
||||||
|
switch(unitValue) {
|
||||||
|
case 'minutes':
|
||||||
|
seconds = numValue * 60;
|
||||||
|
break;
|
||||||
|
case 'hours':
|
||||||
|
seconds = numValue * 3600;
|
||||||
|
break;
|
||||||
|
case 'days':
|
||||||
|
seconds = numValue * 24 * 3600;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
config[baseKey] = seconds;
|
||||||
|
}
|
||||||
|
} else if (key.endsWith('_unit')) {
|
||||||
|
// Skip unit keys - they're handled with their corresponding value
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
// Regular field
|
||||||
|
if (form.querySelector(`[name="${key}"]`).type === 'checkbox') {
|
||||||
|
config[key] = form.querySelector(`[name="${key}"]`).checked;
|
||||||
|
} else {
|
||||||
|
const numValue = parseFloat(value);
|
||||||
|
config[key] = isNaN(numValue) ? value : numValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch('/maintenance/config', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(config)
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
alert('Configuration saved successfully!');
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert('Error saving configuration: ' + (data.error || 'Unknown error'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
alert('Error saving configuration: ' + error.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetToDefaults() {
|
||||||
|
if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {
|
||||||
|
fetch('/maintenance/config/defaults', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
alert('Configuration reset to defaults!');
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert('Error resetting configuration: ' + (data.error || 'Unknown error'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
alert('Error resetting configuration: ' + error.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfigField renders a single configuration field based on schema
|
||||||
|
templ ConfigField(field *config.Field, value interface{}) {
|
||||||
|
if field.InputType == "interval" {
|
||||||
|
<!-- Interval field with number input + unit dropdown -->
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for={ field.JSONName } class="form-label">
|
||||||
|
{ field.DisplayName }
|
||||||
|
if field.Required {
|
||||||
|
<span class="text-danger">*</span>
|
||||||
|
}
|
||||||
|
</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
class="form-control"
|
||||||
|
id={ field.JSONName + "_value" }
|
||||||
|
name={ field.JSONName + "_value" }
|
||||||
|
value={ fmt.Sprintf("%.0f", convertSecondsToDisplayValue(value, field)) }
|
||||||
|
step="1"
|
||||||
|
min="1"
|
||||||
|
if field.Required {
|
||||||
|
required
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<select
|
||||||
|
class="form-select"
|
||||||
|
id={ field.JSONName + "_unit" }
|
||||||
|
name={ field.JSONName + "_unit" }
|
||||||
|
style="max-width: 120px;"
|
||||||
|
if field.Required {
|
||||||
|
required
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
value="minutes"
|
||||||
|
if getDisplayUnit(value, field) == "minutes" {
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Minutes
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="hours"
|
||||||
|
if getDisplayUnit(value, field) == "hours" {
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Hours
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="days"
|
||||||
|
if getDisplayUnit(value, field) == "days" {
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Days
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
if field.Description != "" {
|
||||||
|
<div class="form-text text-muted">{ field.Description }</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
} else if field.InputType == "checkbox" {
|
||||||
|
<!-- Checkbox field -->
|
||||||
|
<div class="mb-3">
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input
|
||||||
|
class="form-check-input"
|
||||||
|
type="checkbox"
|
||||||
|
id={ field.JSONName }
|
||||||
|
name={ field.JSONName }
|
||||||
|
if getBoolValue(value) {
|
||||||
|
checked
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<label class="form-check-label" for={ field.JSONName }>
|
||||||
|
<strong>{ field.DisplayName }</strong>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
if field.Description != "" {
|
||||||
|
<div class="form-text text-muted">{ field.Description }</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
} else {
|
||||||
|
<!-- Number field -->
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for={ field.JSONName } class="form-label">
|
||||||
|
{ field.DisplayName }
|
||||||
|
if field.Required {
|
||||||
|
<span class="text-danger">*</span>
|
||||||
|
}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
class="form-control"
|
||||||
|
id={ field.JSONName }
|
||||||
|
name={ field.JSONName }
|
||||||
|
value={ fmt.Sprintf("%v", value) }
|
||||||
|
placeholder={ field.Placeholder }
|
||||||
|
if field.MinValue != nil {
|
||||||
|
min={ fmt.Sprintf("%v", field.MinValue) }
|
||||||
|
}
|
||||||
|
if field.MaxValue != nil {
|
||||||
|
max={ fmt.Sprintf("%v", field.MaxValue) }
|
||||||
|
}
|
||||||
|
step={ getNumberStep(field) }
|
||||||
|
if field.Required {
|
||||||
|
required
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
if field.Description != "" {
|
||||||
|
<div class="form-text text-muted">{ field.Description }</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper functions for the template
|
||||||
|
func getBoolValue(value interface{}) bool {
|
||||||
|
if boolVal, ok := value.(bool); ok {
|
||||||
|
return boolVal
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertSecondsToDisplayValue(value interface{}, field *config.Field) float64 {
|
||||||
|
if intVal, ok := value.(int); ok {
|
||||||
|
if intVal == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if intVal%(24*3600) == 0 {
|
||||||
|
return float64(intVal / (24 * 3600))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if intVal%3600 == 0 {
|
||||||
|
return float64(intVal / 3600)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return float64(intVal / 60)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDisplayUnit(value interface{}, field *config.Field) string {
|
||||||
|
if intVal, ok := value.(int); ok {
|
||||||
|
if intVal == 0 {
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if intVal%(24*3600) == 0 {
|
||||||
|
return "days"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if intVal%3600 == 0 {
|
||||||
|
return "hours"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getNumberStep(field *config.Field) string {
|
||||||
|
if field.Type == config.FieldTypeFloat {
|
||||||
|
return "0.01"
|
||||||
|
}
|
||||||
|
return "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMaintenanceFieldValue(config *maintenance.MaintenanceConfig, fieldName string) interface{} {
|
||||||
|
if config == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use reflection to get the field value from the config struct
|
||||||
|
configValue := reflect.ValueOf(config)
|
||||||
|
if configValue.Kind() == reflect.Ptr {
|
||||||
|
configValue = configValue.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if configValue.Kind() != reflect.Struct {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
configType := configValue.Type()
|
||||||
|
|
||||||
|
for i := 0; i < configValue.NumField(); i++ {
|
||||||
|
field := configValue.Field(i)
|
||||||
|
fieldType := configType.Field(i)
|
||||||
|
|
||||||
|
// Get JSON tag name
|
||||||
|
jsonTag := fieldType.Tag.Get("json")
|
||||||
|
if jsonTag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove options like ",omitempty"
|
||||||
|
if commaIdx := strings.Index(jsonTag, ","); commaIdx > 0 {
|
||||||
|
jsonTag = jsonTag[:commaIdx]
|
||||||
|
}
|
||||||
|
|
||||||
|
if jsonTag == fieldName {
|
||||||
|
return field.Interface()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle nested Policy fields
|
||||||
|
if config.Policy != nil && fieldName == "global_max_concurrent" {
|
||||||
|
return config.Policy.GlobalMaxConcurrent
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to convert schema to JSON for JavaScript
|
||||||
|
templ schemaToJSON(schema *maintenance.MaintenanceConfigSchema) {
|
||||||
|
{`{}`}
|
||||||
|
}
|
||||||
@@ -0,0 +1,674 @@
|
|||||||
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
|
// templ: version: v0.3.906
|
||||||
|
package app
|
||||||
|
|
||||||
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
|
|
||||||
|
import "github.com/a-h/templ"
|
||||||
|
import templruntime "github.com/a-h/templ/runtime"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/maintenance"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MaintenanceConfigSchema(data *maintenance.MaintenanceConfigData, schema *maintenance.MaintenanceConfigSchema) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var1 == nil {
|
||||||
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"container-fluid\"><div class=\"row mb-4\"><div class=\"col-12\"><div class=\"d-flex justify-content-between align-items-center\"><h2 class=\"mb-0\"><i class=\"fas fa-cogs me-2\"></i> Maintenance Configuration</h2><div class=\"btn-group\"><a href=\"/maintenance/tasks\" class=\"btn btn-outline-primary\"><i class=\"fas fa-tasks me-1\"></i> View Tasks</a></div></div></div></div><div class=\"row\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"mb-0\">System Settings</h5></div><div class=\"card-body\"><form id=\"maintenanceConfigForm\"><!-- Dynamically render all schema fields in order -->")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, field := range schema.Fields {
|
||||||
|
templ_7745c5c3_Err = ConfigField(field, getMaintenanceFieldValue(data.Config, field.JSONName)).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<div class=\"d-flex gap-2\"><button type=\"button\" class=\"btn btn-primary\" onclick=\"saveConfiguration()\"><i class=\"fas fa-save me-1\"></i> Save Configuration</button> <button type=\"button\" class=\"btn btn-secondary\" onclick=\"resetToDefaults()\"><i class=\"fas fa-undo me-1\"></i> Reset to Defaults</button></div></form></div></div></div></div><!-- Task Configuration Cards --><div class=\"row mt-4\"><div class=\"col-md-4\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"mb-0\"><i class=\"fas fa-broom me-2\"></i> Volume Vacuum</h5></div><div class=\"card-body\"><p class=\"card-text\">Reclaims disk space by removing deleted files from volumes.</p><a href=\"/maintenance/config/vacuum\" class=\"btn btn-primary\">Configure</a></div></div></div><div class=\"col-md-4\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"mb-0\"><i class=\"fas fa-balance-scale me-2\"></i> Volume Balance</h5></div><div class=\"card-body\"><p class=\"card-text\">Redistributes volumes across servers to optimize storage utilization.</p><a href=\"/maintenance/config/balance\" class=\"btn btn-primary\">Configure</a></div></div></div><div class=\"col-md-4\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"mb-0\"><i class=\"fas fa-shield-alt me-2\"></i> Erasure Coding</h5></div><div class=\"card-body\"><p class=\"card-text\">Converts volumes to erasure coded format for improved durability.</p><a href=\"/maintenance/config/erasure_coding\" class=\"btn btn-primary\">Configure</a></div></div></div></div></div><script>\n function saveConfiguration() {\n const form = document.getElementById('maintenanceConfigForm');\n const formData = new FormData(form);\n \n // Convert form data to JSON, handling interval fields specially\n const config = {};\n \n for (let [key, value] of formData.entries()) {\n if (key.endsWith('_value')) {\n // This is an interval value part\n const baseKey = key.replace('_value', '');\n const unitKey = baseKey + '_unit';\n const unitValue = formData.get(unitKey);\n \n if (unitValue) {\n // Convert to seconds based on unit\n const numValue = parseInt(value) || 0;\n let seconds = numValue;\n switch(unitValue) {\n case 'minutes':\n seconds = numValue * 60;\n break;\n case 'hours':\n seconds = numValue * 3600;\n break;\n case 'days':\n seconds = numValue * 24 * 3600;\n break;\n }\n config[baseKey] = seconds;\n }\n } else if (key.endsWith('_unit')) {\n // Skip unit keys - they're handled with their corresponding value\n continue;\n } else {\n // Regular field\n if (form.querySelector(`[name=\"${key}\"]`).type === 'checkbox') {\n config[key] = form.querySelector(`[name=\"${key}\"]`).checked;\n } else {\n const numValue = parseFloat(value);\n config[key] = isNaN(numValue) ? value : numValue;\n }\n }\n }\n\n fetch('/maintenance/config', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(config)\n })\n .then(response => response.json())\n .then(data => {\n if (data.success) {\n alert('Configuration saved successfully!');\n location.reload();\n } else {\n alert('Error saving configuration: ' + (data.error || 'Unknown error'));\n }\n })\n .catch(error => {\n console.error('Error:', error);\n alert('Error saving configuration: ' + error.message);\n });\n }\n\n function resetToDefaults() {\n if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {\n fetch('/maintenance/config/defaults', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n }\n })\n .then(response => response.json())\n .then(data => {Line truncated
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfigField renders a single configuration field based on schema
|
||||||
|
func ConfigField(field *config.Field, value interface{}) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var2 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var2 == nil {
|
||||||
|
templ_7745c5c3_Var2 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
if field.InputType == "interval" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<!-- Interval field with number input + unit dropdown --> <div class=\"mb-3\"><label for=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var3 string
|
||||||
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 205, Col: 39}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\" class=\"form-label\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var4 string
|
||||||
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(field.DisplayName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 206, Col: 35}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, " ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<span class=\"text-danger\">*</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "</label><div class=\"input-group\"><input type=\"number\" class=\"form-control\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var5 string
|
||||||
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName + "_value")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 215, Col: 50}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var6 string
|
||||||
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName + "_value")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 216, Col: 52}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var7 string
|
||||||
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", convertSecondsToDisplayValue(value, field)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 217, Col: 91}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\" step=\"1\" min=\"1\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, " required")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "> <select class=\"form-select\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var8 string
|
||||||
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName + "_unit")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 226, Col: 49}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var9 string
|
||||||
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName + "_unit")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 227, Col: 51}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "\" style=\"max-width: 120px;\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " required")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "><option value=\"minutes\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if getDisplayUnit(value, field) == "minutes" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, ">Minutes</option> <option value=\"hours\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if getDisplayUnit(value, field) == "hours" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, ">Hours</option> <option value=\"days\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if getDisplayUnit(value, field) == "days" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, ">Days</option></select></div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Description != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "<div class=\"form-text text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var10 string
|
||||||
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(field.Description)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 260, Col: 69}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else if field.InputType == "checkbox" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<!-- Checkbox field --> <div class=\"mb-3\"><div class=\"form-check form-switch\"><input class=\"form-check-input\" type=\"checkbox\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var11 string
|
||||||
|
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 270, Col: 39}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var12 string
|
||||||
|
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 271, Col: 41}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if getBoolValue(value) {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, " checked")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "> <label class=\"form-check-label\" for=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var13 string
|
||||||
|
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 276, Col: 68}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "\"><strong>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var14 string
|
||||||
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(field.DisplayName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 277, Col: 47}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "</strong></label></div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Description != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "<div class=\"form-text text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var15 string
|
||||||
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(field.Description)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 281, Col: 69}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "<!-- Number field --> <div class=\"mb-3\"><label for=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var16 string
|
||||||
|
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 287, Col: 39}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "\" class=\"form-label\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var17 string
|
||||||
|
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(field.DisplayName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 288, Col: 35}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, " ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "<span class=\"text-danger\">*</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "</label> <input type=\"number\" class=\"form-control\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var18 string
|
||||||
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 296, Col: 35}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var19 string
|
||||||
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 297, Col: 37}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "\" value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var20 string
|
||||||
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%v", value))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 298, Col: 48}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "\" placeholder=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var21 string
|
||||||
|
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(field.Placeholder)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 299, Col: 47}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.MinValue != nil {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, " min=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var22 string
|
||||||
|
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%v", field.MinValue))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 301, Col: 59}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if field.MaxValue != nil {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, " max=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var23 string
|
||||||
|
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%v", field.MaxValue))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 304, Col: 59}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, " step=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var24 string
|
||||||
|
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(getNumberStep(field))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 306, Col: 43}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, " required")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Description != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "<div class=\"form-text text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var25 string
|
||||||
|
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(field.Description)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 312, Col: 69}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper functions for the template
|
||||||
|
func getBoolValue(value interface{}) bool {
|
||||||
|
if boolVal, ok := value.(bool); ok {
|
||||||
|
return boolVal
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertSecondsToDisplayValue(value interface{}, field *config.Field) float64 {
|
||||||
|
if intVal, ok := value.(int); ok {
|
||||||
|
if intVal == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if intVal%(24*3600) == 0 {
|
||||||
|
return float64(intVal / (24 * 3600))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if intVal%3600 == 0 {
|
||||||
|
return float64(intVal / 3600)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return float64(intVal / 60)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDisplayUnit(value interface{}, field *config.Field) string {
|
||||||
|
if intVal, ok := value.(int); ok {
|
||||||
|
if intVal == 0 {
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if intVal%(24*3600) == 0 {
|
||||||
|
return "days"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if intVal%3600 == 0 {
|
||||||
|
return "hours"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getNumberStep(field *config.Field) string {
|
||||||
|
if field.Type == config.FieldTypeFloat {
|
||||||
|
return "0.01"
|
||||||
|
}
|
||||||
|
return "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMaintenanceFieldValue(config *maintenance.MaintenanceConfig, fieldName string) interface{} {
|
||||||
|
if config == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use reflection to get the field value from the config struct
|
||||||
|
configValue := reflect.ValueOf(config)
|
||||||
|
if configValue.Kind() == reflect.Ptr {
|
||||||
|
configValue = configValue.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if configValue.Kind() != reflect.Struct {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
configType := configValue.Type()
|
||||||
|
|
||||||
|
for i := 0; i < configValue.NumField(); i++ {
|
||||||
|
field := configValue.Field(i)
|
||||||
|
fieldType := configType.Field(i)
|
||||||
|
|
||||||
|
// Get JSON tag name
|
||||||
|
jsonTag := fieldType.Tag.Get("json")
|
||||||
|
if jsonTag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove options like ",omitempty"
|
||||||
|
if commaIdx := strings.Index(jsonTag, ","); commaIdx > 0 {
|
||||||
|
jsonTag = jsonTag[:commaIdx]
|
||||||
|
}
|
||||||
|
|
||||||
|
if jsonTag == fieldName {
|
||||||
|
return field.Interface()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle nested Policy fields
|
||||||
|
if config.Policy != nil && fieldName == "global_max_concurrent" {
|
||||||
|
return config.Policy.GlobalMaxConcurrent
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to convert schema to JSON for JavaScript
|
||||||
|
func schemaToJSON(schema *maintenance.MaintenanceConfigSchema) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var26 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var26 == nil {
|
||||||
|
templ_7745c5c3_Var26 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
var templ_7745c5c3_Var27 string
|
||||||
|
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(`{}`)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config_schema.templ`, Line: 424, Col: 9}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = templruntime.GeneratedTemplate
|
||||||
@@ -57,85 +57,85 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\" min=\"1\" max=\"1440\"> <small class=\"form-text text-muted\">How often to scan for maintenance tasks (1-1440 minutes).</small></div><div class=\"mb-3\"><label for=\"workerTimeout\" class=\"form-label\">Worker Timeout (minutes)</label> <input type=\"number\" class=\"form-control\" id=\"workerTimeout\" value=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\" placeholder=\"30 (default)\" min=\"1\" max=\"1440\"> <small class=\"form-text text-muted\">How often to scan for maintenance tasks (1-1440 minutes). <strong>Default: 30 minutes</strong></small></div><div class=\"mb-3\"><label for=\"workerTimeout\" class=\"form-label\">Worker Timeout (minutes)</label> <input type=\"number\" class=\"form-control\" id=\"workerTimeout\" value=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var3 string
|
var templ_7745c5c3_Var3 string
|
||||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", float64(data.Config.WorkerTimeoutSeconds)/60))
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", float64(data.Config.WorkerTimeoutSeconds)/60))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 59, Col: 111}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 60, Col: 111}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\" min=\"1\" max=\"60\"> <small class=\"form-text text-muted\">How long to wait for worker heartbeat before considering it inactive (1-60 minutes).</small></div><div class=\"mb-3\"><label for=\"taskTimeout\" class=\"form-label\">Task Timeout (hours)</label> <input type=\"number\" class=\"form-control\" id=\"taskTimeout\" value=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\" placeholder=\"5 (default)\" min=\"1\" max=\"60\"> <small class=\"form-text text-muted\">How long to wait for worker heartbeat before considering it inactive (1-60 minutes). <strong>Default: 5 minutes</strong></small></div><div class=\"mb-3\"><label for=\"taskTimeout\" class=\"form-label\">Task Timeout (hours)</label> <input type=\"number\" class=\"form-control\" id=\"taskTimeout\" value=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var4 string
|
var templ_7745c5c3_Var4 string
|
||||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", float64(data.Config.TaskTimeoutSeconds)/3600))
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", float64(data.Config.TaskTimeoutSeconds)/3600))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 68, Col: 111}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 70, Col: 111}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "\" min=\"1\" max=\"24\"> <small class=\"form-text text-muted\">Maximum time allowed for a single task to complete (1-24 hours).</small></div><div class=\"mb-3\"><label for=\"globalMaxConcurrent\" class=\"form-label\">Global Concurrent Limit</label> <input type=\"number\" class=\"form-control\" id=\"globalMaxConcurrent\" value=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "\" placeholder=\"2 (default)\" min=\"1\" max=\"24\"> <small class=\"form-text text-muted\">Maximum time allowed for a single task to complete (1-24 hours). <strong>Default: 2 hours</strong></small></div><div class=\"mb-3\"><label for=\"globalMaxConcurrent\" class=\"form-label\">Global Concurrent Limit</label> <input type=\"number\" class=\"form-control\" id=\"globalMaxConcurrent\" value=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var5 string
|
var templ_7745c5c3_Var5 string
|
||||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.Config.Policy.GlobalMaxConcurrent))
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.Config.Policy.GlobalMaxConcurrent))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 77, Col: 103}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 80, Col: 103}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\" min=\"1\" max=\"20\"> <small class=\"form-text text-muted\">Maximum number of maintenance tasks that can run simultaneously across all workers (1-20).</small></div><div class=\"mb-3\"><label for=\"maxRetries\" class=\"form-label\">Default Max Retries</label> <input type=\"number\" class=\"form-control\" id=\"maxRetries\" value=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\" placeholder=\"4 (default)\" min=\"1\" max=\"20\"> <small class=\"form-text text-muted\">Maximum number of maintenance tasks that can run simultaneously across all workers (1-20). <strong>Default: 4</strong></small></div><div class=\"mb-3\"><label for=\"maxRetries\" class=\"form-label\">Default Max Retries</label> <input type=\"number\" class=\"form-control\" id=\"maxRetries\" value=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var6 string
|
var templ_7745c5c3_Var6 string
|
||||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.Config.MaxRetries))
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.Config.MaxRetries))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 86, Col: 87}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 90, Col: 87}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "\" min=\"0\" max=\"10\"> <small class=\"form-text text-muted\">Default number of times to retry failed tasks (0-10).</small></div><div class=\"mb-3\"><label for=\"retryDelay\" class=\"form-label\">Retry Delay (minutes)</label> <input type=\"number\" class=\"form-control\" id=\"retryDelay\" value=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "\" placeholder=\"3 (default)\" min=\"0\" max=\"10\"> <small class=\"form-text text-muted\">Default number of times to retry failed tasks (0-10). <strong>Default: 3</strong></small></div><div class=\"mb-3\"><label for=\"retryDelay\" class=\"form-label\">Retry Delay (minutes)</label> <input type=\"number\" class=\"form-control\" id=\"retryDelay\" value=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var7 string
|
var templ_7745c5c3_Var7 string
|
||||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", float64(data.Config.RetryDelaySeconds)/60))
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", float64(data.Config.RetryDelaySeconds)/60))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 95, Col: 108}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 100, Col: 108}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" min=\"1\" max=\"120\"> <small class=\"form-text text-muted\">Time to wait before retrying failed tasks (1-120 minutes).</small></div><div class=\"mb-3\"><label for=\"taskRetention\" class=\"form-label\">Task Retention (days)</label> <input type=\"number\" class=\"form-control\" id=\"taskRetention\" value=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" placeholder=\"15 (default)\" min=\"1\" max=\"120\"> <small class=\"form-text text-muted\">Time to wait before retrying failed tasks (1-120 minutes). <strong>Default: 15 minutes</strong></small></div><div class=\"mb-3\"><label for=\"taskRetention\" class=\"form-label\">Task Retention (days)</label> <input type=\"number\" class=\"form-control\" id=\"taskRetention\" value=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var8 string
|
var templ_7745c5c3_Var8 string
|
||||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", float64(data.Config.TaskRetentionSeconds)/(24*3600)))
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", float64(data.Config.TaskRetentionSeconds)/(24*3600)))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 104, Col: 118}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 110, Col: 118}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\" min=\"1\" max=\"30\"> <small class=\"form-text text-muted\">How long to keep completed/failed task records (1-30 days).</small></div><div class=\"d-flex gap-2\"><button type=\"button\" class=\"btn btn-primary\" onclick=\"saveConfiguration()\"><i class=\"fas fa-save me-1\"></i> Save Configuration</button> <button type=\"button\" class=\"btn btn-secondary\" onclick=\"resetToDefaults()\"><i class=\"fas fa-undo me-1\"></i> Reset to Defaults</button></div></form></div></div></div></div><!-- Individual Task Configuration Menu --><div class=\"row mt-4\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"mb-0\"><i class=\"fas fa-cogs me-2\"></i> Task Configuration</h5></div><div class=\"card-body\"><p class=\"text-muted mb-3\">Configure specific settings for each maintenance task type.</p><div class=\"list-group\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\" placeholder=\"7 (default)\" min=\"1\" max=\"30\"> <small class=\"form-text text-muted\">How long to keep completed/failed task records (1-30 days). <strong>Default: 7 days</strong></small></div><div class=\"d-flex gap-2\"><button type=\"button\" class=\"btn btn-primary\" onclick=\"saveConfiguration()\"><i class=\"fas fa-save me-1\"></i> Save Configuration</button> <button type=\"button\" class=\"btn btn-secondary\" onclick=\"resetToDefaults()\"><i class=\"fas fa-undo me-1\"></i> Reset to Defaults</button></div></form></div></div></div></div><!-- Individual Task Configuration Menu --><div class=\"row mt-4\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"mb-0\"><i class=\"fas fa-cogs me-2\"></i> Task Configuration</h5></div><div class=\"card-body\"><p class=\"text-muted mb-3\">Configure specific settings for each maintenance task type.</p><div class=\"list-group\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
|||||||
var templ_7745c5c3_Var9 templ.SafeURL
|
var templ_7745c5c3_Var9 templ.SafeURL
|
||||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(menuItem.Path))
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(menuItem.Path))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 140, Col: 69}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 147, Col: 69}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -182,7 +182,7 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
|||||||
var templ_7745c5c3_Var12 string
|
var templ_7745c5c3_Var12 string
|
||||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(menuItem.DisplayName)
|
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(menuItem.DisplayName)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 144, Col: 65}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 151, Col: 65}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -192,7 +192,7 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if data.Config.Policy.IsTaskEnabled(menuItem.TaskType) {
|
if menuItem.IsEnabled {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "<span class=\"badge bg-success\">Enabled</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "<span class=\"badge bg-success\">Enabled</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
@@ -210,7 +210,7 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
|||||||
var templ_7745c5c3_Var13 string
|
var templ_7745c5c3_Var13 string
|
||||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(menuItem.Description)
|
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(menuItem.Description)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 152, Col: 90}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 159, Col: 90}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -228,7 +228,7 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
|||||||
var templ_7745c5c3_Var14 string
|
var templ_7745c5c3_Var14 string
|
||||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(data.LastScanTime.Format("2006-01-02 15:04:05"))
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(data.LastScanTime.Format("2006-01-02 15:04:05"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 173, Col: 100}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 180, Col: 100}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -241,7 +241,7 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
|||||||
var templ_7745c5c3_Var15 string
|
var templ_7745c5c3_Var15 string
|
||||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(data.NextScanTime.Format("2006-01-02 15:04:05"))
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(data.NextScanTime.Format("2006-01-02 15:04:05"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 179, Col: 100}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 186, Col: 100}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -254,7 +254,7 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
|||||||
var templ_7745c5c3_Var16 string
|
var templ_7745c5c3_Var16 string
|
||||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.SystemStats.TotalTasks))
|
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.SystemStats.TotalTasks))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 185, Col: 99}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 192, Col: 99}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -267,13 +267,13 @@ func MaintenanceConfig(data *maintenance.MaintenanceConfigData) templ.Component
|
|||||||
var templ_7745c5c3_Var17 string
|
var templ_7745c5c3_Var17 string
|
||||||
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.SystemStats.ActiveWorkers))
|
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", data.SystemStats.ActiveWorkers))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 191, Col: 102}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_config.templ`, Line: 198, Col: 102}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</p></div></div></div></div></div></div></div></div><script>\n function saveConfiguration() {\n const config = {\n enabled: document.getElementById('enabled').checked,\n scan_interval_seconds: parseInt(document.getElementById('scanInterval').value) * 60, // Convert to seconds\n policy: {\n vacuum_enabled: document.getElementById('vacuumEnabled').checked,\n vacuum_garbage_ratio: parseFloat(document.getElementById('vacuumGarbageRatio').value) / 100,\n replication_fix_enabled: document.getElementById('replicationFixEnabled').checked,\n }\n };\n\n fetch('/api/maintenance/config', {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(config)\n })\n .then(response => response.json())\n .then(data => {\n if (data.success) {\n alert('Configuration saved successfully');\n } else {\n alert('Failed to save configuration: ' + (data.error || 'Unknown error'));\n }\n })\n .catch(error => {\n alert('Error: ' + error.message);\n });\n }\n\n function resetToDefaults() {\n if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {\n // Reset form to defaults\n document.getElementById('enabled').checked = false;\n document.getElementById('scanInterval').value = '30';\n document.getElementById('vacuumEnabled').checked = false;\n document.getElementById('vacuumGarbageRatio').value = '30';\n document.getElementById('replicationFixEnabled').checked = false;\n }\n }\n </script>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</p></div></div></div></div></div></div></div></div><script>\n function saveConfiguration() {\n // First, get current configuration to preserve existing values\n fetch('/api/maintenance/config')\n .then(response => response.json())\n .then(currentConfig => {\n // Update only the fields from the form\n const updatedConfig = {\n ...currentConfig.config, // Preserve existing config\n enabled: document.getElementById('enabled').checked,\n scan_interval_seconds: parseInt(document.getElementById('scanInterval').value) * 60, // Convert to seconds\n worker_timeout_seconds: parseInt(document.getElementById('workerTimeout').value) * 60, // Convert to seconds\n task_timeout_seconds: parseInt(document.getElementById('taskTimeout').value) * 3600, // Convert to seconds\n retry_delay_seconds: parseInt(document.getElementById('retryDelay').value) * 60, // Convert to seconds\n max_retries: parseInt(document.getElementById('maxRetries').value),\n task_retention_seconds: parseInt(document.getElementById('taskRetention').value) * 24 * 3600, // Convert to seconds\n policy: {\n ...currentConfig.config.policy, // Preserve existing policy\n global_max_concurrent: parseInt(document.getElementById('globalMaxConcurrent').value)\n }\n };\n\n // Send the updated configuration\n return fetch('/api/maintenance/config', {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(updatedConfig)\n });\n })\n .then(response => response.json())\n .then(data => {\n if (data.success) {\n alert('Configuration saved successfully');\n location.reload(); // Reload to show updated values\n } else {\n alert('Failed to save configuration: ' + (data.error || 'Unknown error'));\n }\n })\n .catch(error => {\n alert('Error: ' + error.message);\n });\n }\n\n function resetToDefaults() {\n if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {\n // Reset form to defaults (matching DefaultMaintenanceConfig values)\n document.getElementById('enabled').checked = false;\n document.getElementById('scanInterval').value = '30';\n document.getElementById('workerTimeout').value = '5';\n document.getElementById('taskTimeout').value = '2';\n document.getElementById('globalMaxConcurrent').value = '4';\n document.getElementById('maxRetries').value = '3';\n document.getElementById('retryDelay').value = '15';\n document.getElementById('taskRetention').value = '7';\n }\n }\n </script>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,43 +70,51 @@ templ MaintenanceQueue(data *maintenance.MaintenanceQueueData) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Simple task queue display -->
|
<!-- Pending Tasks -->
|
||||||
<div class="row">
|
<div class="row mb-4">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header bg-primary text-white">
|
||||||
<h5 class="mb-0">Task Queue</h5>
|
<h5 class="mb-0">
|
||||||
|
<i class="fas fa-clock me-2"></i>
|
||||||
|
Pending Tasks
|
||||||
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
if len(data.Tasks) == 0 {
|
if data.Stats.PendingTasks == 0 {
|
||||||
<div class="text-center text-muted py-4">
|
<div class="text-center text-muted py-4">
|
||||||
<i class="fas fa-clipboard-list fa-3x mb-3"></i>
|
<i class="fas fa-clipboard-list fa-3x mb-3"></i>
|
||||||
<p>No maintenance tasks in queue</p>
|
<p>No pending maintenance tasks</p>
|
||||||
<small>Tasks will appear here when the system detects maintenance needs</small>
|
<small>Pending tasks will appear here when the system detects maintenance needs</small>
|
||||||
</div>
|
</div>
|
||||||
} else {
|
} else {
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th>Status</th>
|
<th>Priority</th>
|
||||||
<th>Volume</th>
|
<th>Volume</th>
|
||||||
<th>Server</th>
|
<th>Server</th>
|
||||||
|
<th>Reason</th>
|
||||||
<th>Created</th>
|
<th>Created</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
for _, task := range data.Tasks {
|
for _, task := range data.Tasks {
|
||||||
<tr>
|
if string(task.Status) == "pending" {
|
||||||
<td><code>{task.ID[:8]}...</code></td>
|
<tr>
|
||||||
<td>{string(task.Type)}</td>
|
<td>
|
||||||
<td>{string(task.Status)}</td>
|
@TaskTypeIcon(task.Type)
|
||||||
<td>{fmt.Sprintf("%d", task.VolumeID)}</td>
|
{string(task.Type)}
|
||||||
<td>{task.Server}</td>
|
</td>
|
||||||
<td>{task.CreatedAt.Format("2006-01-02 15:04")}</td>
|
<td>@PriorityBadge(task.Priority)</td>
|
||||||
</tr>
|
<td>{fmt.Sprintf("%d", task.VolumeID)}</td>
|
||||||
|
<td><small>{task.Server}</small></td>
|
||||||
|
<td><small>{task.Reason}</small></td>
|
||||||
|
<td>{task.CreatedAt.Format("2006-01-02 15:04")}</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -117,36 +125,171 @@ templ MaintenanceQueue(data *maintenance.MaintenanceQueueData) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Workers Summary -->
|
<!-- Active Tasks -->
|
||||||
<div class="row mt-4">
|
<div class="row mb-4">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header bg-warning text-dark">
|
||||||
<h5 class="mb-0">Active Workers</h5>
|
<h5 class="mb-0">
|
||||||
|
<i class="fas fa-running me-2"></i>
|
||||||
|
Active Tasks
|
||||||
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
if len(data.Workers) == 0 {
|
if data.Stats.RunningTasks == 0 {
|
||||||
<div class="text-center text-muted py-4">
|
<div class="text-center text-muted py-4">
|
||||||
<i class="fas fa-robot fa-3x mb-3"></i>
|
<i class="fas fa-tasks fa-3x mb-3"></i>
|
||||||
<p>No workers are currently active</p>
|
<p>No active maintenance tasks</p>
|
||||||
<small>Start workers using: <code>weed worker -admin=localhost:9333</code></small>
|
<small>Active tasks will appear here when workers start processing them</small>
|
||||||
</div>
|
</div>
|
||||||
} else {
|
} else {
|
||||||
<div class="row">
|
<div class="table-responsive">
|
||||||
for _, worker := range data.Workers {
|
<table class="table table-hover">
|
||||||
<div class="col-md-4 mb-3">
|
<thead>
|
||||||
<div class="card">
|
<tr>
|
||||||
<div class="card-body">
|
<th>Type</th>
|
||||||
<h6 class="card-title">{worker.ID}</h6>
|
<th>Status</th>
|
||||||
<p class="card-text">
|
<th>Progress</th>
|
||||||
<small class="text-muted">{worker.Address}</small><br/>
|
<th>Volume</th>
|
||||||
Status: {worker.Status}<br/>
|
<th>Worker</th>
|
||||||
Load: {fmt.Sprintf("%d/%d", worker.CurrentLoad, worker.MaxConcurrent)}
|
<th>Started</th>
|
||||||
</p>
|
</tr>
|
||||||
</div>
|
</thead>
|
||||||
</div>
|
<tbody>
|
||||||
</div>
|
for _, task := range data.Tasks {
|
||||||
}
|
if string(task.Status) == "assigned" || string(task.Status) == "in_progress" {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@TaskTypeIcon(task.Type)
|
||||||
|
{string(task.Type)}
|
||||||
|
</td>
|
||||||
|
<td>@StatusBadge(task.Status)</td>
|
||||||
|
<td>@ProgressBar(task.Progress, task.Status)</td>
|
||||||
|
<td>{fmt.Sprintf("%d", task.VolumeID)}</td>
|
||||||
|
<td>
|
||||||
|
if task.WorkerID != "" {
|
||||||
|
<small>{task.WorkerID}</small>
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
if task.StartedAt != nil {
|
||||||
|
{task.StartedAt.Format("2006-01-02 15:04")}
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Completed Tasks -->
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header bg-success text-white">
|
||||||
|
<h5 class="mb-0">
|
||||||
|
<i class="fas fa-check-circle me-2"></i>
|
||||||
|
Completed Tasks
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
if data.Stats.CompletedToday == 0 && data.Stats.FailedToday == 0 {
|
||||||
|
<div class="text-center text-muted py-4">
|
||||||
|
<i class="fas fa-check-circle fa-3x mb-3"></i>
|
||||||
|
<p>No completed maintenance tasks today</p>
|
||||||
|
<small>Completed tasks will appear here after workers finish processing them</small>
|
||||||
|
</div>
|
||||||
|
} else {
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Volume</th>
|
||||||
|
<th>Worker</th>
|
||||||
|
<th>Duration</th>
|
||||||
|
<th>Completed</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
for _, task := range data.Tasks {
|
||||||
|
if string(task.Status) == "completed" || string(task.Status) == "failed" || string(task.Status) == "cancelled" {
|
||||||
|
if string(task.Status) == "failed" {
|
||||||
|
<tr class="table-danger">
|
||||||
|
<td>
|
||||||
|
@TaskTypeIcon(task.Type)
|
||||||
|
{string(task.Type)}
|
||||||
|
</td>
|
||||||
|
<td>@StatusBadge(task.Status)</td>
|
||||||
|
<td>{fmt.Sprintf("%d", task.VolumeID)}</td>
|
||||||
|
<td>
|
||||||
|
if task.WorkerID != "" {
|
||||||
|
<small>{task.WorkerID}</small>
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
if task.StartedAt != nil && task.CompletedAt != nil {
|
||||||
|
{formatDuration(task.CompletedAt.Sub(*task.StartedAt))}
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
if task.CompletedAt != nil {
|
||||||
|
{task.CompletedAt.Format("2006-01-02 15:04")}
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
} else {
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@TaskTypeIcon(task.Type)
|
||||||
|
{string(task.Type)}
|
||||||
|
</td>
|
||||||
|
<td>@StatusBadge(task.Status)</td>
|
||||||
|
<td>{fmt.Sprintf("%d", task.VolumeID)}</td>
|
||||||
|
<td>
|
||||||
|
if task.WorkerID != "" {
|
||||||
|
<small>{task.WorkerID}</small>
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
if task.StartedAt != nil && task.CompletedAt != nil {
|
||||||
|
{formatDuration(task.CompletedAt.Sub(*task.StartedAt))}
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
if task.CompletedAt != nil {
|
||||||
|
{task.CompletedAt.Format("2006-01-02 15:04")}
|
||||||
|
} else {
|
||||||
|
<span class="text-muted">-</span>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@@ -156,6 +299,9 @@ templ MaintenanceQueue(data *maintenance.MaintenanceQueueData) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// Debug output to browser console
|
||||||
|
console.log("DEBUG: Maintenance Queue Template loaded");
|
||||||
|
|
||||||
// Auto-refresh every 10 seconds
|
// Auto-refresh every 10 seconds
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
if (!document.hidden) {
|
if (!document.hidden) {
|
||||||
@@ -163,7 +309,8 @@ templ MaintenanceQueue(data *maintenance.MaintenanceQueueData) {
|
|||||||
}
|
}
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
|
||||||
function triggerScan() {
|
window.triggerScan = function() {
|
||||||
|
console.log("triggerScan called");
|
||||||
fetch('/api/maintenance/scan', {
|
fetch('/api/maintenance/scan', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -182,7 +329,12 @@ templ MaintenanceQueue(data *maintenance.MaintenanceQueueData) {
|
|||||||
.catch(error => {
|
.catch(error => {
|
||||||
alert('Error: ' + error.message);
|
alert('Error: ' + error.message);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
window.refreshPage = function() {
|
||||||
|
console.log("refreshPage called");
|
||||||
|
window.location.reload();
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,32 +395,13 @@ templ ProgressBar(progress float64, status maintenance.MaintenanceTaskStatus) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
templ WorkerStatusBadge(status string) {
|
func formatDuration(d time.Duration) string {
|
||||||
switch status {
|
if d < time.Minute {
|
||||||
case "active":
|
return fmt.Sprintf("%.0fs", d.Seconds())
|
||||||
<span class="badge bg-success">Active</span>
|
} else if d < time.Hour {
|
||||||
case "busy":
|
return fmt.Sprintf("%.1fm", d.Minutes())
|
||||||
<span class="badge bg-warning">Busy</span>
|
} else {
|
||||||
case "inactive":
|
return fmt.Sprintf("%.1fh", d.Hours())
|
||||||
<span class="badge bg-secondary">Inactive</span>
|
|
||||||
default:
|
|
||||||
<span class="badge bg-light text-dark">Unknown</span>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper functions (would be defined in Go)
|
|
||||||
|
|
||||||
|
|
||||||
func getWorkerStatusColor(status string) string {
|
|
||||||
switch status {
|
|
||||||
case "active":
|
|
||||||
return "success"
|
|
||||||
case "busy":
|
|
||||||
return "warning"
|
|
||||||
case "inactive":
|
|
||||||
return "secondary"
|
|
||||||
default:
|
|
||||||
return "light"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,102 +87,103 @@ func MaintenanceQueue(data *maintenance.MaintenanceQueueData) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</h4><p class=\"text-muted mb-0\">Failed Today</p></div></div></div></div><!-- Simple task queue display --><div class=\"row\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"mb-0\">Task Queue</h5></div><div class=\"card-body\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</h4><p class=\"text-muted mb-0\">Failed Today</p></div></div></div></div><!-- Pending Tasks --><div class=\"row mb-4\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header bg-primary text-white\"><h5 class=\"mb-0\"><i class=\"fas fa-clock me-2\"></i> Pending Tasks</h5></div><div class=\"card-body\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if len(data.Tasks) == 0 {
|
if data.Stats.PendingTasks == 0 {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<div class=\"text-center text-muted py-4\"><i class=\"fas fa-clipboard-list fa-3x mb-3\"></i><p>No maintenance tasks in queue</p><small>Tasks will appear here when the system detects maintenance needs</small></div>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<div class=\"text-center text-muted py-4\"><i class=\"fas fa-clipboard-list fa-3x mb-3\"></i><p>No pending maintenance tasks</p><small>Pending tasks will appear here when the system detects maintenance needs</small></div>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<div class=\"table-responsive\"><table class=\"table table-hover\"><thead><tr><th>ID</th><th>Type</th><th>Status</th><th>Volume</th><th>Server</th><th>Created</th></tr></thead> <tbody>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<div class=\"table-responsive\"><table class=\"table table-hover\"><thead><tr><th>Type</th><th>Priority</th><th>Volume</th><th>Server</th><th>Reason</th><th>Created</th></tr></thead> <tbody>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
for _, task := range data.Tasks {
|
for _, task := range data.Tasks {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<tr><td><code>")
|
if string(task.Status) == "pending" {
|
||||||
if templ_7745c5c3_Err != nil {
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<tr><td>")
|
||||||
return templ_7745c5c3_Err
|
if templ_7745c5c3_Err != nil {
|
||||||
}
|
return templ_7745c5c3_Err
|
||||||
var templ_7745c5c3_Var6 string
|
}
|
||||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(task.ID[:8])
|
templ_7745c5c3_Err = TaskTypeIcon(task.Type).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 103, Col: 70}
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
var templ_7745c5c3_Var6 string
|
||||||
if templ_7745c5c3_Err != nil {
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(string(task.Type))
|
||||||
return templ_7745c5c3_Err
|
if templ_7745c5c3_Err != nil {
|
||||||
}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 109, Col: 74}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "...</code></td><td>")
|
}
|
||||||
if templ_7745c5c3_Err != nil {
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
return templ_7745c5c3_Err
|
if templ_7745c5c3_Err != nil {
|
||||||
}
|
return templ_7745c5c3_Err
|
||||||
var templ_7745c5c3_Var7 string
|
}
|
||||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(string(task.Type))
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</td><td>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 104, Col: 70}
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
templ_7745c5c3_Err = PriorityBadge(task.Priority).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "</td><td>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "</td><td>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var8 string
|
var templ_7745c5c3_Var7 string
|
||||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(string(task.Status))
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", task.VolumeID))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 105, Col: 72}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 112, Col: 89}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</td><td>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</td><td><small>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var9 string
|
var templ_7745c5c3_Var8 string
|
||||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", task.VolumeID))
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(task.Server)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 106, Col: 85}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 113, Col: 75}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</td><td>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</small></td><td><small>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var10 string
|
var templ_7745c5c3_Var9 string
|
||||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(task.Server)
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(task.Reason)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 107, Col: 64}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 114, Col: 75}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</td><td>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</small></td><td>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var11 string
|
var templ_7745c5c3_Var10 string
|
||||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(task.CreatedAt.Format("2006-01-02 15:04"))
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(task.CreatedAt.Format("2006-01-02 15:04"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 108, Col: 94}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 115, Col: 98}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</td></tr>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</td></tr>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</tbody></table></div>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</tbody></table></div>")
|
||||||
@@ -190,84 +191,374 @@ func MaintenanceQueue(data *maintenance.MaintenanceQueueData) templ.Component {
|
|||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</div></div></div></div><!-- Workers Summary --><div class=\"row mt-4\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"mb-0\">Active Workers</h5></div><div class=\"card-body\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</div></div></div></div><!-- Active Tasks --><div class=\"row mb-4\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header bg-warning text-dark\"><h5 class=\"mb-0\"><i class=\"fas fa-running me-2\"></i> Active Tasks</h5></div><div class=\"card-body\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if len(data.Workers) == 0 {
|
if data.Stats.RunningTasks == 0 {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<div class=\"text-center text-muted py-4\"><i class=\"fas fa-robot fa-3x mb-3\"></i><p>No workers are currently active</p><small>Start workers using: <code>weed worker -admin=localhost:9333</code></small></div>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<div class=\"text-center text-muted py-4\"><i class=\"fas fa-tasks fa-3x mb-3\"></i><p>No active maintenance tasks</p><small>Active tasks will appear here when workers start processing them</small></div>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<div class=\"row\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<div class=\"table-responsive\"><table class=\"table table-hover\"><thead><tr><th>Type</th><th>Status</th><th>Progress</th><th>Volume</th><th>Worker</th><th>Started</th></tr></thead> <tbody>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
for _, worker := range data.Workers {
|
for _, task := range data.Tasks {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<div class=\"col-md-4 mb-3\"><div class=\"card\"><div class=\"card-body\"><h6 class=\"card-title\">")
|
if string(task.Status) == "assigned" || string(task.Status) == "in_progress" {
|
||||||
if templ_7745c5c3_Err != nil {
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<tr><td>")
|
||||||
return templ_7745c5c3_Err
|
if templ_7745c5c3_Err != nil {
|
||||||
}
|
return templ_7745c5c3_Err
|
||||||
var templ_7745c5c3_Var12 string
|
}
|
||||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(worker.ID)
|
templ_7745c5c3_Err = TaskTypeIcon(task.Type).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 140, Col: 81}
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
var templ_7745c5c3_Var11 string
|
||||||
if templ_7745c5c3_Err != nil {
|
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(string(task.Type))
|
||||||
return templ_7745c5c3_Err
|
if templ_7745c5c3_Err != nil {
|
||||||
}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 164, Col: 74}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</h6><p class=\"card-text\"><small class=\"text-muted\">")
|
}
|
||||||
if templ_7745c5c3_Err != nil {
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||||
return templ_7745c5c3_Err
|
if templ_7745c5c3_Err != nil {
|
||||||
}
|
return templ_7745c5c3_Err
|
||||||
var templ_7745c5c3_Var13 string
|
}
|
||||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(worker.Address)
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</td><td>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 142, Col: 93}
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
templ_7745c5c3_Err = StatusBadge(task.Status).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</small><br>Status: ")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</td><td>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var14 string
|
templ_7745c5c3_Err = ProgressBar(task.Progress, task.Status).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(worker.Status)
|
if templ_7745c5c3_Err != nil {
|
||||||
if templ_7745c5c3_Err != nil {
|
return templ_7745c5c3_Err
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 143, Col: 74}
|
}
|
||||||
}
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "</td><td>")
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
if templ_7745c5c3_Err != nil {
|
||||||
if templ_7745c5c3_Err != nil {
|
return templ_7745c5c3_Err
|
||||||
return templ_7745c5c3_Err
|
}
|
||||||
}
|
var templ_7745c5c3_Var12 string
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "<br>Load: ")
|
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", task.VolumeID))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 168, Col: 89}
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var15 string
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d/%d", worker.CurrentLoad, worker.MaxConcurrent))
|
if templ_7745c5c3_Err != nil {
|
||||||
if templ_7745c5c3_Err != nil {
|
return templ_7745c5c3_Err
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 144, Col: 121}
|
}
|
||||||
}
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "</td><td>")
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
if templ_7745c5c3_Err != nil {
|
||||||
if templ_7745c5c3_Err != nil {
|
return templ_7745c5c3_Err
|
||||||
return templ_7745c5c3_Err
|
}
|
||||||
}
|
if task.WorkerID != "" {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "</p></div></div></div>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "<small>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var13 string
|
||||||
|
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(task.WorkerID)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 171, Col: 81}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</small>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<span class=\"text-muted\">-</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if task.StartedAt != nil {
|
||||||
|
var templ_7745c5c3_Var14 string
|
||||||
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(task.StartedAt.Format("2006-01-02 15:04"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 178, Col: 102}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<span class=\"text-muted\">-</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "</td></tr>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</div>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "</tbody></table></div>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</div></div></div></div></div><script>\n // Auto-refresh every 10 seconds\n setInterval(function() {\n if (!document.hidden) {\n window.location.reload();\n }\n }, 10000);\n\n function triggerScan() {\n fetch('/api/maintenance/scan', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n }\n })\n .then(response => response.json())\n .then(data => {\n if (data.success) {\n alert('Maintenance scan triggered successfully');\n setTimeout(() => window.location.reload(), 2000);\n } else {\n alert('Failed to trigger scan: ' + (data.error || 'Unknown error'));\n }\n })\n .catch(error => {\n alert('Error: ' + error.message);\n });\n }\n </script>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "</div></div></div></div><!-- Completed Tasks --><div class=\"row mb-4\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header bg-success text-white\"><h5 class=\"mb-0\"><i class=\"fas fa-check-circle me-2\"></i> Completed Tasks</h5></div><div class=\"card-body\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.Stats.CompletedToday == 0 && data.Stats.FailedToday == 0 {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<div class=\"text-center text-muted py-4\"><i class=\"fas fa-check-circle fa-3x mb-3\"></i><p>No completed maintenance tasks today</p><small>Completed tasks will appear here after workers finish processing them</small></div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "<div class=\"table-responsive\"><table class=\"table table-hover\"><thead><tr><th>Type</th><th>Status</th><th>Volume</th><th>Worker</th><th>Duration</th><th>Completed</th></tr></thead> <tbody>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, task := range data.Tasks {
|
||||||
|
if string(task.Status) == "completed" || string(task.Status) == "failed" || string(task.Status) == "cancelled" {
|
||||||
|
if string(task.Status) == "failed" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "<tr class=\"table-danger\"><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = TaskTypeIcon(task.Type).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var15 string
|
||||||
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(string(task.Type))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 232, Col: 78}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = StatusBadge(task.Status).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var16 string
|
||||||
|
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", task.VolumeID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 235, Col: 93}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if task.WorkerID != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "<small>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var17 string
|
||||||
|
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(task.WorkerID)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 238, Col: 85}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "</small>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "<span class=\"text-muted\">-</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if task.StartedAt != nil && task.CompletedAt != nil {
|
||||||
|
var templ_7745c5c3_Var18 string
|
||||||
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(formatDuration(task.CompletedAt.Sub(*task.StartedAt)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 245, Col: 118}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "<span class=\"text-muted\">-</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if task.CompletedAt != nil {
|
||||||
|
var templ_7745c5c3_Var19 string
|
||||||
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(task.CompletedAt.Format("2006-01-02 15:04"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 252, Col: 108}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "<span class=\"text-muted\">-</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "</td></tr>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "<tr><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = TaskTypeIcon(task.Type).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var20 string
|
||||||
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(string(task.Type))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 262, Col: 78}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = StatusBadge(task.Status).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var21 string
|
||||||
|
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", task.VolumeID))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 265, Col: 93}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if task.WorkerID != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "<small>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var22 string
|
||||||
|
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(task.WorkerID)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 268, Col: 85}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "</small>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "<span class=\"text-muted\">-</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if task.StartedAt != nil && task.CompletedAt != nil {
|
||||||
|
var templ_7745c5c3_Var23 string
|
||||||
|
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(formatDuration(task.CompletedAt.Sub(*task.StartedAt)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 275, Col: 118}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "<span class=\"text-muted\">-</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "</td><td>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if task.CompletedAt != nil {
|
||||||
|
var templ_7745c5c3_Var24 string
|
||||||
|
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(task.CompletedAt.Format("2006-01-02 15:04"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 282, Col: 108}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "<span class=\"text-muted\">-</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "</td></tr>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "</tbody></table></div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "</div></div></div></div></div><script>\n // Debug output to browser console\n console.log(\"DEBUG: Maintenance Queue Template loaded\");\n \n // Auto-refresh every 10 seconds\n setInterval(function() {\n if (!document.hidden) {\n window.location.reload();\n }\n }, 10000);\n\n window.triggerScan = function() {\n console.log(\"triggerScan called\");\n fetch('/api/maintenance/scan', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n }\n })\n .then(response => response.json())\n .then(data => {\n if (data.success) {\n alert('Maintenance scan triggered successfully');\n setTimeout(() => window.location.reload(), 2000);\n } else {\n alert('Failed to trigger scan: ' + (data.error || 'Unknown error'));\n }\n })\n .catch(error => {\n alert('Error: ' + error.message);\n });\n };\n\n window.refreshPage = function() {\n console.log(\"refreshPage called\");\n window.location.reload();\n };\n </script>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -292,30 +583,30 @@ func TaskTypeIcon(taskType maintenance.MaintenanceTaskType) templ.Component {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
ctx = templ.InitializeContext(ctx)
|
ctx = templ.InitializeContext(ctx)
|
||||||
templ_7745c5c3_Var16 := templ.GetChildren(ctx)
|
templ_7745c5c3_Var25 := templ.GetChildren(ctx)
|
||||||
if templ_7745c5c3_Var16 == nil {
|
if templ_7745c5c3_Var25 == nil {
|
||||||
templ_7745c5c3_Var16 = templ.NopComponent
|
templ_7745c5c3_Var25 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
var templ_7745c5c3_Var17 = []any{maintenance.GetTaskIcon(taskType) + " me-1"}
|
var templ_7745c5c3_Var26 = []any{maintenance.GetTaskIcon(taskType) + " me-1"}
|
||||||
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var17...)
|
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var26...)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<i class=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "<i class=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var18 string
|
var templ_7745c5c3_Var27 string
|
||||||
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var17).String())
|
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var26).String())
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 1, Col: 0}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 1, Col: 0}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\"></i>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "\"></i>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -339,34 +630,34 @@ func PriorityBadge(priority maintenance.MaintenanceTaskPriority) templ.Component
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
ctx = templ.InitializeContext(ctx)
|
ctx = templ.InitializeContext(ctx)
|
||||||
templ_7745c5c3_Var19 := templ.GetChildren(ctx)
|
templ_7745c5c3_Var28 := templ.GetChildren(ctx)
|
||||||
if templ_7745c5c3_Var19 == nil {
|
if templ_7745c5c3_Var28 == nil {
|
||||||
templ_7745c5c3_Var19 = templ.NopComponent
|
templ_7745c5c3_Var28 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
switch priority {
|
switch priority {
|
||||||
case maintenance.PriorityCritical:
|
case maintenance.PriorityCritical:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<span class=\"badge bg-danger\">Critical</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "<span class=\"badge bg-danger\">Critical</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
case maintenance.PriorityHigh:
|
case maintenance.PriorityHigh:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "<span class=\"badge bg-warning\">High</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "<span class=\"badge bg-warning\">High</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
case maintenance.PriorityNormal:
|
case maintenance.PriorityNormal:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "<span class=\"badge bg-primary\">Normal</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "<span class=\"badge bg-primary\">Normal</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
case maintenance.PriorityLow:
|
case maintenance.PriorityLow:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "<span class=\"badge bg-secondary\">Low</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "<span class=\"badge bg-secondary\">Low</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<span class=\"badge bg-light text-dark\">Unknown</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "<span class=\"badge bg-light text-dark\">Unknown</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -391,44 +682,44 @@ func StatusBadge(status maintenance.MaintenanceTaskStatus) templ.Component {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
ctx = templ.InitializeContext(ctx)
|
ctx = templ.InitializeContext(ctx)
|
||||||
templ_7745c5c3_Var20 := templ.GetChildren(ctx)
|
templ_7745c5c3_Var29 := templ.GetChildren(ctx)
|
||||||
if templ_7745c5c3_Var20 == nil {
|
if templ_7745c5c3_Var29 == nil {
|
||||||
templ_7745c5c3_Var20 = templ.NopComponent
|
templ_7745c5c3_Var29 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
switch status {
|
switch status {
|
||||||
case maintenance.TaskStatusPending:
|
case maintenance.TaskStatusPending:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "<span class=\"badge bg-secondary\">Pending</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "<span class=\"badge bg-secondary\">Pending</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
case maintenance.TaskStatusAssigned:
|
case maintenance.TaskStatusAssigned:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "<span class=\"badge bg-info\">Assigned</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "<span class=\"badge bg-info\">Assigned</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
case maintenance.TaskStatusInProgress:
|
case maintenance.TaskStatusInProgress:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "<span class=\"badge bg-warning\">Running</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "<span class=\"badge bg-warning\">Running</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
case maintenance.TaskStatusCompleted:
|
case maintenance.TaskStatusCompleted:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "<span class=\"badge bg-success\">Completed</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "<span class=\"badge bg-success\">Completed</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
case maintenance.TaskStatusFailed:
|
case maintenance.TaskStatusFailed:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "<span class=\"badge bg-danger\">Failed</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "<span class=\"badge bg-danger\">Failed</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
case maintenance.TaskStatusCancelled:
|
case maintenance.TaskStatusCancelled:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "<span class=\"badge bg-light text-dark\">Cancelled</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 72, "<span class=\"badge bg-light text-dark\">Cancelled</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "<span class=\"badge bg-light text-dark\">Unknown</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 73, "<span class=\"badge bg-light text-dark\">Unknown</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -453,49 +744,49 @@ func ProgressBar(progress float64, status maintenance.MaintenanceTaskStatus) tem
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
ctx = templ.InitializeContext(ctx)
|
ctx = templ.InitializeContext(ctx)
|
||||||
templ_7745c5c3_Var21 := templ.GetChildren(ctx)
|
templ_7745c5c3_Var30 := templ.GetChildren(ctx)
|
||||||
if templ_7745c5c3_Var21 == nil {
|
if templ_7745c5c3_Var30 == nil {
|
||||||
templ_7745c5c3_Var21 = templ.NopComponent
|
templ_7745c5c3_Var30 = templ.NopComponent
|
||||||
}
|
}
|
||||||
ctx = templ.ClearChildren(ctx)
|
ctx = templ.ClearChildren(ctx)
|
||||||
if status == maintenance.TaskStatusInProgress || status == maintenance.TaskStatusAssigned {
|
if status == maintenance.TaskStatusInProgress || status == maintenance.TaskStatusAssigned {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "<div class=\"progress\" style=\"height: 8px; min-width: 100px;\"><div class=\"progress-bar\" role=\"progressbar\" style=\"")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, "<div class=\"progress\" style=\"height: 8px; min-width: 100px;\"><div class=\"progress-bar\" role=\"progressbar\" style=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var22 string
|
var templ_7745c5c3_Var31 string
|
||||||
templ_7745c5c3_Var22, templ_7745c5c3_Err = templruntime.SanitizeStyleAttributeValues(fmt.Sprintf("width: %.1f%%", progress))
|
templ_7745c5c3_Var31, templ_7745c5c3_Err = templruntime.SanitizeStyleAttributeValues(fmt.Sprintf("width: %.1f%%", progress))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 231, Col: 102}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 383, Col: 102}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "\"></div></div><small class=\"text-muted\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 75, "\"></div></div><small class=\"text-muted\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var23 string
|
var templ_7745c5c3_Var32 string
|
||||||
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.1f%%", progress))
|
templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.1f%%", progress))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 234, Col: 66}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/maintenance_queue.templ`, Line: 386, Col: 66}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "</small>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 76, "</small>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
} else if status == maintenance.TaskStatusCompleted {
|
} else if status == maintenance.TaskStatusCompleted {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "<div class=\"progress\" style=\"height: 8px; min-width: 100px;\"><div class=\"progress-bar bg-success\" role=\"progressbar\" style=\"width: 100%\"></div></div><small class=\"text-success\">100%</small>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "<div class=\"progress\" style=\"height: 8px; min-width: 100px;\"><div class=\"progress-bar bg-success\" role=\"progressbar\" style=\"width: 100%\"></div></div><small class=\"text-success\">100%</small>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "<span class=\"text-muted\">-</span>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 78, "<span class=\"text-muted\">-</span>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -504,65 +795,13 @@ func ProgressBar(progress float64, status maintenance.MaintenanceTaskStatus) tem
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func WorkerStatusBadge(status string) templ.Component {
|
func formatDuration(d time.Duration) string {
|
||||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
if d < time.Minute {
|
||||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
return fmt.Sprintf("%.0fs", d.Seconds())
|
||||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
} else if d < time.Hour {
|
||||||
return templ_7745c5c3_CtxErr
|
return fmt.Sprintf("%.1fm", d.Minutes())
|
||||||
}
|
} else {
|
||||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
return fmt.Sprintf("%.1fh", d.Hours())
|
||||||
if !templ_7745c5c3_IsBuffer {
|
|
||||||
defer func() {
|
|
||||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
||||||
if templ_7745c5c3_Err == nil {
|
|
||||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
ctx = templ.InitializeContext(ctx)
|
|
||||||
templ_7745c5c3_Var24 := templ.GetChildren(ctx)
|
|
||||||
if templ_7745c5c3_Var24 == nil {
|
|
||||||
templ_7745c5c3_Var24 = templ.NopComponent
|
|
||||||
}
|
|
||||||
ctx = templ.ClearChildren(ctx)
|
|
||||||
switch status {
|
|
||||||
case "active":
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "<span class=\"badge bg-success\">Active</span>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
case "busy":
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "<span class=\"badge bg-warning\">Busy</span>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
case "inactive":
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "<span class=\"badge bg-secondary\">Inactive</span>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "<span class=\"badge bg-light text-dark\">Unknown</span>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
|
||||||
return templ_7745c5c3_Err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper functions (would be defined in Go)
|
|
||||||
|
|
||||||
func getWorkerStatusColor(status string) string {
|
|
||||||
switch status {
|
|
||||||
case "active":
|
|
||||||
return "success"
|
|
||||||
case "busy":
|
|
||||||
return "warning"
|
|
||||||
case "inactive":
|
|
||||||
return "secondary"
|
|
||||||
default:
|
|
||||||
return "light"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,396 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/maintenance"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
templ TaskConfigSchema(data *maintenance.TaskConfigData, schema *tasks.TaskConfigSchema, config interface{}) {
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row mb-4">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<h2 class="mb-0">
|
||||||
|
<i class={schema.Icon + " me-2"}></i>
|
||||||
|
{schema.DisplayName} Configuration
|
||||||
|
</h2>
|
||||||
|
<div class="btn-group">
|
||||||
|
<a href="/maintenance/config" class="btn btn-outline-secondary">
|
||||||
|
<i class="fas fa-arrow-left me-1"></i>
|
||||||
|
Back to System Config
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="mb-0">{schema.DisplayName} Settings</h5>
|
||||||
|
<p class="mb-0 text-muted">{schema.Description}</p>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form id="taskConfigForm" method="POST">
|
||||||
|
<!-- Dynamically render all schema fields in defined order -->
|
||||||
|
for _, field := range schema.Fields {
|
||||||
|
@TaskConfigField(field, getTaskFieldValue(config, field.JSONName))
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="d-flex gap-2">
|
||||||
|
<button type="submit" class="btn btn-primary">
|
||||||
|
<i class="fas fa-save me-1"></i>
|
||||||
|
Save Configuration
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-secondary" onclick="resetToDefaults()">
|
||||||
|
<i class="fas fa-undo me-1"></i>
|
||||||
|
Reset to Defaults
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Performance Notes Card -->
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="mb-0">
|
||||||
|
<i class="fas fa-info-circle me-2"></i>
|
||||||
|
Important Notes
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="alert alert-info" role="alert">
|
||||||
|
if schema.TaskName == "vacuum" {
|
||||||
|
<h6 class="alert-heading">Vacuum Operations:</h6>
|
||||||
|
<p class="mb-2"><strong>Performance:</strong> Vacuum operations are I/O intensive and may impact cluster performance.</p>
|
||||||
|
<p class="mb-2"><strong>Safety:</strong> Only volumes meeting age and garbage thresholds will be processed.</p>
|
||||||
|
<p class="mb-0"><strong>Recommendation:</strong> Monitor cluster load and adjust concurrent limits accordingly.</p>
|
||||||
|
} else if schema.TaskName == "balance" {
|
||||||
|
<h6 class="alert-heading">Balance Operations:</h6>
|
||||||
|
<p class="mb-2"><strong>Performance:</strong> Volume balancing involves data movement and can impact cluster performance.</p>
|
||||||
|
<p class="mb-2"><strong>Safety:</strong> Requires adequate server count to ensure data safety during moves.</p>
|
||||||
|
<p class="mb-0"><strong>Recommendation:</strong> Run during off-peak hours to minimize impact on production workloads.</p>
|
||||||
|
} else if schema.TaskName == "erasure_coding" {
|
||||||
|
<h6 class="alert-heading">Erasure Coding Operations:</h6>
|
||||||
|
<p class="mb-2"><strong>Performance:</strong> Erasure coding is CPU and I/O intensive. Consider running during off-peak hours.</p>
|
||||||
|
<p class="mb-2"><strong>Durability:</strong> With 10+4 configuration, can tolerate up to 4 shard failures.</p>
|
||||||
|
<p class="mb-0"><strong>Configuration:</strong> Fullness ratio should be between 0.5 and 1.0 (e.g., 0.90 for 90%).</p>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function resetToDefaults() {
|
||||||
|
if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {
|
||||||
|
// Reset form fields to their default values
|
||||||
|
const form = document.getElementById('taskConfigForm');
|
||||||
|
const schemaFields = window.taskConfigSchema ? window.taskConfigSchema.fields : {};
|
||||||
|
|
||||||
|
Object.keys(schemaFields).forEach(fieldName => {
|
||||||
|
const field = schemaFields[fieldName];
|
||||||
|
const element = document.getElementById(fieldName);
|
||||||
|
|
||||||
|
if (element && field.default_value !== undefined) {
|
||||||
|
if (field.input_type === 'checkbox') {
|
||||||
|
element.checked = field.default_value;
|
||||||
|
} else if (field.input_type === 'interval') {
|
||||||
|
// Handle interval fields with value and unit
|
||||||
|
const valueElement = document.getElementById(fieldName + '_value');
|
||||||
|
const unitElement = document.getElementById(fieldName + '_unit');
|
||||||
|
if (valueElement && unitElement && field.default_value) {
|
||||||
|
const defaultSeconds = field.default_value;
|
||||||
|
const { value, unit } = convertSecondsToTaskIntervalValueUnit(defaultSeconds);
|
||||||
|
valueElement.value = value;
|
||||||
|
unitElement.value = unit;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
element.value = field.default_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertSecondsToTaskIntervalValueUnit(totalSeconds) {
|
||||||
|
if (totalSeconds === 0) {
|
||||||
|
return { value: 0, unit: 'minutes' };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if (totalSeconds % (24 * 3600) === 0) {
|
||||||
|
return { value: totalSeconds / (24 * 3600), unit: 'days' };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if (totalSeconds % 3600 === 0) {
|
||||||
|
return { value: totalSeconds / 3600, unit: 'hours' };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return { value: totalSeconds / 60, unit: 'minutes' };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store schema data for JavaScript access
|
||||||
|
window.taskConfigSchema = @taskSchemaToTaskJSON(schema);
|
||||||
|
</script>
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskConfigField renders a single task configuration field based on schema
|
||||||
|
templ TaskConfigField(field *config.Field, value interface{}) {
|
||||||
|
if field.InputType == "interval" {
|
||||||
|
<!-- Interval field with number input + unit dropdown -->
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for={ field.JSONName } class="form-label">
|
||||||
|
{ field.DisplayName }
|
||||||
|
if field.Required {
|
||||||
|
<span class="text-danger">*</span>
|
||||||
|
}
|
||||||
|
</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
class="form-control"
|
||||||
|
id={ field.JSONName + "_value" }
|
||||||
|
name={ field.JSONName + "_value" }
|
||||||
|
value={ fmt.Sprintf("%.0f", convertTaskSecondsToDisplayValue(value, field)) }
|
||||||
|
step="1"
|
||||||
|
min="1"
|
||||||
|
if field.Required {
|
||||||
|
required
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<select
|
||||||
|
class="form-select"
|
||||||
|
id={ field.JSONName + "_unit" }
|
||||||
|
name={ field.JSONName + "_unit" }
|
||||||
|
style="max-width: 120px;"
|
||||||
|
if field.Required {
|
||||||
|
required
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
value="minutes"
|
||||||
|
if getTaskDisplayUnit(value, field) == "minutes" {
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Minutes
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="hours"
|
||||||
|
if getTaskDisplayUnit(value, field) == "hours" {
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Hours
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="days"
|
||||||
|
if getTaskDisplayUnit(value, field) == "days" {
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Days
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
if field.Description != "" {
|
||||||
|
<div class="form-text text-muted">{ field.Description }</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
} else if field.InputType == "checkbox" {
|
||||||
|
<!-- Checkbox field -->
|
||||||
|
<div class="mb-3">
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input
|
||||||
|
class="form-check-input"
|
||||||
|
type="checkbox"
|
||||||
|
id={ field.JSONName }
|
||||||
|
name={ field.JSONName }
|
||||||
|
if getTaskBoolValue(value) {
|
||||||
|
checked
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<label class="form-check-label" for={ field.JSONName }>
|
||||||
|
<strong>{ field.DisplayName }</strong>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
if field.Description != "" {
|
||||||
|
<div class="form-text text-muted">{ field.Description }</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
} else if field.InputType == "text" {
|
||||||
|
<!-- Text field -->
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for={ field.JSONName } class="form-label">
|
||||||
|
{ field.DisplayName }
|
||||||
|
if field.Required {
|
||||||
|
<span class="text-danger">*</span>
|
||||||
|
}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="form-control"
|
||||||
|
id={ field.JSONName }
|
||||||
|
name={ field.JSONName }
|
||||||
|
value={ fmt.Sprintf("%v", value) }
|
||||||
|
placeholder={ field.Placeholder }
|
||||||
|
if field.Required {
|
||||||
|
required
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
if field.Description != "" {
|
||||||
|
<div class="form-text text-muted">{ field.Description }</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
} else {
|
||||||
|
<!-- Number field -->
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for={ field.JSONName } class="form-label">
|
||||||
|
{ field.DisplayName }
|
||||||
|
if field.Required {
|
||||||
|
<span class="text-danger">*</span>
|
||||||
|
}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
class="form-control"
|
||||||
|
id={ field.JSONName }
|
||||||
|
name={ field.JSONName }
|
||||||
|
value={ fmt.Sprintf("%v", value) }
|
||||||
|
placeholder={ field.Placeholder }
|
||||||
|
if field.MinValue != nil {
|
||||||
|
min={ fmt.Sprintf("%v", field.MinValue) }
|
||||||
|
}
|
||||||
|
if field.MaxValue != nil {
|
||||||
|
max={ fmt.Sprintf("%v", field.MaxValue) }
|
||||||
|
}
|
||||||
|
step={ getTaskNumberStep(field) }
|
||||||
|
if field.Required {
|
||||||
|
required
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
if field.Description != "" {
|
||||||
|
<div class="form-text text-muted">{ field.Description }</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper functions for the template
|
||||||
|
func getTaskBoolValue(value interface{}) bool {
|
||||||
|
if boolVal, ok := value.(bool); ok {
|
||||||
|
return boolVal
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertTaskSecondsToDisplayValue(value interface{}, field *config.Field) float64 {
|
||||||
|
if intVal, ok := value.(int); ok {
|
||||||
|
if intVal == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if intVal%(24*3600) == 0 {
|
||||||
|
return float64(intVal / (24 * 3600))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if intVal%3600 == 0 {
|
||||||
|
return float64(intVal / 3600)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return float64(intVal / 60)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTaskDisplayUnit(value interface{}, field *config.Field) string {
|
||||||
|
if intVal, ok := value.(int); ok {
|
||||||
|
if intVal == 0 {
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if intVal%(24*3600) == 0 {
|
||||||
|
return "days"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if intVal%3600 == 0 {
|
||||||
|
return "hours"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTaskNumberStep(field *config.Field) string {
|
||||||
|
if field.Type == config.FieldTypeFloat {
|
||||||
|
return "0.01"
|
||||||
|
}
|
||||||
|
return "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTaskFieldValue(config interface{}, fieldName string) interface{} {
|
||||||
|
if config == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use reflection to get the field value from the config struct
|
||||||
|
configValue := reflect.ValueOf(config)
|
||||||
|
if configValue.Kind() == reflect.Ptr {
|
||||||
|
configValue = configValue.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if configValue.Kind() != reflect.Struct {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
configType := configValue.Type()
|
||||||
|
|
||||||
|
for i := 0; i < configValue.NumField(); i++ {
|
||||||
|
field := configValue.Field(i)
|
||||||
|
fieldType := configType.Field(i)
|
||||||
|
|
||||||
|
// Get JSON tag name
|
||||||
|
jsonTag := fieldType.Tag.Get("json")
|
||||||
|
if jsonTag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove options like ",omitempty"
|
||||||
|
if commaIdx := strings.Index(jsonTag, ","); commaIdx > 0 {
|
||||||
|
jsonTag = jsonTag[:commaIdx]
|
||||||
|
}
|
||||||
|
|
||||||
|
if jsonTag == fieldName {
|
||||||
|
return field.Interface()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to convert schema to JSON for JavaScript
|
||||||
|
templ taskSchemaToTaskJSON(schema *tasks.TaskConfigSchema) {
|
||||||
|
{`{}`}
|
||||||
|
}
|
||||||
@@ -0,0 +1,877 @@
|
|||||||
|
// Code generated by templ - DO NOT EDIT.
|
||||||
|
|
||||||
|
// templ: version: v0.3.906
|
||||||
|
package app
|
||||||
|
|
||||||
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||||
|
|
||||||
|
import "github.com/a-h/templ"
|
||||||
|
import templruntime "github.com/a-h/templ/runtime"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/maintenance"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TaskConfigSchema(data *maintenance.TaskConfigData, schema *tasks.TaskConfigSchema, config interface{}) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var1 == nil {
|
||||||
|
templ_7745c5c3_Var1 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"container-fluid\"><div class=\"row mb-4\"><div class=\"col-12\"><div class=\"d-flex justify-content-between align-items-center\"><h2 class=\"mb-0\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var2 = []any{schema.Icon + " me-2"}
|
||||||
|
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var2...)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<i class=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var3 string
|
||||||
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var2).String())
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 1, Col: 0}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\"></i> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var4 string
|
||||||
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(schema.DisplayName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 19, Col: 43}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, " Configuration</h2><div class=\"btn-group\"><a href=\"/maintenance/config\" class=\"btn btn-outline-secondary\"><i class=\"fas fa-arrow-left me-1\"></i> Back to System Config</a></div></div></div></div><div class=\"row\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"mb-0\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var5 string
|
||||||
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(schema.DisplayName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 35, Col: 60}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, " Settings</h5><p class=\"mb-0 text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var6 string
|
||||||
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(schema.Description)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 36, Col: 70}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</p></div><div class=\"card-body\"><form id=\"taskConfigForm\" method=\"POST\"><!-- Dynamically render all schema fields in defined order -->")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
for _, field := range schema.Fields {
|
||||||
|
templ_7745c5c3_Err = TaskConfigField(field, getTaskFieldValue(config, field.JSONName)).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "<div class=\"d-flex gap-2\"><button type=\"submit\" class=\"btn btn-primary\"><i class=\"fas fa-save me-1\"></i> Save Configuration</button> <button type=\"button\" class=\"btn btn-secondary\" onclick=\"resetToDefaults()\"><i class=\"fas fa-undo me-1\"></i> Reset to Defaults</button></div></form></div></div></div></div><!-- Performance Notes Card --><div class=\"row mt-4\"><div class=\"col-12\"><div class=\"card\"><div class=\"card-header\"><h5 class=\"mb-0\"><i class=\"fas fa-info-circle me-2\"></i> Important Notes</h5></div><div class=\"card-body\"><div class=\"alert alert-info\" role=\"alert\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if schema.TaskName == "vacuum" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<h6 class=\"alert-heading\">Vacuum Operations:</h6><p class=\"mb-2\"><strong>Performance:</strong> Vacuum operations are I/O intensive and may impact cluster performance.</p><p class=\"mb-2\"><strong>Safety:</strong> Only volumes meeting age and garbage thresholds will be processed.</p><p class=\"mb-0\"><strong>Recommendation:</strong> Monitor cluster load and adjust concurrent limits accordingly.</p>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else if schema.TaskName == "balance" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<h6 class=\"alert-heading\">Balance Operations:</h6><p class=\"mb-2\"><strong>Performance:</strong> Volume balancing involves data movement and can impact cluster performance.</p><p class=\"mb-2\"><strong>Safety:</strong> Requires adequate server count to ensure data safety during moves.</p><p class=\"mb-0\"><strong>Recommendation:</strong> Run during off-peak hours to minimize impact on production workloads.</p>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else if schema.TaskName == "erasure_coding" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<h6 class=\"alert-heading\">Erasure Coding Operations:</h6><p class=\"mb-2\"><strong>Performance:</strong> Erasure coding is CPU and I/O intensive. Consider running during off-peak hours.</p><p class=\"mb-2\"><strong>Durability:</strong> With 10+4 configuration, can tolerate up to 4 shard failures.</p><p class=\"mb-0\"><strong>Configuration:</strong> Fullness ratio should be between 0.5 and 1.0 (e.g., 0.90 for 90%).</p>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</div></div></div></div></div></div><script>\n function resetToDefaults() {\n if (confirm('Are you sure you want to reset to default configuration? This will overwrite your current settings.')) {\n // Reset form fields to their default values\n const form = document.getElementById('taskConfigForm');\n const schemaFields = window.taskConfigSchema ? window.taskConfigSchema.fields : {};\n \n Object.keys(schemaFields).forEach(fieldName => {\n const field = schemaFields[fieldName];\n const element = document.getElementById(fieldName);\n \n if (element && field.default_value !== undefined) {\n if (field.input_type === 'checkbox') {\n element.checked = field.default_value;\n } else if (field.input_type === 'interval') {\n // Handle interval fields with value and unit\n const valueElement = document.getElementById(fieldName + '_value');\n const unitElement = document.getElementById(fieldName + '_unit');\n if (valueElement && unitElement && field.default_value) {\n const defaultSeconds = field.default_value;\n const { value, unit } = convertSecondsToTaskIntervalValueUnit(defaultSeconds);\n valueElement.value = value;\n unitElement.value = unit;\n }\n } else {\n element.value = field.default_value;\n }\n }\n });\n }\n }\n\n function convertSecondsToTaskIntervalValueUnit(totalSeconds) {\n if (totalSeconds === 0) {\n return { value: 0, unit: 'minutes' };\n }\n\n // Check if it's evenly divisible by days\n if (totalSeconds % (24 * 3600) === 0) {\n return { value: totalSeconds / (24 * 3600), unit: 'days' };\n }\n\n // Check if it's evenly divisible by hours\n if (totalSeconds % 3600 === 0) {\n return { value: totalSeconds / 3600, unit: 'hours' };\n }\n\n // Default to minutes\n return { value: totalSeconds / 60, unit: 'minutes' };\n }\n\n // Store schema data for JavaScript access\n window.taskConfigSchema = @taskSchemaToTaskJSON(schema);\n </script>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskConfigField renders a single task configuration field based on schema
|
||||||
|
func TaskConfigField(field *config.Field, value interface{}) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var7 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var7 == nil {
|
||||||
|
templ_7745c5c3_Var7 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
if field.InputType == "interval" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<!-- Interval field with number input + unit dropdown --> <div class=\"mb-3\"><label for=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var8 string
|
||||||
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 157, Col: 39}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "\" class=\"form-label\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var9 string
|
||||||
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(field.DisplayName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 158, Col: 35}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, " ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<span class=\"text-danger\">*</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</label><div class=\"input-group\"><input type=\"number\" class=\"form-control\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var10 string
|
||||||
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName + "_value")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 167, Col: 50}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var11 string
|
||||||
|
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName + "_value")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 168, Col: 52}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "\" value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var12 string
|
||||||
|
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", convertTaskSecondsToDisplayValue(value, field)))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 169, Col: 95}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "\" step=\"1\" min=\"1\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, " required")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "> <select class=\"form-select\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var13 string
|
||||||
|
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName + "_unit")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 178, Col: 49}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var14 string
|
||||||
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName + "_unit")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 179, Col: 51}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "\" style=\"max-width: 120px;\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, " required")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "><option value=\"minutes\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if getTaskDisplayUnit(value, field) == "minutes" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, ">Minutes</option> <option value=\"hours\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if getTaskDisplayUnit(value, field) == "hours" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, ">Hours</option> <option value=\"days\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if getTaskDisplayUnit(value, field) == "days" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, ">Days</option></select></div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Description != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<div class=\"form-text text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var15 string
|
||||||
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(field.Description)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 212, Col: 69}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else if field.InputType == "checkbox" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "<!-- Checkbox field --> <div class=\"mb-3\"><div class=\"form-check form-switch\"><input class=\"form-check-input\" type=\"checkbox\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var16 string
|
||||||
|
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 222, Col: 39}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var17 string
|
||||||
|
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 223, Col: 41}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if getTaskBoolValue(value) {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, " checked")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "> <label class=\"form-check-label\" for=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var18 string
|
||||||
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 228, Col: 68}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "\"><strong>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var19 string
|
||||||
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(field.DisplayName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 229, Col: 47}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "</strong></label></div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Description != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "<div class=\"form-text text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var20 string
|
||||||
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(field.Description)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 233, Col: 69}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else if field.InputType == "text" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "<!-- Text field --> <div class=\"mb-3\"><label for=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var21 string
|
||||||
|
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 239, Col: 39}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "\" class=\"form-label\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var22 string
|
||||||
|
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(field.DisplayName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 240, Col: 35}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, " ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "<span class=\"text-danger\">*</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "</label> <input type=\"text\" class=\"form-control\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var23 string
|
||||||
|
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 248, Col: 35}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var24 string
|
||||||
|
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 249, Col: 37}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "\" value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var25 string
|
||||||
|
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%v", value))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 250, Col: 48}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "\" placeholder=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var26 string
|
||||||
|
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(field.Placeholder)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 251, Col: 47}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, " required")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Description != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "<div class=\"form-text text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var27 string
|
||||||
|
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(field.Description)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 257, Col: 69}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "<!-- Number field --> <div class=\"mb-3\"><label for=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var28 string
|
||||||
|
templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 263, Col: 39}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "\" class=\"form-label\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var29 string
|
||||||
|
templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(field.DisplayName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 264, Col: 35}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, " ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "<span class=\"text-danger\">*</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "</label> <input type=\"number\" class=\"form-control\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var30 string
|
||||||
|
templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 272, Col: 35}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var31 string
|
||||||
|
templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(field.JSONName)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 273, Col: 37}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "\" value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var32 string
|
||||||
|
templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%v", value))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 274, Col: 48}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "\" placeholder=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var33 string
|
||||||
|
templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(field.Placeholder)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 275, Col: 47}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.MinValue != nil {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, " min=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var34 string
|
||||||
|
templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%v", field.MinValue))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 277, Col: 59}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if field.MaxValue != nil {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, " max=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var35 string
|
||||||
|
templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%v", field.MaxValue))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 280, Col: 59}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 72, " step=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var36 string
|
||||||
|
templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(getTaskNumberStep(field))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 282, Col: 47}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 73, "\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, " required")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 75, "> ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if field.Description != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 76, "<div class=\"form-text text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var37 string
|
||||||
|
templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(field.Description)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 288, Col: 69}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 78, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper functions for the template
|
||||||
|
func getTaskBoolValue(value interface{}) bool {
|
||||||
|
if boolVal, ok := value.(bool); ok {
|
||||||
|
return boolVal
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertTaskSecondsToDisplayValue(value interface{}, field *config.Field) float64 {
|
||||||
|
if intVal, ok := value.(int); ok {
|
||||||
|
if intVal == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if intVal%(24*3600) == 0 {
|
||||||
|
return float64(intVal / (24 * 3600))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if intVal%3600 == 0 {
|
||||||
|
return float64(intVal / 3600)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return float64(intVal / 60)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTaskDisplayUnit(value interface{}, field *config.Field) string {
|
||||||
|
if intVal, ok := value.(int); ok {
|
||||||
|
if intVal == 0 {
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if intVal%(24*3600) == 0 {
|
||||||
|
return "days"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if intVal%3600 == 0 {
|
||||||
|
return "hours"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
return "minutes"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTaskNumberStep(field *config.Field) string {
|
||||||
|
if field.Type == config.FieldTypeFloat {
|
||||||
|
return "0.01"
|
||||||
|
}
|
||||||
|
return "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTaskFieldValue(config interface{}, fieldName string) interface{} {
|
||||||
|
if config == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use reflection to get the field value from the config struct
|
||||||
|
configValue := reflect.ValueOf(config)
|
||||||
|
if configValue.Kind() == reflect.Ptr {
|
||||||
|
configValue = configValue.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if configValue.Kind() != reflect.Struct {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
configType := configValue.Type()
|
||||||
|
|
||||||
|
for i := 0; i < configValue.NumField(); i++ {
|
||||||
|
field := configValue.Field(i)
|
||||||
|
fieldType := configType.Field(i)
|
||||||
|
|
||||||
|
// Get JSON tag name
|
||||||
|
jsonTag := fieldType.Tag.Get("json")
|
||||||
|
if jsonTag == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove options like ",omitempty"
|
||||||
|
if commaIdx := strings.Index(jsonTag, ","); commaIdx > 0 {
|
||||||
|
jsonTag = jsonTag[:commaIdx]
|
||||||
|
}
|
||||||
|
|
||||||
|
if jsonTag == fieldName {
|
||||||
|
return field.Interface()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to convert schema to JSON for JavaScript
|
||||||
|
func taskSchemaToTaskJSON(schema *tasks.TaskConfigSchema) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var38 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var38 == nil {
|
||||||
|
templ_7745c5c3_Var38 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
var templ_7745c5c3_Var39 string
|
||||||
|
templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(`{}`)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/task_config_schema.templ`, Line: 395, Col: 9}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var39))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = templruntime.GeneratedTemplate
|
||||||
@@ -303,4 +303,73 @@ func convertSecondsToValue(seconds int, unit string) float64 {
|
|||||||
default:
|
default:
|
||||||
return float64(seconds / 60) // Default to minutes
|
return float64(seconds / 60) // Default to minutes
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntervalFieldData represents interval input field data with separate value and unit
|
||||||
|
type IntervalFieldData struct {
|
||||||
|
FormFieldData
|
||||||
|
Seconds int // The interval value in seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntervalField renders a Bootstrap interval input with number + unit dropdown (like task config)
|
||||||
|
templ IntervalField(data IntervalFieldData) {
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for={ data.Name } class="form-label">
|
||||||
|
{ data.Label }
|
||||||
|
if data.Required {
|
||||||
|
<span class="text-danger">*</span>
|
||||||
|
}
|
||||||
|
</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
class="form-control"
|
||||||
|
id={ data.Name + "_value" }
|
||||||
|
name={ data.Name + "_value" }
|
||||||
|
value={ fmt.Sprintf("%.0f", convertSecondsToValue(data.Seconds, convertSecondsToUnit(data.Seconds))) }
|
||||||
|
step="1"
|
||||||
|
min="1"
|
||||||
|
if data.Required {
|
||||||
|
required
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<select
|
||||||
|
class="form-select"
|
||||||
|
id={ data.Name + "_unit" }
|
||||||
|
name={ data.Name + "_unit" }
|
||||||
|
style="max-width: 120px;"
|
||||||
|
if data.Required {
|
||||||
|
required
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
value="minutes"
|
||||||
|
if convertSecondsToUnit(data.Seconds) == "minutes" {
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Minutes
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="hours"
|
||||||
|
if convertSecondsToUnit(data.Seconds) == "hours" {
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Hours
|
||||||
|
</option>
|
||||||
|
<option
|
||||||
|
value="days"
|
||||||
|
if convertSecondsToUnit(data.Seconds) == "days" {
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Days
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
if data.Description != "" {
|
||||||
|
<div class="form-text text-muted">{ data.Description }</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
@@ -1101,4 +1101,214 @@ func convertSecondsToValue(seconds int, unit string) float64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IntervalFieldData represents interval input field data with separate value and unit
|
||||||
|
type IntervalFieldData struct {
|
||||||
|
FormFieldData
|
||||||
|
Seconds int // The interval value in seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntervalField renders a Bootstrap interval input with number + unit dropdown (like task config)
|
||||||
|
func IntervalField(data IntervalFieldData) templ.Component {
|
||||||
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||||
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||||
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||||
|
return templ_7745c5c3_CtxErr
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||||
|
if !templ_7745c5c3_IsBuffer {
|
||||||
|
defer func() {
|
||||||
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err == nil {
|
||||||
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
ctx = templ.InitializeContext(ctx)
|
||||||
|
templ_7745c5c3_Var50 := templ.GetChildren(ctx)
|
||||||
|
if templ_7745c5c3_Var50 == nil {
|
||||||
|
templ_7745c5c3_Var50 = templ.NopComponent
|
||||||
|
}
|
||||||
|
ctx = templ.ClearChildren(ctx)
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 101, "<div class=\"mb-3\"><label for=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var51 string
|
||||||
|
templ_7745c5c3_Var51, templ_7745c5c3_Err = templ.JoinStringErrs(data.Name)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/components/form_fields.templ`, Line: 317, Col: 24}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var51))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 102, "\" class=\"form-label\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var52 string
|
||||||
|
templ_7745c5c3_Var52, templ_7745c5c3_Err = templ.JoinStringErrs(data.Label)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/components/form_fields.templ`, Line: 318, Col: 15}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var52))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 103, " ")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 104, "<span class=\"text-danger\">*</span>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 105, "</label><div class=\"input-group\"><input type=\"number\" class=\"form-control\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var53 string
|
||||||
|
templ_7745c5c3_Var53, templ_7745c5c3_Err = templ.JoinStringErrs(data.Name + "_value")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/components/form_fields.templ`, Line: 327, Col: 29}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var53))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 106, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var54 string
|
||||||
|
templ_7745c5c3_Var54, templ_7745c5c3_Err = templ.JoinStringErrs(data.Name + "_value")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/components/form_fields.templ`, Line: 328, Col: 31}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var54))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 107, "\" value=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var55 string
|
||||||
|
templ_7745c5c3_Var55, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f", convertSecondsToValue(data.Seconds, convertSecondsToUnit(data.Seconds))))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/components/form_fields.templ`, Line: 329, Col: 104}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var55))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 108, "\" step=\"1\" min=\"1\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 109, " required")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 110, "> <select class=\"form-select\" id=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var56 string
|
||||||
|
templ_7745c5c3_Var56, templ_7745c5c3_Err = templ.JoinStringErrs(data.Name + "_unit")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/components/form_fields.templ`, Line: 338, Col: 28}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var56))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 111, "\" name=\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var57 string
|
||||||
|
templ_7745c5c3_Var57, templ_7745c5c3_Err = templ.JoinStringErrs(data.Name + "_unit")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/components/form_fields.templ`, Line: 339, Col: 30}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var57))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 112, "\" style=\"max-width: 120px;\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.Required {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 113, " required")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 114, "><option value=\"minutes\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if convertSecondsToUnit(data.Seconds) == "minutes" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 115, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 116, ">Minutes</option> <option value=\"hours\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if convertSecondsToUnit(data.Seconds) == "hours" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 117, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 118, ">Hours</option> <option value=\"days\"")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if convertSecondsToUnit(data.Seconds) == "days" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 119, " selected")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 120, ">Days</option></select></div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
if data.Description != "" {
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 121, "<div class=\"form-text text-muted\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var58 string
|
||||||
|
templ_7745c5c3_Var58, templ_7745c5c3_Err = templ.JoinStringErrs(data.Description)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/components/form_fields.templ`, Line: 372, Col: 55}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var58))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 122, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 123, "</div>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var _ = templruntime.GeneratedTemplate
|
var _ = templruntime.GeneratedTemplate
|
||||||
@@ -111,6 +111,11 @@ templ Layout(c *gin.Context, content templ.Component) {
|
|||||||
<i class="fas fa-database me-2"></i>Volumes
|
<i class="fas fa-database me-2"></i>Volumes
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link py-2" href="/cluster/ec-shards">
|
||||||
|
<i class="fas fa-th-large me-2"></i>EC Volumes
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link py-2" href="/cluster/collections">
|
<a class="nav-link py-2" href="/cluster/collections">
|
||||||
<i class="fas fa-layer-group me-2"></i>Collections
|
<i class="fas fa-layer-group me-2"></i>Collections
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func Layout(c *gin.Context, content templ.Component) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</a><ul class=\"dropdown-menu\"><li><a class=\"dropdown-item\" href=\"/logout\"><i class=\"fas fa-sign-out-alt me-2\"></i>Logout</a></li></ul></li></ul></div></div></header><div class=\"row g-0\"><!-- Sidebar --><div class=\"col-md-3 col-lg-2 d-md-block bg-light sidebar collapse\"><div class=\"position-sticky pt-3\"><h6 class=\"sidebar-heading px-3 mt-4 mb-1 text-muted\"><span>MAIN</span></h6><ul class=\"nav flex-column\"><li class=\"nav-item\"><a class=\"nav-link\" href=\"/admin\"><i class=\"fas fa-tachometer-alt me-2\"></i>Dashboard</a></li><li class=\"nav-item\"><a class=\"nav-link collapsed\" href=\"#\" data-bs-toggle=\"collapse\" data-bs-target=\"#clusterSubmenu\" aria-expanded=\"false\" aria-controls=\"clusterSubmenu\"><i class=\"fas fa-sitemap me-2\"></i>Cluster <i class=\"fas fa-chevron-down ms-auto\"></i></a><div class=\"collapse\" id=\"clusterSubmenu\"><ul class=\"nav flex-column ms-3\"><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/masters\"><i class=\"fas fa-crown me-2\"></i>Masters</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/volume-servers\"><i class=\"fas fa-server me-2\"></i>Volume Servers</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/filers\"><i class=\"fas fa-folder-open me-2\"></i>Filers</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/volumes\"><i class=\"fas fa-database me-2\"></i>Volumes</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/collections\"><i class=\"fas fa-layer-group me-2\"></i>Collections</a></li></ul></div></li></ul><h6 class=\"sidebar-heading px-3 mt-4 mb-1 text-muted\"><span>MANAGEMENT</span></h6><ul class=\"nav flex-column\"><li class=\"nav-item\"><a class=\"nav-link\" href=\"/files\"><i class=\"fas fa-folder me-2\"></i>File Browser</a></li><li class=\"nav-item\"><a class=\"nav-link collapsed\" href=\"#\" data-bs-toggle=\"collapse\" data-bs-target=\"#objectStoreSubmenu\" aria-expanded=\"false\" aria-controls=\"objectStoreSubmenu\"><i class=\"fas fa-cloud me-2\"></i>Object Store <i class=\"fas fa-chevron-down ms-auto\"></i></a><div class=\"collapse\" id=\"objectStoreSubmenu\"><ul class=\"nav flex-column ms-3\"><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/object-store/buckets\"><i class=\"fas fa-cube me-2\"></i>Buckets</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/object-store/users\"><i class=\"fas fa-users me-2\"></i>Users</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/object-store/policies\"><i class=\"fas fa-shield-alt me-2\"></i>Policies</a></li></ul></div></li><li class=\"nav-item\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</a><ul class=\"dropdown-menu\"><li><a class=\"dropdown-item\" href=\"/logout\"><i class=\"fas fa-sign-out-alt me-2\"></i>Logout</a></li></ul></li></ul></div></div></header><div class=\"row g-0\"><!-- Sidebar --><div class=\"col-md-3 col-lg-2 d-md-block bg-light sidebar collapse\"><div class=\"position-sticky pt-3\"><h6 class=\"sidebar-heading px-3 mt-4 mb-1 text-muted\"><span>MAIN</span></h6><ul class=\"nav flex-column\"><li class=\"nav-item\"><a class=\"nav-link\" href=\"/admin\"><i class=\"fas fa-tachometer-alt me-2\"></i>Dashboard</a></li><li class=\"nav-item\"><a class=\"nav-link collapsed\" href=\"#\" data-bs-toggle=\"collapse\" data-bs-target=\"#clusterSubmenu\" aria-expanded=\"false\" aria-controls=\"clusterSubmenu\"><i class=\"fas fa-sitemap me-2\"></i>Cluster <i class=\"fas fa-chevron-down ms-auto\"></i></a><div class=\"collapse\" id=\"clusterSubmenu\"><ul class=\"nav flex-column ms-3\"><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/masters\"><i class=\"fas fa-crown me-2\"></i>Masters</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/volume-servers\"><i class=\"fas fa-server me-2\"></i>Volume Servers</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/filers\"><i class=\"fas fa-folder-open me-2\"></i>Filers</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/volumes\"><i class=\"fas fa-database me-2\"></i>Volumes</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/ec-shards\"><i class=\"fas fa-th-large me-2\"></i>EC Volumes</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/cluster/collections\"><i class=\"fas fa-layer-group me-2\"></i>Collections</a></li></ul></div></li></ul><h6 class=\"sidebar-heading px-3 mt-4 mb-1 text-muted\"><span>MANAGEMENT</span></h6><ul class=\"nav flex-column\"><li class=\"nav-item\"><a class=\"nav-link\" href=\"/files\"><i class=\"fas fa-folder me-2\"></i>File Browser</a></li><li class=\"nav-item\"><a class=\"nav-link collapsed\" href=\"#\" data-bs-toggle=\"collapse\" data-bs-target=\"#objectStoreSubmenu\" aria-expanded=\"false\" aria-controls=\"objectStoreSubmenu\"><i class=\"fas fa-cloud me-2\"></i>Object Store <i class=\"fas fa-chevron-down ms-auto\"></i></a><div class=\"collapse\" id=\"objectStoreSubmenu\"><ul class=\"nav flex-column ms-3\"><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/object-store/buckets\"><i class=\"fas fa-cube me-2\"></i>Buckets</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/object-store/users\"><i class=\"fas fa-users me-2\"></i>Users</a></li><li class=\"nav-item\"><a class=\"nav-link py-2\" href=\"/object-store/policies\"><i class=\"fas fa-shield-alt me-2\"></i>Policies</a></li></ul></div></li><li class=\"nav-item\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ func Layout(c *gin.Context, content templ.Component) templ.Component {
|
|||||||
var templ_7745c5c3_Var3 templ.SafeURL
|
var templ_7745c5c3_Var3 templ.SafeURL
|
||||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(menuItem.URL))
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(menuItem.URL))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 253, Col: 117}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 258, Col: 117}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -188,7 +188,7 @@ func Layout(c *gin.Context, content templ.Component) templ.Component {
|
|||||||
var templ_7745c5c3_Var6 string
|
var templ_7745c5c3_Var6 string
|
||||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(menuItem.Name)
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(menuItem.Name)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 254, Col: 109}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 259, Col: 109}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -206,7 +206,7 @@ func Layout(c *gin.Context, content templ.Component) templ.Component {
|
|||||||
var templ_7745c5c3_Var7 templ.SafeURL
|
var templ_7745c5c3_Var7 templ.SafeURL
|
||||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(menuItem.URL))
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(menuItem.URL))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 257, Col: 110}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 262, Col: 110}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -241,7 +241,7 @@ func Layout(c *gin.Context, content templ.Component) templ.Component {
|
|||||||
var templ_7745c5c3_Var10 string
|
var templ_7745c5c3_Var10 string
|
||||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(menuItem.Name)
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(menuItem.Name)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 258, Col: 109}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 263, Col: 109}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -274,7 +274,7 @@ func Layout(c *gin.Context, content templ.Component) templ.Component {
|
|||||||
var templ_7745c5c3_Var11 templ.SafeURL
|
var templ_7745c5c3_Var11 templ.SafeURL
|
||||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(menuItem.URL))
|
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(menuItem.URL))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 270, Col: 106}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 275, Col: 106}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -309,7 +309,7 @@ func Layout(c *gin.Context, content templ.Component) templ.Component {
|
|||||||
var templ_7745c5c3_Var14 string
|
var templ_7745c5c3_Var14 string
|
||||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(menuItem.Name)
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(menuItem.Name)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 271, Col: 105}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 276, Col: 105}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -370,7 +370,7 @@ func Layout(c *gin.Context, content templ.Component) templ.Component {
|
|||||||
var templ_7745c5c3_Var15 string
|
var templ_7745c5c3_Var15 string
|
||||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", time.Now().Year()))
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", time.Now().Year()))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 318, Col: 60}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 323, Col: 60}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -383,7 +383,7 @@ func Layout(c *gin.Context, content templ.Component) templ.Component {
|
|||||||
var templ_7745c5c3_Var16 string
|
var templ_7745c5c3_Var16 string
|
||||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(version.VERSION_NUMBER)
|
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(version.VERSION_NUMBER)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 318, Col: 102}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 323, Col: 102}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -435,7 +435,7 @@ func LoginForm(c *gin.Context, title string, errorMessage string) templ.Componen
|
|||||||
var templ_7745c5c3_Var18 string
|
var templ_7745c5c3_Var18 string
|
||||||
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(title)
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(title)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 342, Col: 17}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 347, Col: 17}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -448,7 +448,7 @@ func LoginForm(c *gin.Context, title string, errorMessage string) templ.Componen
|
|||||||
var templ_7745c5c3_Var19 string
|
var templ_7745c5c3_Var19 string
|
||||||
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(title)
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(title)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 356, Col: 57}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 361, Col: 57}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -466,7 +466,7 @@ func LoginForm(c *gin.Context, title string, errorMessage string) templ.Componen
|
|||||||
var templ_7745c5c3_Var20 string
|
var templ_7745c5c3_Var20 string
|
||||||
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(errorMessage)
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(errorMessage)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 363, Col: 45}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/layout/layout.templ`, Line: 368, Col: 45}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
|
|||||||
+13
-4
@@ -33,6 +33,7 @@ var (
|
|||||||
|
|
||||||
type AdminOptions struct {
|
type AdminOptions struct {
|
||||||
port *int
|
port *int
|
||||||
|
grpcPort *int
|
||||||
masters *string
|
masters *string
|
||||||
adminUser *string
|
adminUser *string
|
||||||
adminPassword *string
|
adminPassword *string
|
||||||
@@ -42,6 +43,7 @@ type AdminOptions struct {
|
|||||||
func init() {
|
func init() {
|
||||||
cmdAdmin.Run = runAdmin // break init cycle
|
cmdAdmin.Run = runAdmin // break init cycle
|
||||||
a.port = cmdAdmin.Flag.Int("port", 23646, "admin server port")
|
a.port = cmdAdmin.Flag.Int("port", 23646, "admin server port")
|
||||||
|
a.grpcPort = cmdAdmin.Flag.Int("port.grpc", 0, "gRPC server port for worker connections (default: http port + 10000)")
|
||||||
a.masters = cmdAdmin.Flag.String("masters", "localhost:9333", "comma-separated master servers")
|
a.masters = cmdAdmin.Flag.String("masters", "localhost:9333", "comma-separated master servers")
|
||||||
a.dataDir = cmdAdmin.Flag.String("dataDir", "", "directory to store admin configuration and data files")
|
a.dataDir = cmdAdmin.Flag.String("dataDir", "", "directory to store admin configuration and data files")
|
||||||
|
|
||||||
@@ -50,7 +52,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cmdAdmin = &Command{
|
var cmdAdmin = &Command{
|
||||||
UsageLine: "admin -port=23646 -masters=localhost:9333 [-dataDir=/path/to/data]",
|
UsageLine: "admin -port=23646 -masters=localhost:9333 [-port.grpc=33646] [-dataDir=/path/to/data]",
|
||||||
Short: "start SeaweedFS web admin interface",
|
Short: "start SeaweedFS web admin interface",
|
||||||
Long: `Start a web admin interface for SeaweedFS cluster management.
|
Long: `Start a web admin interface for SeaweedFS cluster management.
|
||||||
|
|
||||||
@@ -63,12 +65,13 @@ var cmdAdmin = &Command{
|
|||||||
- Maintenance operations
|
- Maintenance operations
|
||||||
|
|
||||||
The admin interface automatically discovers filers from the master servers.
|
The admin interface automatically discovers filers from the master servers.
|
||||||
A gRPC server for worker connections runs on HTTP port + 10000.
|
A gRPC server for worker connections runs on the configured gRPC port (default: HTTP port + 10000).
|
||||||
|
|
||||||
Example Usage:
|
Example Usage:
|
||||||
weed admin -port=23646 -masters="master1:9333,master2:9333"
|
weed admin -port=23646 -masters="master1:9333,master2:9333"
|
||||||
weed admin -port=23646 -masters="localhost:9333" -dataDir="/var/lib/seaweedfs-admin"
|
weed admin -port=23646 -masters="localhost:9333" -dataDir="/var/lib/seaweedfs-admin"
|
||||||
weed admin -port=23646 -masters="localhost:9333" -dataDir="~/seaweedfs-admin"
|
weed admin -port=23646 -port.grpc=33646 -masters="localhost:9333" -dataDir="~/seaweedfs-admin"
|
||||||
|
weed admin -port=9900 -port.grpc=19900 -masters="localhost:9333"
|
||||||
|
|
||||||
Data Directory:
|
Data Directory:
|
||||||
- If dataDir is specified, admin configuration and maintenance data is persisted
|
- If dataDir is specified, admin configuration and maintenance data is persisted
|
||||||
@@ -128,6 +131,11 @@ func runAdmin(cmd *Command, args []string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set default gRPC port if not specified
|
||||||
|
if *a.grpcPort == 0 {
|
||||||
|
*a.grpcPort = *a.port + 10000
|
||||||
|
}
|
||||||
|
|
||||||
// Security warnings
|
// Security warnings
|
||||||
if *a.adminPassword == "" {
|
if *a.adminPassword == "" {
|
||||||
fmt.Println("WARNING: Admin interface is running without authentication!")
|
fmt.Println("WARNING: Admin interface is running without authentication!")
|
||||||
@@ -135,6 +143,7 @@ func runAdmin(cmd *Command, args []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Starting SeaweedFS Admin Interface on port %d\n", *a.port)
|
fmt.Printf("Starting SeaweedFS Admin Interface on port %d\n", *a.port)
|
||||||
|
fmt.Printf("Worker gRPC server will run on port %d\n", *a.grpcPort)
|
||||||
fmt.Printf("Masters: %s\n", *a.masters)
|
fmt.Printf("Masters: %s\n", *a.masters)
|
||||||
fmt.Printf("Filers will be discovered automatically from masters\n")
|
fmt.Printf("Filers will be discovered automatically from masters\n")
|
||||||
if *a.dataDir != "" {
|
if *a.dataDir != "" {
|
||||||
@@ -232,7 +241,7 @@ func startAdminServer(ctx context.Context, options AdminOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start worker gRPC server for worker connections
|
// Start worker gRPC server for worker connections
|
||||||
err = adminServer.StartWorkerGrpcServer(*options.port)
|
err = adminServer.StartWorkerGrpcServer(*options.grpcPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to start worker gRPC server: %w", err)
|
return fmt.Errorf("failed to start worker gRPC server: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+52
-5
@@ -3,6 +3,7 @@ package command
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@@ -21,7 +22,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var cmdWorker = &Command{
|
var cmdWorker = &Command{
|
||||||
UsageLine: "worker -admin=<admin_server> [-capabilities=<task_types>] [-maxConcurrent=<num>]",
|
UsageLine: "worker -admin=<admin_server> [-capabilities=<task_types>] [-maxConcurrent=<num>] [-workingDir=<path>]",
|
||||||
Short: "start a maintenance worker to process cluster maintenance tasks",
|
Short: "start a maintenance worker to process cluster maintenance tasks",
|
||||||
Long: `Start a maintenance worker that connects to an admin server to process
|
Long: `Start a maintenance worker that connects to an admin server to process
|
||||||
maintenance tasks like vacuum, erasure coding, remote upload, and replication fixes.
|
maintenance tasks like vacuum, erasure coding, remote upload, and replication fixes.
|
||||||
@@ -34,6 +35,7 @@ Examples:
|
|||||||
weed worker -admin=admin.example.com:23646
|
weed worker -admin=admin.example.com:23646
|
||||||
weed worker -admin=localhost:23646 -capabilities=vacuum,replication
|
weed worker -admin=localhost:23646 -capabilities=vacuum,replication
|
||||||
weed worker -admin=localhost:23646 -maxConcurrent=4
|
weed worker -admin=localhost:23646 -maxConcurrent=4
|
||||||
|
weed worker -admin=localhost:23646 -workingDir=/tmp/worker
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +45,7 @@ var (
|
|||||||
workerMaxConcurrent = cmdWorker.Flag.Int("maxConcurrent", 2, "maximum number of concurrent tasks")
|
workerMaxConcurrent = cmdWorker.Flag.Int("maxConcurrent", 2, "maximum number of concurrent tasks")
|
||||||
workerHeartbeatInterval = cmdWorker.Flag.Duration("heartbeat", 30*time.Second, "heartbeat interval")
|
workerHeartbeatInterval = cmdWorker.Flag.Duration("heartbeat", 30*time.Second, "heartbeat interval")
|
||||||
workerTaskRequestInterval = cmdWorker.Flag.Duration("taskInterval", 5*time.Second, "task request interval")
|
workerTaskRequestInterval = cmdWorker.Flag.Duration("taskInterval", 5*time.Second, "task request interval")
|
||||||
|
workerWorkingDir = cmdWorker.Flag.String("workingDir", "", "working directory for the worker")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -67,6 +70,36 @@ func runWorker(cmd *Command, args []string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set working directory and create task-specific subdirectories
|
||||||
|
var baseWorkingDir string
|
||||||
|
if *workerWorkingDir != "" {
|
||||||
|
glog.Infof("Setting working directory to: %s", *workerWorkingDir)
|
||||||
|
if err := os.Chdir(*workerWorkingDir); err != nil {
|
||||||
|
glog.Fatalf("Failed to change working directory: %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalf("Failed to get working directory: %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
baseWorkingDir = wd
|
||||||
|
glog.Infof("Current working directory: %s", baseWorkingDir)
|
||||||
|
|
||||||
|
// Create task-specific subdirectories
|
||||||
|
for _, capability := range capabilities {
|
||||||
|
taskDir := filepath.Join(baseWorkingDir, string(capability))
|
||||||
|
if err := os.MkdirAll(taskDir, 0755); err != nil {
|
||||||
|
glog.Fatalf("Failed to create task directory %s: %v", taskDir, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
glog.Infof("Created task directory: %s", taskDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create gRPC dial option using TLS configuration
|
||||||
|
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.worker")
|
||||||
|
|
||||||
// Create worker configuration
|
// Create worker configuration
|
||||||
config := &types.WorkerConfig{
|
config := &types.WorkerConfig{
|
||||||
AdminServer: *workerAdminServer,
|
AdminServer: *workerAdminServer,
|
||||||
@@ -74,6 +107,8 @@ func runWorker(cmd *Command, args []string) bool {
|
|||||||
MaxConcurrent: *workerMaxConcurrent,
|
MaxConcurrent: *workerMaxConcurrent,
|
||||||
HeartbeatInterval: *workerHeartbeatInterval,
|
HeartbeatInterval: *workerHeartbeatInterval,
|
||||||
TaskRequestInterval: *workerTaskRequestInterval,
|
TaskRequestInterval: *workerTaskRequestInterval,
|
||||||
|
BaseWorkingDir: baseWorkingDir,
|
||||||
|
GrpcDialOption: grpcDialOption,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create worker instance
|
// Create worker instance
|
||||||
@@ -82,9 +117,6 @@ func runWorker(cmd *Command, args []string) bool {
|
|||||||
glog.Fatalf("Failed to create worker: %v", err)
|
glog.Fatalf("Failed to create worker: %v", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create admin client with LoadClientTLS
|
|
||||||
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.worker")
|
|
||||||
adminClient, err := worker.CreateAdminClient(*workerAdminServer, workerInstance.ID(), grpcDialOption)
|
adminClient, err := worker.CreateAdminClient(*workerAdminServer, workerInstance.ID(), grpcDialOption)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed to create admin client: %v", err)
|
glog.Fatalf("Failed to create admin client: %v", err)
|
||||||
@@ -94,10 +126,25 @@ func runWorker(cmd *Command, args []string) bool {
|
|||||||
// Set admin client
|
// Set admin client
|
||||||
workerInstance.SetAdminClient(adminClient)
|
workerInstance.SetAdminClient(adminClient)
|
||||||
|
|
||||||
|
// Set working directory
|
||||||
|
if *workerWorkingDir != "" {
|
||||||
|
glog.Infof("Setting working directory to: %s", *workerWorkingDir)
|
||||||
|
if err := os.Chdir(*workerWorkingDir); err != nil {
|
||||||
|
glog.Fatalf("Failed to change working directory: %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalf("Failed to get working directory: %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
glog.Infof("Current working directory: %s", wd)
|
||||||
|
}
|
||||||
|
|
||||||
// Start the worker
|
// Start the worker
|
||||||
err = workerInstance.Start()
|
err = workerInstance.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed to start worker: %v", err)
|
glog.Errorf("Failed to start worker: %v", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ service VolumeServer {
|
|||||||
}
|
}
|
||||||
rpc CopyFile (CopyFileRequest) returns (stream CopyFileResponse) {
|
rpc CopyFile (CopyFileRequest) returns (stream CopyFileResponse) {
|
||||||
}
|
}
|
||||||
|
rpc ReceiveFile (stream ReceiveFileRequest) returns (ReceiveFileResponse) {
|
||||||
|
}
|
||||||
|
|
||||||
rpc ReadNeedleBlob (ReadNeedleBlobRequest) returns (ReadNeedleBlobResponse) {
|
rpc ReadNeedleBlob (ReadNeedleBlobRequest) returns (ReadNeedleBlobResponse) {
|
||||||
}
|
}
|
||||||
@@ -87,6 +89,8 @@ service VolumeServer {
|
|||||||
}
|
}
|
||||||
rpc VolumeEcShardsToVolume (VolumeEcShardsToVolumeRequest) returns (VolumeEcShardsToVolumeResponse) {
|
rpc VolumeEcShardsToVolume (VolumeEcShardsToVolumeRequest) returns (VolumeEcShardsToVolumeResponse) {
|
||||||
}
|
}
|
||||||
|
rpc VolumeEcShardsInfo (VolumeEcShardsInfoRequest) returns (VolumeEcShardsInfoResponse) {
|
||||||
|
}
|
||||||
|
|
||||||
// tiered storage
|
// tiered storage
|
||||||
rpc VolumeTierMoveDatToRemote (VolumeTierMoveDatToRemoteRequest) returns (stream VolumeTierMoveDatToRemoteResponse) {
|
rpc VolumeTierMoveDatToRemote (VolumeTierMoveDatToRemoteRequest) returns (stream VolumeTierMoveDatToRemoteResponse) {
|
||||||
@@ -285,6 +289,27 @@ message CopyFileResponse {
|
|||||||
int64 modified_ts_ns = 2;
|
int64 modified_ts_ns = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ReceiveFileRequest {
|
||||||
|
oneof data {
|
||||||
|
ReceiveFileInfo info = 1;
|
||||||
|
bytes file_content = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message ReceiveFileInfo {
|
||||||
|
uint32 volume_id = 1;
|
||||||
|
string ext = 2;
|
||||||
|
string collection = 3;
|
||||||
|
bool is_ec_volume = 4;
|
||||||
|
uint32 shard_id = 5;
|
||||||
|
uint64 file_size = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ReceiveFileResponse {
|
||||||
|
uint64 bytes_written = 1;
|
||||||
|
string error = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message ReadNeedleBlobRequest {
|
message ReadNeedleBlobRequest {
|
||||||
uint32 volume_id = 1;
|
uint32 volume_id = 1;
|
||||||
int64 offset = 3; // actual offset
|
int64 offset = 3; // actual offset
|
||||||
@@ -431,6 +456,19 @@ message VolumeEcShardsToVolumeRequest {
|
|||||||
message VolumeEcShardsToVolumeResponse {
|
message VolumeEcShardsToVolumeResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message VolumeEcShardsInfoRequest {
|
||||||
|
uint32 volume_id = 1;
|
||||||
|
}
|
||||||
|
message VolumeEcShardsInfoResponse {
|
||||||
|
repeated EcShardInfo ec_shard_infos = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EcShardInfo {
|
||||||
|
uint32 shard_id = 1;
|
||||||
|
int64 size = 2;
|
||||||
|
string collection = 3;
|
||||||
|
}
|
||||||
|
|
||||||
message ReadVolumeFileStatusRequest {
|
message ReadVolumeFileStatusRequest {
|
||||||
uint32 volume_id = 1;
|
uint32 volume_id = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -38,6 +38,7 @@ const (
|
|||||||
VolumeServer_VolumeCopy_FullMethodName = "/volume_server_pb.VolumeServer/VolumeCopy"
|
VolumeServer_VolumeCopy_FullMethodName = "/volume_server_pb.VolumeServer/VolumeCopy"
|
||||||
VolumeServer_ReadVolumeFileStatus_FullMethodName = "/volume_server_pb.VolumeServer/ReadVolumeFileStatus"
|
VolumeServer_ReadVolumeFileStatus_FullMethodName = "/volume_server_pb.VolumeServer/ReadVolumeFileStatus"
|
||||||
VolumeServer_CopyFile_FullMethodName = "/volume_server_pb.VolumeServer/CopyFile"
|
VolumeServer_CopyFile_FullMethodName = "/volume_server_pb.VolumeServer/CopyFile"
|
||||||
|
VolumeServer_ReceiveFile_FullMethodName = "/volume_server_pb.VolumeServer/ReceiveFile"
|
||||||
VolumeServer_ReadNeedleBlob_FullMethodName = "/volume_server_pb.VolumeServer/ReadNeedleBlob"
|
VolumeServer_ReadNeedleBlob_FullMethodName = "/volume_server_pb.VolumeServer/ReadNeedleBlob"
|
||||||
VolumeServer_ReadNeedleMeta_FullMethodName = "/volume_server_pb.VolumeServer/ReadNeedleMeta"
|
VolumeServer_ReadNeedleMeta_FullMethodName = "/volume_server_pb.VolumeServer/ReadNeedleMeta"
|
||||||
VolumeServer_WriteNeedleBlob_FullMethodName = "/volume_server_pb.VolumeServer/WriteNeedleBlob"
|
VolumeServer_WriteNeedleBlob_FullMethodName = "/volume_server_pb.VolumeServer/WriteNeedleBlob"
|
||||||
@@ -53,6 +54,7 @@ const (
|
|||||||
VolumeServer_VolumeEcShardRead_FullMethodName = "/volume_server_pb.VolumeServer/VolumeEcShardRead"
|
VolumeServer_VolumeEcShardRead_FullMethodName = "/volume_server_pb.VolumeServer/VolumeEcShardRead"
|
||||||
VolumeServer_VolumeEcBlobDelete_FullMethodName = "/volume_server_pb.VolumeServer/VolumeEcBlobDelete"
|
VolumeServer_VolumeEcBlobDelete_FullMethodName = "/volume_server_pb.VolumeServer/VolumeEcBlobDelete"
|
||||||
VolumeServer_VolumeEcShardsToVolume_FullMethodName = "/volume_server_pb.VolumeServer/VolumeEcShardsToVolume"
|
VolumeServer_VolumeEcShardsToVolume_FullMethodName = "/volume_server_pb.VolumeServer/VolumeEcShardsToVolume"
|
||||||
|
VolumeServer_VolumeEcShardsInfo_FullMethodName = "/volume_server_pb.VolumeServer/VolumeEcShardsInfo"
|
||||||
VolumeServer_VolumeTierMoveDatToRemote_FullMethodName = "/volume_server_pb.VolumeServer/VolumeTierMoveDatToRemote"
|
VolumeServer_VolumeTierMoveDatToRemote_FullMethodName = "/volume_server_pb.VolumeServer/VolumeTierMoveDatToRemote"
|
||||||
VolumeServer_VolumeTierMoveDatFromRemote_FullMethodName = "/volume_server_pb.VolumeServer/VolumeTierMoveDatFromRemote"
|
VolumeServer_VolumeTierMoveDatFromRemote_FullMethodName = "/volume_server_pb.VolumeServer/VolumeTierMoveDatFromRemote"
|
||||||
VolumeServer_VolumeServerStatus_FullMethodName = "/volume_server_pb.VolumeServer/VolumeServerStatus"
|
VolumeServer_VolumeServerStatus_FullMethodName = "/volume_server_pb.VolumeServer/VolumeServerStatus"
|
||||||
@@ -88,6 +90,7 @@ type VolumeServerClient interface {
|
|||||||
VolumeCopy(ctx context.Context, in *VolumeCopyRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeCopyResponse], error)
|
VolumeCopy(ctx context.Context, in *VolumeCopyRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeCopyResponse], error)
|
||||||
ReadVolumeFileStatus(ctx context.Context, in *ReadVolumeFileStatusRequest, opts ...grpc.CallOption) (*ReadVolumeFileStatusResponse, error)
|
ReadVolumeFileStatus(ctx context.Context, in *ReadVolumeFileStatusRequest, opts ...grpc.CallOption) (*ReadVolumeFileStatusResponse, error)
|
||||||
CopyFile(ctx context.Context, in *CopyFileRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[CopyFileResponse], error)
|
CopyFile(ctx context.Context, in *CopyFileRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[CopyFileResponse], error)
|
||||||
|
ReceiveFile(ctx context.Context, opts ...grpc.CallOption) (grpc.ClientStreamingClient[ReceiveFileRequest, ReceiveFileResponse], error)
|
||||||
ReadNeedleBlob(ctx context.Context, in *ReadNeedleBlobRequest, opts ...grpc.CallOption) (*ReadNeedleBlobResponse, error)
|
ReadNeedleBlob(ctx context.Context, in *ReadNeedleBlobRequest, opts ...grpc.CallOption) (*ReadNeedleBlobResponse, error)
|
||||||
ReadNeedleMeta(ctx context.Context, in *ReadNeedleMetaRequest, opts ...grpc.CallOption) (*ReadNeedleMetaResponse, error)
|
ReadNeedleMeta(ctx context.Context, in *ReadNeedleMetaRequest, opts ...grpc.CallOption) (*ReadNeedleMetaResponse, error)
|
||||||
WriteNeedleBlob(ctx context.Context, in *WriteNeedleBlobRequest, opts ...grpc.CallOption) (*WriteNeedleBlobResponse, error)
|
WriteNeedleBlob(ctx context.Context, in *WriteNeedleBlobRequest, opts ...grpc.CallOption) (*WriteNeedleBlobResponse, error)
|
||||||
@@ -104,6 +107,7 @@ type VolumeServerClient interface {
|
|||||||
VolumeEcShardRead(ctx context.Context, in *VolumeEcShardReadRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeEcShardReadResponse], error)
|
VolumeEcShardRead(ctx context.Context, in *VolumeEcShardReadRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeEcShardReadResponse], error)
|
||||||
VolumeEcBlobDelete(ctx context.Context, in *VolumeEcBlobDeleteRequest, opts ...grpc.CallOption) (*VolumeEcBlobDeleteResponse, error)
|
VolumeEcBlobDelete(ctx context.Context, in *VolumeEcBlobDeleteRequest, opts ...grpc.CallOption) (*VolumeEcBlobDeleteResponse, error)
|
||||||
VolumeEcShardsToVolume(ctx context.Context, in *VolumeEcShardsToVolumeRequest, opts ...grpc.CallOption) (*VolumeEcShardsToVolumeResponse, error)
|
VolumeEcShardsToVolume(ctx context.Context, in *VolumeEcShardsToVolumeRequest, opts ...grpc.CallOption) (*VolumeEcShardsToVolumeResponse, error)
|
||||||
|
VolumeEcShardsInfo(ctx context.Context, in *VolumeEcShardsInfoRequest, opts ...grpc.CallOption) (*VolumeEcShardsInfoResponse, error)
|
||||||
// tiered storage
|
// tiered storage
|
||||||
VolumeTierMoveDatToRemote(ctx context.Context, in *VolumeTierMoveDatToRemoteRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeTierMoveDatToRemoteResponse], error)
|
VolumeTierMoveDatToRemote(ctx context.Context, in *VolumeTierMoveDatToRemoteRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeTierMoveDatToRemoteResponse], error)
|
||||||
VolumeTierMoveDatFromRemote(ctx context.Context, in *VolumeTierMoveDatFromRemoteRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeTierMoveDatFromRemoteResponse], error)
|
VolumeTierMoveDatFromRemote(ctx context.Context, in *VolumeTierMoveDatFromRemoteRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeTierMoveDatFromRemoteResponse], error)
|
||||||
@@ -351,6 +355,19 @@ func (c *volumeServerClient) CopyFile(ctx context.Context, in *CopyFileRequest,
|
|||||||
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
||||||
type VolumeServer_CopyFileClient = grpc.ServerStreamingClient[CopyFileResponse]
|
type VolumeServer_CopyFileClient = grpc.ServerStreamingClient[CopyFileResponse]
|
||||||
|
|
||||||
|
func (c *volumeServerClient) ReceiveFile(ctx context.Context, opts ...grpc.CallOption) (grpc.ClientStreamingClient[ReceiveFileRequest, ReceiveFileResponse], error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[4], VolumeServer_ReceiveFile_FullMethodName, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &grpc.GenericClientStream[ReceiveFileRequest, ReceiveFileResponse]{ClientStream: stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
||||||
|
type VolumeServer_ReceiveFileClient = grpc.ClientStreamingClient[ReceiveFileRequest, ReceiveFileResponse]
|
||||||
|
|
||||||
func (c *volumeServerClient) ReadNeedleBlob(ctx context.Context, in *ReadNeedleBlobRequest, opts ...grpc.CallOption) (*ReadNeedleBlobResponse, error) {
|
func (c *volumeServerClient) ReadNeedleBlob(ctx context.Context, in *ReadNeedleBlobRequest, opts ...grpc.CallOption) (*ReadNeedleBlobResponse, error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
out := new(ReadNeedleBlobResponse)
|
out := new(ReadNeedleBlobResponse)
|
||||||
@@ -383,7 +400,7 @@ func (c *volumeServerClient) WriteNeedleBlob(ctx context.Context, in *WriteNeedl
|
|||||||
|
|
||||||
func (c *volumeServerClient) ReadAllNeedles(ctx context.Context, in *ReadAllNeedlesRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ReadAllNeedlesResponse], error) {
|
func (c *volumeServerClient) ReadAllNeedles(ctx context.Context, in *ReadAllNeedlesRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ReadAllNeedlesResponse], error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[4], VolumeServer_ReadAllNeedles_FullMethodName, cOpts...)
|
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[5], VolumeServer_ReadAllNeedles_FullMethodName, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -402,7 +419,7 @@ type VolumeServer_ReadAllNeedlesClient = grpc.ServerStreamingClient[ReadAllNeedl
|
|||||||
|
|
||||||
func (c *volumeServerClient) VolumeTailSender(ctx context.Context, in *VolumeTailSenderRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeTailSenderResponse], error) {
|
func (c *volumeServerClient) VolumeTailSender(ctx context.Context, in *VolumeTailSenderRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeTailSenderResponse], error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[5], VolumeServer_VolumeTailSender_FullMethodName, cOpts...)
|
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[6], VolumeServer_VolumeTailSender_FullMethodName, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -491,7 +508,7 @@ func (c *volumeServerClient) VolumeEcShardsUnmount(ctx context.Context, in *Volu
|
|||||||
|
|
||||||
func (c *volumeServerClient) VolumeEcShardRead(ctx context.Context, in *VolumeEcShardReadRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeEcShardReadResponse], error) {
|
func (c *volumeServerClient) VolumeEcShardRead(ctx context.Context, in *VolumeEcShardReadRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeEcShardReadResponse], error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[6], VolumeServer_VolumeEcShardRead_FullMethodName, cOpts...)
|
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[7], VolumeServer_VolumeEcShardRead_FullMethodName, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -528,9 +545,19 @@ func (c *volumeServerClient) VolumeEcShardsToVolume(ctx context.Context, in *Vol
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *volumeServerClient) VolumeEcShardsInfo(ctx context.Context, in *VolumeEcShardsInfoRequest, opts ...grpc.CallOption) (*VolumeEcShardsInfoResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(VolumeEcShardsInfoResponse)
|
||||||
|
err := c.cc.Invoke(ctx, VolumeServer_VolumeEcShardsInfo_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *volumeServerClient) VolumeTierMoveDatToRemote(ctx context.Context, in *VolumeTierMoveDatToRemoteRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeTierMoveDatToRemoteResponse], error) {
|
func (c *volumeServerClient) VolumeTierMoveDatToRemote(ctx context.Context, in *VolumeTierMoveDatToRemoteRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeTierMoveDatToRemoteResponse], error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[7], VolumeServer_VolumeTierMoveDatToRemote_FullMethodName, cOpts...)
|
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[8], VolumeServer_VolumeTierMoveDatToRemote_FullMethodName, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -549,7 +576,7 @@ type VolumeServer_VolumeTierMoveDatToRemoteClient = grpc.ServerStreamingClient[V
|
|||||||
|
|
||||||
func (c *volumeServerClient) VolumeTierMoveDatFromRemote(ctx context.Context, in *VolumeTierMoveDatFromRemoteRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeTierMoveDatFromRemoteResponse], error) {
|
func (c *volumeServerClient) VolumeTierMoveDatFromRemote(ctx context.Context, in *VolumeTierMoveDatFromRemoteRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[VolumeTierMoveDatFromRemoteResponse], error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[8], VolumeServer_VolumeTierMoveDatFromRemote_FullMethodName, cOpts...)
|
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[9], VolumeServer_VolumeTierMoveDatFromRemote_FullMethodName, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -598,7 +625,7 @@ func (c *volumeServerClient) FetchAndWriteNeedle(ctx context.Context, in *FetchA
|
|||||||
|
|
||||||
func (c *volumeServerClient) Query(ctx context.Context, in *QueryRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[QueriedStripe], error) {
|
func (c *volumeServerClient) Query(ctx context.Context, in *QueryRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[QueriedStripe], error) {
|
||||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[9], VolumeServer_Query_FullMethodName, cOpts...)
|
stream, err := c.cc.NewStream(ctx, &VolumeServer_ServiceDesc.Streams[10], VolumeServer_Query_FullMethodName, cOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -660,6 +687,7 @@ type VolumeServerServer interface {
|
|||||||
VolumeCopy(*VolumeCopyRequest, grpc.ServerStreamingServer[VolumeCopyResponse]) error
|
VolumeCopy(*VolumeCopyRequest, grpc.ServerStreamingServer[VolumeCopyResponse]) error
|
||||||
ReadVolumeFileStatus(context.Context, *ReadVolumeFileStatusRequest) (*ReadVolumeFileStatusResponse, error)
|
ReadVolumeFileStatus(context.Context, *ReadVolumeFileStatusRequest) (*ReadVolumeFileStatusResponse, error)
|
||||||
CopyFile(*CopyFileRequest, grpc.ServerStreamingServer[CopyFileResponse]) error
|
CopyFile(*CopyFileRequest, grpc.ServerStreamingServer[CopyFileResponse]) error
|
||||||
|
ReceiveFile(grpc.ClientStreamingServer[ReceiveFileRequest, ReceiveFileResponse]) error
|
||||||
ReadNeedleBlob(context.Context, *ReadNeedleBlobRequest) (*ReadNeedleBlobResponse, error)
|
ReadNeedleBlob(context.Context, *ReadNeedleBlobRequest) (*ReadNeedleBlobResponse, error)
|
||||||
ReadNeedleMeta(context.Context, *ReadNeedleMetaRequest) (*ReadNeedleMetaResponse, error)
|
ReadNeedleMeta(context.Context, *ReadNeedleMetaRequest) (*ReadNeedleMetaResponse, error)
|
||||||
WriteNeedleBlob(context.Context, *WriteNeedleBlobRequest) (*WriteNeedleBlobResponse, error)
|
WriteNeedleBlob(context.Context, *WriteNeedleBlobRequest) (*WriteNeedleBlobResponse, error)
|
||||||
@@ -676,6 +704,7 @@ type VolumeServerServer interface {
|
|||||||
VolumeEcShardRead(*VolumeEcShardReadRequest, grpc.ServerStreamingServer[VolumeEcShardReadResponse]) error
|
VolumeEcShardRead(*VolumeEcShardReadRequest, grpc.ServerStreamingServer[VolumeEcShardReadResponse]) error
|
||||||
VolumeEcBlobDelete(context.Context, *VolumeEcBlobDeleteRequest) (*VolumeEcBlobDeleteResponse, error)
|
VolumeEcBlobDelete(context.Context, *VolumeEcBlobDeleteRequest) (*VolumeEcBlobDeleteResponse, error)
|
||||||
VolumeEcShardsToVolume(context.Context, *VolumeEcShardsToVolumeRequest) (*VolumeEcShardsToVolumeResponse, error)
|
VolumeEcShardsToVolume(context.Context, *VolumeEcShardsToVolumeRequest) (*VolumeEcShardsToVolumeResponse, error)
|
||||||
|
VolumeEcShardsInfo(context.Context, *VolumeEcShardsInfoRequest) (*VolumeEcShardsInfoResponse, error)
|
||||||
// tiered storage
|
// tiered storage
|
||||||
VolumeTierMoveDatToRemote(*VolumeTierMoveDatToRemoteRequest, grpc.ServerStreamingServer[VolumeTierMoveDatToRemoteResponse]) error
|
VolumeTierMoveDatToRemote(*VolumeTierMoveDatToRemoteRequest, grpc.ServerStreamingServer[VolumeTierMoveDatToRemoteResponse]) error
|
||||||
VolumeTierMoveDatFromRemote(*VolumeTierMoveDatFromRemoteRequest, grpc.ServerStreamingServer[VolumeTierMoveDatFromRemoteResponse]) error
|
VolumeTierMoveDatFromRemote(*VolumeTierMoveDatFromRemoteRequest, grpc.ServerStreamingServer[VolumeTierMoveDatFromRemoteResponse]) error
|
||||||
@@ -754,6 +783,9 @@ func (UnimplementedVolumeServerServer) ReadVolumeFileStatus(context.Context, *Re
|
|||||||
func (UnimplementedVolumeServerServer) CopyFile(*CopyFileRequest, grpc.ServerStreamingServer[CopyFileResponse]) error {
|
func (UnimplementedVolumeServerServer) CopyFile(*CopyFileRequest, grpc.ServerStreamingServer[CopyFileResponse]) error {
|
||||||
return status.Errorf(codes.Unimplemented, "method CopyFile not implemented")
|
return status.Errorf(codes.Unimplemented, "method CopyFile not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedVolumeServerServer) ReceiveFile(grpc.ClientStreamingServer[ReceiveFileRequest, ReceiveFileResponse]) error {
|
||||||
|
return status.Errorf(codes.Unimplemented, "method ReceiveFile not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedVolumeServerServer) ReadNeedleBlob(context.Context, *ReadNeedleBlobRequest) (*ReadNeedleBlobResponse, error) {
|
func (UnimplementedVolumeServerServer) ReadNeedleBlob(context.Context, *ReadNeedleBlobRequest) (*ReadNeedleBlobResponse, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method ReadNeedleBlob not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method ReadNeedleBlob not implemented")
|
||||||
}
|
}
|
||||||
@@ -799,6 +831,9 @@ func (UnimplementedVolumeServerServer) VolumeEcBlobDelete(context.Context, *Volu
|
|||||||
func (UnimplementedVolumeServerServer) VolumeEcShardsToVolume(context.Context, *VolumeEcShardsToVolumeRequest) (*VolumeEcShardsToVolumeResponse, error) {
|
func (UnimplementedVolumeServerServer) VolumeEcShardsToVolume(context.Context, *VolumeEcShardsToVolumeRequest) (*VolumeEcShardsToVolumeResponse, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method VolumeEcShardsToVolume not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method VolumeEcShardsToVolume not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedVolumeServerServer) VolumeEcShardsInfo(context.Context, *VolumeEcShardsInfoRequest) (*VolumeEcShardsInfoResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method VolumeEcShardsInfo not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedVolumeServerServer) VolumeTierMoveDatToRemote(*VolumeTierMoveDatToRemoteRequest, grpc.ServerStreamingServer[VolumeTierMoveDatToRemoteResponse]) error {
|
func (UnimplementedVolumeServerServer) VolumeTierMoveDatToRemote(*VolumeTierMoveDatToRemoteRequest, grpc.ServerStreamingServer[VolumeTierMoveDatToRemoteResponse]) error {
|
||||||
return status.Errorf(codes.Unimplemented, "method VolumeTierMoveDatToRemote not implemented")
|
return status.Errorf(codes.Unimplemented, "method VolumeTierMoveDatToRemote not implemented")
|
||||||
}
|
}
|
||||||
@@ -1158,6 +1193,13 @@ func _VolumeServer_CopyFile_Handler(srv interface{}, stream grpc.ServerStream) e
|
|||||||
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
||||||
type VolumeServer_CopyFileServer = grpc.ServerStreamingServer[CopyFileResponse]
|
type VolumeServer_CopyFileServer = grpc.ServerStreamingServer[CopyFileResponse]
|
||||||
|
|
||||||
|
func _VolumeServer_ReceiveFile_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(VolumeServerServer).ReceiveFile(&grpc.GenericServerStream[ReceiveFileRequest, ReceiveFileResponse]{ServerStream: stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
|
||||||
|
type VolumeServer_ReceiveFileServer = grpc.ClientStreamingServer[ReceiveFileRequest, ReceiveFileResponse]
|
||||||
|
|
||||||
func _VolumeServer_ReadNeedleBlob_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
func _VolumeServer_ReadNeedleBlob_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
in := new(ReadNeedleBlobRequest)
|
in := new(ReadNeedleBlobRequest)
|
||||||
if err := dec(in); err != nil {
|
if err := dec(in); err != nil {
|
||||||
@@ -1407,6 +1449,24 @@ func _VolumeServer_VolumeEcShardsToVolume_Handler(srv interface{}, ctx context.C
|
|||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _VolumeServer_VolumeEcShardsInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(VolumeEcShardsInfoRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(VolumeServerServer).VolumeEcShardsInfo(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: VolumeServer_VolumeEcShardsInfo_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(VolumeServerServer).VolumeEcShardsInfo(ctx, req.(*VolumeEcShardsInfoRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
func _VolumeServer_VolumeTierMoveDatToRemote_Handler(srv interface{}, stream grpc.ServerStream) error {
|
func _VolumeServer_VolumeTierMoveDatToRemote_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
m := new(VolumeTierMoveDatToRemoteRequest)
|
m := new(VolumeTierMoveDatToRemoteRequest)
|
||||||
if err := stream.RecvMsg(m); err != nil {
|
if err := stream.RecvMsg(m); err != nil {
|
||||||
@@ -1645,6 +1705,10 @@ var VolumeServer_ServiceDesc = grpc.ServiceDesc{
|
|||||||
MethodName: "VolumeEcShardsToVolume",
|
MethodName: "VolumeEcShardsToVolume",
|
||||||
Handler: _VolumeServer_VolumeEcShardsToVolume_Handler,
|
Handler: _VolumeServer_VolumeEcShardsToVolume_Handler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MethodName: "VolumeEcShardsInfo",
|
||||||
|
Handler: _VolumeServer_VolumeEcShardsInfo_Handler,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
MethodName: "VolumeServerStatus",
|
MethodName: "VolumeServerStatus",
|
||||||
Handler: _VolumeServer_VolumeServerStatus_Handler,
|
Handler: _VolumeServer_VolumeServerStatus_Handler,
|
||||||
@@ -1687,6 +1751,11 @@ var VolumeServer_ServiceDesc = grpc.ServiceDesc{
|
|||||||
Handler: _VolumeServer_CopyFile_Handler,
|
Handler: _VolumeServer_CopyFile_Handler,
|
||||||
ServerStreams: true,
|
ServerStreams: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
StreamName: "ReceiveFile",
|
||||||
|
Handler: _VolumeServer_ReceiveFile_Handler,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
StreamName: "ReadAllNeedles",
|
StreamName: "ReadAllNeedles",
|
||||||
Handler: _VolumeServer_ReadAllNeedles_Handler,
|
Handler: _VolumeServer_ReadAllNeedles_Handler,
|
||||||
|
|||||||
@@ -402,3 +402,120 @@ func (vs *VolumeServer) CopyFile(req *volume_server_pb.CopyFileRequest, stream v
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReceiveFile receives a file stream from client and writes it to storage
|
||||||
|
func (vs *VolumeServer) ReceiveFile(stream volume_server_pb.VolumeServer_ReceiveFileServer) error {
|
||||||
|
var fileInfo *volume_server_pb.ReceiveFileInfo
|
||||||
|
var targetFile *os.File
|
||||||
|
var filePath string
|
||||||
|
var bytesWritten uint64
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if targetFile != nil {
|
||||||
|
targetFile.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
req, err := stream.Recv()
|
||||||
|
if err == io.EOF {
|
||||||
|
// Stream completed successfully
|
||||||
|
if targetFile != nil {
|
||||||
|
targetFile.Sync()
|
||||||
|
glog.V(1).Infof("Successfully received file %s (%d bytes)", filePath, bytesWritten)
|
||||||
|
}
|
||||||
|
return stream.SendAndClose(&volume_server_pb.ReceiveFileResponse{
|
||||||
|
BytesWritten: bytesWritten,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
// Clean up on error
|
||||||
|
if targetFile != nil {
|
||||||
|
targetFile.Close()
|
||||||
|
os.Remove(filePath)
|
||||||
|
}
|
||||||
|
glog.Errorf("Failed to receive stream: %v", err)
|
||||||
|
return fmt.Errorf("failed to receive stream: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch data := req.Data.(type) {
|
||||||
|
case *volume_server_pb.ReceiveFileRequest_Info:
|
||||||
|
// First message contains file info
|
||||||
|
fileInfo = data.Info
|
||||||
|
glog.V(1).Infof("ReceiveFile: volume %d, ext %s, collection %s, shard %d, size %d",
|
||||||
|
fileInfo.VolumeId, fileInfo.Ext, fileInfo.Collection, fileInfo.ShardId, fileInfo.FileSize)
|
||||||
|
|
||||||
|
// Create file path based on file info
|
||||||
|
if fileInfo.IsEcVolume {
|
||||||
|
// Find storage location for EC shard
|
||||||
|
var targetLocation *storage.DiskLocation
|
||||||
|
for _, location := range vs.store.Locations {
|
||||||
|
if location.DiskType == types.HardDriveType {
|
||||||
|
targetLocation = location
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if targetLocation == nil && len(vs.store.Locations) > 0 {
|
||||||
|
targetLocation = vs.store.Locations[0] // Fall back to first available location
|
||||||
|
}
|
||||||
|
if targetLocation == nil {
|
||||||
|
glog.Errorf("ReceiveFile: no storage location available")
|
||||||
|
return stream.SendAndClose(&volume_server_pb.ReceiveFileResponse{
|
||||||
|
Error: "no storage location available",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create EC shard file path
|
||||||
|
baseFileName := erasure_coding.EcShardBaseFileName(fileInfo.Collection, int(fileInfo.VolumeId))
|
||||||
|
filePath = util.Join(targetLocation.Directory, baseFileName+fileInfo.Ext)
|
||||||
|
} else {
|
||||||
|
// Regular volume file
|
||||||
|
v := vs.store.GetVolume(needle.VolumeId(fileInfo.VolumeId))
|
||||||
|
if v == nil {
|
||||||
|
glog.Errorf("ReceiveFile: volume %d not found", fileInfo.VolumeId)
|
||||||
|
return stream.SendAndClose(&volume_server_pb.ReceiveFileResponse{
|
||||||
|
Error: fmt.Sprintf("volume %d not found", fileInfo.VolumeId),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
filePath = v.FileName(fileInfo.Ext)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create target file
|
||||||
|
targetFile, err = os.Create(filePath)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("ReceiveFile: failed to create file %s: %v", filePath, err)
|
||||||
|
return stream.SendAndClose(&volume_server_pb.ReceiveFileResponse{
|
||||||
|
Error: fmt.Sprintf("failed to create file: %v", err),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
glog.V(1).Infof("ReceiveFile: created target file %s", filePath)
|
||||||
|
|
||||||
|
case *volume_server_pb.ReceiveFileRequest_FileContent:
|
||||||
|
// Subsequent messages contain file content
|
||||||
|
if targetFile == nil {
|
||||||
|
glog.Errorf("ReceiveFile: file info must be sent first")
|
||||||
|
return stream.SendAndClose(&volume_server_pb.ReceiveFileResponse{
|
||||||
|
Error: "file info must be sent first",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
n, err := targetFile.Write(data.FileContent)
|
||||||
|
if err != nil {
|
||||||
|
targetFile.Close()
|
||||||
|
os.Remove(filePath)
|
||||||
|
glog.Errorf("ReceiveFile: failed to write to file %s: %v", filePath, err)
|
||||||
|
return stream.SendAndClose(&volume_server_pb.ReceiveFileResponse{
|
||||||
|
Error: fmt.Sprintf("failed to write file: %v", err),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
bytesWritten += uint64(n)
|
||||||
|
glog.V(2).Infof("ReceiveFile: wrote %d bytes to %s (total: %d)", n, filePath, bytesWritten)
|
||||||
|
|
||||||
|
default:
|
||||||
|
glog.Errorf("ReceiveFile: unknown message type")
|
||||||
|
return stream.SendAndClose(&volume_server_pb.ReceiveFileResponse{
|
||||||
|
Error: "unknown message type",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -467,3 +467,30 @@ func (vs *VolumeServer) VolumeEcShardsToVolume(ctx context.Context, req *volume_
|
|||||||
|
|
||||||
return &volume_server_pb.VolumeEcShardsToVolumeResponse{}, nil
|
return &volume_server_pb.VolumeEcShardsToVolumeResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (vs *VolumeServer) VolumeEcShardsInfo(ctx context.Context, req *volume_server_pb.VolumeEcShardsInfoRequest) (*volume_server_pb.VolumeEcShardsInfoResponse, error) {
|
||||||
|
glog.V(0).Infof("VolumeEcShardsInfo: volume %d", req.VolumeId)
|
||||||
|
|
||||||
|
var ecShardInfos []*volume_server_pb.EcShardInfo
|
||||||
|
|
||||||
|
// Find the EC volume
|
||||||
|
for _, location := range vs.store.Locations {
|
||||||
|
if v, found := location.FindEcVolume(needle.VolumeId(req.VolumeId)); found {
|
||||||
|
// Get shard details from the EC volume
|
||||||
|
shardDetails := v.ShardDetails()
|
||||||
|
for _, shardDetail := range shardDetails {
|
||||||
|
ecShardInfo := &volume_server_pb.EcShardInfo{
|
||||||
|
ShardId: uint32(shardDetail.ShardId),
|
||||||
|
Size: shardDetail.Size,
|
||||||
|
Collection: v.Collection,
|
||||||
|
}
|
||||||
|
ecShardInfos = append(ecShardInfos, ecShardInfo)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &volume_server_pb.VolumeEcShardsInfoResponse{
|
||||||
|
EcShardInfos: ecShardInfos,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
package weed_server
|
package weed_server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/seaweedfs/seaweedfs/weed/topology"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/util/version"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/topology"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/util/version"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/stats"
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -175,8 +175,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Id</th>
|
<th>Id</th>
|
||||||
<th>Collection</th>
|
<th>Collection</th>
|
||||||
<th>Shard Size</th>
|
<th>Total Size</th>
|
||||||
<th>Shards</th>
|
<th>Shard Details</th>
|
||||||
<th>CreatedAt</th>
|
<th>CreatedAt</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -185,8 +185,14 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><code>{{ .VolumeId }}</code></td>
|
<td><code>{{ .VolumeId }}</code></td>
|
||||||
<td>{{ .Collection }}</td>
|
<td>{{ .Collection }}</td>
|
||||||
<td>{{ bytesToHumanReadable .ShardSize }}</td>
|
<td>{{ bytesToHumanReadable .Size }}</td>
|
||||||
<td>{{ .ShardIdList }}</td>
|
<td>
|
||||||
|
{{ range .ShardDetails }}
|
||||||
|
<span class="label label-info" style="margin-right: 5px;">
|
||||||
|
{{ .ShardId }}: {{ bytesToHumanReadable .Size }}
|
||||||
|
</span>
|
||||||
|
{{ end }}
|
||||||
|
</td>
|
||||||
<td>{{ .CreatedAt.Format "2006-01-02 15:04" }}</td>
|
<td>{{ .CreatedAt.Format "2006-01-02 15:04" }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
@@ -196,6 +196,21 @@ func (ev *EcVolume) ShardIdList() (shardIds []ShardId) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ShardInfo struct {
|
||||||
|
ShardId ShardId
|
||||||
|
Size int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ev *EcVolume) ShardDetails() (shards []ShardInfo) {
|
||||||
|
for _, s := range ev.Shards {
|
||||||
|
shards = append(shards, ShardInfo{
|
||||||
|
ShardId: s.ShardId,
|
||||||
|
Size: s.Size(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (ev *EcVolume) ToVolumeEcShardInformationMessage() (messages []*master_pb.VolumeEcShardInformationMessage) {
|
func (ev *EcVolume) ToVolumeEcShardInformationMessage() (messages []*master_pb.VolumeEcShardInformationMessage) {
|
||||||
prevVolumeId := needle.VolumeId(math.MaxUint32)
|
prevVolumeId := needle.VolumeId(math.MaxUint32)
|
||||||
var m *master_pb.VolumeEcShardInformationMessage
|
var m *master_pb.VolumeEcShardInformationMessage
|
||||||
|
|||||||
+184
-50
@@ -80,6 +80,21 @@ func (c *GrpcAdminClient) Connect() error {
|
|||||||
return fmt.Errorf("already connected")
|
return fmt.Errorf("already connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always start the reconnection loop, even if initial connection fails
|
||||||
|
go c.reconnectionLoop()
|
||||||
|
|
||||||
|
// Attempt initial connection
|
||||||
|
err := c.attemptConnection()
|
||||||
|
if err != nil {
|
||||||
|
glog.V(1).Infof("Initial connection failed, reconnection loop will retry: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// attemptConnection tries to establish the connection without managing the reconnection loop
|
||||||
|
func (c *GrpcAdminClient) attemptConnection() error {
|
||||||
// Detect TLS support and create appropriate connection
|
// Detect TLS support and create appropriate connection
|
||||||
conn, err := c.createConnection()
|
conn, err := c.createConnection()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -100,10 +115,34 @@ func (c *GrpcAdminClient) Connect() error {
|
|||||||
c.stream = stream
|
c.stream = stream
|
||||||
c.connected = true
|
c.connected = true
|
||||||
|
|
||||||
// Start stream handlers and reconnection loop
|
// Always check for worker info and send registration immediately as the very first message
|
||||||
go c.handleOutgoing()
|
c.mutex.RLock()
|
||||||
go c.handleIncoming()
|
workerInfo := c.lastWorkerInfo
|
||||||
go c.reconnectionLoop()
|
c.mutex.RUnlock()
|
||||||
|
|
||||||
|
if workerInfo != nil {
|
||||||
|
// Send registration synchronously as the very first message
|
||||||
|
if err := c.sendRegistrationSync(workerInfo); err != nil {
|
||||||
|
c.conn.Close()
|
||||||
|
c.connected = false
|
||||||
|
return fmt.Errorf("failed to register worker: %w", err)
|
||||||
|
}
|
||||||
|
glog.Infof("Worker registered successfully with admin server")
|
||||||
|
} else {
|
||||||
|
// No worker info yet - stream will wait for registration
|
||||||
|
glog.V(1).Infof("Connected to admin server, waiting for worker registration info")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start stream handlers with synchronization
|
||||||
|
outgoingReady := make(chan struct{})
|
||||||
|
incomingReady := make(chan struct{})
|
||||||
|
|
||||||
|
go c.handleOutgoingWithReady(outgoingReady)
|
||||||
|
go c.handleIncomingWithReady(incomingReady)
|
||||||
|
|
||||||
|
// Wait for both handlers to be ready
|
||||||
|
<-outgoingReady
|
||||||
|
<-incomingReady
|
||||||
|
|
||||||
glog.Infof("Connected to admin server at %s", c.adminAddress)
|
glog.Infof("Connected to admin server at %s", c.adminAddress)
|
||||||
return nil
|
return nil
|
||||||
@@ -268,53 +307,16 @@ func (c *GrpcAdminClient) reconnect() error {
|
|||||||
if c.conn != nil {
|
if c.conn != nil {
|
||||||
c.conn.Close()
|
c.conn.Close()
|
||||||
}
|
}
|
||||||
|
c.connected = false
|
||||||
c.mutex.Unlock()
|
c.mutex.Unlock()
|
||||||
|
|
||||||
// Create new connection
|
// Attempt to re-establish connection using the same logic as initial connection
|
||||||
conn, err := c.createConnection()
|
err := c.attemptConnection()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create connection: %w", err)
|
return fmt.Errorf("failed to reconnect: %w", err)
|
||||||
}
|
|
||||||
|
|
||||||
client := worker_pb.NewWorkerServiceClient(conn)
|
|
||||||
|
|
||||||
// Create new stream
|
|
||||||
streamCtx, streamCancel := context.WithCancel(context.Background())
|
|
||||||
stream, err := client.WorkerStream(streamCtx)
|
|
||||||
if err != nil {
|
|
||||||
conn.Close()
|
|
||||||
streamCancel()
|
|
||||||
return fmt.Errorf("failed to create stream: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update client state
|
|
||||||
c.mutex.Lock()
|
|
||||||
c.conn = conn
|
|
||||||
c.client = client
|
|
||||||
c.stream = stream
|
|
||||||
c.streamCtx = streamCtx
|
|
||||||
c.streamCancel = streamCancel
|
|
||||||
c.connected = true
|
|
||||||
c.mutex.Unlock()
|
|
||||||
|
|
||||||
// Restart stream handlers
|
|
||||||
go c.handleOutgoing()
|
|
||||||
go c.handleIncoming()
|
|
||||||
|
|
||||||
// Re-register worker if we have previous registration info
|
|
||||||
c.mutex.RLock()
|
|
||||||
workerInfo := c.lastWorkerInfo
|
|
||||||
c.mutex.RUnlock()
|
|
||||||
|
|
||||||
if workerInfo != nil {
|
|
||||||
glog.Infof("Re-registering worker after reconnection...")
|
|
||||||
if err := c.sendRegistration(workerInfo); err != nil {
|
|
||||||
glog.Errorf("Failed to re-register worker: %v", err)
|
|
||||||
// Don't fail the reconnection because of registration failure
|
|
||||||
// The registration will be retried on next heartbeat or operation
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Registration is now handled in attemptConnection if worker info is available
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,6 +342,15 @@ func (c *GrpcAdminClient) handleOutgoing() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleOutgoingWithReady processes outgoing messages and signals when ready
|
||||||
|
func (c *GrpcAdminClient) handleOutgoingWithReady(ready chan struct{}) {
|
||||||
|
// Signal that this handler is ready to process messages
|
||||||
|
close(ready)
|
||||||
|
|
||||||
|
// Now process messages normally
|
||||||
|
c.handleOutgoing()
|
||||||
|
}
|
||||||
|
|
||||||
// handleIncoming processes incoming messages from admin
|
// handleIncoming processes incoming messages from admin
|
||||||
func (c *GrpcAdminClient) handleIncoming() {
|
func (c *GrpcAdminClient) handleIncoming() {
|
||||||
for {
|
for {
|
||||||
@@ -374,17 +385,28 @@ func (c *GrpcAdminClient) handleIncoming() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleIncomingWithReady processes incoming messages and signals when ready
|
||||||
|
func (c *GrpcAdminClient) handleIncomingWithReady(ready chan struct{}) {
|
||||||
|
// Signal that this handler is ready to process messages
|
||||||
|
close(ready)
|
||||||
|
|
||||||
|
// Now process messages normally
|
||||||
|
c.handleIncoming()
|
||||||
|
}
|
||||||
|
|
||||||
// RegisterWorker registers the worker with the admin server
|
// RegisterWorker registers the worker with the admin server
|
||||||
func (c *GrpcAdminClient) RegisterWorker(worker *types.Worker) error {
|
func (c *GrpcAdminClient) RegisterWorker(worker *types.Worker) error {
|
||||||
if !c.connected {
|
|
||||||
return fmt.Errorf("not connected to admin server")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store worker info for re-registration after reconnection
|
// Store worker info for re-registration after reconnection
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
c.lastWorkerInfo = worker
|
c.lastWorkerInfo = worker
|
||||||
c.mutex.Unlock()
|
c.mutex.Unlock()
|
||||||
|
|
||||||
|
// If not connected, registration will happen when connection is established
|
||||||
|
if !c.connected {
|
||||||
|
glog.V(1).Infof("Not connected yet, worker info stored for registration upon connection")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return c.sendRegistration(worker)
|
return c.sendRegistration(worker)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,9 +457,88 @@ func (c *GrpcAdminClient) sendRegistration(worker *types.Worker) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sendRegistrationSync sends the registration message synchronously
|
||||||
|
func (c *GrpcAdminClient) sendRegistrationSync(worker *types.Worker) error {
|
||||||
|
capabilities := make([]string, len(worker.Capabilities))
|
||||||
|
for i, cap := range worker.Capabilities {
|
||||||
|
capabilities[i] = string(cap)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := &worker_pb.WorkerMessage{
|
||||||
|
WorkerId: c.workerID,
|
||||||
|
Timestamp: time.Now().Unix(),
|
||||||
|
Message: &worker_pb.WorkerMessage_Registration{
|
||||||
|
Registration: &worker_pb.WorkerRegistration{
|
||||||
|
WorkerId: c.workerID,
|
||||||
|
Address: worker.Address,
|
||||||
|
Capabilities: capabilities,
|
||||||
|
MaxConcurrent: int32(worker.MaxConcurrent),
|
||||||
|
Metadata: make(map[string]string),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send directly to stream to ensure it's the first message
|
||||||
|
if err := c.stream.Send(msg); err != nil {
|
||||||
|
return fmt.Errorf("failed to send registration message: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a channel to receive the response
|
||||||
|
responseChan := make(chan *worker_pb.AdminMessage, 1)
|
||||||
|
errChan := make(chan error, 1)
|
||||||
|
|
||||||
|
// Start a goroutine to listen for the response
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
response, err := c.stream.Recv()
|
||||||
|
if err != nil {
|
||||||
|
errChan <- fmt.Errorf("failed to receive registration response: %w", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if regResp := response.GetRegistrationResponse(); regResp != nil {
|
||||||
|
responseChan <- response
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Continue waiting if it's not a registration response
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Wait for registration response with timeout
|
||||||
|
timeout := time.NewTimer(10 * time.Second)
|
||||||
|
defer timeout.Stop()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case response := <-responseChan:
|
||||||
|
if regResp := response.GetRegistrationResponse(); regResp != nil {
|
||||||
|
if regResp.Success {
|
||||||
|
glog.V(1).Infof("Worker registered successfully: %s", regResp.Message)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("registration failed: %s", regResp.Message)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unexpected response type")
|
||||||
|
case err := <-errChan:
|
||||||
|
return err
|
||||||
|
case <-timeout.C:
|
||||||
|
return fmt.Errorf("registration timeout")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SendHeartbeat sends heartbeat to admin server
|
// SendHeartbeat sends heartbeat to admin server
|
||||||
func (c *GrpcAdminClient) SendHeartbeat(workerID string, status *types.WorkerStatus) error {
|
func (c *GrpcAdminClient) SendHeartbeat(workerID string, status *types.WorkerStatus) error {
|
||||||
if !c.connected {
|
if !c.connected {
|
||||||
|
// If we're currently reconnecting, don't wait - just skip the heartbeat
|
||||||
|
c.mutex.RLock()
|
||||||
|
reconnecting := c.reconnecting
|
||||||
|
c.mutex.RUnlock()
|
||||||
|
|
||||||
|
if reconnecting {
|
||||||
|
// Don't treat as an error - reconnection is in progress
|
||||||
|
glog.V(2).Infof("Skipping heartbeat during reconnection")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for reconnection for a short time
|
// Wait for reconnection for a short time
|
||||||
if err := c.waitForConnection(10 * time.Second); err != nil {
|
if err := c.waitForConnection(10 * time.Second); err != nil {
|
||||||
return fmt.Errorf("not connected to admin server: %w", err)
|
return fmt.Errorf("not connected to admin server: %w", err)
|
||||||
@@ -477,6 +578,17 @@ func (c *GrpcAdminClient) SendHeartbeat(workerID string, status *types.WorkerSta
|
|||||||
// RequestTask requests a new task from admin server
|
// RequestTask requests a new task from admin server
|
||||||
func (c *GrpcAdminClient) RequestTask(workerID string, capabilities []types.TaskType) (*types.Task, error) {
|
func (c *GrpcAdminClient) RequestTask(workerID string, capabilities []types.TaskType) (*types.Task, error) {
|
||||||
if !c.connected {
|
if !c.connected {
|
||||||
|
// If we're currently reconnecting, don't wait - just return no task
|
||||||
|
c.mutex.RLock()
|
||||||
|
reconnecting := c.reconnecting
|
||||||
|
c.mutex.RUnlock()
|
||||||
|
|
||||||
|
if reconnecting {
|
||||||
|
// Don't treat as an error - reconnection is in progress
|
||||||
|
glog.V(2).Infof("Skipping task request during reconnection")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for reconnection for a short time
|
// Wait for reconnection for a short time
|
||||||
if err := c.waitForConnection(5 * time.Second); err != nil {
|
if err := c.waitForConnection(5 * time.Second); err != nil {
|
||||||
return nil, fmt.Errorf("not connected to admin server: %w", err)
|
return nil, fmt.Errorf("not connected to admin server: %w", err)
|
||||||
@@ -543,6 +655,17 @@ func (c *GrpcAdminClient) RequestTask(workerID string, capabilities []types.Task
|
|||||||
// CompleteTask reports task completion to admin server
|
// CompleteTask reports task completion to admin server
|
||||||
func (c *GrpcAdminClient) CompleteTask(taskID string, success bool, errorMsg string) error {
|
func (c *GrpcAdminClient) CompleteTask(taskID string, success bool, errorMsg string) error {
|
||||||
if !c.connected {
|
if !c.connected {
|
||||||
|
// If we're currently reconnecting, don't wait - just skip the completion report
|
||||||
|
c.mutex.RLock()
|
||||||
|
reconnecting := c.reconnecting
|
||||||
|
c.mutex.RUnlock()
|
||||||
|
|
||||||
|
if reconnecting {
|
||||||
|
// Don't treat as an error - reconnection is in progress
|
||||||
|
glog.V(2).Infof("Skipping task completion report during reconnection for task %s", taskID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for reconnection for a short time
|
// Wait for reconnection for a short time
|
||||||
if err := c.waitForConnection(5 * time.Second); err != nil {
|
if err := c.waitForConnection(5 * time.Second); err != nil {
|
||||||
return fmt.Errorf("not connected to admin server: %w", err)
|
return fmt.Errorf("not connected to admin server: %w", err)
|
||||||
@@ -574,6 +697,17 @@ func (c *GrpcAdminClient) CompleteTask(taskID string, success bool, errorMsg str
|
|||||||
// UpdateTaskProgress updates task progress to admin server
|
// UpdateTaskProgress updates task progress to admin server
|
||||||
func (c *GrpcAdminClient) UpdateTaskProgress(taskID string, progress float64) error {
|
func (c *GrpcAdminClient) UpdateTaskProgress(taskID string, progress float64) error {
|
||||||
if !c.connected {
|
if !c.connected {
|
||||||
|
// If we're currently reconnecting, don't wait - just skip the progress update
|
||||||
|
c.mutex.RLock()
|
||||||
|
reconnecting := c.reconnecting
|
||||||
|
c.mutex.RUnlock()
|
||||||
|
|
||||||
|
if reconnecting {
|
||||||
|
// Don't treat as an error - reconnection is in progress
|
||||||
|
glog.V(2).Infof("Skipping task progress update during reconnection for task %s", taskID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for reconnection for a short time
|
// Wait for reconnection for a short time
|
||||||
if err := c.waitForConnection(5 * time.Second); err != nil {
|
if err := c.waitForConnection(5 * time.Second); err != nil {
|
||||||
return fmt.Errorf("not connected to admin server: %w", err)
|
return fmt.Errorf("not connected to admin server: %w", err)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ func NewTask(server string, volumeID uint32, collection string) *Task {
|
|||||||
|
|
||||||
// Execute executes the balance task
|
// Execute executes the balance task
|
||||||
func (t *Task) Execute(params types.TaskParams) error {
|
func (t *Task) Execute(params types.TaskParams) error {
|
||||||
|
t.LogInfo("Starting balance task for volume %d on server %s (collection: %s)", t.volumeID, t.server, t.collection)
|
||||||
glog.Infof("Starting balance task for volume %d on server %s (collection: %s)", t.volumeID, t.server, t.collection)
|
glog.Infof("Starting balance task for volume %d on server %s (collection: %s)", t.volumeID, t.server, t.collection)
|
||||||
|
|
||||||
// Simulate balance operation with progress updates
|
// Simulate balance operation with progress updates
|
||||||
@@ -45,18 +46,23 @@ func (t *Task) Execute(params types.TaskParams) error {
|
|||||||
{"Verifying balance", 1 * time.Second, 100},
|
{"Verifying balance", 1 * time.Second, 100},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, step := range steps {
|
for i, step := range steps {
|
||||||
if t.IsCancelled() {
|
if t.IsCancelled() {
|
||||||
|
t.LogWarning("Balance task cancelled at step %d: %s", i+1, step.name)
|
||||||
return fmt.Errorf("balance task cancelled")
|
return fmt.Errorf("balance task cancelled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.LogInfo("Starting step %d/%d: %s", i+1, len(steps), step.name)
|
||||||
glog.V(1).Infof("Balance task step: %s", step.name)
|
glog.V(1).Infof("Balance task step: %s", step.name)
|
||||||
t.SetProgress(step.progress)
|
t.SetProgress(step.progress)
|
||||||
|
|
||||||
// Simulate work
|
// Simulate work
|
||||||
time.Sleep(step.duration)
|
time.Sleep(step.duration)
|
||||||
|
|
||||||
|
t.LogDebug("Completed step %d/%d: %s (progress: %.1f%%)", i+1, len(steps), step.name, step.progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.LogInfo("Balance task completed successfully for volume %d on server %s", t.volumeID, t.server)
|
||||||
glog.Infof("Balance task completed for volume %d on server %s", t.volumeID, t.server)
|
glog.Infof("Balance task completed for volume %d on server %s", t.volumeID, t.server)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,171 +0,0 @@
|
|||||||
package balance
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// BalanceDetector implements TaskDetector for balance tasks
|
|
||||||
type BalanceDetector struct {
|
|
||||||
enabled bool
|
|
||||||
threshold float64 // Imbalance threshold (0.1 = 10%)
|
|
||||||
minCheckInterval time.Duration
|
|
||||||
minVolumeCount int
|
|
||||||
lastCheck time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile-time interface assertions
|
|
||||||
var (
|
|
||||||
_ types.TaskDetector = (*BalanceDetector)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewBalanceDetector creates a new balance detector
|
|
||||||
func NewBalanceDetector() *BalanceDetector {
|
|
||||||
return &BalanceDetector{
|
|
||||||
enabled: true,
|
|
||||||
threshold: 0.1, // 10% imbalance threshold
|
|
||||||
minCheckInterval: 1 * time.Hour,
|
|
||||||
minVolumeCount: 10, // Don't balance small clusters
|
|
||||||
lastCheck: time.Time{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTaskType returns the task type
|
|
||||||
func (d *BalanceDetector) GetTaskType() types.TaskType {
|
|
||||||
return types.TaskTypeBalance
|
|
||||||
}
|
|
||||||
|
|
||||||
// ScanForTasks checks if cluster balance is needed
|
|
||||||
func (d *BalanceDetector) ScanForTasks(volumeMetrics []*types.VolumeHealthMetrics, clusterInfo *types.ClusterInfo) ([]*types.TaskDetectionResult, error) {
|
|
||||||
if !d.enabled {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.V(2).Infof("Scanning for balance tasks...")
|
|
||||||
|
|
||||||
// Don't check too frequently
|
|
||||||
if time.Since(d.lastCheck) < d.minCheckInterval {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
d.lastCheck = time.Now()
|
|
||||||
|
|
||||||
// Skip if cluster is too small
|
|
||||||
if len(volumeMetrics) < d.minVolumeCount {
|
|
||||||
glog.V(2).Infof("Cluster too small for balance (%d volumes < %d minimum)", len(volumeMetrics), d.minVolumeCount)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Analyze volume distribution across servers
|
|
||||||
serverVolumeCounts := make(map[string]int)
|
|
||||||
for _, metric := range volumeMetrics {
|
|
||||||
serverVolumeCounts[metric.Server]++
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(serverVolumeCounts) < 2 {
|
|
||||||
glog.V(2).Infof("Not enough servers for balance (%d servers)", len(serverVolumeCounts))
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate balance metrics
|
|
||||||
totalVolumes := len(volumeMetrics)
|
|
||||||
avgVolumesPerServer := float64(totalVolumes) / float64(len(serverVolumeCounts))
|
|
||||||
|
|
||||||
maxVolumes := 0
|
|
||||||
minVolumes := totalVolumes
|
|
||||||
maxServer := ""
|
|
||||||
minServer := ""
|
|
||||||
|
|
||||||
for server, count := range serverVolumeCounts {
|
|
||||||
if count > maxVolumes {
|
|
||||||
maxVolumes = count
|
|
||||||
maxServer = server
|
|
||||||
}
|
|
||||||
if count < minVolumes {
|
|
||||||
minVolumes = count
|
|
||||||
minServer = server
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if imbalance exceeds threshold
|
|
||||||
imbalanceRatio := float64(maxVolumes-minVolumes) / avgVolumesPerServer
|
|
||||||
if imbalanceRatio <= d.threshold {
|
|
||||||
glog.V(2).Infof("Cluster is balanced (imbalance ratio: %.2f <= %.2f)", imbalanceRatio, d.threshold)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create balance task
|
|
||||||
reason := fmt.Sprintf("Cluster imbalance detected: %.1f%% (max: %d on %s, min: %d on %s, avg: %.1f)",
|
|
||||||
imbalanceRatio*100, maxVolumes, maxServer, minVolumes, minServer, avgVolumesPerServer)
|
|
||||||
|
|
||||||
task := &types.TaskDetectionResult{
|
|
||||||
TaskType: types.TaskTypeBalance,
|
|
||||||
Priority: types.TaskPriorityNormal,
|
|
||||||
Reason: reason,
|
|
||||||
ScheduleAt: time.Now(),
|
|
||||||
Parameters: map[string]interface{}{
|
|
||||||
"imbalance_ratio": imbalanceRatio,
|
|
||||||
"threshold": d.threshold,
|
|
||||||
"max_volumes": maxVolumes,
|
|
||||||
"min_volumes": minVolumes,
|
|
||||||
"avg_volumes_per_server": avgVolumesPerServer,
|
|
||||||
"max_server": maxServer,
|
|
||||||
"min_server": minServer,
|
|
||||||
"total_servers": len(serverVolumeCounts),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.V(1).Infof("🔄 Found balance task: %s", reason)
|
|
||||||
return []*types.TaskDetectionResult{task}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ScanInterval returns how often to scan
|
|
||||||
func (d *BalanceDetector) ScanInterval() time.Duration {
|
|
||||||
return d.minCheckInterval
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsEnabled returns whether the detector is enabled
|
|
||||||
func (d *BalanceDetector) IsEnabled() bool {
|
|
||||||
return d.enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetEnabled sets whether the detector is enabled
|
|
||||||
func (d *BalanceDetector) SetEnabled(enabled bool) {
|
|
||||||
d.enabled = enabled
|
|
||||||
glog.V(1).Infof("🔄 Balance detector enabled: %v", enabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetThreshold sets the imbalance threshold
|
|
||||||
func (d *BalanceDetector) SetThreshold(threshold float64) {
|
|
||||||
d.threshold = threshold
|
|
||||||
glog.V(1).Infof("🔄 Balance threshold set to: %.1f%%", threshold*100)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMinCheckInterval sets the minimum time between balance checks
|
|
||||||
func (d *BalanceDetector) SetMinCheckInterval(interval time.Duration) {
|
|
||||||
d.minCheckInterval = interval
|
|
||||||
glog.V(1).Infof("🔄 Balance check interval set to: %v", interval)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMinVolumeCount sets the minimum volume count for balance operations
|
|
||||||
func (d *BalanceDetector) SetMinVolumeCount(count int) {
|
|
||||||
d.minVolumeCount = count
|
|
||||||
glog.V(1).Infof("🔄 Balance minimum volume count set to: %d", count)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetThreshold returns the current imbalance threshold
|
|
||||||
func (d *BalanceDetector) GetThreshold() float64 {
|
|
||||||
return d.threshold
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMinCheckInterval returns the minimum check interval
|
|
||||||
func (d *BalanceDetector) GetMinCheckInterval() time.Duration {
|
|
||||||
return d.minCheckInterval
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMinVolumeCount returns the minimum volume count
|
|
||||||
func (d *BalanceDetector) GetMinVolumeCount() int {
|
|
||||||
return d.minVolumeCount
|
|
||||||
}
|
|
||||||
@@ -1,81 +1,41 @@
|
|||||||
package balance
|
package balance
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"time"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/base"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Factory creates balance task instances
|
|
||||||
type Factory struct {
|
|
||||||
*tasks.BaseTaskFactory
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFactory creates a new balance task factory
|
|
||||||
func NewFactory() *Factory {
|
|
||||||
return &Factory{
|
|
||||||
BaseTaskFactory: tasks.NewBaseTaskFactory(
|
|
||||||
types.TaskTypeBalance,
|
|
||||||
[]string{"balance", "storage", "optimization"},
|
|
||||||
"Balance data across volume servers for optimal performance",
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create creates a new balance task instance
|
|
||||||
func (f *Factory) Create(params types.TaskParams) (types.TaskInterface, error) {
|
|
||||||
// Validate parameters
|
|
||||||
if params.VolumeID == 0 {
|
|
||||||
return nil, fmt.Errorf("volume_id is required")
|
|
||||||
}
|
|
||||||
if params.Server == "" {
|
|
||||||
return nil, fmt.Errorf("server is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
task := NewTask(params.Server, params.VolumeID, params.Collection)
|
|
||||||
task.SetEstimatedDuration(task.EstimateTime(params))
|
|
||||||
|
|
||||||
return task, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shared detector and scheduler instances
|
|
||||||
var (
|
|
||||||
sharedDetector *BalanceDetector
|
|
||||||
sharedScheduler *BalanceScheduler
|
|
||||||
)
|
|
||||||
|
|
||||||
// getSharedInstances returns the shared detector and scheduler instances
|
|
||||||
func getSharedInstances() (*BalanceDetector, *BalanceScheduler) {
|
|
||||||
if sharedDetector == nil {
|
|
||||||
sharedDetector = NewBalanceDetector()
|
|
||||||
}
|
|
||||||
if sharedScheduler == nil {
|
|
||||||
sharedScheduler = NewBalanceScheduler()
|
|
||||||
}
|
|
||||||
return sharedDetector, sharedScheduler
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSharedInstances returns the shared detector and scheduler instances (public access)
|
|
||||||
func GetSharedInstances() (*BalanceDetector, *BalanceScheduler) {
|
|
||||||
return getSharedInstances()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auto-register this task when the package is imported
|
// Auto-register this task when the package is imported
|
||||||
func init() {
|
func init() {
|
||||||
factory := NewFactory()
|
RegisterBalanceTask()
|
||||||
tasks.AutoRegister(types.TaskTypeBalance, factory)
|
}
|
||||||
|
|
||||||
// Get shared instances for all registrations
|
// RegisterBalanceTask registers the balance task with the new architecture
|
||||||
detector, scheduler := getSharedInstances()
|
func RegisterBalanceTask() {
|
||||||
|
// Create configuration instance
|
||||||
|
config := NewDefaultConfig()
|
||||||
|
|
||||||
// Register with types registry
|
// Create complete task definition
|
||||||
tasks.AutoRegisterTypes(func(registry *types.TaskRegistry) {
|
taskDef := &base.TaskDefinition{
|
||||||
registry.RegisterTask(detector, scheduler)
|
Type: types.TaskTypeBalance,
|
||||||
})
|
Name: "balance",
|
||||||
|
DisplayName: "Volume Balance",
|
||||||
|
Description: "Balances volume distribution across servers",
|
||||||
|
Icon: "fas fa-balance-scale text-warning",
|
||||||
|
Capabilities: []string{"balance", "distribution"},
|
||||||
|
|
||||||
// Register with UI registry using the same instances
|
Config: config,
|
||||||
tasks.AutoRegisterUI(func(uiRegistry *types.UIRegistry) {
|
ConfigSpec: GetConfigSpec(),
|
||||||
RegisterUI(uiRegistry, detector, scheduler)
|
CreateTask: CreateTask,
|
||||||
})
|
DetectionFunc: Detection,
|
||||||
|
ScanInterval: 30 * time.Minute,
|
||||||
|
SchedulingFunc: Scheduling,
|
||||||
|
MaxConcurrent: 1,
|
||||||
|
RepeatInterval: 2 * time.Hour,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register everything with a single function call!
|
||||||
|
base.RegisterTask(taskDef)
|
||||||
}
|
}
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
package balance
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// BalanceScheduler implements TaskScheduler for balance tasks
|
|
||||||
type BalanceScheduler struct {
|
|
||||||
enabled bool
|
|
||||||
maxConcurrent int
|
|
||||||
minInterval time.Duration
|
|
||||||
lastScheduled map[string]time.Time // track when we last scheduled a balance for each task type
|
|
||||||
minServerCount int
|
|
||||||
moveDuringOffHours bool
|
|
||||||
offHoursStart string
|
|
||||||
offHoursEnd string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile-time interface assertions
|
|
||||||
var (
|
|
||||||
_ types.TaskScheduler = (*BalanceScheduler)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewBalanceScheduler creates a new balance scheduler
|
|
||||||
func NewBalanceScheduler() *BalanceScheduler {
|
|
||||||
return &BalanceScheduler{
|
|
||||||
enabled: true,
|
|
||||||
maxConcurrent: 1, // Only run one balance at a time
|
|
||||||
minInterval: 6 * time.Hour,
|
|
||||||
lastScheduled: make(map[string]time.Time),
|
|
||||||
minServerCount: 3,
|
|
||||||
moveDuringOffHours: true,
|
|
||||||
offHoursStart: "23:00",
|
|
||||||
offHoursEnd: "06:00",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTaskType returns the task type
|
|
||||||
func (s *BalanceScheduler) GetTaskType() types.TaskType {
|
|
||||||
return types.TaskTypeBalance
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanScheduleNow determines if a balance task can be scheduled
|
|
||||||
func (s *BalanceScheduler) CanScheduleNow(task *types.Task, runningTasks []*types.Task, availableWorkers []*types.Worker) bool {
|
|
||||||
if !s.enabled {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Count running balance tasks
|
|
||||||
runningBalanceCount := 0
|
|
||||||
for _, runningTask := range runningTasks {
|
|
||||||
if runningTask.Type == types.TaskTypeBalance {
|
|
||||||
runningBalanceCount++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check concurrency limit
|
|
||||||
if runningBalanceCount >= s.maxConcurrent {
|
|
||||||
glog.V(3).Infof("⏸️ Balance task blocked: too many running (%d >= %d)", runningBalanceCount, s.maxConcurrent)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check minimum interval between balance operations
|
|
||||||
if lastTime, exists := s.lastScheduled["balance"]; exists {
|
|
||||||
if time.Since(lastTime) < s.minInterval {
|
|
||||||
timeLeft := s.minInterval - time.Since(lastTime)
|
|
||||||
glog.V(3).Infof("⏸️ Balance task blocked: too soon (wait %v)", timeLeft)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we have available workers
|
|
||||||
availableWorkerCount := 0
|
|
||||||
for _, worker := range availableWorkers {
|
|
||||||
for _, capability := range worker.Capabilities {
|
|
||||||
if capability == types.TaskTypeBalance {
|
|
||||||
availableWorkerCount++
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if availableWorkerCount == 0 {
|
|
||||||
glog.V(3).Infof("⏸️ Balance task blocked: no available workers")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// All checks passed - can schedule
|
|
||||||
s.lastScheduled["balance"] = time.Now()
|
|
||||||
glog.V(2).Infof("✅ Balance task can be scheduled (running: %d/%d, workers: %d)",
|
|
||||||
runningBalanceCount, s.maxConcurrent, availableWorkerCount)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPriority returns the priority for balance tasks
|
|
||||||
func (s *BalanceScheduler) GetPriority(task *types.Task) types.TaskPriority {
|
|
||||||
// Balance is typically normal priority - not urgent but important for optimization
|
|
||||||
return types.TaskPriorityNormal
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMaxConcurrent returns the maximum concurrent balance tasks
|
|
||||||
func (s *BalanceScheduler) GetMaxConcurrent() int {
|
|
||||||
return s.maxConcurrent
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDefaultRepeatInterval returns the default interval to wait before repeating balance tasks
|
|
||||||
func (s *BalanceScheduler) GetDefaultRepeatInterval() time.Duration {
|
|
||||||
return s.minInterval
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsEnabled returns whether the scheduler is enabled
|
|
||||||
func (s *BalanceScheduler) IsEnabled() bool {
|
|
||||||
return s.enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetEnabled sets whether the scheduler is enabled
|
|
||||||
func (s *BalanceScheduler) SetEnabled(enabled bool) {
|
|
||||||
s.enabled = enabled
|
|
||||||
glog.V(1).Infof("🔄 Balance scheduler enabled: %v", enabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMaxConcurrent sets the maximum concurrent balance tasks
|
|
||||||
func (s *BalanceScheduler) SetMaxConcurrent(max int) {
|
|
||||||
s.maxConcurrent = max
|
|
||||||
glog.V(1).Infof("🔄 Balance max concurrent set to: %d", max)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMinInterval sets the minimum interval between balance operations
|
|
||||||
func (s *BalanceScheduler) SetMinInterval(interval time.Duration) {
|
|
||||||
s.minInterval = interval
|
|
||||||
glog.V(1).Infof("🔄 Balance minimum interval set to: %v", interval)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLastScheduled returns when we last scheduled this task type
|
|
||||||
func (s *BalanceScheduler) GetLastScheduled(taskKey string) time.Time {
|
|
||||||
if lastTime, exists := s.lastScheduled[taskKey]; exists {
|
|
||||||
return lastTime
|
|
||||||
}
|
|
||||||
return time.Time{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetLastScheduled updates when we last scheduled this task type
|
|
||||||
func (s *BalanceScheduler) SetLastScheduled(taskKey string, when time.Time) {
|
|
||||||
s.lastScheduled[taskKey] = when
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMinServerCount returns the minimum server count
|
|
||||||
func (s *BalanceScheduler) GetMinServerCount() int {
|
|
||||||
return s.minServerCount
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMinServerCount sets the minimum server count
|
|
||||||
func (s *BalanceScheduler) SetMinServerCount(count int) {
|
|
||||||
s.minServerCount = count
|
|
||||||
glog.V(1).Infof("🔄 Balance minimum server count set to: %d", count)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMoveDuringOffHours returns whether to move only during off-hours
|
|
||||||
func (s *BalanceScheduler) GetMoveDuringOffHours() bool {
|
|
||||||
return s.moveDuringOffHours
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetMoveDuringOffHours sets whether to move only during off-hours
|
|
||||||
func (s *BalanceScheduler) SetMoveDuringOffHours(enabled bool) {
|
|
||||||
s.moveDuringOffHours = enabled
|
|
||||||
glog.V(1).Infof("🔄 Balance move during off-hours: %v", enabled)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetOffHoursStart returns the off-hours start time
|
|
||||||
func (s *BalanceScheduler) GetOffHoursStart() string {
|
|
||||||
return s.offHoursStart
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetOffHoursStart sets the off-hours start time
|
|
||||||
func (s *BalanceScheduler) SetOffHoursStart(start string) {
|
|
||||||
s.offHoursStart = start
|
|
||||||
glog.V(1).Infof("🔄 Balance off-hours start time set to: %s", start)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetOffHoursEnd returns the off-hours end time
|
|
||||||
func (s *BalanceScheduler) GetOffHoursEnd() string {
|
|
||||||
return s.offHoursEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetOffHoursEnd sets the off-hours end time
|
|
||||||
func (s *BalanceScheduler) SetOffHoursEnd(end string) {
|
|
||||||
s.offHoursEnd = end
|
|
||||||
glog.V(1).Infof("🔄 Balance off-hours end time set to: %s", end)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMinInterval returns the minimum interval
|
|
||||||
func (s *BalanceScheduler) GetMinInterval() time.Duration {
|
|
||||||
return s.minInterval
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package balance
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/base"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config extends BaseConfig with balance-specific settings
|
||||||
|
type Config struct {
|
||||||
|
base.BaseConfig
|
||||||
|
ImbalanceThreshold float64 `json:"imbalance_threshold"`
|
||||||
|
MinServerCount int `json:"min_server_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDefaultConfig creates a new default balance configuration
|
||||||
|
func NewDefaultConfig() *Config {
|
||||||
|
return &Config{
|
||||||
|
BaseConfig: base.BaseConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ScanIntervalSeconds: 30 * 60, // 30 minutes
|
||||||
|
MaxConcurrent: 1,
|
||||||
|
},
|
||||||
|
ImbalanceThreshold: 0.2, // 20%
|
||||||
|
MinServerCount: 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConfigSpec returns the configuration schema for balance tasks
|
||||||
|
func GetConfigSpec() base.ConfigSpec {
|
||||||
|
return base.ConfigSpec{
|
||||||
|
Fields: []*config.Field{
|
||||||
|
{
|
||||||
|
Name: "enabled",
|
||||||
|
JSONName: "enabled",
|
||||||
|
Type: config.FieldTypeBool,
|
||||||
|
DefaultValue: true,
|
||||||
|
Required: false,
|
||||||
|
DisplayName: "Enable Balance Tasks",
|
||||||
|
Description: "Whether balance tasks should be automatically created",
|
||||||
|
HelpText: "Toggle this to enable or disable automatic balance task generation",
|
||||||
|
InputType: "checkbox",
|
||||||
|
CSSClasses: "form-check-input",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "scan_interval_seconds",
|
||||||
|
JSONName: "scan_interval_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 30 * 60,
|
||||||
|
MinValue: 5 * 60,
|
||||||
|
MaxValue: 2 * 60 * 60,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Scan Interval",
|
||||||
|
Description: "How often to scan for volume distribution imbalances",
|
||||||
|
HelpText: "The system will check for volume distribution imbalances at this interval",
|
||||||
|
Placeholder: "30",
|
||||||
|
Unit: config.UnitMinutes,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "max_concurrent",
|
||||||
|
JSONName: "max_concurrent",
|
||||||
|
Type: config.FieldTypeInt,
|
||||||
|
DefaultValue: 1,
|
||||||
|
MinValue: 1,
|
||||||
|
MaxValue: 3,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Max Concurrent Tasks",
|
||||||
|
Description: "Maximum number of balance tasks that can run simultaneously",
|
||||||
|
HelpText: "Limits the number of balance operations running at the same time",
|
||||||
|
Placeholder: "1 (default)",
|
||||||
|
Unit: config.UnitCount,
|
||||||
|
InputType: "number",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "imbalance_threshold",
|
||||||
|
JSONName: "imbalance_threshold",
|
||||||
|
Type: config.FieldTypeFloat,
|
||||||
|
DefaultValue: 0.2,
|
||||||
|
MinValue: 0.05,
|
||||||
|
MaxValue: 0.5,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Imbalance Threshold",
|
||||||
|
Description: "Minimum imbalance ratio to trigger balancing",
|
||||||
|
HelpText: "Volume distribution imbalances above this threshold will trigger balancing",
|
||||||
|
Placeholder: "0.20 (20%)",
|
||||||
|
Unit: config.UnitNone,
|
||||||
|
InputType: "number",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "min_server_count",
|
||||||
|
JSONName: "min_server_count",
|
||||||
|
Type: config.FieldTypeInt,
|
||||||
|
DefaultValue: 2,
|
||||||
|
MinValue: 2,
|
||||||
|
MaxValue: 10,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Minimum Server Count",
|
||||||
|
Description: "Minimum number of servers required for balancing",
|
||||||
|
HelpText: "Balancing will only occur if there are at least this many servers",
|
||||||
|
Placeholder: "2 (default)",
|
||||||
|
Unit: config.UnitCount,
|
||||||
|
InputType: "number",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
package balance
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/base"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Detection implements the detection logic for balance tasks
|
||||||
|
func Detection(metrics []*types.VolumeHealthMetrics, clusterInfo *types.ClusterInfo, config base.TaskConfig) ([]*types.TaskDetectionResult, error) {
|
||||||
|
if !config.IsEnabled() {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
balanceConfig := config.(*Config)
|
||||||
|
|
||||||
|
// Skip if cluster is too small
|
||||||
|
minVolumeCount := 10
|
||||||
|
if len(metrics) < minVolumeCount {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Analyze volume distribution across servers
|
||||||
|
serverVolumeCounts := make(map[string]int)
|
||||||
|
for _, metric := range metrics {
|
||||||
|
serverVolumeCounts[metric.Server]++
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(serverVolumeCounts) < balanceConfig.MinServerCount {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate balance metrics
|
||||||
|
totalVolumes := len(metrics)
|
||||||
|
avgVolumesPerServer := float64(totalVolumes) / float64(len(serverVolumeCounts))
|
||||||
|
|
||||||
|
maxVolumes := 0
|
||||||
|
minVolumes := totalVolumes
|
||||||
|
maxServer := ""
|
||||||
|
minServer := ""
|
||||||
|
|
||||||
|
for server, count := range serverVolumeCounts {
|
||||||
|
if count > maxVolumes {
|
||||||
|
maxVolumes = count
|
||||||
|
maxServer = server
|
||||||
|
}
|
||||||
|
if count < minVolumes {
|
||||||
|
minVolumes = count
|
||||||
|
minServer = server
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if imbalance exceeds threshold
|
||||||
|
imbalanceRatio := float64(maxVolumes-minVolumes) / avgVolumesPerServer
|
||||||
|
if imbalanceRatio <= balanceConfig.ImbalanceThreshold {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create balance task
|
||||||
|
reason := fmt.Sprintf("Cluster imbalance detected: %.1f%% (max: %d on %s, min: %d on %s, avg: %.1f)",
|
||||||
|
imbalanceRatio*100, maxVolumes, maxServer, minVolumes, minServer, avgVolumesPerServer)
|
||||||
|
|
||||||
|
task := &types.TaskDetectionResult{
|
||||||
|
TaskType: types.TaskTypeBalance,
|
||||||
|
Priority: types.TaskPriorityNormal,
|
||||||
|
Reason: reason,
|
||||||
|
ScheduleAt: time.Now(),
|
||||||
|
Parameters: map[string]interface{}{
|
||||||
|
"imbalance_ratio": imbalanceRatio,
|
||||||
|
"threshold": balanceConfig.ImbalanceThreshold,
|
||||||
|
"max_volumes": maxVolumes,
|
||||||
|
"min_volumes": minVolumes,
|
||||||
|
"avg_volumes_per_server": avgVolumesPerServer,
|
||||||
|
"max_server": maxServer,
|
||||||
|
"min_server": minServer,
|
||||||
|
"total_servers": len(serverVolumeCounts),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return []*types.TaskDetectionResult{task}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scheduling implements the scheduling logic for balance tasks
|
||||||
|
func Scheduling(task *types.Task, runningTasks []*types.Task, availableWorkers []*types.Worker, config base.TaskConfig) bool {
|
||||||
|
balanceConfig := config.(*Config)
|
||||||
|
|
||||||
|
// Count running balance tasks
|
||||||
|
runningBalanceCount := 0
|
||||||
|
for _, runningTask := range runningTasks {
|
||||||
|
if runningTask.Type == types.TaskTypeBalance {
|
||||||
|
runningBalanceCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check concurrency limit
|
||||||
|
if runningBalanceCount >= balanceConfig.MaxConcurrent {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we have available workers
|
||||||
|
availableWorkerCount := 0
|
||||||
|
for _, worker := range availableWorkers {
|
||||||
|
for _, capability := range worker.Capabilities {
|
||||||
|
if capability == types.TaskTypeBalance {
|
||||||
|
availableWorkerCount++
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return availableWorkerCount > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTask creates a new balance task instance
|
||||||
|
func CreateTask(params types.TaskParams) (types.TaskInterface, error) {
|
||||||
|
// Extract configuration from params
|
||||||
|
var config *Config
|
||||||
|
if configData, ok := params.Parameters["config"]; ok {
|
||||||
|
if configMap, ok := configData.(map[string]interface{}); ok {
|
||||||
|
config = &Config{}
|
||||||
|
if err := config.FromMap(configMap); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse balance config: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if config == nil {
|
||||||
|
config = NewDefaultConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and return the balance task using existing Task type
|
||||||
|
return NewTask(params.Server, params.VolumeID, params.Collection), nil
|
||||||
|
}
|
||||||
@@ -1,361 +0,0 @@
|
|||||||
package balance
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"html/template"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// UIProvider provides the UI for balance task configuration
|
|
||||||
type UIProvider struct {
|
|
||||||
detector *BalanceDetector
|
|
||||||
scheduler *BalanceScheduler
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewUIProvider creates a new balance UI provider
|
|
||||||
func NewUIProvider(detector *BalanceDetector, scheduler *BalanceScheduler) *UIProvider {
|
|
||||||
return &UIProvider{
|
|
||||||
detector: detector,
|
|
||||||
scheduler: scheduler,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTaskType returns the task type
|
|
||||||
func (ui *UIProvider) GetTaskType() types.TaskType {
|
|
||||||
return types.TaskTypeBalance
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDisplayName returns the human-readable name
|
|
||||||
func (ui *UIProvider) GetDisplayName() string {
|
|
||||||
return "Volume Balance"
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDescription returns a description of what this task does
|
|
||||||
func (ui *UIProvider) GetDescription() string {
|
|
||||||
return "Redistributes volumes across volume servers to optimize storage utilization and performance"
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetIcon returns the icon CSS class for this task type
|
|
||||||
func (ui *UIProvider) GetIcon() string {
|
|
||||||
return "fas fa-balance-scale text-secondary"
|
|
||||||
}
|
|
||||||
|
|
||||||
// BalanceConfig represents the balance configuration
|
|
||||||
type BalanceConfig struct {
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
ImbalanceThreshold float64 `json:"imbalance_threshold"`
|
|
||||||
ScanIntervalSeconds int `json:"scan_interval_seconds"`
|
|
||||||
MaxConcurrent int `json:"max_concurrent"`
|
|
||||||
MinServerCount int `json:"min_server_count"`
|
|
||||||
MoveDuringOffHours bool `json:"move_during_off_hours"`
|
|
||||||
OffHoursStart string `json:"off_hours_start"`
|
|
||||||
OffHoursEnd string `json:"off_hours_end"`
|
|
||||||
MinIntervalSeconds int `json:"min_interval_seconds"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper functions for duration conversion
|
|
||||||
func secondsToDuration(seconds int) time.Duration {
|
|
||||||
return time.Duration(seconds) * time.Second
|
|
||||||
}
|
|
||||||
|
|
||||||
func durationToSeconds(d time.Duration) int {
|
|
||||||
return int(d.Seconds())
|
|
||||||
}
|
|
||||||
|
|
||||||
// formatDurationForUser formats seconds as a user-friendly duration string
|
|
||||||
func formatDurationForUser(seconds int) string {
|
|
||||||
d := secondsToDuration(seconds)
|
|
||||||
if d < time.Minute {
|
|
||||||
return fmt.Sprintf("%ds", seconds)
|
|
||||||
}
|
|
||||||
if d < time.Hour {
|
|
||||||
return fmt.Sprintf("%.0fm", d.Minutes())
|
|
||||||
}
|
|
||||||
if d < 24*time.Hour {
|
|
||||||
return fmt.Sprintf("%.1fh", d.Hours())
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%.1fd", d.Hours()/24)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RenderConfigForm renders the configuration form HTML
|
|
||||||
func (ui *UIProvider) RenderConfigForm(currentConfig interface{}) (template.HTML, error) {
|
|
||||||
config := ui.getCurrentBalanceConfig()
|
|
||||||
|
|
||||||
// Build form using the FormBuilder helper
|
|
||||||
form := types.NewFormBuilder()
|
|
||||||
|
|
||||||
// Detection Settings
|
|
||||||
form.AddCheckboxField(
|
|
||||||
"enabled",
|
|
||||||
"Enable Balance Tasks",
|
|
||||||
"Whether balance tasks should be automatically created",
|
|
||||||
config.Enabled,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddNumberField(
|
|
||||||
"imbalance_threshold",
|
|
||||||
"Imbalance Threshold (%)",
|
|
||||||
"Trigger balance when storage imbalance exceeds this percentage (0.0-1.0)",
|
|
||||||
config.ImbalanceThreshold,
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddDurationField("scan_interval", "Scan Interval", "How often to scan for imbalanced volumes", secondsToDuration(config.ScanIntervalSeconds), true)
|
|
||||||
|
|
||||||
// Scheduling Settings
|
|
||||||
form.AddNumberField(
|
|
||||||
"max_concurrent",
|
|
||||||
"Max Concurrent Tasks",
|
|
||||||
"Maximum number of balance tasks that can run simultaneously",
|
|
||||||
float64(config.MaxConcurrent),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddNumberField(
|
|
||||||
"min_server_count",
|
|
||||||
"Minimum Server Count",
|
|
||||||
"Only balance when at least this many servers are available",
|
|
||||||
float64(config.MinServerCount),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Timing Settings
|
|
||||||
form.AddCheckboxField(
|
|
||||||
"move_during_off_hours",
|
|
||||||
"Restrict to Off-Hours",
|
|
||||||
"Only perform balance operations during off-peak hours",
|
|
||||||
config.MoveDuringOffHours,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddTextField(
|
|
||||||
"off_hours_start",
|
|
||||||
"Off-Hours Start Time",
|
|
||||||
"Start time for off-hours window (e.g., 23:00)",
|
|
||||||
config.OffHoursStart,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddTextField(
|
|
||||||
"off_hours_end",
|
|
||||||
"Off-Hours End Time",
|
|
||||||
"End time for off-hours window (e.g., 06:00)",
|
|
||||||
config.OffHoursEnd,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Timing constraints
|
|
||||||
form.AddDurationField("min_interval", "Min Interval", "Minimum time between balance operations", secondsToDuration(config.MinIntervalSeconds), true)
|
|
||||||
|
|
||||||
// Generate organized form sections using Bootstrap components
|
|
||||||
html := `
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-12">
|
|
||||||
<div class="card mb-4">
|
|
||||||
<div class="card-header">
|
|
||||||
<h5 class="mb-0">
|
|
||||||
<i class="fas fa-balance-scale me-2"></i>
|
|
||||||
Balance Configuration
|
|
||||||
</h5>
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
` + string(form.Build()) + `
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-12">
|
|
||||||
<div class="card mb-3">
|
|
||||||
<div class="card-header">
|
|
||||||
<h5 class="mb-0">
|
|
||||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
|
||||||
Performance Considerations
|
|
||||||
</h5>
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="alert alert-warning" role="alert">
|
|
||||||
<h6 class="alert-heading">Important Considerations:</h6>
|
|
||||||
<p class="mb-2"><strong>Performance:</strong> Volume balancing involves data movement and can impact cluster performance.</p>
|
|
||||||
<p class="mb-2"><strong>Recommendation:</strong> Enable off-hours restriction to minimize impact on production workloads.</p>
|
|
||||||
<p class="mb-0"><strong>Safety:</strong> Requires at least ` + fmt.Sprintf("%d", config.MinServerCount) + ` servers to ensure data safety during moves.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>`
|
|
||||||
|
|
||||||
return template.HTML(html), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigForm parses form data into configuration
|
|
||||||
func (ui *UIProvider) ParseConfigForm(formData map[string][]string) (interface{}, error) {
|
|
||||||
config := &BalanceConfig{}
|
|
||||||
|
|
||||||
// Parse enabled
|
|
||||||
config.Enabled = len(formData["enabled"]) > 0
|
|
||||||
|
|
||||||
// Parse imbalance threshold
|
|
||||||
if values, ok := formData["imbalance_threshold"]; ok && len(values) > 0 {
|
|
||||||
threshold, err := strconv.ParseFloat(values[0], 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid imbalance threshold: %w", err)
|
|
||||||
}
|
|
||||||
if threshold < 0 || threshold > 1 {
|
|
||||||
return nil, fmt.Errorf("imbalance threshold must be between 0.0 and 1.0")
|
|
||||||
}
|
|
||||||
config.ImbalanceThreshold = threshold
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse scan interval
|
|
||||||
if values, ok := formData["scan_interval"]; ok && len(values) > 0 {
|
|
||||||
duration, err := time.ParseDuration(values[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid scan interval: %w", err)
|
|
||||||
}
|
|
||||||
config.ScanIntervalSeconds = int(duration.Seconds())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse max concurrent
|
|
||||||
if values, ok := formData["max_concurrent"]; ok && len(values) > 0 {
|
|
||||||
maxConcurrent, err := strconv.Atoi(values[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid max concurrent: %w", err)
|
|
||||||
}
|
|
||||||
if maxConcurrent < 1 {
|
|
||||||
return nil, fmt.Errorf("max concurrent must be at least 1")
|
|
||||||
}
|
|
||||||
config.MaxConcurrent = maxConcurrent
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse min server count
|
|
||||||
if values, ok := formData["min_server_count"]; ok && len(values) > 0 {
|
|
||||||
minServerCount, err := strconv.Atoi(values[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid min server count: %w", err)
|
|
||||||
}
|
|
||||||
if minServerCount < 2 {
|
|
||||||
return nil, fmt.Errorf("min server count must be at least 2")
|
|
||||||
}
|
|
||||||
config.MinServerCount = minServerCount
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse off-hours settings
|
|
||||||
config.MoveDuringOffHours = len(formData["move_during_off_hours"]) > 0
|
|
||||||
|
|
||||||
if values, ok := formData["off_hours_start"]; ok && len(values) > 0 {
|
|
||||||
config.OffHoursStart = values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if values, ok := formData["off_hours_end"]; ok && len(values) > 0 {
|
|
||||||
config.OffHoursEnd = values[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse min interval
|
|
||||||
if values, ok := formData["min_interval"]; ok && len(values) > 0 {
|
|
||||||
duration, err := time.ParseDuration(values[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid min interval: %w", err)
|
|
||||||
}
|
|
||||||
config.MinIntervalSeconds = int(duration.Seconds())
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCurrentConfig returns the current configuration
|
|
||||||
func (ui *UIProvider) GetCurrentConfig() interface{} {
|
|
||||||
return ui.getCurrentBalanceConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyConfig applies the new configuration
|
|
||||||
func (ui *UIProvider) ApplyConfig(config interface{}) error {
|
|
||||||
balanceConfig, ok := config.(*BalanceConfig)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("invalid config type, expected *BalanceConfig")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply to detector
|
|
||||||
if ui.detector != nil {
|
|
||||||
ui.detector.SetEnabled(balanceConfig.Enabled)
|
|
||||||
ui.detector.SetThreshold(balanceConfig.ImbalanceThreshold)
|
|
||||||
ui.detector.SetMinCheckInterval(secondsToDuration(balanceConfig.ScanIntervalSeconds))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply to scheduler
|
|
||||||
if ui.scheduler != nil {
|
|
||||||
ui.scheduler.SetEnabled(balanceConfig.Enabled)
|
|
||||||
ui.scheduler.SetMaxConcurrent(balanceConfig.MaxConcurrent)
|
|
||||||
ui.scheduler.SetMinServerCount(balanceConfig.MinServerCount)
|
|
||||||
ui.scheduler.SetMoveDuringOffHours(balanceConfig.MoveDuringOffHours)
|
|
||||||
ui.scheduler.SetOffHoursStart(balanceConfig.OffHoursStart)
|
|
||||||
ui.scheduler.SetOffHoursEnd(balanceConfig.OffHoursEnd)
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.V(1).Infof("Applied balance configuration: enabled=%v, threshold=%.1f%%, max_concurrent=%d, min_servers=%d, off_hours=%v",
|
|
||||||
balanceConfig.Enabled, balanceConfig.ImbalanceThreshold*100, balanceConfig.MaxConcurrent,
|
|
||||||
balanceConfig.MinServerCount, balanceConfig.MoveDuringOffHours)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// getCurrentBalanceConfig gets the current configuration from detector and scheduler
|
|
||||||
func (ui *UIProvider) getCurrentBalanceConfig() *BalanceConfig {
|
|
||||||
config := &BalanceConfig{
|
|
||||||
// Default values (fallback if detectors/schedulers are nil)
|
|
||||||
Enabled: true,
|
|
||||||
ImbalanceThreshold: 0.1, // 10% imbalance
|
|
||||||
ScanIntervalSeconds: durationToSeconds(4 * time.Hour),
|
|
||||||
MaxConcurrent: 1,
|
|
||||||
MinServerCount: 3,
|
|
||||||
MoveDuringOffHours: true,
|
|
||||||
OffHoursStart: "23:00",
|
|
||||||
OffHoursEnd: "06:00",
|
|
||||||
MinIntervalSeconds: durationToSeconds(1 * time.Hour),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current values from detector
|
|
||||||
if ui.detector != nil {
|
|
||||||
config.Enabled = ui.detector.IsEnabled()
|
|
||||||
config.ImbalanceThreshold = ui.detector.GetThreshold()
|
|
||||||
config.ScanIntervalSeconds = int(ui.detector.ScanInterval().Seconds())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current values from scheduler
|
|
||||||
if ui.scheduler != nil {
|
|
||||||
config.MaxConcurrent = ui.scheduler.GetMaxConcurrent()
|
|
||||||
config.MinServerCount = ui.scheduler.GetMinServerCount()
|
|
||||||
config.MoveDuringOffHours = ui.scheduler.GetMoveDuringOffHours()
|
|
||||||
config.OffHoursStart = ui.scheduler.GetOffHoursStart()
|
|
||||||
config.OffHoursEnd = ui.scheduler.GetOffHoursEnd()
|
|
||||||
}
|
|
||||||
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterUI registers the balance UI provider with the UI registry
|
|
||||||
func RegisterUI(uiRegistry *types.UIRegistry, detector *BalanceDetector, scheduler *BalanceScheduler) {
|
|
||||||
uiProvider := NewUIProvider(detector, scheduler)
|
|
||||||
uiRegistry.RegisterUI(uiProvider)
|
|
||||||
|
|
||||||
glog.V(1).Infof("✅ Registered balance task UI provider")
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultBalanceConfig returns default balance configuration
|
|
||||||
func DefaultBalanceConfig() *BalanceConfig {
|
|
||||||
return &BalanceConfig{
|
|
||||||
Enabled: false,
|
|
||||||
ImbalanceThreshold: 0.3,
|
|
||||||
ScanIntervalSeconds: durationToSeconds(4 * time.Hour),
|
|
||||||
MaxConcurrent: 1,
|
|
||||||
MinServerCount: 3,
|
|
||||||
MoveDuringOffHours: false,
|
|
||||||
OffHoursStart: "22:00",
|
|
||||||
OffHoursEnd: "06:00",
|
|
||||||
MinIntervalSeconds: durationToSeconds(1 * time.Hour),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
package base
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GenericDetector implements TaskDetector using function-based logic
|
||||||
|
type GenericDetector struct {
|
||||||
|
taskDef *TaskDefinition
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGenericDetector creates a detector from a task definition
|
||||||
|
func NewGenericDetector(taskDef *TaskDefinition) *GenericDetector {
|
||||||
|
return &GenericDetector{taskDef: taskDef}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTaskType returns the task type
|
||||||
|
func (d *GenericDetector) GetTaskType() types.TaskType {
|
||||||
|
return d.taskDef.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanForTasks scans using the task definition's detection function
|
||||||
|
func (d *GenericDetector) ScanForTasks(volumeMetrics []*types.VolumeHealthMetrics, clusterInfo *types.ClusterInfo) ([]*types.TaskDetectionResult, error) {
|
||||||
|
if d.taskDef.DetectionFunc == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return d.taskDef.DetectionFunc(volumeMetrics, clusterInfo, d.taskDef.Config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanInterval returns the scan interval from task definition
|
||||||
|
func (d *GenericDetector) ScanInterval() time.Duration {
|
||||||
|
if d.taskDef.ScanInterval > 0 {
|
||||||
|
return d.taskDef.ScanInterval
|
||||||
|
}
|
||||||
|
return 30 * time.Minute // Default
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsEnabled returns whether this detector is enabled
|
||||||
|
func (d *GenericDetector) IsEnabled() bool {
|
||||||
|
return d.taskDef.Config.IsEnabled()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenericScheduler implements TaskScheduler using function-based logic
|
||||||
|
type GenericScheduler struct {
|
||||||
|
taskDef *TaskDefinition
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGenericScheduler creates a scheduler from a task definition
|
||||||
|
func NewGenericScheduler(taskDef *TaskDefinition) *GenericScheduler {
|
||||||
|
return &GenericScheduler{taskDef: taskDef}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTaskType returns the task type
|
||||||
|
func (s *GenericScheduler) GetTaskType() types.TaskType {
|
||||||
|
return s.taskDef.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
// CanScheduleNow determines if a task can be scheduled using the task definition's function
|
||||||
|
func (s *GenericScheduler) CanScheduleNow(task *types.Task, runningTasks []*types.Task, availableWorkers []*types.Worker) bool {
|
||||||
|
if s.taskDef.SchedulingFunc == nil {
|
||||||
|
return s.defaultCanSchedule(task, runningTasks, availableWorkers)
|
||||||
|
}
|
||||||
|
return s.taskDef.SchedulingFunc(task, runningTasks, availableWorkers, s.taskDef.Config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaultCanSchedule provides default scheduling logic
|
||||||
|
func (s *GenericScheduler) defaultCanSchedule(task *types.Task, runningTasks []*types.Task, availableWorkers []*types.Worker) bool {
|
||||||
|
if !s.taskDef.Config.IsEnabled() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count running tasks of this type
|
||||||
|
runningCount := 0
|
||||||
|
for _, runningTask := range runningTasks {
|
||||||
|
if runningTask.Type == s.taskDef.Type {
|
||||||
|
runningCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check concurrency limit
|
||||||
|
maxConcurrent := s.taskDef.MaxConcurrent
|
||||||
|
if maxConcurrent <= 0 {
|
||||||
|
maxConcurrent = 1 // Default
|
||||||
|
}
|
||||||
|
if runningCount >= maxConcurrent {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we have available workers
|
||||||
|
for _, worker := range availableWorkers {
|
||||||
|
if worker.CurrentLoad < worker.MaxConcurrent {
|
||||||
|
for _, capability := range worker.Capabilities {
|
||||||
|
if capability == s.taskDef.Type {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPriority returns the priority for this task
|
||||||
|
func (s *GenericScheduler) GetPriority(task *types.Task) types.TaskPriority {
|
||||||
|
return task.Priority
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMaxConcurrent returns max concurrent tasks
|
||||||
|
func (s *GenericScheduler) GetMaxConcurrent() int {
|
||||||
|
if s.taskDef.MaxConcurrent > 0 {
|
||||||
|
return s.taskDef.MaxConcurrent
|
||||||
|
}
|
||||||
|
return 1 // Default
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDefaultRepeatInterval returns the default repeat interval
|
||||||
|
func (s *GenericScheduler) GetDefaultRepeatInterval() time.Duration {
|
||||||
|
if s.taskDef.RepeatInterval > 0 {
|
||||||
|
return s.taskDef.RepeatInterval
|
||||||
|
}
|
||||||
|
return 24 * time.Hour // Default
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsEnabled returns whether this scheduler is enabled
|
||||||
|
func (s *GenericScheduler) IsEnabled() bool {
|
||||||
|
return s.taskDef.Config.IsEnabled()
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package base
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GenericFactory creates task instances using a TaskDefinition
|
||||||
|
type GenericFactory struct {
|
||||||
|
*tasks.BaseTaskFactory
|
||||||
|
taskDef *TaskDefinition
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewGenericFactory creates a generic task factory
|
||||||
|
func NewGenericFactory(taskDef *TaskDefinition) *GenericFactory {
|
||||||
|
return &GenericFactory{
|
||||||
|
BaseTaskFactory: tasks.NewBaseTaskFactory(
|
||||||
|
taskDef.Type,
|
||||||
|
taskDef.Capabilities,
|
||||||
|
taskDef.Description,
|
||||||
|
),
|
||||||
|
taskDef: taskDef,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates a task instance using the task definition
|
||||||
|
func (f *GenericFactory) Create(params types.TaskParams) (types.TaskInterface, error) {
|
||||||
|
if f.taskDef.CreateTask == nil {
|
||||||
|
return nil, fmt.Errorf("no task creation function defined for %s", f.taskDef.Type)
|
||||||
|
}
|
||||||
|
return f.taskDef.CreateTask(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenericSchemaProvider provides config schema from TaskDefinition
|
||||||
|
type GenericSchemaProvider struct {
|
||||||
|
taskDef *TaskDefinition
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConfigSchema returns the schema from task definition
|
||||||
|
func (p *GenericSchemaProvider) GetConfigSchema() *tasks.TaskConfigSchema {
|
||||||
|
return &tasks.TaskConfigSchema{
|
||||||
|
TaskName: string(p.taskDef.Type),
|
||||||
|
DisplayName: p.taskDef.DisplayName,
|
||||||
|
Description: p.taskDef.Description,
|
||||||
|
Icon: p.taskDef.Icon,
|
||||||
|
Schema: config.Schema{
|
||||||
|
Fields: p.taskDef.ConfigSpec.Fields,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenericUIProvider provides UI functionality from TaskDefinition
|
||||||
|
type GenericUIProvider struct {
|
||||||
|
taskDef *TaskDefinition
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCurrentConfig returns current config as interface{}
|
||||||
|
func (ui *GenericUIProvider) GetCurrentConfig() interface{} {
|
||||||
|
return ui.taskDef.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyConfig applies configuration
|
||||||
|
func (ui *GenericUIProvider) ApplyConfig(config interface{}) error {
|
||||||
|
if configMap, ok := config.(map[string]interface{}); ok {
|
||||||
|
return ui.taskDef.Config.FromMap(configMap)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("invalid config format for %s", ui.taskDef.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterTask registers a complete task definition with all registries
|
||||||
|
func RegisterTask(taskDef *TaskDefinition) {
|
||||||
|
// Validate task definition
|
||||||
|
if err := validateTaskDefinition(taskDef); err != nil {
|
||||||
|
glog.Errorf("Invalid task definition for %s: %v", taskDef.Type, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and register factory
|
||||||
|
factory := NewGenericFactory(taskDef)
|
||||||
|
tasks.AutoRegister(taskDef.Type, factory)
|
||||||
|
|
||||||
|
// Create and register detector/scheduler
|
||||||
|
detector := NewGenericDetector(taskDef)
|
||||||
|
scheduler := NewGenericScheduler(taskDef)
|
||||||
|
|
||||||
|
tasks.AutoRegisterTypes(func(registry *types.TaskRegistry) {
|
||||||
|
registry.RegisterTask(detector, scheduler)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Create and register schema provider
|
||||||
|
schemaProvider := &GenericSchemaProvider{taskDef: taskDef}
|
||||||
|
tasks.RegisterTaskConfigSchema(string(taskDef.Type), schemaProvider)
|
||||||
|
|
||||||
|
// Create and register UI provider
|
||||||
|
uiProvider := &GenericUIProvider{taskDef: taskDef}
|
||||||
|
tasks.AutoRegisterUI(func(uiRegistry *types.UIRegistry) {
|
||||||
|
baseUIProvider := tasks.NewBaseUIProvider(
|
||||||
|
taskDef.Type,
|
||||||
|
taskDef.DisplayName,
|
||||||
|
taskDef.Description,
|
||||||
|
taskDef.Icon,
|
||||||
|
schemaProvider.GetConfigSchema,
|
||||||
|
uiProvider.GetCurrentConfig,
|
||||||
|
uiProvider.ApplyConfig,
|
||||||
|
)
|
||||||
|
uiRegistry.RegisterUI(baseUIProvider)
|
||||||
|
})
|
||||||
|
|
||||||
|
glog.V(1).Infof("✅ Registered complete task definition: %s", taskDef.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
// validateTaskDefinition ensures the task definition is complete
|
||||||
|
func validateTaskDefinition(taskDef *TaskDefinition) error {
|
||||||
|
if taskDef.Type == "" {
|
||||||
|
return fmt.Errorf("task type is required")
|
||||||
|
}
|
||||||
|
if taskDef.Name == "" {
|
||||||
|
return fmt.Errorf("task name is required")
|
||||||
|
}
|
||||||
|
if taskDef.Config == nil {
|
||||||
|
return fmt.Errorf("task config is required")
|
||||||
|
}
|
||||||
|
if taskDef.CreateTask == nil {
|
||||||
|
return fmt.Errorf("task creation function is required")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,246 @@
|
|||||||
|
package base
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TaskDefinition encapsulates everything needed to define a complete task type
|
||||||
|
type TaskDefinition struct {
|
||||||
|
// Basic task information
|
||||||
|
Type types.TaskType
|
||||||
|
Name string
|
||||||
|
DisplayName string
|
||||||
|
Description string
|
||||||
|
Icon string
|
||||||
|
Capabilities []string
|
||||||
|
|
||||||
|
// Task configuration
|
||||||
|
Config TaskConfig
|
||||||
|
ConfigSpec ConfigSpec
|
||||||
|
|
||||||
|
// Task creation
|
||||||
|
CreateTask func(params types.TaskParams) (types.TaskInterface, error)
|
||||||
|
|
||||||
|
// Detection logic
|
||||||
|
DetectionFunc func(metrics []*types.VolumeHealthMetrics, info *types.ClusterInfo, config TaskConfig) ([]*types.TaskDetectionResult, error)
|
||||||
|
ScanInterval time.Duration
|
||||||
|
|
||||||
|
// Scheduling logic
|
||||||
|
SchedulingFunc func(task *types.Task, running []*types.Task, workers []*types.Worker, config TaskConfig) bool
|
||||||
|
MaxConcurrent int
|
||||||
|
RepeatInterval time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskConfig provides a simple configuration interface
|
||||||
|
type TaskConfig interface {
|
||||||
|
IsEnabled() bool
|
||||||
|
SetEnabled(bool)
|
||||||
|
Validate() error
|
||||||
|
ToMap() map[string]interface{}
|
||||||
|
FromMap(map[string]interface{}) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfigSpec defines the configuration schema
|
||||||
|
type ConfigSpec struct {
|
||||||
|
Fields []*config.Field
|
||||||
|
}
|
||||||
|
|
||||||
|
// BaseConfig provides common configuration fields with reflection-based serialization
|
||||||
|
type BaseConfig struct {
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
ScanIntervalSeconds int `json:"scan_interval_seconds"`
|
||||||
|
MaxConcurrent int `json:"max_concurrent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsEnabled returns whether the task is enabled
|
||||||
|
func (c *BaseConfig) IsEnabled() bool {
|
||||||
|
return c.Enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEnabled sets whether the task is enabled
|
||||||
|
func (c *BaseConfig) SetEnabled(enabled bool) {
|
||||||
|
c.Enabled = enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate validates the base configuration
|
||||||
|
func (c *BaseConfig) Validate() error {
|
||||||
|
// Common validation logic
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StructToMap converts any struct to a map using reflection
|
||||||
|
func StructToMap(obj interface{}) map[string]interface{} {
|
||||||
|
result := make(map[string]interface{})
|
||||||
|
val := reflect.ValueOf(obj)
|
||||||
|
|
||||||
|
// Handle pointer to struct
|
||||||
|
if val.Kind() == reflect.Ptr {
|
||||||
|
val = val.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
if val.Kind() != reflect.Struct {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
typ := val.Type()
|
||||||
|
for i := 0; i < val.NumField(); i++ {
|
||||||
|
field := val.Field(i)
|
||||||
|
fieldType := typ.Field(i)
|
||||||
|
|
||||||
|
// Skip unexported fields
|
||||||
|
if !field.CanInterface() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get JSON tag name
|
||||||
|
jsonTag := fieldType.Tag.Get("json")
|
||||||
|
if jsonTag == "" || jsonTag == "-" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove options like ",omitempty"
|
||||||
|
if commaIdx := strings.Index(jsonTag, ","); commaIdx >= 0 {
|
||||||
|
jsonTag = jsonTag[:commaIdx]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle embedded structs recursively
|
||||||
|
if field.Kind() == reflect.Struct && fieldType.Anonymous {
|
||||||
|
embeddedMap := StructToMap(field.Interface())
|
||||||
|
for k, v := range embeddedMap {
|
||||||
|
result[k] = v
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result[jsonTag] = field.Interface()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapToStruct loads data from map into struct using reflection
|
||||||
|
func MapToStruct(data map[string]interface{}, obj interface{}) error {
|
||||||
|
val := reflect.ValueOf(obj)
|
||||||
|
|
||||||
|
// Must be pointer to struct
|
||||||
|
if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct {
|
||||||
|
return fmt.Errorf("obj must be pointer to struct")
|
||||||
|
}
|
||||||
|
|
||||||
|
val = val.Elem()
|
||||||
|
typ := val.Type()
|
||||||
|
|
||||||
|
for i := 0; i < val.NumField(); i++ {
|
||||||
|
field := val.Field(i)
|
||||||
|
fieldType := typ.Field(i)
|
||||||
|
|
||||||
|
// Skip unexported fields
|
||||||
|
if !field.CanSet() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get JSON tag name
|
||||||
|
jsonTag := fieldType.Tag.Get("json")
|
||||||
|
if jsonTag == "" || jsonTag == "-" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove options like ",omitempty"
|
||||||
|
if commaIdx := strings.Index(jsonTag, ","); commaIdx >= 0 {
|
||||||
|
jsonTag = jsonTag[:commaIdx]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle embedded structs recursively
|
||||||
|
if field.Kind() == reflect.Struct && fieldType.Anonymous {
|
||||||
|
err := MapToStruct(data, field.Addr().Interface())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if value, exists := data[jsonTag]; exists {
|
||||||
|
err := setFieldValue(field, value)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to set field %s: %v", jsonTag, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToMap converts config to map using reflection
|
||||||
|
func (c *BaseConfig) ToMap() map[string]interface{} {
|
||||||
|
return StructToMap(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromMap loads config from map using reflection
|
||||||
|
func (c *BaseConfig) FromMap(data map[string]interface{}) error {
|
||||||
|
return MapToStruct(data, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// setFieldValue sets a field value with type conversion
|
||||||
|
func setFieldValue(field reflect.Value, value interface{}) error {
|
||||||
|
if value == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
valueVal := reflect.ValueOf(value)
|
||||||
|
fieldType := field.Type()
|
||||||
|
valueType := valueVal.Type()
|
||||||
|
|
||||||
|
// Direct assignment if types match
|
||||||
|
if valueType.AssignableTo(fieldType) {
|
||||||
|
field.Set(valueVal)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type conversion for common cases
|
||||||
|
switch fieldType.Kind() {
|
||||||
|
case reflect.Bool:
|
||||||
|
if b, ok := value.(bool); ok {
|
||||||
|
field.SetBool(b)
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("cannot convert %T to bool", value)
|
||||||
|
}
|
||||||
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
|
switch v := value.(type) {
|
||||||
|
case int:
|
||||||
|
field.SetInt(int64(v))
|
||||||
|
case int32:
|
||||||
|
field.SetInt(int64(v))
|
||||||
|
case int64:
|
||||||
|
field.SetInt(v)
|
||||||
|
case float64:
|
||||||
|
field.SetInt(int64(v))
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("cannot convert %T to int", value)
|
||||||
|
}
|
||||||
|
case reflect.Float32, reflect.Float64:
|
||||||
|
switch v := value.(type) {
|
||||||
|
case float32:
|
||||||
|
field.SetFloat(float64(v))
|
||||||
|
case float64:
|
||||||
|
field.SetFloat(v)
|
||||||
|
case int:
|
||||||
|
field.SetFloat(float64(v))
|
||||||
|
case int64:
|
||||||
|
field.SetFloat(float64(v))
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("cannot convert %T to float", value)
|
||||||
|
}
|
||||||
|
case reflect.String:
|
||||||
|
if s, ok := value.(string); ok {
|
||||||
|
field.SetString(s)
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("cannot convert %T to string", value)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unsupported field type %s", fieldType.Kind())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
package erasure_coding
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/base"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config extends BaseConfig with erasure coding specific settings
|
||||||
|
type Config struct {
|
||||||
|
base.BaseConfig
|
||||||
|
QuietForSeconds int `json:"quiet_for_seconds"`
|
||||||
|
FullnessRatio float64 `json:"fullness_ratio"`
|
||||||
|
CollectionFilter string `json:"collection_filter"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDefaultConfig creates a new default erasure coding configuration
|
||||||
|
func NewDefaultConfig() *Config {
|
||||||
|
return &Config{
|
||||||
|
BaseConfig: base.BaseConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ScanIntervalSeconds: 60 * 60, // 1 hour
|
||||||
|
MaxConcurrent: 1,
|
||||||
|
},
|
||||||
|
QuietForSeconds: 300, // 5 minutes
|
||||||
|
FullnessRatio: 0.8, // 80%
|
||||||
|
CollectionFilter: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConfigSpec returns the configuration schema for erasure coding tasks
|
||||||
|
func GetConfigSpec() base.ConfigSpec {
|
||||||
|
return base.ConfigSpec{
|
||||||
|
Fields: []*config.Field{
|
||||||
|
{
|
||||||
|
Name: "enabled",
|
||||||
|
JSONName: "enabled",
|
||||||
|
Type: config.FieldTypeBool,
|
||||||
|
DefaultValue: true,
|
||||||
|
Required: false,
|
||||||
|
DisplayName: "Enable Erasure Coding Tasks",
|
||||||
|
Description: "Whether erasure coding tasks should be automatically created",
|
||||||
|
HelpText: "Toggle this to enable or disable automatic erasure coding task generation",
|
||||||
|
InputType: "checkbox",
|
||||||
|
CSSClasses: "form-check-input",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "scan_interval_seconds",
|
||||||
|
JSONName: "scan_interval_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 60 * 60,
|
||||||
|
MinValue: 10 * 60,
|
||||||
|
MaxValue: 24 * 60 * 60,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Scan Interval",
|
||||||
|
Description: "How often to scan for volumes needing erasure coding",
|
||||||
|
HelpText: "The system will check for volumes that need erasure coding at this interval",
|
||||||
|
Placeholder: "1",
|
||||||
|
Unit: config.UnitHours,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "max_concurrent",
|
||||||
|
JSONName: "max_concurrent",
|
||||||
|
Type: config.FieldTypeInt,
|
||||||
|
DefaultValue: 1,
|
||||||
|
MinValue: 1,
|
||||||
|
MaxValue: 5,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Max Concurrent Tasks",
|
||||||
|
Description: "Maximum number of erasure coding tasks that can run simultaneously",
|
||||||
|
HelpText: "Limits the number of erasure coding operations running at the same time",
|
||||||
|
Placeholder: "1 (default)",
|
||||||
|
Unit: config.UnitCount,
|
||||||
|
InputType: "number",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "quiet_for_seconds",
|
||||||
|
JSONName: "quiet_for_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 300,
|
||||||
|
MinValue: 60,
|
||||||
|
MaxValue: 3600,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Quiet Period",
|
||||||
|
Description: "Minimum time volume must be quiet before erasure coding",
|
||||||
|
HelpText: "Volume must not be modified for this duration before erasure coding",
|
||||||
|
Placeholder: "5",
|
||||||
|
Unit: config.UnitMinutes,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "fullness_ratio",
|
||||||
|
JSONName: "fullness_ratio",
|
||||||
|
Type: config.FieldTypeFloat,
|
||||||
|
DefaultValue: 0.8,
|
||||||
|
MinValue: 0.1,
|
||||||
|
MaxValue: 1.0,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Fullness Ratio",
|
||||||
|
Description: "Minimum fullness ratio to trigger erasure coding",
|
||||||
|
HelpText: "Only volumes with this fullness ratio or higher will be erasure coded",
|
||||||
|
Placeholder: "0.80 (80%)",
|
||||||
|
Unit: config.UnitNone,
|
||||||
|
InputType: "number",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "collection_filter",
|
||||||
|
JSONName: "collection_filter",
|
||||||
|
Type: config.FieldTypeString,
|
||||||
|
DefaultValue: "",
|
||||||
|
Required: false,
|
||||||
|
DisplayName: "Collection Filter",
|
||||||
|
Description: "Only process volumes from specific collections",
|
||||||
|
HelpText: "Leave empty to process all collections, or specify collection name",
|
||||||
|
Placeholder: "my_collection",
|
||||||
|
InputType: "text",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package erasure_coding
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/base"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Detection implements the detection logic for erasure coding tasks
|
||||||
|
func Detection(metrics []*types.VolumeHealthMetrics, clusterInfo *types.ClusterInfo, config base.TaskConfig) ([]*types.TaskDetectionResult, error) {
|
||||||
|
if !config.IsEnabled() {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ecConfig := config.(*Config)
|
||||||
|
var results []*types.TaskDetectionResult
|
||||||
|
now := time.Now()
|
||||||
|
quietThreshold := time.Duration(ecConfig.QuietForSeconds) * time.Second
|
||||||
|
minSizeBytes := uint64(100) * 1024 * 1024 // 100MB minimum
|
||||||
|
|
||||||
|
for _, metric := range metrics {
|
||||||
|
// Skip if already EC volume
|
||||||
|
if metric.IsECVolume {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check minimum size requirement
|
||||||
|
if metric.Size < minSizeBytes {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check collection filter if specified
|
||||||
|
if ecConfig.CollectionFilter != "" {
|
||||||
|
// Parse comma-separated collections
|
||||||
|
allowedCollections := make(map[string]bool)
|
||||||
|
for _, collection := range strings.Split(ecConfig.CollectionFilter, ",") {
|
||||||
|
allowedCollections[strings.TrimSpace(collection)] = true
|
||||||
|
}
|
||||||
|
// Skip if volume's collection is not in the allowed list
|
||||||
|
if !allowedCollections[metric.Collection] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check quiet duration and fullness criteria
|
||||||
|
if metric.Age >= quietThreshold && metric.FullnessRatio >= ecConfig.FullnessRatio {
|
||||||
|
result := &types.TaskDetectionResult{
|
||||||
|
TaskType: types.TaskTypeErasureCoding,
|
||||||
|
VolumeID: metric.VolumeID,
|
||||||
|
Server: metric.Server,
|
||||||
|
Collection: metric.Collection,
|
||||||
|
Priority: types.TaskPriorityLow, // EC is not urgent
|
||||||
|
Reason: fmt.Sprintf("Volume meets EC criteria: quiet for %.1fs (>%ds), fullness=%.1f%% (>%.1f%%), size=%.1fMB (>100MB)",
|
||||||
|
metric.Age.Seconds(), ecConfig.QuietForSeconds, metric.FullnessRatio*100, ecConfig.FullnessRatio*100,
|
||||||
|
float64(metric.Size)/(1024*1024)),
|
||||||
|
Parameters: map[string]interface{}{
|
||||||
|
"age_seconds": int(metric.Age.Seconds()),
|
||||||
|
"fullness_ratio": metric.FullnessRatio,
|
||||||
|
"size_mb": int(metric.Size / (1024 * 1024)),
|
||||||
|
},
|
||||||
|
ScheduleAt: now,
|
||||||
|
}
|
||||||
|
results = append(results, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scheduling implements the scheduling logic for erasure coding tasks
|
||||||
|
func Scheduling(task *types.Task, runningTasks []*types.Task, availableWorkers []*types.Worker, config base.TaskConfig) bool {
|
||||||
|
ecConfig := config.(*Config)
|
||||||
|
|
||||||
|
// Check if we have available workers
|
||||||
|
if len(availableWorkers) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count running EC tasks
|
||||||
|
runningCount := 0
|
||||||
|
for _, runningTask := range runningTasks {
|
||||||
|
if runningTask.Type == types.TaskTypeErasureCoding {
|
||||||
|
runningCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check concurrency limit
|
||||||
|
if runningCount >= ecConfig.MaxConcurrent {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any worker can handle EC tasks
|
||||||
|
for _, worker := range availableWorkers {
|
||||||
|
for _, capability := range worker.Capabilities {
|
||||||
|
if capability == types.TaskTypeErasureCoding {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTask creates a new erasure coding task instance
|
||||||
|
func CreateTask(params types.TaskParams) (types.TaskInterface, error) {
|
||||||
|
// Extract configuration from params
|
||||||
|
var config *Config
|
||||||
|
if configData, ok := params.Parameters["config"]; ok {
|
||||||
|
if configMap, ok := configData.(map[string]interface{}); ok {
|
||||||
|
config = &Config{}
|
||||||
|
if err := config.FromMap(configMap); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse erasure coding config: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if config == nil {
|
||||||
|
config = NewDefaultConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and return the erasure coding task using existing Task type
|
||||||
|
return NewTask(params.Server, params.VolumeID), nil
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,139 +0,0 @@
|
|||||||
package erasure_coding
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// EcDetector implements erasure coding task detection
|
|
||||||
type EcDetector struct {
|
|
||||||
enabled bool
|
|
||||||
volumeAgeHours int
|
|
||||||
fullnessRatio float64
|
|
||||||
scanInterval time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile-time interface assertions
|
|
||||||
var (
|
|
||||||
_ types.TaskDetector = (*EcDetector)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewEcDetector creates a new erasure coding detector
|
|
||||||
func NewEcDetector() *EcDetector {
|
|
||||||
return &EcDetector{
|
|
||||||
enabled: false, // Conservative default
|
|
||||||
volumeAgeHours: 24 * 7, // 1 week
|
|
||||||
fullnessRatio: 0.9, // 90% full
|
|
||||||
scanInterval: 2 * time.Hour,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTaskType returns the task type
|
|
||||||
func (d *EcDetector) GetTaskType() types.TaskType {
|
|
||||||
return types.TaskTypeErasureCoding
|
|
||||||
}
|
|
||||||
|
|
||||||
// ScanForTasks scans for volumes that should be converted to erasure coding
|
|
||||||
func (d *EcDetector) ScanForTasks(volumeMetrics []*types.VolumeHealthMetrics, clusterInfo *types.ClusterInfo) ([]*types.TaskDetectionResult, error) {
|
|
||||||
if !d.enabled {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var results []*types.TaskDetectionResult
|
|
||||||
now := time.Now()
|
|
||||||
ageThreshold := time.Duration(d.volumeAgeHours) * time.Hour
|
|
||||||
|
|
||||||
for _, metric := range volumeMetrics {
|
|
||||||
// Skip if already EC volume
|
|
||||||
if metric.IsECVolume {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check age and fullness criteria
|
|
||||||
if metric.Age >= ageThreshold && metric.FullnessRatio >= d.fullnessRatio {
|
|
||||||
// Check if volume is read-only (safe for EC conversion)
|
|
||||||
if !metric.IsReadOnly {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
result := &types.TaskDetectionResult{
|
|
||||||
TaskType: types.TaskTypeErasureCoding,
|
|
||||||
VolumeID: metric.VolumeID,
|
|
||||||
Server: metric.Server,
|
|
||||||
Collection: metric.Collection,
|
|
||||||
Priority: types.TaskPriorityLow, // EC is not urgent
|
|
||||||
Reason: "Volume is old and full enough for EC conversion",
|
|
||||||
Parameters: map[string]interface{}{
|
|
||||||
"age_hours": int(metric.Age.Hours()),
|
|
||||||
"fullness_ratio": metric.FullnessRatio,
|
|
||||||
},
|
|
||||||
ScheduleAt: now,
|
|
||||||
}
|
|
||||||
results = append(results, result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.V(2).Infof("EC detector found %d tasks to schedule", len(results))
|
|
||||||
return results, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ScanInterval returns how often this task type should be scanned
|
|
||||||
func (d *EcDetector) ScanInterval() time.Duration {
|
|
||||||
return d.scanInterval
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsEnabled returns whether this task type is enabled
|
|
||||||
func (d *EcDetector) IsEnabled() bool {
|
|
||||||
return d.enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configuration setters
|
|
||||||
|
|
||||||
func (d *EcDetector) SetEnabled(enabled bool) {
|
|
||||||
d.enabled = enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *EcDetector) SetVolumeAgeHours(hours int) {
|
|
||||||
d.volumeAgeHours = hours
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *EcDetector) SetFullnessRatio(ratio float64) {
|
|
||||||
d.fullnessRatio = ratio
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *EcDetector) SetScanInterval(interval time.Duration) {
|
|
||||||
d.scanInterval = interval
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetVolumeAgeHours returns the current volume age threshold in hours
|
|
||||||
func (d *EcDetector) GetVolumeAgeHours() int {
|
|
||||||
return d.volumeAgeHours
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetFullnessRatio returns the current fullness ratio threshold
|
|
||||||
func (d *EcDetector) GetFullnessRatio() float64 {
|
|
||||||
return d.fullnessRatio
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetScanInterval returns the scan interval
|
|
||||||
func (d *EcDetector) GetScanInterval() time.Duration {
|
|
||||||
return d.scanInterval
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConfigureFromPolicy configures the detector based on the maintenance policy
|
|
||||||
func (d *EcDetector) ConfigureFromPolicy(policy interface{}) {
|
|
||||||
// Type assert to the maintenance policy type we expect
|
|
||||||
if maintenancePolicy, ok := policy.(interface {
|
|
||||||
GetECEnabled() bool
|
|
||||||
GetECVolumeAgeHours() int
|
|
||||||
GetECFullnessRatio() float64
|
|
||||||
}); ok {
|
|
||||||
d.SetEnabled(maintenancePolicy.GetECEnabled())
|
|
||||||
d.SetVolumeAgeHours(maintenancePolicy.GetECVolumeAgeHours())
|
|
||||||
d.SetFullnessRatio(maintenancePolicy.GetECFullnessRatio())
|
|
||||||
} else {
|
|
||||||
glog.V(1).Infof("Could not configure EC detector from policy: unsupported policy type")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +1,41 @@
|
|||||||
package erasure_coding
|
package erasure_coding
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"time"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/base"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Factory creates erasure coding task instances
|
|
||||||
type Factory struct {
|
|
||||||
*tasks.BaseTaskFactory
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFactory creates a new erasure coding task factory
|
|
||||||
func NewFactory() *Factory {
|
|
||||||
return &Factory{
|
|
||||||
BaseTaskFactory: tasks.NewBaseTaskFactory(
|
|
||||||
types.TaskTypeErasureCoding,
|
|
||||||
[]string{"erasure_coding", "storage", "durability"},
|
|
||||||
"Convert volumes to erasure coded format for improved durability",
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create creates a new erasure coding task instance
|
|
||||||
func (f *Factory) Create(params types.TaskParams) (types.TaskInterface, error) {
|
|
||||||
// Validate parameters
|
|
||||||
if params.VolumeID == 0 {
|
|
||||||
return nil, fmt.Errorf("volume_id is required")
|
|
||||||
}
|
|
||||||
if params.Server == "" {
|
|
||||||
return nil, fmt.Errorf("server is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
task := NewTask(params.Server, params.VolumeID)
|
|
||||||
task.SetEstimatedDuration(task.EstimateTime(params))
|
|
||||||
|
|
||||||
return task, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shared detector and scheduler instances
|
|
||||||
var (
|
|
||||||
sharedDetector *EcDetector
|
|
||||||
sharedScheduler *Scheduler
|
|
||||||
)
|
|
||||||
|
|
||||||
// getSharedInstances returns the shared detector and scheduler instances
|
|
||||||
func getSharedInstances() (*EcDetector, *Scheduler) {
|
|
||||||
if sharedDetector == nil {
|
|
||||||
sharedDetector = NewEcDetector()
|
|
||||||
}
|
|
||||||
if sharedScheduler == nil {
|
|
||||||
sharedScheduler = NewScheduler()
|
|
||||||
}
|
|
||||||
return sharedDetector, sharedScheduler
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSharedInstances returns the shared detector and scheduler instances (public access)
|
|
||||||
func GetSharedInstances() (*EcDetector, *Scheduler) {
|
|
||||||
return getSharedInstances()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auto-register this task when the package is imported
|
// Auto-register this task when the package is imported
|
||||||
func init() {
|
func init() {
|
||||||
factory := NewFactory()
|
RegisterErasureCodingTask()
|
||||||
tasks.AutoRegister(types.TaskTypeErasureCoding, factory)
|
}
|
||||||
|
|
||||||
// Get shared instances for all registrations
|
// RegisterErasureCodingTask registers the erasure coding task with the new architecture
|
||||||
detector, scheduler := getSharedInstances()
|
func RegisterErasureCodingTask() {
|
||||||
|
// Create configuration instance
|
||||||
|
config := NewDefaultConfig()
|
||||||
|
|
||||||
// Register with types registry
|
// Create complete task definition
|
||||||
tasks.AutoRegisterTypes(func(registry *types.TaskRegistry) {
|
taskDef := &base.TaskDefinition{
|
||||||
registry.RegisterTask(detector, scheduler)
|
Type: types.TaskTypeErasureCoding,
|
||||||
})
|
Name: "erasure_coding",
|
||||||
|
DisplayName: "Erasure Coding",
|
||||||
|
Description: "Applies erasure coding to volumes for data protection",
|
||||||
|
Icon: "fas fa-shield-alt text-success",
|
||||||
|
Capabilities: []string{"erasure_coding", "data_protection"},
|
||||||
|
|
||||||
// Register with UI registry using the same instances
|
Config: config,
|
||||||
tasks.AutoRegisterUI(func(uiRegistry *types.UIRegistry) {
|
ConfigSpec: GetConfigSpec(),
|
||||||
RegisterUI(uiRegistry, detector, scheduler)
|
CreateTask: CreateTask,
|
||||||
})
|
DetectionFunc: Detection,
|
||||||
|
ScanInterval: 1 * time.Hour,
|
||||||
|
SchedulingFunc: Scheduling,
|
||||||
|
MaxConcurrent: 1,
|
||||||
|
RepeatInterval: 24 * time.Hour,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register everything with a single function call!
|
||||||
|
base.RegisterTask(taskDef)
|
||||||
}
|
}
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
package erasure_coding
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Scheduler implements erasure coding task scheduling
|
|
||||||
type Scheduler struct {
|
|
||||||
maxConcurrent int
|
|
||||||
enabled bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewScheduler creates a new erasure coding scheduler
|
|
||||||
func NewScheduler() *Scheduler {
|
|
||||||
return &Scheduler{
|
|
||||||
maxConcurrent: 1, // Conservative default
|
|
||||||
enabled: false, // Conservative default
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTaskType returns the task type
|
|
||||||
func (s *Scheduler) GetTaskType() types.TaskType {
|
|
||||||
return types.TaskTypeErasureCoding
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanScheduleNow determines if an erasure coding task can be scheduled now
|
|
||||||
func (s *Scheduler) CanScheduleNow(task *types.Task, runningTasks []*types.Task, availableWorkers []*types.Worker) bool {
|
|
||||||
if !s.enabled {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we have available workers
|
|
||||||
if len(availableWorkers) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Count running EC tasks
|
|
||||||
runningCount := 0
|
|
||||||
for _, runningTask := range runningTasks {
|
|
||||||
if runningTask.Type == types.TaskTypeErasureCoding {
|
|
||||||
runningCount++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check concurrency limit
|
|
||||||
if runningCount >= s.maxConcurrent {
|
|
||||||
glog.V(3).Infof("EC scheduler: at concurrency limit (%d/%d)", runningCount, s.maxConcurrent)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if any worker can handle EC tasks
|
|
||||||
for _, worker := range availableWorkers {
|
|
||||||
for _, capability := range worker.Capabilities {
|
|
||||||
if capability == types.TaskTypeErasureCoding {
|
|
||||||
glog.V(3).Infof("EC scheduler: can schedule task for volume %d", task.VolumeID)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMaxConcurrent returns the maximum number of concurrent tasks
|
|
||||||
func (s *Scheduler) GetMaxConcurrent() int {
|
|
||||||
return s.maxConcurrent
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDefaultRepeatInterval returns the default interval to wait before repeating EC tasks
|
|
||||||
func (s *Scheduler) GetDefaultRepeatInterval() time.Duration {
|
|
||||||
return 24 * time.Hour // Don't repeat EC for 24 hours
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPriority returns the priority for this task
|
|
||||||
func (s *Scheduler) GetPriority(task *types.Task) types.TaskPriority {
|
|
||||||
return types.TaskPriorityLow // EC is not urgent
|
|
||||||
}
|
|
||||||
|
|
||||||
// WasTaskRecentlyCompleted checks if a similar task was recently completed
|
|
||||||
func (s *Scheduler) WasTaskRecentlyCompleted(task *types.Task, completedTasks []*types.Task, now time.Time) bool {
|
|
||||||
// Don't repeat EC for 24 hours
|
|
||||||
interval := 24 * time.Hour
|
|
||||||
cutoff := now.Add(-interval)
|
|
||||||
|
|
||||||
for _, completedTask := range completedTasks {
|
|
||||||
if completedTask.Type == types.TaskTypeErasureCoding &&
|
|
||||||
completedTask.VolumeID == task.VolumeID &&
|
|
||||||
completedTask.Server == task.Server &&
|
|
||||||
completedTask.Status == types.TaskStatusCompleted &&
|
|
||||||
completedTask.CompletedAt != nil &&
|
|
||||||
completedTask.CompletedAt.After(cutoff) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsEnabled returns whether this task type is enabled
|
|
||||||
func (s *Scheduler) IsEnabled() bool {
|
|
||||||
return s.enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configuration setters
|
|
||||||
|
|
||||||
func (s *Scheduler) SetEnabled(enabled bool) {
|
|
||||||
s.enabled = enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Scheduler) SetMaxConcurrent(max int) {
|
|
||||||
s.maxConcurrent = max
|
|
||||||
}
|
|
||||||
@@ -1,309 +0,0 @@
|
|||||||
package erasure_coding
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"html/template"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// UIProvider provides the UI for erasure coding task configuration
|
|
||||||
type UIProvider struct {
|
|
||||||
detector *EcDetector
|
|
||||||
scheduler *Scheduler
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewUIProvider creates a new erasure coding UI provider
|
|
||||||
func NewUIProvider(detector *EcDetector, scheduler *Scheduler) *UIProvider {
|
|
||||||
return &UIProvider{
|
|
||||||
detector: detector,
|
|
||||||
scheduler: scheduler,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTaskType returns the task type
|
|
||||||
func (ui *UIProvider) GetTaskType() types.TaskType {
|
|
||||||
return types.TaskTypeErasureCoding
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDisplayName returns the human-readable name
|
|
||||||
func (ui *UIProvider) GetDisplayName() string {
|
|
||||||
return "Erasure Coding"
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDescription returns a description of what this task does
|
|
||||||
func (ui *UIProvider) GetDescription() string {
|
|
||||||
return "Converts volumes to erasure coded format for improved data durability and fault tolerance"
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetIcon returns the icon CSS class for this task type
|
|
||||||
func (ui *UIProvider) GetIcon() string {
|
|
||||||
return "fas fa-shield-alt text-info"
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErasureCodingConfig represents the erasure coding configuration
|
|
||||||
type ErasureCodingConfig struct {
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
VolumeAgeHoursSeconds int `json:"volume_age_hours_seconds"`
|
|
||||||
FullnessRatio float64 `json:"fullness_ratio"`
|
|
||||||
ScanIntervalSeconds int `json:"scan_interval_seconds"`
|
|
||||||
MaxConcurrent int `json:"max_concurrent"`
|
|
||||||
ShardCount int `json:"shard_count"`
|
|
||||||
ParityCount int `json:"parity_count"`
|
|
||||||
CollectionFilter string `json:"collection_filter"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper functions for duration conversion
|
|
||||||
func secondsToDuration(seconds int) time.Duration {
|
|
||||||
return time.Duration(seconds) * time.Second
|
|
||||||
}
|
|
||||||
|
|
||||||
func durationToSeconds(d time.Duration) int {
|
|
||||||
return int(d.Seconds())
|
|
||||||
}
|
|
||||||
|
|
||||||
// formatDurationForUser formats seconds as a user-friendly duration string
|
|
||||||
func formatDurationForUser(seconds int) string {
|
|
||||||
d := secondsToDuration(seconds)
|
|
||||||
if d < time.Minute {
|
|
||||||
return fmt.Sprintf("%ds", seconds)
|
|
||||||
}
|
|
||||||
if d < time.Hour {
|
|
||||||
return fmt.Sprintf("%.0fm", d.Minutes())
|
|
||||||
}
|
|
||||||
if d < 24*time.Hour {
|
|
||||||
return fmt.Sprintf("%.1fh", d.Hours())
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%.1fd", d.Hours()/24)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RenderConfigForm renders the configuration form HTML
|
|
||||||
func (ui *UIProvider) RenderConfigForm(currentConfig interface{}) (template.HTML, error) {
|
|
||||||
config := ui.getCurrentECConfig()
|
|
||||||
|
|
||||||
// Build form using the FormBuilder helper
|
|
||||||
form := types.NewFormBuilder()
|
|
||||||
|
|
||||||
// Detection Settings
|
|
||||||
form.AddCheckboxField(
|
|
||||||
"enabled",
|
|
||||||
"Enable Erasure Coding Tasks",
|
|
||||||
"Whether erasure coding tasks should be automatically created",
|
|
||||||
config.Enabled,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddNumberField(
|
|
||||||
"volume_age_hours_seconds",
|
|
||||||
"Volume Age Threshold",
|
|
||||||
"Only apply erasure coding to volumes older than this duration",
|
|
||||||
float64(config.VolumeAgeHoursSeconds),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddNumberField(
|
|
||||||
"scan_interval_seconds",
|
|
||||||
"Scan Interval",
|
|
||||||
"How often to scan for volumes needing erasure coding",
|
|
||||||
float64(config.ScanIntervalSeconds),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Scheduling Settings
|
|
||||||
form.AddNumberField(
|
|
||||||
"max_concurrent",
|
|
||||||
"Max Concurrent Tasks",
|
|
||||||
"Maximum number of erasure coding tasks that can run simultaneously",
|
|
||||||
float64(config.MaxConcurrent),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Erasure Coding Parameters
|
|
||||||
form.AddNumberField(
|
|
||||||
"shard_count",
|
|
||||||
"Data Shards",
|
|
||||||
"Number of data shards for erasure coding (recommended: 10)",
|
|
||||||
float64(config.ShardCount),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddNumberField(
|
|
||||||
"parity_count",
|
|
||||||
"Parity Shards",
|
|
||||||
"Number of parity shards for erasure coding (recommended: 4)",
|
|
||||||
float64(config.ParityCount),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Generate organized form sections using Bootstrap components
|
|
||||||
html := `
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-12">
|
|
||||||
<div class="card mb-4">
|
|
||||||
<div class="card-header">
|
|
||||||
<h5 class="mb-0">
|
|
||||||
<i class="fas fa-shield-alt me-2"></i>
|
|
||||||
Erasure Coding Configuration
|
|
||||||
</h5>
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
` + string(form.Build()) + `
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-12">
|
|
||||||
<div class="card mb-3">
|
|
||||||
<div class="card-header">
|
|
||||||
<h5 class="mb-0">
|
|
||||||
<i class="fas fa-info-circle me-2"></i>
|
|
||||||
Performance Impact
|
|
||||||
</h5>
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="alert alert-info" role="alert">
|
|
||||||
<h6 class="alert-heading">Important Notes:</h6>
|
|
||||||
<p class="mb-2"><strong>Performance:</strong> Erasure coding is CPU and I/O intensive. Consider running during off-peak hours.</p>
|
|
||||||
<p class="mb-0"><strong>Durability:</strong> With ` + fmt.Sprintf("%d+%d", config.ShardCount, config.ParityCount) + ` configuration, can tolerate up to ` + fmt.Sprintf("%d", config.ParityCount) + ` shard failures.</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>`
|
|
||||||
|
|
||||||
return template.HTML(html), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigForm parses form data into configuration
|
|
||||||
func (ui *UIProvider) ParseConfigForm(formData map[string][]string) (interface{}, error) {
|
|
||||||
config := &ErasureCodingConfig{}
|
|
||||||
|
|
||||||
// Parse enabled
|
|
||||||
config.Enabled = len(formData["enabled"]) > 0
|
|
||||||
|
|
||||||
// Parse volume age hours
|
|
||||||
if values, ok := formData["volume_age_hours_seconds"]; ok && len(values) > 0 {
|
|
||||||
hours, err := strconv.Atoi(values[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid volume age hours: %w", err)
|
|
||||||
}
|
|
||||||
config.VolumeAgeHoursSeconds = hours
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse scan interval
|
|
||||||
if values, ok := formData["scan_interval_seconds"]; ok && len(values) > 0 {
|
|
||||||
interval, err := strconv.Atoi(values[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid scan interval: %w", err)
|
|
||||||
}
|
|
||||||
config.ScanIntervalSeconds = interval
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse max concurrent
|
|
||||||
if values, ok := formData["max_concurrent"]; ok && len(values) > 0 {
|
|
||||||
maxConcurrent, err := strconv.Atoi(values[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid max concurrent: %w", err)
|
|
||||||
}
|
|
||||||
if maxConcurrent < 1 {
|
|
||||||
return nil, fmt.Errorf("max concurrent must be at least 1")
|
|
||||||
}
|
|
||||||
config.MaxConcurrent = maxConcurrent
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse shard count
|
|
||||||
if values, ok := formData["shard_count"]; ok && len(values) > 0 {
|
|
||||||
shardCount, err := strconv.Atoi(values[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid shard count: %w", err)
|
|
||||||
}
|
|
||||||
if shardCount < 1 {
|
|
||||||
return nil, fmt.Errorf("shard count must be at least 1")
|
|
||||||
}
|
|
||||||
config.ShardCount = shardCount
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse parity count
|
|
||||||
if values, ok := formData["parity_count"]; ok && len(values) > 0 {
|
|
||||||
parityCount, err := strconv.Atoi(values[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid parity count: %w", err)
|
|
||||||
}
|
|
||||||
if parityCount < 1 {
|
|
||||||
return nil, fmt.Errorf("parity count must be at least 1")
|
|
||||||
}
|
|
||||||
config.ParityCount = parityCount
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCurrentConfig returns the current configuration
|
|
||||||
func (ui *UIProvider) GetCurrentConfig() interface{} {
|
|
||||||
return ui.getCurrentECConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyConfig applies the new configuration
|
|
||||||
func (ui *UIProvider) ApplyConfig(config interface{}) error {
|
|
||||||
ecConfig, ok := config.(ErasureCodingConfig)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("invalid config type, expected ErasureCodingConfig")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply to detector
|
|
||||||
if ui.detector != nil {
|
|
||||||
ui.detector.SetEnabled(ecConfig.Enabled)
|
|
||||||
ui.detector.SetVolumeAgeHours(ecConfig.VolumeAgeHoursSeconds)
|
|
||||||
ui.detector.SetScanInterval(secondsToDuration(ecConfig.ScanIntervalSeconds))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply to scheduler
|
|
||||||
if ui.scheduler != nil {
|
|
||||||
ui.scheduler.SetEnabled(ecConfig.Enabled)
|
|
||||||
ui.scheduler.SetMaxConcurrent(ecConfig.MaxConcurrent)
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.V(1).Infof("Applied erasure coding configuration: enabled=%v, age_threshold=%v, max_concurrent=%d, shards=%d+%d",
|
|
||||||
ecConfig.Enabled, ecConfig.VolumeAgeHoursSeconds, ecConfig.MaxConcurrent, ecConfig.ShardCount, ecConfig.ParityCount)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// getCurrentECConfig gets the current configuration from detector and scheduler
|
|
||||||
func (ui *UIProvider) getCurrentECConfig() ErasureCodingConfig {
|
|
||||||
config := ErasureCodingConfig{
|
|
||||||
// Default values (fallback if detectors/schedulers are nil)
|
|
||||||
Enabled: true,
|
|
||||||
VolumeAgeHoursSeconds: 24 * 3600, // 24 hours in seconds
|
|
||||||
ScanIntervalSeconds: 2 * 3600, // 2 hours in seconds
|
|
||||||
MaxConcurrent: 1,
|
|
||||||
ShardCount: 10,
|
|
||||||
ParityCount: 4,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current values from detector
|
|
||||||
if ui.detector != nil {
|
|
||||||
config.Enabled = ui.detector.IsEnabled()
|
|
||||||
config.VolumeAgeHoursSeconds = ui.detector.GetVolumeAgeHours()
|
|
||||||
config.ScanIntervalSeconds = durationToSeconds(ui.detector.ScanInterval())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current values from scheduler
|
|
||||||
if ui.scheduler != nil {
|
|
||||||
config.MaxConcurrent = ui.scheduler.GetMaxConcurrent()
|
|
||||||
}
|
|
||||||
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterUI registers the erasure coding UI provider with the UI registry
|
|
||||||
func RegisterUI(uiRegistry *types.UIRegistry, detector *EcDetector, scheduler *Scheduler) {
|
|
||||||
uiProvider := NewUIProvider(detector, scheduler)
|
|
||||||
uiRegistry.RegisterUI(uiProvider)
|
|
||||||
|
|
||||||
glog.V(1).Infof("✅ Registered erasure coding task UI provider")
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TaskConfigSchema defines the schema for task configuration
|
||||||
|
type TaskConfigSchema struct {
|
||||||
|
config.Schema // Embed common schema functionality
|
||||||
|
TaskName string `json:"task_name"`
|
||||||
|
DisplayName string `json:"display_name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskConfigSchemaProvider is an interface for providing task configuration schemas
|
||||||
|
type TaskConfigSchemaProvider interface {
|
||||||
|
GetConfigSchema() *TaskConfigSchema
|
||||||
|
}
|
||||||
|
|
||||||
|
// schemaRegistry maintains a registry of schema providers by task type
|
||||||
|
type schemaRegistry struct {
|
||||||
|
providers map[string]TaskConfigSchemaProvider
|
||||||
|
mutex sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
var globalSchemaRegistry = &schemaRegistry{
|
||||||
|
providers: make(map[string]TaskConfigSchemaProvider),
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterTaskConfigSchema registers a schema provider for a task type
|
||||||
|
func RegisterTaskConfigSchema(taskType string, provider TaskConfigSchemaProvider) {
|
||||||
|
globalSchemaRegistry.mutex.Lock()
|
||||||
|
defer globalSchemaRegistry.mutex.Unlock()
|
||||||
|
globalSchemaRegistry.providers[taskType] = provider
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTaskConfigSchema returns the schema for the specified task type
|
||||||
|
func GetTaskConfigSchema(taskType string) *TaskConfigSchema {
|
||||||
|
globalSchemaRegistry.mutex.RLock()
|
||||||
|
provider, exists := globalSchemaRegistry.providers[taskType]
|
||||||
|
globalSchemaRegistry.mutex.RUnlock()
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return provider.GetConfigSchema()
|
||||||
|
}
|
||||||
@@ -2,6 +2,10 @@ package tasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -16,6 +20,11 @@ type BaseTask struct {
|
|||||||
mutex sync.RWMutex
|
mutex sync.RWMutex
|
||||||
startTime time.Time
|
startTime time.Time
|
||||||
estimatedDuration time.Duration
|
estimatedDuration time.Duration
|
||||||
|
|
||||||
|
// Logging functionality
|
||||||
|
logFile *os.File
|
||||||
|
logger *log.Logger
|
||||||
|
logFilePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBaseTask creates a new base task
|
// NewBaseTask creates a new base task
|
||||||
@@ -95,6 +104,16 @@ func (t *BaseTask) GetEstimatedDuration() time.Duration {
|
|||||||
return t.estimatedDuration
|
return t.estimatedDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitializeTaskLogging sets up task-specific logging - can be called by worker or tasks
|
||||||
|
func (t *BaseTask) InitializeTaskLogging(workingDir, taskID string) error {
|
||||||
|
return t.initializeLogging(workingDir, taskID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloseTaskLogging properly closes task logging - can be called by worker or tasks
|
||||||
|
func (t *BaseTask) CloseTaskLogging() {
|
||||||
|
t.closeLogging()
|
||||||
|
}
|
||||||
|
|
||||||
// ExecuteTask is a wrapper that handles common task execution logic
|
// ExecuteTask is a wrapper that handles common task execution logic
|
||||||
func (t *BaseTask) ExecuteTask(ctx context.Context, params types.TaskParams, executor func(context.Context, types.TaskParams) error) error {
|
func (t *BaseTask) ExecuteTask(ctx context.Context, params types.TaskParams, executor func(context.Context, types.TaskParams) error) error {
|
||||||
t.SetStartTime(time.Now())
|
t.SetStartTime(time.Now())
|
||||||
@@ -132,6 +151,92 @@ func (t *BaseTask) ExecuteTask(ctx context.Context, params types.TaskParams, exe
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initializeLogging sets up task-specific logging to a file in the working directory
|
||||||
|
func (t *BaseTask) initializeLogging(workingDir, taskID string) error {
|
||||||
|
if workingDir == "" {
|
||||||
|
// If no working directory specified, skip file logging
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure working directory exists
|
||||||
|
if err := os.MkdirAll(workingDir, 0755); err != nil {
|
||||||
|
return fmt.Errorf("failed to create working directory %s: %v", workingDir, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create task-specific log file
|
||||||
|
timestamp := time.Now().Format("20060102_150405")
|
||||||
|
logFileName := fmt.Sprintf("%s_%s_%s.log", t.taskType, taskID, timestamp)
|
||||||
|
t.logFilePath = filepath.Join(workingDir, logFileName)
|
||||||
|
|
||||||
|
logFile, err := os.OpenFile(t.logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create log file %s: %v", t.logFilePath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.logFile = logFile
|
||||||
|
t.logger = log.New(logFile, "", log.LstdFlags|log.Lmicroseconds)
|
||||||
|
|
||||||
|
// Log task initialization
|
||||||
|
t.LogInfo("Task %s initialized for %s", taskID, t.taskType)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// closeLogging properly closes the log file
|
||||||
|
func (t *BaseTask) closeLogging() {
|
||||||
|
if t.logFile != nil {
|
||||||
|
t.LogInfo("Task completed, closing log file")
|
||||||
|
t.logFile.Close()
|
||||||
|
t.logFile = nil
|
||||||
|
t.logger = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogInfo writes an info-level log message to both glog and task log file
|
||||||
|
func (t *BaseTask) LogInfo(format string, args ...interface{}) {
|
||||||
|
message := fmt.Sprintf(format, args...)
|
||||||
|
|
||||||
|
// Always log to task file if available
|
||||||
|
if t.logger != nil {
|
||||||
|
t.logger.Printf("[INFO] %s", message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogError writes an error-level log message to both glog and task log file
|
||||||
|
func (t *BaseTask) LogError(format string, args ...interface{}) {
|
||||||
|
message := fmt.Sprintf(format, args...)
|
||||||
|
|
||||||
|
// Always log to task file if available
|
||||||
|
if t.logger != nil {
|
||||||
|
t.logger.Printf("[ERROR] %s", message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogDebug writes a debug-level log message to task log file
|
||||||
|
func (t *BaseTask) LogDebug(format string, args ...interface{}) {
|
||||||
|
message := fmt.Sprintf(format, args...)
|
||||||
|
|
||||||
|
// Always log to task file if available
|
||||||
|
if t.logger != nil {
|
||||||
|
t.logger.Printf("[DEBUG] %s", message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogWarning writes a warning-level log message to both glog and task log file
|
||||||
|
func (t *BaseTask) LogWarning(format string, args ...interface{}) {
|
||||||
|
message := fmt.Sprintf(format, args...)
|
||||||
|
|
||||||
|
// Always log to task file if available
|
||||||
|
if t.logger != nil {
|
||||||
|
t.logger.Printf("[WARNING] %s", message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLogFilePath returns the path to the task's log file
|
||||||
|
func (t *BaseTask) GetLogFilePath() string {
|
||||||
|
return t.logFilePath
|
||||||
|
}
|
||||||
|
|
||||||
// TaskRegistry manages task factories
|
// TaskRegistry manages task factories
|
||||||
type TaskRegistry struct {
|
type TaskRegistry struct {
|
||||||
factories map[types.TaskType]types.TaskFactory
|
factories map[types.TaskType]types.TaskFactory
|
||||||
|
|||||||
@@ -0,0 +1,218 @@
|
|||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BaseUIProvider provides common UIProvider functionality for all tasks
|
||||||
|
type BaseUIProvider struct {
|
||||||
|
taskType types.TaskType
|
||||||
|
displayName string
|
||||||
|
description string
|
||||||
|
icon string
|
||||||
|
schemaFunc func() *TaskConfigSchema
|
||||||
|
configFunc func() interface{}
|
||||||
|
applyFunc func(config interface{}) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBaseUIProvider creates a new base UI provider
|
||||||
|
func NewBaseUIProvider(
|
||||||
|
taskType types.TaskType,
|
||||||
|
displayName string,
|
||||||
|
description string,
|
||||||
|
icon string,
|
||||||
|
schemaFunc func() *TaskConfigSchema,
|
||||||
|
configFunc func() interface{},
|
||||||
|
applyFunc func(config interface{}) error,
|
||||||
|
) *BaseUIProvider {
|
||||||
|
return &BaseUIProvider{
|
||||||
|
taskType: taskType,
|
||||||
|
displayName: displayName,
|
||||||
|
description: description,
|
||||||
|
icon: icon,
|
||||||
|
schemaFunc: schemaFunc,
|
||||||
|
configFunc: configFunc,
|
||||||
|
applyFunc: applyFunc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTaskType returns the task type
|
||||||
|
func (ui *BaseUIProvider) GetTaskType() types.TaskType {
|
||||||
|
return ui.taskType
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDisplayName returns the human-readable name
|
||||||
|
func (ui *BaseUIProvider) GetDisplayName() string {
|
||||||
|
return ui.displayName
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDescription returns a description of what this task does
|
||||||
|
func (ui *BaseUIProvider) GetDescription() string {
|
||||||
|
return ui.description
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIcon returns the icon CSS class for this task type
|
||||||
|
func (ui *BaseUIProvider) GetIcon() string {
|
||||||
|
return ui.icon
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCurrentConfig returns the current configuration
|
||||||
|
func (ui *BaseUIProvider) GetCurrentConfig() interface{} {
|
||||||
|
return ui.configFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyConfig applies the new configuration with common schema-based handling
|
||||||
|
func (ui *BaseUIProvider) ApplyConfig(config interface{}) error {
|
||||||
|
// First try direct application
|
||||||
|
if err := ui.applyFunc(config); err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: Try to get the configuration from the schema-based system
|
||||||
|
schema := ui.schemaFunc()
|
||||||
|
if schema != nil {
|
||||||
|
// Apply defaults to ensure we have a complete config
|
||||||
|
if err := schema.ApplyDefaults(config); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try again with defaults applied
|
||||||
|
if err := ui.applyFunc(config); err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Last resort: use current config
|
||||||
|
glog.Warningf("Config type conversion failed for %s, using current config", ui.taskType)
|
||||||
|
currentConfig := ui.GetCurrentConfig()
|
||||||
|
return ui.applyFunc(currentConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CommonConfigGetter provides a common pattern for getting current configuration
|
||||||
|
type CommonConfigGetter[T any] struct {
|
||||||
|
defaultConfig T
|
||||||
|
detectorFunc func() T
|
||||||
|
schedulerFunc func() T
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCommonConfigGetter creates a new common config getter
|
||||||
|
func NewCommonConfigGetter[T any](
|
||||||
|
defaultConfig T,
|
||||||
|
detectorFunc func() T,
|
||||||
|
schedulerFunc func() T,
|
||||||
|
) *CommonConfigGetter[T] {
|
||||||
|
return &CommonConfigGetter[T]{
|
||||||
|
defaultConfig: defaultConfig,
|
||||||
|
detectorFunc: detectorFunc,
|
||||||
|
schedulerFunc: schedulerFunc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConfig returns the merged configuration
|
||||||
|
func (cg *CommonConfigGetter[T]) GetConfig() T {
|
||||||
|
config := cg.defaultConfig
|
||||||
|
|
||||||
|
// Apply detector values if available
|
||||||
|
if cg.detectorFunc != nil {
|
||||||
|
detectorConfig := cg.detectorFunc()
|
||||||
|
mergeConfigs(&config, detectorConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply scheduler values if available
|
||||||
|
if cg.schedulerFunc != nil {
|
||||||
|
schedulerConfig := cg.schedulerFunc()
|
||||||
|
mergeConfigs(&config, schedulerConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
// mergeConfigs merges non-zero values from source into dest
|
||||||
|
func mergeConfigs[T any](dest *T, source T) {
|
||||||
|
destValue := reflect.ValueOf(dest).Elem()
|
||||||
|
sourceValue := reflect.ValueOf(source)
|
||||||
|
|
||||||
|
if destValue.Kind() != reflect.Struct || sourceValue.Kind() != reflect.Struct {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < destValue.NumField(); i++ {
|
||||||
|
destField := destValue.Field(i)
|
||||||
|
sourceField := sourceValue.Field(i)
|
||||||
|
|
||||||
|
if !destField.CanSet() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only copy non-zero values
|
||||||
|
if !isZeroValue(sourceField) {
|
||||||
|
if destField.Type() == sourceField.Type() {
|
||||||
|
destField.Set(sourceField)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// isZeroValue checks if a reflect.Value represents a zero value
|
||||||
|
func isZeroValue(v reflect.Value) bool {
|
||||||
|
switch v.Kind() {
|
||||||
|
case reflect.Bool:
|
||||||
|
return !v.Bool()
|
||||||
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
|
return v.Int() == 0
|
||||||
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||||
|
return v.Uint() == 0
|
||||||
|
case reflect.Float32, reflect.Float64:
|
||||||
|
return v.Float() == 0
|
||||||
|
case reflect.String:
|
||||||
|
return v.String() == ""
|
||||||
|
case reflect.Slice, reflect.Map, reflect.Array:
|
||||||
|
return v.IsNil() || v.Len() == 0
|
||||||
|
case reflect.Interface, reflect.Ptr:
|
||||||
|
return v.IsNil()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterUIFunc provides a common registration function signature
|
||||||
|
type RegisterUIFunc[D, S any] func(uiRegistry *types.UIRegistry, detector D, scheduler S)
|
||||||
|
|
||||||
|
// CommonRegisterUI provides a common registration implementation
|
||||||
|
func CommonRegisterUI[D, S any](
|
||||||
|
taskType types.TaskType,
|
||||||
|
displayName string,
|
||||||
|
uiRegistry *types.UIRegistry,
|
||||||
|
detector D,
|
||||||
|
scheduler S,
|
||||||
|
schemaFunc func() *TaskConfigSchema,
|
||||||
|
configFunc func() interface{},
|
||||||
|
applyFunc func(config interface{}) error,
|
||||||
|
) {
|
||||||
|
// Get metadata from schema
|
||||||
|
schema := schemaFunc()
|
||||||
|
description := "Task configuration"
|
||||||
|
icon := "fas fa-cog"
|
||||||
|
|
||||||
|
if schema != nil {
|
||||||
|
description = schema.Description
|
||||||
|
icon = schema.Icon
|
||||||
|
}
|
||||||
|
|
||||||
|
uiProvider := NewBaseUIProvider(
|
||||||
|
taskType,
|
||||||
|
displayName,
|
||||||
|
description,
|
||||||
|
icon,
|
||||||
|
schemaFunc,
|
||||||
|
configFunc,
|
||||||
|
applyFunc,
|
||||||
|
)
|
||||||
|
|
||||||
|
uiRegistry.RegisterUI(uiProvider)
|
||||||
|
glog.V(1).Infof("✅ Registered %s task UI provider", taskType)
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package vacuum
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/admin/config"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/base"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config extends BaseConfig with vacuum-specific settings
|
||||||
|
type Config struct {
|
||||||
|
base.BaseConfig
|
||||||
|
GarbageThreshold float64 `json:"garbage_threshold"`
|
||||||
|
MinVolumeAgeSeconds int `json:"min_volume_age_seconds"`
|
||||||
|
MinIntervalSeconds int `json:"min_interval_seconds"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDefaultConfig creates a new default vacuum configuration
|
||||||
|
func NewDefaultConfig() *Config {
|
||||||
|
return &Config{
|
||||||
|
BaseConfig: base.BaseConfig{
|
||||||
|
Enabled: true,
|
||||||
|
ScanIntervalSeconds: 2 * 60 * 60, // 2 hours
|
||||||
|
MaxConcurrent: 2,
|
||||||
|
},
|
||||||
|
GarbageThreshold: 0.3, // 30%
|
||||||
|
MinVolumeAgeSeconds: 24 * 60 * 60, // 24 hours
|
||||||
|
MinIntervalSeconds: 7 * 24 * 60 * 60, // 7 days
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConfigSpec returns the configuration schema for vacuum tasks
|
||||||
|
func GetConfigSpec() base.ConfigSpec {
|
||||||
|
return base.ConfigSpec{
|
||||||
|
Fields: []*config.Field{
|
||||||
|
{
|
||||||
|
Name: "enabled",
|
||||||
|
JSONName: "enabled",
|
||||||
|
Type: config.FieldTypeBool,
|
||||||
|
DefaultValue: true,
|
||||||
|
Required: false,
|
||||||
|
DisplayName: "Enable Vacuum Tasks",
|
||||||
|
Description: "Whether vacuum tasks should be automatically created",
|
||||||
|
HelpText: "Toggle this to enable or disable automatic vacuum task generation",
|
||||||
|
InputType: "checkbox",
|
||||||
|
CSSClasses: "form-check-input",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "scan_interval_seconds",
|
||||||
|
JSONName: "scan_interval_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 2 * 60 * 60,
|
||||||
|
MinValue: 10 * 60,
|
||||||
|
MaxValue: 24 * 60 * 60,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Scan Interval",
|
||||||
|
Description: "How often to scan for volumes needing vacuum",
|
||||||
|
HelpText: "The system will check for volumes that need vacuuming at this interval",
|
||||||
|
Placeholder: "2",
|
||||||
|
Unit: config.UnitHours,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "max_concurrent",
|
||||||
|
JSONName: "max_concurrent",
|
||||||
|
Type: config.FieldTypeInt,
|
||||||
|
DefaultValue: 2,
|
||||||
|
MinValue: 1,
|
||||||
|
MaxValue: 10,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Max Concurrent Tasks",
|
||||||
|
Description: "Maximum number of vacuum tasks that can run simultaneously",
|
||||||
|
HelpText: "Limits the number of vacuum operations running at the same time to control system load",
|
||||||
|
Placeholder: "2 (default)",
|
||||||
|
Unit: config.UnitCount,
|
||||||
|
InputType: "number",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "garbage_threshold",
|
||||||
|
JSONName: "garbage_threshold",
|
||||||
|
Type: config.FieldTypeFloat,
|
||||||
|
DefaultValue: 0.3,
|
||||||
|
MinValue: 0.0,
|
||||||
|
MaxValue: 1.0,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Garbage Percentage Threshold",
|
||||||
|
Description: "Trigger vacuum when garbage ratio exceeds this percentage",
|
||||||
|
HelpText: "Volumes with more deleted content than this threshold will be vacuumed",
|
||||||
|
Placeholder: "0.30 (30%)",
|
||||||
|
Unit: config.UnitNone,
|
||||||
|
InputType: "number",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "min_volume_age_seconds",
|
||||||
|
JSONName: "min_volume_age_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 24 * 60 * 60,
|
||||||
|
MinValue: 1 * 60 * 60,
|
||||||
|
MaxValue: 7 * 24 * 60 * 60,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Minimum Volume Age",
|
||||||
|
Description: "Only vacuum volumes older than this duration",
|
||||||
|
HelpText: "Prevents vacuuming of recently created volumes that may still be actively written to",
|
||||||
|
Placeholder: "24",
|
||||||
|
Unit: config.UnitHours,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "min_interval_seconds",
|
||||||
|
JSONName: "min_interval_seconds",
|
||||||
|
Type: config.FieldTypeInterval,
|
||||||
|
DefaultValue: 7 * 24 * 60 * 60,
|
||||||
|
MinValue: 1 * 24 * 60 * 60,
|
||||||
|
MaxValue: 30 * 24 * 60 * 60,
|
||||||
|
Required: true,
|
||||||
|
DisplayName: "Minimum Interval",
|
||||||
|
Description: "Minimum time between vacuum operations on the same volume",
|
||||||
|
HelpText: "Prevents excessive vacuuming of the same volume by enforcing a minimum wait time",
|
||||||
|
Placeholder: "7",
|
||||||
|
Unit: config.UnitDays,
|
||||||
|
InputType: "interval",
|
||||||
|
CSSClasses: "form-control",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package vacuum
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/base"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Detection implements the detection logic for vacuum tasks
|
||||||
|
func Detection(metrics []*types.VolumeHealthMetrics, clusterInfo *types.ClusterInfo, config base.TaskConfig) ([]*types.TaskDetectionResult, error) {
|
||||||
|
if !config.IsEnabled() {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
vacuumConfig := config.(*Config)
|
||||||
|
var results []*types.TaskDetectionResult
|
||||||
|
minVolumeAge := time.Duration(vacuumConfig.MinVolumeAgeSeconds) * time.Second
|
||||||
|
|
||||||
|
for _, metric := range metrics {
|
||||||
|
// Check if volume needs vacuum
|
||||||
|
if metric.GarbageRatio >= vacuumConfig.GarbageThreshold && metric.Age >= minVolumeAge {
|
||||||
|
priority := types.TaskPriorityNormal
|
||||||
|
if metric.GarbageRatio > 0.6 {
|
||||||
|
priority = types.TaskPriorityHigh
|
||||||
|
}
|
||||||
|
|
||||||
|
result := &types.TaskDetectionResult{
|
||||||
|
TaskType: types.TaskTypeVacuum,
|
||||||
|
VolumeID: metric.VolumeID,
|
||||||
|
Server: metric.Server,
|
||||||
|
Collection: metric.Collection,
|
||||||
|
Priority: priority,
|
||||||
|
Reason: "Volume has excessive garbage requiring vacuum",
|
||||||
|
Parameters: map[string]interface{}{
|
||||||
|
"garbage_ratio": metric.GarbageRatio,
|
||||||
|
"volume_age": metric.Age.String(),
|
||||||
|
},
|
||||||
|
ScheduleAt: time.Now(),
|
||||||
|
}
|
||||||
|
results = append(results, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scheduling implements the scheduling logic for vacuum tasks
|
||||||
|
func Scheduling(task *types.Task, runningTasks []*types.Task, availableWorkers []*types.Worker, config base.TaskConfig) bool {
|
||||||
|
vacuumConfig := config.(*Config)
|
||||||
|
|
||||||
|
// Count running vacuum tasks
|
||||||
|
runningVacuumCount := 0
|
||||||
|
for _, runningTask := range runningTasks {
|
||||||
|
if runningTask.Type == types.TaskTypeVacuum {
|
||||||
|
runningVacuumCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check concurrency limit
|
||||||
|
if runningVacuumCount >= vacuumConfig.MaxConcurrent {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for available workers with vacuum capability
|
||||||
|
for _, worker := range availableWorkers {
|
||||||
|
if worker.CurrentLoad < worker.MaxConcurrent {
|
||||||
|
for _, capability := range worker.Capabilities {
|
||||||
|
if capability == types.TaskTypeVacuum {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTask creates a new vacuum task instance
|
||||||
|
func CreateTask(params types.TaskParams) (types.TaskInterface, error) {
|
||||||
|
// Extract configuration from params
|
||||||
|
var config *Config
|
||||||
|
if configData, ok := params.Parameters["config"]; ok {
|
||||||
|
if configMap, ok := configData.(map[string]interface{}); ok {
|
||||||
|
config = &Config{}
|
||||||
|
if err := config.FromMap(configMap); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse vacuum config: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if config == nil {
|
||||||
|
config = NewDefaultConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and return the vacuum task using existing Task type
|
||||||
|
return NewTask(params.Server, params.VolumeID), nil
|
||||||
|
}
|
||||||
@@ -1,314 +0,0 @@
|
|||||||
package vacuum
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"html/template"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// UIProvider provides the UI for vacuum task configuration
|
|
||||||
type UIProvider struct {
|
|
||||||
detector *VacuumDetector
|
|
||||||
scheduler *VacuumScheduler
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewUIProvider creates a new vacuum UI provider
|
|
||||||
func NewUIProvider(detector *VacuumDetector, scheduler *VacuumScheduler) *UIProvider {
|
|
||||||
return &UIProvider{
|
|
||||||
detector: detector,
|
|
||||||
scheduler: scheduler,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTaskType returns the task type
|
|
||||||
func (ui *UIProvider) GetTaskType() types.TaskType {
|
|
||||||
return types.TaskTypeVacuum
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDisplayName returns the human-readable name
|
|
||||||
func (ui *UIProvider) GetDisplayName() string {
|
|
||||||
return "Volume Vacuum"
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDescription returns a description of what this task does
|
|
||||||
func (ui *UIProvider) GetDescription() string {
|
|
||||||
return "Reclaims disk space by removing deleted files from volumes"
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetIcon returns the icon CSS class for this task type
|
|
||||||
func (ui *UIProvider) GetIcon() string {
|
|
||||||
return "fas fa-broom text-primary"
|
|
||||||
}
|
|
||||||
|
|
||||||
// VacuumConfig represents the vacuum configuration
|
|
||||||
type VacuumConfig struct {
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
GarbageThreshold float64 `json:"garbage_threshold"`
|
|
||||||
ScanIntervalSeconds int `json:"scan_interval_seconds"`
|
|
||||||
MaxConcurrent int `json:"max_concurrent"`
|
|
||||||
MinVolumeAgeSeconds int `json:"min_volume_age_seconds"`
|
|
||||||
MinIntervalSeconds int `json:"min_interval_seconds"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper functions for duration conversion
|
|
||||||
func secondsToDuration(seconds int) time.Duration {
|
|
||||||
return time.Duration(seconds) * time.Second
|
|
||||||
}
|
|
||||||
|
|
||||||
func durationToSeconds(d time.Duration) int {
|
|
||||||
return int(d.Seconds())
|
|
||||||
}
|
|
||||||
|
|
||||||
// formatDurationForUser formats seconds as a user-friendly duration string
|
|
||||||
func formatDurationForUser(seconds int) string {
|
|
||||||
d := secondsToDuration(seconds)
|
|
||||||
if d < time.Minute {
|
|
||||||
return fmt.Sprintf("%ds", seconds)
|
|
||||||
}
|
|
||||||
if d < time.Hour {
|
|
||||||
return fmt.Sprintf("%.0fm", d.Minutes())
|
|
||||||
}
|
|
||||||
if d < 24*time.Hour {
|
|
||||||
return fmt.Sprintf("%.1fh", d.Hours())
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%.1fd", d.Hours()/24)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RenderConfigForm renders the configuration form HTML
|
|
||||||
func (ui *UIProvider) RenderConfigForm(currentConfig interface{}) (template.HTML, error) {
|
|
||||||
config := ui.getCurrentVacuumConfig()
|
|
||||||
|
|
||||||
// Build form using the FormBuilder helper
|
|
||||||
form := types.NewFormBuilder()
|
|
||||||
|
|
||||||
// Detection Settings
|
|
||||||
form.AddCheckboxField(
|
|
||||||
"enabled",
|
|
||||||
"Enable Vacuum Tasks",
|
|
||||||
"Whether vacuum tasks should be automatically created",
|
|
||||||
config.Enabled,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddNumberField(
|
|
||||||
"garbage_threshold",
|
|
||||||
"Garbage Threshold (%)",
|
|
||||||
"Trigger vacuum when garbage ratio exceeds this percentage (0.0-1.0)",
|
|
||||||
config.GarbageThreshold,
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddDurationField(
|
|
||||||
"scan_interval",
|
|
||||||
"Scan Interval",
|
|
||||||
"How often to scan for volumes needing vacuum",
|
|
||||||
secondsToDuration(config.ScanIntervalSeconds),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddDurationField(
|
|
||||||
"min_volume_age",
|
|
||||||
"Minimum Volume Age",
|
|
||||||
"Only vacuum volumes older than this duration",
|
|
||||||
secondsToDuration(config.MinVolumeAgeSeconds),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Scheduling Settings
|
|
||||||
form.AddNumberField(
|
|
||||||
"max_concurrent",
|
|
||||||
"Max Concurrent Tasks",
|
|
||||||
"Maximum number of vacuum tasks that can run simultaneously",
|
|
||||||
float64(config.MaxConcurrent),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
form.AddDurationField(
|
|
||||||
"min_interval",
|
|
||||||
"Minimum Interval",
|
|
||||||
"Minimum time between vacuum operations on the same volume",
|
|
||||||
secondsToDuration(config.MinIntervalSeconds),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Generate organized form sections using Bootstrap components
|
|
||||||
html := `
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-12">
|
|
||||||
<div class="card mb-4">
|
|
||||||
<div class="card-header">
|
|
||||||
<h5 class="mb-0">
|
|
||||||
<i class="fas fa-search me-2"></i>
|
|
||||||
Detection Settings
|
|
||||||
</h5>
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
` + string(form.Build()) + `
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
function resetForm() {
|
|
||||||
if (confirm('Reset all vacuum settings to defaults?')) {
|
|
||||||
// Reset to default values
|
|
||||||
document.querySelector('input[name="enabled"]').checked = true;
|
|
||||||
document.querySelector('input[name="garbage_threshold"]').value = '0.3';
|
|
||||||
document.querySelector('input[name="scan_interval"]').value = '30m';
|
|
||||||
document.querySelector('input[name="min_volume_age"]').value = '1h';
|
|
||||||
document.querySelector('input[name="max_concurrent"]').value = '2';
|
|
||||||
document.querySelector('input[name="min_interval"]').value = '6h';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
`
|
|
||||||
|
|
||||||
return template.HTML(html), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigForm parses form data into configuration
|
|
||||||
func (ui *UIProvider) ParseConfigForm(formData map[string][]string) (interface{}, error) {
|
|
||||||
config := &VacuumConfig{}
|
|
||||||
|
|
||||||
// Parse enabled checkbox
|
|
||||||
config.Enabled = len(formData["enabled"]) > 0 && formData["enabled"][0] == "on"
|
|
||||||
|
|
||||||
// Parse garbage threshold
|
|
||||||
if thresholdStr := formData["garbage_threshold"]; len(thresholdStr) > 0 {
|
|
||||||
if threshold, err := strconv.ParseFloat(thresholdStr[0], 64); err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid garbage threshold: %w", err)
|
|
||||||
} else if threshold < 0 || threshold > 1 {
|
|
||||||
return nil, fmt.Errorf("garbage threshold must be between 0.0 and 1.0")
|
|
||||||
} else {
|
|
||||||
config.GarbageThreshold = threshold
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse scan interval
|
|
||||||
if intervalStr := formData["scan_interval"]; len(intervalStr) > 0 {
|
|
||||||
if interval, err := time.ParseDuration(intervalStr[0]); err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid scan interval: %w", err)
|
|
||||||
} else {
|
|
||||||
config.ScanIntervalSeconds = durationToSeconds(interval)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse min volume age
|
|
||||||
if ageStr := formData["min_volume_age"]; len(ageStr) > 0 {
|
|
||||||
if age, err := time.ParseDuration(ageStr[0]); err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid min volume age: %w", err)
|
|
||||||
} else {
|
|
||||||
config.MinVolumeAgeSeconds = durationToSeconds(age)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse max concurrent
|
|
||||||
if concurrentStr := formData["max_concurrent"]; len(concurrentStr) > 0 {
|
|
||||||
if concurrent, err := strconv.Atoi(concurrentStr[0]); err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid max concurrent: %w", err)
|
|
||||||
} else if concurrent < 1 {
|
|
||||||
return nil, fmt.Errorf("max concurrent must be at least 1")
|
|
||||||
} else {
|
|
||||||
config.MaxConcurrent = concurrent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse min interval
|
|
||||||
if intervalStr := formData["min_interval"]; len(intervalStr) > 0 {
|
|
||||||
if interval, err := time.ParseDuration(intervalStr[0]); err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid min interval: %w", err)
|
|
||||||
} else {
|
|
||||||
config.MinIntervalSeconds = durationToSeconds(interval)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCurrentConfig returns the current configuration
|
|
||||||
func (ui *UIProvider) GetCurrentConfig() interface{} {
|
|
||||||
return ui.getCurrentVacuumConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ApplyConfig applies the new configuration
|
|
||||||
func (ui *UIProvider) ApplyConfig(config interface{}) error {
|
|
||||||
vacuumConfig, ok := config.(*VacuumConfig)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("invalid config type, expected *VacuumConfig")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply to detector
|
|
||||||
if ui.detector != nil {
|
|
||||||
ui.detector.SetEnabled(vacuumConfig.Enabled)
|
|
||||||
ui.detector.SetGarbageThreshold(vacuumConfig.GarbageThreshold)
|
|
||||||
ui.detector.SetScanInterval(secondsToDuration(vacuumConfig.ScanIntervalSeconds))
|
|
||||||
ui.detector.SetMinVolumeAge(secondsToDuration(vacuumConfig.MinVolumeAgeSeconds))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply to scheduler
|
|
||||||
if ui.scheduler != nil {
|
|
||||||
ui.scheduler.SetEnabled(vacuumConfig.Enabled)
|
|
||||||
ui.scheduler.SetMaxConcurrent(vacuumConfig.MaxConcurrent)
|
|
||||||
ui.scheduler.SetMinInterval(secondsToDuration(vacuumConfig.MinIntervalSeconds))
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.V(1).Infof("Applied vacuum configuration: enabled=%v, threshold=%.1f%%, scan_interval=%s, max_concurrent=%d",
|
|
||||||
vacuumConfig.Enabled, vacuumConfig.GarbageThreshold*100, formatDurationForUser(vacuumConfig.ScanIntervalSeconds), vacuumConfig.MaxConcurrent)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// getCurrentVacuumConfig gets the current configuration from detector and scheduler
|
|
||||||
func (ui *UIProvider) getCurrentVacuumConfig() *VacuumConfig {
|
|
||||||
config := &VacuumConfig{
|
|
||||||
// Default values (fallback if detectors/schedulers are nil)
|
|
||||||
Enabled: true,
|
|
||||||
GarbageThreshold: 0.3,
|
|
||||||
ScanIntervalSeconds: 30 * 60,
|
|
||||||
MinVolumeAgeSeconds: 1 * 60 * 60,
|
|
||||||
MaxConcurrent: 2,
|
|
||||||
MinIntervalSeconds: 6 * 60 * 60,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current values from detector
|
|
||||||
if ui.detector != nil {
|
|
||||||
config.Enabled = ui.detector.IsEnabled()
|
|
||||||
config.GarbageThreshold = ui.detector.GetGarbageThreshold()
|
|
||||||
config.ScanIntervalSeconds = durationToSeconds(ui.detector.ScanInterval())
|
|
||||||
config.MinVolumeAgeSeconds = durationToSeconds(ui.detector.GetMinVolumeAge())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current values from scheduler
|
|
||||||
if ui.scheduler != nil {
|
|
||||||
config.MaxConcurrent = ui.scheduler.GetMaxConcurrent()
|
|
||||||
config.MinIntervalSeconds = durationToSeconds(ui.scheduler.GetMinInterval())
|
|
||||||
}
|
|
||||||
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
// RegisterUI registers the vacuum UI provider with the UI registry
|
|
||||||
func RegisterUI(uiRegistry *types.UIRegistry, detector *VacuumDetector, scheduler *VacuumScheduler) {
|
|
||||||
uiProvider := NewUIProvider(detector, scheduler)
|
|
||||||
uiRegistry.RegisterUI(uiProvider)
|
|
||||||
|
|
||||||
glog.V(1).Infof("✅ Registered vacuum task UI provider")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Example: How to get the UI provider for external use
|
|
||||||
func GetUIProvider(uiRegistry *types.UIRegistry) *UIProvider {
|
|
||||||
provider := uiRegistry.GetProvider(types.TaskTypeVacuum)
|
|
||||||
if provider == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if vacuumProvider, ok := provider.(*UIProvider); ok {
|
|
||||||
return vacuumProvider
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,60 +1,161 @@
|
|||||||
package vacuum
|
package vacuum
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||||
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Task implements vacuum operation to reclaim disk space
|
// Task implements vacuum operation to reclaim disk space
|
||||||
type Task struct {
|
type Task struct {
|
||||||
*tasks.BaseTask
|
*tasks.BaseTask
|
||||||
server string
|
server string
|
||||||
volumeID uint32
|
volumeID uint32
|
||||||
|
garbageThreshold float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTask creates a new vacuum task instance
|
// NewTask creates a new vacuum task instance
|
||||||
func NewTask(server string, volumeID uint32) *Task {
|
func NewTask(server string, volumeID uint32) *Task {
|
||||||
task := &Task{
|
task := &Task{
|
||||||
BaseTask: tasks.NewBaseTask(types.TaskTypeVacuum),
|
BaseTask: tasks.NewBaseTask(types.TaskTypeVacuum),
|
||||||
server: server,
|
server: server,
|
||||||
volumeID: volumeID,
|
volumeID: volumeID,
|
||||||
|
garbageThreshold: 0.3, // Default 30% threshold
|
||||||
}
|
}
|
||||||
return task
|
return task
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute executes the vacuum task
|
// Execute performs the vacuum operation
|
||||||
func (t *Task) Execute(params types.TaskParams) error {
|
func (t *Task) Execute(params types.TaskParams) error {
|
||||||
glog.Infof("Starting vacuum task for volume %d on server %s", t.volumeID, t.server)
|
glog.Infof("Starting vacuum for volume %d on server %s", t.volumeID, t.server)
|
||||||
|
|
||||||
// Simulate vacuum operation with progress updates
|
ctx := context.Background()
|
||||||
steps := []struct {
|
|
||||||
name string
|
// Parse garbage threshold from parameters
|
||||||
duration time.Duration
|
if thresholdParam, ok := params.Parameters["garbage_threshold"]; ok {
|
||||||
progress float64
|
if thresholdStr, ok := thresholdParam.(string); ok {
|
||||||
}{
|
if threshold, err := strconv.ParseFloat(thresholdStr, 64); err == nil {
|
||||||
{"Scanning volume", 1 * time.Second, 20},
|
t.garbageThreshold = threshold
|
||||||
{"Identifying deleted files", 2 * time.Second, 50},
|
}
|
||||||
{"Compacting data", 3 * time.Second, 80},
|
}
|
||||||
{"Finalizing vacuum", 1 * time.Second, 100},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, step := range steps {
|
// Convert server address to gRPC address and use proper dial option
|
||||||
if t.IsCancelled() {
|
grpcAddress := pb.ServerToGrpcAddress(t.server)
|
||||||
return fmt.Errorf("vacuum task cancelled")
|
var dialOpt grpc.DialOption = grpc.WithTransportCredentials(insecure.NewCredentials())
|
||||||
|
if params.GrpcDialOption != nil {
|
||||||
|
dialOpt = params.GrpcDialOption
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := grpc.NewClient(grpcAddress, dialOpt)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to connect to volume server %s: %v", t.server, err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
client := volume_server_pb.NewVolumeServerClient(conn)
|
||||||
|
|
||||||
|
// Step 1: Check vacuum eligibility
|
||||||
|
t.SetProgress(10.0)
|
||||||
|
glog.V(1).Infof("Checking vacuum eligibility for volume %d", t.volumeID)
|
||||||
|
|
||||||
|
checkResp, err := client.VacuumVolumeCheck(ctx, &volume_server_pb.VacuumVolumeCheckRequest{
|
||||||
|
VolumeId: t.volumeID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("vacuum check failed for volume %d: %v", t.volumeID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if garbage ratio meets threshold
|
||||||
|
if checkResp.GarbageRatio < t.garbageThreshold {
|
||||||
|
return fmt.Errorf("volume %d garbage ratio %.2f%% is below threshold %.2f%%, skipping vacuum",
|
||||||
|
t.volumeID, checkResp.GarbageRatio*100, t.garbageThreshold*100)
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.V(1).Infof("Volume %d has %.2f%% garbage, proceeding with vacuum",
|
||||||
|
t.volumeID, checkResp.GarbageRatio*100)
|
||||||
|
|
||||||
|
// Step 2: Compact volume
|
||||||
|
t.SetProgress(30.0)
|
||||||
|
glog.V(1).Infof("Starting compact for volume %d", t.volumeID)
|
||||||
|
|
||||||
|
compactStream, err := client.VacuumVolumeCompact(ctx, &volume_server_pb.VacuumVolumeCompactRequest{
|
||||||
|
VolumeId: t.volumeID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("vacuum compact failed for volume %d: %v", t.volumeID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process compact stream and track progress
|
||||||
|
var processedBytes int64
|
||||||
|
var totalBytes int64
|
||||||
|
|
||||||
|
for {
|
||||||
|
resp, err := compactStream.Recv()
|
||||||
|
if err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return fmt.Errorf("vacuum compact stream error for volume %d: %v", t.volumeID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(1).Infof("Vacuum task step: %s", step.name)
|
processedBytes = resp.ProcessedBytes
|
||||||
t.SetProgress(step.progress)
|
if resp.LoadAvg_1M > 0 {
|
||||||
|
totalBytes = int64(resp.LoadAvg_1M) // This is a rough approximation
|
||||||
|
}
|
||||||
|
|
||||||
// Simulate work
|
// Update progress based on processed bytes (30% to 70% of total progress)
|
||||||
time.Sleep(step.duration)
|
if totalBytes > 0 {
|
||||||
|
compactProgress := float64(processedBytes) / float64(totalBytes)
|
||||||
|
if compactProgress > 1.0 {
|
||||||
|
compactProgress = 1.0
|
||||||
|
}
|
||||||
|
progress := 30.0 + (compactProgress * 40.0) // 30% to 70%
|
||||||
|
t.SetProgress(progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.V(2).Infof("Volume %d compact progress: %d bytes processed", t.volumeID, processedBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("Vacuum task completed for volume %d on server %s", t.volumeID, t.server)
|
// Step 3: Commit vacuum changes
|
||||||
|
t.SetProgress(80.0)
|
||||||
|
glog.V(1).Infof("Committing vacuum for volume %d", t.volumeID)
|
||||||
|
|
||||||
|
commitResp, err := client.VacuumVolumeCommit(ctx, &volume_server_pb.VacuumVolumeCommitRequest{
|
||||||
|
VolumeId: t.volumeID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("vacuum commit failed for volume %d: %v", t.volumeID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 4: Cleanup temporary files
|
||||||
|
t.SetProgress(90.0)
|
||||||
|
glog.V(1).Infof("Cleaning up vacuum files for volume %d", t.volumeID)
|
||||||
|
|
||||||
|
_, err = client.VacuumVolumeCleanup(ctx, &volume_server_pb.VacuumVolumeCleanupRequest{
|
||||||
|
VolumeId: t.volumeID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
// Log warning but don't fail the task
|
||||||
|
glog.Warningf("Vacuum cleanup warning for volume %d: %v", t.volumeID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.SetProgress(100.0)
|
||||||
|
|
||||||
|
newVolumeSize := commitResp.VolumeSize
|
||||||
|
glog.Infof("Successfully completed vacuum for volume %d on server %s, new volume size: %d bytes",
|
||||||
|
t.volumeID, t.server, newVolumeSize)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,9 +172,28 @@ func (t *Task) Validate(params types.TaskParams) error {
|
|||||||
|
|
||||||
// EstimateTime estimates the time needed for the task
|
// EstimateTime estimates the time needed for the task
|
||||||
func (t *Task) EstimateTime(params types.TaskParams) time.Duration {
|
func (t *Task) EstimateTime(params types.TaskParams) time.Duration {
|
||||||
// Base time for vacuum operation
|
// Base time for vacuum operations - varies by volume size and garbage ratio
|
||||||
baseTime := 25 * time.Second
|
// Typically vacuum is faster than EC encoding
|
||||||
|
baseTime := 5 * time.Minute
|
||||||
|
|
||||||
|
// Could adjust based on volume size and garbage ratio if available in params
|
||||||
|
if size, ok := params.Parameters["volume_size"].(int64); ok {
|
||||||
|
// Rough estimate: 30 seconds per GB for vacuum
|
||||||
|
estimatedTime := time.Duration(size/(1024*1024*1024)) * 30 * time.Second
|
||||||
|
if estimatedTime > baseTime {
|
||||||
|
return estimatedTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Could adjust based on volume size or usage patterns
|
|
||||||
return baseTime
|
return baseTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetProgress returns the current progress
|
||||||
|
func (t *Task) GetProgress() float64 {
|
||||||
|
return t.BaseTask.GetProgress()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel cancels the task
|
||||||
|
func (t *Task) Cancel() error {
|
||||||
|
return t.BaseTask.Cancel()
|
||||||
|
}
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
package vacuum
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// VacuumDetector implements vacuum task detection using code instead of schemas
|
|
||||||
type VacuumDetector struct {
|
|
||||||
enabled bool
|
|
||||||
garbageThreshold float64
|
|
||||||
minVolumeAge time.Duration
|
|
||||||
scanInterval time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile-time interface assertions
|
|
||||||
var (
|
|
||||||
_ types.TaskDetector = (*VacuumDetector)(nil)
|
|
||||||
_ types.PolicyConfigurableDetector = (*VacuumDetector)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewVacuumDetector creates a new simple vacuum detector
|
|
||||||
func NewVacuumDetector() *VacuumDetector {
|
|
||||||
return &VacuumDetector{
|
|
||||||
enabled: true,
|
|
||||||
garbageThreshold: 0.3,
|
|
||||||
minVolumeAge: 24 * time.Hour,
|
|
||||||
scanInterval: 30 * time.Minute,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTaskType returns the task type
|
|
||||||
func (d *VacuumDetector) GetTaskType() types.TaskType {
|
|
||||||
return types.TaskTypeVacuum
|
|
||||||
}
|
|
||||||
|
|
||||||
// ScanForTasks scans for volumes that need vacuum operations
|
|
||||||
func (d *VacuumDetector) ScanForTasks(volumeMetrics []*types.VolumeHealthMetrics, clusterInfo *types.ClusterInfo) ([]*types.TaskDetectionResult, error) {
|
|
||||||
if !d.enabled {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var results []*types.TaskDetectionResult
|
|
||||||
|
|
||||||
for _, metric := range volumeMetrics {
|
|
||||||
// Check if volume needs vacuum
|
|
||||||
if metric.GarbageRatio >= d.garbageThreshold && metric.Age >= d.minVolumeAge {
|
|
||||||
// Higher priority for volumes with more garbage
|
|
||||||
priority := types.TaskPriorityNormal
|
|
||||||
if metric.GarbageRatio > 0.6 {
|
|
||||||
priority = types.TaskPriorityHigh
|
|
||||||
}
|
|
||||||
|
|
||||||
result := &types.TaskDetectionResult{
|
|
||||||
TaskType: types.TaskTypeVacuum,
|
|
||||||
VolumeID: metric.VolumeID,
|
|
||||||
Server: metric.Server,
|
|
||||||
Collection: metric.Collection,
|
|
||||||
Priority: priority,
|
|
||||||
Reason: "Volume has excessive garbage requiring vacuum",
|
|
||||||
Parameters: map[string]interface{}{
|
|
||||||
"garbage_ratio": metric.GarbageRatio,
|
|
||||||
"volume_age": metric.Age.String(),
|
|
||||||
},
|
|
||||||
ScheduleAt: time.Now(),
|
|
||||||
}
|
|
||||||
results = append(results, result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.V(2).Infof("Vacuum detector found %d volumes needing vacuum", len(results))
|
|
||||||
return results, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ScanInterval returns how often this detector should scan
|
|
||||||
func (d *VacuumDetector) ScanInterval() time.Duration {
|
|
||||||
return d.scanInterval
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsEnabled returns whether this detector is enabled
|
|
||||||
func (d *VacuumDetector) IsEnabled() bool {
|
|
||||||
return d.enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configuration setters
|
|
||||||
|
|
||||||
func (d *VacuumDetector) SetEnabled(enabled bool) {
|
|
||||||
d.enabled = enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *VacuumDetector) SetGarbageThreshold(threshold float64) {
|
|
||||||
d.garbageThreshold = threshold
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *VacuumDetector) SetScanInterval(interval time.Duration) {
|
|
||||||
d.scanInterval = interval
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *VacuumDetector) SetMinVolumeAge(age time.Duration) {
|
|
||||||
d.minVolumeAge = age
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGarbageThreshold returns the current garbage threshold
|
|
||||||
func (d *VacuumDetector) GetGarbageThreshold() float64 {
|
|
||||||
return d.garbageThreshold
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMinVolumeAge returns the minimum volume age
|
|
||||||
func (d *VacuumDetector) GetMinVolumeAge() time.Duration {
|
|
||||||
return d.minVolumeAge
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetScanInterval returns the scan interval
|
|
||||||
func (d *VacuumDetector) GetScanInterval() time.Duration {
|
|
||||||
return d.scanInterval
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConfigureFromPolicy configures the detector based on the maintenance policy
|
|
||||||
func (d *VacuumDetector) ConfigureFromPolicy(policy interface{}) {
|
|
||||||
// Type assert to the maintenance policy type we expect
|
|
||||||
if maintenancePolicy, ok := policy.(interface {
|
|
||||||
GetVacuumEnabled() bool
|
|
||||||
GetVacuumGarbageRatio() float64
|
|
||||||
}); ok {
|
|
||||||
d.SetEnabled(maintenancePolicy.GetVacuumEnabled())
|
|
||||||
d.SetGarbageThreshold(maintenancePolicy.GetVacuumGarbageRatio())
|
|
||||||
} else {
|
|
||||||
glog.V(1).Infof("Could not configure vacuum detector from policy: unsupported policy type")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +1,41 @@
|
|||||||
package vacuum
|
package vacuum
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"time"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/tasks"
|
"github.com/seaweedfs/seaweedfs/weed/worker/tasks/base"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Factory creates vacuum task instances
|
|
||||||
type Factory struct {
|
|
||||||
*tasks.BaseTaskFactory
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFactory creates a new vacuum task factory
|
|
||||||
func NewFactory() *Factory {
|
|
||||||
return &Factory{
|
|
||||||
BaseTaskFactory: tasks.NewBaseTaskFactory(
|
|
||||||
types.TaskTypeVacuum,
|
|
||||||
[]string{"vacuum", "storage"},
|
|
||||||
"Vacuum operation to reclaim disk space by removing deleted files",
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create creates a new vacuum task instance
|
|
||||||
func (f *Factory) Create(params types.TaskParams) (types.TaskInterface, error) {
|
|
||||||
// Validate parameters
|
|
||||||
if params.VolumeID == 0 {
|
|
||||||
return nil, fmt.Errorf("volume_id is required")
|
|
||||||
}
|
|
||||||
if params.Server == "" {
|
|
||||||
return nil, fmt.Errorf("server is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
task := NewTask(params.Server, params.VolumeID)
|
|
||||||
task.SetEstimatedDuration(task.EstimateTime(params))
|
|
||||||
|
|
||||||
return task, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shared detector and scheduler instances
|
|
||||||
var (
|
|
||||||
sharedDetector *VacuumDetector
|
|
||||||
sharedScheduler *VacuumScheduler
|
|
||||||
)
|
|
||||||
|
|
||||||
// getSharedInstances returns the shared detector and scheduler instances
|
|
||||||
func getSharedInstances() (*VacuumDetector, *VacuumScheduler) {
|
|
||||||
if sharedDetector == nil {
|
|
||||||
sharedDetector = NewVacuumDetector()
|
|
||||||
}
|
|
||||||
if sharedScheduler == nil {
|
|
||||||
sharedScheduler = NewVacuumScheduler()
|
|
||||||
}
|
|
||||||
return sharedDetector, sharedScheduler
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSharedInstances returns the shared detector and scheduler instances (public access)
|
|
||||||
func GetSharedInstances() (*VacuumDetector, *VacuumScheduler) {
|
|
||||||
return getSharedInstances()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auto-register this task when the package is imported
|
// Auto-register this task when the package is imported
|
||||||
func init() {
|
func init() {
|
||||||
factory := NewFactory()
|
RegisterVacuumTask()
|
||||||
tasks.AutoRegister(types.TaskTypeVacuum, factory)
|
}
|
||||||
|
|
||||||
// Get shared instances for all registrations
|
// RegisterVacuumTask registers the vacuum task with the new architecture
|
||||||
detector, scheduler := getSharedInstances()
|
func RegisterVacuumTask() {
|
||||||
|
// Create configuration instance
|
||||||
|
config := NewDefaultConfig()
|
||||||
|
|
||||||
// Register with types registry
|
// Create complete task definition
|
||||||
tasks.AutoRegisterTypes(func(registry *types.TaskRegistry) {
|
taskDef := &base.TaskDefinition{
|
||||||
registry.RegisterTask(detector, scheduler)
|
Type: types.TaskTypeVacuum,
|
||||||
})
|
Name: "vacuum",
|
||||||
|
DisplayName: "Volume Vacuum",
|
||||||
|
Description: "Reclaims disk space by removing deleted files from volumes",
|
||||||
|
Icon: "fas fa-broom text-primary",
|
||||||
|
Capabilities: []string{"vacuum", "storage"},
|
||||||
|
|
||||||
// Register with UI registry using the same instances
|
Config: config,
|
||||||
tasks.AutoRegisterUI(func(uiRegistry *types.UIRegistry) {
|
ConfigSpec: GetConfigSpec(),
|
||||||
RegisterUI(uiRegistry, detector, scheduler)
|
CreateTask: CreateTask,
|
||||||
})
|
DetectionFunc: Detection,
|
||||||
|
ScanInterval: 2 * time.Hour,
|
||||||
|
SchedulingFunc: Scheduling,
|
||||||
|
MaxConcurrent: 2,
|
||||||
|
RepeatInterval: 7 * 24 * time.Hour,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register everything with a single function call!
|
||||||
|
base.RegisterTask(taskDef)
|
||||||
}
|
}
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
package vacuum
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/worker/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
// VacuumScheduler implements vacuum task scheduling using code instead of schemas
|
|
||||||
type VacuumScheduler struct {
|
|
||||||
enabled bool
|
|
||||||
maxConcurrent int
|
|
||||||
minInterval time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile-time interface assertions
|
|
||||||
var (
|
|
||||||
_ types.TaskScheduler = (*VacuumScheduler)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewVacuumScheduler creates a new simple vacuum scheduler
|
|
||||||
func NewVacuumScheduler() *VacuumScheduler {
|
|
||||||
return &VacuumScheduler{
|
|
||||||
enabled: true,
|
|
||||||
maxConcurrent: 2,
|
|
||||||
minInterval: 6 * time.Hour,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetTaskType returns the task type
|
|
||||||
func (s *VacuumScheduler) GetTaskType() types.TaskType {
|
|
||||||
return types.TaskTypeVacuum
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanScheduleNow determines if a vacuum task can be scheduled right now
|
|
||||||
func (s *VacuumScheduler) CanScheduleNow(task *types.Task, runningTasks []*types.Task, availableWorkers []*types.Worker) bool {
|
|
||||||
// Check if scheduler is enabled
|
|
||||||
if !s.enabled {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check concurrent limit
|
|
||||||
runningVacuumCount := 0
|
|
||||||
for _, runningTask := range runningTasks {
|
|
||||||
if runningTask.Type == types.TaskTypeVacuum {
|
|
||||||
runningVacuumCount++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if runningVacuumCount >= s.maxConcurrent {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if there's an available worker with vacuum capability
|
|
||||||
for _, worker := range availableWorkers {
|
|
||||||
if worker.CurrentLoad < worker.MaxConcurrent {
|
|
||||||
for _, capability := range worker.Capabilities {
|
|
||||||
if capability == types.TaskTypeVacuum {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPriority returns the priority for this task
|
|
||||||
func (s *VacuumScheduler) GetPriority(task *types.Task) types.TaskPriority {
|
|
||||||
// Could adjust priority based on task parameters
|
|
||||||
if params, ok := task.Parameters["garbage_ratio"].(float64); ok {
|
|
||||||
if params > 0.8 {
|
|
||||||
return types.TaskPriorityHigh
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return task.Priority
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMaxConcurrent returns max concurrent tasks of this type
|
|
||||||
func (s *VacuumScheduler) GetMaxConcurrent() int {
|
|
||||||
return s.maxConcurrent
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDefaultRepeatInterval returns the default interval to wait before repeating vacuum tasks
|
|
||||||
func (s *VacuumScheduler) GetDefaultRepeatInterval() time.Duration {
|
|
||||||
return s.minInterval
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsEnabled returns whether this scheduler is enabled
|
|
||||||
func (s *VacuumScheduler) IsEnabled() bool {
|
|
||||||
return s.enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configuration setters
|
|
||||||
|
|
||||||
func (s *VacuumScheduler) SetEnabled(enabled bool) {
|
|
||||||
s.enabled = enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *VacuumScheduler) SetMaxConcurrent(max int) {
|
|
||||||
s.maxConcurrent = max
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *VacuumScheduler) SetMinInterval(interval time.Duration) {
|
|
||||||
s.minInterval = interval
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMinInterval returns the minimum interval
|
|
||||||
func (s *VacuumScheduler) GetMinInterval() time.Duration {
|
|
||||||
return s.minInterval
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,8 @@ package types
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WorkerConfig represents the configuration for a worker
|
// WorkerConfig represents the configuration for a worker
|
||||||
@@ -12,7 +14,9 @@ type WorkerConfig struct {
|
|||||||
MaxConcurrent int `json:"max_concurrent"`
|
MaxConcurrent int `json:"max_concurrent"`
|
||||||
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
||||||
TaskRequestInterval time.Duration `json:"task_request_interval"`
|
TaskRequestInterval time.Duration `json:"task_request_interval"`
|
||||||
|
BaseWorkingDir string `json:"base_working_dir,omitempty"`
|
||||||
CustomParameters map[string]interface{} `json:"custom_parameters,omitempty"`
|
CustomParameters map[string]interface{} `json:"custom_parameters,omitempty"`
|
||||||
|
GrpcDialOption grpc.DialOption `json:"-"` // Not serializable, for runtime use only
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaintenanceConfig represents the configuration for the maintenance system
|
// MaintenanceConfig represents the configuration for the maintenance system
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TaskType represents the type of maintenance task
|
// TaskType represents the type of maintenance task
|
||||||
@@ -57,10 +59,12 @@ type Task struct {
|
|||||||
|
|
||||||
// TaskParams represents parameters for task execution
|
// TaskParams represents parameters for task execution
|
||||||
type TaskParams struct {
|
type TaskParams struct {
|
||||||
VolumeID uint32 `json:"volume_id,omitempty"`
|
VolumeID uint32 `json:"volume_id,omitempty"`
|
||||||
Server string `json:"server,omitempty"`
|
Server string `json:"server,omitempty"`
|
||||||
Collection string `json:"collection,omitempty"`
|
Collection string `json:"collection,omitempty"`
|
||||||
Parameters map[string]interface{} `json:"parameters,omitempty"`
|
WorkingDir string `json:"working_dir,omitempty"`
|
||||||
|
Parameters map[string]interface{} `json:"parameters,omitempty"`
|
||||||
|
GrpcDialOption grpc.DialOption `json:"-"` // Not serializable, for runtime use only
|
||||||
}
|
}
|
||||||
|
|
||||||
// TaskDetectionResult represents the result of scanning for maintenance needs
|
// TaskDetectionResult represents the result of scanning for maintenance needs
|
||||||
|
|||||||
+41
-199
@@ -1,12 +1,45 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"html/template"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Helper function to convert seconds to the most appropriate interval unit
|
||||||
|
func secondsToIntervalValueUnit(totalSeconds int) (int, string) {
|
||||||
|
if totalSeconds == 0 {
|
||||||
|
return 0, "minute"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by days
|
||||||
|
if totalSeconds%(24*3600) == 0 {
|
||||||
|
return totalSeconds / (24 * 3600), "day"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's evenly divisible by hours
|
||||||
|
if totalSeconds%3600 == 0 {
|
||||||
|
return totalSeconds / 3600, "hour"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to minutes
|
||||||
|
return totalSeconds / 60, "minute"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to convert interval value and unit to seconds
|
||||||
|
func IntervalValueUnitToSeconds(value int, unit string) int {
|
||||||
|
switch unit {
|
||||||
|
case "day":
|
||||||
|
return value * 24 * 3600
|
||||||
|
case "hour":
|
||||||
|
return value * 3600
|
||||||
|
case "minute":
|
||||||
|
return value * 60
|
||||||
|
default:
|
||||||
|
return value * 60 // Default to minutes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TaskUIProvider defines how tasks provide their configuration UI
|
// TaskUIProvider defines how tasks provide their configuration UI
|
||||||
|
// This interface is simplified to work with schema-driven configuration
|
||||||
type TaskUIProvider interface {
|
type TaskUIProvider interface {
|
||||||
// GetTaskType returns the task type
|
// GetTaskType returns the task type
|
||||||
GetTaskType() TaskType
|
GetTaskType() TaskType
|
||||||
@@ -20,12 +53,6 @@ type TaskUIProvider interface {
|
|||||||
// GetIcon returns the icon CSS class or HTML for this task type
|
// GetIcon returns the icon CSS class or HTML for this task type
|
||||||
GetIcon() string
|
GetIcon() string
|
||||||
|
|
||||||
// RenderConfigForm renders the configuration form HTML
|
|
||||||
RenderConfigForm(currentConfig interface{}) (template.HTML, error)
|
|
||||||
|
|
||||||
// ParseConfigForm parses form data into configuration
|
|
||||||
ParseConfigForm(formData map[string][]string) (interface{}, error)
|
|
||||||
|
|
||||||
// GetCurrentConfig returns the current configuration
|
// GetCurrentConfig returns the current configuration
|
||||||
GetCurrentConfig() interface{}
|
GetCurrentConfig() interface{}
|
||||||
|
|
||||||
@@ -87,195 +114,10 @@ type TaskListData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TaskDetailsData struct {
|
type TaskDetailsData struct {
|
||||||
Task *Task `json:"task"`
|
Task *Task `json:"task"`
|
||||||
TaskType TaskType `json:"task_type"`
|
TaskType TaskType `json:"task_type"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Stats *TaskStats `json:"stats"`
|
Stats *TaskStats `json:"stats"`
|
||||||
ConfigForm template.HTML `json:"config_form"`
|
LastUpdated time.Time `json:"last_updated"`
|
||||||
LastUpdated time.Time `json:"last_updated"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Common form field types for simple form building
|
|
||||||
type FormField struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Label string `json:"label"`
|
|
||||||
Type string `json:"type"` // text, number, checkbox, select, duration
|
|
||||||
Value interface{} `json:"value"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
Required bool `json:"required"`
|
|
||||||
Options []FormOption `json:"options,omitempty"` // For select fields
|
|
||||||
}
|
|
||||||
|
|
||||||
type FormOption struct {
|
|
||||||
Value string `json:"value"`
|
|
||||||
Label string `json:"label"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper for building forms in code
|
|
||||||
type FormBuilder struct {
|
|
||||||
fields []FormField
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFormBuilder creates a new form builder
|
|
||||||
func NewFormBuilder() *FormBuilder {
|
|
||||||
return &FormBuilder{
|
|
||||||
fields: make([]FormField, 0),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddTextField adds a text input field
|
|
||||||
func (fb *FormBuilder) AddTextField(name, label, description string, value string, required bool) *FormBuilder {
|
|
||||||
fb.fields = append(fb.fields, FormField{
|
|
||||||
Name: name,
|
|
||||||
Label: label,
|
|
||||||
Type: "text",
|
|
||||||
Value: value,
|
|
||||||
Description: description,
|
|
||||||
Required: required,
|
|
||||||
})
|
|
||||||
return fb
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddNumberField adds a number input field
|
|
||||||
func (fb *FormBuilder) AddNumberField(name, label, description string, value float64, required bool) *FormBuilder {
|
|
||||||
fb.fields = append(fb.fields, FormField{
|
|
||||||
Name: name,
|
|
||||||
Label: label,
|
|
||||||
Type: "number",
|
|
||||||
Value: value,
|
|
||||||
Description: description,
|
|
||||||
Required: required,
|
|
||||||
})
|
|
||||||
return fb
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddCheckboxField adds a checkbox field
|
|
||||||
func (fb *FormBuilder) AddCheckboxField(name, label, description string, value bool) *FormBuilder {
|
|
||||||
fb.fields = append(fb.fields, FormField{
|
|
||||||
Name: name,
|
|
||||||
Label: label,
|
|
||||||
Type: "checkbox",
|
|
||||||
Value: value,
|
|
||||||
Description: description,
|
|
||||||
Required: false,
|
|
||||||
})
|
|
||||||
return fb
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddSelectField adds a select dropdown field
|
|
||||||
func (fb *FormBuilder) AddSelectField(name, label, description string, value string, options []FormOption, required bool) *FormBuilder {
|
|
||||||
fb.fields = append(fb.fields, FormField{
|
|
||||||
Name: name,
|
|
||||||
Label: label,
|
|
||||||
Type: "select",
|
|
||||||
Value: value,
|
|
||||||
Description: description,
|
|
||||||
Required: required,
|
|
||||||
Options: options,
|
|
||||||
})
|
|
||||||
return fb
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddDurationField adds a duration input field
|
|
||||||
func (fb *FormBuilder) AddDurationField(name, label, description string, value time.Duration, required bool) *FormBuilder {
|
|
||||||
fb.fields = append(fb.fields, FormField{
|
|
||||||
Name: name,
|
|
||||||
Label: label,
|
|
||||||
Type: "duration",
|
|
||||||
Value: value.String(),
|
|
||||||
Description: description,
|
|
||||||
Required: required,
|
|
||||||
})
|
|
||||||
return fb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build generates the HTML form fields with Bootstrap styling
|
|
||||||
func (fb *FormBuilder) Build() template.HTML {
|
|
||||||
html := ""
|
|
||||||
|
|
||||||
for _, field := range fb.fields {
|
|
||||||
html += fb.renderField(field)
|
|
||||||
}
|
|
||||||
|
|
||||||
return template.HTML(html)
|
|
||||||
}
|
|
||||||
|
|
||||||
// renderField renders a single form field with Bootstrap classes
|
|
||||||
func (fb *FormBuilder) renderField(field FormField) string {
|
|
||||||
html := "<div class=\"mb-3\">\n"
|
|
||||||
|
|
||||||
// Special handling for checkbox fields
|
|
||||||
if field.Type == "checkbox" {
|
|
||||||
checked := ""
|
|
||||||
if field.Value.(bool) {
|
|
||||||
checked = " checked"
|
|
||||||
}
|
|
||||||
html += " <div class=\"form-check\">\n"
|
|
||||||
html += " <input type=\"checkbox\" class=\"form-check-input\" id=\"" + field.Name + "\" name=\"" + field.Name + "\"" + checked + ">\n"
|
|
||||||
html += " <label class=\"form-check-label\" for=\"" + field.Name + "\">" + field.Label + "</label>\n"
|
|
||||||
html += " </div>\n"
|
|
||||||
// Description for checkbox
|
|
||||||
if field.Description != "" {
|
|
||||||
html += " <div class=\"form-text text-muted\">" + field.Description + "</div>\n"
|
|
||||||
}
|
|
||||||
html += "</div>\n"
|
|
||||||
return html
|
|
||||||
}
|
|
||||||
|
|
||||||
// Label for non-checkbox fields
|
|
||||||
required := ""
|
|
||||||
if field.Required {
|
|
||||||
required = " <span class=\"text-danger\">*</span>"
|
|
||||||
}
|
|
||||||
html += " <label for=\"" + field.Name + "\" class=\"form-label\">" + field.Label + required + "</label>\n"
|
|
||||||
|
|
||||||
// Input based on type
|
|
||||||
switch field.Type {
|
|
||||||
case "text":
|
|
||||||
html += " <input type=\"text\" class=\"form-control\" id=\"" + field.Name + "\" name=\"" + field.Name + "\" value=\"" + field.Value.(string) + "\""
|
|
||||||
if field.Required {
|
|
||||||
html += " required"
|
|
||||||
}
|
|
||||||
html += ">\n"
|
|
||||||
|
|
||||||
case "number":
|
|
||||||
html += " <input type=\"number\" class=\"form-control\" id=\"" + field.Name + "\" name=\"" + field.Name + "\" step=\"any\" value=\"" +
|
|
||||||
fmt.Sprintf("%v", field.Value) + "\""
|
|
||||||
if field.Required {
|
|
||||||
html += " required"
|
|
||||||
}
|
|
||||||
html += ">\n"
|
|
||||||
|
|
||||||
case "select":
|
|
||||||
html += " <select class=\"form-select\" id=\"" + field.Name + "\" name=\"" + field.Name + "\""
|
|
||||||
if field.Required {
|
|
||||||
html += " required"
|
|
||||||
}
|
|
||||||
html += ">\n"
|
|
||||||
for _, option := range field.Options {
|
|
||||||
selected := ""
|
|
||||||
if option.Value == field.Value.(string) {
|
|
||||||
selected = " selected"
|
|
||||||
}
|
|
||||||
html += " <option value=\"" + option.Value + "\"" + selected + ">" + option.Label + "</option>\n"
|
|
||||||
}
|
|
||||||
html += " </select>\n"
|
|
||||||
|
|
||||||
case "duration":
|
|
||||||
html += " <input type=\"text\" class=\"form-control\" id=\"" + field.Name + "\" name=\"" + field.Name + "\" value=\"" + field.Value.(string) +
|
|
||||||
"\" placeholder=\"e.g., 30m, 2h, 24h\""
|
|
||||||
if field.Required {
|
|
||||||
html += " required"
|
|
||||||
}
|
|
||||||
html += ">\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Description for non-checkbox fields
|
|
||||||
if field.Description != "" {
|
|
||||||
html += " <div class=\"form-text text-muted\">" + field.Description + "</div>\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
html += "</div>\n"
|
|
||||||
return html
|
|
||||||
}
|
}
|
||||||
@@ -108,4 +108,13 @@ type TaskInterface interface {
|
|||||||
EstimateTime(params TaskParams) time.Duration
|
EstimateTime(params TaskParams) time.Duration
|
||||||
GetProgress() float64
|
GetProgress() float64
|
||||||
Cancel() error
|
Cancel() error
|
||||||
|
|
||||||
|
// Logging methods for task-specific log files
|
||||||
|
InitializeTaskLogging(workingDir, taskID string) error
|
||||||
|
CloseTaskLogging()
|
||||||
|
LogInfo(format string, args ...interface{})
|
||||||
|
LogError(format string, args ...interface{})
|
||||||
|
LogDebug(format string, args ...interface{})
|
||||||
|
LogWarning(format string, args ...interface{})
|
||||||
|
GetLogFilePath() string
|
||||||
}
|
}
|
||||||
+166
-18
@@ -1,8 +1,12 @@
|
|||||||
package worker
|
package worker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -45,15 +49,92 @@ type AdminClient interface {
|
|||||||
IsConnected() bool
|
IsConnected() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateOrLoadWorkerID generates a unique worker ID or loads existing one from working directory
|
||||||
|
func GenerateOrLoadWorkerID(workingDir string) (string, error) {
|
||||||
|
const workerIDFile = "worker.id"
|
||||||
|
|
||||||
|
var idFilePath string
|
||||||
|
if workingDir != "" {
|
||||||
|
idFilePath = filepath.Join(workingDir, workerIDFile)
|
||||||
|
} else {
|
||||||
|
// Use current working directory if none specified
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to get working directory: %w", err)
|
||||||
|
}
|
||||||
|
idFilePath = filepath.Join(wd, workerIDFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to read existing worker ID
|
||||||
|
if data, err := os.ReadFile(idFilePath); err == nil {
|
||||||
|
workerID := strings.TrimSpace(string(data))
|
||||||
|
if workerID != "" {
|
||||||
|
glog.Infof("Loaded existing worker ID from %s: %s", idFilePath, workerID)
|
||||||
|
return workerID, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate new unique worker ID with host information
|
||||||
|
hostname, _ := os.Hostname()
|
||||||
|
if hostname == "" {
|
||||||
|
hostname = "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get local IP address for better host identification
|
||||||
|
var hostIP string
|
||||||
|
if addrs, err := net.InterfaceAddrs(); err == nil {
|
||||||
|
for _, addr := range addrs {
|
||||||
|
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||||
|
if ipnet.IP.To4() != nil {
|
||||||
|
hostIP = ipnet.IP.String()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hostIP == "" {
|
||||||
|
hostIP = "noip"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create host identifier combining hostname and IP
|
||||||
|
hostID := fmt.Sprintf("%s@%s", hostname, hostIP)
|
||||||
|
|
||||||
|
// Generate random component for uniqueness
|
||||||
|
randomBytes := make([]byte, 4)
|
||||||
|
var workerID string
|
||||||
|
if _, err := rand.Read(randomBytes); err != nil {
|
||||||
|
// Fallback to timestamp if crypto/rand fails
|
||||||
|
workerID = fmt.Sprintf("worker-%s-%d", hostID, time.Now().Unix())
|
||||||
|
glog.Infof("Generated fallback worker ID: %s", workerID)
|
||||||
|
} else {
|
||||||
|
// Use random bytes + timestamp for uniqueness
|
||||||
|
randomHex := fmt.Sprintf("%x", randomBytes)
|
||||||
|
timestamp := time.Now().Unix()
|
||||||
|
workerID = fmt.Sprintf("worker-%s-%s-%d", hostID, randomHex, timestamp)
|
||||||
|
glog.Infof("Generated new worker ID: %s", workerID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save worker ID to file
|
||||||
|
if err := os.WriteFile(idFilePath, []byte(workerID), 0644); err != nil {
|
||||||
|
glog.Warningf("Failed to save worker ID to %s: %v", idFilePath, err)
|
||||||
|
} else {
|
||||||
|
glog.Infof("Saved worker ID to %s", idFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return workerID, nil
|
||||||
|
}
|
||||||
|
|
||||||
// NewWorker creates a new worker instance
|
// NewWorker creates a new worker instance
|
||||||
func NewWorker(config *types.WorkerConfig) (*Worker, error) {
|
func NewWorker(config *types.WorkerConfig) (*Worker, error) {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = types.DefaultWorkerConfig()
|
config = types.DefaultWorkerConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always auto-generate worker ID
|
// Generate or load persistent worker ID
|
||||||
hostname, _ := os.Hostname()
|
workerID, err := GenerateOrLoadWorkerID(config.BaseWorkingDir)
|
||||||
workerID := fmt.Sprintf("worker-%s-%d", hostname, time.Now().Unix())
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to generate or load worker ID: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Use the global registry that already has all tasks registered
|
// Use the global registry that already has all tasks registered
|
||||||
registry := tasks.GetGlobalRegistry()
|
registry := tasks.GetGlobalRegistry()
|
||||||
@@ -90,15 +171,10 @@ func (w *Worker) Start() error {
|
|||||||
return fmt.Errorf("admin client is not set")
|
return fmt.Errorf("admin client is not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to admin server
|
|
||||||
if err := w.adminClient.Connect(); err != nil {
|
|
||||||
return fmt.Errorf("failed to connect to admin server: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
w.running = true
|
w.running = true
|
||||||
w.startTime = time.Now()
|
w.startTime = time.Now()
|
||||||
|
|
||||||
// Register with admin server
|
// Prepare worker info for registration
|
||||||
workerInfo := &types.Worker{
|
workerInfo := &types.Worker{
|
||||||
ID: w.id,
|
ID: w.id,
|
||||||
Capabilities: w.config.Capabilities,
|
Capabilities: w.config.Capabilities,
|
||||||
@@ -108,17 +184,28 @@ func (w *Worker) Start() error {
|
|||||||
LastHeartbeat: time.Now(),
|
LastHeartbeat: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register worker info with client first (this stores it for use during connection)
|
||||||
if err := w.adminClient.RegisterWorker(workerInfo); err != nil {
|
if err := w.adminClient.RegisterWorker(workerInfo); err != nil {
|
||||||
w.running = false
|
glog.V(1).Infof("Worker info stored for registration: %v", err)
|
||||||
w.adminClient.Disconnect()
|
// This is expected if not connected yet
|
||||||
return fmt.Errorf("failed to register worker: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start worker loops
|
// Start connection attempt (will register immediately if successful)
|
||||||
|
glog.Infof("Worker %s starting, attempting to connect to admin server...", w.id)
|
||||||
|
|
||||||
|
// Try initial connection, but don't fail if it doesn't work immediately
|
||||||
|
if err := w.adminClient.Connect(); err != nil {
|
||||||
|
glog.Warningf("Initial connection to admin server failed, will keep retrying: %v", err)
|
||||||
|
// Don't return error - let the reconnection loop handle it
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start worker loops regardless of initial connection status
|
||||||
|
// They will handle connection failures gracefully
|
||||||
go w.heartbeatLoop()
|
go w.heartbeatLoop()
|
||||||
go w.taskRequestLoop()
|
go w.taskRequestLoop()
|
||||||
|
go w.connectionMonitorLoop()
|
||||||
|
|
||||||
glog.Infof("Worker %s started", w.id)
|
glog.Infof("Worker %s started (connection attempts will continue in background)", w.id)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,12 +344,20 @@ func (w *Worker) executeTask(task *types.Task) {
|
|||||||
|
|
||||||
glog.Infof("Worker %s executing task %s: %s", w.id, task.ID, task.Type)
|
glog.Infof("Worker %s executing task %s: %s", w.id, task.ID, task.Type)
|
||||||
|
|
||||||
|
// Determine task-specific working directory
|
||||||
|
var taskWorkingDir string
|
||||||
|
if w.config.BaseWorkingDir != "" {
|
||||||
|
taskWorkingDir = fmt.Sprintf("%s/%s", w.config.BaseWorkingDir, string(task.Type))
|
||||||
|
}
|
||||||
|
|
||||||
// Create task instance
|
// Create task instance
|
||||||
taskParams := types.TaskParams{
|
taskParams := types.TaskParams{
|
||||||
VolumeID: task.VolumeID,
|
VolumeID: task.VolumeID,
|
||||||
Server: task.Server,
|
Server: task.Server,
|
||||||
Collection: task.Collection,
|
Collection: task.Collection,
|
||||||
Parameters: task.Parameters,
|
WorkingDir: taskWorkingDir,
|
||||||
|
Parameters: task.Parameters,
|
||||||
|
GrpcDialOption: w.config.GrpcDialOption,
|
||||||
}
|
}
|
||||||
|
|
||||||
taskInstance, err := w.registry.CreateTask(task.Type, taskParams)
|
taskInstance, err := w.registry.CreateTask(task.Type, taskParams)
|
||||||
@@ -271,15 +366,29 @@ func (w *Worker) executeTask(task *types.Task) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize task logging
|
||||||
|
if err := taskInstance.InitializeTaskLogging(taskWorkingDir, task.ID); err != nil {
|
||||||
|
glog.Warningf("Failed to initialize task logging for %s: %v", task.ID, err)
|
||||||
|
} else {
|
||||||
|
// Ensure logging is closed when task completes
|
||||||
|
defer taskInstance.CloseTaskLogging()
|
||||||
|
taskInstance.LogInfo("Worker %s starting execution of task %s (type: %s)", w.id, task.ID, task.Type)
|
||||||
|
if task.VolumeID != 0 {
|
||||||
|
taskInstance.LogInfo("Task parameters: VolumeID=%d, Server=%s, Collection=%s", task.VolumeID, task.Server, task.Collection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute task
|
// Execute task
|
||||||
err = taskInstance.Execute(taskParams)
|
err = taskInstance.Execute(taskParams)
|
||||||
|
|
||||||
// Report completion
|
// Report completion
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
taskInstance.LogError("Task execution failed: %v", err)
|
||||||
w.completeTask(task.ID, false, err.Error())
|
w.completeTask(task.ID, false, err.Error())
|
||||||
w.tasksFailed++
|
w.tasksFailed++
|
||||||
glog.Errorf("Worker %s failed to execute task %s: %v", w.id, task.ID, err)
|
glog.Errorf("Worker %s failed to execute task %s: %v", w.id, task.ID, err)
|
||||||
} else {
|
} else {
|
||||||
|
taskInstance.LogInfo("Task completed successfully")
|
||||||
w.completeTask(task.ID, true, "")
|
w.completeTask(task.ID, true, "")
|
||||||
w.tasksCompleted++
|
w.tasksCompleted++
|
||||||
glog.Infof("Worker %s completed task %s successfully", w.id, task.ID)
|
glog.Infof("Worker %s completed task %s successfully", w.id, task.ID)
|
||||||
@@ -383,6 +492,45 @@ func (w *Worker) GetCurrentTasks() map[string]*types.Task {
|
|||||||
return tasks
|
return tasks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// registerWorker registers the worker with the admin server
|
||||||
|
func (w *Worker) registerWorker() {
|
||||||
|
workerInfo := &types.Worker{
|
||||||
|
ID: w.id,
|
||||||
|
Capabilities: w.config.Capabilities,
|
||||||
|
MaxConcurrent: w.config.MaxConcurrent,
|
||||||
|
Status: "active",
|
||||||
|
CurrentLoad: 0,
|
||||||
|
LastHeartbeat: time.Now(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := w.adminClient.RegisterWorker(workerInfo); err != nil {
|
||||||
|
glog.Warningf("Failed to register worker (will retry on next heartbeat): %v", err)
|
||||||
|
} else {
|
||||||
|
glog.Infof("Worker %s registered successfully with admin server", w.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// connectionMonitorLoop monitors connection status
|
||||||
|
func (w *Worker) connectionMonitorLoop() {
|
||||||
|
ticker := time.NewTicker(30 * time.Second) // Check every 30 seconds
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-w.stopChan:
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
// Just monitor connection status - registration is handled automatically
|
||||||
|
// by the client's reconnection logic
|
||||||
|
if w.adminClient != nil && w.adminClient.IsConnected() {
|
||||||
|
glog.V(2).Infof("Worker %s connection status: connected", w.id)
|
||||||
|
} else if w.adminClient != nil {
|
||||||
|
glog.V(1).Infof("Worker %s connection status: disconnected, reconnection in progress", w.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetConfig returns the worker configuration
|
// GetConfig returns the worker configuration
|
||||||
func (w *Worker) GetConfig() *types.WorkerConfig {
|
func (w *Worker) GetConfig() *types.WorkerConfig {
|
||||||
return w.config
|
return w.config
|
||||||
|
|||||||
Reference in new issue
Block a user