mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 06:34:18 +02:00
check at bootstrap which cluster is reachable, fix current cluster
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -3,3 +3,5 @@
|
|||||||
|
|
||||||
- Fix index names custom completion
|
- Fix index names custom completion
|
||||||
- add cluster default <name> which would add a flag to the config, so that no -C is needed subsequently
|
- add cluster default <name> which would add a flag to the config, so that no -C is needed subsequently
|
||||||
|
- add `cluster stats` from `/_cluster/stats` like mem, procs, open files, num indices, shards etc
|
||||||
|
- add version[s] to `cluster status`
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -76,6 +77,8 @@ func (conf *Config) Init() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conf.SetupES()
|
||||||
|
|
||||||
if conf.CurrentCluster != "" {
|
if conf.CurrentCluster != "" {
|
||||||
current, exists := conf.Clusters[conf.CurrentCluster]
|
current, exists := conf.Clusters[conf.CurrentCluster]
|
||||||
if !exists {
|
if !exists {
|
||||||
@@ -83,14 +86,29 @@ func (conf *Config) Init() error {
|
|||||||
} else {
|
} else {
|
||||||
conf.DefaultCluster = current
|
conf.DefaultCluster = current
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if len(conf.Clusters) == 1 {
|
||||||
|
for _, cluster := range conf.Clusters {
|
||||||
|
conf.DefaultCluster = cluster
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for _, cluster := range conf.Clusters {
|
||||||
|
_, err := cluster.ES.Cluster.Health().
|
||||||
|
Header("content-type", "application/json").
|
||||||
|
Header("accept", "application/json").
|
||||||
|
Do(context.Background())
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
conf.DefaultCluster = cluster
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.Debug {
|
if conf.Debug {
|
||||||
repr.Println(conf)
|
repr.Println(conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
conf.SetupES()
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,12 +75,24 @@ func ClusterCompare(conf *cfg.Config, leader, follower string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ClusterList(conf *cfg.Config) error {
|
func ClusterList(conf *cfg.Config) error {
|
||||||
table := NewTable(2, len(conf.Clusters))
|
table := NewTable(3, len(conf.Clusters))
|
||||||
table.Addheaders("cluster", "uri")
|
|
||||||
|
table.Addheaders("cluster", "uri", "default")
|
||||||
|
|
||||||
idx := 0
|
idx := 0
|
||||||
for name, cluster := range conf.Clusters {
|
for name, cluster := range conf.Clusters {
|
||||||
table.entries[idx] = []string{name, cluster.Uri}
|
current := name == "default" || name == conf.CurrentCluster
|
||||||
|
|
||||||
|
_, err := cluster.ES.Cluster.Health().
|
||||||
|
Header("content-type", "application/json").
|
||||||
|
Header("accept", "application/json").
|
||||||
|
Do(context.Background())
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
name = Colorize("green", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
table.entries[idx] = []string{name, cluster.Uri, fmt.Sprintf("%t", current)}
|
||||||
idx++
|
idx++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user