Skip to content

Commit

Permalink
Merge branch 'master' into ngm_default
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored Jan 5, 2022
2 parents b4a54a7 + 99bbe1d commit 9b1282d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/cluster/manager/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (m *Manager) CheckCluster(clusterOrTopoName, scaleoutTopo string, opt Check
topo.MonitoredOptions = currTopo.MonitoredOptions
topo.ServerConfigs = currTopo.ServerConfigs

if err := spec.ParseTopologyYaml(scaleoutTopo, &topo); err != nil {
if err := spec.ParseTopologyYaml(scaleoutTopo, &topo, true); err != nil {
return err
}
spec.ExpandRelativeDir(&topo)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/manager/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (m *Manager) ScaleOut(
// The no tispark master error is ignored, as if the tispark master is removed from the topology
// file for some reason (manual edit, for example), it is still possible to scale-out it to make
// the whole topology back to normal state.
if err := spec.ParseTopologyYaml(topoFile, newPart); err != nil &&
if err := spec.ParseTopologyYaml(topoFile, newPart, true); err != nil &&
!errors.Is(perrs.Cause(err), spec.ErrNoTiSparkMaster) {
return err
}
Expand Down
20 changes: 19 additions & 1 deletion pkg/cluster/spec/parse_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ To generate a sample topology file:
}

// ParseTopologyYaml read yaml content from `file` and unmarshal it to `out`
func ParseTopologyYaml(file string, out Topology) error {
// ignoreGlobal ignore global variables in file, only ignoreGlobal with a index of 0 is effective
func ParseTopologyYaml(file string, out Topology, ignoreGlobal ...bool) error {
suggestionProps := map[string]string{
"File": file,
}
Expand All @@ -68,6 +69,23 @@ func ParseTopologyYaml(file string, out Topology) error {
return err
}

// keep the global config in out
if len(ignoreGlobal) > 0 && ignoreGlobal[0] {
var newTopo map[string]interface{}
if err := yaml.Unmarshal(yamlFile, &newTopo); err != nil {
return err
}
for k := range newTopo {
switch k {
case "global",
"monitored",
"server_configs":
delete(newTopo, k)
}
}
yamlFile, _ = yaml.Marshal(newTopo)
}

if err = yaml.UnmarshalStrict(yamlFile, out); err != nil {
return ErrTopologyParseFailed.
Wrap(err, "Failed to parse topology file %s", file).
Expand Down
10 changes: 10 additions & 0 deletions pkg/cluster/spec/parse_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ func (s *topoSuite) TestParseTopologyYaml(c *check.C) {
c.Assert(err, check.IsNil)
}

func (s *topoSuite) TestParseTopologyYamlIgnoreGlobal(c *check.C) {
file := filepath.Join("testdata", "topology_err.yaml")
topo := Specification{}
err := ParseTopologyYaml(file, &topo, true)
if topo.GlobalOptions.DeployDir == "/tidb/deploy" {
c.Error("Can not ignore global variables")
}
c.Assert(err, check.IsNil)
}

func (s *topoSuite) TestRelativePath(c *check.C) {
// test relative path
withTempFile(`
Expand Down

0 comments on commit 9b1282d

Please sign in to comment.