mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-12-19 05:36:17 +01:00
Make NATS API subjects configurable
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ClusterCockpit/cc-backend/internal/archiver"
|
"github.com/ClusterCockpit/cc-backend/internal/archiver"
|
||||||
|
"github.com/ClusterCockpit/cc-backend/internal/config"
|
||||||
"github.com/ClusterCockpit/cc-backend/internal/importer"
|
"github.com/ClusterCockpit/cc-backend/internal/importer"
|
||||||
"github.com/ClusterCockpit/cc-backend/internal/repository"
|
"github.com/ClusterCockpit/cc-backend/internal/repository"
|
||||||
"github.com/ClusterCockpit/cc-backend/pkg/nats"
|
"github.com/ClusterCockpit/cc-backend/pkg/nats"
|
||||||
@@ -20,13 +21,6 @@ import (
|
|||||||
"github.com/ClusterCockpit/cc-lib/schema"
|
"github.com/ClusterCockpit/cc-lib/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NATS subject constants for Job and Node APIs.
|
|
||||||
const (
|
|
||||||
SubjectJobStart = "cc.job.start"
|
|
||||||
SubjectJobStop = "cc.job.stop"
|
|
||||||
SubjectNodeState = "cc.node.state"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NatsAPI provides NATS subscription-based handlers for Job and Node operations.
|
// NatsAPI provides NATS subscription-based handlers for Job and Node operations.
|
||||||
// It mirrors the functionality of the REST API but uses NATS messaging.
|
// It mirrors the functionality of the REST API but uses NATS messaging.
|
||||||
type NatsAPI struct {
|
type NatsAPI struct {
|
||||||
@@ -52,19 +46,24 @@ func (api *NatsAPI) StartSubscriptions() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.Subscribe(SubjectJobStart, api.handleStartJob); err != nil {
|
if config.Keys.APISubjects != nil {
|
||||||
|
|
||||||
|
s := config.Keys.APISubjects
|
||||||
|
|
||||||
|
if err := client.Subscribe(s.SubjectJobStart, api.handleStartJob); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.Subscribe(SubjectJobStop, api.handleStopJob); err != nil {
|
if err := client.Subscribe(s.SubjectJobStop, api.handleStopJob); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.Subscribe(SubjectNodeState, api.handleNodeState); err != nil {
|
if err := client.Subscribe(s.SubjectNodeState, api.handleNodeState); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cclog.Info("NATS API subscriptions started")
|
cclog.Info("NATS API subscriptions started")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ type ProgramConfig struct {
|
|||||||
// Addresses from which secured admin API endpoints can be reached, can be wildcard "*"
|
// Addresses from which secured admin API endpoints can be reached, can be wildcard "*"
|
||||||
APIAllowedIPs []string `json:"apiAllowedIPs"`
|
APIAllowedIPs []string `json:"apiAllowedIPs"`
|
||||||
|
|
||||||
|
APISubjects *NATSConfig `json:"apiSubjects"`
|
||||||
|
|
||||||
// Drop root permissions once .env was read and the port was taken.
|
// Drop root permissions once .env was read and the port was taken.
|
||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
Group string `json:"group"`
|
Group string `json:"group"`
|
||||||
@@ -87,6 +89,12 @@ type ResampleConfig struct {
|
|||||||
Trigger int `json:"trigger"`
|
Trigger int `json:"trigger"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NATSConfig struct {
|
||||||
|
SubjectJobStart string `json:"subjectJobStart"`
|
||||||
|
SubjectJobStop string `json:"subjectJobStop"`
|
||||||
|
SubjectNodeState string `json:"subjectNodeState"`
|
||||||
|
}
|
||||||
|
|
||||||
type IntRange struct {
|
type IntRange struct {
|
||||||
From int `json:"from"`
|
From int `json:"from"`
|
||||||
To int `json:"to"`
|
To int `json:"to"`
|
||||||
|
|||||||
Reference in New Issue
Block a user