Files
hpc/internal/server/server.go
dailz dd8d226e78 refactor: remove JobTemplate production code
Remove all JobTemplate model, store, handler, migrations, and wiring. Replaced by Application Definition system.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-13 17:07:46 +08:00

115 lines
2.8 KiB
Go

package server
import (
"net/http"
"gcy_hpc_server/internal/middleware"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type JobHandler interface {
SubmitJob(c *gin.Context)
GetJobs(c *gin.Context)
GetJobHistory(c *gin.Context)
GetJob(c *gin.Context)
CancelJob(c *gin.Context)
}
type ClusterHandler interface {
GetNodes(c *gin.Context)
GetNode(c *gin.Context)
GetPartitions(c *gin.Context)
GetPartition(c *gin.Context)
GetDiag(c *gin.Context)
}
type ApplicationHandler interface {
ListApplications(c *gin.Context)
CreateApplication(c *gin.Context)
GetApplication(c *gin.Context)
UpdateApplication(c *gin.Context)
DeleteApplication(c *gin.Context)
SubmitApplication(c *gin.Context)
}
// NewRouter creates a Gin engine with all API v1 routes registered with real handlers.
func NewRouter(jobH JobHandler, clusterH ClusterHandler, appH ApplicationHandler, logger *zap.Logger) *gin.Engine {
gin.SetMode(gin.ReleaseMode)
r := gin.New()
r.Use(gin.Recovery())
if logger != nil {
r.Use(middleware.RequestLogger(logger))
}
v1 := r.Group("/api/v1")
jobs := v1.Group("/jobs")
jobs.POST("/submit", jobH.SubmitJob)
jobs.GET("", jobH.GetJobs)
jobs.GET("/history", jobH.GetJobHistory)
jobs.GET("/:id", jobH.GetJob)
jobs.DELETE("/:id", jobH.CancelJob)
v1.GET("/nodes", clusterH.GetNodes)
v1.GET("/nodes/:name", clusterH.GetNode)
v1.GET("/partitions", clusterH.GetPartitions)
v1.GET("/partitions/:name", clusterH.GetPartition)
v1.GET("/diag", clusterH.GetDiag)
apps := v1.Group("/applications")
apps.GET("", appH.ListApplications)
apps.POST("", appH.CreateApplication)
apps.GET("/:id", appH.GetApplication)
apps.PUT("/:id", appH.UpdateApplication)
apps.DELETE("/:id", appH.DeleteApplication)
apps.POST("/:id/submit", appH.SubmitApplication)
return r
}
// NewTestRouter creates a router for testing without real handlers.
func NewTestRouter() *gin.Engine {
gin.SetMode(gin.TestMode)
r := gin.New()
r.Use(gin.Recovery())
v1 := r.Group("/api/v1")
registerPlaceholderRoutes(v1)
return r
}
func registerPlaceholderRoutes(v1 *gin.RouterGroup) {
jobs := v1.Group("/jobs")
jobs.POST("/submit", notImplemented)
jobs.GET("", notImplemented)
jobs.GET("/history", notImplemented)
jobs.GET("/:id", notImplemented)
jobs.DELETE("/:id", notImplemented)
v1.GET("/nodes", notImplemented)
v1.GET("/nodes/:name", notImplemented)
v1.GET("/partitions", notImplemented)
v1.GET("/partitions/:name", notImplemented)
v1.GET("/diag", notImplemented)
apps := v1.Group("/applications")
apps.GET("", notImplemented)
apps.POST("", notImplemented)
apps.GET("/:id", notImplemented)
apps.PUT("/:id", notImplemented)
apps.DELETE("/:id", notImplemented)
apps.POST("/:id/submit", notImplemented)
}
func notImplemented(c *gin.Context) {
c.JSON(http.StatusNotImplemented, APIResponse{
Success: false,
Error: "not implemented",
})
}