Skip to content

Commit 9c7b5e9

Browse files
committed
add client for cat datafeeds, data frame analytics, and cat fielddata
1 parent c93cb0b commit 9c7b5e9

File tree

4 files changed

+287
-2
lines changed

4 files changed

+287
-2
lines changed

src/nimastic/api/api.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import catmaster, cataliases, catallocation, catanomalydetectors, catcount
2-
1+
import catmaster, cataliases, catallocation, catanomalydetectors, catcount,
2+
catdataframeanalytics, catdatafeeds, catfielddata
33
type
44
elasticsearch* = object
55
CatMaster* : catMaster
66
CatAliases*: catAliases
77
CatAllocation*: catAllocation
88
CatAnomalyDitectors*: catAnomalyDitectors
99
CatCount*: catCount
10+
CatDataFrameAnalytics*: catDataFrameAnalytics
11+
CatDatafeeds*: catDatafeeds
12+
CatFieldData*: catFieldData
13+
1014

src/nimastic/api/catdatafeeds.nim

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import strutils, httpclient
2+
import ../transport
3+
4+
type
5+
catDatafeeds* = object
6+
FeedId*: string
7+
#query
8+
AllowNoMatch*: bool
9+
Format*: string
10+
H*: seq[string]
11+
Help*: bool
12+
S*: seq[string]
13+
Time*: string
14+
V*: bool
15+
16+
const ValidCollumn: seq[string] = @["assignment_explanation", "ae",
17+
"buckets.count", "bc", "bucketsCount",
18+
"id",
19+
"node.address", "na", "nodeAddress",
20+
"node.ephemeral_id", "ne", "nodeEphemeralId",
21+
"node.id", "ni", "nodeId",
22+
"node.name", "nn", "nodeName",
23+
"search.bucket_avg", "sba", "searchBucketAvg",
24+
"search.bucket_avg", "sba", "searchBucketAvg",
25+
"search.exp_avg_hour", "seah", "searchExpAvgHour",
26+
"search.time", "st", "searchTime",
27+
"state", "s"]
28+
29+
# check value in column valid or not
30+
proc checkValidColumn(h: seq[string]): bool =
31+
32+
var valid: bool
33+
34+
block checkH:
35+
for i, val in h.pairs:
36+
37+
var match: bool = false
38+
39+
block checkColumn:
40+
for j, k in ValidCollumn.pairs:
41+
if val == k :
42+
match = true
43+
break checkColumn
44+
45+
if match :
46+
valid = true
47+
else :
48+
valid = false
49+
break checkH
50+
51+
return valid
52+
53+
54+
method Do*(this: catDatafeeds, c: var elClient ) : Response {.base.} =
55+
56+
var q = ""
57+
58+
if this.Format != "":
59+
case this.Format:
60+
of "text": q.add("format=text")
61+
of "json": q.add("format=json")
62+
of "smile": q.add("format=smile")
63+
of "yaml": q.add("format=yaml")
64+
of "cbor": q.add("format=cbor")
65+
else:
66+
echo "not found format " & this.Format
67+
68+
if this.AllowNoMatch :
69+
q.add("&allow_no_match")
70+
71+
if len(this.H) > 0 :
72+
73+
let valid = checkValidColumn(this.H)
74+
if valid :
75+
let hStr = join(this.H, ",")
76+
q.add("&h=" & hStr)
77+
78+
if this.Help :
79+
q.add("&help")
80+
81+
if len(this.S) > 0 :
82+
let sStr = join(this.S, ",")
83+
q.add("&s=" & sStr)
84+
85+
if this.V :
86+
q.add("&v")
87+
88+
if this.Time != "":
89+
case this.Time:
90+
of "d": q.add("&time=d")
91+
of "h": q.add("&time=h")
92+
of "m": q.add("&time=m")
93+
of "s": q.add("&time=s")
94+
of "ms": q.add("&time=ms")
95+
of "micros": q.add("&time=micros")
96+
of "nanos": q.add("&time=nanos")
97+
else:
98+
echo "not found time " & this.Time
99+
100+
# add query to elasticsearch.Query
101+
c.Query = q
102+
# add method to elasticsearch.Method
103+
c.Method = HttpGet
104+
c.Endpoint = "/_cat/ml/datafeeds"
105+
106+
if this.FeedId != "" :
107+
c.Endpoint.add("/" & this.FeedId)
108+
109+
return c.estransport()
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import strutils, httpclient
2+
import ../transport
3+
4+
type
5+
catDataFrameAnalytics* = object
6+
DataFrameAnalyticsId*: string
7+
#query
8+
Format*: string
9+
H*: seq[string]
10+
Help*: bool
11+
S*: seq[string]
12+
Time*: string
13+
V*: bool
14+
15+
const ValidCollumn: seq[string] = @["assignment_explanation", "ae",
16+
"create_time", "ct", "createTime",
17+
"description", "d",
18+
"dest_index", "di", "destIndex",
19+
"failure_reason", "fr", "failureReason",
20+
"id",
21+
"model_memory_limit", "mml", "modelMemoryLimit",
22+
"node.address", "na", "nodeAddress",
23+
"node.ephemeral_id", "ne", "nodeEphemeralId",
24+
"node.id", "ni", "nodeId",
25+
"node.name", "nn", "nodeName",
26+
"progress", "p",
27+
"source_index", "si", "sourceIndex",
28+
"state", "s",
29+
"type", "t",
30+
"version", "v"]
31+
32+
# check value in column valid or not
33+
proc checkValidColumn(h: seq[string]): bool =
34+
35+
var valid: bool
36+
37+
block checkH:
38+
for i, val in h.pairs:
39+
40+
var match: bool = false
41+
42+
block checkColumn:
43+
for j, k in ValidCollumn.pairs:
44+
if val == k :
45+
match = true
46+
break checkColumn
47+
48+
if match :
49+
valid = true
50+
else :
51+
valid = false
52+
break checkH
53+
54+
return valid
55+
56+
method Do*(this: catDataFrameAnalytics, c: var elClient): Response {.base.} =
57+
58+
var q = ""
59+
60+
if this.Format != "":
61+
case this.Format:
62+
of "text": q.add("format=text")
63+
of "json": q.add("format=json")
64+
of "smile": q.add("format=smile")
65+
of "yaml": q.add("format=yaml")
66+
of "cbor": q.add("format=cbor")
67+
else:
68+
echo "not found format " & this.Format
69+
70+
if len(this.H) > 0 :
71+
72+
let valid = checkValidColumn(this.H)
73+
if valid :
74+
let hStr = join(this.H, ",")
75+
q.add("&h=" & hStr)
76+
77+
if this.Help :
78+
q.add("&help")
79+
80+
if len(this.S) > 0 :
81+
let sStr = join(this.S, ",")
82+
q.add("&s=" & sStr)
83+
84+
if this.V :
85+
q.add("&v")
86+
87+
if this.Time != "":
88+
case this.Time:
89+
of "d": q.add("&time=d")
90+
of "h": q.add("&time=h")
91+
of "m": q.add("&time=m")
92+
of "s": q.add("&time=s")
93+
of "ms": q.add("&time=ms")
94+
of "micros": q.add("&time=micros")
95+
of "nanos": q.add("&time=nanos")
96+
else:
97+
echo "not found time " & this.Time
98+
99+
# add query to elasticsearch.Query
100+
c.Query = q
101+
# add method to elasticsearch.Method
102+
c.Method = HttpGet
103+
c.Endpoint = "/_cat/ml/data_frame/analytics"
104+
105+
if this.DataFrameAnalyticsId != "" :
106+
c.Endpoint.add("/" & this.DataFrameAnalyticsId)
107+
108+
return c.estransport()

