github.com/diptanu/nomad@v0.5.7-0.20170516172507-d72e86cbe3d9/nomad/system_endpoint.go (about)

     1  package nomad
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/nomad/nomad/structs"
     7  )
     8  
     9  // System endpoint is used to call invoke system tasks.
    10  type System struct {
    11  	srv *Server
    12  }
    13  
    14  // GarbageCollect is used to trigger the system to immediately garbage collect nodes, evals
    15  // and jobs.
    16  func (s *System) GarbageCollect(args *structs.GenericRequest, reply *structs.GenericResponse) error {
    17  	if done, err := s.srv.forward("System.GarbageCollect", args, args, reply); done {
    18  		return err
    19  	}
    20  
    21  	// Get the states current index
    22  	snapshotIndex, err := s.srv.fsm.State().LatestIndex()
    23  	if err != nil {
    24  		return fmt.Errorf("failed to determine state store's index: %v", err)
    25  	}
    26  
    27  	s.srv.evalBroker.Enqueue(s.srv.coreJobEval(structs.CoreJobForceGC, snapshotIndex))
    28  	return nil
    29  }
    30  
    31  // ReconcileSummaries reconciles the summaries of all the jobs in the state
    32  // store
    33  func (s *System) ReconcileJobSummaries(args *structs.GenericRequest, reply *structs.GenericResponse) error {
    34  	if done, err := s.srv.forward("System.ReconcileJobSummaries", args, args, reply); done {
    35  		return err
    36  	}
    37  
    38  	_, index, err := s.srv.raftApply(structs.ReconcileJobSummariesRequestType, args)
    39  	if err != nil {
    40  		return fmt.Errorf("reconciliation of job summaries failed: %v", err)
    41  	}
    42  	reply.Index = index
    43  	return nil
    44  }