Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@
- [v0.30.0](services/mariadb/CHANGELOG.md#v0300)
- **Feature:** Introduce enums for various attributes
- `modelexperiments`:
- [v.0.2.0](services/modelexperiments/CHANGELOG.md#v020)
- **New**: STACKIT Model Experiments module wait handler added.
- [v0.1.0](services/modelexperiments/CHANGELOG.md#v010)
- **New**: API for STACKIT modelexperiments
- `modelserving`:
Expand Down
14 changes: 14 additions & 0 deletions examples/modelexperiments/go.mod
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
)
8 changes: 8 additions & 0 deletions examples/modelexperiments/go.sum
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=
151 changes: 151 additions & 0 deletions examples/modelexperiments/modelexperiments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package main

import (
"context"
"fmt"
"os"

modelexperiments "github.com/stackitcloud/stackit-sdk-go/services/modelexperiments/v1api"
"github.com/stackitcloud/stackit-sdk-go/services/modelexperiments/v1api/wait"
)

func main() {
Comment thread
paul-sffrth marked this conversation as resolved.
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 {
fmt.Fprintf(os.Stderr, "[Model Experiments] Creating API client: %v\n", err)
os.Exit(1)
}

// Create an Model Experiments Instance
Comment thread
GokceGK marked this conversation as resolved.
Outdated
createInstancePayload := modelexperiments.CreateInstancePayload{
Name: instanceName,
Description: &description,
}
createInstanceResp, err := modelexperimentsClient.DefaultAPI.CreateInstance(ctx, projectId, region).CreateInstancePayload(createInstancePayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `CreateInstance`: %v\n", err)
Comment thread
GokceGK marked this conversation as resolved.
Outdated
} else {
fmt.Printf("[Model Experiments] Created Model Experiments Instance with ID: \"%s\".\n", createInstanceResp.Instance.Id)
Comment thread
GokceGK marked this conversation as resolved.
Outdated
}

Comment thread
paul-sffrth marked this conversation as resolved.
// Wait for the Model Experiments Instance to be ready
fmt.Printf("[Model Experiments] Waiting for Model Experiments Instance to be created.\n")
_, err = wait.CreateModelExperimentsInstanceWaitHandler(ctx, modelexperimentsClient.DefaultAPI, region, projectId, createInstanceResp.Instance.Id).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when waiting for creation: %v\n", err)
}
fmt.Printf("[Model Experiments] Model Experiments Instance \"%s\" has been successfully created.\n", createInstanceResp.Instance.Id)

// Get the created Model Experiments Instance
getInstanceResp, err := modelexperimentsClient.DefaultAPI.GetInstance(ctx, projectId, region, createInstanceResp.Instance.Id).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `GetInstance`: %v\n", err)
} else {
fmt.Printf("[Model Experiments] Retrieved Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", getInstanceResp.Instance.Id, getInstanceResp.Instance.Name)
}

// List Model Experiments Instances
Comment thread
GokceGK marked this conversation as resolved.
listInstaceResp, err := modelexperimentsClient.DefaultAPI.ListInstances(ctx, projectId, region).Execute()
Comment thread
GokceGK marked this conversation as resolved.
Outdated
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `ListInstances`: %v\n", err)
} else {
fmt.Printf("[Model Experiments] Retrieved %d instances\n", len(listInstaceResp.Instances))
}

// Update an Model Experiments Instance
Comment thread
GokceGK marked this conversation as resolved.
Outdated
Comment thread
GokceGK marked this conversation as resolved.
Outdated
partialUpdateInstancePayload := modelexperiments.PartialUpdateInstancePayload{
Name: &newInstanceName,
}
partialUpdateInstanceResp, err := modelexperimentsClient.DefaultAPI.PartialUpdateInstance(ctx, projectId, region, getInstanceResp.Instance.Id).PartialUpdateInstancePayload(partialUpdateInstancePayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `PartialUpdateInstance`: %v\n", err)
} else {
fmt.Printf("[Model Experiments] Updated Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", partialUpdateInstanceResp.Instance.Id, partialUpdateInstanceResp.Instance.Name)
}

// Delete an Model Experiments Instance
Comment thread
GokceGK marked this conversation as resolved.
Outdated
Comment thread
GokceGK marked this conversation as resolved.
Outdated
deleteInstanceResp, err := modelexperimentsClient.DefaultAPI.DeleteInstance(ctx, projectId, region, getInstanceResp.Instance.Id).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `DeleteInstance`: %v\n", err)
} else {
fmt.Printf("[Model Experiments] Deleted Model Experiments Instance with ID: \"%s\" and display name: \"%s\"\n", deleteInstanceResp.Instance.Id, deleteInstanceResp.Instance.Name)
Comment thread
GokceGK marked this conversation as resolved.
Outdated
}

// Wait for the Model Experiments Instance to be deleted
fmt.Printf("[Model Experiments] Waiting for Model Experiments Instance to be deleted.\n")
_, err = wait.DeleteModelExperimentsInstanceWaitHandler(ctx, modelexperimentsClient.DefaultAPI, region, projectId, getInstanceResp.Instance.Id).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when waiting for deletion: %v\n", err)
}
fmt.Printf("[Model Experiments] Model Experiments Instance \"%s\" has been successfully deleted.\n", deleteInstanceResp.Instance.Id)