src/nimastic/api/catfielddata.nim

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import strutils, httpclient
2+
import ../transport
3+
4+
type
5+
catFieldData* = object
6+
Field*: string
7+
#query
8+
Format*: string
9+
Bytes*: string
10+
H*: seq[string]
11+
Help*: bool
12+
S*: seq[string]
13+
V*: bool
14+
15+
16+
method Do*(this: catFieldData, c: var elClient): Response {.base.} =
17+
var q = ""
18+
19+
if this.Format != "":
20+
case this.Format:
21+
of "text": q.add("format=text")
22+
of "json": q.add("format=json")
23+
of "smile": q.add("format=smile")
24+
of "yaml": q.add("format=yaml")
25+
of "cbor": q.add("format=cbor")
26+
else:
27+
echo "not found format " & this.Format
28+
29+
if this.Bytes != "":
30+
case this.Bytes:
31+
of "b": q.add("&bytes=b")
32+
of "kb": q.add("&bytes=kb")
33+
of "mb": q.add("&bytes=mb")
34+
of "gb": q.add("&bytes=gb")
35+
of "tb": q.add("&bytes=tb")
36+
of "pb": q.add("&bytes=pb")
37+
else:
38+
echo "not found"
39+
#add exeption in logger
40+
41+
if len(this.H) > 0 :
42+
let hStr = join(this.H, ",")
43+
q.add("&h=" & hStr)
44+
45+
if this.Help :
46+
q.add("&help")
47+
48+
if len(this.S) > 0 :
49+
let sStr = join(this.S, ",")
50+
q.add("&s=" & sStr)
51+
52+
if this.V :
53+
q.add("&v")
54+
55+
# add query to elasticsearch.Query
56+
c.Query = q
57+
# add method to elasticsearch.Method
58+
c.Method = HttpGet
59+
c.Endpoint = "/_cat/fielddata"
60+
61+
if this.Field != "" :
62+
c.Endpoint.add("/" & this.Field)
63+
64+
return c.estransport()

0 commit comments

Comments
 (0)