New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trigger upgrade-series-prepare hook. #8864
Changes from 1 commit
1c0e8c7
0ac2132
02ce53c
be3d968
c5f67d3
678e376
3d71446
9873531
025d928
095e39e
132b877
9e06d5e
e7d842a
afd2b0e
ce7f0c9
418f215
737461e
d31fefe
cd35901
93b5a64
92d223c
f7e1ab8
1ac1597
facc529
ff4ac60
2eda0a1
7ca5aae
27b7ec7
cef8aed
aa6dcff
e5c98bb
c622313
0d31aea
71f3958
44050d1
600d130
8cee315
fb9f7cd
550ecd7
3d830be
b99b95a
2ab106c
6c00b4e
a5c59a6
8cc0cae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2205,29 +2205,62 @@ func (m *Machine) RemoveUpgradeSeriesLock() error { | |
|
||
// UpgradeSeriesStatus returns the status of a series upgrade. | ||
func (m *Machine) UpgradeSeriesStatus() (string, error) { | ||
return "preparing", nil | ||
coll, closer := m.st.db().GetCollection(machineUpgradeSeriesLocksC) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we move 2208-2215 into a helper method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can lines 2187-2198 go in a helper function to return the lock data? They are used by IsLocked() and will be used for future work as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would want to wait a bit to pull this out into a helper, perhaps we can wait until more of a tell-don't-ask pattern appears rather than making a helper that facilitates an "ask for lock, then do something with it" pattern. This comment does actually point out another issue, and that is |
||
defer closer() | ||
|
||
var lock upgradeSeriesLock | ||
err := coll.FindId(m.Id()).One(&lock) | ||
if err != nil { | ||
return "", errors.Trace(err) | ||
} | ||
s := fmt.Sprintf("%d", lock.PrepareUnits[0].Status) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest we rename to UpgradeSeriesPrepareStatus() and return the lock.PrepareStatus, and have a new Unit.UpgradeSeriesPrepareStatus() for the individual units? |
||
return s, nil | ||
} | ||
|
||
// SetUpgradeSeriesStatus sets the status of a series upgrade. | ||
func (m *Machine) SetUpgradeSeriesStatus(unitName string, status string) (string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SetUpgradeSeriesPrepareUnitStatus()? |
||
// buildTxn := func(attempt int) ([]txn.Op, error) { | ||
// if attempt > 0 { | ||
// if err := m.Refresh(); err != nil { | ||
// return nil, errors.Trace(err) | ||
// } | ||
// } | ||
// locked, err := m.IsLocked() | ||
// if err != nil { | ||
// return nil, errors.Trace(err) | ||
// } | ||
// if !locked { | ||
// return nil, errors.BadRequestf("Machine %q is not locked for upgrade", m) | ||
// } | ||
// if err = m.isStillAlive(); err != nil { | ||
// return nil, errors.Trace(err) | ||
// } | ||
// return setUpgradeSeriesTxnOps(m.doc.Id), nil | ||
// } | ||
buildTxn := func(attempt int) ([]txn.Op, error) { | ||
if attempt > 0 { | ||
if err := m.Refresh(); err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
} | ||
locked, err := m.IsLocked() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling IsLocked() is here appears to be redundant given the code at 2227-2233 with an extra error. |
||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
if !locked { | ||
return nil, errors.BadRequestf("Machine %q is not locked for upgrade", m) | ||
} | ||
if err = m.isStillAlive(); err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
coll, closer := m.st.db().GetCollection(machineUpgradeSeriesLocksC) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function should use unitStatus, err := m.UpgradeSeriesStatus(unitName)
if err != nil {
return nil, errors.Trace(err)
}
if unitStatus == status {
return nil, jujutxn.ErrNoOperations
}
// pass in the current status to assert against, and the status to set it to.
return setUpgradeSeriesTxnOps(m.Id(), unitStatus, status), nil
} |
||
defer closer() | ||
var lock upgradeSeriesLock | ||
err = coll.FindId(m.Id()).One(&lock) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot get upgrade series lock for machine %v: %v", m.Id(), err) | ||
} | ||
docIndex := -1 | ||
for i, unitStatus := range lock.PrepareUnits { | ||
if unitStatus.Id == unitName { | ||
docIndex = i | ||
} | ||
} | ||
if docIndex == -1 { | ||
return nil, fmt.Errorf("cannot get upgrade series lock for unit %q of machine %v: %v", unitName, m.Id(), err) | ||
} | ||
return setUpgradeSeriesTxnOps(m.doc.Id, unitName, docIndex, status), nil | ||
} | ||
err := m.st.db().Run(buildTxn) | ||
if err != nil { | ||
err = onAbort(err, ErrDead) | ||
logger.Errorf("cannot complete series upgrade for machine %q: %v", m, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "cannot set unit prepare upgrade series for" |
||
return "", err | ||
} | ||
|
||
return "", nil | ||
} | ||
|
||
|
@@ -2258,7 +2291,8 @@ func removeUpgradeSeriesLockTxnOps(machineDocId string) []txn.Op { | |
} | ||
} | ||
|
||
func setUpgradeSeriesTxnOps(machineDocId string) []txn.Op { | ||
func setUpgradeSeriesTxnOps(machineDocId, unitName string, unitIndex int, status string) []txn.Op { | ||
unitField := fmt.Sprintf("prepareunits.%d.status", unitIndex) | ||
return []txn.Op{ | ||
{ | ||
C: machinesC, | ||
|
@@ -2268,8 +2302,9 @@ func setUpgradeSeriesTxnOps(machineDocId string) []txn.Op { | |
{ | ||
C: machineUpgradeSeriesLocksC, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would we want to take the unit id and assert that |
||
Id: machineDocId, | ||
Assert: txn.DocMissing, | ||
// Update: bson.D{{"$set", bson.D{{"keep-instance", keepInstance}}}}, | ||
Assert: txn.DocExists, | ||
Update: bson.D{ | ||
{"$set", bson.D{{unitField, status}}}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would probably be better to have the unit fields keyed off the unit tag rather than an offset. This would make it easier to make the sested set. Also you should assert that the field matches the expected value. |
||
}, | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why pass back a string? the two status types are typed.