github.com/emate/nomad@v0.8.2-wo-binpacking/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  	// Check management level permissions
    22  	if acl, err := s.srv.ResolveToken(args.AuthToken); err != nil {
    23  		return err
    24  	} else if acl != nil && !acl.IsManagement() {
    25  		return structs.ErrPermissionDenied
    26  	}
    27  
    28  	// Get the states current index
    29  	snapshotIndex, err := s.srv.fsm.State().LatestIndex()
    30  	if err != nil {
    31  		return fmt.Errorf("failed to determine state store's index: %v", err)
    32  	}
    33  
    34  	s.srv.evalBroker.Enqueue(s.srv.coreJobEval(structs.CoreJobForceGC, snapshotIndex))
    35  	return nil
    36  }
    37  
    38  // ReconcileSummaries reconciles the summaries of all the jobs in the state
    39  // store
    40  func (s *System) ReconcileJobSummaries(args *structs.GenericRequest, reply *structs.GenericResponse) error {
    41  	if done, err := s.srv.forward("System.ReconcileJobSummaries", args, args, reply); done {
    42  		return err
    43  	}
    44  
    45  	// Check management level permissions
    46  	if acl, err := s.srv.ResolveToken(args.AuthToken); err != nil {
    47  		return err
    48  	} else if acl != nil && !acl.IsManagement() {
    49  		return structs.ErrPermissionDenied
    50  	}
    51  
    52  	_, index, err := s.srv.raftApply(structs.ReconcileJobSummariesRequestType, args)
    53  	if err != nil {
    54  		return fmt.Errorf("reconciliation of job summaries failed: %v", err)
    55  	}
    56  	reply.Index = index
    57  	return nil
    58  }