Skip to content

Commit

Permalink
1.add http deployment method
Browse files Browse the repository at this point in the history
Signed-off-by: liuminjian <[email protected]>
  • Loading branch information
liuminjian committed Dec 13, 2023
1 parent 462929c commit f2cf233
Show file tree
Hide file tree
Showing 79 changed files with 1,570 additions and 176 deletions.
12 changes: 11 additions & 1 deletion cli/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
configure "github.com/opencurve/curveadm/internal/configure/curveadm"
"github.com/opencurve/curveadm/internal/configure/hosts"
"github.com/opencurve/curveadm/internal/configure/topology"
"github.com/opencurve/curveadm/internal/daemon"
"github.com/opencurve/curveadm/internal/errno"
"github.com/opencurve/curveadm/internal/storage"
tools "github.com/opencurve/curveadm/internal/tools/upgrade"
Expand All @@ -43,6 +44,7 @@ import (
cliutil "github.com/opencurve/curveadm/internal/utils"
log "github.com/opencurve/curveadm/pkg/log/glg"
"github.com/opencurve/curveadm/pkg/module"
pigeoncore "github.com/opencurve/pigeon"
)

type CurveAdm struct {
Expand Down Expand Up @@ -70,6 +72,9 @@ type CurveAdm struct {
clusterTopologyData string // cluster topology
clusterPoolData string // cluster pool
monitor storage.Monitor

// pigeon
pigeon *pigeoncore.Pigeon
}

/*
Expand Down Expand Up @@ -195,7 +200,8 @@ func (curveadm *CurveAdm) init() error {
curveadm.clusterTopologyData = cluster.Topology
curveadm.clusterPoolData = cluster.Pool
curveadm.monitor = monitor

admServer := daemon.NewServer()
curveadm.pigeon = pigeoncore.NewPigeon([]*pigeoncore.HTTPServer{admServer})
return nil
}

Expand Down Expand Up @@ -534,3 +540,7 @@ func (curveadm *CurveAdm) PostAudit(id int64, ec error) {
log.Field("Error", err))
}
}

func (curveadm *CurveAdm) GetPigeon() *pigeoncore.Pigeon {
return curveadm.pigeon
}
2 changes: 2 additions & 0 deletions cli/command/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/opencurve/curveadm/cli/command/client"
"github.com/opencurve/curveadm/cli/command/cluster"
"github.com/opencurve/curveadm/cli/command/config"
"github.com/opencurve/curveadm/cli/command/daemon"
"github.com/opencurve/curveadm/cli/command/hosts"
"github.com/opencurve/curveadm/cli/command/monitor"
"github.com/opencurve/curveadm/cli/command/pfs"
Expand Down Expand Up @@ -66,6 +67,7 @@ func addSubCommands(cmd *cobra.Command, curveadm *cli.CurveAdm) {
target.NewTargetCommand(curveadm), // curveadm target ...
pfs.NewPFSCommand(curveadm), // curveadm pfs ...
monitor.NewMonitorCommand(curveadm), // curveadm monitor ...
daemon.NewDaemonCommand(curveadm), // curveadm http

NewAuditCommand(curveadm), // curveadm audit
NewCleanCommand(curveadm), // curveadm clean
Expand Down
44 changes: 44 additions & 0 deletions cli/command/daemon/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: Curveadm
* Created Date: 2023-03-31
* Author: wanghai (SeanHai)
*/

package daemon

import (
"github.com/opencurve/curveadm/cli/cli"
cliutil "github.com/opencurve/curveadm/internal/utils"
"github.com/spf13/cobra"
)

func NewDaemonCommand(curveadm *cli.CurveAdm) *cobra.Command {
cmd := &cobra.Command{
Use: "daemon",
Short: "Manage http service",
Args: cliutil.NoArgs,
RunE: cliutil.ShowHelp(curveadm.Err()),
}

cmd.AddCommand(
NewStartCommand(curveadm),
NewStopCommand(curveadm),
)
return cmd
}
58 changes: 58 additions & 0 deletions cli/command/daemon/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2023 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: Curveadm
* Created Date: 2023-03-31
* Author: wanghai (SeanHai)
*/

package daemon

import (
"github.com/opencurve/curveadm/cli/cli"
"github.com/spf13/cobra"
)

const (
START_EXAMPLR = `Examples:
$ curveadm daemon start -c config/pigeon.yaml # Start an http service to receive requests`
)

type startOptions struct {
filename string
}

func NewStartCommand(curveadm *cli.CurveAdm) *cobra.Command {
var options startOptions
pigeon := curveadm.GetPigeon()

cmd := &cobra.Command{
Use: "start [OPTIONS]",
Short: "Start http service",
Example: START_EXAMPLR,
RunE: func(cmd *cobra.Command, args []string) error {
return pigeon.Start(options.filename)
},
DisableFlagsInUseLine: true,
}

flags := cmd.Flags()
flags.StringVarP(&options.filename, "conf", "c", pigeon.DefaultConfFile(),
"Specify pigeon configure file")

return cmd
}
60 changes: 60 additions & 0 deletions cli/command/daemon/stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2023 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: Curveadm
* Created Date: 2023-03-31
* Author: wanghai (SeanHai)
*/

package daemon

import (
"github.com/opencurve/curveadm/cli/cli"
cliutil "github.com/opencurve/curveadm/internal/utils"
"github.com/spf13/cobra"
)

const (
STOP_EXAMPLR = `Examples:
$ curveadm daemon stop -c config/pigeon.yaml # Stop an http service`
)

type stopOptions struct {
filename string
}

func NewStopCommand(curveadm *cli.CurveAdm) *cobra.Command {
var options stopOptions
pigeon := curveadm.GetPigeon()

cmd := &cobra.Command{
Use: "stop",
Short: "Stop http service",
Args: cliutil.NoArgs,
Example: STOP_EXAMPLR,
RunE: func(cmd *cobra.Command, args []string) error {
return pigeon.Stop(options.filename)
},
DisableFlagsInUseLine: true,
}

flags := cmd.Flags()
flags.StringVarP(&options.filename, "conf", "c", pigeon.DefaultConfFile(),
"Specify pigeon configure file")

return cmd
}
Loading

0 comments on commit f2cf233

Please sign in to comment.