working on system management
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package tape_vtl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/atlasos/calypso/internal/common/database"
|
||||
@@ -29,6 +30,7 @@ func NewHandler(db *database.DB, log *logger.Logger) *Handler {
|
||||
|
||||
// ListLibraries lists all virtual tape libraries
|
||||
func (h *Handler) ListLibraries(c *gin.Context) {
|
||||
h.logger.Info("ListLibraries called")
|
||||
libraries, err := h.service.ListLibraries(c.Request.Context())
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to list libraries", "error", err)
|
||||
@@ -36,7 +38,36 @@ func (h *Handler) ListLibraries(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"libraries": libraries})
|
||||
h.logger.Info("ListLibraries result", "count", len(libraries), "is_nil", libraries == nil)
|
||||
|
||||
// Ensure we return an empty array instead of null
|
||||
if libraries == nil {
|
||||
h.logger.Warn("Libraries is nil, converting to empty array")
|
||||
libraries = []VirtualTapeLibrary{}
|
||||
}
|
||||
|
||||
h.logger.Info("Returning libraries", "count", len(libraries), "libraries", libraries)
|
||||
|
||||
// Ensure we always return an array, never null
|
||||
if libraries == nil {
|
||||
libraries = []VirtualTapeLibrary{}
|
||||
}
|
||||
|
||||
// Force empty array if nil (double check)
|
||||
if libraries == nil {
|
||||
h.logger.Warn("Libraries is still nil in handler, forcing empty array")
|
||||
libraries = []VirtualTapeLibrary{}
|
||||
}
|
||||
|
||||
// Use explicit JSON marshalling to ensure empty array, not null
|
||||
response := map[string]interface{}{
|
||||
"libraries": libraries,
|
||||
}
|
||||
|
||||
h.logger.Info("Response payload", "count", len(libraries), "response_type", fmt.Sprintf("%T", libraries))
|
||||
|
||||
// Use JSON marshalling that handles empty slices correctly
|
||||
c.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
// GetLibrary retrieves a library by ID
|
||||
@@ -69,11 +100,11 @@ func (h *Handler) GetLibrary(c *gin.Context) {
|
||||
|
||||
// CreateLibraryRequest represents a library creation request
|
||||
type CreateLibraryRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
BackingStorePath string `json:"backing_store_path" binding:"required"`
|
||||
SlotCount int `json:"slot_count" binding:"required"`
|
||||
DriveCount int `json:"drive_count" binding:"required"`
|
||||
SlotCount int `json:"slot_count" binding:"required"`
|
||||
DriveCount int `json:"drive_count" binding:"required"`
|
||||
}
|
||||
|
||||
// CreateLibrary creates a new virtual tape library
|
||||
@@ -161,10 +192,10 @@ func (h *Handler) GetLibraryTapes(c *gin.Context) {
|
||||
|
||||
// CreateTapeRequest represents a tape creation request
|
||||
type CreateTapeRequest struct {
|
||||
Barcode string `json:"barcode" binding:"required"`
|
||||
SlotNumber int `json:"slot_number" binding:"required"`
|
||||
TapeType string `json:"tape_type" binding:"required"`
|
||||
SizeGB int64 `json:"size_gb" binding:"required"`
|
||||
Barcode string `json:"barcode" binding:"required"`
|
||||
SlotNumber int `json:"slot_number" binding:"required"`
|
||||
TapeType string `json:"tape_type" binding:"required"`
|
||||
SizeGB int64 `json:"size_gb" binding:"required"`
|
||||
}
|
||||
|
||||
// CreateTape creates a new virtual tape
|
||||
@@ -218,9 +249,9 @@ func (h *Handler) LoadTape(c *gin.Context) {
|
||||
// Create async task
|
||||
taskID, err := h.taskEngine.CreateTask(c.Request.Context(),
|
||||
tasks.TaskTypeLoadUnload, userID.(string), map[string]interface{}{
|
||||
"operation": "load_tape",
|
||||
"library_id": libraryID,
|
||||
"slot_number": req.SlotNumber,
|
||||
"operation": "load_tape",
|
||||
"library_id": libraryID,
|
||||
"slot_number": req.SlotNumber,
|
||||
"drive_number": req.DriveNumber,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -268,9 +299,9 @@ func (h *Handler) UnloadTape(c *gin.Context) {
|
||||
// Create async task
|
||||
taskID, err := h.taskEngine.CreateTask(c.Request.Context(),
|
||||
tasks.TaskTypeLoadUnload, userID.(string), map[string]interface{}{
|
||||
"operation": "unload_tape",
|
||||
"library_id": libraryID,
|
||||
"slot_number": req.SlotNumber,
|
||||
"operation": "unload_tape",
|
||||
"library_id": libraryID,
|
||||
"slot_number": req.SlotNumber,
|
||||
"drive_number": req.DriveNumber,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -295,4 +326,3 @@ func (h *Handler) UnloadTape(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusAccepted, gin.H{"task_id": taskID})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user