Skip to content
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

LRO poller rewrite #14752

Merged
merged 21 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
consolidate status constants
  • Loading branch information
jhendrixMSFT committed Jun 9, 2021
commit 311af89299f0c5b4670ab9f32ef97fc607ab672f
2 changes: 1 addition & 1 deletion sdk/armcore/internal/pollers/async/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func New(resp *azcore.Response, finalState string, pollerID string) (*Poller, er
return nil, err
}*/
// for DELETE/PATCH/POST, provisioning state is optional
state = "InProgress"
state = pollers.StatusInProgress
} else if err != nil {
return nil, err
}
Expand Down
15 changes: 5 additions & 10 deletions sdk/armcore/internal/pollers/body/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
)

const (
stateSucceeded = "Succeeded"
stateInProgress = "InProgress"
)

// Applicable returns true if the LRO is using no headers, just provisioning state.
// This is only applicable to PATCH and PUT methods and assumes no polling headers.
func Applicable(resp *azcore.Response) bool {
Expand All @@ -42,7 +37,7 @@ func New(resp *azcore.Response, pollerID string) (*Poller, error) {
}
// default initial state to InProgress. depending on the HTTP
// status code and provisioning state, we might change the value.
curState := stateInProgress
curState := pollers.StatusInProgress
provState, err := pollers.GetProvisioningState(resp)
if err != nil && !errors.Is(err, pollers.ErrNoBody) && !errors.Is(err, pollers.ErrNoProvisioningState) {
return nil, err
Expand All @@ -55,10 +50,10 @@ func New(resp *azcore.Response, pollerID string) (*Poller, error) {
curState = provState
} else if provState == "" {
// for a 200, absense of provisioning state indicates success
curState = stateSucceeded
curState = pollers.StatusSucceeded
}
} else if resp.StatusCode == http.StatusNoContent {
curState = stateSucceeded
curState = pollers.StatusSucceeded
}
p.CurState = curState
return p, nil
Expand All @@ -77,7 +72,7 @@ func (p *Poller) Done() bool {
// Update updates the Poller from the polling response.
func (p *Poller) Update(resp *azcore.Response) error {
if resp.StatusCode == http.StatusNoContent {
p.CurState = stateSucceeded
p.CurState = pollers.StatusSucceeded
return nil
}
state, err := pollers.GetProvisioningState(resp)
Expand All @@ -86,7 +81,7 @@ func (p *Poller) Update(resp *azcore.Response) error {
return err
} else if errors.Is(err, pollers.ErrNoProvisioningState) {
// a response body without provisioning state is considered terminal success
state = stateSucceeded
state = pollers.StatusSucceeded
} else if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions sdk/armcore/internal/pollers/loc/loc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func New(resp *azcore.Response, pollerID string) (*Poller, error) {
p := &Poller{
Type: pollers.MakeID(pollerID, "loc"),
PollURL: locURL,
CurState: "InProgress",
CurState: pollers.StatusInProgress,
}
return p, nil
}
Expand Down Expand Up @@ -67,12 +67,12 @@ func (p *Poller) Update(resp *azcore.Response) error {
p.CurState = state
} else {
// a 200/201 with no provisioning state indicates success
p.CurState = "Succeeded"
p.CurState = pollers.StatusSucceeded
}
} else if resp.StatusCode == http.StatusNoContent {
p.CurState = "Succeeded"
p.CurState = pollers.StatusSucceeded
} else if resp.StatusCode > 399 && resp.StatusCode < 500 {
p.CurState = "Failed"
p.CurState = pollers.StatusFailed
}
// a 202 falls through, means the LRO is still in progress and we don't check for provisioning state
return nil
Expand Down
11 changes: 6 additions & 5 deletions sdk/armcore/internal/pollers/pollers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ const (
)

const (
statusSucceeded = "succeeded"
statusCanceled = "canceled"
statusFailed = "failed"
StatusSucceeded = "Succeeded"
StatusCanceled = "Canceled"
StatusFailed = "Failed"
StatusInProgress = "InProgress"
)

// reads the response body into a raw JSON object.
Expand Down Expand Up @@ -85,12 +86,12 @@ func status(jsonBody map[string]interface{}) string {

// IsTerminalState returns true if the LRO's state is terminal.
func IsTerminalState(s string) bool {
return strings.EqualFold(s, statusSucceeded) || strings.EqualFold(s, statusFailed) || strings.EqualFold(s, statusCanceled)
return strings.EqualFold(s, StatusSucceeded) || strings.EqualFold(s, StatusFailed) || strings.EqualFold(s, StatusCanceled)
}

// Failed returns true if the LRO's state is terminal failure.
func Failed(s string) bool {
return strings.EqualFold(s, statusFailed) || strings.EqualFold(s, statusCanceled)
return strings.EqualFold(s, StatusFailed) || strings.EqualFold(s, StatusCanceled)
}

// GetStatus returns the LRO's status from the response body.
Expand Down
2 changes: 1 addition & 1 deletion sdk/armcore/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (*nopPoller) FinalGetURL() string {
}

func (*nopPoller) Status() string {
return "Succeeded"
return pollers.StatusSucceeded
}

// returns true if the LRO response contains a valid HTTP status code
Expand Down