Skip to content

Commit 0f37cd6

Browse files
committed
improved stdout/logging readability
1 parent 2a9d397 commit 0f37cd6

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

internal/pkg/rpa/main.go

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,19 @@ func (a *App) startTransfer(t Task) error {
214214
body, statusCode := a.apiRequest("PUT", endpoint, nil)
215215
if statusCode != 204 {
216216
log.Debugf("Expected status code '204' and received: %d\n", statusCode)
217-
log.Warnf("Error Starting Transfer for Group %s Copy %s\n", t.GroupName, t.CopyName)
217+
log.Warnf("%s - Error Starting Transfer for Copy %s\n", t.GroupName, t.CopyName)
218218
return errors.New(string(body))
219219
}
220220
}
221-
fmt.Printf("Starting Transfer for Group %s Copy %s\n", t.GroupName, t.CopyName)
221+
fmt.Printf("%s - Starting Transfer for Copy %s\n", t.GroupName, t.CopyName)
222222
return nil
223223
}
224224

225225
func (a *App) imageAccess(t Task) error {
226-
operationName := "Disabling"
226+
operationName := "Disabled"
227227
operation := "disable_image_access"
228228
if t.Enable == true {
229-
operationName = "Enabling"
229+
operationName = "Enabled"
230230
operation = "image_access/latest/enable"
231231
}
232232
endpoint := fmt.Sprintf(
@@ -249,41 +249,40 @@ func (a *App) imageAccess(t Task) error {
249249
return errors.New(string(body))
250250
}
251251
}
252-
fmt.Printf("%s Latest Image for Group %s Copy %s\n", operationName, t.GroupName, t.CopyName)
252+
fmt.Printf("%s - %s Latest Image for Group Copy %s\n", t.GroupName, operationName, t.CopyName)
253253
return nil
254254
}
255255

