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.
84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
package jobs
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"xcecli/common/request"
|
|
"xcecli/config"
|
|
"xcecli/models"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func NewJobRestart(configManager *config.ConfigManager) *JobRestart {
|
|
return &JobRestart{
|
|
configManager: configManager,
|
|
jobID: "",
|
|
askedHosts: "",
|
|
}
|
|
}
|
|
|
|
type JobRestart struct {
|
|
configManager *config.ConfigManager
|
|
jobID string
|
|
askedHosts string
|
|
}
|
|
|
|
func (c *JobRestart) ParseCmdArgs(cmd *cobra.Command, args []string) error {
|
|
for _, arg := range args {
|
|
if arg != "" && c.jobID == "" {
|
|
c.jobID = arg
|
|
}
|
|
}
|
|
// check if any filter conditions are set
|
|
if c.jobID == "" {
|
|
// if no job IDs or filter conditions are specified, default to processing all jobs of the current user
|
|
return fmt.Errorf("no job ID is specified")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c *JobRestart) RunJobsRestart() error {
|
|
// Get server information
|
|
serverInfo, _ := c.configManager.GetServerInfo()
|
|
|
|
// Create API client
|
|
apiClient := request.NewAPIClient(serverInfo.URL)
|
|
|
|
return c.restartJobsByID(apiClient, serverInfo.Token)
|
|
}
|
|
|
|
func (c *JobRestart) restartJobsByID(apiClient *request.APIClient, token string) error {
|
|
url := fmt.Sprintf("/xce/v1/jobs/%s/restart", c.jobID)
|
|
|
|
req := &models.JobRestartRequest{
|
|
AskedHosts: c.askedHosts,
|
|
}
|
|
|
|
return c.printJobRestartResponse(req, apiClient, token, url)
|
|
|
|
}
|
|
|
|
func (c *JobRestart) printJobRestartResponse(req interface{}, apiClient *request.APIClient, token string, url string) error {
|
|
reqData, err := json.Marshal(req)
|
|
if err != nil {
|
|
errMsg := request.ExtractErrorMessage(err)
|
|
return fmt.Errorf("failed to encode request data: [%s]", errMsg)
|
|
}
|
|
var resp models.JobRestartResponse
|
|
err = apiClient.PostRequestToAPIServer(
|
|
token,
|
|
url,
|
|
reqData,
|
|
&resp,
|
|
)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
row := resp.Data
|
|
if row != nil {
|
|
fmt.Printf("%s\n", row.Message)
|
|
}
|
|
return nil
|
|
}
|