-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompute_contexts.go
More file actions
80 lines (68 loc) · 2.62 KB
/
Copy pathcompute_contexts.go
File metadata and controls
80 lines (68 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package viya
import (
"context"
"fmt"
"time"
"go.opentelemetry.io/otel/codes"
)
// ComputeContext describes a SAS Viya Compute context definition.
type ComputeContext struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
LaunchType string `json:"launchType"`
QueueName string `json:"queueName"`
LaunchContext map[string]any `json:"launchContext,omitempty"`
Attributes map[string]any `json:"attributes,omitempty"`
MediaTypeMap map[string]string `json:"mediaTypeMap,omitempty"`
Resources []ComputeExternalResource `json:"resources,omitempty"`
Environment *ComputeEnvironment `json:"environment,omitempty"`
CreatedBy string `json:"createdBy"`
CreationTime time.Time `json:"creationTimeStamp"`
ModifiedBy string `json:"modifiedBy"`
ModifiedTime time.Time `json:"modifiedTimeStamp"`
Version int `json:"version"`
Links []Link `json:"links"`
}
// ComputeContextsResponse is a collection of SAS Viya Compute contexts.
type ComputeContextsResponse = ListResponse[ComputeContext]
// GetComputeContexts returns available SAS Viya Compute context definitions.
func (c *Client) GetComputeContexts(ctx context.Context) (resp ComputeContextsResponse, err error) {
ctx, span := tracer.Start(ctx, "GetComputeContexts")
defer span.End()
r, err := c.client.R().
SetContext(ctx).
SetHeader("Accept", AcceptCollection).
SetHeader("Accept-Item", "application/vnd.sas.compute.context+json").
SetResult(&resp).
Get("/compute/contexts")
if err != nil {
return resp, err
}
if !r.IsSuccess() {
span.SetStatus(codes.Error, r.String())
return resp, fmt.Errorf("failed to get compute contexts, status code: %d", r.StatusCode())
}
return resp, nil
}
// GetComputeContextInfo returns a single SAS Viya Compute context definition.
func (c *Client) GetComputeContextInfo(ctx context.Context, contextID string) (resp ComputeContext, err error) {
if contextID == "" {
return resp, &ErrInvalidParameter{Parameter: "contextID", Reason: "must not be empty"}
}
ctx, span := tracer.Start(ctx, "GetComputeContextInfo")
defer span.End()
r, err := c.client.R().
SetContext(ctx).
SetHeader("Accept", AcceptComputeContext).
SetResult(&resp).
Get(fmt.Sprintf("/compute/contexts/%s", contextID))
if err != nil {
return resp, err
}
if !r.IsSuccess() {
span.SetStatus(codes.Error, r.String())
return resp, fmt.Errorf("failed to get compute context info, status code: %d", r.StatusCode())
}
return resp, nil
}