github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/payloads/status.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package payloads 5 6 import ( 7 "fmt" 8 "sort" 9 "strings" 10 11 "github.com/juju/collections/set" 12 "github.com/juju/errors" 13 ) 14 15 // The Juju-recognized states in which a payload might be. 16 const ( 17 StateUndefined = "" 18 //TODO(wwitzel3) remove defined throughout 19 StateDefined = "defined" 20 StateStarting = "starting" 21 StateRunning = "running" 22 StateStopping = "stopping" 23 StateStopped = "stopped" 24 ) 25 26 var okayStates = set.NewStrings( 27 StateStarting, 28 StateRunning, 29 StateStopping, 30 StateStopped, 31 ) 32 33 // ValidateState verifies the state passed in is a valid okayState. 34 func ValidateState(state string) error { 35 if !okayStates.Contains(state) { 36 supported := okayStates.Values() 37 sort.Strings(supported) 38 states := strings.Join(supported, `", "`) 39 msg := fmt.Sprintf(`status %q not supported; expected one of ["%s"]`, state, states) 40 return errors.NewNotValid(nil, msg) 41 } 42 return nil 43 }