Skip to content

Commit 9cc9488

Browse files
author
liuminjian
committed
1.add http deployment method
Signed-off-by: liuminjian <[email protected]>
1 parent 580b26d commit 9cc9488

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1744
-198
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ GO := go
2121

2222
# output
2323
OUTPUT := bin/curveadm
24+
SERVER_OUTPUT := bin/pigeon
2425

2526
# build flags
2627
LDFLAGS := -s -w
@@ -52,6 +53,7 @@ TEST_FLAGS += -run $(CASE)
5253

5354
# packages
5455
PACKAGES := $(PWD)/cmd/curveadm/main.go
56+
SERVER_PACKAGES := $(PWD)/cmd/service/main.go
5557

5658
# tar
5759
VERSION := "unknown"

cli/cli/cli.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
configure "github.com/opencurve/curveadm/internal/configure/curveadm"
3636
"github.com/opencurve/curveadm/internal/configure/hosts"
3737
"github.com/opencurve/curveadm/internal/configure/topology"
38+
"github.com/opencurve/curveadm/internal/daemon"
3839
"github.com/opencurve/curveadm/internal/errno"
3940
"github.com/opencurve/curveadm/internal/storage"
4041
tools "github.com/opencurve/curveadm/internal/tools/upgrade"
@@ -43,6 +44,7 @@ import (
4344
cliutil "github.com/opencurve/curveadm/internal/utils"
4445
log "github.com/opencurve/curveadm/pkg/log/glg"
4546
"github.com/opencurve/curveadm/pkg/module"
47+
pigeoncore "github.com/opencurve/pigeon"
4648
)
4749

