api_op_GetChange.go raw

   1  // Code generated by smithy-go-codegen DO NOT EDIT.
   2  
   3  package route53
   4  
   5  import (
   6  	"context"
   7  	"fmt"
   8  	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
   9  	"github.com/aws/aws-sdk-go-v2/service/route53/types"
  10  	"github.com/aws/smithy-go/middleware"
  11  	smithytime "github.com/aws/smithy-go/time"
  12  	smithyhttp "github.com/aws/smithy-go/transport/http"
  13  	smithywaiter "github.com/aws/smithy-go/waiter"
  14  	"time"
  15  )
  16  
  17  // Returns the current status of a change batch request. The status is one of the
  18  // following values:
  19  //
  20  //   - PENDING indicates that the changes in this request have not propagated to
  21  //     all Amazon Route 53 DNS servers managing the hosted zone. This is the initial
  22  //     status of all change batch requests.
  23  //
  24  //   - INSYNC indicates that the changes have propagated to all Route 53 DNS
  25  //     servers managing the hosted zone.
  26  func (c *Client) GetChange(ctx context.Context, params *GetChangeInput, optFns ...func(*Options)) (*GetChangeOutput, error) {
  27  	if params == nil {
  28  		params = &GetChangeInput{}
  29  	}
  30  
  31  	result, metadata, err := c.invokeOperation(ctx, "GetChange", params, optFns, c.addOperationGetChangeMiddlewares)
  32  	if err != nil {
  33  		return nil, err
  34  	}
  35  
  36  	out := result.(*GetChangeOutput)
  37  	out.ResultMetadata = metadata
  38  	return out, nil
  39  }
  40  
  41  // The input for a GetChange request.
  42  type GetChangeInput struct {
  43  
  44  	// The ID of the change batch request. The value that you specify here is the
  45  	// value that ChangeResourceRecordSets returned in the Id element when you
  46  	// submitted the request.
  47  	//
  48  	// This member is required.
  49  	Id *string
  50  
  51  	noSmithyDocumentSerde
  52  }
  53  
  54  // A complex type that contains the ChangeInfo element.
  55  type GetChangeOutput struct {
  56  
  57  	// A complex type that contains information about the specified change batch.
  58  	//
  59  	// This member is required.
  60  	ChangeInfo *types.ChangeInfo
  61  
  62  	// Metadata pertaining to the operation's result.
  63  	ResultMetadata middleware.Metadata
  64  
  65  	noSmithyDocumentSerde
  66  }
  67  
  68  func (c *Client) addOperationGetChangeMiddlewares(stack *middleware.Stack, options Options) (err error) {
  69  	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
  70  		return err
  71  	}
  72  	err = stack.Serialize.Add(&awsRestxml_serializeOpGetChange{}, middleware.After)
  73  	if err != nil {
  74  		return err
  75  	}
  76  	err = stack.Deserialize.Add(&awsRestxml_deserializeOpGetChange{}, middleware.After)
  77  	if err != nil {
  78  		return err
  79  	}
  80  	if err := addProtocolFinalizerMiddlewares(stack, options, "GetChange"); err != nil {
  81  		return fmt.Errorf("add protocol finalizers: %v", err)
  82  	}
  83  
  84  	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
  85  		return err
  86  	}
  87  	if err = addSetLoggerMiddleware(stack, options); err != nil {
  88  		return err
  89  	}
  90  	if err = addClientRequestID(stack); err != nil {
  91  		return err
  92  	}
  93  	if err = addComputeContentLength(stack); err != nil {
  94  		return err
  95  	}
  96  	if err = addResolveEndpointMiddleware(stack, options); err != nil {
  97  		return err
  98  	}
  99  	if err = addComputePayloadSHA256(stack); err != nil {
 100  		return err
 101  	}
 102  	if err = addRetry(stack, options); err != nil {
 103  		return err
 104  	}
 105  	if err = addRawResponseToMetadata(stack); err != nil {
 106  		return err
 107  	}
 108  	if err = addRecordResponseTiming(stack); err != nil {
 109  		return err
 110  	}
 111  	if err = addSpanRetryLoop(stack, options); err != nil {
 112  		return err
 113  	}
 114  	if err = addClientUserAgent(stack, options); err != nil {
 115  		return err
 116  	}
 117  	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
 118  		return err
 119  	}
 120  	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
 121  		return err
 122  	}
 123  	if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
 124  		return err
 125  	}
 126  	if err = addTimeOffsetBuild(stack, c); err != nil {
 127  		return err
 128  	}
 129  	if err = addUserAgentRetryMode(stack, options); err != nil {
 130  		return err
 131  	}
 132  	if err = addCredentialSource(stack, options); err != nil {
 133  		return err
 134  	}
 135  	if err = addOpGetChangeValidationMiddleware(stack); err != nil {
 136  		return err
 137  	}
 138  	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetChange(options.Region), middleware.Before); err != nil {
 139  		return err
 140  	}
 141  	if err = addRecursionDetection(stack); err != nil {
 142  		return err
 143  	}
 144  	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
 145  		return err
 146  	}
 147  	if err = addResponseErrorMiddleware(stack); err != nil {
 148  		return err
 149  	}
 150  	if err = addSanitizeURLMiddleware(stack); err != nil {
 151  		return err
 152  	}
 153  	if err = addRequestResponseLogging(stack, options); err != nil {
 154  		return err
 155  	}
 156  	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
 157  		return err
 158  	}
 159  	if err = addInterceptBeforeRetryLoop(stack, options); err != nil {
 160  		return err
 161  	}
 162  	if err = addInterceptAttempt(stack, options); err != nil {
 163  		return err
 164  	}
 165  	if err = addInterceptors(stack, options); err != nil {
 166  		return err
 167  	}
 168  	return nil
 169  }
 170  
 171  // ResourceRecordSetsChangedWaiterOptions are waiter options for
 172  // ResourceRecordSetsChangedWaiter
 173  type ResourceRecordSetsChangedWaiterOptions struct {
 174  
 175  	// Set of options to modify how an operation is invoked. These apply to all
 176  	// operations invoked for this client. Use functional options on operation call to
 177  	// modify this list for per operation behavior.
 178  	//
 179  	// Passing options here is functionally equivalent to passing values to this
 180  	// config's ClientOptions field that extend the inner client's APIOptions directly.
 181  	APIOptions []func(*middleware.Stack) error
 182  
 183  	// Functional options to be passed to all operations invoked by this client.
 184  	//
 185  	// Function values that modify the inner APIOptions are applied after the waiter
 186  	// config's own APIOptions modifiers.
 187  	ClientOptions []func(*Options)
 188  
 189  	// MinDelay is the minimum amount of time to delay between retries. If unset,
 190  	// ResourceRecordSetsChangedWaiter will use default minimum delay of 30 seconds.
 191  	// Note that MinDelay must resolve to a value lesser than or equal to the MaxDelay.
 192  	MinDelay time.Duration
 193  
 194  	// MaxDelay is the maximum amount of time to delay between retries. If unset or
 195  	// set to zero, ResourceRecordSetsChangedWaiter will use default max delay of 120
 196  	// seconds. Note that MaxDelay must resolve to value greater than or equal to the
 197  	// MinDelay.
 198  	MaxDelay time.Duration
 199  
 200  	// LogWaitAttempts is used to enable logging for waiter retry attempts
 201  	LogWaitAttempts bool
 202  
 203  	// Retryable is function that can be used to override the service defined
 204  	// waiter-behavior based on operation output, or returned error. This function is
 205  	// used by the waiter to decide if a state is retryable or a terminal state.
 206  	//
 207  	// By default service-modeled logic will populate this option. This option can
 208  	// thus be used to define a custom waiter state with fall-back to service-modeled
 209  	// waiter state mutators.The function returns an error in case of a failure state.
 210  	// In case of retry state, this function returns a bool value of true and nil
 211  	// error, while in case of success it returns a bool value of false and nil error.
 212  	Retryable func(context.Context, *GetChangeInput, *GetChangeOutput, error) (bool, error)
 213  }
 214  
 215  // ResourceRecordSetsChangedWaiter defines the waiters for
 216  // ResourceRecordSetsChanged
 217  type ResourceRecordSetsChangedWaiter struct {
 218  	client GetChangeAPIClient
 219  
 220  	options ResourceRecordSetsChangedWaiterOptions
 221  }
 222  
 223  // NewResourceRecordSetsChangedWaiter constructs a ResourceRecordSetsChangedWaiter.
 224  func NewResourceRecordSetsChangedWaiter(client GetChangeAPIClient, optFns ...func(*ResourceRecordSetsChangedWaiterOptions)) *ResourceRecordSetsChangedWaiter {
 225  	options := ResourceRecordSetsChangedWaiterOptions{}
 226  	options.MinDelay = 30 * time.Second
 227  	options.MaxDelay = 120 * time.Second
 228  	options.Retryable = resourceRecordSetsChangedStateRetryable
 229  
 230  	for _, fn := range optFns {
 231  		fn(&options)
 232  	}
 233  	return &ResourceRecordSetsChangedWaiter{
 234  		client:  client,
 235  		options: options,
 236  	}
 237  }
 238  
 239  // Wait calls the waiter function for ResourceRecordSetsChanged waiter. The
 240  // maxWaitDur is the maximum wait duration the waiter will wait. The maxWaitDur is
 241  // required and must be greater than zero.
 242  func (w *ResourceRecordSetsChangedWaiter) Wait(ctx context.Context, params *GetChangeInput, maxWaitDur time.Duration, optFns ...func(*ResourceRecordSetsChangedWaiterOptions)) error {
 243  	_, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...)
 244  	return err
 245  }
 246  
 247  // WaitForOutput calls the waiter function for ResourceRecordSetsChanged waiter
 248  // and returns the output of the successful operation. The maxWaitDur is the
 249  // maximum wait duration the waiter will wait. The maxWaitDur is required and must
 250  // be greater than zero.
 251  func (w *ResourceRecordSetsChangedWaiter) WaitForOutput(ctx context.Context, params *GetChangeInput, maxWaitDur time.Duration, optFns ...func(*ResourceRecordSetsChangedWaiterOptions)) (*GetChangeOutput, error) {
 252  	if maxWaitDur <= 0 {
 253  		return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero")
 254  	}
 255  
 256  	options := w.options
 257  	for _, fn := range optFns {
 258  		fn(&options)
 259  	}
 260  
 261  	if options.MaxDelay <= 0 {
 262  		options.MaxDelay = 120 * time.Second
 263  	}
 264  
 265  	if options.MinDelay > options.MaxDelay {
 266  		return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay)
 267  	}
 268  
 269  	ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur)
 270  	defer cancelFn()
 271  
 272  	logger := smithywaiter.Logger{}
 273  	remainingTime := maxWaitDur
 274  
 275  	var attempt int64
 276  	for {
 277  
 278  		attempt++
 279  		apiOptions := options.APIOptions
 280  		start := time.Now()
 281  
 282  		if options.LogWaitAttempts {
 283  			logger.Attempt = attempt
 284  			apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...)
 285  			apiOptions = append(apiOptions, logger.AddLogger)
 286  		}
 287  
 288  		out, err := w.client.GetChange(ctx, params, func(o *Options) {
 289  			baseOpts := []func(*Options){
 290  				addIsWaiterUserAgent,
 291  			}
 292  			o.APIOptions = append(o.APIOptions, apiOptions...)
 293  			for _, opt := range baseOpts {
 294  				opt(o)
 295  			}
 296  			for _, opt := range options.ClientOptions {
 297  				opt(o)
 298  			}
 299  		})
 300  
 301  		retryable, err := options.Retryable(ctx, params, out, err)
 302  		if err != nil {
 303  			return nil, err
 304  		}
 305  		if !retryable {
 306  			return out, nil
 307  		}
 308  
 309  		remainingTime -= time.Since(start)
 310  		if remainingTime < options.MinDelay || remainingTime <= 0 {
 311  			break
 312  		}
 313  
 314  		// compute exponential backoff between waiter retries
 315  		delay, err := smithywaiter.ComputeDelay(
 316  			attempt, options.MinDelay, options.MaxDelay, remainingTime,
 317  		)
 318  		if err != nil {
 319  			return nil, fmt.Errorf("error computing waiter delay, %w", err)
 320  		}
 321  
 322  		remainingTime -= delay
 323  		// sleep for the delay amount before invoking a request
 324  		if err := smithytime.SleepWithContext(ctx, delay); err != nil {
 325  			return nil, fmt.Errorf("request cancelled while waiting, %w", err)
 326  		}
 327  	}
 328  	return nil, fmt.Errorf("exceeded max wait time for ResourceRecordSetsChanged waiter")
 329  }
 330  
 331  func resourceRecordSetsChangedStateRetryable(ctx context.Context, input *GetChangeInput, output *GetChangeOutput, err error) (bool, error) {
 332  
 333  	if err == nil {
 334  		v1 := output.ChangeInfo
 335  		var v2 types.ChangeStatus
 336  		if v1 != nil {
 337  			v3 := v1.Status
 338  			v2 = v3
 339  		}
 340  		expectedValue := "INSYNC"
 341  		var pathValue string
 342  		pathValue = string(v2)
 343  		if pathValue == expectedValue {
 344  			return false, nil
 345  		}
 346  	}
 347  
 348  	if err != nil {
 349  		return false, err
 350  	}
 351  	return true, nil
 352  }
 353  
 354  // GetChangeAPIClient is a client that implements the GetChange operation.
 355  type GetChangeAPIClient interface {
 356  	GetChange(context.Context, *GetChangeInput, ...func(*Options)) (*GetChangeOutput, error)
 357  }
 358  
 359  var _ GetChangeAPIClient = (*Client)(nil)
 360  
 361  func newServiceMetadataMiddleware_opGetChange(region string) *awsmiddleware.RegisterServiceMetadata {
 362  	return &awsmiddleware.RegisterServiceMetadata{
 363  		Region:        region,
 364  		ServiceID:     ServiceID,
 365  		OperationName: "GetChange",
 366  	}
 367  }
 368