Skip to content

Commit c5ba79b

Browse files
committed
add polling for image access updates
1 parent 3b550c3 commit c5ba79b

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ rpda
44
# site settings
55
.rpda.yaml
66

7+
# local development files
8+
.local

internal/pkg/rpa/main.go

+30-7
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ func (a *App) startTransfer(t Task) {
250250
}
251251

252252
func (a *App) imageAccess(t Task) {
253+
operationName := "Disabling"
253254
operation := "disable_image_access"
254255
if t.Enable == true {
256+
operationName = "Enabling"
255257
operation = "image_access/latest/enable"
256258
}
257259
endpoint := fmt.Sprintf(
@@ -271,15 +273,36 @@ func (a *App) imageAccess(t Task) {
271273
_, statusCode := a.apiRequest("PUT", endpoint, bytes.NewBuffer(json))
272274
if statusCode != 204 {
273275
log.Errorf("Expected status code '204' and received: %d\n", statusCode)
274-
log.Fatalf("Error enabling Latest Image for Group %s Copy %s\n", t.GroupName, t.CopyName)
276+
log.Fatalf("Error %s Latest Image for Group %s Copy %s\n", operationName, t.GroupName, t.CopyName)
275277
}
276278
}
277-
fmt.Printf("Enabling Latest Image for Group %s Copy %s\n", t.GroupName, t.CopyName)
279+
fmt.Printf("%s Latest Image for Group %s Copy %s\n", operationName, t.GroupName, t.CopyName)
280+
}
281+
282+
func (a *App) pollImageAccessEnabled(groupID int, stateDesired bool) {
283+
pollDelay := 3 // seconds
284+
pollCount := 0 // iteration counter
285+
pollMax := 60 // max times to poll before breaking the poll loop
286+
fmt.Println("waiting for image access to update..")
287+
groupCopiesSettings := a.getGroupCopiesSettings(groupID)
288+
copySettings := a.getRequestedCopy(groupCopiesSettings)
289+
for copySettings.ImageAccessInformation.ImageAccessEnabled != stateDesired {
290+
time.Sleep(time.Duration(pollDelay) * time.Second)
291+
groupCopiesSettings = a.getGroupCopiesSettings(groupID)
292+
copySettings = a.getRequestedCopy(groupCopiesSettings)
293+
if pollCount > pollMax {
294+
fmt.Println("Maximum poll count reached while waiting for image access")
295+
break
296+
}
297+
pollCount++
298+
}
278299
}
279300

280301
func (a *App) directAccess(t Task) {
302+
operationName := "Disabling"
281303
operation := "disable_direct_access"
282304
if t.Enable == true {
305+
operationName = "Enabling"
283306
operation = "enable_direct_access"
284307
}
285308
endpoint := fmt.Sprintf(
@@ -292,7 +315,7 @@ func (a *App) directAccess(t Task) {
292315
log.Fatalf("Error enabling Direct Access for Group %s Copy %s\n", t.GroupName, t.CopyName)
293316
}
294317
}
295-
fmt.Printf("Enabling Direct Access for Group %s Copy %s\n", t.GroupName, t.CopyName)
318+
fmt.Printf("%s Direct Access for Group %s Copy %s\n", operationName, t.GroupName, t.CopyName)
296319
}
297320

298321
// EnableAll wraper for enabling Direct Image Access for all CG
@@ -316,7 +339,7 @@ func (a *App) EnableAll() {
316339
t.Enable = true // whether to enable or disable the following tasks
317340
if !a.Config.CheckMode {
318341
a.imageAccess(t)
319-
time.Sleep(3 * time.Second) // wait a few seconds for platform
342+
a.pollImageAccessEnabled(g.ID, true)
320343
a.directAccess(t)
321344
}
322345
time.Sleep(time.Duration(a.Config.Delay) * time.Second)
@@ -347,7 +370,7 @@ func (a *App) EnableOne() {
347370
t.Enable = true // whether to enable or disable the following tasks
348371
if !a.Config.CheckMode {
349372
a.imageAccess(t)
350-
time.Sleep(3 * time.Second) // wait a few seconds for platform
373+
a.pollImageAccessEnabled(groupID, true)
351374
a.directAccess(t)
352375
}
353376
}
@@ -368,7 +391,7 @@ func (a *App) FinishAll() {
368391
t.Enable = false // whether to enable or disable the following tasks
369392
if !a.Config.CheckMode {
370393
a.imageAccess(t)
371-
time.Sleep(3 * time.Second) // wait a few seconds for platform
394+
a.pollImageAccessEnabled(g.ID, false)
372395
a.startTransfer(t)
373396
}
374397
time.Sleep(time.Duration(a.Config.Delay) * time.Second)
@@ -394,7 +417,7 @@ func (a *App) FinishOne() {
394417
t.Enable = false // whether to enable or disable the following tasks
395418
if !a.Config.CheckMode {
396419
a.imageAccess(t)
397-
time.Sleep(3 * time.Second) // wait a few seconds for platform
420+
a.pollImageAccessEnabled(groupID, false)
398421
a.startTransfer(t)
399422
}
400423
}

internal/pkg/rpa/model.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ type GroupName struct {
7878

7979
// GroupCopiesSettings is used by GroupSettingsResponse for groupCopiesSettings
8080
type GroupCopiesSettings struct {
81-
Name string `json:"name"`
82-
CopyUID CopyUID `json:"copyUID"`
83-
RoleInfo RoleInfo `json:"roleInfo"`
81+
Name string `json:"name"`
82+
CopyUID CopyUID `json:"copyUID"`
83+
RoleInfo RoleInfo `json:"roleInfo"`
84+
ImageAccessInformation ImageAccessInformation `json:"imageAccessInformation"`
8485
}
8586

8687
// CopyUID is used by GroupCopiesSettings for copyUID within groupCopiesSettings
@@ -100,6 +101,11 @@ type ClusterUID struct {
100101
ID int `json:"id"`
101102
}
102103

104+
// ImageAccessInformation holds the boolean imageAccessEnabled within groupCopiesSettings
105+
type ImageAccessInformation struct {
106+
ImageAccessEnabled bool `json:"imageAccessEnabled"`
107+
}
108+
103109
// RoleInfo holds the 'ACTIVE/REPLICA' json string roleInfo within groupCopiesSettings
104110
type RoleInfo struct {
105111
Role string `json:"role"`

0 commit comments

Comments
 (0)