Skip to content

Commit

Permalink
cluster: fix topology validation
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroProfundis committed Jul 10, 2020
1 parent 782b4d2 commit 2c4f7a9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
3 changes: 2 additions & 1 deletion components/cluster/command/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ You can retain some nodes and roles data when destroy cluster, eg:

logger.EnableAuditLog()
metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
perrs.Cause(err) != spec.ErrNoTiSparkMaster {
return err
}

Expand Down
12 changes: 8 additions & 4 deletions components/cluster/command/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func newDisplayCmd() *cobra.Command {
}

metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
perrs.Cause(err) != spec.ErrNoTiSparkMaster {
return perrs.AddStack(err)
}
return destroyTombstoneIfNeed(clusterName, metadata, gOpt)
Expand All @@ -88,7 +89,8 @@ func newDisplayCmd() *cobra.Command {

func displayDashboardInfo(clusterName string) error {
metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
perrs.Cause(err) != spec.ErrNoTiSparkMaster {
return err
}

Expand Down Expand Up @@ -121,7 +123,8 @@ func displayDashboardInfo(clusterName string) error {

func displayClusterMeta(clusterName string, opt *operator.Options) error {
clsMeta, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
perrs.Cause(err) != spec.ErrNoTiSparkMaster {
return err
}

Expand Down Expand Up @@ -175,7 +178,8 @@ func destroyTombstoneIfNeed(clusterName string, metadata *spec.ClusterMeta, opt

func displayClusterTopology(clusterName string, opt *operator.Options) error {
metadata, err := spec.ClusterMetadata(clusterName)
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) {
if err != nil && !errors.Is(perrs.Cause(err), meta.ErrValidate) &&
perrs.Cause(err) != spec.ErrNoTiSparkMaster {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion components/cluster/command/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func scaleOut(clusterName, topoFile string, opt scaleOutOptions) error {
MonitoredOptions: metadata.Topology.MonitoredOptions,
ServerConfigs: metadata.Topology.ServerConfigs,
}
if err := clusterutil.ParseTopologyYaml(topoFile, &newPart); err != nil {
if err := clusterutil.ParseTopologyYaml(topoFile, &newPart); err != nil && errors.Cause(err) != spec.ErrNoTiSparkMaster {
return err
}

Expand Down
12 changes: 7 additions & 5 deletions pkg/cluster/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ const (

// general role names
var (
RoleMonitor = "monitor"
RoleTiSparkMaster = "tispark-master"
RoleTiSparkWorker = "tispark-worker"
RoleMonitor = "monitor"
RoleTiSparkMaster = "tispark-master"
RoleTiSparkWorker = "tispark-worker"
ErrNoTiSparkMaster = errors.New("There must be a Spark master node if you want to use the TiSpark component")
ErrMultipleTiSparkMaster = errors.New("TiSpark enabled cluster with more than 1 Spark master node is not supported")
)

type (
Expand Down Expand Up @@ -507,12 +509,12 @@ func (s *Specification) validateTiSparkSpec() error {
if s.TiSparkWorkers == nil || len(s.TiSparkWorkers) == 0 {
return nil
}
return errors.New("There must be a Spark master node if you want to use the TiSpark component")
return ErrNoTiSparkMaster
}

// We only support 1 spark master at present
if s.TiSparkMasters != nil && len(s.TiSparkMasters) > 1 {
return errors.New("TiSpark enabled cluster with more than 1 Spark master node is not supported")
return ErrMultipleTiSparkMaster
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/spec/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func ClusterMetadata(clusterName string) (*ClusterMeta, error) {
var cm ClusterMeta
err := GetSpecManager().Metadata(clusterName, &cm)
if err != nil {
return nil, errors.AddStack(err)
return &cm, errors.AddStack(err)
}

return &cm, nil
Expand Down
2 changes: 1 addition & 1 deletion tests/tiup-cluster/script/cmd_subtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ function cmd_subtest() {

echo "start scale in tispark"
yes | tiup-cluster --yes scale-in $name -N 172.19.0.104:7078
wait_instance_num_reach $name $total_sub_one
echo "start scale out tispark"
yes | tiup-cluster --yes scale-out $name ./topo/full_scale_in_tispark.yaml
wait_instance_num_reach $name $total_sub_one

echo "start scale in grafana"
tiup-cluster --yes scale-in $name -N 172.19.0.101:3000
Expand Down

0 comments on commit 2c4f7a9

Please sign in to comment.