client server 실행인자 추가
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
go-ayo/
|
||||
*.log
|
||||
*.exe
|
||||
|
||||
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
@ -9,14 +9,12 @@
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/houston",
|
||||
"program": "${workspaceFolder}",
|
||||
"env": {
|
||||
},
|
||||
"args" : [
|
||||
"-config=./config_template.json",
|
||||
"-dev",
|
||||
"-nosession=true",
|
||||
"-port=8080"
|
||||
"-port=8080",
|
||||
"-client"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@ -5,11 +5,13 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
@ -28,6 +30,7 @@ import (
|
||||
type HoustonClient interface {
|
||||
SetReportMetrics(map[string]float32)
|
||||
Shutdown()
|
||||
Start()
|
||||
}
|
||||
|
||||
type bufferStack struct {
|
||||
@ -68,14 +71,16 @@ type procmeta struct {
|
||||
}
|
||||
|
||||
type houstonClient struct {
|
||||
client *grpc.ClientConn
|
||||
childProcs []*procmeta
|
||||
extraMetrics unsafe.Pointer // map[string]float32
|
||||
deploys map[string][]*protos.VersionAndArgs
|
||||
shutdownFunc context.CancelFunc
|
||||
exitChan chan *exec.Cmd
|
||||
httpAddr string
|
||||
timestamp string
|
||||
client *grpc.ClientConn
|
||||
childProcs []*procmeta
|
||||
extraMetrics unsafe.Pointer // map[string]float32
|
||||
deploys map[string][]*protos.VersionAndArgs
|
||||
shutdownFunc context.CancelFunc
|
||||
ctx context.Context
|
||||
operationChan chan *protos.OperationQueryResponse
|
||||
exitChan chan *exec.Cmd
|
||||
httpAddr string
|
||||
timestamp string
|
||||
}
|
||||
|
||||
func bToMb(b uint64) uint32 {
|
||||
@ -208,7 +213,7 @@ func NewClient(grpcAddr string, httpAddr string) (HoustonClient, error) {
|
||||
metrics.Free = bToMb(mem.ActualFree)
|
||||
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()
|
||||
}
|
||||
}
|
||||
@ -295,33 +300,57 @@ func NewClient(grpcAddr string, httpAddr string) (HoustonClient, error) {
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
// receive from stream
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
hc.shutdownFunc = cancel
|
||||
hc.exitChan = exitChan
|
||||
hc.ctx = ctx
|
||||
hc.operationChan = operationChan
|
||||
|
||||
default:
|
||||
err := hc.checkOperation(operationChan)
|
||||
if err != nil {
|
||||
logger.Println("hc.checkUpdate failed :", err)
|
||||
}
|
||||
return hc, nil
|
||||
}
|
||||
|
||||
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
|
||||
hc.exitChan = exitChan
|
||||
interrupt := make(chan os.Signal, 1)
|
||||
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() {
|
||||
hc.shutdownFunc()
|
||||
}
|
||||
|
||||
func (hc *houstonClient) checkOperation(opChan chan<- *protos.OperationQueryResponse) error {
|
||||
func (hc *houstonClient) checkOperation() error {
|
||||
defer func() {
|
||||
r := recover()
|
||||
if r != nil {
|
||||
@ -330,13 +359,12 @@ func (hc *houstonClient) checkOperation(opChan chan<- *protos.OperationQueryResp
|
||||
}()
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
err = cl.Send(hc.makeOperationQueryRequest())
|
||||
|
||||
if err != nil {
|
||||
cl.CloseSend()
|
||||
return err
|
||||
@ -348,7 +376,8 @@ func (hc *houstonClient) checkOperation(opChan chan<- *protos.OperationQueryResp
|
||||
cl.CloseSend()
|
||||
return err
|
||||
}
|
||||
opChan <- update
|
||||
logger.Println(update)
|
||||
hc.operationChan <- update
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package houston_test
|
||||
package main
|
||||
|
||||
import (
|
||||
"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%2FwEaDmFwLW5vcnRoZWFzdC0yIkcwRQIgeYQKZXvVQsYEZNoWzxSRVjsKHzhq5VhIHVI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&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230331T060558Z&X-Amz-SignedHeaders=host&X-Amz-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