From 8d9c430b57ee790107e2a09bc5431811d569090c Mon Sep 17 00:00:00 2001 From: caoxianfei1 Date: Wed, 20 Dec 2023 14:06:24 +0800 Subject: [PATCH] Revert "Feature(cluster add): add deploy type parameter" This reverts commit 828680a83c043e26f4b1e28f4498b97331031d99. Signed-off-by: caoxianfei1 --- cli/cli/cli.go | 4 +--- cli/command/cluster/add.go | 26 ++------------------------ cli/command/cluster/import.go | 2 +- cli/command/deploy.go | 1 - internal/errno/errno.go | 5 ++--- internal/storage/sql.go | 13 +++---------- internal/storage/storage.go | 32 +++----------------------------- 7 files changed, 12 insertions(+), 71 deletions(-) diff --git a/cli/cli/cli.go b/cli/cli/cli.go index ba255b050..5882350cd 100644 --- a/cli/cli/cli.go +++ b/cli/cli/cli.go @@ -69,7 +69,6 @@ type CurveAdm struct { clusterName string // current cluster name clusterTopologyData string // cluster topology clusterPoolData string // cluster pool - clusterType string // cluster type like develop, production, etc. monitor storage.Monitor } @@ -196,7 +195,7 @@ func (curveadm *CurveAdm) init() error { curveadm.clusterTopologyData = cluster.Topology curveadm.clusterPoolData = cluster.Pool curveadm.monitor = monitor - curveadm.clusterType = cluster.Type + return nil } @@ -277,7 +276,6 @@ func (curveadm *CurveAdm) ClusterUUId() string { return curveadm.c func (curveadm *CurveAdm) ClusterName() string { return curveadm.clusterName } func (curveadm *CurveAdm) ClusterTopologyData() string { return curveadm.clusterTopologyData } func (curveadm *CurveAdm) ClusterPoolData() string { return curveadm.clusterPoolData } -func (curveadm *CurveAdm) ClusterType() string { return curveadm.clusterType } func (curveadm *CurveAdm) Monitor() storage.Monitor { return curveadm.monitor } func (curveadm *CurveAdm) GetHost(name string) (*hosts.HostConfig, error) { diff --git a/cli/command/cluster/add.go b/cli/command/cluster/add.go index 2504d94de..458f89d06 100644 --- a/cli/command/cluster/add.go +++ b/cli/command/cluster/add.go @@ -47,18 +47,12 @@ var ( CHECK_TOPOLOGY_PLAYBOOK_STEPS = []int{ playbook.CHECK_TOPOLOGY, } - SUPPORTED_DEPLOY_TYPES = []string{ - "production", - "test", - "develop", - } ) type addOptions struct { name string description string filename string - deployType string } func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command { @@ -69,9 +63,6 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command { Short: "Add cluster", Args: utils.ExactArgs(1), Example: ADD_EXAMPLE, - PreRunE: func(cmd *cobra.Command, args []string) error { - return checkAddOptions(cmd) - }, RunE: func(cmd *cobra.Command, args []string) error { options.name = args[0] return runAdd(curveadm, options) @@ -82,7 +73,7 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command { flags := cmd.Flags() flags.StringVarP(&options.description, "description", "m", "", "Description for cluster") flags.StringVarP(&options.filename, "topology", "f", "", "Specify the path of topology file") - flags.StringVar(&options.deployType, "type", "develop", "Specify the type of cluster") + return cmd } @@ -143,19 +134,6 @@ func checkTopology(curveadm *cli.CurveAdm, data string, options addOptions) erro return pb.Run() } -func checkAddOptions(cmd *cobra.Command) error { - deployType, err := cmd.Flags().GetString("deploy-type") - if err != nil { - return err - } - for _, t := range SUPPORTED_DEPLOY_TYPES { - if deployType == t { - return nil - } - } - return errno.ERR_UNSUPPORT_DEPLOY_TYPE.F("deploy type: %s", deployType) -} - func runAdd(curveadm *cli.CurveAdm, options addOptions) error { // 1) check wether cluster already exist name := options.name @@ -185,7 +163,7 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error { // 4) insert cluster (with topology) into database uuid := uuid.NewString() - err = storage.InsertCluster(name, uuid, options.description, data, options.deployType) + err = storage.InsertCluster(name, uuid, options.description, data) if err != nil { return errno.ERR_INSERT_CLUSTER_FAILED.E(err) } diff --git a/cli/command/cluster/import.go b/cli/command/cluster/import.go index e0c4f6b2f..e4f8de0eb 100644 --- a/cli/command/cluster/import.go +++ b/cli/command/cluster/import.go @@ -100,7 +100,7 @@ func importCluster(storage *storage.Storage, dbfile, name string) error { } // insert cluster - err = storage.InsertCluster(name, cluster.UUId, cluster.Description, cluster.Topology, cluster.Type) + err = storage.InsertCluster(name, cluster.UUId, cluster.Description, cluster.Topology) if err != nil { return err } diff --git a/cli/command/deploy.go b/cli/command/deploy.go index 52ab5d3f1..a193d88f3 100644 --- a/cli/command/deploy.go +++ b/cli/command/deploy.go @@ -302,7 +302,6 @@ func displayDeployTitle(curveadm *cli.CurveAdm, dcs []*topology.DeployConfig) { curveadm.WriteOutln("Cluster Name : %s", curveadm.ClusterName()) curveadm.WriteOutln("Cluster Kind : %s", dcs[0].GetKind()) curveadm.WriteOutln("Cluster Services: %s", serviceStats(dcs)) - curveadm.WriteOutln("Cluster Type : %s", curveadm.ClusterType()) curveadm.WriteOutln("") } diff --git a/internal/errno/errno.go b/internal/errno/errno.go index 74c5f3b6b..2b6ec0ca7 100644 --- a/internal/errno/errno.go +++ b/internal/errno/errno.go @@ -254,9 +254,8 @@ var ( ERR_NO_SERVICES_MATCHED = EC(210006, "no services matched") // TODO: please check pool set disk type ERR_INVALID_DISK_TYPE = EC(210007, "poolset disk type must be lowercase and can only be one of ssd, hdd and nvme") - ERR_UNSUPPORT_DEPLOY_TYPE = EC(210008, "unknown deploy type") - ERR_NO_LEADER_OR_RANDOM_CONTAINER_FOUND = EC(210009, "no leader or random container found") - + ERR_NO_LEADER_OR_RANDOM_CONTAINER_FOUND = EC(210008, "no leader or random container found") + // 220: commad options (client common) ERR_UNSUPPORT_CLIENT_KIND = EC(220000, "unsupport client kind") // 221: command options (client/bs) diff --git a/internal/storage/sql.go b/internal/storage/sql.go index 22e994ee6..0ce916aa1 100644 --- a/internal/storage/sql.go +++ b/internal/storage/sql.go @@ -103,7 +103,6 @@ type Cluster struct { Topology string Pool string Current bool - Type string } var ( @@ -117,21 +116,15 @@ var ( topology TEXT NULL, pool TEXT NULL, create_time DATE NOT NULL, - current INTEGER DEFAULT 0, - type TEXT NOT NULL + current INTEGER DEFAULT 0 ) ` // insert cluster InsertCluster = ` - INSERT INTO clusters(uuid, name, description, topology, type, pool, create_time) - VALUES(?, ?, ?, ?, ?, "", datetime('now','localtime')) + INSERT INTO clusters(uuid, name, description, topology, pool, create_time) + VALUES(?, ?, ?, ?, "", datetime('now','localtime')) ` - // check new cluster column - GetTypeFiled = `SELECT COUNT(*) FROM pragma_table_info('clusters') WHERE name = 'type'` - - // update new cluster column - UpdateCluster = `ALTER TABLE clusters ADD COLUMN type TEXT NOT NULL DEFAULT 'develop'` // delete cluster DeleteCluster = `DELETE from clusters WHERE name = ?` diff --git a/internal/storage/storage.go b/internal/storage/storage.go index 49e6834b4..bd1f69a13 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -91,14 +91,7 @@ func (s *Storage) init() error { } } - flag, err := s.CheckTypeFiledExist() - if err != nil { - return err - } - if !flag { - _, err = s.db.Write(UpdateCluster) - } - return err + return nil } func (s *Storage) write(query string, args ...any) error { @@ -167,26 +160,8 @@ func (s *Storage) GetHostses() ([]Hosts, error) { } // cluster -func (s *Storage) InsertCluster(name, uuid, description, topology, deployType string) error { - return s.write(InsertCluster, uuid, name, description, topology, deployType) -} - -func (s *Storage) CheckTypeFiledExist() (bool, error) { - result, err := s.db.Query(GetTypeFiled) - if err != nil { - return false, err - } - defer result.Close() - - var isFiledExist bool - for result.Next() { - err = result.Scan(&isFiledExist) - if err != nil { - return false, err - } - break - } - return isFiledExist, nil +func (s *Storage) InsertCluster(name, uuid, description, topology string) error { + return s.write(InsertCluster, uuid, name, description, topology) } func (s *Storage) DeleteCluster(name string) error { @@ -212,7 +187,6 @@ func (s *Storage) getClusters(query string, args ...interface{}) ([]Cluster, err &cluster.Pool, &cluster.CreateTime, &cluster.Current, - &cluster.Type, ) if err != nil { return nil, err