-
Notifications
You must be signed in to change notification settings - Fork 33
feat: model experiments wait handler #7800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f3e992d
557a03e
adfed35
6cffbe6
bc71b3a
9871182
90ff726
eb24830
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| module github.com/stackitcloud/stackit-sdk-go/examples/modelexperiments | ||
|
|
||
| go 1.25 | ||
|
|
||
| // This is not needed in production. This is only here to point the golangci linter to the local version instead of the last release on GitHub. | ||
| replace github.com/stackitcloud/stackit-sdk-go/services/modelexperiments => ../../services/modelexperiments | ||
|
|
||
| require github.com/stackitcloud/stackit-sdk-go/services/modelexperiments v0.2.0 | ||
|
|
||
| require ( | ||
| github.com/golang-jwt/jwt/v5 v5.3.1 // indirect | ||
| github.com/google/uuid v1.6.0 // indirect | ||
| github.com/stackitcloud/stackit-sdk-go/core v0.26.0 // indirect | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= | ||
| github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= | ||
| github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= | ||
| github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= | ||
| github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
| github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
| github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10cz4l0KM2L6hqYBH2QA= | ||
| github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA= |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,149 @@ | ||||||
| package main | ||||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
| "log" | ||||||
|
|
||||||
| modelexperiments "github.com/stackitcloud/stackit-sdk-go/services/modelexperiments/v1api" | ||||||
| "github.com/stackitcloud/stackit-sdk-go/services/modelexperiments/v1api/wait" | ||||||
| ) | ||||||
|
|
||||||
| func main() { | ||||||
| projectId := "PROJECT_ID" // the uuid of your STACKIT project | ||||||
| region := "eu01" | ||||||
| instanceName := "instance" | ||||||
| newInstanceName := "newInstance" | ||||||
| newTokenName := "newTokenName" | ||||||
| description := "description" | ||||||
| ctx := context.Background() | ||||||
|
|
||||||
| modelexperimentsClient, err := modelexperiments.NewAPIClient() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Creating API client: %v\n", err) | ||||||
| } | ||||||
|
|
||||||
| // Create a Model Experiments Instance | ||||||
| log.Printf("[Model Experiments] Creating Model Experiments Instance.\n") | ||||||
| createInstancePayload := modelexperiments.CreateInstancePayload{ | ||||||
| Name: instanceName, | ||||||
| Description: &description, | ||||||
| } | ||||||
| createInstanceResp, err := modelexperimentsClient.DefaultAPI.CreateInstance(ctx, projectId, region).CreateInstancePayload(createInstancePayload).Execute() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when calling `CreateInstance`: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Triggered creation of Model Experiments Instance with ID: \"%s\".\n", createInstanceResp.Instance.Id) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick
Suggested change
|
||||||
|
|
||||||
|
paul-sffrth marked this conversation as resolved.
|
||||||
| // Wait for the Model Experiments Instance to be ready | ||||||
| log.Printf("[Model Experiments] Waiting for Model Experiments Instance to be created.\n") | ||||||
| _, err = wait.CreateInstanceWaitHandler(ctx, modelexperimentsClient.DefaultAPI, region, projectId, createInstanceResp.Instance.Id).WaitWithContext(ctx) | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when waiting for creation: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Model Experiments Instance \"%s\" has been successfully created.\n", createInstanceResp.Instance.Id) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| // Get the created Model Experiments Instance | ||||||
| log.Printf("[Model Experiments] Retrieving Model Experiments Instance.\n") | ||||||
| getInstanceResp, err := modelexperimentsClient.DefaultAPI.GetInstance(ctx, projectId, region, createInstanceResp.Instance.Id).Execute() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when calling `GetInstance`: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Retrieved Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", getInstanceResp.Instance.Id, getInstanceResp.Instance.Name) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| // List Model Experiments Instances | ||||||
|
GokceGK marked this conversation as resolved.
|
||||||
| log.Printf("[Model Experiments] Listing Model Experiments Instances.\n") | ||||||
| listInstanceResp, err := modelexperimentsClient.DefaultAPI.ListInstances(ctx, projectId, region).Execute() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when calling `ListInstances`: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Retrieved %d instances\n", len(listInstanceResp.Instances)) | ||||||
|
|
||||||
| // Update a Model Experiments Instance | ||||||
| log.Printf("[Model Experiments] Updating Model Experiments Instance.\n") | ||||||
| partialUpdateInstancePayload := modelexperiments.PartialUpdateInstancePayload{ | ||||||
| Name: &newInstanceName, | ||||||
| } | ||||||
| partialUpdateInstanceResp, err := modelexperimentsClient.DefaultAPI.PartialUpdateInstance(ctx, projectId, region, getInstanceResp.Instance.Id).PartialUpdateInstancePayload(partialUpdateInstancePayload).Execute() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when calling `PartialUpdateInstance`: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Updated Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", partialUpdateInstanceResp.Instance.Id, partialUpdateInstanceResp.Instance.Name) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace it also in all following prints |
||||||
|
|
||||||
| // Create a Model Experiments Instance Token | ||||||
| log.Printf("[Model Experiments] Creating Model Experiments Instance Token.\n") | ||||||
| createTokenPayload := modelexperiments.CreateInstanceTokenPayload{ | ||||||
| Name: "token-name", | ||||||
| } | ||||||
| createTokenResp, err := modelexperimentsClient.DefaultAPI.CreateInstanceToken(ctx, projectId, region, createInstanceResp.Instance.Id).CreateInstanceTokenPayload(createTokenPayload).Execute() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when calling `CreateToken`: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Triggered creation of Model Experiments Instance Token: %+v\n", createTokenResp.Token) | ||||||
|
|
||||||
| // Wait for the Model Experiments Instance Token to be ready | ||||||
| log.Printf("[Model Experiments] Waiting for Model Experiments Instance Token to be created.\n") | ||||||
| _, err = wait.CreateInstanceTokenWaitHandler(ctx, modelexperimentsClient.DefaultAPI, region, projectId, getInstanceResp.Instance.Id, createTokenResp.Token.Id).WaitWithContext(ctx) | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when waiting for creation: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Model Experiments Instance Token \"%s\" has been successfully created.\n", createTokenResp.Token.Id) | ||||||
|
|
||||||
| // Get the created Model Experiments Instance Token | ||||||
| log.Printf("[Model Experiments] Retrieving Model Experiments Instance Token.\n") | ||||||
| getTokenResp, err := modelexperimentsClient.DefaultAPI.GetInstanceToken(ctx, projectId, region, createTokenResp.Token.Id, getInstanceResp.Instance.Id).Execute() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when calling `GetInstanceToken`: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Retrieved Model Experiments Instance Token with ID: \"%s\" and display name: \"%s\"\n", getTokenResp.Token.Id, getTokenResp.Token.Name) | ||||||
|
|
||||||
| // List Model Experiments Instance Tokens | ||||||
| log.Printf("[Model Experiments] Listing Model Experiments Instance Tokens.\n") | ||||||
| listTokenResp, err := modelexperimentsClient.DefaultAPI.ListInstanceTokens(ctx, projectId, region, getInstanceResp.Instance.Id).Execute() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when calling `ListInstanceTokens`: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Retrieved %d Instance tokens\n", len(listTokenResp.Tokens)) | ||||||
|
|
||||||
| // Update a Model Experiments Instance Token | ||||||
| log.Printf("[Model Experiments] Updating Model Experiments Instance Token.\n") | ||||||
| partialUpdateInstanceTokenPayload := modelexperiments.PartialUpdateInstanceTokenPayload{ | ||||||
| Name: &newTokenName, | ||||||
| } | ||||||
| partialUpdateTokenResp, err := modelexperimentsClient.DefaultAPI.PartialUpdateInstanceToken(ctx, projectId, region, getTokenResp.Token.Id, getInstanceResp.Instance.Id).PartialUpdateInstanceTokenPayload(partialUpdateInstanceTokenPayload).Execute() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when calling `PartialUpdateInstanceToken`: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Updated Model Experiments Instance Token with ID: \"%s\" and display name: \"%s\"\n", partialUpdateTokenResp.Token.Id, partialUpdateTokenResp.Token.Name) | ||||||
|
|
||||||
| // Delete a Model Experiments Instance Token | ||||||
| log.Printf("[Model Experiments] Deleting Model Experiments Instance Token.\n") | ||||||
| deleteTokenResp, err := modelexperimentsClient.DefaultAPI.DeleteInstanceToken(ctx, projectId, region, getTokenResp.Token.Id, getInstanceResp.Instance.Id).Execute() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when calling `DeleteInstanceToken`: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Triggered deletion of Model Experiments Instance Token with ID: \"%s\" and display name: \"%s\"\n", deleteTokenResp.Token.Id, deleteTokenResp.Token.Name) | ||||||
|
|
||||||
| // Wait for the Model Experiments Instance Token to be deleted | ||||||
| log.Printf("[Model Experiments] Waiting for Model Experiments Instance Token to be deleted.\n") | ||||||
| _, err = wait.DeleteInstanceTokenWaitHandler(ctx, modelexperimentsClient.DefaultAPI, region, projectId, getInstanceResp.Instance.Id, deleteTokenResp.Token.Id).WaitWithContext(ctx) | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when waiting for deletion: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Model Experiments Instance Token \"%s\" has been successfully deleted.\n", deleteTokenResp.Token.Id) | ||||||
|
|
||||||
| // Delete a Model Experiments Instance | ||||||
| log.Printf("[Model Experiments] Deleting Model Experiments Instance.\n") | ||||||
| deleteInstanceResp, err := modelexperimentsClient.DefaultAPI.DeleteInstance(ctx, projectId, region, getInstanceResp.Instance.Id).Execute() | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when calling `DeleteInstance`: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Triggered deletion of Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", deleteInstanceResp.Instance.Id, deleteInstanceResp.Instance.Name) | ||||||
|
|
||||||
| // Wait for the Model Experiments Instance to be deleted | ||||||
| log.Printf("[Model Experiments] Waiting for Model Experiments Instance to be deleted.\n") | ||||||
| _, err = wait.DeleteInstanceWaitHandler(ctx, modelexperimentsClient.DefaultAPI, region, projectId, getInstanceResp.Instance.Id).WaitWithContext(ctx) | ||||||
| if err != nil { | ||||||
| log.Fatalf("[Model Experiments] Error when waiting for deletion: %v\n", err) | ||||||
| } | ||||||
| log.Printf("[Model Experiments] Model Experiments Instance \"%s\" has been successfully deleted.\n", deleteInstanceResp.Instance.Id) | ||||||
| } | ||||||
|
paul-sffrth marked this conversation as resolved.
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| ## v0.2.0 | ||
| - **New**: STACKIT Model Experiments module wait handler added. | ||
|
|
||
| ## v0.1.0 | ||
| - **New**: API for STACKIT modelexperiments |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| STACKIT modelexperiments SDK for Go | ||
| STACKIT Model Experiments SDK for Go | ||
| Copyright 2026 Schwarz IT KG |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v0.1.0 | ||
| v0.2.0 |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,92 @@ | ||||||||||||||
| package wait | ||||||||||||||
|
|
||||||||||||||
| import ( | ||||||||||||||
| "context" | ||||||||||||||
| "errors" | ||||||||||||||
| "net/http" | ||||||||||||||
| "time" | ||||||||||||||
|
|
||||||||||||||
| "github.com/stackitcloud/stackit-sdk-go/core/wait" | ||||||||||||||
| modelexperiments "github.com/stackitcloud/stackit-sdk-go/services/modelexperiments/v1api" | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| const ( | ||||||||||||||
| INSTANCESTATE_ACTIVE = "active" | ||||||||||||||
| INSTANCESTATE_IMPAIRED = "impaired" | ||||||||||||||
|
|
||||||||||||||
| TOKENSTATE_ACTIVE = "active" | ||||||||||||||
| ) | ||||||||||||||
|
Comment on lines
+13
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
These aren't used at all and should be removed |
||||||||||||||
|
|
||||||||||||||
| // CreateInstanceWaitHandler will wait for creation of Model Experiments instance | ||||||||||||||
| func CreateInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] { | ||||||||||||||
| waitConfig := wait.WaiterHelper[modelexperiments.GetInstanceResponse, modelexperiments.InstanceState]{ | ||||||||||||||
| FetchInstance: a.GetInstance(ctx, projectId, region, instanceId).Execute, | ||||||||||||||
| GetState: func(response *modelexperiments.GetInstanceResponse) (modelexperiments.InstanceState, error) { | ||||||||||||||
| if response == nil { | ||||||||||||||
| return "", errors.New("empty response") | ||||||||||||||
| } | ||||||||||||||
| return response.Instance.State, nil | ||||||||||||||
| }, | ||||||||||||||
| ActiveState: []modelexperiments.InstanceState{modelexperiments.INSTANCESTATE_ACTIVE}, | ||||||||||||||
| ErrorState: []modelexperiments.InstanceState{modelexperiments.INSTANCESTATE_IMPAIRED}, | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| handler := wait.New(waitConfig.Wait()) | ||||||||||||||
| handler.SetTimeout(45 * time.Minute) | ||||||||||||||
| return handler | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // DeleteInstanceWaitHandler will wait for deletion of Model Experiments instance | ||||||||||||||
| func DeleteInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] { | ||||||||||||||
| waitConfig := wait.WaiterHelper[modelexperiments.GetInstanceResponse, modelexperiments.InstanceState]{ | ||||||||||||||
| FetchInstance: a.GetInstance(ctx, projectId, region, instanceId).Execute, | ||||||||||||||
| GetState: func(response *modelexperiments.GetInstanceResponse) (modelexperiments.InstanceState, error) { | ||||||||||||||
| if response == nil { | ||||||||||||||
| return "", errors.New("empty response") | ||||||||||||||
| } | ||||||||||||||
| return response.Instance.State, nil | ||||||||||||||
| }, | ||||||||||||||
| DeleteHttpErrorStatusCodes: []int{http.StatusNotFound}, | ||||||||||||||
|
Comment on lines
+48
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ErrorState is missing
Suggested change
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| handler := wait.New(waitConfig.Wait()) | ||||||||||||||
| handler.SetTimeout(45 * time.Minute) | ||||||||||||||
| return handler | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // CreateInstanceTokenWaitHandler will wait for creation of Model Experiments instance token | ||||||||||||||
| func CreateInstanceTokenWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId, tokenId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceTokenResponse] { | ||||||||||||||
| waitConfig := wait.WaiterHelper[modelexperiments.GetInstanceTokenResponse, modelexperiments.TokenState]{ | ||||||||||||||
| FetchInstance: a.GetInstanceToken(ctx, projectId, region, tokenId, instanceId).Execute, | ||||||||||||||
| GetState: func(response *modelexperiments.GetInstanceTokenResponse) (modelexperiments.TokenState, error) { | ||||||||||||||
| if response == nil { | ||||||||||||||
| return "", errors.New("empty response") | ||||||||||||||
| } | ||||||||||||||
| return response.Token.State, nil | ||||||||||||||
| }, | ||||||||||||||
| ActiveState: []modelexperiments.TokenState{modelexperiments.TOKENSTATE_ACTIVE}, | ||||||||||||||
| ErrorState: []modelexperiments.TokenState{}, | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| handler := wait.New(waitConfig.Wait()) | ||||||||||||||
| handler.SetTimeout(45 * time.Minute) | ||||||||||||||
| return handler | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // DeleteInstanceTokenWaitHandler will wait for deletion of Model Experiments instance token | ||||||||||||||
| func DeleteInstanceTokenWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId, tokenId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceTokenResponse] { | ||||||||||||||
| waitConfig := wait.WaiterHelper[modelexperiments.GetInstanceTokenResponse, modelexperiments.TokenState]{ | ||||||||||||||
| FetchInstance: a.GetInstanceToken(ctx, projectId, region, tokenId, instanceId).Execute, | ||||||||||||||
| GetState: func(response *modelexperiments.GetInstanceTokenResponse) (modelexperiments.TokenState, error) { | ||||||||||||||
| if response == nil { | ||||||||||||||
| return "", errors.New("empty response") | ||||||||||||||
| } | ||||||||||||||
| return response.Token.State, nil | ||||||||||||||
| }, | ||||||||||||||
| DeleteHttpErrorStatusCodes: []int{http.StatusNotFound}, | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| handler := wait.New(waitConfig.Wait()) | ||||||||||||||
| handler.SetTimeout(45 * time.Minute) | ||||||||||||||
| return handler | ||||||||||||||
| } | ||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.