mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
API: Add cluster operations endpoints to manage and register nodes #98
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
committed by
Michael Mayer
parent
efbcf34588
commit
d3775f02e6
86
internal/api/cluster_summary.go
Normal file
86
internal/api/cluster_summary.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/auth/acl"
|
||||
"github.com/photoprism/photoprism/internal/photoprism/get"
|
||||
reg "github.com/photoprism/photoprism/internal/service/cluster/registry"
|
||||
"github.com/photoprism/photoprism/pkg/service/cluster"
|
||||
"github.com/photoprism/photoprism/pkg/service/http/header"
|
||||
)
|
||||
|
||||
// ClusterSummary returns a minimal overview of the cluster/portal.
|
||||
//
|
||||
// @Summary cluster summary
|
||||
// @Id ClusterSummary
|
||||
// @Tags Cluster
|
||||
// @Produce json
|
||||
// @Success 200 {object} cluster.SummaryResponse
|
||||
// @Failure 401,403,429 {object} i18n.Response
|
||||
// @Router /api/v1/cluster [get]
|
||||
func ClusterSummary(router *gin.RouterGroup) {
|
||||
router.GET("/cluster", func(c *gin.Context) {
|
||||
s := Auth(c, acl.ResourceCluster, acl.ActionView)
|
||||
if s.Abort(c) {
|
||||
return
|
||||
}
|
||||
|
||||
conf := get.Config()
|
||||
|
||||
if !conf.IsPortal() {
|
||||
AbortFeatureDisabled(c)
|
||||
return
|
||||
}
|
||||
|
||||
regy, err := reg.NewFileRegistry(conf)
|
||||
|
||||
if err != nil {
|
||||
AbortUnexpectedError(c)
|
||||
return
|
||||
}
|
||||
|
||||
nodes, _ := regy.List()
|
||||
|
||||
c.JSON(http.StatusOK, cluster.SummaryResponse{
|
||||
PortalUUID: conf.PortalUUID(),
|
||||
Nodes: len(nodes),
|
||||
DB: cluster.DBInfo{Driver: conf.DatabaseDriverName(), Host: conf.DatabaseHost(), Port: conf.DatabasePort()},
|
||||
Time: time.Now().UTC().Format(time.RFC3339),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// ClusterHealth returns minimal health information.
|
||||
//
|
||||
// @Summary cluster health
|
||||
// @Id ClusterHealth
|
||||
// @Tags Cluster
|
||||
// @Produce json
|
||||
// @Success 200 {object} HealthResponse
|
||||
// @Failure 401,403,429 {object} i18n.Response
|
||||
// @Router /api/v1/cluster/health [get]
|
||||
func ClusterHealth(router *gin.RouterGroup) {
|
||||
router.GET("/cluster/health", func(c *gin.Context) {
|
||||
s := Auth(c, acl.ResourceCluster, acl.ActionView)
|
||||
|
||||
if s.Abort(c) {
|
||||
return
|
||||
}
|
||||
|
||||
conf := get.Config()
|
||||
|
||||
if !conf.IsPortal() {
|
||||
AbortFeatureDisabled(c)
|
||||
return
|
||||
}
|
||||
|
||||
// Align headers with server-level health endpoints
|
||||
c.Header(header.CacheControl, header.CacheControlNoStore)
|
||||
c.Header(header.AccessControlAllowOrigin, header.Any)
|
||||
c.JSON(http.StatusOK, NewHealthResponse("ok"))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user