-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceDetails.go
127 lines (104 loc) · 4.36 KB
/
serviceDetails.go
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
ESRI REST API implementation library.
ServiceDetails function.
DetailsJSON and properties structs can be enriched with values found in server doc at
https://developers.arcgis.com/rest/enterprise-administration/server/service.htm
when with Enterprise a more complete description can be found here:
https://developers.arcgis.com/rest/enterprise-administration/enterprise/service.htm title is kubernetes but seems compatible
*/
package go_esri
import (
"encoding/json"
"net/url"
"github.com/go-resty/resty/v2"
)
type sProperties struct {
PortalURL string `json:"portalURL"`
VirtualOutputDir string `json:"virtualOutputDir"`
MaxImageHeight string `json:"maxImageHeight"`
MaxRecordCount string `json:"maxRecordCount"`
MaxScale string `json:"maxScale"`
MinScale string `json:"minScale"`
FilePath string `json:"filePath"`
CacheOnDemand string `json:"cacheOnDemand"`
}
type sframeworkProp struct {
ServiceHeapSize string `json:"javaHeapSize"`
}
type sdataSource struct {
SourceName string `json:"name"`
}
type sdataBase struct {
DataSource sdataSource `json:"datasource"`
}
type sadminServiceInfo struct {
PropertiesType string `json:"type"`
PropertiesStatus string `json:"status"`
PropertiesName string `json:"name"`
DataBase sdataBase `json:"database"`
}
type sjsonProperties struct {
PropertiesAllowGeoUpdate bool `json:"allowGeometryUpdates"`
AdminServiceInfo sadminServiceInfo `json:"adminServiceInfo"`
MaxViewsCount int32 `json:"maxViewsCount"`
SyncEnabled bool `json:"syncEnabled"`
HasVersionedData bool `json:"hasVersionedData"`
}
// struct returned by services call
type detailsJSON struct {
ServiceType string `json:"type"`
ServiceDescription string `json:"description"`
ServiceCapabilities string `json:"capabilities"`
ServiceClusterName string `json:"clusterName"`
ServiceConfiguredState string `json:"configuredState"`
ServiceMinInstPerNode int32 `json:"minInstancesPerNode"`
ServiceMaxInstPerNode int32 `json:"maxInstancesPerNode"`
ServiceMaxWaitTime int32 `json:"maxWaitTime"`
ServiceMaxIdelTime int32 `json:"maxIdleTime"`
ServiceMaxUsageTime int32 `json:"maxUsageTime"`
ServiceRecycleInterval int32 `json:"recycleInterval"`
ServiceRecycleStartTime string `json:"recycleStartTime"`
ServiceMaxViewsCount int32 `json:"maxViewsCount"`
ServiceProvider string `json:"provider"`
ServiceLoadBalancing string `json:"loadBalancing"`
ServiceKeepAliveInterval int32 `json:"keepAliveInterval"`
ServiceIsolationLevel string `json:"isolationLevel"`
ServicehasVersionedData bool `json:"hasVersionedData"`
ServiceSyncEnabled bool `json:"syncEnabled"`
ServiceInstancesPerContainer int32 `json:"instancesPerContainer"`
ServiceMaxUploadFileSize int32 `json:"maxUploadFileSize"`
ServiceProperties sProperties `json:"properties"`
ServiceJsonProperties sjsonProperties `json:"jsonProperties"`
ServiceFramework sframeworkProp `json:"frameworkProperties"`
}
// Returns DetailsJSON struct with service info
func ServiceDetails(token, serverName, folder, serviceFullName string) (*detailsJSON, error) {
// ----------------------------------------- build and validate url
baseUrl, err := url.Parse(serverName)
if err != nil {
return nil, err
}
baseUrl.Path += "/admin/services/"
baseUrl.Path += folder + "/"
baseUrl.Path += serviceFullName
// ----------------------------------------- build url encode string to be included in the header body
v := url.Values{}
v.Set("token", token)
v.Add("f", "json")
// ----------------------------------------- request
req := resty.New()
resp, err := req.R().
SetHeader("Content-type", "application/x-www-form-urlencoded").
SetBody(string(v.Encode())).
Post(baseUrl.String())
if err != nil {
return nil, err
}
// ----------------------------------------- decode json response
var obj detailsJSON
err = json.Unmarshal(resp.Body(), &obj)
if err != nil {
return nil, err
}
return &obj, nil
}