Skip to content

Commit

Permalink
Update CodeRepositoryIndex and RepositoryGroup 409 error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JumiDeluxe committed Nov 15, 2024
1 parent be8cc8c commit 6fbcd65
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 154 deletions.
1 change: 0 additions & 1 deletion mmv1/products/cloudaicompanion/CodeRepositoryIndex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async:
message: message
include_project: false
custom_code:
custom_create: templates/terraform/custom_create/code_repository_index.go.tmpl
custom_update: templates/terraform/custom_update/code_repository_index.go.tmpl
parameters:
- name: location
Expand Down
121 changes: 0 additions & 121 deletions mmv1/templates/terraform/custom_create/code_repository_index.go.tmpl

This file was deleted.

12 changes: 10 additions & 2 deletions mmv1/templates/terraform/custom_create/repository_group.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ for {
})
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 409) {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before creating RepositoryGroup: %#v", obj)
time.Sleep(3 * time.Minute)
errMsg := fmt.Sprintf("%s", errMsg)
if strings.Contains(errMsg, "unable to queue the operation") {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before creating RepositoryGroup: %#v", obj)
time.Sleep(10 * time.Second)
} else if strings.Contains(errMsg, "parent resource not in ready state") {
log.Printf("[DEBUG] Waiting for parent resource to become active before creating RepositoryGroup: %#v", obj)
time.Sleep(1 * time.Minute)
} else {
return fmt.Errorf("Error creating RepositoryGroup %q: %s", d.Id(), err)
}
} else {
return fmt.Errorf("Error creating RepositoryGroup: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ for {
})
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 409) {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before updating CodeRepositoryIndex: %#v", obj)
time.Sleep(3 * time.Minute)
errMsg := fmt.Sprintf("%s", errMsg)
if strings.Contains(errMsg, "parent resource not in ready state") {
log.Printf("[DEBUG] Waiting for parent resource to become active before updating CodeRepositoryIndex: %#v", obj)
time.Sleep(1 * time.Minute)
} else {
return fmt.Errorf("Error updating CodeRepositoryIndex %q: %s", d.Id(), err)
}
} else {
return fmt.Errorf("Error updating CodeRepositoryIndex: %s", err)
return fmt.Errorf("Error updating CodeRepositoryIndex %q: %s", d.Id(), err)
}
} else {
break
Expand Down
14 changes: 11 additions & 3 deletions mmv1/templates/terraform/custom_update/repository_group.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ for {
})
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 409) {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before updating RepositoryGroup %q: %#v", d.Id(), obj)
time.Sleep(3 * time.Minute)
errMsg := fmt.Sprintf("%s", errMsg)
if strings.Contains(errMsg, "unable to queue the operation") {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before updating RepositoryGroup: %#v", obj)
time.Sleep(10 * time.Second)
} else if strings.Contains(errMsg, "parent resource not in ready state") {
log.Printf("[DEBUG] Waiting for parent resource to become active before updating RepositoryGroup: %#v", obj)
time.Sleep(1 * time.Minute)
} else {
return fmt.Errorf("Error updating RepositoryGroup %q: %s", d.Id(), err)
}
} else {
return fmt.Errorf("Error updating RepositoryGroup: %s", err)
return fmt.Errorf("Error updating RepositoryGroup %q: %s", d.Id(), err)
}
} else {
break
Expand Down
47 changes: 23 additions & 24 deletions mmv1/third_party/terraform/acctest/bootstrap_test_utils.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1626,10 +1626,18 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
})
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 409) {
log.Printf("[DEBUG] Waiting for enqueued operation to finish")
time.Sleep(3 * time.Minute)
errMsg := fmt.Sprintf("%s", errMsg)
if strings.Contains(errMsg, "unable to queue the operation") {
log.Printf("[DEBUG] Waiting for enqueued operation to finish before creating RepositoryGroup: %#v", obj)
time.Sleep(10 * time.Second)
} else if strings.Contains(errMsg, "parent resource not in ready state") {
log.Printf("[DEBUG] Waiting for parent resource to become active before creating RepositoryGroup: %#v", obj)
time.Sleep(1 * time.Minute)
} else {
return t.Fatalf("Error creating RepositoryGroup: %s", err)
}
} else {
t.Fatalf("Error creating code repository index %q: %s", codeRepositoryIndexId, err)
t.Fatalf("Error creating repository group %q: %s", repositoryGroupId, err)
}
} else {
break
Expand Down Expand Up @@ -1700,27 +1708,18 @@ func SetupProjectsAndGetAccessToken(org, billing, pid, service string, config *t
}

headers := make(http.Header)
for {
_, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "POST",
Project: config.Project,
RawURL: postURL,
UserAgent: config.UserAgent,
Body: obj,
Timeout: 90 * time.Minute,
Headers: headers,
})
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 409) {
log.Printf("[DEBUG] Waiting for enqueued operation to finish")
time.Sleep(3 * time.Minute)
} else {
t.Fatalf("Error creating code repository index %q: %s", codeRepositoryIndexId, err)
}
} else {
break
}
_, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "POST",
Project: config.Project,
RawURL: postURL,
UserAgent: config.UserAgent,
Body: obj,
Timeout: 90 * time.Minute,
Headers: headers,
})
if err != nil {
t.Fatalf("Error creating code repository index %q: %s", codeRepositoryIndexId, err)
}

_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Expand Down

0 comments on commit 6fbcd65

Please sign in to comment.