Skip to content

Commit

Permalink
Merge pull request #109 from cybozu-go/update-lifecycle
Browse files Browse the repository at this point in the history
Replace `Dead` to `Unreachable`
  • Loading branch information
zoetrope committed Oct 11, 2018
2 parents 71976c4 + 544fdb0 commit 261eae4
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/sabactl/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ STATE can be one of:
uninitialized The machine is not yet initialized.
healthy The machine has no problems.
unhealthy The machine has some problems.
dead The machine does not communicate with others.
unreachable The machine does not communicate with others.
updating The machine is updating.
retiring The machine should soon be retired/repaired.
`,
Expand Down
4 changes: 2 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ The new state is given by contents of request body and should be one of:
* `uninitialized`
* `healthy`
* `unhealthy`
* `dead`
* `unreachable`
* `updating`
* `retiring`

Expand Down Expand Up @@ -313,7 +313,7 @@ The state will be returned by response body and should be one of:
* uninitialized
* healthy
* unhealthy
* dead
* unreachable
* updating
* retiring
* retired
Expand Down
14 changes: 7 additions & 7 deletions docs/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Sabakan defines following machine states:
* **Uninitialized**: Machines to not be initialized.
* **Healthy**: Machines that can run applications
* **Unhealthy**: Machines having problems to be repaired
* **Dead**: Machines that cannot be accessed
* **Unreachable**: Machines that cannot be accessed
* **Updating**: Machines to be updating
* **Retiring**: Machines to be retired/repaired
* **Retired**: Machines whose disk encryption keys were deleted
Expand All @@ -40,16 +40,16 @@ External controllers are expected to:
* Prepare **Uninitialized** machines to (re)join to application clusters.
* Allocate **Healthy** machines to applications like Kubernetes or Ceph.
* Reboot the **Updating** machines, Machines will be **Uninitialized** after reboot.
* Drain **Unhealthy**, **Dead** and **Retiring** machines from applications.
* Drain **Unhealthy**, **Unreachable** and **Retiring** machines from applications.
* Remove disk encryption keys of **Retiring** machines after drain.

### Transition constraints

* **Uninitialized**, ***Healthy**, **Unhealthy**, or **Dead** machine can transition to **Retiring**.
* **Uninitialized**, ***Healthy**, **Unhealthy**, or **Unreachable** machine can transition to **Retiring**.
* A **Retiring** machine can transition only to **Retired**.
* A **Healthy** machine can transition to **Unhealthy**, **Dead**, **Retiring**, and **Updating**.
* A **Unhealthy** machine can transition to **Dead**.
* **Uneahlthy** and **Dead** machine can not return to **Healthy** directly.
* A **Healthy** machine can transition to **Unhealthy**, **Unreachable**, **Retiring**, and **Updating**.
* A **Unreachable** machine can transition to **Healthy**.
* **Uneahlthy** machine cannot return to **Healthy** directly.
* Disk encryption keys of a machine can be deleted if the machine is in **Retiring** state.
* A machine transitions to **Retired** when its disk encryption keys are deleted.
* Only **Retired** machines can be removed from sabakan.
Expand All @@ -64,4 +64,4 @@ sabakan.

### Transition diagram

![state transition diagram](http://www.plantuml.com/plantuml/png/ZP91JuH038NlyojwDY7UEPWrxa4lncoo9-EXC5sPCDCXfRZ1No-3B3h4nBsGbdxlFMYwwnL5X-3DwyqR53QUkRY38pjswj2xJx8cww2Ove-4NflnZyc1r8dZznBsL7jqGY3BAsCMsGmUkVdk4gbKQm_8G29HCcvFQ4ju9Zr7QM5W8QmRh3nbr2RsT-gA3LsAxIng0jVgza1LZAa2RGZ2PE-OZBdCeTWkf8JxavA0pCA9vEQwJyd0hUVJsa107j3xSID8gp0cFVyBMfbDnejGby3iHyt5wCSriGSAyOFwcRMkRu6ubh5J5nbQ6XSPNPspuEkDJVTMmWCoI0hAM3X93D1ZXIsosH7R8VWl)
![state transition diagram](http://www.plantuml.com/plantuml/png/ZPB1JiCm38RlUGgVaIhkFQ0XTe0BGfKu8GvUuz6eYLEvBbDvUfgnXQL2QBVO_dv_RPJDg2Ww1M_URjwXil70rHsyicEd3htx8ckA2gfb_aZejPl_c3IaJXn_rB2brgCJ0ZcrZ3d55Z0fkfygaKgjZe0C91AbuBQ4jePdqaEK7YOMmhR3dQU2McalhHcRXgGTB6e2y-cseLsCwGJQ4OHblMCovZo7QdqXDTplbGJa65n8xgxxb19SxNpA1GJa2RsVZTaIbZUU6_zeChCol0WD2RpupGkLEM_yNPz23ONuIUCnPDtO0t4hyw0kClGqds9qhJ3ZvwUsFBiQ7f11agXWOIynm8Wxx97DXjXEmNy3)
4 changes: 2 additions & 2 deletions docs/sabactl.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Detailed specification of the query parameters and the output JSON content is sa
----------------------------

Set the state of a machine.
State is one of `uninitialized`, `healthy`, `unhealthy`, `dead`, `updating` or `retiring`.
State is one of `uninitialized`, `healthy`, `unhealthy`, `unreachable`, `updating` or `retiring`.

```console
$ sabactl machines set-state <serial> <state>
Expand All @@ -100,7 +100,7 @@ $ sabactl machines set-state <serial> <state>
----------------------------

