aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/admin/clusterstate/known_state.go
blob: 18e5239061e258675e75bbcec0e3b3ffc38b7d9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej

// utilities to get and manipulate node states in a storage cluster
package clusterstate

import (
	"fmt"
)

type KnownState string

// these are all the valid node states:
const (
	StateUp          KnownState = "up"
	StateDown        KnownState = "down"
	StateMaintenance KnownState = "maintenance"
	StateRetired     KnownState = "retired"
)

// verify that a string is one of the known states:
func knownState(s string) (KnownState, error) {
	alternatives := []KnownState{
		StateUp,
		StateDown,
		StateMaintenance,
		StateRetired,
	}
	for _, v := range alternatives {
		if s == string(v) {
			return v, nil
		}
	}
	return KnownState("unknown"), fmt.Errorf("<Wanted State> must be one of %v, was %s\n", alternatives, s)
}