4850
type CurveAdm struct {
@@ -69,7 +71,11 @@ type CurveAdm struct {
6971
clusterName string // current cluster name
7072
clusterTopologyData string // cluster topology
7173
clusterPoolData string // cluster pool
74+
clusterType string // cluster type like develop, production, etc.
7275
monitor storage.Monitor
76+
77+
// pigeon
78+
pigeon *pigeoncore.Pigeon
7379
}
7480

7581
/*
@@ -195,7 +201,9 @@ func (curveadm *CurveAdm) init() error {
195201
curveadm.clusterTopologyData = cluster.Topology
196202
curveadm.clusterPoolData = cluster.Pool
197203
curveadm.monitor = monitor
198-
204+
admServer := daemon.NewServer()
205+
curveadm.pigeon = pigeoncore.NewPigeon([]*pigeoncore.HTTPServer{admServer})
206+
curveadm.clusterType = cluster.Type
199207
return nil
200208
}
201209

@@ -276,6 +284,7 @@ func (curveadm *CurveAdm) ClusterUUId() string { return curveadm.c
276284
func (curveadm *CurveAdm) ClusterName() string { return curveadm.clusterName }
277285
func (curveadm *CurveAdm) ClusterTopologyData() string { return curveadm.clusterTopologyData }
278286
func (curveadm *CurveAdm) ClusterPoolData() string { return curveadm.clusterPoolData }
287+
func (curveadm *CurveAdm) ClusterType() string { return curveadm.clusterType }
279288
func (curveadm *CurveAdm) Monitor() storage.Monitor { return curveadm.monitor }
280289

281290
func (curveadm *CurveAdm) GetHost(host string) (*hosts.HostConfig, error) {
@@ -534,3 +543,7 @@ func (curveadm *CurveAdm) PostAudit(id int64, ec error) {
534543
log.Field("Error", err))
535544
}
536545
}
546+
547+
func (curveadm *CurveAdm) GetPigeon() *pigeoncore.Pigeon {
548+
return curveadm.pigeon
549+
}

cli/command/cluster/add.go

+26-4
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ var (
4747
CHECK_TOPOLOGY_PLAYBOOK_STEPS = []int{
4848
playbook.CHECK_TOPOLOGY,
4949
}
50+
SUPPORTED_DEPLOY_TYPES = []string{
51+
"production",
52+
"test",
53+
"develop",
54+
}
5055
)
5156

5257
type addOptions struct {
5358
name string
54-
descriotion string
59+
description string
5560
filename string
61+
deployType string
5662
}
5763

5864
func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
@@ -63,6 +69,9 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
6369
Short: "Add cluster",
6470
Args: utils.ExactArgs(1),
6571
Example: ADD_EXAMPLE,
72+
PreRunE: func(cmd *cobra.Command, args []string) error {
73+
return checkAddOptions(cmd)
74+
},
6675
RunE: func(cmd *cobra.Command, args []string) error {
6776
options.name = args[0]
6877
return runAdd(curveadm, options)
@@ -71,9 +80,9 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
7180
}
7281

7382
flags := cmd.Flags()
74-
flags.StringVarP(&options.descriotion, "description", "m", "", "Description for cluster")
83+
flags.StringVarP(&options.description, "description", "m", "", "Description for cluster")
7584
flags.StringVarP(&options.filename, "topology", "f", "", "Specify the path of topology file")
76-
85+
flags.StringVar(&options.deployType, "type", "develop", "Specify the type of cluster")
7786
return cmd
7887
}
7988

@@ -134,6 +143,19 @@ func checkTopology(curveadm *cli.CurveAdm, data string, options addOptions) erro
134143
return pb.Run()
135144
}
136145

146+
func checkAddOptions(cmd *cobra.Command) error {
147+
deployType, err := cmd.Flags().GetString("deploy-type")
148+
if err != nil {
149+
return err
150+
}
151+
for _, t := range SUPPORTED_DEPLOY_TYPES {
152+
if deployType == t {
153+
return nil
154+
}
155+
}
156+
return errno.ERR_UNSUPPORT_DEPLOY_TYPE.F("deploy type: %s", deployType)
157+
}
158+
137159
func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
138160
// 1) check wether cluster already exist
139161
name := options.name
@@ -163,7 +185,7 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
163185

164186
// 4) insert cluster (with topology) into database
165187
uuid := uuid.NewString()
166-
err = storage.InsertCluster(name, uuid, options.descriotion, data)
188+
err = storage.InsertCluster(name, uuid, options.description, data, options.deployType)
167189
if err != nil {
168190
return errno.ERR_INSERT_CLUSTER_FAILED.E(err)
169191
}

cli/command/cluster/import.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func importCluster(storage *storage.Storage, dbfile, name string) error {
100100
}
101101

102102
// insert cluster
103-
err = storage.InsertCluster(name, cluster.UUId, cluster.Description, cluster.Topology)
103+
err = storage.InsertCluster(name, cluster.UUId, cluster.Description, cluster.Topology, cluster.Type)
104104
if err != nil {
105105
return err
106106
}

cli/command/cmd.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/opencurve/curveadm/cli/command/client"
3232
"github.com/opencurve/curveadm/cli/command/cluster"
3333
"github.com/opencurve/curveadm/cli/command/config"
34+
"github.com/opencurve/curveadm/cli/command/daemon"
3435
"github.com/opencurve/curveadm/cli/command/hosts"
3536
"github.com/opencurve/curveadm/cli/command/monitor"
3637
"github.com/opencurve/curveadm/cli/command/pfs"
@@ -66,6 +67,7 @@ func addSubCommands(cmd *cobra.Command, curveadm *cli.CurveAdm) {
6667
target.NewTargetCommand(curveadm), // curveadm target ...
6768
pfs.NewPFSCommand(curveadm), // curveadm pfs ...
6869
monitor.NewMonitorCommand(curveadm), // curveadm monitor ...
70+
daemon.NewDaemonCommand(curveadm), // curveadm http
6971

7072
NewAuditCommand(curveadm), // curveadm audit
7173
NewCleanCommand(curveadm), // curveadm clean

cli/command/daemon/cmd.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2023 NetEase Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Project: Curveadm
19+
* Created Date: 2023-03-31
20+
* Author: wanghai (SeanHai)
21+
*/
22+
23+
package daemon
24+
25+
import (
26+
"github.com/opencurve/curveadm/cli/cli"
27+
cliutil "github.com/opencurve/curveadm/internal/utils"
28+
"github.com/spf13/cobra"
29+
)
30+
31+
func NewDaemonCommand(curveadm *cli.CurveAdm) *cobra.Command {
32+
cmd := &cobra.Command{
33+
Use: "daemon",
34+
Short: "Manage http service",
35+
Args: cliutil.NoArgs,
36+
RunE: cliutil.ShowHelp(curveadm.Err()),
37+
}
38+
39+
cmd.AddCommand(
40+
NewStartCommand(curveadm),
41+
NewStopCommand(curveadm),
42+
)
43+
return cmd
44+
}

cli/command/daemon/start.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2023 NetEase Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Project: Curveadm
19+
* Created Date: 2023-03-31
20+
* Author: wanghai (SeanHai)
21+
*/
22+
23+
package daemon
24+
25+
import (
26+
"github.com/opencurve/curveadm/cli/cli"
27+
"github.com/spf13/cobra"
28+
)
29+
30+
const (
31+
START_EXAMPLR = `Examples:
32+
$ curveadm daemon start -c config/pigeon.yaml # Start an http service to receive requests`
33+
)
34+
35+
type startOptions struct {
36+
filename string
37+
}
38+
39+
func NewStartCommand(curveadm *cli.CurveAdm) *cobra.Command {
40+
var options startOptions
41+
pigeon := curveadm.GetPigeon()
42+
43+
cmd := &cobra.Command{
44+
Use: "start [OPTIONS]",
45+
Short: "Start http service",
46+
Example: START_EXAMPLR,
47+
RunE: func(cmd *cobra.Command, args []string) error {
48+
return pigeon.Start(options.filename)
49+
},
50+
DisableFlagsInUseLine: true,
51+
}
52+
53+
flags := cmd.Flags()
54+
flags.StringVarP(&options.filename, "conf", "c", pigeon.DefaultConfFile(),
55+
"Specify pigeon configure file")
56+
57+
return cmd
58+
}

cli/command/daemon/stop.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2023 NetEase Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Project: Curveadm
19+
* Created Date: 2023-03-31
20+
* Author: wanghai (SeanHai)
21+
*/
22+
23+
package daemon
24+
25+
import (
26+
"github.com/opencurve/curveadm/cli/cli"
27+
cliutil "github.com/opencurve/curveadm/internal/utils"
28+
"github.com/spf13/cobra"
29+
)
30+
31+
const (
32+
STOP_EXAMPLR = `Examples:
33+
$ curveadm daemon stop -c config/pigeon.yaml # Stop an http service`
34+
)
35+
36+
type stopOptions struct {
37+
filename string
38+
}
39+
40+
func NewStopCommand(curveadm *cli.CurveAdm) *cobra.Command {
41+
var options stopOptions
42+
pigeon := curveadm.GetPigeon()
43+
44+
cmd := &cobra.Command{
45+
Use: "stop",
46+
Short: "Stop http service",
47+
Args: cliutil.NoArgs,
48+
Example: STOP_EXAMPLR,
49+
RunE: func(cmd *cobra.Command, args []string) error {
50+
return pigeon.Stop(options.filename)
51+
},
52+
DisableFlagsInUseLine: true,
53+
}
54+
55+
flags := cmd.Flags()
56+
flags.StringVarP(&options.filename, "conf", "c", pigeon.DefaultConfFile(),
57+
"Specify pigeon configure file")
58+
59+
return cmd
60+
}

cli/command/deploy.go

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ func displayDeployTitle(curveadm *cli.CurveAdm, dcs []*topology.DeployConfig) {
302302
curveadm.WriteOutln("Cluster Name : %s", curveadm.ClusterName())
303303
curveadm.WriteOutln("Cluster Kind : %s", dcs[0].GetKind())
304304
curveadm.WriteOutln("Cluster Services: %s", serviceStats(dcs))
305+
curveadm.WriteOutln("Cluster Type : %s", curveadm.ClusterType())
305306
curveadm.WriteOutln("")
306307
}
307308

0 commit comments

Comments
 (0)