// Code generated by smithy-go-codegen DO NOT EDIT. package nimble import ( "context" "fmt" awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" "github.com/aws/aws-sdk-go-v2/aws/signer/v4" "github.com/aws/aws-sdk-go-v2/service/nimble/types" "github.com/aws/smithy-go/middleware" smithytime "github.com/aws/smithy-go/time" smithyhttp "github.com/aws/smithy-go/transport/http" smithywaiter "github.com/aws/smithy-go/waiter" "github.com/jmespath/go-jmespath" "time" ) // Gets StreamingSession resource. Invoke this operation to poll for a streaming // session state while creating or deleting a session. func (c *Client) GetStreamingSession(ctx context.Context, params *GetStreamingSessionInput, optFns ...func(*Options)) (*GetStreamingSessionOutput, error) { if params == nil { params = &GetStreamingSessionInput{} } result, metadata, err := c.invokeOperation(ctx, "GetStreamingSession", params, optFns, c.addOperationGetStreamingSessionMiddlewares) if err != nil { return nil, err } out := result.(*GetStreamingSessionOutput) out.ResultMetadata = metadata return out, nil } type GetStreamingSessionInput struct { // The streaming session ID. // // This member is required. SessionId *string // The studio ID. // // This member is required. StudioId *string noSmithyDocumentSerde } type GetStreamingSessionOutput struct { // The session. Session *types.StreamingSession // Metadata pertaining to the operation's result. ResultMetadata middleware.Metadata noSmithyDocumentSerde } func (c *Client) addOperationGetStreamingSessionMiddlewares(stack *middleware.Stack, options Options) (err error) { err = stack.Serialize.Add(&awsRestjson1_serializeOpGetStreamingSession{}, middleware.After) if err != nil { return err } err = stack.Deserialize.Add(&awsRestjson1_deserializeOpGetStreamingSession{}, middleware.After) if err != nil { return err } if err = addSetLoggerMiddleware(stack, options); err != nil { return err } if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { return err } if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { return err } if err = addResolveEndpointMiddleware(stack, options); err != nil { return err } if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { return err } if err = addRetryMiddlewares(stack, options); err != nil { return err } if err = addHTTPSignerV4Middleware(stack, options); err != nil { return err } if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { return err } if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { return err } if err = addClientUserAgent(stack, options); err != nil { return err } if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { return err } if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { return err } if err = addOpGetStreamingSessionValidationMiddleware(stack); err != nil { return err } if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetStreamingSession(options.Region), middleware.Before); err != nil { return err } if err = awsmiddleware.AddRecursionDetection(stack); err != nil { return err } if err = addRequestIDRetrieverMiddleware(stack); err != nil { return err } if err = addResponseErrorMiddleware(stack); err != nil { return err } if err = addRequestResponseLogging(stack, options); err != nil { return err } return nil } // GetStreamingSessionAPIClient is a client that implements the // GetStreamingSession operation. type GetStreamingSessionAPIClient interface { GetStreamingSession(context.Context, *GetStreamingSessionInput, ...func(*Options)) (*GetStreamingSessionOutput, error) } var _ GetStreamingSessionAPIClient = (*Client)(nil) // StreamingSessionReadyWaiterOptions are waiter options for // StreamingSessionReadyWaiter type StreamingSessionReadyWaiterOptions struct { // Set of options to modify how an operation is invoked. These apply to all // operations invoked for this client. Use functional options on operation call to // modify this list for per operation behavior. APIOptions []func(*middleware.Stack) error // MinDelay is the minimum amount of time to delay between retries. If unset, // StreamingSessionReadyWaiter will use default minimum delay of 10 seconds. Note // that MinDelay must resolve to a value lesser than or equal to the MaxDelay. MinDelay time.Duration // MaxDelay is the maximum amount of time to delay between retries. If unset or // set to zero, StreamingSessionReadyWaiter will use default max delay of 1800 // seconds. Note that MaxDelay must resolve to value greater than or equal to the // MinDelay. MaxDelay time.Duration // LogWaitAttempts is used to enable logging for waiter retry attempts LogWaitAttempts bool // Retryable is function that can be used to override the service defined // waiter-behavior based on operation output, or returned error. This function is // used by the waiter to decide if a state is retryable or a terminal state. By // default service-modeled logic will populate this option. This option can thus be // used to define a custom waiter state with fall-back to service-modeled waiter // state mutators.The function returns an error in case of a failure state. In case // of retry state, this function returns a bool value of true and nil error, while // in case of success it returns a bool value of false and nil error. Retryable func(context.Context, *GetStreamingSessionInput, *GetStreamingSessionOutput, error) (bool, error) } // StreamingSessionReadyWaiter defines the waiters for StreamingSessionReady type StreamingSessionReadyWaiter struct { client GetStreamingSessionAPIClient options StreamingSessionReadyWaiterOptions } // NewStreamingSessionReadyWaiter constructs a StreamingSessionReadyWaiter. func NewStreamingSessionReadyWaiter(client GetStreamingSessionAPIClient, optFns ...func(*StreamingSessionReadyWaiterOptions)) *StreamingSessionReadyWaiter { options := StreamingSessionReadyWaiterOptions{} options.MinDelay = 10 * time.Second options.MaxDelay = 1800 * time.Second options.Retryable = streamingSessionReadyStateRetryable for _, fn := range optFns { fn(&options) } return &StreamingSessionReadyWaiter{ client: client, options: options, } } // Wait calls the waiter function for StreamingSessionReady waiter. The maxWaitDur // is the maximum wait duration the waiter will wait. The maxWaitDur is required // and must be greater than zero. func (w *StreamingSessionReadyWaiter) Wait(ctx context.Context, params *GetStreamingSessionInput, maxWaitDur time.Duration, optFns ...func(*StreamingSessionReadyWaiterOptions)) error { _, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...) return err } // WaitForOutput calls the waiter function for StreamingSessionReady waiter and // returns the output of the successful operation. The maxWaitDur is the maximum // wait duration the waiter will wait. The maxWaitDur is required and must be // greater than zero. func (w *StreamingSessionReadyWaiter) WaitForOutput(ctx context.Context, params *GetStreamingSessionInput, maxWaitDur time.Duration, optFns ...func(*StreamingSessionReadyWaiterOptions)) (*GetStreamingSessionOutput, error) { if maxWaitDur <= 0 { return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero") } options := w.options for _, fn := range optFns { fn(&options) } if options.MaxDelay <= 0 { options.MaxDelay = 1800 * time.Second } if options.MinDelay > options.MaxDelay { return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) } ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) defer cancelFn() logger := smithywaiter.Logger{} remainingTime := maxWaitDur var attempt int64 for { attempt++ apiOptions := options.APIOptions start := time.Now() if options.LogWaitAttempts { logger.Attempt = attempt apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) apiOptions = append(apiOptions, logger.AddLogger) } out, err := w.client.GetStreamingSession(ctx, params, func(o *Options) { o.APIOptions = append(o.APIOptions, apiOptions...) }) retryable, err := options.Retryable(ctx, params, out, err) if err != nil { return nil, err } if !retryable { return out, nil } remainingTime -= time.Since(start) if remainingTime < options.MinDelay || remainingTime <= 0 { break } // compute exponential backoff between waiter retries delay, err := smithywaiter.ComputeDelay( attempt, options.MinDelay, options.MaxDelay, remainingTime, ) if err != nil { return nil, fmt.Errorf("error computing waiter delay, %w", err) } remainingTime -= delay // sleep for the delay amount before invoking a request if err := smithytime.SleepWithContext(ctx, delay); err != nil { return nil, fmt.Errorf("request cancelled while waiting, %w", err) } } return nil, fmt.Errorf("exceeded max wait time for StreamingSessionReady waiter") } func streamingSessionReadyStateRetryable(ctx context.Context, input *GetStreamingSessionInput, output *GetStreamingSessionOutput, err error) (bool, error) { if err == nil { pathValue, err := jmespath.Search("session.state", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "READY" value, ok := pathValue.(types.StreamingSessionState) if !ok { return false, fmt.Errorf("waiter comparator expected types.StreamingSessionState value, got %T", pathValue) } if string(value) == expectedValue { return false, nil } } if err == nil { pathValue, err := jmespath.Search("session.state", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "CREATE_FAILED" value, ok := pathValue.(types.StreamingSessionState) if !ok { return false, fmt.Errorf("waiter comparator expected types.StreamingSessionState value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } if err == nil { pathValue, err := jmespath.Search("session.state", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "START_FAILED" value, ok := pathValue.(types.StreamingSessionState) if !ok { return false, fmt.Errorf("waiter comparator expected types.StreamingSessionState value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } return true, nil } // StreamingSessionStoppedWaiterOptions are waiter options for // StreamingSessionStoppedWaiter type StreamingSessionStoppedWaiterOptions struct { // Set of options to modify how an operation is invoked. These apply to all // operations invoked for this client. Use functional options on operation call to // modify this list for per operation behavior. APIOptions []func(*middleware.Stack) error // MinDelay is the minimum amount of time to delay between retries. If unset, // StreamingSessionStoppedWaiter will use default minimum delay of 5 seconds. Note // that MinDelay must resolve to a value lesser than or equal to the MaxDelay. MinDelay time.Duration // MaxDelay is the maximum amount of time to delay between retries. If unset or // set to zero, StreamingSessionStoppedWaiter will use default max delay of 900 // seconds. Note that MaxDelay must resolve to value greater than or equal to the // MinDelay. MaxDelay time.Duration // LogWaitAttempts is used to enable logging for waiter retry attempts LogWaitAttempts bool // Retryable is function that can be used to override the service defined // waiter-behavior based on operation output, or returned error. This function is // used by the waiter to decide if a state is retryable or a terminal state. By // default service-modeled logic will populate this option. This option can thus be // used to define a custom waiter state with fall-back to service-modeled waiter // state mutators.The function returns an error in case of a failure state. In case // of retry state, this function returns a bool value of true and nil error, while // in case of success it returns a bool value of false and nil error. Retryable func(context.Context, *GetStreamingSessionInput, *GetStreamingSessionOutput, error) (bool, error) } // StreamingSessionStoppedWaiter defines the waiters for StreamingSessionStopped type StreamingSessionStoppedWaiter struct { client GetStreamingSessionAPIClient options StreamingSessionStoppedWaiterOptions } // NewStreamingSessionStoppedWaiter constructs a StreamingSessionStoppedWaiter. func NewStreamingSessionStoppedWaiter(client GetStreamingSessionAPIClient, optFns ...func(*StreamingSessionStoppedWaiterOptions)) *StreamingSessionStoppedWaiter { options := StreamingSessionStoppedWaiterOptions{} options.MinDelay = 5 * time.Second options.MaxDelay = 900 * time.Second options.Retryable = streamingSessionStoppedStateRetryable for _, fn := range optFns { fn(&options) } return &StreamingSessionStoppedWaiter{ client: client, options: options, } } // Wait calls the waiter function for StreamingSessionStopped waiter. The // maxWaitDur is the maximum wait duration the waiter will wait. The maxWaitDur is // required and must be greater than zero. func (w *StreamingSessionStoppedWaiter) Wait(ctx context.Context, params *GetStreamingSessionInput, maxWaitDur time.Duration, optFns ...func(*StreamingSessionStoppedWaiterOptions)) error { _, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...) return err } // WaitForOutput calls the waiter function for StreamingSessionStopped waiter and // returns the output of the successful operation. The maxWaitDur is the maximum // wait duration the waiter will wait. The maxWaitDur is required and must be // greater than zero. func (w *StreamingSessionStoppedWaiter) WaitForOutput(ctx context.Context, params *GetStreamingSessionInput, maxWaitDur time.Duration, optFns ...func(*StreamingSessionStoppedWaiterOptions)) (*GetStreamingSessionOutput, error) { if maxWaitDur <= 0 { return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero") } options := w.options for _, fn := range optFns { fn(&options) } if options.MaxDelay <= 0 { options.MaxDelay = 900 * time.Second } if options.MinDelay > options.MaxDelay { return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) } ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) defer cancelFn() logger := smithywaiter.Logger{} remainingTime := maxWaitDur var attempt int64 for { attempt++ apiOptions := options.APIOptions start := time.Now() if options.LogWaitAttempts { logger.Attempt = attempt apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) apiOptions = append(apiOptions, logger.AddLogger) } out, err := w.client.GetStreamingSession(ctx, params, func(o *Options) { o.APIOptions = append(o.APIOptions, apiOptions...) }) retryable, err := options.Retryable(ctx, params, out, err) if err != nil { return nil, err } if !retryable { return out, nil } remainingTime -= time.Since(start) if remainingTime < options.MinDelay || remainingTime <= 0 { break } // compute exponential backoff between waiter retries delay, err := smithywaiter.ComputeDelay( attempt, options.MinDelay, options.MaxDelay, remainingTime, ) if err != nil { return nil, fmt.Errorf("error computing waiter delay, %w", err) } remainingTime -= delay // sleep for the delay amount before invoking a request if err := smithytime.SleepWithContext(ctx, delay); err != nil { return nil, fmt.Errorf("request cancelled while waiting, %w", err) } } return nil, fmt.Errorf("exceeded max wait time for StreamingSessionStopped waiter") } func streamingSessionStoppedStateRetryable(ctx context.Context, input *GetStreamingSessionInput, output *GetStreamingSessionOutput, err error) (bool, error) { if err == nil { pathValue, err := jmespath.Search("session.state", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "STOPPED" value, ok := pathValue.(types.StreamingSessionState) if !ok { return false, fmt.Errorf("waiter comparator expected types.StreamingSessionState value, got %T", pathValue) } if string(value) == expectedValue { return false, nil } } if err == nil { pathValue, err := jmespath.Search("session.state", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "STOP_FAILED" value, ok := pathValue.(types.StreamingSessionState) if !ok { return false, fmt.Errorf("waiter comparator expected types.StreamingSessionState value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } return true, nil } // StreamingSessionDeletedWaiterOptions are waiter options for // StreamingSessionDeletedWaiter type StreamingSessionDeletedWaiterOptions struct { // Set of options to modify how an operation is invoked. These apply to all // operations invoked for this client. Use functional options on operation call to // modify this list for per operation behavior. APIOptions []func(*middleware.Stack) error // MinDelay is the minimum amount of time to delay between retries. If unset, // StreamingSessionDeletedWaiter will use default minimum delay of 5 seconds. Note // that MinDelay must resolve to a value lesser than or equal to the MaxDelay. MinDelay time.Duration // MaxDelay is the maximum amount of time to delay between retries. If unset or // set to zero, StreamingSessionDeletedWaiter will use default max delay of 900 // seconds. Note that MaxDelay must resolve to value greater than or equal to the // MinDelay. MaxDelay time.Duration // LogWaitAttempts is used to enable logging for waiter retry attempts LogWaitAttempts bool // Retryable is function that can be used to override the service defined // waiter-behavior based on operation output, or returned error. This function is // used by the waiter to decide if a state is retryable or a terminal state. By // default service-modeled logic will populate this option. This option can thus be // used to define a custom waiter state with fall-back to service-modeled waiter // state mutators.The function returns an error in case of a failure state. In case // of retry state, this function returns a bool value of true and nil error, while // in case of success it returns a bool value of false and nil error. Retryable func(context.Context, *GetStreamingSessionInput, *GetStreamingSessionOutput, error) (bool, error) } // StreamingSessionDeletedWaiter defines the waiters for StreamingSessionDeleted type StreamingSessionDeletedWaiter struct { client GetStreamingSessionAPIClient options StreamingSessionDeletedWaiterOptions } // NewStreamingSessionDeletedWaiter constructs a StreamingSessionDeletedWaiter. func NewStreamingSessionDeletedWaiter(client GetStreamingSessionAPIClient, optFns ...func(*StreamingSessionDeletedWaiterOptions)) *StreamingSessionDeletedWaiter { options := StreamingSessionDeletedWaiterOptions{} options.MinDelay = 5 * time.Second options.MaxDelay = 900 * time.Second options.Retryable = streamingSessionDeletedStateRetryable for _, fn := range optFns { fn(&options) } return &StreamingSessionDeletedWaiter{ client: client, options: options, } } // Wait calls the waiter function for StreamingSessionDeleted waiter. The // maxWaitDur is the maximum wait duration the waiter will wait. The maxWaitDur is // required and must be greater than zero. func (w *StreamingSessionDeletedWaiter) Wait(ctx context.Context, params *GetStreamingSessionInput, maxWaitDur time.Duration, optFns ...func(*StreamingSessionDeletedWaiterOptions)) error { _, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...) return err } // WaitForOutput calls the waiter function for StreamingSessionDeleted waiter and // returns the output of the successful operation. The maxWaitDur is the maximum // wait duration the waiter will wait. The maxWaitDur is required and must be // greater than zero. func (w *StreamingSessionDeletedWaiter) WaitForOutput(ctx context.Context, params *GetStreamingSessionInput, maxWaitDur time.Duration, optFns ...func(*StreamingSessionDeletedWaiterOptions)) (*GetStreamingSessionOutput, error) { if maxWaitDur <= 0 { return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero") } options := w.options for _, fn := range optFns { fn(&options) } if options.MaxDelay <= 0 { options.MaxDelay = 900 * time.Second } if options.MinDelay > options.MaxDelay { return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) } ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) defer cancelFn() logger := smithywaiter.Logger{} remainingTime := maxWaitDur var attempt int64 for { attempt++ apiOptions := options.APIOptions start := time.Now() if options.LogWaitAttempts { logger.Attempt = attempt apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) apiOptions = append(apiOptions, logger.AddLogger) } out, err := w.client.GetStreamingSession(ctx, params, func(o *Options) { o.APIOptions = append(o.APIOptions, apiOptions...) }) retryable, err := options.Retryable(ctx, params, out, err) if err != nil { return nil, err } if !retryable { return out, nil } remainingTime -= time.Since(start) if remainingTime < options.MinDelay || remainingTime <= 0 { break } // compute exponential backoff between waiter retries delay, err := smithywaiter.ComputeDelay( attempt, options.MinDelay, options.MaxDelay, remainingTime, ) if err != nil { return nil, fmt.Errorf("error computing waiter delay, %w", err) } remainingTime -= delay // sleep for the delay amount before invoking a request if err := smithytime.SleepWithContext(ctx, delay); err != nil { return nil, fmt.Errorf("request cancelled while waiting, %w", err) } } return nil, fmt.Errorf("exceeded max wait time for StreamingSessionDeleted waiter") } func streamingSessionDeletedStateRetryable(ctx context.Context, input *GetStreamingSessionInput, output *GetStreamingSessionOutput, err error) (bool, error) { if err == nil { pathValue, err := jmespath.Search("session.state", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "DELETED" value, ok := pathValue.(types.StreamingSessionState) if !ok { return false, fmt.Errorf("waiter comparator expected types.StreamingSessionState value, got %T", pathValue) } if string(value) == expectedValue { return false, nil } } if err == nil { pathValue, err := jmespath.Search("session.state", output) if err != nil { return false, fmt.Errorf("error evaluating waiter state: %w", err) } expectedValue := "DELETE_FAILED" value, ok := pathValue.(types.StreamingSessionState) if !ok { return false, fmt.Errorf("waiter comparator expected types.StreamingSessionState value, got %T", pathValue) } if string(value) == expectedValue { return false, fmt.Errorf("waiter state transitioned to Failure") } } return true, nil } func newServiceMetadataMiddleware_opGetStreamingSession(region string) *awsmiddleware.RegisterServiceMetadata { return &awsmiddleware.RegisterServiceMetadata{ Region: region, ServiceID: ServiceID, SigningName: "nimble", OperationName: "GetStreamingSession", } }