Skip to content

Commit

Permalink
Merge pull request #93 from Cray-HPE/ActionIDNull
Browse files Browse the repository at this point in the history
CASMHMS-6055 - FAS Action IDs null
  • Loading branch information
mbuchmann-hpe committed Jun 30, 2023
2 parents f4d7ccd + bb96c2c commit d244cc0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.28.0
1.29.0
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.29.0] - 2023-06-30

- Changed FAS database struct back to use "actionID" instead of the
accidental change to "id"
- Any records created with "id" will still work by adjusting the id when read

## [1.28.0] - 2023-04-27

- Update to Python library Semver to 3.0
Expand Down
17 changes: 13 additions & 4 deletions internal/storage/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ type Action struct {
}

type ActionStorable struct {
ActionID uuid.UUID `json:"id"`
SnapshotID uuid.UUID `json:"snapshotID,omitempty"`
Command Command `json:"command"`
ActionID uuid.UUID
SnapshotID uuid.UUID
Command Command
StartTime sql.NullTime `json:"startTime"`
EndTime sql.NullTime `json:"endTime"`
State string `json:"state"`
Expand All @@ -72,6 +72,10 @@ type ActionStorable struct {
Errors []string `json:"errors"`
}

type ActionStorableID struct {
ActionID uuid.UUID `json:"id"`
}

func ToActionStorable(from Action) (to ActionStorable) {
to = ActionStorable{
ActionID: from.ActionID,
Expand All @@ -89,7 +93,9 @@ func ToActionStorable(from Action) (to ActionStorable) {
return
}

func ToActionFromStorable(from ActionStorable) (to Action) {
// Added id - workaround for incorrect storage from v1.26.0
// id will overwrite ActionID if ActionID is Nil
func ToActionFromStorable(from ActionStorable, id uuid.UUID) (to Action) {
to = Action{
ActionID: from.ActionID,
SnapshotID: from.SnapshotID,
Expand All @@ -102,6 +108,9 @@ func ToActionFromStorable(from ActionStorable) (to Action) {
BlockedBy: from.BlockedBy,
Errors: from.Errors,
}
if to.ActionID == uuid.Nil {
to.ActionID = id
}

to.State = fsm.NewFSM(
"new",
Expand Down
14 changes: 12 additions & 2 deletions internal/storage/etcd_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,17 @@ func (e *ETCDStorage) DeleteAction(actionID uuid.UUID) (err error) {
func (e *ETCDStorage) GetAction(actionID uuid.UUID) (a Action, err error) {
key := fmt.Sprintf("/actions/%s", actionID.String())

// Look for an id instead of an actionID - workaround for incorrect string in v1.26.0
var retrieveableID ActionStorableID
retrieveableID.ActionID = uuid.Nil
err = e.kvGet(key, &retrieveableID)

var retrieveable ActionStorable
err = e.kvGet(key, &retrieveable)
if err != nil {
e.Logger.Error(err)
}
a = ToActionFromStorable(retrieveable)
a = ToActionFromStorable(retrieveable, retrieveableID.ActionID)
return a, err
}

Expand All @@ -190,12 +195,17 @@ func (e *ETCDStorage) GetActions() (a []Action, err error) {
kvl, err := e.kvHandle.GetRange(k+keyMin, k+keyMax)
if err == nil {
for _, kv := range kvl {
// Look for an id instead of an actionID - workaround for incorrect string in v1.26.0
var actID ActionStorableID
actID.ActionID = uuid.Nil
_ = json.Unmarshal([]byte(kv.Value), &actID)

var act ActionStorable
err = json.Unmarshal([]byte(kv.Value), &act)
if err != nil {
e.Logger.Error(err)
} else {
newAct := ToActionFromStorable(act)
newAct := ToActionFromStorable(act, actID.ActionID)
a = append(a, newAct)
}
}
Expand Down

0 comments on commit d244cc0

Please sign in to comment.