forked from tikv/pd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
close tikv#6897 Signed-off-by: husharp <[email protected]> Co-authored-by: husharp <[email protected]> Co-authored-by: Hu# <[email protected]>
- Loading branch information
1 parent
9365b94
commit b7396e6
Showing
6 changed files
with
225 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2024 TiKV Project Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package api | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/pingcap/check" | ||
) | ||
|
||
const schedulersPrefix = "/pd/api/v1/schedulers" | ||
|
||
// dialClient used to dial http request. | ||
var dialClient = &http.Client{ | ||
Transport: &http.Transport{ | ||
DisableKeepAlives: true, | ||
}, | ||
} | ||
|
||
// MustAddScheduler adds a scheduler with HTTP API. | ||
func MustAddScheduler( | ||
c *check.C, serverAddr string, | ||
schedulerName string, args map[string]interface{}, | ||
) { | ||
request := map[string]interface{}{ | ||
"name": schedulerName, | ||
} | ||
for arg, val := range args { | ||
request[arg] = val | ||
} | ||
data, err := json.Marshal(request) | ||
c.Assert(err, check.IsNil) | ||
|
||
httpReq, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s%s", serverAddr, schedulersPrefix), bytes.NewBuffer(data)) | ||
c.Assert(err, check.IsNil) | ||
// Send request. | ||
resp, err := dialClient.Do(httpReq) | ||
c.Assert(err, check.IsNil) | ||
defer resp.Body.Close() | ||
_, err = io.ReadAll(resp.Body) | ||
c.Assert(err, check.IsNil) | ||
c.Assert(resp.StatusCode, check.Equals, http.StatusOK) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters