-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_contexts.go
More file actions
88 lines (77 loc) · 2.86 KB
/
Copy pathbatch_contexts.go
File metadata and controls
88 lines (77 loc) · 2.86 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
81
82
83
84
85
86
87
88
// Package viya provides a client library for selected SAS Viya REST APIs,
// including authentication, identities, configuration, batch, CAS, files,
// compute, and job execution.
package viya
import (
"context"
"fmt"
"time"
"go.opentelemetry.io/otel/codes"
)
// SAS Viya Batch API reference:
// https://developer.sas.com/rest-apis/batch
// BatchContext describes a SAS Viya Batch execution context.
//
// A context defines how batch jobs are launched, including queue, resource,
// server, and SAS option settings.
type BatchContext struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
State string `json:"state"`
CreatedBy string `json:"createdBy"`
CreationTimeStamp time.Time `json:"creationTimeStamp"`
IsMultiServer bool `json:"isMultiServer"`
LauncherContextID string `json:"launcherContextId"`
MaxServers int `json:"maxServers"`
MinServers int `json:"minServers"`
ModifiedBy string `json:"modifiedBy"`
ModifiedTimeStamp time.Time `json:"modifiedTimeStamp"`
ProviderOptions string `json:"providerOptions"`
QueueName string `json:"queueName"`
RequiredResources string `json:"requiredResources"`
RunServerAs string `json:"runServerAs"`
SASOptions string `json:"sasOptions"`
ServerTimeout int `json:"serverTimeout"`
Version int `json:"version"`
Links []Link `json:"links"`
}
// BatchContextsResponse is a collection of SAS Viya Batch contexts.
type BatchContextsResponse = ListResponse[BatchContext]
// GetBatchContexts returns the available SAS Viya Batch execution contexts.
func (c *Client) GetBatchContexts(ctx context.Context) (resp BatchContextsResponse, err error) {
ctx, span := tracer.Start(ctx, "GetBatchContexts")
defer span.End()
r, err := c.client.R().
SetHeader("Accept", AcceptCollection).
SetContext(ctx).
SetResult(&resp).
Get("/batch/contexts")
if err != nil {
return resp, err
}
if !r.IsStatusSuccess() {
span.SetStatus(codes.Error, r.String())
return resp, fmt.Errorf("failed to get batch contexts, status code: %d", r.StatusCode())
}
return resp, nil
}
// GetBatchContextByName returns a SAS Viya Batch execution context by name.
func (c *Client) GetBatchContextByName(ctx context.Context, name string) (resp BatchContext, err error) {
ctx, span := tracer.Start(ctx, "GetBatchContextByName")
defer span.End()
r, err := c.client.R().
SetHeader("Accept", AcceptBatchContext).
SetContext(ctx).
SetQueryParam("name", name).
SetResult(&resp).
Get("/batch/contexts/@item")
if err != nil {
return resp, err
}
if !r.IsStatusSuccess() {
span.SetStatus(codes.Error, r.String())
return resp, fmt.Errorf("failed to get batch context by name, status code: %d", r.StatusCode())
}
return resp, nil
}