Skip to content

Commit

Permalink
cluster: add GetClusterID() in pdapi (#1573)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored Oct 11, 2021
1 parent 0295c07 commit 75cc31e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/cluster/api/pdapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,29 @@ func (pc *PDClient) GetConfig() (map[string]interface{}, error) {
return flatten.Flatten(pdConfig, "", flatten.DotStyle)
}

// GetClusterID return cluster ID
func (pc *PDClient) GetClusterID() (string, error) {
endpoints := pc.getEndpoints(pdClusterIDURI)

// We don't use the `github.com/tikv/pd/server/config` directly because
// there is compatible issue: https://github.com/pingcap/tiup/issues/637
clusterID := map[string]interface{}{}

_, err := tryURLs(endpoints, func(endpoint string) ([]byte, error) {
body, err := pc.httpClient.Get(context.TODO(), endpoint)
if err != nil {
return body, err
}

return body, json.Unmarshal(body, &clusterID)
})
if err != nil {
return "", err
}

return clusterID["id"].(string), nil
}

// GetDashboardAddress get the PD node address which runs dashboard
func (pc *PDClient) GetDashboardAddress() (string, error) {
cfg, err := pc.GetConfig()
Expand Down

0 comments on commit 75cc31e

Please sign in to comment.