Get the state of a machine.
State is one of `uninitialized`, `healthy`, `unhealthy`, `dead`, `updating`, `retiring` or `retired`.
State is one of `uninitialized`, `healthy`, `unhealthy`, `unreachable`, `updating`, `retiring` or `retired`.

```console
$ sabactl machines get-state <serial>
Expand Down
8 changes: 4 additions & 4 deletions machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
StateUninitialized = MachineState("uninitialized")
StateHealthy = MachineState("healthy")
StateUnhealthy = MachineState("unhealthy")
StateDead = MachineState("dead")
StateUnreachable = MachineState("unreachable")
StateUpdating = MachineState("updating")
StateRetiring = MachineState("retiring")
StateRetired = MachineState("retired")
Expand Down Expand Up @@ -111,11 +111,11 @@ func (m *Machine) SetState(ms MachineState) error {
return errors.New("transition to " + ms.String() + " is forbidden")
}
case StateUnhealthy:
if ms == StateHealthy || ms == StateUpdating || ms == StateRetired {
if ms != StateUninitialized && ms != StateRetiring {
return errors.New("transition to " + ms.String() + " is forbidden")
}
case StateDead:
if ms == StateHealthy || ms == StateUpdating || ms == StateRetired || ms == StateUnhealthy {
case StateUnreachable:
if ms == StateUpdating || ms == StateRetired || ms == StateUnhealthy {
return errors.New("transition to " + ms.String() + " is forbidden")
}
case StateUpdating:
Expand Down
2 changes: 1 addition & 1 deletion query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestMatch(t *testing.T) {
{Query{"ipv6": "aa::ff"}, NewMachine(MachineSpec{IPv6: []string{"bb::ff", "cc::ff"}}), false},
{Query{"ipv4": "10.20.30.40"}, NewMachine(MachineSpec{}), false},
{Query{"ipv6": "aa::ff"}, NewMachine(MachineSpec{}), false},
{Query{"state": "dead"}, NewMachine(MachineSpec{}), false},
{Query{"state": "unreachable"}, NewMachine(MachineSpec{}), false},
}

for _, c := range cases {
Expand Down
2 changes: 1 addition & 1 deletion web/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func testMachinesGet(t *testing.T) {
expected: nil,
},
{
query: map[string][]string{"state": {"dead"}},
query: map[string][]string{"state": {"unreachable"}},
status: http.StatusNotFound,
expected: nil,
},
Expand Down
2 changes: 1 addition & 1 deletion web/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s Server) handleStatePut(w http.ResponseWriter, r *http.Request, serial st

ms := sabakan.MachineState(state)
switch ms {
case sabakan.StateUninitialized, sabakan.StateHealthy, sabakan.StateUnhealthy, sabakan.StateDead, sabakan.StateUpdating, sabakan.StateRetiring:
case sabakan.StateUninitialized, sabakan.StateHealthy, sabakan.StateUnhealthy, sabakan.StateUnreachable, sabakan.StateUpdating, sabakan.StateRetiring:
default:
renderError(r.Context(), w, BadRequest("invalid state: "+string(state)))
return
Expand Down
7 changes: 6 additions & 1 deletion web/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ func testStatePut(t *testing.T) {
{"unhealthy", 500},
{"uninitialized", 200},
{"healthy", 200},
{"unreachable", 200},
{"healthy", 200},
{"unreachable", 200},
{"unhealthy", 500},
{"healthy", 200},
{"unhealthy", 200},
{"healthy", 500},
{"dead", 200},
{"unreachable", 500},
{"uninitialized", 200},
{"healthy", 200},
{"retired", 400},
Expand Down

0 comments on commit 261eae4

Please sign in to comment.