Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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=
53 changes: 53 additions & 0 deletions examples/modelexperiments/modelexperiments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"context"
"fmt"
"os"

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

func main() {
Comment thread
paul-sffrth marked this conversation as resolved.
projectId := "PROJECT_ID" // the uuid of your STACKIT project
region := "eu01"
instanceName := "instance"
description := "description"

modelexperimentsClient, err := modelexperiments.NewAPIClient()
if err != nil {
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
Comment thread
paul-sffrth marked this conversation as resolved.
Outdated
os.Exit(1)
}

// Create a instance
Comment thread
paul-sffrth marked this conversation as resolved.
Outdated
createInstancePayload := modelexperiments.CreateInstancePayload{
Name: instanceName,
Description: &description,
}
createInstanceResp, err := modelexperimentsClient.DefaultAPI.CreateInstance(context.Background(), projectId, region).CreateInstancePayload(createInstancePayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CreateInstance`: %v\n", err)
} else {
fmt.Printf("Created instance with instance id \"%s\".\n", createInstanceResp.Instance.Id)
}

Comment thread
paul-sffrth marked this conversation as resolved.
// Get the created instance
getInstanceResp, err := modelexperimentsClient.DefaultAPI.GetInstance(context.Background(), projectId, region, createInstanceResp.Instance.Id).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `GetInstance`: %v\n", err)
} else {
fmt.Printf("Retrieved instance: %+v\n", getInstanceResp.Instance)
Comment thread
paul-sffrth marked this conversation as resolved.
Outdated
}

// Create a token for the instance
createTokenPayload := modelexperiments.CreateInstanceTokenPayload{
Name: "token-name",
}
createTokenResp, err := modelexperimentsClient.DefaultAPI.CreateInstanceToken(context.Background(), projectId, region, createInstanceResp.Instance.Id).CreateInstanceTokenPayload(createTokenPayload).Execute()
Comment thread
paul-sffrth marked this conversation as resolved.
Outdated
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CreateToken`: %v\n", err)
} else {
fmt.Printf("Created token: %+v\n", createTokenResp.Token)
}
}
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/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
96 changes: 96 additions & 0 deletions services/modelexperiments/v1api/wait/wait.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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


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

handler.SetTimeout(10 * time.Minute)

return handler
}

// DeleteMExpInstanceWaitHandler will wait for deletion of Model Experiments instance
func DeleteMExpInstanceWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceResponse] {
Comment thread
paul-sffrth 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
},
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())
Comment thread
paul-sffrth marked this conversation as resolved.
Outdated

handler.SetTimeout(10 * time.Minute)

return handler
}

// CreateMExpTokenWait Handler will wait for creation of Model Experiments instance token
func CreateMExpInstanceTokenWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId, tokenId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceTokenResponse] {
Comment thread
paul-sffrth marked this conversation as resolved.
Outdated
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())
Comment thread
paul-sffrth marked this conversation as resolved.
Outdated

handler.SetTimeout(10 * time.Minute)

return handler
}

// DeleteMExpInstanceTokenWaitHandler will wait for deletion of Model Experiments instance token
func DeleteMExpInstanceTokenWaitHandler(ctx context.Context, a modelexperiments.DefaultAPI, region, projectId, instanceId, tokenId string) *wait.AsyncActionHandler[modelexperiments.GetInstanceTokenResponse] {
Comment thread
paul-sffrth marked this conversation as resolved.
Outdated
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())
Comment thread
paul-sffrth marked this conversation as resolved.
Outdated

handler.SetTimeout(10 * time.Minute)

return handler
}
Loading
Loading