open-nomad/nomad/system_endpoint.go

46 lines
1.3 KiB
Go
Raw Normal View History

2016-02-20 23:50:41 +00:00
package nomad
import (
"fmt"
2016-02-20 23:50:41 +00:00
"github.com/hashicorp/nomad/nomad/structs"
)
// System endpoint is used to call invoke system tasks.
type System struct {
srv *Server
}
// GarbageCollect is used to trigger the system to immediately garbage collect nodes, evals
// and jobs.
func (s *System) GarbageCollect(args *structs.GenericRequest, reply *structs.GenericResponse) error {
if done, err := s.srv.forward("System.GarbageCollect", args, args, reply); done {
return err
}
2016-06-22 16:33:15 +00:00
// Get the states current index
snapshotIndex, err := s.srv.fsm.State().LatestIndex()
if err != nil {
2016-06-22 16:33:15 +00:00
return fmt.Errorf("failed to determine state store's index: %v", err)
}
s.srv.evalBroker.Enqueue(s.srv.coreJobEval(structs.CoreJobForceGC, snapshotIndex))
2016-02-20 23:50:41 +00:00
return nil
}
// ReconcileSummaries reconciles the summaries of all the jobs in the state
// store
func (s *System) ReconcileJobSummaries(args *structs.GenericRequest, reply *structs.GenericResponse) error {
if done, err := s.srv.forward("System.ReconcileJobSummaries", args, args, reply); done {
return err
}
_, index, err := s.srv.raftApply(structs.ReconcileJobSummariesRequestType, args)
if err != nil {
s.srv.logger.Printf("[ERR] nomad.client: Reconcile failed: %v", err)
return err
}
reply.Index = index
return nil
}