github.com/pingcap/tiup@v1.15.1/components/dm/spec/cluster.go (about) 1 // Copyright 2020 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package spec 15 16 import ( 17 "fmt" 18 "path/filepath" 19 "reflect" 20 21 cspec "github.com/pingcap/tiup/pkg/cluster/spec" 22 ) 23 24 var specManager *cspec.SpecManager 25 26 // Metadata is the specification of generic cluster metadata 27 type Metadata struct { 28 User string `yaml:"user"` // the user to run and manage cluster on remote 29 Version string `yaml:"dm_version"` // the version of TiDB cluster 30 // EnableFirewall bool `yaml:"firewall"` 31 32 Topology *Specification `yaml:"topology"` 33 } 34 35 var _ cspec.UpgradableMetadata = &Metadata{} 36 37 // SetVersion implement UpgradableMetadata interface. 38 func (m *Metadata) SetVersion(s string) { 39 m.Version = s 40 } 41 42 // SetUser implement UpgradableMetadata interface. 43 func (m *Metadata) SetUser(s string) { 44 m.User = s 45 } 46 47 // GetTopology implements Metadata interface. 48 func (m *Metadata) GetTopology() cspec.Topology { 49 return m.Topology 50 } 51 52 // SetTopology implements Metadata interface. 53 func (m *Metadata) SetTopology(topo cspec.Topology) { 54 dmTopo, ok := topo.(*Specification) 55 if !ok { 56 panic(fmt.Sprintln("wrong type: ", reflect.TypeOf(topo))) 57 } 58 59 m.Topology = dmTopo 60 } 61 62 // GetBaseMeta implements Metadata interface. 63 func (m *Metadata) GetBaseMeta() *cspec.BaseMeta { 64 return &cspec.BaseMeta{ 65 Version: m.Version, 66 User: m.User, 67 } 68 } 69 70 // GetSpecManager return the spec manager of dm cluster. 71 func GetSpecManager() *cspec.SpecManager { 72 if specManager == nil { 73 specManager = cspec.NewSpec(filepath.Join(cspec.ProfileDir(), cspec.TiUPClusterDir), func() cspec.Metadata { 74 return &Metadata{ 75 Topology: new(Specification), 76 } 77 }) 78 } 79 return specManager 80 }