Compare commits
119 Commits
fdb0a7baa5
...
sbl
| Author | SHA1 | Date | |
|---|---|---|---|
| 598181e7f7 | |||
| 7015dc99d6 | |||
| df56a542a1 | |||
| 46dd289c28 | |||
| 43b5aee48b | |||
| 592e00b98b | |||
| 92432fcd83 | |||
| a844bed056 | |||
| 2ddbae07b2 | |||
| 4d6665b64a | |||
| 99e1007012 | |||
| 9632dc7755 | |||
| a60dee1645 | |||
| 7fe5090efa | |||
| e9370513c2 | |||
| 387d4f3ea8 | |||
| e5984b3342 | |||
| f174a165fe | |||
| a112f20cb8 | |||
| 97fc64be81 | |||
| 7ae391b599 | |||
| f5e491325f | |||
| 2fa02374fd | |||
| 380586fb73 | |||
| da37ed11cd | |||
| 3ab055008c | |||
| 71e80d2908 | |||
| 12a0f9d2b1 | |||
| 016f459252 | |||
| 030fa658f5 | |||
| 3c96921703 | |||
| 6f444e0187 | |||
| 3eaad85453 | |||
| 401cfa8b84 | |||
| 5e4799ff55 | |||
| 86e14fbd23 | |||
| fb3886e2e4 | |||
| 95d6741389 | |||
| fdb534c5e0 | |||
| dfcb78b70c | |||
| 4e928f3426 | |||
| d546f2340d | |||
| bad563dce7 | |||
| 62494fb052 | |||
| eb86c0a073 | |||
| 9d4718592d | |||
| dcc94d2609 | |||
| f45558483e | |||
| 01940222b6 | |||
| d03f02a44f | |||
| 27dd9226e9 | |||
| 00fa08a739 | |||
| ccfa9e4be3 | |||
| 68a5876fd8 | |||
| 33181f1717 | |||
| 6e0bd71c80 | |||
| 75992472f3 | |||
| ee1459d760 | |||
| 3913c6cdcf | |||
| 2744a0a990 | |||
| 1d3266bbaf | |||
| 023a2a5194 | |||
| 6eaa856688 | |||
| afa270c9a0 | |||
| ad3382db89 | |||
| e1e2f3c087 | |||
| cf4b458a4b | |||
| 72b88b194f | |||
| cfd6e23384 | |||
| 6416c27230 | |||
| 2ae42d0b08 | |||
| d4cd792950 | |||
| 84543f9a31 | |||
| 1a404e5361 | |||
| d18fe3e3a1 | |||
| b2ff0e8ffc | |||
| 3208eba280 | |||
| 882d35d604 | |||
| ba72262d50 | |||
| 8d764c8d18 | |||
| 299a0a2bd3 | |||
| 5c765fe32f | |||
| 394466e216 | |||
| 61d2fbf709 | |||
| d43b83e761 | |||
| 432cc68024 | |||
| 22148f8ae7 | |||
| 282ef95ab0 | |||
| 5b0b977a39 | |||
| 2985e0fdaf | |||
| b8c1e97ab8 | |||
| c9fecf55de | |||
| 15ab1c9e7c | |||
| b6b8aa0794 | |||
| 64ca01c3a7 | |||
| 5798e77a6c | |||
| c5e2bc203a | |||
| 3ace1be27a | |||
| 3dc121bc71 | |||
| 849973c449 | |||
| d1a192159b | |||
| 7a5696961f | |||
| 4d9a25dd6b | |||
| 9bd09509c8 | |||
| 1b57e9f87e | |||
| 4667d351a8 | |||
| 571f0d76df | |||
| 15dd1e544c | |||
| 45ab15d345 | |||
| 02db65e06f | |||
| a8821b694b | |||
| 5429d3d90f | |||
| cf46888b6a | |||
| 6a35d7b1fe | |||
| d04dd5b05d | |||
| d3442be5dc | |||
| 06bc095ea4 | |||
| da47d7c587 | |||
| d464812cf8 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ houston
|
|||||||
houston.zip
|
houston.zip
|
||||||
config.json
|
config.json
|
||||||
.vscode/
|
.vscode/
|
||||||
|
/data
|
||||||
|
|||||||
470
client/client.go
470
client/client.go
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@ -22,87 +23,106 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/djherbis/times"
|
||||||
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
"repositories.action2quare.com/ayo/houston/shared"
|
"repositories.action2quare.com/ayo/houston/shared"
|
||||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type runcommand struct {
|
||||||
|
Exec string `json:"exec"`
|
||||||
|
Args []string `json:"args"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
AutoRestart bool `json:"auto_restart"`
|
||||||
|
OutputLogFile string `json:"logfile"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type easyruncommand runcommand
|
||||||
|
|
||||||
|
func (t *runcommand) UnmarshalJSON(b []byte) error {
|
||||||
|
easy := easyruncommand{
|
||||||
|
Version: "latest",
|
||||||
|
AutoRestart: true,
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(b, &easy); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*t = runcommand(easy)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type clientConfig struct {
|
type clientConfig struct {
|
||||||
GrpcAddress string `json:"grpc_server_address"`
|
GrpcAddress string `json:"grpc_server_address"`
|
||||||
HttpAddress string `json:"http_server_address"`
|
HttpAddress string `json:"http_server_address"`
|
||||||
StorageRoot string `json:"storage_path"`
|
StorageRoot string `json:"storage_path"`
|
||||||
|
MetricNamespace string `json:"metric_namespace"`
|
||||||
|
ConstLabels map[string]string `json:"metric_const_labels"`
|
||||||
|
Autorun map[string]runcommand `json:"autorun"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadClientConfig() (clientConfig, error) {
|
var autorun = flagx.String("autorun", "", "")
|
||||||
configFile, err := os.Open("config.json")
|
|
||||||
if err != nil {
|
|
||||||
return clientConfig{}, err
|
|
||||||
}
|
|
||||||
defer configFile.Close()
|
|
||||||
|
|
||||||
var config struct {
|
type outerconfig struct {
|
||||||
Houston *struct {
|
Houston *struct {
|
||||||
Client clientConfig `json:"client"`
|
Client clientConfig `json:"client"`
|
||||||
} `json:"houston"`
|
} `json:"houston"`
|
||||||
}
|
}
|
||||||
|
|
||||||
dec := json.NewDecoder(configFile)
|
func loadClientConfig() (clientConfig, error) {
|
||||||
err = dec.Decode(&config)
|
var oc outerconfig
|
||||||
|
err := gocommon.LoadConfig[outerconfig](&oc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Println(err)
|
||||||
return clientConfig{}, err
|
return clientConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Houston == nil {
|
return oc.Houston.Client, nil
|
||||||
return clientConfig{}, errors.New(`"houston" object is missing in config.json`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return config.Houston.Client, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type HoustonClient interface {
|
type HoustonClient interface {
|
||||||
SetReportMetrics(map[string]float32)
|
|
||||||
Shutdown()
|
Shutdown()
|
||||||
Start()
|
Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
type bufferStack struct {
|
var seq = int32(1)
|
||||||
pool [5][]byte
|
|
||||||
cursor int32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bs *bufferStack) pop() []byte {
|
|
||||||
pos := atomic.LoadInt32(&bs.cursor)
|
|
||||||
for !atomic.CompareAndSwapInt32(&bs.cursor, pos, pos+1) {
|
|
||||||
pos = atomic.LoadInt32(&bs.cursor)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
bs.pool[pos] = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
curbuf := bs.pool[pos]
|
|
||||||
if curbuf == nil {
|
|
||||||
curbuf = make([]byte, 1024)
|
|
||||||
}
|
|
||||||
return curbuf
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bs *bufferStack) push(x []byte) {
|
|
||||||
pos := atomic.AddInt32(&bs.cursor, -1)
|
|
||||||
bs.pool[pos] = x
|
|
||||||
}
|
|
||||||
|
|
||||||
type procmeta struct {
|
type procmeta struct {
|
||||||
|
id int32
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
name string
|
name string
|
||||||
|
args []string
|
||||||
version string
|
version string
|
||||||
state protos.ProcessState
|
verpath string
|
||||||
|
recover bool
|
||||||
|
state int32
|
||||||
stdin io.WriteCloser
|
stdin io.WriteCloser
|
||||||
logUploadChan chan *shared.UploadRequest
|
logfile string
|
||||||
buffers bufferStack
|
keepLatest bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pm *procmeta) isState(s protos.ProcessState) bool {
|
||||||
|
return atomic.LoadInt32(&pm.state) == int32(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pm *procmeta) getState() protos.ProcessState {
|
||||||
|
return protos.ProcessState(atomic.LoadInt32(&pm.state))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pm *procmeta) setState(s protos.ProcessState) {
|
||||||
|
atomic.StoreInt32(&pm.state, int32(s))
|
||||||
|
}
|
||||||
|
|
||||||
|
type uploadRequest struct {
|
||||||
|
logFile string
|
||||||
|
name string
|
||||||
|
version string
|
||||||
}
|
}
|
||||||
|
|
||||||
type houstonClient struct {
|
type houstonClient struct {
|
||||||
@ -114,14 +134,24 @@ type houstonClient struct {
|
|||||||
operationChan chan *protos.OperationQueryResponse
|
operationChan chan *protos.OperationQueryResponse
|
||||||
exitChan chan *exec.Cmd
|
exitChan chan *exec.Cmd
|
||||||
clientChan chan *grpc.ClientConn
|
clientChan chan *grpc.ClientConn
|
||||||
|
uploadChan chan uploadRequest
|
||||||
timestamp string
|
timestamp string
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
config clientConfig
|
config clientConfig
|
||||||
|
version string
|
||||||
|
standalone bool
|
||||||
|
siblingProcIndex map[string]uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func unmarshal[T any](val *T, src map[string]string) {
|
func unmarshal[T any](val *T, src map[string]string) {
|
||||||
|
defer func() {
|
||||||
|
r := recover()
|
||||||
|
if r != nil {
|
||||||
|
logger.Error(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
argval := reflect.ValueOf(val)
|
argval := reflect.ValueOf(val)
|
||||||
logger.Println("operation receive :", argval.Type().Name(), src)
|
|
||||||
for i := 0; i < argval.Elem().Type().NumField(); i++ {
|
for i := 0; i < argval.Elem().Type().NumField(); i++ {
|
||||||
if !argval.Elem().Type().Field(i).IsExported() {
|
if !argval.Elem().Type().Field(i).IsExported() {
|
||||||
continue
|
continue
|
||||||
@ -133,48 +163,91 @@ func unmarshal[T any](val *T, src map[string]string) {
|
|||||||
} else if argval.Elem().Field(i).Kind() == reflect.Array || argval.Elem().Field(i).Kind() == reflect.Slice {
|
} else if argval.Elem().Field(i).Kind() == reflect.Array || argval.Elem().Field(i).Kind() == reflect.Slice {
|
||||||
conv := strings.Split(arg, "\n")
|
conv := strings.Split(arg, "\n")
|
||||||
argval.Elem().Field(i).Set(reflect.ValueOf(conv))
|
argval.Elem().Field(i).Set(reflect.ValueOf(conv))
|
||||||
|
} else if argval.Elem().Field(i).Kind() == reflect.Bool {
|
||||||
|
bv, _ := strconv.ParseBool(arg)
|
||||||
|
argval.Elem().Field(i).SetBool(bv)
|
||||||
} else {
|
} else {
|
||||||
argval.Elem().Field(i).SetString(arg)
|
argval.Elem().Field(i).SetString(arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.Println("operation receive :", argval.Elem().Type().Name(), *val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func gatherDeployedPrograms(storageRoot, name string) []*protos.VersionAndArgs {
|
type version_args_ts struct {
|
||||||
var rawvers []*protos.VersionAndArgs
|
*protos.VersionAndArgs
|
||||||
|
modTime time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func gatherDeployedPrograms(storageRoot, name string) (out []*protos.VersionAndArgs) {
|
||||||
|
var rawvers []version_args_ts
|
||||||
targetPath := path.Join(storageRoot, name)
|
targetPath := path.Join(storageRoot, name)
|
||||||
if vers, err := os.ReadDir(targetPath); err == nil {
|
if vers, err := os.ReadDir(targetPath); err == nil {
|
||||||
for _, ver := range vers {
|
for _, ver := range vers {
|
||||||
if ver.IsDir() {
|
if ver.IsDir() {
|
||||||
|
fi, _ := ver.Info()
|
||||||
args := lastExecutionArgs(path.Join(targetPath, ver.Name()))
|
args := lastExecutionArgs(path.Join(targetPath, ver.Name()))
|
||||||
rawvers = append(rawvers, &protos.VersionAndArgs{
|
rawvers = append(rawvers, version_args_ts{
|
||||||
|
VersionAndArgs: &protos.VersionAndArgs{
|
||||||
Version: ver.Name(),
|
Version: ver.Name(),
|
||||||
Args: args,
|
Args: args,
|
||||||
|
},
|
||||||
|
modTime: fi.ModTime(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Slice(rawvers, func(i, j int) bool {
|
sort.Slice(rawvers, func(i, j int) bool {
|
||||||
leftParsed := shared.ParseVersionString(rawvers[i].Version)
|
return rawvers[i].modTime.After(rawvers[j].modTime)
|
||||||
rightParsed := shared.ParseVersionString(rawvers[j].Version)
|
|
||||||
return shared.CompareVersionString(leftParsed, rightParsed) < 0
|
|
||||||
})
|
})
|
||||||
return rawvers
|
|
||||||
|
for _, v := range rawvers {
|
||||||
|
out = append(out, v.VersionAndArgs)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryRequest {
|
func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryRequest {
|
||||||
hn, _ := os.Hostname()
|
var procs []*protos.ProcessDescription
|
||||||
procs := make([]*protos.ProcessDescription, 0, len(hc.childProcs))
|
var deploys []*protos.DeployedVersions
|
||||||
|
|
||||||
|
var selfname string
|
||||||
|
var selfargs []string
|
||||||
|
if hc.standalone {
|
||||||
|
selfname = path.Base(filepath.ToSlash(os.Args[0]))
|
||||||
|
selfargs = os.Args[1:]
|
||||||
|
} else {
|
||||||
|
selfname = "houston"
|
||||||
|
selfargs = []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(path.Ext(selfname)) > 0 {
|
||||||
|
selfname = selfname[:len(selfname)-len(path.Ext(selfname))]
|
||||||
|
}
|
||||||
|
|
||||||
|
procs = append(procs, &protos.ProcessDescription{
|
||||||
|
Name: selfname,
|
||||||
|
Args: selfargs,
|
||||||
|
Version: hc.version,
|
||||||
|
State: protos.ProcessState_Running,
|
||||||
|
Pid: int32(os.Getpid()),
|
||||||
|
})
|
||||||
|
deploys = append(deploys, &protos.DeployedVersions{
|
||||||
|
Name: selfname,
|
||||||
|
Versions: []*protos.VersionAndArgs{
|
||||||
|
{Version: hc.version, Args: selfargs},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
for _, child := range hc.childProcs {
|
for _, child := range hc.childProcs {
|
||||||
procs = append(procs, &protos.ProcessDescription{
|
procs = append(procs, &protos.ProcessDescription{
|
||||||
Name: child.name,
|
Name: child.name,
|
||||||
Args: child.cmd.Args,
|
Args: child.cmd.Args,
|
||||||
Version: child.version,
|
Version: child.version,
|
||||||
State: child.state,
|
State: child.getState(),
|
||||||
Pid: int32(child.cmd.Process.Pid),
|
Pid: int32(child.cmd.Process.Pid),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var deploys []*protos.DeployedVersions
|
|
||||||
for name, prog := range hc.deploys {
|
for name, prog := range hc.deploys {
|
||||||
deploys = append(deploys, &protos.DeployedVersions{
|
deploys = append(deploys, &protos.DeployedVersions{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -182,14 +255,17 @@ func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryReque
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hn, _ := os.Hostname()
|
||||||
return &protos.OperationQueryRequest{
|
return &protos.OperationQueryRequest{
|
||||||
Hostname: hn,
|
Hostname: hn,
|
||||||
|
PublicIp: os.Getenv("PUBIP"),
|
||||||
|
PrivateIp: os.Getenv("PRVIP"),
|
||||||
Procs: procs,
|
Procs: procs,
|
||||||
Deploys: deploys,
|
Deploys: deploys,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient() (HoustonClient, error) {
|
func NewClient(standalone bool) (HoustonClient, error) {
|
||||||
clientConfig, err := loadClientConfig()
|
clientConfig, err := loadClientConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -238,12 +314,21 @@ func NewClient() (HoustonClient, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ver, _ := os.ReadFile("@version")
|
||||||
|
if len(ver) == 0 {
|
||||||
|
ver = []byte("0.0.0")
|
||||||
|
}
|
||||||
|
|
||||||
hc := &houstonClient{
|
hc := &houstonClient{
|
||||||
config: clientConfig,
|
config: clientConfig,
|
||||||
clientChan: make(chan *grpc.ClientConn),
|
clientChan: make(chan *grpc.ClientConn),
|
||||||
extraMetrics: unsafe.Pointer(&map[string]float32{}),
|
extraMetrics: unsafe.Pointer(&map[string]float32{}),
|
||||||
deploys: deploys,
|
deploys: deploys,
|
||||||
timestamp: exefi.ModTime().String(),
|
timestamp: exefi.ModTime().String(),
|
||||||
|
version: string(ver),
|
||||||
|
standalone: standalone,
|
||||||
|
uploadChan: make(chan uploadRequest, 100),
|
||||||
|
siblingProcIndex: make(map[string]uint64),
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
@ -251,7 +336,9 @@ func NewClient() (HoustonClient, error) {
|
|||||||
exitChan := make(chan *exec.Cmd, 10)
|
exitChan := make(chan *exec.Cmd, 10)
|
||||||
operationChan := make(chan *protos.OperationQueryResponse, 10)
|
operationChan := make(chan *protos.OperationQueryResponse, 10)
|
||||||
hc.wg.Add(1)
|
hc.wg.Add(1)
|
||||||
|
ignoreRecover := int32(0)
|
||||||
|
|
||||||
|
// autorun 처리
|
||||||
go func() {
|
go func() {
|
||||||
defer hc.wg.Done()
|
defer hc.wg.Done()
|
||||||
|
|
||||||
@ -273,12 +360,13 @@ func NewClient() (HoustonClient, error) {
|
|||||||
|
|
||||||
case newClient := <-hc.clientChan:
|
case newClient := <-hc.clientChan:
|
||||||
op = protos.NewOperationClient(newClient)
|
op = protos.NewOperationClient(newClient)
|
||||||
|
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||||
|
|
||||||
case exited := <-exitChan:
|
case exited := <-exitChan:
|
||||||
var newprocs []*procmeta
|
var newprocs []*procmeta
|
||||||
for _, proc := range hc.childProcs {
|
for _, proc := range hc.childProcs {
|
||||||
if proc.cmd == exited {
|
if proc.cmd == exited {
|
||||||
if proc.state == protos.ProcessState_Running || proc.state == protos.ProcessState_Restart {
|
if proc.isState(protos.ProcessState_Running) || proc.isState(protos.ProcessState_Restart) {
|
||||||
go func(proc *procmeta) {
|
go func(proc *procmeta) {
|
||||||
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||||
proc.cmd.Process.Signal(os.Kill)
|
proc.cmd.Process.Signal(os.Kill)
|
||||||
@ -286,12 +374,20 @@ func NewClient() (HoustonClient, error) {
|
|||||||
proc.cmd.Wait()
|
proc.cmd.Wait()
|
||||||
proc.cmd.Process.Release()
|
proc.cmd.Process.Release()
|
||||||
|
|
||||||
if proc.state == protos.ProcessState_Restart {
|
if proc.isState(protos.ProcessState_Restart) {
|
||||||
hc.startChildProcess(&shared.StartProcessRequest{
|
if proc.keepLatest {
|
||||||
|
proc.version = "latest"
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := hc.startChildProcess(&shared.StartProcessRequest{
|
||||||
Version: proc.version,
|
Version: proc.version,
|
||||||
Name: proc.name,
|
Name: proc.name,
|
||||||
Args: proc.cmd.Args,
|
Args: proc.args,
|
||||||
}, op)
|
}); err != nil {
|
||||||
|
logger.ErrorWithCallStack(err)
|
||||||
|
} else {
|
||||||
|
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}(proc)
|
}(proc)
|
||||||
}
|
}
|
||||||
@ -303,40 +399,58 @@ func NewClient() (HoustonClient, error) {
|
|||||||
op.Refresh(ctx, hc.makeOperationQueryRequest())
|
op.Refresh(ctx, hc.makeOperationQueryRequest())
|
||||||
|
|
||||||
case resp := <-operationChan:
|
case resp := <-operationChan:
|
||||||
|
logger.Println("houton query operation :", resp.Operation)
|
||||||
|
|
||||||
switch shared.Operation(resp.Operation) {
|
switch shared.Operation(resp.Operation) {
|
||||||
case shared.Deploy:
|
case shared.Deploy:
|
||||||
var dr shared.DeployRequest
|
var dr shared.DeployRequest
|
||||||
unmarshal(&dr, resp.Args)
|
unmarshal(&dr, resp.Args)
|
||||||
if dr.Name == myname {
|
logger.Println("args :", dr)
|
||||||
if srcdir, replacer, err := hc.prepareUpdateSelf(&dr); err == nil {
|
|
||||||
args := []string{
|
hn, _ := os.Hostname()
|
||||||
fmt.Sprintf("%d", os.Getpid()),
|
|
||||||
srcdir,
|
if err := hc.deploy(&dr, func(dp *protos.DeployingProgress) {
|
||||||
filepath.ToSlash(os.Args[0]),
|
dp.Hostname = hn
|
||||||
|
dp.Name = dr.Name
|
||||||
|
dp.Version = dr.Version
|
||||||
|
op.ReportDeployingProgress(ctx, dp)
|
||||||
|
}); err == nil {
|
||||||
|
if dr.Name == "houston" {
|
||||||
|
// houston_update_dir 다운로드가 완료되었으므로 종료
|
||||||
|
// 종료되고나면 스크립트가 알아서 재 실행
|
||||||
|
hc.Shutdown()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
args = append(args, os.Args[1:]...)
|
|
||||||
cmd := exec.Command(replacer, args...)
|
|
||||||
if err := cmd.Start(); err != nil {
|
|
||||||
logger.Println(err)
|
|
||||||
} else {
|
|
||||||
hc.shutdownFunc()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.Println(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err := hc.deploy(&dr); err == nil {
|
|
||||||
prog := gatherDeployedPrograms(hc.config.StorageRoot, dr.Name)
|
prog := gatherDeployedPrograms(hc.config.StorageRoot, dr.Name)
|
||||||
hc.deploys[dr.Name] = prog
|
hc.deploys[dr.Name] = prog
|
||||||
op.Refresh(ctx, hc.makeOperationQueryRequest())
|
op.Refresh(ctx, hc.makeOperationQueryRequest())
|
||||||
|
|
||||||
|
op.ReportDeployingProgress(ctx, &protos.DeployingProgress{
|
||||||
|
Hostname: hn,
|
||||||
|
Name: dr.Name,
|
||||||
|
Version: dr.Version,
|
||||||
|
State: "success",
|
||||||
|
Progress: 0,
|
||||||
|
Total: 0,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
logger.Println(err)
|
logger.Println(err)
|
||||||
}
|
|
||||||
|
op.ReportDeployingProgress(ctx, &protos.DeployingProgress{
|
||||||
|
Hostname: hn,
|
||||||
|
Name: dr.Name,
|
||||||
|
Version: dr.Version,
|
||||||
|
State: "fail:" + err.Error(),
|
||||||
|
Progress: 0,
|
||||||
|
Total: 0,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
case shared.Withdraw:
|
case shared.Withdraw:
|
||||||
var wr shared.WithdrawRequest
|
var wr shared.WithdrawRequest
|
||||||
unmarshal(&wr, resp.Args)
|
unmarshal(&wr, resp.Args)
|
||||||
|
logger.Println("args :", wr)
|
||||||
|
|
||||||
err := hc.withdraw(&wr)
|
err := hc.withdraw(&wr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
prog := gatherDeployedPrograms(hc.config.StorageRoot, wr.Name)
|
prog := gatherDeployedPrograms(hc.config.StorageRoot, wr.Name)
|
||||||
@ -353,13 +467,19 @@ func NewClient() (HoustonClient, error) {
|
|||||||
case shared.Start:
|
case shared.Start:
|
||||||
var sr shared.StartProcessRequest
|
var sr shared.StartProcessRequest
|
||||||
unmarshal(&sr, resp.Args)
|
unmarshal(&sr, resp.Args)
|
||||||
if err := hc.startChildProcess(&sr, op); err != nil {
|
logger.Println("args :", sr)
|
||||||
logger.Println(err)
|
|
||||||
|
if err := hc.startChildProcess(&sr); err != nil {
|
||||||
|
logger.ErrorWithCallStack(err)
|
||||||
|
} else {
|
||||||
|
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||||
}
|
}
|
||||||
|
|
||||||
case shared.Stop:
|
case shared.Stop:
|
||||||
var sr shared.StopProcessRequest
|
var sr shared.StopProcessRequest
|
||||||
unmarshal(&sr, resp.Args)
|
unmarshal(&sr, resp.Args)
|
||||||
|
logger.Println("args :", sr)
|
||||||
|
|
||||||
if err := hc.stopChildProcess(&sr, op); err != nil {
|
if err := hc.stopChildProcess(&sr, op); err != nil {
|
||||||
logger.Println(err)
|
logger.Println(err)
|
||||||
}
|
}
|
||||||
@ -367,22 +487,71 @@ func NewClient() (HoustonClient, error) {
|
|||||||
case shared.Restart:
|
case shared.Restart:
|
||||||
var rr shared.RestartProcessRequest
|
var rr shared.RestartProcessRequest
|
||||||
unmarshal(&rr, resp.Args)
|
unmarshal(&rr, resp.Args)
|
||||||
|
logger.Println("args :", rr)
|
||||||
|
|
||||||
if err := hc.restartChildProcess(&rr, op); err != nil {
|
if err := hc.restartChildProcess(&rr, op); err != nil {
|
||||||
logger.Println(err)
|
logger.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
case shared.Upload:
|
case shared.Exception:
|
||||||
var ur shared.UploadRequest
|
idstr := resp.Args["id"]
|
||||||
unmarshal(&ur, resp.Args)
|
id64, _ := strconv.ParseInt(idstr, 10, 0)
|
||||||
if err := hc.uploadFiles(&ur); err != nil {
|
id := int32(id64)
|
||||||
logger.Println(err)
|
|
||||||
|
var found *procmeta
|
||||||
|
hc.childProcs = gocommon.ShrinkSlice(hc.childProcs, func(e *procmeta) bool {
|
||||||
|
if e.id == id {
|
||||||
|
found = e
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
if found != nil {
|
||||||
|
found.cmd.Wait()
|
||||||
|
found.cmd.Process.Release()
|
||||||
|
|
||||||
|
if found.recover && atomic.LoadInt32(&ignoreRecover) == 0 {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
sr := shared.StartProcessRequest{
|
||||||
|
Name: found.name,
|
||||||
|
Version: found.version,
|
||||||
|
Args: found.args,
|
||||||
|
AutoRestart: found.recover,
|
||||||
|
OutputLogFile: found.logfile,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := hc.startChildProcess(&sr); err != nil {
|
||||||
|
logger.Println("startChildProcess failed by autorun :", err)
|
||||||
|
logger.ErrorWithCallStack(err)
|
||||||
|
} else {
|
||||||
|
logger.Println("recover success :", sr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if op != nil {
|
||||||
|
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
hc.shutdownFunc = cancel
|
hc.shutdownFunc = func() {
|
||||||
|
// child process 강제 종료
|
||||||
|
atomic.StoreInt32(&ignoreRecover, 1)
|
||||||
|
|
||||||
|
for _, procmeta := range hc.childProcs {
|
||||||
|
if procmeta.cmd != nil && procmeta.cmd.Process != nil {
|
||||||
|
procmeta.cmd.Process.Signal(os.Kill)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
|
||||||
hc.exitChan = exitChan
|
hc.exitChan = exitChan
|
||||||
hc.ctx = ctx
|
hc.ctx = ctx
|
||||||
hc.operationChan = operationChan
|
hc.operationChan = operationChan
|
||||||
@ -390,6 +559,59 @@ func NewClient() (HoustonClient, error) {
|
|||||||
return hc, nil
|
return hc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func uploadSafe(url, filePath, name, version string) error {
|
||||||
|
defer func() {
|
||||||
|
r := recover()
|
||||||
|
if r != nil {
|
||||||
|
logger.Error(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
t, err := times.Stat(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if file == nil {
|
||||||
|
return errors.New("upload file is missing :" + filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// hc.config.HttpAddress+"/upload",
|
||||||
|
httpreq, err := http.NewRequest("POST", url, file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
hn, _ := os.Hostname()
|
||||||
|
// createTime := file.
|
||||||
|
httpreq.Header.Set("Houston-Service-Name", name)
|
||||||
|
httpreq.Header.Set("Houston-Service-Version", version)
|
||||||
|
httpreq.Header.Set("Houston-Service-Filename", t.BirthTime().UTC().Format(time.DateOnly)+"."+hn+path.Ext(filePath))
|
||||||
|
httpreq.Header.Set("Content-Type", "application/zip")
|
||||||
|
resp, err := http.DefaultClient.Do(httpreq)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("upload file failed. response code : %s, %d", filePath, resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.Remove(filePath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (hc *houstonClient) Start() {
|
func (hc *houstonClient) Start() {
|
||||||
// receive from stream
|
// receive from stream
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -398,7 +620,7 @@ func (hc *houstonClient) Start() {
|
|||||||
for _, proc := range hc.childProcs {
|
for _, proc := range hc.childProcs {
|
||||||
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||||
proc.cmd.Process.Signal(os.Kill)
|
proc.cmd.Process.Signal(os.Kill)
|
||||||
proc.state = protos.ProcessState_Stopping
|
proc.setState(protos.ProcessState_Stopping)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,6 +628,20 @@ func (hc *houstonClient) Start() {
|
|||||||
proc.cmd.Wait()
|
proc.cmd.Wait()
|
||||||
proc.cmd.Process.Release()
|
proc.cmd.Process.Release()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(hc.uploadChan)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
// upload 고루틴
|
||||||
|
url := hc.config.HttpAddress + "/upload"
|
||||||
|
for req := range hc.uploadChan {
|
||||||
|
logger.Println("uploadSafe :", req)
|
||||||
|
err := uploadSafe(url, req.logFile, req.name, req.version)
|
||||||
|
if err != nil {
|
||||||
|
logger.Println("uploadSafe return err :", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
@ -419,6 +655,42 @@ func (hc *houstonClient) Start() {
|
|||||||
|
|
||||||
var client *grpc.ClientConn
|
var client *grpc.ClientConn
|
||||||
reconnCount := 0
|
reconnCount := 0
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
|
if autorun != nil && len(*autorun) > 0 {
|
||||||
|
hascount := strings.Split(*autorun, "/")
|
||||||
|
var service string
|
||||||
|
count := 1
|
||||||
|
if len(hascount) > 1 {
|
||||||
|
service = hascount[0]
|
||||||
|
if len(hascount[1]) > 0 {
|
||||||
|
count, _ = strconv.Atoi(hascount[1])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
service = *autorun
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd, ok := hc.config.Autorun[service]; ok {
|
||||||
|
// service 서비스
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
|
sr := shared.StartProcessRequest{
|
||||||
|
Name: service,
|
||||||
|
Version: cmd.Version,
|
||||||
|
Args: append([]string{cmd.Exec}, cmd.Args...),
|
||||||
|
AutoRestart: cmd.AutoRestart,
|
||||||
|
OutputLogFile: cmd.OutputLogFile,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := hc.startChildProcess(&sr); err != nil {
|
||||||
|
logger.Println("startChildProcess failed by autorun :", err)
|
||||||
|
logger.ErrorWithCallStack(err)
|
||||||
|
} else {
|
||||||
|
logger.Println("autorun success :", sr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-hc.ctx.Done():
|
case <-hc.ctx.Done():
|
||||||
@ -431,10 +703,15 @@ func (hc *houstonClient) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reconnCount++
|
reconnCount++
|
||||||
|
|
||||||
|
var err error
|
||||||
dialContext, cancelDial := context.WithTimeout(context.Background(), 15*time.Second)
|
dialContext, cancelDial := context.WithTimeout(context.Background(), 15*time.Second)
|
||||||
client, _ = grpc.DialContext(dialContext, hc.config.GrpcAddress, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
client, err = grpc.DialContext(dialContext, hc.config.GrpcAddress, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
cancelDial()
|
cancelDial()
|
||||||
if client != nil {
|
|
||||||
|
if err != nil {
|
||||||
|
logger.Println("grpc.DialContext returns err :", err)
|
||||||
|
} else if client != nil {
|
||||||
reconnCount = 0
|
reconnCount = 0
|
||||||
logger.Println("grpc.DialContext succeeded")
|
logger.Println("grpc.DialContext succeeded")
|
||||||
hc.clientChan <- client
|
hc.clientChan <- client
|
||||||
@ -444,8 +721,9 @@ func (hc *houstonClient) Start() {
|
|||||||
if client != nil {
|
if client != nil {
|
||||||
err := hc.checkOperation(client)
|
err := hc.checkOperation(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Println("hc.checkUpdate failed :", err)
|
if status.Convert(err).Message() != status.Convert(context.Canceled).Message() {
|
||||||
|
logger.Println("grpc.DialContext hc.checkOperation failed :", err)
|
||||||
|
}
|
||||||
client = nil
|
client = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -486,7 +764,3 @@ func (hc *houstonClient) checkOperation(client *grpc.ClientConn) error {
|
|||||||
hc.operationChan <- update
|
hc.operationChan <- update
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *houstonClient) SetReportMetrics(extra map[string]float32) {
|
|
||||||
atomic.StorePointer(&hc.extraMetrics, unsafe.Pointer(&extra))
|
|
||||||
}
|
|
||||||
|
|||||||
26
client/client_linux.go
Normal file
26
client/client_linux.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
func set_affinity(pid int, cpu int) {
|
||||||
|
var cpuset unix.CPUSet
|
||||||
|
err := unix.SchedGetaffinity(pid, &cpuset)
|
||||||
|
if err != nil {
|
||||||
|
logger.Println("SchedGetaffinity failed :", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
count := cpuset.Count()
|
||||||
|
cpuset.Zero()
|
||||||
|
cpuset.Set(cpu % count)
|
||||||
|
|
||||||
|
err = unix.SchedSetaffinity(pid, &cpuset)
|
||||||
|
if err != nil {
|
||||||
|
logger.Println("SchedSetaffinity failed :", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
41
client/client_misc.go
Normal file
41
client/client_misc.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package client
|
||||||
|
|
||||||
|
func set_affinity(pid int, cpu int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// package main
|
||||||
|
|
||||||
|
// import (
|
||||||
|
// "fmt"
|
||||||
|
// "syscall"
|
||||||
|
// "time"
|
||||||
|
// "unsafe"
|
||||||
|
// )
|
||||||
|
|
||||||
|
// func main() {
|
||||||
|
// var mask uintptr
|
||||||
|
|
||||||
|
// // Get the current CPU affinity of the process
|
||||||
|
// if _, _, err := syscall.RawSyscall(syscall.SYS_SCHED_GETAFFINITY, 0, uintptr(unsafe.Sizeof(mask)), uintptr(unsafe.Pointer(&mask))); err != 0 {
|
||||||
|
// fmt.Println("Failed to get CPU affinity:", err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// fmt.Println("Current CPU affinity:", mask)
|
||||||
|
|
||||||
|
// // Set the new CPU affinity
|
||||||
|
// mask = 3
|
||||||
|
// if _, _, err := syscall.RawSyscall(syscall.SYS_SCHED_SETAFFINITY, 0, uintptr(unsafe.Sizeof(mask)), uintptr(unsafe.Pointer(&mask))); err != 0 {
|
||||||
|
// fmt.Println("Failed to set CPU affinity:", err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// fmt.Println("New CPU affinity:", mask)
|
||||||
|
|
||||||
|
// // some code
|
||||||
|
// for {
|
||||||
|
// println("Hello, World!")
|
||||||
|
// time.Sleep(1 * time.Second)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
35
client/client_test.go
Normal file
35
client/client_test.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_houstonClient_Start(t *testing.T) {
|
||||||
|
tc := make(chan int, 1000)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
// receive
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
for v := range tc {
|
||||||
|
fmt.Println(v)
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
// send
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
tc <- i
|
||||||
|
}
|
||||||
|
close(tc)
|
||||||
|
fmt.Println("channel close called")
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
142
client/deploy.go
142
client/deploy.go
@ -3,6 +3,8 @@ package client
|
|||||||
import (
|
import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -11,17 +13,41 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
"repositories.action2quare.com/ayo/houston/shared"
|
"repositories.action2quare.com/ayo/houston/shared"
|
||||||
|
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||||
|
|
||||||
"golang.org/x/text/encoding/korean"
|
"golang.org/x/text/encoding/korean"
|
||||||
|
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func download(dir string, urlpath string, accessToken string) (target string, err error) {
|
const (
|
||||||
|
houston_update_dir = "./houston.update"
|
||||||
|
)
|
||||||
|
|
||||||
|
func pof2(x int64, min int64) (out int64) {
|
||||||
|
out = 1
|
||||||
|
org := x
|
||||||
|
for (x >> 1) > 0 {
|
||||||
|
out = out << 1
|
||||||
|
x = x >> 1
|
||||||
|
}
|
||||||
|
if org > out {
|
||||||
|
out = out << 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if out < min {
|
||||||
|
out = min
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func download(dir string, urlpath string, accessToken string, cb func(int64, int64)) (target string, err error) {
|
||||||
logger.Println("start downloading", dir, urlpath)
|
logger.Println("start downloading", dir, urlpath)
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -38,6 +64,7 @@ func download(dir string, urlpath string, accessToken string) (target string, er
|
|||||||
|
|
||||||
req, _ := http.NewRequest("GET", urlpath, nil)
|
req, _ := http.NewRequest("GET", urlpath, nil)
|
||||||
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51")
|
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51")
|
||||||
|
req.Header.Add("As-X-UrlHash", accessToken)
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -48,16 +75,34 @@ func download(dir string, urlpath string, accessToken string) (target string, er
|
|||||||
return "", fmt.Errorf("download failed : %d %s", resp.StatusCode, parsed.Path)
|
return "", fmt.Errorf("download failed : %d %s", resp.StatusCode, parsed.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := os.Create(path.Join(dir, path.Base(parsed.Path)))
|
out, err := os.Create(path.Join(dir, path.Base(filepath.ToSlash(parsed.Path))))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
_, err = io.Copy(out, resp.Body)
|
cl := resp.Header.Get("Content-Length")
|
||||||
|
totalLength, _ := strconv.ParseInt(cl, 10, 0)
|
||||||
|
totalWritten := int64(0)
|
||||||
|
chunkSize := pof2(totalLength/100, 1024*1024)
|
||||||
|
if cb != nil {
|
||||||
|
cb(0, totalLength)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
written, err := io.CopyN(out, resp.Body, chunkSize)
|
||||||
|
totalWritten += written
|
||||||
|
if cb != nil {
|
||||||
|
cb(totalWritten, totalLength)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return filepath.ToSlash(out.Name()), nil
|
return filepath.ToSlash(out.Name()), nil
|
||||||
}
|
}
|
||||||
@ -176,13 +221,7 @@ func (hc *houstonClient) prepareDeploy(name string, version string) (destPath st
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
verpath := path.Join(hc.config.StorageRoot, name, version)
|
verpath := path.Join(hc.config.StorageRoot, name, version)
|
||||||
if _, err := os.Stat(verpath); os.IsNotExist(err) {
|
if _, err := os.Stat(verpath); !os.IsNotExist(err) {
|
||||||
// 없네? 만들면 된다.
|
|
||||||
err = os.MkdirAll(verpath, 0775)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 있네? 재배포 가능한가?
|
// 있네? 재배포 가능한가?
|
||||||
for _, child := range hc.childProcs {
|
for _, child := range hc.childProcs {
|
||||||
if child.version == version && child.name == name {
|
if child.version == version && child.name == name {
|
||||||
@ -204,7 +243,7 @@ func (hc *houstonClient) makeDownloadUrl(rel string) string {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func copy(src, dst string) error {
|
func copyfile(src, dst string) error {
|
||||||
fi, err := os.Stat(src)
|
fi, err := os.Stat(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -241,54 +280,51 @@ func copy(src, dst string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *houstonClient) prepareUpdateSelf(req *shared.DeployRequest) (srcdir string, replacer string, err error) {
|
func (hc *houstonClient) deploy(req *shared.DeployRequest, cb func(*protos.DeployingProgress)) (err error) {
|
||||||
// 내가 스스로 업데이트
|
|
||||||
// 다운로드 받고 압축 푼 다음에 교체용 프로세스 시작
|
|
||||||
tempdir, err := os.MkdirTemp(os.TempDir(), "*")
|
|
||||||
if err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
fname, err := download(tempdir, hc.makeDownloadUrl(req.Url), req.AccessToken)
|
|
||||||
if err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch path.Ext(fname) {
|
|
||||||
case ".zip":
|
|
||||||
err = unzip(fname)
|
|
||||||
case ".tar":
|
|
||||||
err = untar(fname)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
selfname, _ := os.Executable()
|
|
||||||
srcreplacer := path.Join(path.Dir(fname), "replacer") + path.Ext(selfname)
|
|
||||||
replacer = "./" + filepath.ToSlash("replacer"+path.Ext(selfname))
|
|
||||||
err = copy(srcreplacer, replacer)
|
|
||||||
if err == nil {
|
|
||||||
err = os.Chmod(replacer, 0775)
|
|
||||||
}
|
|
||||||
|
|
||||||
// replacer먼저 가져옴
|
|
||||||
return filepath.ToSlash(tempdir), replacer, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hc *houstonClient) deploy(req *shared.DeployRequest) error {
|
|
||||||
logger.Println("start deploying")
|
logger.Println("start deploying")
|
||||||
root, err := hc.prepareDeploy(req.Name, req.Version)
|
|
||||||
|
var root string
|
||||||
|
if req.Name == "houston" {
|
||||||
|
// houston은 버전없이 houston_update_dir폴더로 다운로드
|
||||||
|
root = houston_update_dir
|
||||||
|
// 이미 houston_update_dir가 있을 수도 있으므로 폴더채로 삭제
|
||||||
|
os.RemoveAll(houston_update_dir)
|
||||||
|
} else {
|
||||||
|
root, err = hc.prepareDeploy(req.Name, req.Version)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.MkdirAll(root, 0775)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// verpath에 배포 시작
|
// verpath에 배포 시작
|
||||||
fname, err := download(root, hc.makeDownloadUrl(req.Url), req.AccessToken)
|
h := md5.New()
|
||||||
|
h.Write([]byte(strings.Trim(req.Url, "/")))
|
||||||
|
at := hex.EncodeToString(h.Sum(nil))
|
||||||
|
var fname string
|
||||||
|
fname, err = download(root, hc.makeDownloadUrl(req.Url), at, func(written int64, total int64) {
|
||||||
|
prog := protos.DeployingProgress{
|
||||||
|
State: "download",
|
||||||
|
Progress: written,
|
||||||
|
Total: total,
|
||||||
|
}
|
||||||
|
cb(&prog)
|
||||||
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cb(&protos.DeployingProgress{
|
||||||
|
State: "unpack",
|
||||||
|
Progress: 0,
|
||||||
|
Total: 0,
|
||||||
|
})
|
||||||
|
|
||||||
switch path.Ext(fname) {
|
switch path.Ext(fname) {
|
||||||
case ".zip":
|
case ".zip":
|
||||||
err = unzip(fname)
|
err = unzip(fname)
|
||||||
@ -296,9 +332,13 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest) error {
|
|||||||
err = untar(fname)
|
err = untar(fname)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil && len(req.Config) > 0 {
|
if err == nil && len(req.Config) > 0 && req.Name != "houston" {
|
||||||
// config.json도 다운로드
|
// config.json도 다운로드
|
||||||
_, err = download(root, hc.makeDownloadUrl(req.Config), req.AccessToken)
|
h := md5.New()
|
||||||
|
h.Write([]byte(strings.Trim(req.Config, "/")))
|
||||||
|
at = hex.EncodeToString(h.Sum(nil))
|
||||||
|
|
||||||
|
_, err = download(root, hc.makeDownloadUrl(req.Config), at, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|||||||
9
client/deploy_test.go
Normal file
9
client/deploy_test.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDownload(t *testing.T) {
|
||||||
|
|
||||||
|
}
|
||||||
133
client/node_exporter.go
Normal file
133
client/node_exporter.go
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
stdlog "log"
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/go-kit/log"
|
||||||
|
"github.com/go-kit/log/level"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
promcollectors "github.com/prometheus/client_golang/prometheus/collectors"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
"github.com/prometheus/common/version"
|
||||||
|
"github.com/prometheus/node_exporter/collector"
|
||||||
|
)
|
||||||
|
|
||||||
|
// handler wraps an unfiltered http.Handler but uses a filtered handler,
|
||||||
|
// created on the fly, if filtering is requested. Create instances with
|
||||||
|
// newHandler.
|
||||||
|
type handler struct {
|
||||||
|
unfilteredHandler http.Handler
|
||||||
|
// exporterMetricsRegistry is a separate registry for the metrics about
|
||||||
|
// the exporter itself.
|
||||||
|
exporterMetricsRegistry *prometheus.Registry
|
||||||
|
includeExporterMetrics bool
|
||||||
|
maxRequests int
|
||||||
|
logger log.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHandlerForNodeExporter(includeExporterMetrics bool, maxRequests int, logger log.Logger) *handler {
|
||||||
|
h := &handler{
|
||||||
|
exporterMetricsRegistry: prometheus.NewRegistry(),
|
||||||
|
includeExporterMetrics: includeExporterMetrics,
|
||||||
|
maxRequests: maxRequests,
|
||||||
|
logger: logger,
|
||||||
|
}
|
||||||
|
if h.includeExporterMetrics {
|
||||||
|
h.exporterMetricsRegistry.MustRegister(
|
||||||
|
promcollectors.NewProcessCollector(promcollectors.ProcessCollectorOpts{}),
|
||||||
|
promcollectors.NewGoCollector(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if innerHandler, err := h.innerHandler(); err != nil {
|
||||||
|
panic(fmt.Sprintf("Couldn't create metrics handler: %s", err))
|
||||||
|
} else {
|
||||||
|
h.unfilteredHandler = innerHandler
|
||||||
|
}
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServeHTTP implements http.Handler.
|
||||||
|
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
filters := r.URL.Query()["collect[]"]
|
||||||
|
level.Debug(h.logger).Log("msg", "collect query:", "filters", filters)
|
||||||
|
|
||||||
|
if len(filters) == 0 {
|
||||||
|
// No filters, use the prepared unfiltered handler.
|
||||||
|
h.unfilteredHandler.ServeHTTP(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// To serve filtered metrics, we create a filtering handler on the fly.
|
||||||
|
filteredHandler, err := h.innerHandler(filters...)
|
||||||
|
if err != nil {
|
||||||
|
level.Warn(h.logger).Log("msg", "Couldn't create filtered metrics handler:", "err", err)
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
filteredHandler.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
// innerHandler is used to create both the one unfiltered http.Handler to be
|
||||||
|
// wrapped by the outer handler and also the filtered handlers created on the
|
||||||
|
// fly. The former is accomplished by calling innerHandler without any arguments
|
||||||
|
// (in which case it will log all the collectors enabled via command-line
|
||||||
|
// flags).
|
||||||
|
func (h *handler) innerHandler(filters ...string) (http.Handler, error) {
|
||||||
|
nc, err := collector.NewNodeCollector(h.logger, filters...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("couldn't create collector: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only log the creation of an unfiltered handler, which should happen
|
||||||
|
// only once upon startup.
|
||||||
|
if len(filters) == 0 {
|
||||||
|
level.Info(h.logger).Log("msg", "Enabled collectors")
|
||||||
|
collectors := []string{}
|
||||||
|
for n := range nc.Collectors {
|
||||||
|
collectors = append(collectors, n)
|
||||||
|
}
|
||||||
|
sort.Strings(collectors)
|
||||||
|
for _, c := range collectors {
|
||||||
|
level.Info(h.logger).Log("collector", c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r := prometheus.NewRegistry()
|
||||||
|
r.MustRegister(version.NewCollector("node_exporter"))
|
||||||
|
if err := r.Register(nc); err != nil {
|
||||||
|
return nil, fmt.Errorf("couldn't register node collector: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var handler http.Handler
|
||||||
|
if h.includeExporterMetrics {
|
||||||
|
handler = promhttp.HandlerFor(
|
||||||
|
prometheus.Gatherers{h.exporterMetricsRegistry, r},
|
||||||
|
promhttp.HandlerOpts{
|
||||||
|
ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0),
|
||||||
|
ErrorHandling: promhttp.ContinueOnError,
|
||||||
|
MaxRequestsInFlight: h.maxRequests,
|
||||||
|
Registry: h.exporterMetricsRegistry,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
// Note that we have to use h.exporterMetricsRegistry here to
|
||||||
|
// use the same promhttp metrics for all expositions.
|
||||||
|
handler = promhttp.InstrumentMetricHandler(
|
||||||
|
h.exporterMetricsRegistry, handler,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
handler = promhttp.HandlerFor(
|
||||||
|
r,
|
||||||
|
promhttp.HandlerOpts{
|
||||||
|
ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0),
|
||||||
|
ErrorHandling: promhttp.ContinueOnError,
|
||||||
|
MaxRequestsInFlight: h.maxRequests,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return handler, nil
|
||||||
|
}
|
||||||
@ -2,22 +2,26 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime/debug"
|
"regexp"
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Knetic/govaluate"
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/metric"
|
||||||
"repositories.action2quare.com/ayo/houston/shared"
|
"repositories.action2quare.com/ayo/houston/shared"
|
||||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||||
)
|
)
|
||||||
@ -38,63 +42,43 @@ func lastExecutionArgs(verpath string) []string {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
var errUploadZipLogFailed = errors.New("not ok")
|
func (hc *houstonClient) uploadToAppendLog(logFile string, name string, version string) {
|
||||||
|
hc.uploadChan <- uploadRequest{
|
||||||
|
logFile: logFile,
|
||||||
|
name: name,
|
||||||
|
version: version,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (hc *houstonClient) uploadZipLogFile(zipFile string, name string, version string) error {
|
func findMatchFiles(storageRoot, name, version, filter string) (string, []string) {
|
||||||
zf, err := os.Open(zipFile)
|
root := path.Join(storageRoot, name, version)
|
||||||
|
matches, err := filepath.Glob(path.Join(root, filter))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return "", nil
|
||||||
}
|
|
||||||
|
|
||||||
if zf == nil {
|
|
||||||
return errUploadZipLogFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
defer zf.Close()
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", hc.config.HttpAddress+"/upload", zf)
|
|
||||||
if err != nil {
|
|
||||||
logger.Println(err)
|
|
||||||
}
|
|
||||||
req.Header.Set("Houston-Service-Name", name)
|
|
||||||
req.Header.Set("Houston-Service-Version", version)
|
|
||||||
req.Header.Set("Houston-Service-Filename", path.Base(zipFile))
|
|
||||||
req.Header.Set("Content-Type", "application/zip")
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return errUploadZipLogFailed
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func zipLogFiles(storageRoot string, req *shared.UploadRequest, start, except string) (string, []string, error) {
|
|
||||||
root := path.Join(storageRoot, req.Name, req.Version)
|
|
||||||
matches, err := filepath.Glob(path.Join(root, req.Filter))
|
|
||||||
if err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
return "", nil, nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, file := range matches {
|
root = path.Join(root, path.Dir(filter))
|
||||||
|
out := make([]string, 0, len(matches))
|
||||||
|
for _, file := range matches {
|
||||||
file = filepath.ToSlash(file)
|
file = filepath.ToSlash(file)
|
||||||
matches[i] = file
|
if file == root {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
root = path.Join(root, path.Dir(req.Filter))
|
out = append(out, file)
|
||||||
zipFileName := path.Join(os.TempDir(), path.Base(matches[0])) + ".zip"
|
}
|
||||||
f, err := os.OpenFile(zipFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600)
|
slices.Sort(out)
|
||||||
|
return root, out
|
||||||
|
}
|
||||||
|
|
||||||
|
func zipCompressFiles(root string, matches []string) (string, error) {
|
||||||
|
f, err := os.CreateTemp(os.TempDir(), "*.zip")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
@ -102,93 +86,170 @@ func zipLogFiles(storageRoot string, req *shared.UploadRequest, start, except st
|
|||||||
defer w.Close()
|
defer w.Close()
|
||||||
|
|
||||||
oldestFile := ""
|
oldestFile := ""
|
||||||
for _, file := range matches {
|
for i, file := range matches {
|
||||||
if file == root {
|
if fi, err := os.Lstat(file); err == nil {
|
||||||
|
if (fi.Mode() & os.ModeSymlink) == os.ModeSymlink {
|
||||||
|
matches[i] = ""
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(except) > 0 && file >= except {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if len(start) > 0 && file < start {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(oldestFile) == 0 {
|
if len(oldestFile) == 0 {
|
||||||
oldestFile = path.Base(file)
|
oldestFile = path.Base(filepath.ToSlash(file))
|
||||||
}
|
}
|
||||||
|
|
||||||
relative := file[len(root)+1:]
|
relative := file[len(root)+1:]
|
||||||
fw, err := w.Create(relative)
|
fw, err := w.Create(relative)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Println(err)
|
return "", err
|
||||||
return "", nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
src, err := os.Open(file)
|
src, err := os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Println(err)
|
return "", err
|
||||||
return "", nil, err
|
|
||||||
}
|
}
|
||||||
defer src.Close()
|
defer src.Close()
|
||||||
|
|
||||||
if _, err = io.Copy(fw, src); err != nil {
|
if _, err = io.Copy(fw, src); err != nil {
|
||||||
logger.Println(err)
|
return "", err
|
||||||
return "", nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return f.Name(), matches, nil
|
return f.Name(), nil
|
||||||
// defer func() {
|
|
||||||
// tempname := f.Name()
|
|
||||||
// f.Close()
|
|
||||||
|
|
||||||
// resp, _ := http.Post(req.Url, "application/zip", f)
|
|
||||||
// if resp != nil && resp.Body != nil {
|
|
||||||
// resp.Body.Close()
|
|
||||||
// }
|
|
||||||
// os.Remove(tempname)
|
|
||||||
// if del, err := strconv.ParseBool(req.DeleteAfterUploaded); del && err == nil {
|
|
||||||
// for _, file := range matches {
|
|
||||||
// if strings.HasSuffix(file, except) {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// os.Remove(file)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }()
|
|
||||||
|
|
||||||
// Create a new zip archive.
|
|
||||||
|
|
||||||
//}(f)
|
|
||||||
|
|
||||||
//return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) *procmeta {
|
func prepareProcessLaunch(storageRoot string, req *shared.StartProcessRequest) (*procmeta, error) {
|
||||||
if len(req.Args) == 0 {
|
if len(req.Args) == 0 {
|
||||||
return nil
|
return nil, errors.New("args is empty")
|
||||||
}
|
}
|
||||||
verpath := path.Join(storageRoot, req.Name, req.Version)
|
|
||||||
|
foundVersion := req.Version
|
||||||
|
if req.Version == "latest" {
|
||||||
|
entries, err := os.ReadDir(path.Join(storageRoot, req.Name))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var latestTimestamp time.Time
|
||||||
|
var latestVersion string
|
||||||
|
for _, entry := range entries {
|
||||||
|
if !entry.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := entry.Info()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
createTime := fi.ModTime()
|
||||||
|
if latestTimestamp.Before(createTime) {
|
||||||
|
latestTimestamp = fi.ModTime()
|
||||||
|
latestVersion = fi.Name()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(latestVersion) > 0 {
|
||||||
|
foundVersion = latestVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
verpath := path.Join(storageRoot, req.Name, foundVersion)
|
||||||
fi, err := os.Stat(verpath)
|
fi, err := os.Stat(verpath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if err == nil && fi.IsDir() {
|
if fi.IsDir() {
|
||||||
req.Args[0] = "./" + path.Clean(strings.TrimPrefix(req.Args[0], "/"))
|
exefile := "./" + path.Clean(strings.TrimPrefix(req.Args[0], "/"))
|
||||||
os.Chmod(path.Join(verpath, req.Args[0]), 0777)
|
os.Chmod(path.Join(verpath, exefile), 0777)
|
||||||
|
|
||||||
|
exef, _ := os.Executable()
|
||||||
|
expanded := make([]string, len(req.Args))
|
||||||
|
for i, arg := range req.Args {
|
||||||
|
expanded[i] = os.ExpandEnv(arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
exename := path.Join(path.Dir(strings.ReplaceAll(exef, "\\", "/")), verpath, exefile)
|
||||||
|
|
||||||
|
logger.Println("exefile :", exefile)
|
||||||
|
logger.Println("verpath :", verpath)
|
||||||
|
logger.Println("exef :", exef)
|
||||||
|
logger.Println("path.Dir :", path.Dir(exef))
|
||||||
|
logger.Println("exename :", exename)
|
||||||
|
|
||||||
|
cmd := exec.Command(os.ExpandEnv(exename), expanded[1:]...)
|
||||||
|
|
||||||
cmd := exec.Command(req.Args[0], req.Args[1:]...)
|
|
||||||
cmd.Dir = verpath
|
cmd.Dir = verpath
|
||||||
stdin, _ := cmd.StdinPipe()
|
stdin, _ := cmd.StdinPipe()
|
||||||
|
|
||||||
|
seq++
|
||||||
return &procmeta{
|
return &procmeta{
|
||||||
|
id: seq,
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
name: req.Name,
|
name: req.Name,
|
||||||
version: req.Version,
|
args: req.Args,
|
||||||
state: protos.ProcessState_Stopped,
|
version: foundVersion,
|
||||||
|
recover: req.AutoRestart,
|
||||||
|
verpath: verpath,
|
||||||
|
state: int32(protos.ProcessState_Stopped),
|
||||||
stdin: stdin,
|
stdin: stdin,
|
||||||
logUploadChan: make(chan *shared.UploadRequest),
|
logfile: req.OutputLogFile,
|
||||||
buffers: bufferStack{cursor: 0},
|
keepLatest: req.Version == "latest",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func evaluateArgs(args []string, params map[string]any) ([]string, error) {
|
||||||
|
re := regexp.MustCompile(`\$\(\((.*?)\)\)`)
|
||||||
|
|
||||||
|
for i, input := range args {
|
||||||
|
matches := re.FindAllStringSubmatch(input, -1)
|
||||||
|
if len(matches) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, match := range matches {
|
||||||
|
if len(match) > 1 {
|
||||||
|
expression := strings.TrimSpace(match[1])
|
||||||
|
expr, err := govaluate.NewEvaluableExpression(expression)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := expr.Evaluate(params)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 원래 표현식을 결과로 대체
|
||||||
|
input = strings.Replace(input, match[0], fmt.Sprintf("%v", result), -1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
args[i] = input
|
||||||
|
}
|
||||||
|
|
||||||
|
return args, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseEnv(input []string) map[string]any {
|
||||||
|
output := make(map[string]any, len(input))
|
||||||
|
for _, envkv := range input {
|
||||||
|
kv := strings.SplitN(envkv, "=", 2)
|
||||||
|
parsed, err := strconv.ParseInt(kv[1], 10, 0)
|
||||||
|
if err == nil {
|
||||||
|
output[kv[0]] = parsed
|
||||||
|
} else {
|
||||||
|
parsed, err := strconv.ParseFloat(kv[1], 32)
|
||||||
|
if err == nil {
|
||||||
|
output[kv[0]] = parsed
|
||||||
|
} else {
|
||||||
|
output[kv[0]] = kv[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *houstonClient) launch(meta *procmeta) error {
|
func (hc *houstonClient) launch(meta *procmeta) error {
|
||||||
@ -201,141 +262,197 @@ func (hc *houstonClient) launch(meta *procmeta) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.MkdirAll(path.Join(meta.cmd.Dir, "logs"), 0775)
|
logfolder := path.Join(meta.verpath, "logs")
|
||||||
|
err = os.MkdirAll(logfolder, 0775)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
relayChan := make(chan struct {
|
logUploader := func(localctx context.Context, logfilePath string, logChan chan []byte) {
|
||||||
size int
|
var logFile *os.File
|
||||||
buf []byte
|
var logFilePath string
|
||||||
})
|
|
||||||
|
|
||||||
go func() {
|
ext := path.Ext(logfilePath)
|
||||||
defer func() {
|
head := logfilePath[:len(logfilePath)-len(ext)]
|
||||||
r := recover()
|
if len(head) > 0 && !strings.HasSuffix(head, "/") {
|
||||||
if r != nil {
|
head += "."
|
||||||
logger.Println(r)
|
}
|
||||||
debug.PrintStack()
|
|
||||||
|
writeLog := func(log []byte) {
|
||||||
|
if logFile == nil {
|
||||||
|
logFilePath = head + time.Now().UTC().Format("2006-01-02.150405") + ext
|
||||||
|
logFile, _ = os.OpenFile(logFilePath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
|
||||||
|
}
|
||||||
|
for written := 0; written < len(log); {
|
||||||
|
n, err := logFile.Write(log[written:])
|
||||||
|
if err != nil {
|
||||||
|
logger.Println("write log file failed :", logfilePath, err)
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
written += n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if logFile != nil {
|
||||||
|
logFile.Close()
|
||||||
|
logFile = nil
|
||||||
|
hc.uploadToAppendLog(logFilePath, meta.name, meta.version)
|
||||||
}
|
}
|
||||||
close(relayChan)
|
|
||||||
hc.exitChan <- meta.cmd
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
now := time.Now().UTC()
|
defer func() {
|
||||||
ext := path.Ext(meta.cmd.Args[0])
|
|
||||||
nameonly := path.Base(meta.cmd.Args[0])
|
|
||||||
if len(ext) > 0 {
|
|
||||||
nameonly = nameonly[:len(nameonly)-len(ext)]
|
|
||||||
}
|
|
||||||
ts := now.Format("2006-01-02T15-04-05")
|
|
||||||
stdPrefix := path.Join(meta.cmd.Dir, "logs", fmt.Sprintf("%s_%s", nameonly, ts))
|
|
||||||
logfile, _ := os.Create(stdPrefix + "_0.log")
|
|
||||||
defer logfile.Close()
|
|
||||||
|
|
||||||
logfileIdx := 0
|
|
||||||
for {
|
for {
|
||||||
thisFileSize := 0
|
|
||||||
switchToNextFile := func() string {
|
|
||||||
logfileIdx++
|
|
||||||
nextFile := fmt.Sprintf("%s_%d.log", stdPrefix, logfileIdx)
|
|
||||||
if nextLogfile, err := os.Create(nextFile); err == nil {
|
|
||||||
logfile.Close()
|
|
||||||
logfile = nextLogfile
|
|
||||||
}
|
|
||||||
thisFileSize = 0
|
|
||||||
return nextFile
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadStartFile := ""
|
|
||||||
select {
|
select {
|
||||||
case req := <-meta.logUploadChan:
|
case log := <-logChan:
|
||||||
nextFile := switchToNextFile()
|
writeLog(log)
|
||||||
startFile := uploadStartFile
|
|
||||||
uploadStartFile = nextFile
|
|
||||||
go func(startFile, nextFile string) {
|
|
||||||
zipFile, srcFiles, err := zipLogFiles(hc.config.StorageRoot, req, startFile, nextFile)
|
|
||||||
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
|
|
||||||
if err = hc.uploadZipLogFile(zipFile, meta.name, meta.version); err == nil {
|
|
||||||
for _, oldf := range srcFiles {
|
|
||||||
os.Remove(oldf)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.Println("uploadZipLogFile failed :", err)
|
|
||||||
}
|
|
||||||
} else if err != nil {
|
|
||||||
logger.Println("zipLogFiles failed :", err)
|
|
||||||
}
|
|
||||||
}(startFile, nextFile)
|
|
||||||
|
|
||||||
case bt := <-relayChan:
|
default:
|
||||||
if bt.buf == nil {
|
// logChan에 있는 모든 로그 소비
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logfile.Write(bt.buf[:bt.size])
|
|
||||||
logfile.Sync()
|
|
||||||
meta.buffers.push(bt.buf)
|
|
||||||
thisFileSize += bt.size
|
|
||||||
if thisFileSize > 10*1024*1024 {
|
|
||||||
switchToNextFile()
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
stdReader := func(r io.Reader) {
|
|
||||||
defer func() {
|
|
||||||
recover()
|
|
||||||
stdout.Close()
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
buff := meta.buffers.pop()
|
heartbeat := time.After(time.Minute)
|
||||||
size, err := r.Read(buff)
|
select {
|
||||||
if err != nil {
|
case <-localctx.Done():
|
||||||
relayChan <- struct {
|
return
|
||||||
size int
|
|
||||||
buf []byte
|
case <-heartbeat:
|
||||||
}{buf: nil}
|
heartbeat = time.After(time.Minute)
|
||||||
break
|
// 지금까지의 로그를 저장해서 업로드
|
||||||
|
if logFile != nil {
|
||||||
|
logFile.Close()
|
||||||
|
logFile = nil
|
||||||
|
hc.uploadToAppendLog(logFilePath, meta.name, meta.version)
|
||||||
}
|
}
|
||||||
if size > 0 {
|
|
||||||
relayChan <- struct {
|
case log := <-logChan:
|
||||||
size int
|
writeLog(log)
|
||||||
buf []byte
|
|
||||||
}{size: size, buf: buff}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
go stdReader(stderr)
|
stdReader := func(r io.ReadCloser, logfilePath string, verify func(buff []byte) bool) {
|
||||||
go stdReader(stdout)
|
defer func() {
|
||||||
|
reco := recover()
|
||||||
|
if reco != nil {
|
||||||
|
logger.Println(reco)
|
||||||
|
}
|
||||||
|
r.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
localctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
logChan := make(chan []byte, 1)
|
||||||
|
go logUploader(localctx, logfilePath, logChan)
|
||||||
|
|
||||||
|
reader := bufio.NewReader(r)
|
||||||
|
for {
|
||||||
|
buff, err := reader.ReadBytes('\n')
|
||||||
|
if err != nil {
|
||||||
|
logger.Println("ReadBytes at stdReader return err :", err, meta.name)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if verify(buff) {
|
||||||
|
if len(buff) > 0 {
|
||||||
|
logChan <- buff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var evalfile string
|
||||||
|
if len(meta.logfile) > 0 {
|
||||||
|
evalfile = path.Join(logfolder, meta.logfile)
|
||||||
|
} else {
|
||||||
|
evalfile = logfolder + "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
metricExporter := metric.NewPrometheusExport(hc.config.MetricNamespace)
|
||||||
|
defer metricExporter.Shutdown()
|
||||||
|
|
||||||
|
var metricBuffer []byte
|
||||||
|
readingMetric := false
|
||||||
|
stdReader(stdout, evalfile+".log", func(buff []byte) bool {
|
||||||
|
if readingMetric {
|
||||||
|
metricBuffer = append(metricBuffer, buff...)
|
||||||
|
} else if buff[0] == metric.METRIC_HEAD_INLINE {
|
||||||
|
readingMetric = true
|
||||||
|
metricBuffer = append(metricBuffer, buff[1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if readingMetric {
|
||||||
|
if metricBuffer[len(metricBuffer)-2] == metric.METRIC_TAIL_INLINE {
|
||||||
|
readingMetric = false
|
||||||
|
|
||||||
|
metricBuffer = metricBuffer[:len(metricBuffer)-2]
|
||||||
|
if metricBuffer[0] == '{' {
|
||||||
|
var desc metric.MetricDescription
|
||||||
|
if err := json.Unmarshal(metricBuffer, &desc); err != nil {
|
||||||
|
logger.Println("unmarshal metric failed :", err, string(metricBuffer))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if desc.ConstLabels == nil {
|
||||||
|
desc.ConstLabels = make(map[string]string)
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range hc.config.ConstLabels {
|
||||||
|
desc.ConstLabels[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
desc.ConstLabels["job"] = meta.name
|
||||||
|
metricExporter.RegisterMetric(&desc)
|
||||||
|
} else {
|
||||||
|
key, val := metric.ReadMetricValue(metricBuffer)
|
||||||
|
metricExporter.UpdateMetric(key, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
metricBuffer = metricBuffer[:0]
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
logger.Println("stdReader is terminated :", meta.name)
|
||||||
|
|
||||||
|
if meta.isState(protos.ProcessState_Running) {
|
||||||
|
// state는 running인데 종료됐으면 exception처리
|
||||||
|
hc.operationChan <- &protos.OperationQueryResponse{
|
||||||
|
Operation: string(shared.Exception),
|
||||||
|
Args: map[string]string{
|
||||||
|
"id": fmt.Sprintf("%d", meta.id),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
go stdReader(stderr, evalfile+".err", func([]byte) bool { return true })
|
||||||
|
|
||||||
|
logger.Println("startChildProcess :", meta.cmd.Args)
|
||||||
|
|
||||||
err = meta.cmd.Start()
|
err = meta.cmd.Start()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
meta.state = protos.ProcessState_Running
|
meta.setState(protos.ProcessState_Running)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var errPrepareprocessLaunchFailed = errors.New("prepareProcessLaunch failed")
|
func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest) error {
|
||||||
|
meta, err := prepareProcessLaunch(hc.config.StorageRoot, req)
|
||||||
func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op protos.OperationClient) error {
|
|
||||||
logger.Println("startChildProcess :", *req)
|
|
||||||
if req.Version == "latest" {
|
|
||||||
// 최신 버전을 찾음
|
|
||||||
latest, err := shared.FindLastestVersion(hc.config.StorageRoot, req.Name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Version = latest
|
|
||||||
}
|
|
||||||
|
|
||||||
meta := prepareProcessLaunch(hc.config.StorageRoot, req)
|
|
||||||
if meta == nil {
|
|
||||||
return errPrepareprocessLaunchFailed
|
|
||||||
}
|
|
||||||
if err := hc.launch(meta); err != nil {
|
if err := hc.launch(meta); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -344,108 +461,81 @@ func (hc *houstonClient) startChildProcess(req *shared.StartProcessRequest, op p
|
|||||||
vers := hc.deploys[req.Name]
|
vers := hc.deploys[req.Name]
|
||||||
for _, ver := range vers {
|
for _, ver := range vers {
|
||||||
if ver.Version == req.Version {
|
if ver.Version == req.Version {
|
||||||
ver.Args = meta.cmd.Args
|
ver.Args = meta.args
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if argfile, err := os.Create(path.Join(hc.config.StorageRoot, req.Name, "@args")); err == nil {
|
if argfile, err := os.Create(path.Join(hc.config.StorageRoot, req.Name, "@args")); err == nil {
|
||||||
enc := json.NewEncoder(argfile)
|
enc := json.NewEncoder(argfile)
|
||||||
enc.Encode(meta.cmd.Args)
|
enc.Encode(req.Args)
|
||||||
argfile.Close()
|
argfile.Close()
|
||||||
}
|
}
|
||||||
if argfile, err := os.Create(path.Join(hc.config.StorageRoot, req.Name, req.Version, "@args")); err == nil {
|
if argfile, err := os.Create(path.Join(hc.config.StorageRoot, req.Name, req.Version, "@args")); err == nil {
|
||||||
enc := json.NewEncoder(argfile)
|
enc := json.NewEncoder(argfile)
|
||||||
enc.Encode(meta.cmd.Args)
|
enc.Encode(req.Args)
|
||||||
argfile.Close()
|
argfile.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
hc.childProcs = append(hc.childProcs, meta)
|
hc.childProcs = append(hc.childProcs, meta)
|
||||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var errNoRunningProcess = errors.New("no running processed")
|
|
||||||
|
|
||||||
func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op protos.OperationClient) error {
|
func (hc *houstonClient) stopChildProcess(req *shared.StopProcessRequest, op protos.OperationClient) error {
|
||||||
if req.Version == "latest" {
|
killer := func(proc *procmeta) {
|
||||||
// 최신 버전을 찾음
|
proc.setState(protos.ProcessState_Stopping)
|
||||||
latest, err := shared.FindLastestVersion(hc.config.StorageRoot, req.Name)
|
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
||||||
if err != nil {
|
proc.cmd.Process.Signal(os.Kill)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Version = latest
|
go func() {
|
||||||
|
proc.cmd.Wait()
|
||||||
|
hc.operationChan <- &protos.OperationQueryResponse{
|
||||||
|
Operation: string(shared.Exception),
|
||||||
|
Args: map[string]string{
|
||||||
|
"id": fmt.Sprintf("%d", proc.id),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
var remains []*procmeta
|
|
||||||
var killing []*procmeta
|
|
||||||
for _, proc := range hc.childProcs {
|
for _, proc := range hc.childProcs {
|
||||||
if proc.state != protos.ProcessState_Running {
|
if !proc.isState(protos.ProcessState_Running) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Pid != 0 {
|
if req.Pid != 0 {
|
||||||
if req.Pid == int32(proc.cmd.Process.Pid) {
|
if req.Pid == int32(proc.cmd.Process.Pid) {
|
||||||
// 해당 pid만 제거
|
// 해당 pid만 제거
|
||||||
killing = append(killing, proc)
|
killer(proc)
|
||||||
} else {
|
|
||||||
remains = append(remains, proc)
|
|
||||||
}
|
}
|
||||||
} else if proc.name == req.Name {
|
} else if proc.name == req.Name {
|
||||||
if len(req.Version) == 0 {
|
if len(req.Version) == 0 {
|
||||||
// program 다 정지
|
// program 다 정지
|
||||||
killing = append(killing, proc)
|
killer(proc)
|
||||||
} else if req.Version == proc.version {
|
} else if req.Version == proc.version {
|
||||||
// program의 특정 버전만 정지
|
// program의 특정 버전만 정지
|
||||||
killing = append(killing, proc)
|
killer(proc)
|
||||||
} else {
|
|
||||||
// 해당 사항 없음
|
|
||||||
remains = append(remains, proc)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 해당 사항 없음
|
|
||||||
remains = append(remains, proc)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(killing) > 0 {
|
|
||||||
for _, proc := range killing {
|
|
||||||
proc.state = protos.ProcessState_Stopping
|
|
||||||
if err := proc.cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
|
||||||
proc.cmd.Process.Signal(os.Kill)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
|
||||||
|
|
||||||
for _, proc := range killing {
|
|
||||||
proc.cmd.Wait()
|
|
||||||
proc.cmd.Process.Release()
|
|
||||||
}
|
|
||||||
|
|
||||||
hc.childProcs = remains
|
|
||||||
|
|
||||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return errNoRunningProcess
|
|
||||||
}
|
|
||||||
|
|
||||||
func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest, op protos.OperationClient) error {
|
func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest, op protos.OperationClient) error {
|
||||||
for _, proc := range hc.childProcs {
|
for _, proc := range hc.childProcs {
|
||||||
if proc.cmd.Process.Pid == int(req.Pid) {
|
if proc.cmd.Process.Pid == int(req.Pid) {
|
||||||
if len(req.Config) > 0 {
|
if len(req.Config) > 0 {
|
||||||
// config.json를 먼저 다운로드 시도
|
// config.json를 먼저 다운로드 시도
|
||||||
root := proc.cmd.Path
|
root := proc.verpath
|
||||||
if _, err := download(root, hc.makeDownloadUrl(req.Config), ""); err != nil {
|
if _, err := download(root, hc.makeDownloadUrl(req.Config), "", nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
proc.state = protos.ProcessState_Restart
|
proc.setState(protos.ProcessState_Restart)
|
||||||
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
op.Refresh(context.Background(), hc.makeOperationQueryRequest())
|
||||||
hc.exitChan <- proc.cmd
|
hc.exitChan <- proc.cmd
|
||||||
|
|
||||||
@ -455,41 +545,3 @@ func (hc *houstonClient) restartChildProcess(req *shared.RestartProcessRequest,
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *houstonClient) uploadFiles(req *shared.UploadRequest) error {
|
|
||||||
if req.Version == "latest" {
|
|
||||||
// 최신 버전을 찾음
|
|
||||||
latest, err := shared.FindLastestVersion(hc.config.StorageRoot, req.Name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Version = latest
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Println("uploadFiles req :", *req)
|
|
||||||
for _, child := range hc.childProcs {
|
|
||||||
if child.version == req.Version && child.name == req.Name {
|
|
||||||
logger.Println("uploadFiles found :", child.version, child.name)
|
|
||||||
child.logUploadChan <- req
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 실행 중이 아닌 폴더에서도 대상을 찾는다
|
|
||||||
// 전체 파일을 대상으로
|
|
||||||
zipFile, srcFiles, err := zipLogFiles(hc.config.StorageRoot, req, "", "")
|
|
||||||
if err == nil && len(zipFile) > 0 && len(srcFiles) > 0 {
|
|
||||||
if err = hc.uploadZipLogFile(zipFile, req.Name, req.Version); err == nil {
|
|
||||||
for _, oldf := range srcFiles {
|
|
||||||
os.Remove(oldf)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.Println("uploadZipLogFile failed :", err)
|
|
||||||
}
|
|
||||||
} else if err != nil {
|
|
||||||
logger.Println("zipLogFiles failed :", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
70
go.mod
70
go.mod
@ -3,16 +3,70 @@ module repositories.action2quare.com/ayo/houston
|
|||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
golang.org/x/text v0.10.0
|
github.com/Knetic/govaluate v3.0.0+incompatible
|
||||||
google.golang.org/grpc v1.56.0
|
github.com/djherbis/times v1.6.0
|
||||||
google.golang.org/protobuf v1.30.0
|
github.com/go-kit/log v0.2.1
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230621052811-06ef97f11d22
|
github.com/prometheus/client_golang v1.17.0
|
||||||
|
github.com/prometheus/common v0.44.0
|
||||||
|
github.com/prometheus/node_exporter v1.6.1
|
||||||
|
golang.org/x/sys v0.16.0
|
||||||
|
golang.org/x/text v0.14.0
|
||||||
|
google.golang.org/grpc v1.60.1
|
||||||
|
google.golang.org/protobuf v1.32.0
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20240729084947-8e3d6c28f024
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/alecthomas/kingpin/v2 v2.3.2 // indirect
|
||||||
|
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
|
||||||
|
github.com/beevik/ntp v0.3.0 // indirect
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
|
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||||
|
github.com/dennwc/btrfs v0.0.0-20230312211831-a1f570bd01a1 // indirect
|
||||||
|
github.com/dennwc/ioctl v1.0.0 // indirect
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
|
github.com/ema/qdisc v0.0.0-20230120214811-5b708f463de3 // indirect
|
||||||
|
github.com/go-logfmt/logfmt v0.5.1 // indirect
|
||||||
|
github.com/go-redis/redis/v8 v8.11.5 // indirect
|
||||||
|
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
golang.org/x/net v0.11.0 // indirect
|
github.com/golang/snappy v0.0.1 // indirect
|
||||||
golang.org/x/sys v0.9.0 // indirect
|
github.com/google/go-cmp v0.5.9 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20230525234025-438c736192d0 // indirect
|
github.com/hashicorp/go-envparse v0.1.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
|
github.com/hodgesds/perf-utils v0.7.0 // indirect
|
||||||
|
github.com/illumos/go-kstat v0.0.0-20210513183136-173c9b0a9973 // indirect
|
||||||
|
github.com/josharian/native v1.1.0 // indirect
|
||||||
|
github.com/jsimonetti/rtnetlink v1.3.2 // indirect
|
||||||
|
github.com/klauspost/compress v1.13.6 // indirect
|
||||||
|
github.com/lufia/iostat v1.2.1 // indirect
|
||||||
|
github.com/mattn/go-xmlrpc v0.0.3 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||||
|
github.com/mdlayher/ethtool v0.0.0-20221212131811-ba3b4bc2e02c // indirect
|
||||||
|
github.com/mdlayher/genetlink v1.3.1 // indirect
|
||||||
|
github.com/mdlayher/netlink v1.7.2 // indirect
|
||||||
|
github.com/mdlayher/socket v0.4.1 // indirect
|
||||||
|
github.com/mdlayher/wifi v0.0.0-20220330172155-a44c70b6d3c8 // indirect
|
||||||
|
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
|
||||||
|
github.com/opencontainers/selinux v1.11.0 // indirect
|
||||||
|
github.com/pires/go-proxyproto v0.7.0 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/prometheus-community/go-runit v0.1.0 // indirect
|
||||||
|
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
|
||||||
|
github.com/prometheus/procfs v0.11.1 // indirect
|
||||||
|
github.com/safchain/ethtool v0.3.0 // indirect
|
||||||
|
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||||
|
github.com/xdg-go/scram v1.1.1 // indirect
|
||||||
|
github.com/xdg-go/stringprep v1.0.3 // indirect
|
||||||
|
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
|
||||||
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||||
|
go.mongodb.org/mongo-driver v1.11.6 // indirect
|
||||||
|
go.uber.org/atomic v1.7.0 // indirect
|
||||||
|
go.uber.org/multierr v1.6.0 // indirect
|
||||||
|
golang.org/x/crypto v0.18.0 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
|
||||||
|
golang.org/x/net v0.20.0 // indirect
|
||||||
|
golang.org/x/sync v0.6.0 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
|
||||||
|
howett.net/plist v1.0.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
202
go.sum
202
go.sum
@ -1,36 +1,182 @@
|
|||||||
|
github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg=
|
||||||
|
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||||
|
github.com/alecthomas/kingpin/v2 v2.3.2 h1:H0aULhgmSzN8xQ3nX1uxtdlTHYoPLu5AhHxWrKI6ocU=
|
||||||
|
github.com/alecthomas/kingpin/v2 v2.3.2/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
|
||||||
|
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
|
||||||
|
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
|
||||||
|
github.com/beevik/ntp v0.3.0 h1:xzVrPrE4ziasFXgBVBZJDP0Wg/KpMwk2KHJ4Ba8GrDw=
|
||||||
|
github.com/beevik/ntp v0.3.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg=
|
||||||
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/cilium/ebpf v0.10.0 h1:nk5HPMeoBXtOzbkZBWym+ZWq1GIiHUsBFXxwewXAHLQ=
|
||||||
|
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
|
||||||
|
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dennwc/btrfs v0.0.0-20230312211831-a1f570bd01a1 h1:ue4Es4Xzz255hWQ7NAWzZxuXG+YOV7URzzusLLSe0zU=
|
||||||
|
github.com/dennwc/btrfs v0.0.0-20230312211831-a1f570bd01a1/go.mod h1:MYsOV9Dgsec3FFSOjywi0QK5r6TeBbdWxdrMGtiYXHA=
|
||||||
|
github.com/dennwc/ioctl v1.0.0 h1:DsWAAjIxRqNcLn9x6mwfuf2pet3iB7aK90K4tF16rLg=
|
||||||
|
github.com/dennwc/ioctl v1.0.0/go.mod h1:ellh2YB5ldny99SBU/VX7Nq0xiZbHphf1DrtHxxjMk0=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
|
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
|
||||||
|
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
|
||||||
|
github.com/ema/qdisc v0.0.0-20230120214811-5b708f463de3 h1:Jrl8sD8wO34+EE1dV2vhOXrqFAZa/FILDnZRaV28+cw=
|
||||||
|
github.com/ema/qdisc v0.0.0-20230120214811-5b708f463de3/go.mod h1:FhIc0fLYi7f+lK5maMsesDqwYojIOh3VfRs8EVd5YJQ=
|
||||||
|
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||||
|
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
|
||||||
|
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
|
||||||
|
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
|
||||||
|
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
||||||
|
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||||
|
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||||
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||||
|
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
|
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||||
|
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
github.com/hashicorp/go-envparse v0.1.0 h1:bE++6bhIsNCPLvgDZkYqo3nA+/PFI51pkrHdmPSDFPY=
|
||||||
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
|
github.com/hashicorp/go-envparse v0.1.0/go.mod h1:OHheN1GoygLlAkTlXLXvAdnXdZxy8JUweQ1rAXx1xnc=
|
||||||
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
github.com/hodgesds/perf-utils v0.7.0 h1:7KlHGMuig4FRH5fNw68PV6xLmgTe7jKs9hgAcEAbioU=
|
||||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
github.com/hodgesds/perf-utils v0.7.0/go.mod h1:LAklqfDadNKpkxoAJNHpD5tkY0rkZEVdnCEWN5k4QJY=
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
github.com/illumos/go-kstat v0.0.0-20210513183136-173c9b0a9973 h1:hk4LPqXIY/c9XzRbe7dA6qQxaT6Axcbny0L/G5a4owQ=
|
||||||
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
github.com/illumos/go-kstat v0.0.0-20210513183136-173c9b0a9973/go.mod h1:PoK3ejP3LJkGTzKqRlpvCIFas3ncU02v8zzWDW+g0FY=
|
||||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
|
||||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
|
||||||
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
|
github.com/jsimonetti/rtnetlink v1.3.2 h1:dcn0uWkfxycEEyNy0IGfx3GrhQ38LH7odjxAghimsVI=
|
||||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
github.com/jsimonetti/rtnetlink v1.3.2/go.mod h1:BBu4jZCpTjP6Gk0/wfrO8qcqymnN3g0hoFqObRmUo6U=
|
||||||
|
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
||||||
|
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/lufia/iostat v1.2.1 h1:tnCdZBIglgxD47RyD55kfWQcJMGzO+1QBziSQfesf2k=
|
||||||
|
github.com/lufia/iostat v1.2.1/go.mod h1:rEPNA0xXgjHQjuI5Cy05sLlS2oRcSlWHRLrvh/AQ+Pg=
|
||||||
|
github.com/mattn/go-xmlrpc v0.0.3 h1:Y6WEMLEsqs3RviBrAa1/7qmbGB7DVD3brZIbqMbQdGY=
|
||||||
|
github.com/mattn/go-xmlrpc v0.0.3/go.mod h1:mqc2dz7tP5x5BKlCahN/n+hs7OSZKJkS9JsHNBRlrxA=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
||||||
|
github.com/mdlayher/ethtool v0.0.0-20221212131811-ba3b4bc2e02c h1:Y7LoKqIgD7vmqJ7+6ZVnADuwUO+m3tGXbf2lK0OvjIw=
|
||||||
|
github.com/mdlayher/ethtool v0.0.0-20221212131811-ba3b4bc2e02c/go.mod h1:i0nPbE+sL2G3OtdIb9SXxW/T4UiAwh6rxPW7zcuX+KQ=
|
||||||
|
github.com/mdlayher/genetlink v1.3.1 h1:roBiPnual+eqtRkKX2Jb8UQN5ZPWnhDCGj/wR6Jlz2w=
|
||||||
|
github.com/mdlayher/genetlink v1.3.1/go.mod h1:uaIPxkWmGk753VVIzDtROxQ8+T+dkHqOI0vB1NA9S/Q=
|
||||||
|
github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g=
|
||||||
|
github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
|
||||||
|
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
|
||||||
|
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
|
||||||
|
github.com/mdlayher/wifi v0.0.0-20220330172155-a44c70b6d3c8 h1:/HCRFfpoICSWHvNrJ356VO4opd9dg/LaU7m8Tzdf39c=
|
||||||
|
github.com/mdlayher/wifi v0.0.0-20220330172155-a44c70b6d3c8/go.mod h1:IqdtNfemiXr50M8tnxLWSFdZKZ9vcI1Mgt0oTrCIS7A=
|
||||||
|
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
|
||||||
|
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||||
|
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||||
|
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||||
|
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||||
|
github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU=
|
||||||
|
github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
|
||||||
|
github.com/pires/go-proxyproto v0.7.0 h1:IukmRewDQFWC7kfnb66CSomk2q/seBuilHBYFwyq0Hs=
|
||||||
|
github.com/pires/go-proxyproto v0.7.0/go.mod h1:Vz/1JPY/OACxWGQNIRY2BeyDmpoaWmEP40O9LbuiFR4=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/prometheus-community/go-runit v0.1.0 h1:uTWEj/Fn2RoLdfg/etSqwzgYNOYPrARx1BHUN052tGA=
|
||||||
|
github.com/prometheus-community/go-runit v0.1.0/go.mod h1:AvJ9Jo3gAFu2lbM4+qfjdpq30FfiLDJZKbQ015u08IQ=
|
||||||
|
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
|
||||||
|
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
|
||||||
|
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 h1:v7DLqVdK4VrYkVD5diGdl4sxJurKJEMnODWRJlxV9oM=
|
||||||
|
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
|
||||||
|
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
|
||||||
|
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
|
||||||
|
github.com/prometheus/node_exporter v1.6.1 h1:Srqr6UAOUDnKhurvYGIYa7GZXuMCwJpzT9KP8uTJ4vw=
|
||||||
|
github.com/prometheus/node_exporter v1.6.1/go.mod h1:+zK+m9vwxu19JHl/kVVmixdCT6fWWHlmcOUHDFpkt0Y=
|
||||||
|
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
|
||||||
|
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
|
||||||
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
|
github.com/safchain/ethtool v0.3.0 h1:gimQJpsI6sc1yIqP/y8GYgiXn/NjgvpM0RNoWLVVmP0=
|
||||||
|
github.com/safchain/ethtool v0.3.0/go.mod h1:SA9BwrgyAqNo7M+uaL6IYbxpm5wk3L7Mm6ocLW+CJUs=
|
||||||
|
github.com/siebenmann/go-kstat v0.0.0-20210513183136-173c9b0a9973 h1:GfSdC6wKfTGcgCS7BtzF5694Amne1pGCSTY252WhlEY=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||||
|
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
|
||||||
|
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||||
|
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||||
|
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||||
|
github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E=
|
||||||
|
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
||||||
|
github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs=
|
||||||
|
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||||
|
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
|
||||||
|
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
|
||||||
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
|
||||||
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||||
|
go.mongodb.org/mongo-driver v1.11.6 h1:XM7G6PjiGAO5betLF13BIa5TlLUUE3uJ/2Ox3Lz1K+o=
|
||||||
|
go.mongodb.org/mongo-driver v1.11.6/go.mod h1:G9TgswdsWjX4tmDA5zfs2+6AEPpYJwqblyjsfuh8oXY=
|
||||||
|
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||||
|
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||||
|
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||||
|
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||||
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
|
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
|
||||||
|
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
||||||
|
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
|
||||||
|
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
||||||
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
||||||
|
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
||||||
|
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
|
||||||
|
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20211031064116-611d5d643895/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
||||||
|
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac h1:nUQEQmH/csSvFECKYRv6HWEyypysidKl2I6Qpsglq/0=
|
||||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:daQN87bsDqDoe316QbbvX60nMoJQa4r6Ds0ZuoAe5yA=
|
||||||
google.golang.org/genproto v0.0.0-20230525234025-438c736192d0 h1:x1vNwUhVOcsYoKyEGCZBH694SBmmBjA2EfauFVEI2+M=
|
google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU=
|
||||||
google.golang.org/genproto v0.0.0-20230525234025-438c736192d0/go.mod h1:9ExIQyXL5hZrHzQceCwuSYwZZ5QZBazOcprJ5rgs3lY=
|
google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc h1:XSJ8Vk1SWuNr8S18z1NZSziL0CPIXLCCMDOEFtHBOFc=
|
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
|
|
||||||
google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag=
|
|
||||||
google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8=
|
|
||||||
google.golang.org/grpc v1.56.0 h1:+y7Bs8rtMd07LeXmL3NxcTLn7mUkbKZqEpPhMNkwJEE=
|
|
||||||
google.golang.org/grpc v1.56.0/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
|
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
||||||
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230613162208-4ebf231bbe72 h1:2qaxct6dumM2JjguSp5nofeWZwWsozKSJWC36q9Q0qc=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230613162208-4ebf231bbe72/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230621052811-06ef97f11d22 h1:DImSGNxZrc+Q4WlS1OKMsLAScEfDYLX4XMJdjAaVnXc=
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230621052811-06ef97f11d22/go.mod h1:ng62uGMGXyQSeuxePG5gJAMtip4Rnspu5Tu7hgvaXns=
|
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
|
||||||
|
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20240729084947-8e3d6c28f024 h1:WdvW4BJHoBwXqNsfEgOAZai7L9iHqRCZ7PZL0cwOULE=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20240729084947-8e3d6c28f024/go.mod h1:XA8+hQtUNh956T+kAbJKkUtMl5HUWj83knvdBvvPS5s=
|
||||||
|
|||||||
37
houston.sh
37
houston.sh
@ -1,4 +1,37 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
nohup /home/opdev/houston -client -logfile &
|
HOUSTON_PATH="./houston"
|
||||||
|
UPDATE_DIR="houston.update"
|
||||||
|
|
||||||
|
run_houston() {
|
||||||
|
if [ -f "$HOUSTON_PATH" ]; then
|
||||||
|
"$HOUSTON_PATH" "$@"
|
||||||
|
return $?
|
||||||
|
else
|
||||||
|
echo "houston 실행 파일이 없습니다."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
echo "현재 버전의 houston을 실행합니다."
|
||||||
|
run_houston "$@"
|
||||||
|
|
||||||
|
# houston.update 폴더가 존재하는지 확인
|
||||||
|
if [ -d "$UPDATE_DIR" ]; then
|
||||||
|
echo "새로운 업데이트 폴더 발견. 업데이트를 진행합니다."
|
||||||
|
# houston.update 폴더 내의 모든 파일을 현재 폴더로 복사
|
||||||
|
cp -R "$UPDATE_DIR"/* .
|
||||||
|
# 실행 권한 부여 (필요한 경우)
|
||||||
|
chmod +x "$HOUSTON_PATH"
|
||||||
|
# 업데이트 폴더 삭제
|
||||||
|
rm -rf "$UPDATE_DIR"
|
||||||
|
echo "업데이트 완료 및 업데이트 폴더 삭제. houston을 다시 시작합니다."
|
||||||
|
else
|
||||||
|
echo "업데이트 폴더가 없습니다. 스크립트 실행을 종료합니다."
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "houston 실행 및 업데이트 스크립트 종료"
|
||||||
|
exit $?
|
||||||
108
main.go
108
main.go
@ -1,108 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"repositories.action2quare.com/ayo/gocommon/flagx"
|
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
|
||||||
"repositories.action2quare.com/ayo/houston/client"
|
|
||||||
"repositories.action2quare.com/ayo/houston/server"
|
|
||||||
)
|
|
||||||
|
|
||||||
var runAsClient = flagx.Bool("client", false, "")
|
|
||||||
var runAsServer = flagx.Bool("server", false, "")
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flagx.Parse()
|
|
||||||
if !*runAsClient && !*runAsServer {
|
|
||||||
logger.Fatal("client or server flag is needed")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if *runAsClient {
|
|
||||||
hc, err := client.NewClient()
|
|
||||||
if err != nil {
|
|
||||||
logger.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
hc.Start()
|
|
||||||
} else if *runAsServer {
|
|
||||||
svr := server.NewServer()
|
|
||||||
svr.Start()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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%2F%2F%2F%2F%2F%2F%2F8BEAIaDDU0OTY2MjkyMDczOCIMeHddxdoH6Xfz68ZqKtoCwVyCYH45tC7aDBpkl%2FsGRPYlhUVy84h%2FVQx4Bu8hvgu3Y3fYSceAFgFWv%2FE3HpvrHD8AY42UsaHPBCd7tmlyydqnPoOr%2F5rjUCAmHXziGV7oAcO3HIbobbjO1rf3W2tQf7FSGbfPyxFdRhoObRz3sQi%2FcmYLKZWPS9UZRuWOSh2J3HHOoEdAIDq38eYxtVl1OEKxPIjfeJHTzmOOmvoOFBOzrY9HJyABcYxvmtOUvR6469Qf5r%2FTe%2BvuL1NQsYyBKwukcSxHcGbg7t%2BNeDTE%2FUS9lL7VYMEZlhfA1WSADbvAcYEu7cv7MENJ44XmAEHnC6zWIvDNqwK9FCfJrpALIJhbXqv%2FU%2Ft%2B5udZT1TXDDqp1se%2FBRLg8NyplcN4E8z6Qt%2F9pNSm1flhORHJsaPzk2ZfGeqvFvZGv1oBigwA6eJ3WCNl2hHhLkiSBg%2BvFwXA1KxxH9U8Nkl7EjDp7JmhBjqzAqPqVamph2PzNkEszr52GH69m90pjYkNTLM4nwMuGdo1f5%2BOm%2FVloBjBCh6OpTSK3XH67zEMZE0tFQ7qmqu2d69EY8Frt749G3RSNPeKptuIKxhBYF692an9nYUXiVH8OJkey0LDMbwWDaVfSZyOiYr%2FmeiVK0eRdK3C0JGwP%2BT6vUHBL1Agi5MH0dKvmlHwzvl%2BuqArgw7ZdOx%2BJsFHRD%2FqA87B5qPuvxPXkAO5qgwZfUW9MAxdh5hxcc9kNfmryYuVWD1DM%2BvRsRF2TsUqeffucajpQ7lhvN6rspDPMltD3VHFX82Hv12nqU7pHwtNLSO0D43W4JCmOJA8TFqhCkY4zCFDok0lx3x6b8w%2F4GptjvCo1c4HG9LAurTNK8HOb3XkYdmPwKOHaqMNajMsKZoohb0%3D&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,
|
|
||||||
// // ))
|
|
||||||
// //}()
|
|
||||||
// }
|
|
||||||
38
main_client.go
Normal file
38
main_client.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
//go:build client
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
|
"repositories.action2quare.com/ayo/houston/client"
|
||||||
|
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flagx.Parse()
|
||||||
|
|
||||||
|
hc, err := client.NewClient(true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
|
server := &http.Server{Addr: ":9100", Handler: nil}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
logger.Println("listen /metrics")
|
||||||
|
server.ListenAndServe()
|
||||||
|
}()
|
||||||
|
|
||||||
|
hc.Start()
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
|
||||||
|
server.Shutdown(ctx)
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
15
main_server.go
Normal file
15
main_server.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
//go:build !client
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||||
|
"repositories.action2quare.com/ayo/houston/server"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flagx.Parse()
|
||||||
|
|
||||||
|
svr := server.NewServer()
|
||||||
|
svr.Start()
|
||||||
|
}
|
||||||
@ -4,21 +4,13 @@ del houston.zip
|
|||||||
|
|
||||||
$Env:GOOS="linux"
|
$Env:GOOS="linux"
|
||||||
$Env:GOARCH="amd64"
|
$Env:GOARCH="amd64"
|
||||||
go build -ldflags="-s -w" .
|
|
||||||
|
|
||||||
cp houston .\replacer\houston
|
go get repositories.action2quare.com/ayo/gocommon
|
||||||
cp config.json .\replacer\config.json
|
go mod tidy
|
||||||
|
|
||||||
cd replacer
|
go build -ldflags="-s -w" -tags=client .
|
||||||
go build -ldflags="-s -w" .
|
|
||||||
|
|
||||||
Compress-Archive -Path replacer -DestinationPath houston.zip -Force
|
|
||||||
Compress-Archive -Path config.json -Update -DestinationPath houston.zip
|
Compress-Archive -Path config.json -Update -DestinationPath houston.zip
|
||||||
Compress-Archive -Path houston -Update -DestinationPath houston.zip
|
Compress-Archive -Path houston -Update -DestinationPath houston.zip
|
||||||
|
|
||||||
del houston
|
|
||||||
del config.json
|
|
||||||
del replacer
|
|
||||||
|
|
||||||
mv houston.zip ..\houston.zip
|
|
||||||
cd ..
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import "protos/empty.proto";
|
|||||||
service Operation {
|
service Operation {
|
||||||
rpc Query(stream OperationQueryRequest) returns (stream OperationQueryResponse) {}
|
rpc Query(stream OperationQueryRequest) returns (stream OperationQueryResponse) {}
|
||||||
rpc Refresh(OperationQueryRequest) returns (Empty) {}
|
rpc Refresh(OperationQueryRequest) returns (Empty) {}
|
||||||
|
rpc ReportDeployingProgress(DeployingProgress) returns (Empty) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
message VersionAndArgs {
|
message VersionAndArgs {
|
||||||
@ -19,6 +20,9 @@ message DeployedVersions {
|
|||||||
|
|
||||||
message OperationQueryRequest {
|
message OperationQueryRequest {
|
||||||
string hostname = 1;
|
string hostname = 1;
|
||||||
|
string public_ip = 4;
|
||||||
|
string private_ip =5;
|
||||||
|
|
||||||
repeated ProcessDescription procs = 2;
|
repeated ProcessDescription procs = 2;
|
||||||
repeated DeployedVersions deploys = 3;
|
repeated DeployedVersions deploys = 3;
|
||||||
}
|
}
|
||||||
@ -43,3 +47,12 @@ message OperationQueryResponse {
|
|||||||
string operation = 1;
|
string operation = 1;
|
||||||
map<string, string> args = 2;
|
map<string, string> args = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message DeployingProgress {
|
||||||
|
string hostname = 1;
|
||||||
|
string name = 2;
|
||||||
|
string version = 3;
|
||||||
|
string state = 4;
|
||||||
|
int64 progress = 5;
|
||||||
|
int64 total = 6;
|
||||||
|
}
|
||||||
123
replacer/main.go
123
replacer/main.go
@ -1,123 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func copy(src, dst string) error {
|
|
||||||
fi, err := os.Stat(src)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
inmode := fi.Mode()
|
|
||||||
|
|
||||||
in, err := os.Open(src)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer in.Close()
|
|
||||||
|
|
||||||
out, err := os.Create(dst)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer out.Close()
|
|
||||||
|
|
||||||
copied, err := io.Copy(out, in)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if copied < fi.Size() {
|
|
||||||
return errors.New("copy not completed")
|
|
||||||
}
|
|
||||||
if err := out.Sync(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := out.Chmod(inmode); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
logfile, _ := os.OpenFile("replacer.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
|
|
||||||
defer logfile.Close()
|
|
||||||
stdlog := log.New(logfile, "", log.LstdFlags)
|
|
||||||
|
|
||||||
args := os.Args
|
|
||||||
// args[1] : 나를 시작한 pid. pid가 종료될 때 까지 기다림
|
|
||||||
// args[2] : target 폴더
|
|
||||||
// args[3:] : 다시 시작할 때 넘겨줄 arguments(프로세스 이름 포함)
|
|
||||||
stdlog.Println(args)
|
|
||||||
|
|
||||||
pid, err := strconv.Atoi(args[1])
|
|
||||||
if err != nil {
|
|
||||||
stdlog.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
stdlog.Println("wait for terminating of", args[3])
|
|
||||||
proc, err := os.FindProcess(pid)
|
|
||||||
if err != nil {
|
|
||||||
stdlog.Fatal(err)
|
|
||||||
}
|
|
||||||
state, _ := proc.Wait()
|
|
||||||
if state == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
selfext, _ := os.Executable()
|
|
||||||
selfext = path.Base(selfext)
|
|
||||||
nextArgs := args[4:]
|
|
||||||
entries, _ := os.ReadDir(args[2])
|
|
||||||
for _, ent := range entries {
|
|
||||||
if ent.Name() == selfext {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ent.IsDir() {
|
|
||||||
if err := os.MkdirAll(ent.Name(), 0775); err != nil {
|
|
||||||
stdlog.Fatal(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ent.Name() == "@args" {
|
|
||||||
var tempArgs []string
|
|
||||||
argfile, _ := os.Open(path.Join(args[2], ent.Name()))
|
|
||||||
dec := json.NewDecoder(argfile)
|
|
||||||
if dec.Decode(&tempArgs) == nil {
|
|
||||||
nextArgs = tempArgs
|
|
||||||
}
|
|
||||||
} else if err := copy(path.Join(args[2], ent.Name()), ent.Name()); err != nil {
|
|
||||||
stdlog.Println("copy failed :", path.Join(args[2], ent.Name()), ent.Name())
|
|
||||||
stdlog.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.RemoveAll(args[2])
|
|
||||||
if err != nil {
|
|
||||||
stdlog.Println("os.RemoveAll failed :", args[2], err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = os.Chmod(args[3], 0775)
|
|
||||||
if err != nil {
|
|
||||||
stdlog.Println("os.Chmod failed :", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
stdlog.Println("exec.Command :", args)
|
|
||||||
cmd := exec.Command(args[3], nextArgs...)
|
|
||||||
cmd.Start()
|
|
||||||
}
|
|
||||||
@ -34,6 +34,16 @@ func (h *houstonHandler) GetAgents(w http.ResponseWriter, r *http.Request) {
|
|||||||
enc.Encode(allHosts)
|
enc.Encode(allHosts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readTagsFromFile(paths ...string) string {
|
||||||
|
raw, _ := os.ReadFile(path.Join(paths...))
|
||||||
|
if len(raw) > 0 {
|
||||||
|
tag := string(raw)
|
||||||
|
return strings.Trim(tag, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) {
|
func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request) {
|
||||||
files, err := os.ReadDir(h.deployPath)
|
files, err := os.ReadDir(h.deployPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -43,19 +53,31 @@ func (h *houstonHandler) GetDeploySources(w http.ResponseWriter, r *http.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
getVersions := func(name string) []string {
|
getVersions := func(name string) []string {
|
||||||
var out []string
|
|
||||||
vers, _ := os.ReadDir(path.Join(h.deployPath, name))
|
vers, _ := os.ReadDir(path.Join(h.deployPath, name))
|
||||||
|
mytags := readTagsFromFile(h.deployPath, name, "@tags")
|
||||||
|
out := []string{
|
||||||
|
mytags,
|
||||||
|
}
|
||||||
for _, fd := range vers {
|
for _, fd := range vers {
|
||||||
if fd.IsDir() {
|
if fd.IsDir() {
|
||||||
ver := fd.Name()
|
ver := fd.Name()
|
||||||
files, _ := os.ReadDir(path.Join(h.deployPath, name, ver))
|
files, _ := os.ReadDir(path.Join(h.deployPath, name, ver))
|
||||||
|
vertags := readTagsFromFile(h.deployPath, name, ver, "@tags")
|
||||||
if len(files) > 0 {
|
if len(files) > 0 {
|
||||||
downloadpath := path.Join(sub_folder_name_deploys, name, ver, files[0].Name())
|
for _, file := range files {
|
||||||
ver = fmt.Sprintf("%s:%s", ver, downloadpath)
|
if strings.HasPrefix(file.Name(), "@") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadpath := path.Join(sub_folder_name_deploys, name, ver, file.Name())
|
||||||
|
ver = fmt.Sprintf("%s:%s", ver+mytags+vertags, downloadpath)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out = append(out, ver)
|
out = append(out, ver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +100,7 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
|
|||||||
// <input type="submit" value="업로드">
|
// <input type="submit" value="업로드">
|
||||||
// </form>
|
// </form>
|
||||||
file, header, err := r.FormFile("file")
|
file, header, err := r.FormFile("file")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Println(err)
|
logger.Println(err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
@ -100,8 +123,12 @@ func (h *houstonHandler) UploadDeploySource(w http.ResponseWriter, r *http.Reque
|
|||||||
|
|
||||||
if version == "config" {
|
if version == "config" {
|
||||||
filename = path.Join(h.deployPath, name, version, "config"+ext)
|
filename = path.Join(h.deployPath, name, version, "config"+ext)
|
||||||
|
tags := readTagsFromFile(h.deployPath, name, version, "@tags")
|
||||||
|
if !strings.Contains(tags, "#hidden") {
|
||||||
|
tags = tags + "#hidden"
|
||||||
|
os.WriteFile(path.Join(h.deployPath, name, version, "@tags"), []byte(tags), 0644)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
|
|
||||||
filename = path.Join(h.deployPath, name, version, name+ext)
|
filename = path.Join(h.deployPath, name, version, name+ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +162,7 @@ func (h *houstonHandler) DeleteDeploySource(w http.ResponseWriter, r *http.Reque
|
|||||||
|
|
||||||
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
|
// deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
|
||||||
targetpath := path.Join(h.deployPath, name, version)
|
targetpath := path.Join(h.deployPath, name, version)
|
||||||
|
|
||||||
if err := os.RemoveAll(targetpath); err != nil {
|
if err := os.RemoveAll(targetpath); err != nil {
|
||||||
logger.Println("deleteDeploySource failed :", err)
|
logger.Println("deleteDeploySource failed :", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
@ -143,7 +171,6 @@ func (h *houstonHandler) DeleteDeploySource(w http.ResponseWriter, r *http.Reque
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *houstonHandler) findLastestConfigFile(name string) (string, error) {
|
func (h *houstonHandler) findLastestConfigFile(name string) (string, error) {
|
||||||
logger.Println("findLastestConfigFile :", name)
|
|
||||||
configFiles, err := os.ReadDir(path.Join(h.deployPath, name, "config"))
|
configFiles, err := os.ReadDir(path.Join(h.deployPath, name, "config"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
@ -174,12 +201,9 @@ func (h *houstonHandler) findLastestConfigFile(name string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cf != nil {
|
if cf != nil {
|
||||||
logger.Println("findLastestConfigFile cf found :", cf.Name())
|
|
||||||
return path.Join(sub_folder_name_deploys, name, "config", cf.Name()), nil
|
return path.Join(sub_folder_name_deploys, name, "config", cf.Name()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Println("findLastestConfigFile cf NOT found")
|
|
||||||
|
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,6 +247,10 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(fd.Name(), "@") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
fi, _ := fd.Info()
|
fi, _ := fd.Info()
|
||||||
if fi.ModTime().After(latestTime) {
|
if fi.ModTime().After(latestTime) {
|
||||||
latestFilename = fi.Name()
|
latestFilename = fi.Name()
|
||||||
@ -234,12 +262,16 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
configPath, err := h.findLastestConfigFile(name)
|
var configPath string
|
||||||
|
if name != "houston" {
|
||||||
|
// houston은 config를 포함하여 배포
|
||||||
|
configPath, err = h.findLastestConfigFile(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Println(err)
|
logger.Println(err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
h.Operation().Deploy(MakeDeployRequest(
|
h.Operation().Deploy(MakeDeployRequest(
|
||||||
shared.DeployRequest{
|
shared.DeployRequest{
|
||||||
@ -316,6 +348,7 @@ func (h *houstonHandler) StartProcess(w http.ResponseWriter, r *http.Request) {
|
|||||||
argsTemp := re.FindAllString(argsline, -1)
|
argsTemp := re.FindAllString(argsline, -1)
|
||||||
var args []string
|
var args []string
|
||||||
for _, arg := range argsTemp {
|
for _, arg := range argsTemp {
|
||||||
|
arg = strings.Trim(arg, "\n ")
|
||||||
if strings.HasPrefix(arg, `"`) && len(args) > 0 {
|
if strings.HasPrefix(arg, `"`) && len(args) > 0 {
|
||||||
lastarg := args[len(args)-1]
|
lastarg := args[len(args)-1]
|
||||||
if strings.HasSuffix(lastarg, "=") {
|
if strings.HasSuffix(lastarg, "=") {
|
||||||
@ -374,6 +407,13 @@ func (h *houstonHandler) StopProcess(w http.ResponseWriter, r *http.Request) {
|
|||||||
Version: version,
|
Version: version,
|
||||||
Pid: int32(pid),
|
Pid: int32(pid),
|
||||||
}, targets))
|
}, targets))
|
||||||
|
|
||||||
|
h.Operation().Upload(MakeUploadRequest(shared.UploadRequest{
|
||||||
|
Name: name,
|
||||||
|
Version: version,
|
||||||
|
Url: "upload",
|
||||||
|
DeleteAfterUploaded: "true",
|
||||||
|
}, targets))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *houstonHandler) RestartProcess(w http.ResponseWriter, r *http.Request) {
|
func (h *houstonHandler) RestartProcess(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -386,6 +426,7 @@ func (h *houstonHandler) RestartProcess(w http.ResponseWriter, r *http.Request)
|
|||||||
pidstr := r.FormValue("pid")
|
pidstr := r.FormValue("pid")
|
||||||
target := r.FormValue("target")
|
target := r.FormValue("target")
|
||||||
name := r.FormValue("name")
|
name := r.FormValue("name")
|
||||||
|
|
||||||
if len(target) == 0 || len(pidstr) == 0 || len(name) == 0 {
|
if len(target) == 0 || len(pidstr) == 0 || len(name) == 0 {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@ -468,10 +509,6 @@ func (h *houstonHandler) GetLogFileLinks(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if version == "latest" {
|
|
||||||
version, _ = shared.FindLastestVersion(h.downloadPath, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
root := path.Join(h.downloadPath, name, version)
|
root := path.Join(h.downloadPath, name, version)
|
||||||
logfiles, err := os.ReadDir(root)
|
logfiles, err := os.ReadDir(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -487,3 +524,7 @@ func (h *houstonHandler) GetLogFileLinks(w http.ResponseWriter, r *http.Request)
|
|||||||
enc := json.NewEncoder(w)
|
enc := json.NewEncoder(w)
|
||||||
enc.Encode(out)
|
enc.Encode(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *houstonHandler) GetDeployingProgress(w http.ResponseWriter, r *http.Request) {
|
||||||
|
json.NewEncoder(w).Encode(h.Operation().DeplyingProgress())
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -12,17 +13,13 @@ import (
|
|||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"repositories.action2quare.com/ayo/gocommon/flagx"
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
defaultMaxMemory = 32 << 10 // 32 KB
|
|
||||||
)
|
|
||||||
|
|
||||||
type HoustonServerWithHandler interface {
|
type HoustonServerWithHandler interface {
|
||||||
HoustonServer
|
HoustonServer
|
||||||
RegisterHandlers(serveMux *http.ServeMux, prefix string) error
|
RegisterHandlers(serveMux gocommon.ServerMuxInterface, prefix string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type houstonHandler struct {
|
type houstonHandler struct {
|
||||||
@ -30,9 +27,10 @@ type houstonHandler struct {
|
|||||||
methods map[string]reflect.Method
|
methods map[string]reflect.Method
|
||||||
deployPath string
|
deployPath string
|
||||||
downloadPath string
|
downloadPath string
|
||||||
|
maingateApiToken string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHoustonHandler() HoustonServerWithHandler {
|
func NewHoustonHandler(apiToken string) HoustonServerWithHandler {
|
||||||
var tmp *houstonHandler
|
var tmp *houstonHandler
|
||||||
|
|
||||||
methods := make(map[string]reflect.Method)
|
methods := make(map[string]reflect.Method)
|
||||||
@ -44,10 +42,11 @@ func NewHoustonHandler() HoustonServerWithHandler {
|
|||||||
return &houstonHandler{
|
return &houstonHandler{
|
||||||
HoustonServer: NewServer(),
|
HoustonServer: NewServer(),
|
||||||
methods: methods,
|
methods: methods,
|
||||||
|
maingateApiToken: apiToken,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error {
|
func (h *houstonHandler) RegisterHandlers(serveMux gocommon.ServerMuxInterface, prefix string) error {
|
||||||
config := loadServerConfig()
|
config := loadServerConfig()
|
||||||
storagePath := config.StorageRoot
|
storagePath := config.StorageRoot
|
||||||
h.deployPath = path.Join(storagePath, sub_folder_name_deploys)
|
h.deployPath = path.Join(storagePath, sub_folder_name_deploys)
|
||||||
@ -61,15 +60,65 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Printf("houstonHandler registed. deployPath : %s, downloadPath : %s", h.deployPath, h.downloadPath)
|
|
||||||
|
|
||||||
if len(prefix) > 0 {
|
if len(prefix) > 0 {
|
||||||
prefix = "/" + prefix
|
prefix = "/" + prefix
|
||||||
}
|
}
|
||||||
serveMux.Handle(prefix, h)
|
serveMux.Handle(prefix, h)
|
||||||
|
|
||||||
fsx := http.FileServer(http.Dir(h.deployPath))
|
fsx := http.FileServer(http.Dir(h.deployPath))
|
||||||
serveMux.Handle(fmt.Sprintf("%s/%s/", prefix, sub_folder_name_deploys), http.StripPrefix(fmt.Sprintf("%s/%s/", prefix, sub_folder_name_deploys), fsx))
|
deployPrefix := fmt.Sprintf("%s/%s/", prefix, sub_folder_name_deploys)
|
||||||
|
logger.Printf("houstonHandler registed. deployPath : %s -> %s", fmt.Sprintf("%s/%s/", prefix, sub_folder_name_deploys), h.deployPath)
|
||||||
|
serveMux.HandleFunc(fmt.Sprintf("%s/%s/", prefix, sub_folder_name_deploys), func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
p := strings.TrimPrefix(r.URL.Path, deployPrefix)
|
||||||
|
rp := strings.TrimPrefix(r.URL.RawPath, deployPrefix)
|
||||||
|
|
||||||
|
h := md5.New()
|
||||||
|
src := strings.TrimLeft(r.URL.Path, fmt.Sprintf("/%s/", prefix))
|
||||||
|
|
||||||
|
h.Write([]byte(src))
|
||||||
|
at := hex.EncodeToString(h.Sum(nil))
|
||||||
|
|
||||||
|
if len(p) < len(r.URL.Path) && (r.URL.RawPath == "" || len(rp) < len(r.URL.RawPath)) && at == r.Header.Get("As-X-UrlHash") {
|
||||||
|
r2 := new(http.Request)
|
||||||
|
*r2 = *r
|
||||||
|
r2.URL = new(url.URL)
|
||||||
|
*r2.URL = *r.URL
|
||||||
|
r2.URL.Path = p
|
||||||
|
r2.URL.RawPath = rp
|
||||||
|
fsx.ServeHTTP(w, r2)
|
||||||
|
} else {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// config는 접근하기 편하게 단축 경로 제공
|
||||||
|
serveMux.HandleFunc("/config/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
logger.Println("config url.path :", r.URL.Path)
|
||||||
|
testhash := md5.New()
|
||||||
|
testhash.Write([]byte(r.URL.Path))
|
||||||
|
at := hex.EncodeToString(testhash.Sum(nil))
|
||||||
|
hash := r.Header.Get("As-X-UrlHash")
|
||||||
|
logger.Println("config at = hash :", at, hash)
|
||||||
|
if at == hash {
|
||||||
|
urlpath := strings.TrimPrefix(r.URL.Path, "/config/")
|
||||||
|
dir := path.Dir(urlpath)
|
||||||
|
file := path.Base(urlpath)
|
||||||
|
sourceFile := path.Join(h.deployPath, dir, "config", file)
|
||||||
|
logger.Println("config dest :", sourceFile)
|
||||||
|
bt, err := os.ReadFile(sourceFile)
|
||||||
|
if err != nil && !os.IsExist(err) {
|
||||||
|
logger.Println("config file is missing :", sourceFile)
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
} else {
|
||||||
|
if _, err = w.Write(bt); err != nil {
|
||||||
|
logger.Println("config write failed :", err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
ufsx := http.FileServer(http.Dir(h.downloadPath))
|
ufsx := http.FileServer(http.Dir(h.downloadPath))
|
||||||
serveMux.Handle(fmt.Sprintf("%s/%s/", prefix, sub_folder_name_downloads), http.StripPrefix(fmt.Sprintf("%s/%s/", prefix, sub_folder_name_downloads), ufsx))
|
serveMux.Handle(fmt.Sprintf("%s/%s/", prefix, sub_folder_name_downloads), http.StripPrefix(fmt.Sprintf("%s/%s/", prefix, sub_folder_name_downloads), ufsx))
|
||||||
@ -78,8 +127,7 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
|
|||||||
defer func() {
|
defer func() {
|
||||||
s := recover()
|
s := recover()
|
||||||
if s != nil {
|
if s != nil {
|
||||||
logger.Println(s)
|
logger.Error(s)
|
||||||
debug.PrintStack()
|
|
||||||
}
|
}
|
||||||
io.Copy(io.Discard, r.Body)
|
io.Copy(io.Discard, r.Body)
|
||||||
r.Body.Close()
|
r.Body.Close()
|
||||||
@ -90,10 +138,12 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
|
|||||||
filename := r.Header.Get("Houston-Service-Filename")
|
filename := r.Header.Get("Houston-Service-Filename")
|
||||||
dir := path.Join(h.downloadPath, name, version)
|
dir := path.Join(h.downloadPath, name, version)
|
||||||
if err := os.MkdirAll(dir, 0775); err == nil {
|
if err := os.MkdirAll(dir, 0775); err == nil {
|
||||||
file, _ := os.Create(path.Join(dir, filename))
|
filepath := path.Join(dir, filename)
|
||||||
if file != nil {
|
// filepath가 이미 있으면 append
|
||||||
defer file.Close()
|
localfile, _ := os.OpenFile(filepath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
|
||||||
if _, err = io.Copy(file, r.Body); err != nil {
|
if localfile != nil {
|
||||||
|
defer localfile.Close()
|
||||||
|
if _, err = io.Copy(localfile, r.Body); err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -107,31 +157,6 @@ func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var noauth = flagx.Bool("noauth", false, "")
|
|
||||||
|
|
||||||
type respWriteTracker struct {
|
|
||||||
inner http.ResponseWriter
|
|
||||||
reqUrlValues url.Values
|
|
||||||
body []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rt *respWriteTracker) Header() http.Header {
|
|
||||||
return rt.inner.Header()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rt *respWriteTracker) Write(bt []byte) (int, error) {
|
|
||||||
rt.body = append(rt.body, bt...)
|
|
||||||
return rt.inner.Write(bt)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rt *respWriteTracker) WriteHeader(statusCode int) {
|
|
||||||
if statusCode != http.StatusOK {
|
|
||||||
logger.Println()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var logApiCallFlag = flagx.Bool("logapicall", false, "")
|
|
||||||
|
|
||||||
func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
defer func() {
|
defer func() {
|
||||||
s := recover()
|
s := recover()
|
||||||
@ -146,38 +171,6 @@ func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
r.Body.Close()
|
r.Body.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var userinfo map[string]any
|
|
||||||
if !*noauth {
|
|
||||||
authheader := r.Header.Get("Authorization")
|
|
||||||
if len(authheader) == 0 {
|
|
||||||
logger.Println("Authorization header is not valid :", authheader)
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req, _ := http.NewRequest("GET", "https://graph.microsoft.com/oidc/userinfo", nil)
|
|
||||||
req.Header.Add("Authorization", authheader)
|
|
||||||
client := &http.Client{}
|
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
logger.Println("graph microsoft api call failed :", err)
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
raw, _ := io.ReadAll(resp.Body)
|
|
||||||
if err = json.Unmarshal(raw, &userinfo); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, expired := userinfo["error"]; expired {
|
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var operation string
|
var operation string
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" {
|
||||||
operation = r.FormValue("operation")
|
operation = r.FormValue("operation")
|
||||||
@ -198,27 +191,6 @@ func (h *houstonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if *logApiCallFlag {
|
|
||||||
var urlvalues url.Values
|
|
||||||
if r.Method == "POST" {
|
|
||||||
urlvalues = r.Form
|
|
||||||
} else {
|
|
||||||
urlvalues = r.URL.Query()
|
|
||||||
}
|
|
||||||
|
|
||||||
tracker := &respWriteTracker{
|
|
||||||
inner: w,
|
|
||||||
reqUrlValues: urlvalues,
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
logger.Println("api called :", userinfo["email"], urlvalues)
|
|
||||||
logger.Println("-->", string(tracker.body))
|
|
||||||
}()
|
|
||||||
|
|
||||||
w = http.ResponseWriter(tracker)
|
|
||||||
}
|
|
||||||
|
|
||||||
args := []reflect.Value{
|
args := []reflect.Value{
|
||||||
reflect.ValueOf(h),
|
reflect.ValueOf(h),
|
||||||
reflect.ValueOf(w),
|
reflect.ValueOf(w),
|
||||||
|
|||||||
@ -2,11 +2,16 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
"repositories.action2quare.com/ayo/houston/shared"
|
"repositories.action2quare.com/ayo/houston/shared"
|
||||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||||
)
|
)
|
||||||
@ -26,6 +31,8 @@ type ProcessSnapshot struct {
|
|||||||
|
|
||||||
type hostWithChan struct {
|
type hostWithChan struct {
|
||||||
Hostname string
|
Hostname string
|
||||||
|
PrivateIp string
|
||||||
|
PublicIp string
|
||||||
Procs []*protos.ProcessDescription `json:"procs"`
|
Procs []*protos.ProcessDescription `json:"procs"`
|
||||||
Deploys map[string][]*protos.VersionAndArgs `json:"deploys"`
|
Deploys map[string][]*protos.VersionAndArgs `json:"deploys"`
|
||||||
opChan chan *opdef
|
opChan chan *opdef
|
||||||
@ -38,6 +45,8 @@ func makeHostWithChan(desc *protos.OperationQueryRequest) *hostWithChan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &hostWithChan{
|
return &hostWithChan{
|
||||||
|
PrivateIp: desc.PrivateIp,
|
||||||
|
PublicIp: desc.PublicIp,
|
||||||
Hostname: desc.GetHostname(),
|
Hostname: desc.GetHostname(),
|
||||||
Procs: desc.Procs,
|
Procs: desc.Procs,
|
||||||
Deploys: newdeploys,
|
Deploys: newdeploys,
|
||||||
@ -57,6 +66,26 @@ func (pc *hostWithChan) makeOpChan() *hostWithChan {
|
|||||||
type hostPool struct {
|
type hostPool struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
hosts map[string]*hostWithChan
|
hosts map[string]*hostWithChan
|
||||||
|
exportChan chan string
|
||||||
|
}
|
||||||
|
|
||||||
|
type deployingProgress struct {
|
||||||
|
*protos.DeployingProgress
|
||||||
|
Timestamp int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type deployingBoard struct {
|
||||||
|
sync.Mutex
|
||||||
|
progs []deployingProgress
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *deployingBoard) clone() (out []deployingProgress) {
|
||||||
|
db.Lock()
|
||||||
|
defer db.Unlock()
|
||||||
|
|
||||||
|
out = make([]deployingProgress, len(db.progs))
|
||||||
|
copy(out, db.progs)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sp *hostPool) regist(desc *protos.OperationQueryRequest) (string, chan *opdef) {
|
func (sp *hostPool) regist(desc *protos.OperationQueryRequest) (string, chan *opdef) {
|
||||||
@ -68,6 +97,28 @@ func (sp *hostPool) regist(desc *protos.OperationQueryRequest) (string, chan *op
|
|||||||
} else {
|
} else {
|
||||||
host = makeHostWithChan(desc).withOpChan(host.opChan)
|
host = makeHostWithChan(desc).withOpChan(host.opChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Println("houston agent registered :", desc.Hostname, desc.PrivateIp, desc.PublicIp)
|
||||||
|
go func(prvip string, pubip string) {
|
||||||
|
if len(prvip) > 0 {
|
||||||
|
address := net.JoinHostPort(prvip, "9100")
|
||||||
|
if conn, _ := net.DialTimeout("tcp", address, 3*time.Second); conn != nil {
|
||||||
|
conn.Close()
|
||||||
|
sp.exportChan <- "+" + address
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(pubip) > 0 {
|
||||||
|
address := net.JoinHostPort(pubip, "9100")
|
||||||
|
if conn, _ := net.DialTimeout("tcp", address, 3*time.Second); conn != nil {
|
||||||
|
conn.Close()
|
||||||
|
sp.exportChan <- "+" + address
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(desc.PrivateIp, desc.PublicIp)
|
||||||
|
|
||||||
sp.hosts[desc.Hostname] = host
|
sp.hosts[desc.Hostname] = host
|
||||||
return desc.Hostname, host.opChan
|
return desc.Hostname, host.opChan
|
||||||
}
|
}
|
||||||
@ -87,6 +138,12 @@ func (sp *hostPool) unregist(key string) {
|
|||||||
sp.Lock()
|
sp.Lock()
|
||||||
defer sp.Unlock()
|
defer sp.Unlock()
|
||||||
|
|
||||||
|
host := sp.hosts[key]
|
||||||
|
if host != nil {
|
||||||
|
sp.exportChan <- "-" + host.PublicIp
|
||||||
|
sp.exportChan <- "-" + host.PrivateIp
|
||||||
|
}
|
||||||
|
|
||||||
delete(sp.hosts, key)
|
delete(sp.hosts, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +192,7 @@ func (sp *hostPool) query(filter func(*hostWithChan) bool) []*hostWithChan {
|
|||||||
type operationServer struct {
|
type operationServer struct {
|
||||||
protos.UnimplementedOperationServer
|
protos.UnimplementedOperationServer
|
||||||
hp hostPool
|
hp hostPool
|
||||||
|
db deployingBoard
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshal(argval reflect.Value, output map[string]string) map[string]string {
|
func marshal(argval reflect.Value, output map[string]string) map[string]string {
|
||||||
@ -165,15 +223,19 @@ func marshal(argval reflect.Value, output map[string]string) map[string]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (os *operationServer) Query(svr protos.Operation_QueryServer) error {
|
func (os *operationServer) Query(svr protos.Operation_QueryServer) error {
|
||||||
// 서버는 업데이트가 있는지 확인하고 있으면 stream에 응답을 보낸다.
|
|
||||||
// 업데이트가 없으면 대기
|
|
||||||
desc, err := svr.Recv()
|
desc, err := svr.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hostname := desc.Hostname
|
||||||
key, opChan := os.hp.regist(desc)
|
key, opChan := os.hp.regist(desc)
|
||||||
defer os.hp.unregist(key)
|
defer func() {
|
||||||
|
logger.Println("operationServer.Query : houston client unregistered ", hostname)
|
||||||
|
os.hp.unregist(key)
|
||||||
|
}()
|
||||||
|
|
||||||
|
logger.Println("operationServer.Query : houston client registered ", hostname)
|
||||||
|
|
||||||
Outer:
|
Outer:
|
||||||
for {
|
for {
|
||||||
@ -192,6 +254,25 @@ Outer:
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (os *operationServer) ReportDeployingProgress(ctx context.Context, dp *protos.DeployingProgress) (*protos.Empty, error) {
|
||||||
|
os.db.Lock()
|
||||||
|
defer os.db.Unlock()
|
||||||
|
|
||||||
|
for i, p := range os.db.progs {
|
||||||
|
if p.Hostname == dp.Hostname && p.Name == dp.Name && p.Version == dp.Version {
|
||||||
|
os.db.progs[i].DeployingProgress = dp
|
||||||
|
os.db.progs[i].Timestamp = time.Now().UTC().Unix()
|
||||||
|
return &protos.Empty{}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os.db.progs = append(os.db.progs, deployingProgress{
|
||||||
|
DeployingProgress: dp,
|
||||||
|
Timestamp: time.Now().UTC().Unix(),
|
||||||
|
})
|
||||||
|
return &protos.Empty{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (os *operationServer) Refresh(ctx context.Context, desc *protos.OperationQueryRequest) (*protos.Empty, error) {
|
func (os *operationServer) Refresh(ctx context.Context, desc *protos.OperationQueryRequest) (*protos.Empty, error) {
|
||||||
os.hp.refresh(desc)
|
os.hp.refresh(desc)
|
||||||
return &protos.Empty{}, nil
|
return &protos.Empty{}, nil
|
||||||
@ -221,12 +302,29 @@ func (os *operationServer) Deploy(d DeployRequest) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range targets {
|
dps := make([]deployingProgress, len(targets))
|
||||||
|
now := time.Now().UTC().Unix()
|
||||||
|
for i, t := range targets {
|
||||||
|
dps[i] = deployingProgress{
|
||||||
|
DeployingProgress: &protos.DeployingProgress{
|
||||||
|
Hostname: t.Hostname,
|
||||||
|
Name: d.Name,
|
||||||
|
Version: d.Version,
|
||||||
|
State: "prepare",
|
||||||
|
},
|
||||||
|
Timestamp: now,
|
||||||
|
}
|
||||||
|
|
||||||
t.opChan <- &opdef{
|
t.opChan <- &opdef{
|
||||||
operation: shared.Deploy,
|
operation: shared.Deploy,
|
||||||
args: d,
|
args: d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os.db.Lock()
|
||||||
|
defer os.db.Unlock()
|
||||||
|
|
||||||
|
os.db.progs = dps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (os *operationServer) Withdraw(d WithdrawRequest) {
|
func (os *operationServer) Withdraw(d WithdrawRequest) {
|
||||||
@ -386,10 +484,43 @@ func (os *operationServer) Hosts() map[string]hostSnapshot {
|
|||||||
return os.hp.allHosts()
|
return os.hp.allHosts()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (os *operationServer) DeplyingProgress() []deployingProgress {
|
||||||
|
return os.db.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
func targetExportLoop(in chan string) {
|
||||||
|
all := make(map[string]bool)
|
||||||
|
for addr := range in {
|
||||||
|
logger.Println("targetExportLoop :", addr)
|
||||||
|
if addr[0] == '+' {
|
||||||
|
all[addr[1:]] = true
|
||||||
|
} else if addr[0] == '-' {
|
||||||
|
delete(all, addr[1:])
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]string, 0, len(all))
|
||||||
|
for k := range all {
|
||||||
|
list = append(list, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
output := []map[string]any{{"targets": list}}
|
||||||
|
|
||||||
|
if file, err := os.Create("prometheus_targets.json"); err == nil {
|
||||||
|
enc := json.NewEncoder(file)
|
||||||
|
enc.Encode(output)
|
||||||
|
file.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func newOperationServer() *operationServer {
|
func newOperationServer() *operationServer {
|
||||||
|
exportChan := make(chan string)
|
||||||
|
go targetExportLoop(exportChan)
|
||||||
|
|
||||||
return &operationServer{
|
return &operationServer{
|
||||||
hp: hostPool{
|
hp: hostPool{
|
||||||
hosts: map[string]*hostWithChan{},
|
hosts: map[string]*hostWithChan{},
|
||||||
|
exportChan: exportChan,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,12 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
"repositories.action2quare.com/ayo/houston/client"
|
|
||||||
"repositories.action2quare.com/ayo/houston/shared"
|
"repositories.action2quare.com/ayo/houston/shared"
|
||||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||||
|
|
||||||
@ -25,7 +23,6 @@ type HoustonServer interface {
|
|||||||
type serverConfig struct {
|
type serverConfig struct {
|
||||||
GrpcPort int `json:"grpc_port"`
|
GrpcPort int `json:"grpc_port"`
|
||||||
StorageRoot string `json:"storage_path"`
|
StorageRoot string `json:"storage_path"`
|
||||||
RunAsClient bool `json:"run_as_client"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeployRequest struct {
|
type DeployRequest struct {
|
||||||
@ -108,26 +105,21 @@ type Operation interface {
|
|||||||
RestartProcess(RestartProcessRequest)
|
RestartProcess(RestartProcessRequest)
|
||||||
Upload(UploadRequest)
|
Upload(UploadRequest)
|
||||||
Hosts() map[string]hostSnapshot
|
Hosts() map[string]hostSnapshot
|
||||||
|
DeplyingProgress() []deployingProgress
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadServerConfig() serverConfig {
|
type outerconfig struct {
|
||||||
configFile, err := os.Open("config.json")
|
Houston struct {
|
||||||
if err != nil {
|
|
||||||
logger.Println(err)
|
|
||||||
return serverConfig{
|
|
||||||
GrpcPort: 8080,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
defer configFile.Close()
|
|
||||||
|
|
||||||
var config struct {
|
|
||||||
Houston *struct {
|
|
||||||
Server serverConfig `json:"server"`
|
Server serverConfig `json:"server"`
|
||||||
} `json:"houston"`
|
} `json:"houston"`
|
||||||
}
|
}
|
||||||
|
|
||||||
dec := json.NewDecoder(configFile)
|
var storagePath = flagx.String("hs_storage", "", "")
|
||||||
err = dec.Decode(&config)
|
var grpcPort = flagx.Int("hs_grpc_port", 0, "")
|
||||||
|
|
||||||
|
func loadServerConfig() serverConfig {
|
||||||
|
var oc outerconfig
|
||||||
|
err := gocommon.LoadConfig[outerconfig](&oc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Println(err)
|
logger.Println(err)
|
||||||
return serverConfig{
|
return serverConfig{
|
||||||
@ -135,14 +127,16 @@ func loadServerConfig() serverConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Houston == nil {
|
if len(*storagePath) > 0 {
|
||||||
logger.Println(`"houston" object is missing in config.json`)
|
// override
|
||||||
return serverConfig{
|
oc.Houston.Server.StorageRoot = *storagePath
|
||||||
GrpcPort: 8080,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return config.Houston.Server
|
if *grpcPort != 0 {
|
||||||
|
oc.Houston.Server.GrpcPort = *grpcPort
|
||||||
|
}
|
||||||
|
|
||||||
|
return oc.Houston.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer() HoustonServer {
|
func NewServer() HoustonServer {
|
||||||
@ -176,27 +170,11 @@ func (hs *houstonServer) Start() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if loadServerConfig().RunAsClient {
|
return hs.rpcServer.Serve(lis)
|
||||||
go func() {
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
hc, err := client.NewClient()
|
|
||||||
if err != nil {
|
|
||||||
logger.Fatal(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
hc.Start()
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := hs.rpcServer.Serve(lis); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hs *houstonServer) Stop() {
|
func (hs *houstonServer) Stop() {
|
||||||
hs.rpcServer.GracefulStop()
|
hs.rpcServer.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hs *houstonServer) Operation() Operation {
|
func (hs *houstonServer) Operation() Operation {
|
||||||
|
|||||||
@ -1,12 +1,5 @@
|
|||||||
package shared
|
package shared
|
||||||
|
|
||||||
import (
|
|
||||||
"io/fs"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Operation string
|
type Operation string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -17,6 +10,7 @@ const (
|
|||||||
Restart = Operation("restart")
|
Restart = Operation("restart")
|
||||||
Stop = Operation("stop")
|
Stop = Operation("stop")
|
||||||
Upload = Operation("upload")
|
Upload = Operation("upload")
|
||||||
|
Exception = Operation("exception")
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeployRequest struct {
|
type DeployRequest struct {
|
||||||
@ -36,6 +30,8 @@ type StartProcessRequest struct {
|
|||||||
Name string
|
Name string
|
||||||
Version string
|
Version string
|
||||||
Args []string
|
Args []string
|
||||||
|
AutoRestart bool
|
||||||
|
OutputLogFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
type StopProcessRequest struct {
|
type StopProcessRequest struct {
|
||||||
@ -57,62 +53,3 @@ type UploadRequest struct {
|
|||||||
Filter string
|
Filter string
|
||||||
DeleteAfterUploaded string // true, false
|
DeleteAfterUploaded string // true, false
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParsedVersionString = []string
|
|
||||||
|
|
||||||
func ParseVersionString(ver string) ParsedVersionString {
|
|
||||||
return strings.Split(ver, ".")
|
|
||||||
}
|
|
||||||
|
|
||||||
func CompareVersionString(lhs, rhs ParsedVersionString) int {
|
|
||||||
minlen := len(lhs)
|
|
||||||
if minlen > len(rhs) {
|
|
||||||
minlen = len(rhs)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < minlen; i++ {
|
|
||||||
if len(lhs[i]) < len(rhs[i]) {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(lhs[i]) > len(rhs[i]) {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if lhs[i] < rhs[i] {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
if lhs[i] > rhs[i] {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return len(lhs) - len(rhs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func FindLastestVersion(storageRoot, name string) (string, error) {
|
|
||||||
// 최신 버전을 찾음
|
|
||||||
targetPath := path.Join(storageRoot, name)
|
|
||||||
entries, err := os.ReadDir(targetPath)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if len(entries) == 0 {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
var dironly []fs.DirEntry
|
|
||||||
for _, ent := range entries {
|
|
||||||
if ent.IsDir() {
|
|
||||||
dironly = append(dironly, ent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
latest := ParseVersionString(dironly[0].Name())
|
|
||||||
for i := 1; i < len(dironly); i++ {
|
|
||||||
next := ParseVersionString(dironly[i].Name())
|
|
||||||
if CompareVersionString(latest, next) < 0 {
|
|
||||||
latest = next
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return strings.Join(latest, "."), nil
|
|
||||||
}
|
|
||||||
|
|||||||
@ -191,6 +191,8 @@ type OperationQueryRequest struct {
|
|||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
Hostname string `protobuf:"bytes,1,opt,name=hostname,proto3" json:"hostname,omitempty"`
|
Hostname string `protobuf:"bytes,1,opt,name=hostname,proto3" json:"hostname,omitempty"`
|
||||||
|
PublicIp string `protobuf:"bytes,4,opt,name=public_ip,json=publicIp,proto3" json:"public_ip,omitempty"`
|
||||||
|
PrivateIp string `protobuf:"bytes,5,opt,name=private_ip,json=privateIp,proto3" json:"private_ip,omitempty"`
|
||||||
Procs []*ProcessDescription `protobuf:"bytes,2,rep,name=procs,proto3" json:"procs,omitempty"`
|
Procs []*ProcessDescription `protobuf:"bytes,2,rep,name=procs,proto3" json:"procs,omitempty"`
|
||||||
Deploys []*DeployedVersions `protobuf:"bytes,3,rep,name=deploys,proto3" json:"deploys,omitempty"`
|
Deploys []*DeployedVersions `protobuf:"bytes,3,rep,name=deploys,proto3" json:"deploys,omitempty"`
|
||||||
}
|
}
|
||||||
@ -234,6 +236,20 @@ func (x *OperationQueryRequest) GetHostname() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *OperationQueryRequest) GetPublicIp() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.PublicIp
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *OperationQueryRequest) GetPrivateIp() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.PrivateIp
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (x *OperationQueryRequest) GetProcs() []*ProcessDescription {
|
func (x *OperationQueryRequest) GetProcs() []*ProcessDescription {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Procs
|
return x.Procs
|
||||||
@ -382,6 +398,93 @@ func (x *OperationQueryResponse) GetArgs() map[string]string {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeployingProgress struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
Hostname string `protobuf:"bytes,1,opt,name=hostname,proto3" json:"hostname,omitempty"`
|
||||||
|
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||||
|
Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"`
|
||||||
|
State string `protobuf:"bytes,4,opt,name=state,proto3" json:"state,omitempty"`
|
||||||
|
Progress int64 `protobuf:"varint,5,opt,name=progress,proto3" json:"progress,omitempty"`
|
||||||
|
Total int64 `protobuf:"varint,6,opt,name=total,proto3" json:"total,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeployingProgress) Reset() {
|
||||||
|
*x = DeployingProgress{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_protos_operation_proto_msgTypes[5]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeployingProgress) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DeployingProgress) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *DeployingProgress) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_protos_operation_proto_msgTypes[5]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use DeployingProgress.ProtoReflect.Descriptor instead.
|
||||||
|
func (*DeployingProgress) Descriptor() ([]byte, []int) {
|
||||||
|
return file_protos_operation_proto_rawDescGZIP(), []int{5}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeployingProgress) GetHostname() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Hostname
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeployingProgress) GetName() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeployingProgress) GetVersion() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Version
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeployingProgress) GetState() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.State
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeployingProgress) GetProgress() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Progress
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeployingProgress) GetTotal() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Total
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
var File_protos_operation_proto protoreflect.FileDescriptor
|
var File_protos_operation_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_protos_operation_proto_rawDesc = []byte{
|
var file_protos_operation_proto_rawDesc = []byte{
|
||||||
@ -397,49 +500,67 @@ var file_protos_operation_proto_rawDesc = []byte{
|
|||||||
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2b, 0x0a, 0x08, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x73,
|
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2b, 0x0a, 0x08, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x73,
|
||||||
0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
|
0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
|
||||||
0x41, 0x6e, 0x64, 0x41, 0x72, 0x67, 0x73, 0x52, 0x08, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
|
0x41, 0x6e, 0x64, 0x41, 0x72, 0x67, 0x73, 0x52, 0x08, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
|
||||||
0x73, 0x22, 0x8b, 0x01, 0x0a, 0x15, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51,
|
0x73, 0x22, 0xc7, 0x01, 0x0a, 0x15, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51,
|
||||||
0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x68,
|
0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x68,
|
||||||
0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x68,
|
0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x68,
|
||||||
0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x29, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x63, 0x73,
|
0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69,
|
||||||
0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73,
|
0x63, 0x5f, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x75, 0x62, 0x6c,
|
||||||
0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x05, 0x70, 0x72, 0x6f,
|
0x69, 0x63, 0x49, 0x70, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x5f,
|
||||||
0x63, 0x73, 0x12, 0x2b, 0x0a, 0x07, 0x64, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x73, 0x18, 0x03, 0x20,
|
0x69, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74,
|
||||||
0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x64, 0x56, 0x65,
|
0x65, 0x49, 0x70, 0x12, 0x29, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x63, 0x73, 0x18, 0x02, 0x20, 0x03,
|
||||||
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x07, 0x64, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x73, 0x22,
|
0x28, 0x0b, 0x32, 0x13, 0x2e, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x44, 0x65, 0x73, 0x63,
|
||||||
0x8d, 0x01, 0x0a, 0x12, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x44, 0x65, 0x73, 0x63, 0x72,
|
0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x63, 0x73, 0x12, 0x2b,
|
||||||
0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01,
|
0x0a, 0x07, 0x64, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72,
|
0x11, 0x2e, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x64, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f,
|
||||||
0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x12, 0x18,
|
0x6e, 0x73, 0x52, 0x07, 0x64, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x73, 0x22, 0x8d, 0x01, 0x0a, 0x12,
|
||||||
0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69,
|
||||||
0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74,
|
0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0d, 0x2e, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73,
|
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, 0x67, 0x73, 0x18, 0x02,
|
||||||
0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a,
|
0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65,
|
||||||
0x03, 0x70, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x70, 0x69, 0x64, 0x22,
|
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72,
|
||||||
0xa6, 0x01, 0x0a, 0x16, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, 0x65,
|
0x73, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20,
|
||||||
0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x70,
|
0x01, 0x28, 0x0e, 0x32, 0x0d, 0x2e, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x53, 0x74, 0x61,
|
||||||
0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6f,
|
0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x70, 0x69, 0x64,
|
||||||
0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x35, 0x0a, 0x04, 0x61, 0x72, 0x67, 0x73,
|
0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x70, 0x69, 0x64, 0x22, 0xa6, 0x01, 0x0a, 0x16,
|
||||||
0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69,
|
0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65,
|
||||||
0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e,
|
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74,
|
||||||
0x41, 0x72, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x1a,
|
0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61,
|
||||||
0x37, 0x0a, 0x09, 0x41, 0x72, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
|
0x74, 0x69, 0x6f, 0x6e, 0x12, 0x35, 0x0a, 0x04, 0x61, 0x72, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03,
|
||||||
0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14,
|
0x28, 0x0b, 0x32, 0x21, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75,
|
||||||
0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76,
|
0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x41, 0x72, 0x67, 0x73,
|
||||||
0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x2a, 0x4e, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x63,
|
0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x1a, 0x37, 0x0a, 0x09, 0x41,
|
||||||
0x65, 0x73, 0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x74, 0x6f, 0x70,
|
0x72, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
|
||||||
0x70, 0x65, 0x64, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x53, 0x74, 0x6f, 0x70, 0x70, 0x69, 0x6e,
|
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61,
|
||||||
0x67, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x75, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x10, 0x02,
|
0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
|
||||||
0x12, 0x0b, 0x0a, 0x07, 0x52, 0x65, 0x73, 0x74, 0x61, 0x72, 0x74, 0x10, 0x03, 0x12, 0x09, 0x0a,
|
0x3a, 0x02, 0x38, 0x01, 0x22, 0xa5, 0x01, 0x0a, 0x11, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x69,
|
||||||
0x05, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x04, 0x32, 0x78, 0x0a, 0x09, 0x4f, 0x70, 0x65, 0x72,
|
0x6e, 0x67, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x68, 0x6f,
|
||||||
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3e, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x16,
|
0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x68, 0x6f,
|
||||||
0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52,
|
0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02,
|
||||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69,
|
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65,
|
||||||
0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
|
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72,
|
||||||
0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x2b, 0x0a, 0x07, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68,
|
0x73, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20,
|
||||||
0x12, 0x16, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72,
|
0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72,
|
||||||
0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x06, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79,
|
0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x70, 0x72,
|
||||||
0x22, 0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f,
|
0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18,
|
||||||
0x74, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x2a, 0x4e, 0x0a, 0x0c,
|
||||||
|
0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0b, 0x0a, 0x07,
|
||||||
|
0x53, 0x74, 0x6f, 0x70, 0x70, 0x65, 0x64, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x53, 0x74, 0x6f,
|
||||||
|
0x70, 0x70, 0x69, 0x6e, 0x67, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x75, 0x6e, 0x6e, 0x69,
|
||||||
|
0x6e, 0x67, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x65, 0x73, 0x74, 0x61, 0x72, 0x74, 0x10,
|
||||||
|
0x03, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0x04, 0x32, 0xb1, 0x01, 0x0a,
|
||||||
|
0x09, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x3e, 0x0a, 0x05, 0x51, 0x75,
|
||||||
|
0x65, 0x72, 0x79, 0x12, 0x16, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51,
|
||||||
|
0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x4f, 0x70,
|
||||||
|
0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70,
|
||||||
|
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x2b, 0x0a, 0x07, 0x52, 0x65,
|
||||||
|
0x66, 0x72, 0x65, 0x73, 0x68, 0x12, 0x16, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f,
|
||||||
|
0x6e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x06, 0x2e,
|
||||||
|
0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x17, 0x52, 0x65, 0x70, 0x6f, 0x72,
|
||||||
|
0x74, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65,
|
||||||
|
0x73, 0x73, 0x12, 0x12, 0x2e, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x69, 0x6e, 0x67, 0x50, 0x72,
|
||||||
|
0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x1a, 0x06, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00,
|
||||||
|
0x42, 0x0f, 0x5a, 0x0d, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||||
|
0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -455,7 +576,7 @@ func file_protos_operation_proto_rawDescGZIP() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var file_protos_operation_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
var file_protos_operation_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||||
var file_protos_operation_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
|
var file_protos_operation_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
|
||||||
var file_protos_operation_proto_goTypes = []interface{}{
|
var file_protos_operation_proto_goTypes = []interface{}{
|
||||||
(ProcessState)(0), // 0: ProcessState
|
(ProcessState)(0), // 0: ProcessState
|
||||||
(*VersionAndArgs)(nil), // 1: VersionAndArgs
|
(*VersionAndArgs)(nil), // 1: VersionAndArgs
|
||||||
@ -463,21 +584,24 @@ var file_protos_operation_proto_goTypes = []interface{}{
|
|||||||
(*OperationQueryRequest)(nil), // 3: OperationQueryRequest
|
(*OperationQueryRequest)(nil), // 3: OperationQueryRequest
|
||||||
(*ProcessDescription)(nil), // 4: ProcessDescription
|
(*ProcessDescription)(nil), // 4: ProcessDescription
|
||||||
(*OperationQueryResponse)(nil), // 5: OperationQueryResponse
|
(*OperationQueryResponse)(nil), // 5: OperationQueryResponse
|
||||||
nil, // 6: OperationQueryResponse.ArgsEntry
|
(*DeployingProgress)(nil), // 6: DeployingProgress
|
||||||
(*Empty)(nil), // 7: Empty
|
nil, // 7: OperationQueryResponse.ArgsEntry
|
||||||
|
(*Empty)(nil), // 8: Empty
|
||||||
}
|
}
|
||||||
var file_protos_operation_proto_depIdxs = []int32{
|
var file_protos_operation_proto_depIdxs = []int32{
|
||||||
1, // 0: DeployedVersions.versions:type_name -> VersionAndArgs
|
1, // 0: DeployedVersions.versions:type_name -> VersionAndArgs
|
||||||
4, // 1: OperationQueryRequest.procs:type_name -> ProcessDescription
|
4, // 1: OperationQueryRequest.procs:type_name -> ProcessDescription
|
||||||
2, // 2: OperationQueryRequest.deploys:type_name -> DeployedVersions
|
2, // 2: OperationQueryRequest.deploys:type_name -> DeployedVersions
|
||||||
0, // 3: ProcessDescription.state:type_name -> ProcessState
|
0, // 3: ProcessDescription.state:type_name -> ProcessState
|
||||||
6, // 4: OperationQueryResponse.args:type_name -> OperationQueryResponse.ArgsEntry
|
7, // 4: OperationQueryResponse.args:type_name -> OperationQueryResponse.ArgsEntry
|
||||||
3, // 5: Operation.Query:input_type -> OperationQueryRequest
|
3, // 5: Operation.Query:input_type -> OperationQueryRequest
|
||||||
3, // 6: Operation.Refresh:input_type -> OperationQueryRequest
|
3, // 6: Operation.Refresh:input_type -> OperationQueryRequest
|
||||||
5, // 7: Operation.Query:output_type -> OperationQueryResponse
|
6, // 7: Operation.ReportDeployingProgress:input_type -> DeployingProgress
|
||||||
7, // 8: Operation.Refresh:output_type -> Empty
|
5, // 8: Operation.Query:output_type -> OperationQueryResponse
|
||||||
7, // [7:9] is the sub-list for method output_type
|
8, // 9: Operation.Refresh:output_type -> Empty
|
||||||
5, // [5:7] is the sub-list for method input_type
|
8, // 10: Operation.ReportDeployingProgress:output_type -> Empty
|
||||||
|
8, // [8:11] is the sub-list for method output_type
|
||||||
|
5, // [5:8] is the sub-list for method input_type
|
||||||
5, // [5:5] is the sub-list for extension type_name
|
5, // [5:5] is the sub-list for extension type_name
|
||||||
5, // [5:5] is the sub-list for extension extendee
|
5, // [5:5] is the sub-list for extension extendee
|
||||||
0, // [0:5] is the sub-list for field type_name
|
0, // [0:5] is the sub-list for field type_name
|
||||||
@ -550,6 +674,18 @@ func file_protos_operation_proto_init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
file_protos_operation_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*DeployingProgress); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
type x struct{}
|
type x struct{}
|
||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
@ -557,7 +693,7 @@ func file_protos_operation_proto_init() {
|
|||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: file_protos_operation_proto_rawDesc,
|
RawDescriptor: file_protos_operation_proto_rawDesc,
|
||||||
NumEnums: 1,
|
NumEnums: 1,
|
||||||
NumMessages: 6,
|
NumMessages: 7,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 1,
|
NumServices: 1,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -24,6 +24,7 @@ const _ = grpc.SupportPackageIsVersion7
|
|||||||
type OperationClient interface {
|
type OperationClient interface {
|
||||||
Query(ctx context.Context, opts ...grpc.CallOption) (Operation_QueryClient, error)
|
Query(ctx context.Context, opts ...grpc.CallOption) (Operation_QueryClient, error)
|
||||||
Refresh(ctx context.Context, in *OperationQueryRequest, opts ...grpc.CallOption) (*Empty, error)
|
Refresh(ctx context.Context, in *OperationQueryRequest, opts ...grpc.CallOption) (*Empty, error)
|
||||||
|
ReportDeployingProgress(ctx context.Context, in *DeployingProgress, opts ...grpc.CallOption) (*Empty, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type operationClient struct {
|
type operationClient struct {
|
||||||
@ -74,12 +75,22 @@ func (c *operationClient) Refresh(ctx context.Context, in *OperationQueryRequest
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *operationClient) ReportDeployingProgress(ctx context.Context, in *DeployingProgress, opts ...grpc.CallOption) (*Empty, error) {
|
||||||
|
out := new(Empty)
|
||||||
|
err := c.cc.Invoke(ctx, "/Operation/ReportDeployingProgress", in, out, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
// OperationServer is the server API for Operation service.
|
// OperationServer is the server API for Operation service.
|
||||||
// All implementations must embed UnimplementedOperationServer
|
// All implementations must embed UnimplementedOperationServer
|
||||||
// for forward compatibility
|
// for forward compatibility
|
||||||
type OperationServer interface {
|
type OperationServer interface {
|
||||||
Query(Operation_QueryServer) error
|
Query(Operation_QueryServer) error
|
||||||
Refresh(context.Context, *OperationQueryRequest) (*Empty, error)
|
Refresh(context.Context, *OperationQueryRequest) (*Empty, error)
|
||||||
|
ReportDeployingProgress(context.Context, *DeployingProgress) (*Empty, error)
|
||||||
mustEmbedUnimplementedOperationServer()
|
mustEmbedUnimplementedOperationServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +104,9 @@ func (UnimplementedOperationServer) Query(Operation_QueryServer) error {
|
|||||||
func (UnimplementedOperationServer) Refresh(context.Context, *OperationQueryRequest) (*Empty, error) {
|
func (UnimplementedOperationServer) Refresh(context.Context, *OperationQueryRequest) (*Empty, error) {
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method Refresh not implemented")
|
return nil, status.Errorf(codes.Unimplemented, "method Refresh not implemented")
|
||||||
}
|
}
|
||||||
|
func (UnimplementedOperationServer) ReportDeployingProgress(context.Context, *DeployingProgress) (*Empty, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method ReportDeployingProgress not implemented")
|
||||||
|
}
|
||||||
func (UnimplementedOperationServer) mustEmbedUnimplementedOperationServer() {}
|
func (UnimplementedOperationServer) mustEmbedUnimplementedOperationServer() {}
|
||||||
|
|
||||||
// UnsafeOperationServer may be embedded to opt out of forward compatibility for this service.
|
// UnsafeOperationServer may be embedded to opt out of forward compatibility for this service.
|
||||||
@ -150,6 +164,24 @@ func _Operation_Refresh_Handler(srv interface{}, ctx context.Context, dec func(i
|
|||||||
return interceptor(ctx, in, info, handler)
|
return interceptor(ctx, in, info, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _Operation_ReportDeployingProgress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(DeployingProgress)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(OperationServer).ReportDeployingProgress(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: "/Operation/ReportDeployingProgress",
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(OperationServer).ReportDeployingProgress(ctx, req.(*DeployingProgress))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
// Operation_ServiceDesc is the grpc.ServiceDesc for Operation service.
|
// Operation_ServiceDesc is the grpc.ServiceDesc for Operation service.
|
||||||
// It's only intended for direct use with grpc.RegisterService,
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
// and not to be introspected or modified (even as a copy)
|
// and not to be introspected or modified (even as a copy)
|
||||||
@ -161,6 +193,10 @@ var Operation_ServiceDesc = grpc.ServiceDesc{
|
|||||||
MethodName: "Refresh",
|
MethodName: "Refresh",
|
||||||
Handler: _Operation_Refresh_Handler,
|
Handler: _Operation_Refresh_Handler,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ReportDeployingProgress",
|
||||||
|
Handler: _Operation_ReportDeployingProgress_Handler,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Streams: []grpc.StreamDesc{
|
Streams: []grpc.StreamDesc{
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user