forked from lei.chen/myxce
bug-1453: remove unused client-side CA-certificate plumbing. C-side: drop ca_cert_path from xce_cluster_config_t, do_connect()'s ca_cert param, --ca-cert flags on worker/scheduler, and controller's cert population (TLS is server-side only, SSL_VERIFY_NONE everywhere on the client side already, verified zero SSL_CTX_load_verify_locations calls in the C tree). Go-side: delete xcecli's self-signed cert TOFU-pinning flow (cmd/auth/cert/*), CACert field, SetRootCAs/ loadRootCAs, and every call site. bug-1454: fix xcecli_ctx_t leak in scheduler.c sched_init() — the unconditional initial ctx_init was never freed before the HA candidate loop re-initialized it on the first iteration. bug-1455: sched_init()'s memset(sched, 0, ...) was silently wiping sched->cluster_cfg that main.c had populated from --peers just before calling sched_init(), so --peers was always ignored and the scheduler fell back to the hardcoded localhost:9990 single-host default. Restructured sched_init() to take cluster_cfg as an explicit parameter (assigned after the memset) instead of relying on caller-side ordering with a separate sched_set_cluster_cfg() setter, which is now removed. bug-1456: revert an unsafe stack-local xce_client_config_t introduced while fixing bug-1455 — xcecli_ctx_init() stores that pointer as ctx->conf and client_failover.c dereferences it for the ctx's entire life (runtime reconnect), so a per-loop-iteration stack copy would dangle the moment sched_init() returned. Back to mutating the caller-owned, process-lifetime config in place. Verified: full ASAN build (all components), meson test suite 9/9 OK, manual scheduler testsuite 15/15, Go build/vet/test all pass.
237 lines
6.3 KiB
Go
Executable file
237 lines
6.3 KiB
Go
Executable file
package queues
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"xcecli/common/request"
|
|
"xcecli/config"
|
|
"xcecli/models"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// QueueController queue controller
|
|
type QueueController struct {
|
|
configManager *config.ConfigManager
|
|
action string
|
|
queueNames []string
|
|
comment string
|
|
allQueues bool
|
|
}
|
|
|
|
// NewQueueController create queue controller
|
|
func NewQueueController(configManager *config.ConfigManager, action string) *QueueController {
|
|
return &QueueController{
|
|
configManager: configManager,
|
|
action: action,
|
|
queueNames: []string{},
|
|
}
|
|
}
|
|
|
|
// Run execute queue control
|
|
func (c *QueueController) RunQueuesControl() error {
|
|
// get server info and verify authentication
|
|
serverInfo, _ := c.configManager.GetServerInfo()
|
|
// create API client
|
|
apiClient := request.NewAPIClient(serverInfo.URL)
|
|
|
|
// handle all queues case
|
|
if c.allQueues {
|
|
c.queueNames = []string{"all"}
|
|
}
|
|
|
|
// if no queue names are specified, return an error
|
|
if len(c.queueNames) == 0 {
|
|
return fmt.Errorf("must specify queue names or use --all option")
|
|
}
|
|
|
|
// create request
|
|
req := models.QueueControlRequest{
|
|
ControlAction: c.action,
|
|
QueueName: c.queueNames,
|
|
Comment: c.comment,
|
|
}
|
|
|
|
// convert request to JSON bytes
|
|
reqData, err := json.Marshal(req)
|
|
if err != nil {
|
|
errMsg := request.ExtractErrorMessage(err)
|
|
return fmt.Errorf("failed to encode request data: [%s]", errMsg)
|
|
}
|
|
|
|
// send request
|
|
var resp models.QueueControlResponse
|
|
err = apiClient.PostRequestToAPIServer(
|
|
serverInfo.Token,
|
|
"/xce/v1/queues/control",
|
|
reqData,
|
|
&resp,
|
|
)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(c.queueNames) == 1 && c.queueNames[0] == "all" {
|
|
for _, data := range resp.Data.Accepted {
|
|
fmt.Printf("queue <%s> is being <%s>\n", data.QueueName, c.action)
|
|
}
|
|
for _, queue := range resp.Data.Failed {
|
|
fmt.Printf("queue <%s> cannot be <%s> for reason <%s>\n", queue.QueueName, c.action, queue.Msg)
|
|
}
|
|
} else {
|
|
for _, data := range resp.Data.Accepted {
|
|
fmt.Printf("queue <%s> is being <%s>\n", data.QueueName, c.action)
|
|
}
|
|
for _, queue := range resp.Data.Failed {
|
|
fmt.Printf("queue <%s> cannot be <%s> for reason <%s>\n", queue.QueueName, c.action, queue.Msg)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Parse parse command line arguments
|
|
func (c *QueueController) ParseCmdArgs(cmd *cobra.Command, args []string) error {
|
|
// handle queue name parameters
|
|
if len(args) > 0 {
|
|
// Split comma-separated queue names
|
|
for _, arg := range args {
|
|
queues := strings.Split(arg, ",")
|
|
c.queueNames = append(c.queueNames, queues...)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// NewOpenQueuesCmd create open queues command
|
|
func NewOpenQueuesCmd(configManager *config.ConfigManager) *cobra.Command {
|
|
controller := NewQueueController(configManager, "open")
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "open",
|
|
Short: "Open queues",
|
|
Long: `Open queues by queue name.
|
|
Opens queues to accept new job submissions.
|
|
|
|
Examples:
|
|
xce queues open normal priority # open specific queues
|
|
xce queues open --all # open all queues`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if err := controller.ParseCmdArgs(cmd, args); err != nil {
|
|
fmt.Println(strings.ToLower(err.Error()))
|
|
return nil
|
|
}
|
|
if err := controller.RunQueuesControl(); err != nil {
|
|
fmt.Println(strings.ToLower(err.Error()))
|
|
return nil
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// add control options
|
|
flags := cmd.Flags()
|
|
flags.BoolVarP(&controller.allQueues, "all", "a", false, "apply to all queues")
|
|
flags.StringVarP(&controller.comment, "comment", "c", "", "add comment for this operation")
|
|
|
|
return cmd
|
|
}
|
|
|
|
// NewCloseQueuesCmd create close queues command
|
|
func NewCloseQueuesCmd(configManager *config.ConfigManager) *cobra.Command {
|
|
controller := NewQueueController(configManager, "close")
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "close",
|
|
Short: "Close queues",
|
|
Long: `Close queues by queue name.
|
|
Closes queues to prevent new job submissions.
|
|
|
|
Examples:
|
|
xce queues close normal priority # close specific queues
|
|
xce queues close --all # close all queues`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if err := controller.ParseCmdArgs(cmd, args); err != nil {
|
|
fmt.Println(strings.ToLower(err.Error()))
|
|
return nil
|
|
}
|
|
if err := controller.RunQueuesControl(); err != nil {
|
|
fmt.Println(strings.ToLower(err.Error()))
|
|
return nil
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// add control options
|
|
flags := cmd.Flags()
|
|
flags.BoolVarP(&controller.allQueues, "all", "a", false, "apply to all queues")
|
|
flags.StringVarP(&controller.comment, "comment", "c", "", "add comment for this operation")
|
|
|
|
return cmd
|
|
}
|
|
|
|
// NewActiveQueuesCmd create active queues command
|
|
func NewActiveQueuesCmd(configManager *config.ConfigManager) *cobra.Command {
|
|
controller := NewQueueController(configManager, "active")
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "active",
|
|
Short: "Active queues",
|
|
Long: `Active queues by queue name.
|
|
|
|
Examples:
|
|
xce queues active # queues_name status close/d`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if err := controller.ParseCmdArgs(cmd, args); err != nil {
|
|
fmt.Println(strings.ToLower(err.Error()))
|
|
return nil
|
|
}
|
|
if err := controller.RunQueuesControl(); err != nil {
|
|
fmt.Println(strings.ToLower(err.Error()))
|
|
return nil
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// add control options
|
|
flags := cmd.Flags()
|
|
flags.BoolVarP(&controller.allQueues, "all", "a", false, "apply to all queues")
|
|
flags.StringVarP(&controller.comment, "comment", "c", "", "add comment for this operation")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func NewDeactiveQueuesCmd(configManager *config.ConfigManager) *cobra.Command {
|
|
controller := NewQueueController(configManager, "deactive")
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "deactive",
|
|
Short: "Deactive queues",
|
|
Long: `Deactive queues by queue name.
|
|
|
|
Examples:
|
|
xce queues deactive # queues_name status close/d`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if err := controller.ParseCmdArgs(cmd, args); err != nil {
|
|
fmt.Println(strings.ToLower(err.Error()))
|
|
return nil
|
|
}
|
|
if err := controller.RunQueuesControl(); err != nil {
|
|
fmt.Println(strings.ToLower(err.Error()))
|
|
return nil
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// add control options
|
|
flags := cmd.Flags()
|
|
flags.BoolVarP(&controller.allQueues, "all", "a", false, "apply to all queues")
|
|
flags.StringVarP(&controller.comment, "comment", "c", "", "add comment for this operation")
|
|
|
|
return cmd
|
|
}
|