256-
func (a *App) pollImageAccessEnabled(groupID int, stateDesired bool) {
256+
func (a *App) pollImageAccessEnabled(groupID int, groupName string, stateDesired bool) {
257257
pollDelay := a.Config.PollDelay // seconds
258258
pollMax := a.Config.PollMax // max times to poll before breaking the poll loop
259259
pollCount := 0 // iteration counter
260260

261-
fmt.Println("waiting for image access to update..")
261+
fmt.Printf("%s - Waiting for image access to update..\n", groupName)
262262
groupCopiesSettings := a.getGroupCopiesSettings(groupID)
263263
copySettings := a.getRequestedCopy(groupCopiesSettings)
264264
for copySettings.ImageAccessInformation.ImageAccessEnabled != stateDesired {
265265
log.Debug("polling - image access enabled: ", copySettings.ImageAccessInformation.ImageAccessEnabled)
266-
log.Debug("polling - image logged access mode: ", copySettings.ImageAccessInformation.ImageInformation.Mode)
267266
time.Sleep(time.Duration(pollDelay) * time.Second)
268267
groupCopiesSettings = a.getGroupCopiesSettings(groupID)
269268
copySettings = a.getRequestedCopy(groupCopiesSettings)
270269
if pollCount > pollMax {
271-
fmt.Println("Maximum poll count reached while waiting for image access")
270+
fmt.Println("Maximum poll count reached while waiting for image access. Consider increasing 'pollmax' in configuration")
272271
break
273272
}
274273
pollCount++
275274
}
275+
pollCount = 0 // reset counter before polling for logged access
276276
if stateDesired == true {
277277
// if the desired state is to have image access == true, we should ensure that logged access is also
278278
// set before continuing. This seems to take a few seconds longer.. so we will continue polling for mode.
279279
for copySettings.ImageAccessInformation.ImageInformation.Mode != "LOGGED_ACCESS" {
280-
log.Debug("polling image access enabled: ", copySettings.ImageAccessInformation.ImageAccessEnabled)
281280
log.Debug("polling image logged access mode: ", copySettings.ImageAccessInformation.ImageInformation.Mode)
282281
time.Sleep(time.Duration(pollDelay) * time.Second)
283282
groupCopiesSettings = a.getGroupCopiesSettings(groupID)
284283
copySettings = a.getRequestedCopy(groupCopiesSettings)
285284
if pollCount > pollMax {
286-
fmt.Println("Maximum poll count reached while waiting for logged access")
285+
fmt.Println("Maximum poll count reached while waiting for logged access. Consider increasing 'pollmax' in configuration")
287286
break
288287
}
289288
pollCount++
@@ -298,10 +297,10 @@ func (a *App) directAccess(t Task) error {
298297
pollMax := a.Config.PollMax // max times to poll before breaking the poll loop
299298
pollCount := 0 // iteration counter
300299

301-
operationName := "Disabling"
300+
operationName := "Disabl" // suffix is appended based on message
302301
operation := "disable_direct_access"
303302
if t.Enable == true {
304-
operationName = "Enabling"
303+
operationName = "Enabl" // suffix is appended based on message
305304
operation = "enable_direct_access"
306305
}
307306
endpoint := fmt.Sprintf(
@@ -314,14 +313,14 @@ func (a *App) directAccess(t Task) error {
314313
time.Sleep(time.Duration(pollDelay) * time.Second)
315314
body, statusCode = a.apiRequest("PUT", endpoint, nil)
316315
if pollCount > pollMax {
317-
fmt.Println("Maximum poll count reached while waiting for direct access")
318-
log.Warnf("Error %s Direct Access for Group %s Copy %s\n", operationName, t.GroupName, t.CopyName)
316+
log.Warnf("%s - Maximum poll count reached while waiting for direct access\n", t.GroupName)
317+
log.Warnf("%s - Error %sing Direct Access for Copy %s\n", t.GroupName, operationName, t.CopyName)
319318
return errors.New(string(body))
320319
}
321320
pollCount++
322321
}
323322
}
324-
fmt.Printf("%s Direct Access for Group %s Copy %s\n", operationName, t.GroupName, t.CopyName)
323+
fmt.Printf("%s - %sed Direct Access for Copy %s\n", t.GroupName, operationName, t.CopyName)
325324
return nil
326325
}
327326

@@ -331,15 +330,15 @@ func (a *App) EnableAll() {
331330
groups := a.getAllGroups()
332331
for _, g := range groups {
333332
var t Task
334-
GroupName := a.getGroupName(g.ID)
333+
groupName := a.getGroupName(g.ID)
335334
groupCopiesSettings := a.getGroupCopiesSettings(g.ID)
336335
copySettings := a.getRequestedCopy(groupCopiesSettings)
337336
// skip if copy is already 'enabled'
338337
if copySettings.RoleInfo.Role == "ACTIVE" {
339-
fmt.Printf("Image Access already enabled for %s -> %s\n", a.Group, copySettings.Name)
338+
fmt.Printf("%s - Image Access already enabled for copy: %s\n", a.Group, copySettings.Name)
340339
continue
341340
}
342-
t.GroupName = GroupName
341+
t.GroupName = groupName
343342
t.GroupUID = copySettings.CopyUID.GroupUID.ID
344343
t.ClusterUID = copySettings.CopyUID.GlobalCopyUID.ClusterUID.ID
345344
t.CopyName = copySettings.Name
@@ -348,13 +347,13 @@ func (a *App) EnableAll() {
348347
if !a.Config.CheckMode {
349348
err := a.imageAccess(t)
350349
if err != nil {
351-
log.Warnf("%s %s\n", GroupName, err)
350+
log.Warnf("%s - %s\n", groupName, err)
352351
continue
353352
}
354-
a.pollImageAccessEnabled(g.ID, true)
353+
a.pollImageAccessEnabled(g.ID, groupName, true)
355354
err = a.directAccess(t)
356355
if err != nil {
357-
log.Warnf("%s %s\n", GroupName, err)
356+
log.Warnf("%s - %s\n", groupName, err)
358357
continue
359358
}
360359
}
@@ -373,7 +372,7 @@ func (a *App) EnableOne() {
373372
copySettings := a.getRequestedCopy(groupCopiesSettings)
374373
// skip if copy is already 'enabled'
375374
if copySettings.RoleInfo.Role == "ACTIVE" {
376-
fmt.Printf("Image Access already enabled for %s -> %s\n", a.Group, copySettings.Name)
375+
fmt.Printf("%s - Image Access already enabled for copy: %s\n", a.Group, copySettings.Name)
377376
return
378377
}
379378
t.GroupName = a.Group
@@ -385,13 +384,13 @@ func (a *App) EnableOne() {
385384
if !a.Config.CheckMode {
386385
err := a.imageAccess(t)
387386
if err != nil {
388-
log.Warnf("%s %s\n", a.Group, err)
387+
log.Warnf("%s - %s\n", a.Group, err)
389388
return
390389
}
391-
a.pollImageAccessEnabled(groupID, true)
390+
a.pollImageAccessEnabled(groupID, a.Group, true)
392391
err = a.directAccess(t)
393392
if err != nil {
394-
log.Warnf("%s %s\n", a.Group, err)
393+
log.Warnf("%s - %s\n", a.Group, err)
395394
}
396395
}
397396
elapsed := time.Since(start)
@@ -404,10 +403,10 @@ func (a *App) FinishAll() {
404403
groups := a.getAllGroups()
405404
for _, g := range groups {
406405
var t Task
407-
GroupName := a.getGroupName(g.ID)
406+
groupName := a.getGroupName(g.ID)
408407
groupCopiesSettings := a.getGroupCopiesSettings(g.ID)
409408
copySettings := a.getRequestedCopy(groupCopiesSettings)
410-
t.GroupName = GroupName
409+
t.GroupName = groupName
411410
t.GroupUID = copySettings.CopyUID.GroupUID.ID
412411
t.ClusterUID = copySettings.CopyUID.GlobalCopyUID.ClusterUID.ID
413412
t.CopyName = copySettings.Name
@@ -416,15 +415,15 @@ func (a *App) FinishAll() {
416415
if !a.Config.CheckMode {
417416
err := a.imageAccess(t)
418417
if err != nil {
419-
log.Warnf("%s %s\n", GroupName, err)
418+
log.Warnf("%s - %s\n", groupName, err)
420419
// continue as we cannot start transfer when image access does
421420
// not update as expected.
422421
continue
423422
}
424-
a.pollImageAccessEnabled(g.ID, false)
423+
a.pollImageAccessEnabled(g.ID, groupName, false)
425424
err = a.startTransfer(t)
426425
if err != nil {
427-
log.Warnf("%s %s\n", GroupName, err)
426+
log.Warnf("%s - %s\n", groupName, err)
428427
}
429428
}
430429
time.Sleep(time.Duration(a.Config.Delay) * time.Second)
@@ -449,13 +448,13 @@ func (a *App) FinishOne() {
449448
if !a.Config.CheckMode {
450449
err := a.imageAccess(t)
451450
if err != nil {
452-
log.Warnf("%s %s\n", a.Group, err)
451+
log.Warnf("%s - %s\n", a.Group, err)
453452
return
454453
}
455-
a.pollImageAccessEnabled(groupID, false)
454+
a.pollImageAccessEnabled(groupID, a.Group, false)
456455
err = a.startTransfer(t)
457456
if err != nil {
458-
log.Warnf("%s %s\n", a.Group, err)
457+
log.Warnf("%s - %s\n", a.Group, err)
459458
}
460459
}
461460
elapsed := time.Since(start)

0 commit comments

Comments
 (0)