client server 실행인자 추가
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
go-ayo/
|
|
||||||
*.log
|
*.log
|
||||||
*.exe
|
*.exe
|
||||||
|
|||||||
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
@ -9,14 +9,12 @@
|
|||||||
"type": "go",
|
"type": "go",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "auto",
|
"mode": "auto",
|
||||||
"program": "${workspaceFolder}/houston",
|
"program": "${workspaceFolder}",
|
||||||
"env": {
|
"env": {
|
||||||
},
|
},
|
||||||
"args" : [
|
"args" : [
|
||||||
"-config=./config_template.json",
|
"-port=8080",
|
||||||
"-dev",
|
"-client"
|
||||||
"-nosession=true",
|
|
||||||
"-port=8080"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -5,11 +5,13 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
@ -28,6 +30,7 @@ import (
|
|||||||
type HoustonClient interface {
|
type HoustonClient interface {
|
||||||
SetReportMetrics(map[string]float32)
|
SetReportMetrics(map[string]float32)
|
||||||
Shutdown()
|
Shutdown()
|
||||||
|
Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
type bufferStack struct {
|
type bufferStack struct {
|
||||||
@ -68,14 +71,16 @@ type procmeta struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type houstonClient struct {
|
type houstonClient struct {
|
||||||
client *grpc.ClientConn
|
client *grpc.ClientConn
|
||||||
childProcs []*procmeta
|
childProcs []*procmeta
|
||||||
extraMetrics unsafe.Pointer // map[string]float32
|
extraMetrics unsafe.Pointer // map[string]float32
|
||||||
deploys map[string][]*protos.VersionAndArgs
|
deploys map[string][]*protos.VersionAndArgs
|
||||||
shutdownFunc context.CancelFunc
|
shutdownFunc context.CancelFunc
|
||||||
exitChan chan *exec.Cmd
|
ctx context.Context
|
||||||
httpAddr string
|
operationChan chan *protos.OperationQueryResponse
|
||||||
timestamp string
|
exitChan chan *exec.Cmd
|
||||||
|
httpAddr string
|
||||||
|
timestamp string
|
||||||
}
|
}
|
||||||
|
|
||||||
func bToMb(b uint64) uint32 {
|
func bToMb(b uint64) uint32 {
|
||||||
@ -208,7 +213,7 @@ func NewClient(grpcAddr string, httpAddr string) (HoustonClient, error) {
|
|||||||
metrics.Free = bToMb(mem.ActualFree)
|
metrics.Free = bToMb(mem.ActualFree)
|
||||||
metrics.Metrics = *(*map[string]float32)(atomic.LoadPointer(&hc.extraMetrics))
|
metrics.Metrics = *(*map[string]float32)(atomic.LoadPointer(&hc.extraMetrics))
|
||||||
|
|
||||||
sc.Report(context.Background(), metrics, grpc.WaitForReady(true))
|
sc.Report(ctx, metrics, grpc.WaitForReady(true))
|
||||||
mem.Get()
|
mem.Get()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,33 +300,57 @@ func NewClient(grpcAddr string, httpAddr string) (HoustonClient, error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
hc.shutdownFunc = cancel
|
||||||
// receive from stream
|
hc.exitChan = exitChan
|
||||||
for {
|
hc.ctx = ctx
|
||||||
select {
|
hc.operationChan = operationChan
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
|
|
||||||
default:
|
return hc, nil
|
||||||
err := hc.checkOperation(operationChan)
|
}
|
||||||
if err != nil {
|
|
||||||
logger.Println("hc.checkUpdate failed :", err)
|
func (hc *houstonClient) Start() {
|
||||||
}
|
// receive from stream
|
||||||
|
defer func() {
|
||||||
|
for _, proc := range hc.childProcs {
|
||||||
|
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||||
|
proc.cmd.Process.Signal(os.Kill)
|
||||||
|
proc.state = protos.ProcessState_Stopping
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, proc := range hc.childProcs {
|
||||||
|
proc.cmd.Wait()
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
hc.shutdownFunc = cancel
|
interrupt := make(chan os.Signal, 1)
|
||||||
hc.exitChan = exitChan
|
signal.Notify(interrupt, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
||||||
|
|
||||||
return hc, nil
|
go func() {
|
||||||
|
c := <-interrupt
|
||||||
|
logger.Println("interrupt!!!!!!!! :", c.String())
|
||||||
|
hc.shutdownFunc()
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-hc.ctx.Done():
|
||||||
|
return
|
||||||
|
|
||||||
|
default:
|
||||||
|
err := hc.checkOperation()
|
||||||
|
if err != nil {
|
||||||
|
logger.Println("hc.checkUpdate failed :", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *houstonClient) Shutdown() {
|
func (hc *houstonClient) Shutdown() {
|
||||||
hc.shutdownFunc()
|
hc.shutdownFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *houstonClient) checkOperation(opChan chan<- *protos.OperationQueryResponse) error {
|
func (hc *houstonClient) checkOperation() error {
|
||||||
defer func() {
|
defer func() {
|
||||||
r := recover()
|
r := recover()
|
||||||
if r != nil {
|
if r != nil {
|
||||||
@ -330,13 +359,12 @@ func (hc *houstonClient) checkOperation(opChan chan<- *protos.OperationQueryResp
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
op := protos.NewOperationClient(hc.client)
|
op := protos.NewOperationClient(hc.client)
|
||||||
cl, err := op.Query(context.Background(), grpc.WaitForReady(true))
|
cl, err := op.Query(hc.ctx, grpc.WaitForReady(true))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = cl.Send(hc.makeOperationQueryRequest())
|
err = cl.Send(hc.makeOperationQueryRequest())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cl.CloseSend()
|
cl.CloseSend()
|
||||||
return err
|
return err
|
||||||
@ -348,7 +376,8 @@ func (hc *houstonClient) checkOperation(opChan chan<- *protos.OperationQueryResp
|
|||||||
cl.CloseSend()
|
cl.CloseSend()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
opChan <- update
|
logger.Println(update)
|
||||||
|
hc.operationChan <- update
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package houston_test
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|||||||
113
main.go
Normal file
113
main.go
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
|
"repositories.action2quare.com/ayo/houston/client"
|
||||||
|
"repositories.action2quare.com/ayo/houston/server"
|
||||||
|
)
|
||||||
|
|
||||||
|
var runAsClient = flag.Bool("client", false, "")
|
||||||
|
var runAsServer = flag.Bool("server", false, "")
|
||||||
|
var port = flag.Int("port", 8080, "")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if !flag.Parsed() {
|
||||||
|
flag.Parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
if !*runAsClient && !*runAsServer {
|
||||||
|
logger.Fatal("client or server flag is needed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if *runAsClient {
|
||||||
|
hc, err := client.NewClient("192.168.9.32:8080", "http://192.168.9.32/commandcenter")
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hc.Start()
|
||||||
|
} else if *runAsServer {
|
||||||
|
svr := server.NewServer()
|
||||||
|
svr.Start(*port)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// func TestOperationServer(t *testing.T) {
|
||||||
|
// hc, err := client.NewClient("192.168.9.32:8080", "http://192.168.9.32/commandcenter")
|
||||||
|
// if err != nil {
|
||||||
|
// t.Error(err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// for i := 0; ; i++ {
|
||||||
|
// hc.SetReportMetrics(map[string]float32{
|
||||||
|
// "count": float32(i),
|
||||||
|
// })
|
||||||
|
// time.Sleep(1300 * time.Millisecond)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // token, _ := getMicrosoftAuthoizationToken("30330e18-f407-4e35-a6d6-b734b9fe9ee9", "VTr8Q~VBAUAOSmFiHM~bjgszYXBm9nuGBQCk8cLq")
|
||||||
|
// //go func() {
|
||||||
|
// //time.Sleep(2 * time.Second)
|
||||||
|
// // testver := fmt.Sprintf("%d.%d.%d", time.Now().Hour(), time.Now().Minute(), time.Now().Second())
|
||||||
|
|
||||||
|
// // svr.Operation().Deploy(server.MakeDeployRequest(
|
||||||
|
// // common.DeployRequest{
|
||||||
|
// // Name: "warehouse",
|
||||||
|
// // Version: testver,
|
||||||
|
// // Url: "https://actionsquare.s3.ap-northeast-2.amazonaws.com/warehouse.zip?response-content-disposition=inline&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEK7%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDmFwLW5vcnRoZWFzdC0yIkcwRQIgeYQKZXvVQsYEZNoWzxSRVjsKHzhq5VhIHVIaLpsUpssCIQCeZn8tfVM9jIjiKp62RPwEnb9oGR8T7apbsnqnntNlJCqGAwiH%2F%2F%2F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z-Expires=43199&X-Amz-Credential=ASIAX76TWSAROTUEDRGM%2F20230331%2Fap-northeast-2%2Fs3%2Faws4_request&X-Amz-Signature=aa6cc8aac808a066ea0c25e57b3a220cb6b2eb6118f6fb28974cb6e3c34e59d0",
|
||||||
|
// // // AccessToken: token,
|
||||||
|
// // },
|
||||||
|
// // []string{"mountain"},
|
||||||
|
// // ))
|
||||||
|
|
||||||
|
// // time.Sleep(2 * time.Second)
|
||||||
|
// // svr.Operation().Start(server.MakeStartRequest(
|
||||||
|
// // common.StartRequest{
|
||||||
|
// // Name: "warehouse",
|
||||||
|
// // Version: "latest",
|
||||||
|
// // Args: "biglocal.exe -port=8090 -dev",
|
||||||
|
// // },
|
||||||
|
// // []string{"mountain"},
|
||||||
|
// // ))
|
||||||
|
// // time.Sleep(25 * time.Second)
|
||||||
|
// // svr.Operation().Restart(server.MakeRestartRequest(
|
||||||
|
// // common.RestartRequest{
|
||||||
|
// // Name: "warehouse",
|
||||||
|
// // Version: "latest",
|
||||||
|
// // },
|
||||||
|
// // []string{"mountain"},
|
||||||
|
// // ))
|
||||||
|
|
||||||
|
// // time.Sleep(5 * time.Second)
|
||||||
|
// // svr.Operation().Stop(server.MakeStopRequest(
|
||||||
|
// // common.StopRequest{
|
||||||
|
// // Name: "warehouse",
|
||||||
|
// // Version: "latest",
|
||||||
|
// // Pid: 0,
|
||||||
|
// // },
|
||||||
|
// // []string{"mountain"},
|
||||||
|
// // ))
|
||||||
|
|
||||||
|
// // svr.Operation().Upload(server.MakeUploadRequest(
|
||||||
|
// // common.UploadRequest{
|
||||||
|
// // Name: "warehouse",
|
||||||
|
// // Version: "latest",
|
||||||
|
// // Url: "http://localhost",
|
||||||
|
// // Filter: "logs/*.log",
|
||||||
|
// // },
|
||||||
|
// // []string{"mountain"},
|
||||||
|
// // ))
|
||||||
|
// // time.Sleep(5 * time.Second)
|
||||||
|
// // svr.Operation().Withdraw(server.MakeWithdrawRequest(
|
||||||
|
// // common.WithdrawRequest{
|
||||||
|
// // Name: "warehouse",
|
||||||
|
// // Version: testver,
|
||||||
|
// // },
|
||||||
|
// // nil,
|
||||||
|
// // ))
|
||||||
|
// //}()
|
||||||
|
// }
|
||||||
Reference in New Issue
Block a user