check for done operations before waiting on them (#1632)

This commit is contained in:
Dana Hoffman 2018-06-08 16:04:55 -07:00 committed by GitHub
parent e5e7f05f7c
commit d00e55f11b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 91 additions and 2 deletions

View File

@ -59,6 +59,13 @@ func appEngineOperationWait(client *appengine.APIService, op *appengine.Operatio
} }
func appEngineOperationWaitTime(client *appengine.APIService, op *appengine.Operation, appId, activity string, timeoutMin int) error { func appEngineOperationWaitTime(client *appengine.APIService, op *appengine.Operation, appId, activity string, timeoutMin int) error {
if op.Done {
if op.Error != nil {
return AppEngineOperationError(*op.Error)
}
return nil
}
w := &AppEngineOperationWaiter{ w := &AppEngineOperationWaiter{
Service: client, Service: client,
Op: op, Op: op,

View File

@ -47,6 +47,13 @@ func cloudFunctionsOperationWait(client *cloudfunctions.Service,
func cloudFunctionsOperationWaitTime(client *cloudfunctions.Service, op *cloudfunctions.Operation, func cloudFunctionsOperationWaitTime(client *cloudfunctions.Service, op *cloudfunctions.Operation,
activity string, timeoutMin int) error { activity string, timeoutMin int) error {
if op.Done {
if op.Error != nil {
return fmt.Errorf(op.Error.Message)
}
return nil
}
w := &CloudFunctionsOperationWaiter{ w := &CloudFunctionsOperationWaiter{
Service: client, Service: client,
Op: op, Op: op,

View File

@ -67,6 +67,13 @@ func computeOperationWait(client *compute.Service, op *compute.Operation, projec
} }
func computeOperationWaitTime(client *compute.Service, op *compute.Operation, project, activity string, timeoutMin int) error { func computeOperationWaitTime(client *compute.Service, op *compute.Operation, project, activity string, timeoutMin int) error {
if op.Status == "DONE" {
if op.Error != nil {
return ComputeOperationError(*op.Error)
}
return nil
}
w := &ComputeOperationWaiter{ w := &ComputeOperationWaiter{
Service: client, Service: client,
Op: op, Op: op,

View File

@ -80,6 +80,13 @@ func (w *ContainerBetaOperationWaiter) RefreshFunc() resource.StateRefreshFunc {
} }
func containerOperationWait(config *Config, op *container.Operation, project, zone, activity string, timeoutMinutes, minTimeoutSeconds int) error { func containerOperationWait(config *Config, op *container.Operation, project, zone, activity string, timeoutMinutes, minTimeoutSeconds int) error {
if op.Status == "DONE" {
if op.StatusMessage != "" {
return fmt.Errorf(op.StatusMessage)
}
return nil
}
w := &ContainerOperationWaiter{ w := &ContainerOperationWaiter{
Service: config.clientContainer, Service: config.clientContainer,
Op: op, Op: op,
@ -92,6 +99,13 @@ func containerOperationWait(config *Config, op *container.Operation, project, zo
} }
func containerBetaOperationWait(config *Config, op *containerBeta.Operation, project, location, activity string, timeoutMinutes, minTimeoutSeconds int) error { func containerBetaOperationWait(config *Config, op *containerBeta.Operation, project, location, activity string, timeoutMinutes, minTimeoutSeconds int) error {
if op.Status == "DONE" {
if op.StatusMessage != "" {
return fmt.Errorf(op.StatusMessage)
}
return nil
}
w := &ContainerBetaOperationWaiter{ w := &ContainerBetaOperationWaiter{
Service: config.clientContainerBeta, Service: config.clientContainerBeta,
Op: op, Op: op,

View File

@ -37,6 +37,13 @@ func (w *DataprocClusterOperationWaiter) RefreshFunc() resource.StateRefreshFunc
} }
func dataprocClusterOperationWait(config *Config, op *dataproc.Operation, activity string, timeoutMinutes, minTimeoutSeconds int) error { func dataprocClusterOperationWait(config *Config, op *dataproc.Operation, activity string, timeoutMinutes, minTimeoutSeconds int) error {
if op.Done {
if op.Error != nil {
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
}
return nil
}
w := &DataprocClusterOperationWaiter{ w := &DataprocClusterOperationWaiter{
Service: config.clientDataproc, Service: config.clientDataproc,
Op: op, Op: op,

View File

@ -2,10 +2,11 @@ package google
import ( import (
"fmt" "fmt"
"github.com/hashicorp/terraform/helper/resource"
"google.golang.org/api/dns/v1beta2"
"log" "log"
"time" "time"
"github.com/hashicorp/terraform/helper/resource"
"google.golang.org/api/dns/v1beta2"
) )
type DnsOperationWaiter struct { type DnsOperationWaiter struct {
@ -48,6 +49,10 @@ func dnsOperationWait(service *dns.Service, op *dns.Operation, project, activity
} }
func dnsOperationWaitTime(service *dns.Service, op *dns.Operation, project, activity string, timeoutMin int) error { func dnsOperationWaitTime(service *dns.Service, op *dns.Operation, project, activity string, timeoutMin int) error {
if op.Status == "done" {
return nil
}
w := &DnsOperationWaiter{ w := &DnsOperationWaiter{
Service: service.ManagedZoneOperations, Service: service.ManagedZoneOperations,
Op: op, Op: op,

View File

@ -42,6 +42,13 @@ func resourceManagerOperationWait(service *cloudresourcemanager.Service, op *clo
} }
func resourceManagerOperationWaitTime(service *cloudresourcemanager.Service, op *cloudresourcemanager.Operation, activity string, timeoutMin int) error { func resourceManagerOperationWaitTime(service *cloudresourcemanager.Service, op *cloudresourcemanager.Operation, activity string, timeoutMin int) error {
if op.Done {
if op.Error != nil {
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
}
return nil
}
w := &ResourceManagerOperationWaiter{ w := &ResourceManagerOperationWaiter{
Service: service, Service: service,
Op: op, Op: op,

View File

@ -45,6 +45,13 @@ func serviceManagementOperationWait(config *Config, op *servicemanagement.Operat
} }
func serviceManagementOperationWaitTime(config *Config, op *servicemanagement.Operation, activity string, timeoutMin int) (googleapi.RawMessage, error) { func serviceManagementOperationWaitTime(config *Config, op *servicemanagement.Operation, activity string, timeoutMin int) (googleapi.RawMessage, error) {
if op.Done {
if op.Error != nil {
return nil, fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
}
return op.Response, nil
}
w := &ServiceManagementOperationWaiter{ w := &ServiceManagementOperationWaiter{
Service: config.clientServiceMan, Service: config.clientServiceMan,
Op: op, Op: op,

View File

@ -45,6 +45,13 @@ func serviceUsageOperationWait(config *Config, op *serviceusage.Operation, activ
} }
func serviceUsageOperationWaitTime(config *Config, op *serviceusage.Operation, activity string, timeoutMin int) (googleapi.RawMessage, error) { func serviceUsageOperationWaitTime(config *Config, op *serviceusage.Operation, activity string, timeoutMin int) (googleapi.RawMessage, error) {
if op.Done {
if op.Error != nil {
return nil, fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
}
return op.Response, nil
}
w := &serviceUsageOperationWaiter{ w := &serviceUsageOperationWaiter{
Service: config.clientServiceUsage, Service: config.clientServiceUsage,
Op: op, Op: op,

View File

@ -38,6 +38,13 @@ func (w *SpannerDatabaseOperationWaiter) RefreshFunc() resource.StateRefreshFunc
} }
func spannerDatabaseOperationWait(config *Config, op *spanner.Operation, activity string, timeoutMin int) error { func spannerDatabaseOperationWait(config *Config, op *spanner.Operation, activity string, timeoutMin int) error {
if op.Done {
if op.Error != nil {
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
}
return nil
}
w := &SpannerDatabaseOperationWaiter{ w := &SpannerDatabaseOperationWaiter{
Service: config.clientSpanner, Service: config.clientSpanner,
Op: op, Op: op,

View File

@ -38,6 +38,13 @@ func (w *SpannerInstanceOperationWaiter) RefreshFunc() resource.StateRefreshFunc
} }
func spannerInstanceOperationWait(config *Config, op *spanner.Operation, activity string, timeoutMin int) error { func spannerInstanceOperationWait(config *Config, op *spanner.Operation, activity string, timeoutMin int) error {
if op.Done {
if op.Error != nil {
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
}
return nil
}
w := &SpannerInstanceOperationWaiter{ w := &SpannerInstanceOperationWaiter{
Service: config.clientSpanner, Service: config.clientSpanner,
Op: op, Op: op,

View File

@ -61,6 +61,13 @@ func sqladminOperationWait(config *Config, op *sqladmin.Operation, project, acti
} }
func sqladminOperationWaitTime(config *Config, op *sqladmin.Operation, project, activity string, timeoutMinutes int) error { func sqladminOperationWaitTime(config *Config, op *sqladmin.Operation, project, activity string, timeoutMinutes int) error {
if op.Status == "DONE" {
if op.Error != nil {
return SqlAdminOperationError(*op.Error)
}
return nil
}
w := &SqlAdminOperationWaiter{ w := &SqlAdminOperationWaiter{
Service: config.clientSqlAdmin, Service: config.clientSqlAdmin,
Op: op, Op: op,