Skip to content

Commit b13b4e9

Browse files
committed
add client for cluster health and cluster get settings
1 parent 38abbeb commit b13b4e9

File tree

5 files changed

+152
-5
lines changed

5 files changed

+152
-5
lines changed

src/nimastic.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import nimastic/transport
22
import nimastic/api/[api, catmaster, cataliases, catallocation, catanomalydetectors, catdataframeanalytics,
33
catcount, catdatafeeds, cathealth, catfielddata, catindices, catnodeattrs, catnodes, catpendingtasks,
44
catplugins, catrecovery, catrepositories, catsegments, catsnapshots, cattasks, cattemplates,catthreadpool,
5-
cattrainedmodels, cattransforms, clusterallocationexplain]
5+
cattrainedmodels, cattransforms, clusterallocationexplain, clustergetsettings, clusterhealth]
66

77
export transport
88
export api, catmaster, cataliases, catallocation, catanomalydetectors, catdataframeanalytics,
99
catcount, catDatafeeds, cathealth, catfielddata, catindices, catnodeattrs, catnodes, catpendingtasks,
1010
catplugins, catrecovery, catrepositories, catsegments, catsnapshots, cattasks, cattemplates, catthreadpool,
11-
cattrainedmodels, cattransforms, clusterallocationexplain
11+
cattrainedmodels, cattransforms, clusterallocationexplain, clustergetsettings, clusterhealth

src/nimastic/api/api.nim

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import catmaster, cataliases, catallocation, catanomalydetectors, catcount,
22
catdataframeanalytics, catdatafeeds, catfielddata, cathealth, catindices,
33
catnodeattrs, catnodes, catpendingtasks, catplugins, catrecovery, catrepositories,
44
catshards, catsegments, catsnapshots, cattasks, cattemplates, catthreadpool,
5-
cattrainedmodels, cattransforms, clusterallocationexplain
5+
cattrainedmodels, cattransforms, clusterallocationexplain, clustergetsettings,
6+
clusterhealth
67

78
type
89
elasticsearch* = object
@@ -30,4 +31,6 @@ type
3031
CatThreadPool*: catThreadPool
3132
CatTrainedModels*: catTrainedModels
3233
CatTransforms*: catTransforms
33-
ClusterAllocationExplain*: clusterAllocationExplain
34+
ClusterAllocationExplain*: clusterAllocationExplain
35+
ClusterGetSettings*: clusterGetSettings
36+
ClusterHealth*: clusterHealth

src/nimastic/api/clusterallocationexplain.nim

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import httpclient, json
1+
import strutils, httpclient, json
22
import ../transport
33

44
type
@@ -12,6 +12,11 @@ type
1212
Primary*: bool
1313
Shard*: int
1414

15+
Pretty*: bool
16+
Human*: bool
17+
ErrorTrace*: bool
18+
FilterPath*: seq[string]
19+
1520
method Do*( c: var elClient, this: clusterAllocationExplain ): Response {.base.} =
1621

1722
var q = ""
@@ -36,6 +41,18 @@ method Do*( c: var elClient, this: clusterAllocationExplain ): Response {.base.}
3641

3742
body["shard"] = %* this.Shard
3843

44+
if this.Pretty :
45+
q.add("&pretty")
46+
47+
if this.Human :
48+
q.add("&human")
49+
50+
if this.ErrorTrace :
51+
q.add("&error_trace")
52+
53+
if len(this.FilterPath) > 0 :
54+
q.add("&filter_path=" & join(this.FilterPath, ",") )
55+
3956
c.Query = q
4057
c.Body = $body
4158
c.Method = HttpGet
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import strutils, httpclient
2+
import ../transport
3+
4+
type
5+
clusterGetSettings* = object
6+
#query
7+
FlatSettings*: bool
8+
IncludeDefaults*: bool
9+
MasterTimeout*: string
10+
Timeout*: string
11+
12+
Pretty*: bool
13+
Human*: bool
14+
ErrorTrace*: bool
15+
FilterPath*: seq[string]
16+
17+
method Do*(c: var elClient, this: clusterGetSettings ): Response {.base.} =
18+
19+
var q = ""
20+
21+
if this.FlatSettings :
22+
q.add("flat_settings")
23+
24+
if this.IncludeDefaults :
25+
q.add("&include_defaults")
26+
27+
if this.MasterTimeout != "" :
28+
q.add("&master_timeout=" & this.MasterTimeout)
29+
30+
if this.Timeout != "" :
31+
q.add("&timeout=" & this.Timeout)
32+
33+
if this.Pretty :
34+
q.add("&pretty")
35+
36+
if this.Human :
37+
q.add("&human")
38+
39+
if this.ErrorTrace :
40+
q.add("&error_trace")
41+
42+
if len(this.FilterPath) > 0 :
43+
q.add("&filter_path=" & join(this.FilterPath, ",") )
44+
45+
c.Query = q
46+
c.Method = HttpGet
47+
c.Endpoint = "/_cluster/settings"
48+
49+
return c.estransport()

src/nimastic/api/clusterhealth.nim

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import strutils, httpclient
2+
import ../transport
3+
4+
type
5+
clusterHealth* = object
6+
Target*: seq[string]
7+
#query
8+
Level*: string
9+
Local*: bool
10+
MasterTimeout*: string
11+
Timeout*: string
12+
WaitForActiveShards*: string
13+
WaitForEvents*: string
14+
WaitForNoInitializingShards*: bool
15+
WaitForNoRelocatingShards*: bool
16+
WaitForNodes*: string
17+
WaitForStatus*: string
18+
19+
Pretty*: bool
20+
Human*: bool
21+
ErrorTrace*: bool
22+
FilterPath*: seq[string]
23+
24+
25+
method Do*(c: var elClient, this: clusterHealth): Response {.base.} =
26+
27+
var q = ""
28+
29+
if this.Level != "" :
30+
q.add("level=" & this.Level)
31+
32+
if this.Local :
33+
q.add("&local")
34+
35+
if this.MasterTimeout != "" :
36+
q.add("&master_timeout=" & this.MasterTimeout)
37+
38+
if this.Timeout != "" :
39+
q.add("&timeout=" & this.Timeout)
40+
41+
if this.WaitForActiveShards != "" :
42+
q.add("&wait_for_active_shards=" & this.WaitForActiveShards)
43+
44+
if this.WaitForEvents != "" :
45+
q.add("&wait_for_events=" & this.WaitForEvents)
46+
47+
if this.WaitForNoInitializingShards :
48+
q.add("&wait_for_no_initializing_shards")
49+
50+
if this.WaitForNoRelocatingShards :
51+
q.add("&wait_for_no_relocating_shards")
52+
53+
if this.WaitForNodes != "" :
54+
q.add("&wait_for_nodes=" & this.WaitForNodes)
55+
56+
if this.WaitForStatus != "" :
57+
q.add("&wait_for_status=" & this.WaitForStatus)
58+
59+
if this.Pretty :
60+
q.add("&pretty")
61+
62+
if this.Human :
63+
q.add("&human")
64+
65+
if this.ErrorTrace :
66+
q.add("&error_trace")
67+
68+
if len(this.FilterPath) > 0 :
69+
q.add("&filter_path=" & join(this.FilterPath, ",") )
70+
71+
c.Query = q
72+
c.Method = HttpGet
73+
c.Endpoint = "/_cluster/health/"
74+
75+
if len(this.Target) > 0 :
76+
c.Endpoint.add("/" & join(this.Target, ","))
77+
78+
return c.estransport()

0 commit comments

Comments
 (0)