// Create an Model Experiments Instance Token
Comment thread
GokceGK marked this conversation as resolved.
Outdated
createTokenPayload := modelexperiments.CreateInstanceTokenPayload{
Name: "token-name",
}
createTokenResp, err := modelexperimentsClient.DefaultAPI.CreateInstanceToken(ctx, projectId, region, createInstanceResp.Instance.Id).CreateInstanceTokenPayload(createTokenPayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `CreateToken`: %v\n", err)
} else {
fmt.Printf("[Model Experiments] Created Model Experiments Instance Token: %+v\n", createTokenResp.Token)
Comment thread
GokceGK marked this conversation as resolved.
Outdated
}

// Wait for the Model Experiments Instance Token to be ready
fmt.Printf("[Model Experiments] Waiting for Model Experiments Instance Token to be created.\n")
_, err = wait.CreateModelExperimentsInstanceTokenWaitHandler(ctx, modelexperimentsClient.DefaultAPI, region, projectId, getInstanceResp.Instance.Id, createTokenResp.Token.Id).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when waiting for creation: %v\n", err)
}
fmt.Printf("[Model Experiments] Model Experiments Instance Token \"%s\" has been successfully created.\n", createTokenResp.Token.Id)

// Get the created Model Experiments Instance Token
getTokenResp, err := modelexperimentsClient.DefaultAPI.GetInstanceToken(ctx, projectId, region, createTokenResp.Token.Id, getInstanceResp.Instance.Id).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `GetInstanceToken`: %v\n", err)
} else {
fmt.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
listTokenResp, err := modelexperimentsClient.DefaultAPI.ListInstanceTokens(ctx, projectId, region, getInstanceResp.Instance.Id).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `ListInstanceTokens`: %v\n", err)
} else {
fmt.Printf("[Model Experiments] Retrieved %d instance tokens\n", len(listTokenResp.Tokens))
}

// Update an Model Experiments Instance Token
Comment thread
GokceGK marked this conversation as resolved.
Outdated
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 {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `PartialUpdateInstanceToken`: %v\n", err)
} else {
fmt.Printf("[Model Experiments] Updated Model Experiments Instance Token with ID: \"%s\" and display name: \"%s\"\n", partialUpdateTokenResp.Token.Id, partialUpdateTokenResp.Token.Name)
}

// Delete an Model Experiments Instance Token
Comment thread
GokceGK marked this conversation as resolved.
Outdated
deleteTokenResp, err := modelexperimentsClient.DefaultAPI.DeleteInstanceToken(ctx, projectId, region, getTokenResp.Token.Id, getInstanceResp.Instance.Id).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when calling `DeleteInstanceToken`: %v\n", err)
} else {
fmt.Printf("[Model Experiments] Deleted Model Experiments Instance Token with ID: \"%s\" and display name: \"%s\"\n", deleteTokenResp.Token.Id, deleteTokenResp.Token.Name)
Comment thread
GokceGK marked this conversation as resolved.
Outdated
}

// Wait for the Model Experiments Instance Token to be deleted
fmt.Printf("[Model Experiments] Waiting for Model Experiments Instance Token to be deleted.\n")
_, err = wait.DeleteModelExperimentsInstanceTokenWaitHandler(ctx, modelexperimentsClient.DefaultAPI, region, projectId, getInstanceResp.Instance.Id, deleteTokenResp.Token.Id).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "[Model Experiments] Error when waiting for deletion: %v\n", err)
}
fmt.Printf("[Model Experiments] Model Experiments Instance Token \"%s\" has been successfully deleted.\n", deleteTokenResp.Token.Id)
}
Comment thread
paul-sffrth marked this conversation as resolved.
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use (
./examples/logs
./examples/mariadb
./examples/middleware
./examples/modelexperiments
./examples/mongodbflex
./examples/objectstorage
./examples/observability
Expand Down
3 changes: 3 additions & 0 deletions services/modelexperiments/CHANGELOG.md
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
2 changes: 1 addition & 1 deletion services/modelexperiments/NOTICE.txt
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
2 changes: 1 addition & 1 deletion services/modelexperiments/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.0
v0.2.0
5 changes: 4 additions & 1 deletion services/modelexperiments/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/stackitcloud/stackit-sdk-go/services/modelexperiments

go 1.25

require github.com/stackitcloud/stackit-sdk-go/core v0.26.0
require (
github.com/google/go-cmp v0.7.0
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
)

require (
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
Expand Down
92 changes: 92 additions & 0 deletions services/modelexperiments/v1api/wait/wait.go
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const (
INSTANCESTATE_ACTIVE = "active"
INSTANCESTATE_IMPAIRED = "impaired"
TOKENSTATE_ACTIVE = "active"
)

These aren't used at all and should be removed


// CreateModelExperimentsInstanceWaitHandler will wait for creation of Model Experiments instance
func CreateModelExperimentsInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] {
Comment thread
GokceGK marked this conversation as resolved.
Outdated
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(10 * time.Minute)
return handler
}

// DeleteModelExperimentsInstanceWaitHandler will wait for deletion of Model Experiments instance
func DeleteModelExperimentsInstanceWaitHandler(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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrorState is missing

Suggested change
},
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},
},
ErrorState: []modelexperiments.InstanceState{modelexperiments.INSTANCESTATE_IMPAIRED},
DeleteHttpErrorStatusCodes: []int{http.StatusNotFound},

}

handler := wait.New(waitConfig.Wait())
handler.SetTimeout(10 * time.Minute)
return handler
}

// CreateModelExperimentsTokenWait Handler will wait for creation of Model Experiments instance token
func CreateModelExperimentsInstanceTokenWaitHandler(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(10 * time.Minute)
return handler
}

// DeleteModelExperimentsInstanceTokenWaitHandler will wait for deletion of Model Experiments instance token
func DeleteModelExperimentsInstanceTokenWaitHandler(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(10 * time.Minute)
return handler
}
Loading
Loading