Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
add: base subsystem state definitions
Browse files Browse the repository at this point in the history
This adds the definitions for:
- a map defining the priority of a descriptionCode
- a map defining the stateCode of a descriptionCode
- a couple of LogTags the middleware logs, which are read by the
supervisor
  • Loading branch information
0xB10C committed Dec 4, 2019
1 parent f962385 commit 7573df7
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion middleware/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20191122093321-5bacb3c08094
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20191204135529-eb28ed7e9cbd
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6
github.com/gomodule/redigo v2.0.0+incompatible
github.com/gorilla/mux v1.7.3
Expand Down
4 changes: 2 additions & 2 deletions middleware/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20191122093321-5bacb3c08094 h1:jcYoFlcJJQWJENsG2HPNEnp0jNx8H2pmvIv3oa9qLyE=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20191122093321-5bacb3c08094/go.mod h1:yMwrh5lnSF+UDy+PLdCySxWHZubd2Tk/t2EQ1++4mgA=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20191204135529-eb28ed7e9cbd h1:K29fNVgdarWFPuhnR05ZdZYuNeMe63Ym/18nJQohwsU=
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20191204135529-eb28ed7e9cbd/go.mod h1:yMwrh5lnSF+UDy+PLdCySxWHZubd2Tk/t2EQ1++4mgA=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6 h1:u/UEqS66A5ckRmS4yNpjmVH56sVtS/RfclBAYocb4as=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down
36 changes: 36 additions & 0 deletions middleware/src/logtags/logtags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package logtags

// These LogTags are shared logtags between the Middleware and the Supervisor.
// The supervisor watches these and triggers the corresponding handler.
const (
// LogTagMWUpdateStart is logged by the middleware when the update progress
// is started. This triggers the Supervisor to set the
// `BitBoxBaseHeartbeatRequest_DOWNLOAD_UPDATE` descriptionCode to active and
// sets the `BitBoxBaseHeartbeatRequest_UPDATE_FAILED` descriptionCode to
// inactive.
LogTagMWUpdateStart string = "LogTag:Middleware:Base_Image_Update_Start"

// LogTagMWUpdateSuccess is logged by the middleware when the update progress
// ends with the success case. This triggers the supervisor to set the
// `BitBoxBaseHeartbeatRequest_DOWNLOAD_UPDATE` descriptionCode to inactive.
LogTagMWUpdateSuccess string = "LogTag:Middleware:Base_Image_Update_Success"

// LogTagMWUpdateFailure is logged by the middleware when the update progress
// ends with the success case. This triggers the supervisor to set the
// `BitBoxBaseHeartbeatRequest_DOWNLOAD_UPDATE` descriptionCode to inactive
// and sets the `BitBoxBaseHeartbeatRequest_UPDATE_FAILED` descriptionCode to
// active.
LogTagMWUpdateFailure string = "LogTag:Middleware:Base_Image_Update_Failure"

// LogTagMWReboot is logged by the middleware when a Base reboot is started
// via RPC. This triggers the supervisor to set the descriptionCode
// `BitBoxBaseHeartbeatRequest_REBOOT` to active. This descriptionCode is
// reset on every start of the Supervisor.
LogTagMWReboot string = "LogTag:Middleware:Base_Reboot"

// LogTagMWShutdown is logged by the middleware when a Base shutdown is
// started via RPC. This triggers the supervisor to set the descriptionCode
// `BitBoxBaseHeartbeatRequest_SHUTDOWN` to active. This descriptionCode is
// reset on every start of the Supervisor.
LogTagMWShutdown string = "LogTag:Middleware:Base_Shutdown"
)
1 change: 1 addition & 0 deletions tools/bbbsupervisor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ go 1.13

require (
github.com/digitalbitbox/bitbox-base/middleware v0.0.0-20191204153728-1128dd782517
github.com/digitalbitbox/bitbox02-api-go v0.0.0-20191204135529-eb28ed7e9cbd
github.com/tidwall/gjson v1.3.4
)
1 change: 1 addition & 0 deletions tools/bbbsupervisor/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ github.com/digitalbitbox/bitbox02-api-go v0.0.0-20191204135529-eb28ed7e9cbd/go.m
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
Expand Down
30 changes: 30 additions & 0 deletions tools/bbbsupervisor/systemstate/systemstate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Package systemstate defines the Base system states and peripherals of those.
package systemstate

import "github.com/digitalbitbox/bitbox02-api-go/api/firmware/messages"

// MapDescriptionCodePriority defines the priority of the DescriptionCode.
var MapDescriptionCodePriority = map[messages.BitBoxBaseHeartbeatRequest_DescriptionCode]int{
messages.BitBoxBaseHeartbeatRequest_EMPTY: 0,
messages.BitBoxBaseHeartbeatRequest_INITIAL_BLOCK_SYNC: 1200,
messages.BitBoxBaseHeartbeatRequest_DOWNLOAD_UPDATE: 1400,
messages.BitBoxBaseHeartbeatRequest_UPDATE_FAILED: 2300,
messages.BitBoxBaseHeartbeatRequest_NO_NETWORK_CONNECTION: 2400,
messages.BitBoxBaseHeartbeatRequest_REBOOT: 2500,
messages.BitBoxBaseHeartbeatRequest_SHUTDOWN: 2510,
messages.BitBoxBaseHeartbeatRequest_OUT_OF_DISK_SPACE: 3400,
messages.BitBoxBaseHeartbeatRequest_REDIS_ERROR: 3900,
}

// MapDescriptionCodeStateCode maps a DescriptionCode to the corresponding StateCode.
var MapDescriptionCodeStateCode = map[messages.BitBoxBaseHeartbeatRequest_DescriptionCode]messages.BitBoxBaseHeartbeatRequest_StateCode{
messages.BitBoxBaseHeartbeatRequest_EMPTY: messages.BitBoxBaseHeartbeatRequest_IDLE,
messages.BitBoxBaseHeartbeatRequest_INITIAL_BLOCK_SYNC: messages.BitBoxBaseHeartbeatRequest_WORKING,
messages.BitBoxBaseHeartbeatRequest_DOWNLOAD_UPDATE: messages.BitBoxBaseHeartbeatRequest_WORKING,
messages.BitBoxBaseHeartbeatRequest_REBOOT: messages.BitBoxBaseHeartbeatRequest_WARNING,
messages.BitBoxBaseHeartbeatRequest_SHUTDOWN: messages.BitBoxBaseHeartbeatRequest_WARNING,
messages.BitBoxBaseHeartbeatRequest_UPDATE_FAILED: messages.BitBoxBaseHeartbeatRequest_WARNING,
messages.BitBoxBaseHeartbeatRequest_NO_NETWORK_CONNECTION: messages.BitBoxBaseHeartbeatRequest_WARNING,
messages.BitBoxBaseHeartbeatRequest_OUT_OF_DISK_SPACE: messages.BitBoxBaseHeartbeatRequest_ERROR,
messages.BitBoxBaseHeartbeatRequest_REDIS_ERROR: messages.BitBoxBaseHeartbeatRequest_ERROR,
}

0 comments on commit 7573df7

Please sign in to comment.