src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

api_op_GetChange.go (9737B)


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