1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package lookoutvision
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/lookoutvision/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Starts the running of the version of an Amazon Lookout for Vision model.
16// Starting a model takes a while to complete. To check the current state of the
17// model, use DescribeModel. A model is ready to use when its status is HOSTED.
18// Once the model is running, you can detect custom labels in new images by calling
19// DetectAnomalies. You are charged for the amount of time that the model is
20// running. To stop a running model, call StopModel. This operation requires
21// permissions to perform the lookoutvision:StartModel operation.
22func (c *Client) StartModel(ctx context.Context, params *StartModelInput, optFns ...func(*Options)) (*StartModelOutput, error) {
23	if params == nil {
24		params = &StartModelInput{}
25	}
26
27	result, metadata, err := c.invokeOperation(ctx, "StartModel", params, optFns, addOperationStartModelMiddlewares)
28	if err != nil {
29		return nil, err
30	}
31
32	out := result.(*StartModelOutput)
33	out.ResultMetadata = metadata
34	return out, nil
35}
36
37type StartModelInput struct {
38
39	// The minimum number of inference units to use. A single inference unit represents
40	// 1 hour of processing and can support up to 5 Transaction Pers Second (TPS). Use
41	// a higher number to increase the TPS throughput of your model. You are charged
42	// for the number of inference units that you use.
43	//
44	// This member is required.
45	MinInferenceUnits *int32
46
47	// The version of the model that you want to start.
48	//
49	// This member is required.
50	ModelVersion *string
51
52	// The name of the project that contains the model that you want to start.
53	//
54	// This member is required.
55	ProjectName *string
56
57	// ClientToken is an idempotency token that ensures a call to StartModel completes
58	// only once. You choose the value to pass. For example, An issue, such as an
59	// network outage, might prevent you from getting a response from StartModel. In
60	// this case, safely retry your call to StartModel by using the same ClientToken
61	// parameter value. An error occurs if the other input parameters are not the same
62	// as in the first request. Using a different value for ClientToken is considered a
63	// new call to StartModel. An idempotency token is active for 8 hours.
64	ClientToken *string
65}
66
67type StartModelOutput struct {
68
69	// The current running status of the model.
70	Status types.ModelHostingStatus
71
72	// Metadata pertaining to the operation's result.
73	ResultMetadata middleware.Metadata
74}
75
76func addOperationStartModelMiddlewares(stack *middleware.Stack, options Options) (err error) {
77	err = stack.Serialize.Add(&awsRestjson1_serializeOpStartModel{}, middleware.After)
78	if err != nil {
79		return err
80	}
81	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpStartModel{}, middleware.After)
82	if err != nil {
83		return err
84	}
85	if err = addSetLoggerMiddleware(stack, options); err != nil {
86		return err
87	}
88	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
89		return err
90	}
91	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
92		return err
93	}
94	if err = addResolveEndpointMiddleware(stack, options); err != nil {
95		return err
96	}
97	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
98		return err
99	}
100	if err = addRetryMiddlewares(stack, options); err != nil {
101		return err
102	}
103	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
104		return err
105	}
106	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
107		return err
108	}
109	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
110		return err
111	}
112	if err = addClientUserAgent(stack); err != nil {
113		return err
114	}
115	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
116		return err
117	}
118	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
119		return err
120	}
121	if err = addIdempotencyToken_opStartModelMiddleware(stack, options); err != nil {
122		return err
123	}
124	if err = addOpStartModelValidationMiddleware(stack); err != nil {
125		return err
126	}
127	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opStartModel(options.Region), middleware.Before); err != nil {
128		return err
129	}
130	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
131		return err
132	}
133	if err = addResponseErrorMiddleware(stack); err != nil {
134		return err
135	}
136	if err = addRequestResponseLogging(stack, options); err != nil {
137		return err
138	}
139	return nil
140}
141
142type idempotencyToken_initializeOpStartModel struct {
143	tokenProvider IdempotencyTokenProvider
144}
145
146func (*idempotencyToken_initializeOpStartModel) ID() string {
147	return "OperationIdempotencyTokenAutoFill"
148}
149
150func (m *idempotencyToken_initializeOpStartModel) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
151	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
152) {
153	if m.tokenProvider == nil {
154		return next.HandleInitialize(ctx, in)
155	}
156
157	input, ok := in.Parameters.(*StartModelInput)
158	if !ok {
159		return out, metadata, fmt.Errorf("expected middleware input to be of type *StartModelInput ")
160	}
161
162	if input.ClientToken == nil {
163		t, err := m.tokenProvider.GetIdempotencyToken()
164		if err != nil {
165			return out, metadata, err
166		}
167		input.ClientToken = &t
168	}
169	return next.HandleInitialize(ctx, in)
170}
171func addIdempotencyToken_opStartModelMiddleware(stack *middleware.Stack, cfg Options) error {
172	return stack.Initialize.Add(&idempotencyToken_initializeOpStartModel{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
173}
174
175func newServiceMetadataMiddleware_opStartModel(region string) *awsmiddleware.RegisterServiceMetadata {
176	return &awsmiddleware.RegisterServiceMetadata{
177		Region:        region,
178		ServiceID:     ServiceID,
179		SigningName:   "lookoutvision",
180		OperationName: "StartModel",
181	}
182}
183