fixing storage management dashboard
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/atlasos/calypso/internal/common/cache"
|
||||
"github.com/atlasos/calypso/internal/common/database"
|
||||
"github.com/atlasos/calypso/internal/common/logger"
|
||||
"github.com/atlasos/calypso/internal/tasks"
|
||||
@@ -16,9 +17,16 @@ type Handler struct {
|
||||
diskService *DiskService
|
||||
lvmService *LVMService
|
||||
zfsService *ZFSService
|
||||
arcService *ARCService
|
||||
taskEngine *tasks.Engine
|
||||
db *database.DB
|
||||
logger *logger.Logger
|
||||
cache *cache.Cache // Cache for invalidation
|
||||
}
|
||||
|
||||
// SetCache sets the cache instance for cache invalidation
|
||||
func (h *Handler) SetCache(c *cache.Cache) {
|
||||
h.cache = c
|
||||
}
|
||||
|
||||
// NewHandler creates a new storage handler
|
||||
@@ -27,6 +35,7 @@ func NewHandler(db *database.DB, log *logger.Logger) *Handler {
|
||||
diskService: NewDiskService(db, log),
|
||||
lvmService: NewLVMService(db, log),
|
||||
zfsService: NewZFSService(db, log),
|
||||
arcService: NewARCService(log),
|
||||
taskEngine: tasks.NewEngine(db, log),
|
||||
db: db,
|
||||
logger: log,
|
||||
@@ -350,6 +359,11 @@ func (h *Handler) ListZFSDatasets(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Ensure we return an empty array instead of null
|
||||
if datasets == nil {
|
||||
datasets = []*ZFSDataset{}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"datasets": datasets})
|
||||
}
|
||||
|
||||
@@ -392,6 +406,12 @@ func (h *Handler) CreateZFSDataset(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Validate mount point: volumes cannot have mount points
|
||||
if req.Type == "volume" && req.MountPoint != "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "mount point cannot be set for volume datasets (volumes are block devices for iSCSI export)"})
|
||||
return
|
||||
}
|
||||
|
||||
// Validate dataset name (should not contain pool name)
|
||||
if strings.Contains(req.Name, "/") {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dataset name should not contain '/' (pool name is automatically prepended)"})
|
||||
@@ -454,5 +474,26 @@ func (h *Handler) DeleteZFSDataset(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Invalidate cache for this pool's datasets list
|
||||
if h.cache != nil {
|
||||
// Generate cache key using the same format as cache middleware
|
||||
cacheKey := fmt.Sprintf("http:/api/v1/storage/zfs/pools/%s/datasets:", poolID)
|
||||
h.cache.Delete(cacheKey)
|
||||
// Also invalidate any cached responses with query parameters
|
||||
h.logger.Debug("Cache invalidated for dataset list", "pool_id", poolID, "key", cacheKey)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Dataset deleted successfully"})
|
||||
}
|
||||
|
||||
// GetARCStats returns ZFS ARC statistics
|
||||
func (h *Handler) GetARCStats(c *gin.Context) {
|
||||
stats, err := h.arcService.GetARCStats(c.Request.Context())
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to get ARC stats", "error", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to get ARC stats: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, stats)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user