Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 15, 2025. It is now read-only.
/vulcanizerPublic archive

Commitfc21e7f

Browse files
committed
Add new method and tests for ClusterAllocationExplainWithQueryParams
1 parentdf49acb commitfc21e7f

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

‎es.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,30 @@ func (c *Client) ClusterAllocationExplain(req *ClusterAllocationExplainRequest,
16881688
returnstring(body),nil
16891689
}
16901690

1691+
// ClusterAllocationExplainWithQueryParams provides an explanation for a shard’s current allocation with optional query parameters.
1692+
// For more info, please check https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-allocation-explain.html
1693+
func (c*Client)ClusterAllocationExplainWithQueryParams(req*ClusterAllocationExplainRequest,paramsmap[string]string) (string,error) {
1694+
uri:="_cluster/allocation/explain"
1695+
queryStrings:= []string{}
1696+
forparam,val:=rangeparams {
1697+
queryStrings=append(queryStrings,fmt.Sprintf("%s=%s",param,val))
1698+
}
1699+
1700+
uri=fmt.Sprintf("%s?%s",uri,strings.Join(queryStrings,"&"))
1701+
1702+
agent:=c.buildGetRequest(uri)
1703+
ifreq!=nil {
1704+
agent.Set("Content-Type","application/json").Send(req)
1705+
}
1706+
1707+
body,err:=handleErrWithBytes(agent)
1708+
iferr!=nil {
1709+
return"",err
1710+
}
1711+
1712+
returnstring(body),nil
1713+
}
1714+
16911715
typeRerouteRequeststruct {
16921716
// The commands to perform (move, cancel, allocate, etc)
16931717
Commands []RerouteCommand`json:"commands,omitempty"`

‎es_test.go‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,105 @@ func TestClusterAllocationExplain(t *testing.T) {
22112211
}
22122212
}
22132213

2214+
funcTestClusterAllocationExplainWithQueryParams(t*testing.T) {
2215+
shardID:=0
2216+
tests:= []struct {
2217+
namestring
2218+
request*ClusterAllocationExplainRequest
2219+
paramsmap[string]string
2220+
expectedBodystring
2221+
}{
2222+
{
2223+
name:"with nil request",
2224+
request:nil,
2225+
expectedBody:"",
2226+
params:map[string]string{},
2227+
},
2228+
{
2229+
name:"with current_node set",
2230+
request:&ClusterAllocationExplainRequest{
2231+
CurrentNode:"test-node",
2232+
},
2233+
expectedBody:`{"current_node":"test-node"}`,
2234+
params:map[string]string{},
2235+
},
2236+
{
2237+
name:"with index set",
2238+
request:&ClusterAllocationExplainRequest{
2239+
Index:"test-index",
2240+
},
2241+
expectedBody:`{"index":"test-index"}`,
2242+
params:map[string]string{},
2243+
},
2244+
{
2245+
name:"with primary set",
2246+
request:&ClusterAllocationExplainRequest{
2247+
Primary:true,
2248+
},
2249+
expectedBody:`{"primary":true}`,
2250+
params:map[string]string{},
2251+
},
2252+
{
2253+
name:"with shard set",
2254+
request:&ClusterAllocationExplainRequest{
2255+
Shard:&shardID,
2256+
},
2257+
expectedBody:`{"shard":0}`,
2258+
params:map[string]string{},
2259+
},
2260+
{
2261+
name:"with pretty param",
2262+
request:nil,
2263+
params:map[string]string{
2264+
"pretty":"true",
2265+
},
2266+
},
2267+
{
2268+
name:"with multiple params",
2269+
request:nil,
2270+
params:map[string]string{
2271+
"pretty":"true",
2272+
"include_disk_info":"true",
2273+
"include_yes_decisions":"true",
2274+
},
2275+
},
2276+
}
2277+
2278+
for_,tt:=rangetests {
2279+
tc:=tt
2280+
t.Run(tc.name,func(t*testing.T) {
2281+
testSetup:=&ServerSetup{
2282+
Method:"GET",
2283+
Path:"/_cluster/allocation/explain",
2284+
Body:tc.expectedBody,
2285+
}
2286+
2287+
iflen(tc.params)>0 {
2288+
testSetup.extraChecksFn=func(t*testing.T,r*http.Request) {
2289+
vals:=r.URL.Query()
2290+
iflen(vals)!=len(tc.params) {
2291+
t.Errorf("expected %d query params but got %d",len(tc.params),len(vals))
2292+
}
2293+
forparam,val:=rangetc.params {
2294+
ifactual:=vals.Get(param);actual!=val {
2295+
t.Errorf("expected val '%s' for query parameter '%s' but got '%s'",val,param,actual)
2296+
}
2297+
}
2298+
}
2299+
}
2300+
2301+
host,port,ts:=setupTestServers(t, []*ServerSetup{testSetup})
2302+
deferts.Close()
2303+
client:=NewClient(host,port)
2304+
2305+
_,err:=client.ClusterAllocationExplainWithQueryParams(tc.request,tc.params)
2306+
iferr!=nil {
2307+
t.Fatalf("Unexpected error. expected nil, got %s",err)
2308+
}
2309+
})
2310+
}
2311+
}
2312+
22142313
funcTestReroute(t*testing.T) {
22152314
testSetup:=&ServerSetup{
22162315
Method:"POST",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp