Skip to content

Commit 8650b33

Browse files
committed
log warn/error msg instead of fatal/exit
1 parent 715399e commit 8650b33

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

internal/pkg/rpa/main.go

+31-12
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,20 @@ func (a *App) getRequestedCopy(gcs []GroupCopiesSettings) GroupCopiesSettings {
207207
return c
208208
}
209209

210-
func (a *App) startTransfer(t Task) {
210+
func (a *App) startTransfer(t Task) error {
211211
endpoint := fmt.Sprintf(
212212
a.Config.RPAURL+"/fapi/rest/5_1/groups/%d/clusters/%d/copies/%d/start_transfer",
213213
t.GroupUID, t.ClusterUID, t.CopyUID)
214214
if !a.Config.CheckMode {
215-
_, statusCode := a.apiRequest("PUT", endpoint, nil)
215+
body, statusCode := a.apiRequest("PUT", endpoint, nil)
216216
if statusCode != 204 {
217-
log.Errorf("Expected status code '204' and received: %d\n", statusCode)
218-
log.Fatalf("Error Starting Transfer for Group %s Copy %s\n", t.GroupName, t.CopyName)
217+
log.Debugf("Expected status code '204' and received: %d\n", statusCode)
218+
log.Warnf("Error Starting Transfer for Group %s Copy %s\n", t.GroupName, t.CopyName)
219+
return errors.New(string(body))
219220
}
220221
}
221222
fmt.Printf("Starting Transfer for Group %s Copy %s\n", t.GroupName, t.CopyName)
223+
return nil
222224
}
223225

224226
func (a *App) imageAccess(t Task) error {
@@ -271,7 +273,7 @@ func (a *App) pollImageAccessEnabled(groupID int, stateDesired bool) {
271273
}
272274
}
273275

274-
func (a *App) directAccess(t Task) {
276+
func (a *App) directAccess(t Task) error {
275277
operationName := "Disabling"
276278
operation := "disable_direct_access"
277279
if t.Enable == true {
@@ -282,13 +284,15 @@ func (a *App) directAccess(t Task) {
282284
a.Config.RPAURL+"/fapi/rest/5_1/groups/%d/clusters/%d/copies/%d/%s",
283285
t.GroupUID, t.ClusterUID, t.CopyUID, operation)
284286
if !a.Config.CheckMode {
285-
_, statusCode := a.apiRequest("PUT", endpoint, nil)
287+
body, statusCode := a.apiRequest("PUT", endpoint, nil)
286288
if statusCode != 204 {
287-
log.Errorf("Expected status code '204' and received: %d\n", statusCode)
288-
log.Fatalf("Error enabling Direct Access for Group %s Copy %s\n", t.GroupName, t.CopyName)
289+
log.Debugf("Expected status code '204' and received: %d\n", statusCode)
290+
log.Warnf("Error enabling Direct Access for Group %s Copy %s\n", t.GroupName, t.CopyName)
291+
return errors.New(string(body))
289292
}
290293
}
291294
fmt.Printf("%s Direct Access for Group %s Copy %s\n", operationName, t.GroupName, t.CopyName)
295+
return nil
292296
}
293297

294298
// EnableAll wraper for enabling Direct Image Access for all CG
@@ -317,7 +321,11 @@ func (a *App) EnableAll() {
317321
continue
318322
}
319323
a.pollImageAccessEnabled(g.ID, true)
320-
a.directAccess(t)
324+
err = a.directAccess(t)
325+
if err != nil {
326+
log.Warnf("%s %s\n", GroupName, err)
327+
continue
328+
}
321329
}
322330
time.Sleep(time.Duration(a.Config.Delay) * time.Second)
323331
}
@@ -347,7 +355,10 @@ func (a *App) EnableOne() {
347355
return
348356
}
349357
a.pollImageAccessEnabled(groupID, true)
350-
a.directAccess(t)
358+
err = a.directAccess(t)
359+
if err != nil {
360+
log.Warnf("%s %s\n", a.Group, err)
361+
}
351362
}
352363
}
353364

@@ -369,10 +380,15 @@ func (a *App) FinishAll() {
369380
err := a.imageAccess(t)
370381
if err != nil {
371382
log.Warnf("%s %s\n", GroupName, err)
383+
// continue as we cannot start transfer when image access does
384+
// not update as expected.
372385
continue
373386
}
374387
a.pollImageAccessEnabled(g.ID, false)
375-
a.startTransfer(t)
388+
err = a.startTransfer(t)
389+
if err != nil {
390+
log.Warnf("%s %s\n", GroupName, err)
391+
}
376392
}
377393
time.Sleep(time.Duration(a.Config.Delay) * time.Second)
378394
}
@@ -397,6 +413,9 @@ func (a *App) FinishOne() {
397413
return
398414
}
399415
a.pollImageAccessEnabled(groupID, false)
400-
a.startTransfer(t)
416+
err = a.startTransfer(t)
417+
if err != nil {
418+
log.Warnf("%s %s\n", a.Group, err)
419+
}
401420
}
402421
}

0 commit comments

Comments
 (0)