Skip to content

Commit c46e6a9

Browse files
authored
Optimising REST APIs for LUN to wait for job rather than LUN status
1 parent 3e8f61b commit c46e6a9

File tree

2 files changed

+18
-56
lines changed

2 files changed

+18
-56
lines changed

storage_drivers/ontap/api/ontap_rest.go

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,38 +2485,6 @@ func (c *RestClient) LunOptions(
24852485
return result, nil
24862486
}
24872487

2488-
// pollLunCreate polls for the created LUN to appear, with backoff retry logic
2489-
func (c *RestClient) pollLunCreate(ctx context.Context, lunPath string) error {
2490-
checkCreateStatus := func() error {
2491-
fields := []string{""}
2492-
lun, err := c.LunGetByName(ctx, lunPath, fields)
2493-
if err != nil {
2494-
return err
2495-
}
2496-
if lun == nil {
2497-
return fmt.Errorf("could not find LUN with name %v", lunPath)
2498-
}
2499-
return nil
2500-
}
2501-
createStatusNotify := func(err error, duration time.Duration) {
2502-
Logc(ctx).WithField("increment", duration).Debug("LUN creation not finished, waiting.")
2503-
}
2504-
createStatusBackoff := backoff.NewExponentialBackOff()
2505-
createStatusBackoff.InitialInterval = 1 * time.Second
2506-
createStatusBackoff.Multiplier = 2
2507-
createStatusBackoff.RandomizationFactor = 0.1
2508-
createStatusBackoff.MaxElapsedTime = 2 * time.Minute
2509-
2510-
// Run the creation check using an exponential backoff
2511-
if err := backoff.RetryNotify(checkCreateStatus, createStatusBackoff, createStatusNotify); err != nil {
2512-
Logc(ctx).WithField("LUN", lunPath).Warnf("LUN not found after %3.2f seconds.",
2513-
createStatusBackoff.MaxElapsedTime.Seconds())
2514-
return err
2515-
}
2516-
2517-
return nil
2518-
}
2519-
25202488
// LunCloneCreate creates a LUN clone
25212489
func (c *RestClient) LunCloneCreate(
25222490
ctx context.Context, lunPath, sourcePath string, sizeInBytes int64, osType string, qosPolicyGroup QosPolicyGroup,
@@ -2563,16 +2531,7 @@ func (c *RestClient) LunCloneCreate(
25632531

25642532
params.SetInfo(lunInfo)
25652533

2566-
lunCreateCreated, lunCreateAccepted, err := c.api.San.LunCreate(params, c.authInfo)
2567-
if err != nil {
2568-
return err
2569-
}
2570-
if lunCreateCreated == nil && lunCreateAccepted == nil {
2571-
return fmt.Errorf("unexpected response from LUN create")
2572-
}
2573-
2574-
// verify the created LUN can be found
2575-
return c.pollLunCreate(ctx, lunPath)
2534+
return c.lunCreate(ctx, params, "failed to create lun clone")
25762535
}
25772536

25782537
// LunCreate creates a LUN
@@ -2620,18 +2579,31 @@ func (c *RestClient) LunCreate(
26202579

26212580
params.SetInfo(lunInfo)
26222581

2623-
lunCreateCreated, lunCreateAccepted, err := c.api.San.LunCreate(params, c.authInfo)
2582+
return c.lunCreate(ctx, params, "failed to create lun")
2583+
}
2584+
2585+
func (c *RestClient) lunCreate(ctx context.Context, params *san.LunCreateParams, customErrMsg string) error {
2586+
lunCreateOk, lunCreateAccepted, err := c.api.San.LunCreate(params, c.authInfo)
26242587
if err != nil {
26252588
return err
26262589
}
26272590

26282591
// If both response parameter is nil, then it is unexpected.
2629-
if lunCreateCreated == nil && lunCreateAccepted == nil {
2592+
if lunCreateOk == nil && lunCreateAccepted == nil {
26302593
return fmt.Errorf("unexpected response from LUN create")
26312594
}
26322595

2633-
// verify the created LUN can be found
2634-
return c.pollLunCreate(ctx, lunPath)
2596+
// Check for synchronous response and return status based on that
2597+
if lunCreateOk != nil {
2598+
if lunCreateOk.IsSuccess() {
2599+
return nil
2600+
}
2601+
return fmt.Errorf("%s: %v", customErrMsg, lunCreateOk.Error())
2602+
}
2603+
2604+
// Else, wait for job to finish
2605+
jobLink := getGenericJobLinkFromLunJobLink(lunCreateAccepted.Payload)
2606+
return c.PollJobStatus(ctx, jobLink)
26352607
}
26362608

26372609
// LunGet gets the LUN with the specified uuid

storage_drivers/ontap/api/ontap_rest_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,16 +1171,6 @@ func TestOntapREST_LunGet(t *testing.T) {
11711171
}
11721172
}
11731173

1174-
func TestOntapREST_PollLunCreate(t *testing.T) {
1175-
server := httptest.NewServer(http.HandlerFunc(mockLunResponse))
1176-
rs := newRestClient(server.Listener.Addr().String(), server.Client())
1177-
assert.NotNil(t, rs)
1178-
1179-
err := rs.pollLunCreate(ctx, "/fake-lunName")
1180-
assert.NoError(t, err, "could not poll LUN create job")
1181-
server.Close()
1182-
}
1183-
11841174
func mockInvalidResponse(w http.ResponseWriter, r *http.Request) {
11851175
setHTTPResponseHeader(w, http.StatusNotFound)
11861176
json.NewEncoder(w).Encode("invalidResponse")

0 commit comments

Comments
 (0)