Compare commits
3 Commits
faefd8cfca
...
d490188bd2
| Author | SHA1 | Date | |
|---|---|---|---|
| d490188bd2 | |||
| ac355d32b4 | |||
| 26b12fad72 |
@ -6,7 +6,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@ -34,8 +33,30 @@ type clientConfig struct {
|
|||||||
HttpAddress string `json:"http_server_address"`
|
HttpAddress string `json:"http_server_address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type totalConfig struct {
|
func loadClientConfig() (clientConfig, error) {
|
||||||
Client clientConfig `json:"houston_client"`
|
configFile, err := os.Open("config.json")
|
||||||
|
if err != nil {
|
||||||
|
return clientConfig{}, err
|
||||||
|
}
|
||||||
|
defer configFile.Close()
|
||||||
|
|
||||||
|
var config struct {
|
||||||
|
Houston *struct {
|
||||||
|
Client clientConfig `json:"client"`
|
||||||
|
} `json:"houston"`
|
||||||
|
}
|
||||||
|
|
||||||
|
dec := json.NewDecoder(configFile)
|
||||||
|
err = dec.Decode(&config)
|
||||||
|
if err != nil {
|
||||||
|
return clientConfig{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Houston == nil {
|
||||||
|
return clientConfig{}, errors.New(`"houston" object is missing in config.json`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.Houston.Client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type HoustonClient interface {
|
type HoustonClient interface {
|
||||||
@ -161,28 +182,24 @@ func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryReque
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClient() (HoustonClient, error) {
|
func NewClient() (HoustonClient, error) {
|
||||||
bt, err := os.ReadFile("config.json")
|
clientConfig, err := loadClientConfig()
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if err != nil {
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var config totalConfig
|
|
||||||
if err := json.Unmarshal(bt, &config); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.Client.GrpcAddress) == 0 {
|
if len(clientConfig.GrpcAddress) == 0 {
|
||||||
return nil, errors.New("client.grpc_server_address is missing")
|
return nil, errors.New("client.grpc_server_address is missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.Client.HttpAddress) == 0 {
|
if len(clientConfig.HttpAddress) == 0 {
|
||||||
return nil, errors.New("client.http_server_address is missing")
|
return nil, errors.New("client.http_server_address is missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
var client *grpc.ClientConn
|
var client *grpc.ClientConn
|
||||||
for {
|
for {
|
||||||
logger.Println("grpc.DialContext :", config.Client.GrpcAddress)
|
logger.Println("grpc.DialContext :", clientConfig.GrpcAddress)
|
||||||
dialContext, cancelDial := context.WithTimeout(context.Background(), 15*time.Second)
|
dialContext, cancelDial := context.WithTimeout(context.Background(), 15*time.Second)
|
||||||
client, err = grpc.DialContext(dialContext, config.Client.GrpcAddress, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
client, err = grpc.DialContext(dialContext, clientConfig.GrpcAddress, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cancelDial()
|
cancelDial()
|
||||||
break
|
break
|
||||||
@ -220,7 +237,7 @@ func NewClient() (HoustonClient, error) {
|
|||||||
client: client,
|
client: client,
|
||||||
extraMetrics: unsafe.Pointer(&map[string]float32{}),
|
extraMetrics: unsafe.Pointer(&map[string]float32{}),
|
||||||
deploys: deploys,
|
deploys: deploys,
|
||||||
httpAddr: config.Client.HttpAddress,
|
httpAddr: clientConfig.HttpAddress,
|
||||||
timestamp: exefi.ModTime().String(),
|
timestamp: exefi.ModTime().String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,6 +284,7 @@ func NewClient() (HoustonClient, error) {
|
|||||||
var dr shared.DeployRequest
|
var dr shared.DeployRequest
|
||||||
unmarshal(&dr, resp.Args)
|
unmarshal(&dr, resp.Args)
|
||||||
|
|
||||||
|
logger.Println(dr.Name, myname)
|
||||||
if dr.Name == myname {
|
if dr.Name == myname {
|
||||||
if srcdir, replacer, err := hc.prepareUpdateSelf(&dr); err == nil {
|
if srcdir, replacer, err := hc.prepareUpdateSelf(&dr); err == nil {
|
||||||
args := []string{
|
args := []string{
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
{
|
{
|
||||||
"houston_client" : {
|
"houston" : {
|
||||||
"grpc_server_address" : "192.168.9.32:8080",
|
"client" : {
|
||||||
"http_server_address" : "http://192.168.9.32/commandcenter"
|
"grpc_server_address" : "10.5.10.100:8080",
|
||||||
|
"http_server_address" : "https://kdcc.action2quare.com/houston"
|
||||||
},
|
},
|
||||||
"houston_server" : {
|
"server" : {
|
||||||
"grpc_port" : 8080
|
"grpc_port" : 8080,
|
||||||
|
"storage_path" : "/data"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -180,8 +180,8 @@ func (h *houstonHandler) Deploy(w http.ResponseWriter, r *http.Request) {
|
|||||||
shared.DeployRequest{
|
shared.DeployRequest{
|
||||||
Name: name,
|
Name: name,
|
||||||
Version: version,
|
Version: version,
|
||||||
Url: path.Join(relPath, latestFilename),
|
Url: path.Join("deploys", name, version, latestFilename),
|
||||||
Config: path.Join(h.deployPath, name, "config", "config.json"),
|
Config: path.Join("deploys", name, "config", "config.json"),
|
||||||
},
|
},
|
||||||
targets,
|
targets,
|
||||||
))
|
))
|
||||||
|
|||||||
@ -45,7 +45,7 @@ func NewHoustonHandler() HoustonServerWithHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error {
|
func (h *houstonHandler) RegisterHandlers(serveMux *http.ServeMux, prefix string) error {
|
||||||
storagePath := loadConfig().StoragePath
|
storagePath := loadServerConfig().StoragePath
|
||||||
h.deployPath = path.Join(storagePath, "deploys")
|
h.deployPath = path.Join(storagePath, "deploys")
|
||||||
h.downloadPath = path.Join(storagePath, "downloads")
|
h.downloadPath = path.Join(storagePath, "downloads")
|
||||||
|
|
||||||
|
|||||||
@ -25,10 +25,6 @@ type serverConfig struct {
|
|||||||
StoragePath string `json:"storage_path"`
|
StoragePath string `json:"storage_path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type totalConfig struct {
|
|
||||||
Server serverConfig `json:"houston_server"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeployRequest struct {
|
type DeployRequest struct {
|
||||||
shared.DeployRequest
|
shared.DeployRequest
|
||||||
hostnames []string
|
hostnames []string
|
||||||
@ -111,24 +107,39 @@ type Operation interface {
|
|||||||
Hosts() map[string]hostSnapshot
|
Hosts() map[string]hostSnapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig() serverConfig {
|
func loadServerConfig() serverConfig {
|
||||||
var config totalConfig
|
|
||||||
|
|
||||||
config.Server.GrpcPort = 8080
|
|
||||||
configFile, err := os.Open("config.json")
|
configFile, err := os.Open("config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
return config.Server
|
return serverConfig{
|
||||||
|
GrpcPort: 8080,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
defer configFile.Close()
|
defer configFile.Close()
|
||||||
|
|
||||||
|
var config struct {
|
||||||
|
Houston *struct {
|
||||||
|
Server serverConfig `json:"server"`
|
||||||
|
} `json:"houston"`
|
||||||
|
}
|
||||||
|
|
||||||
dec := json.NewDecoder(configFile)
|
dec := json.NewDecoder(configFile)
|
||||||
err = dec.Decode(&config)
|
err = dec.Decode(&config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
return config.Server
|
return serverConfig{
|
||||||
|
GrpcPort: 8080,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return config.Server
|
if config.Houston == nil {
|
||||||
|
logger.Error(`"houston" object is missing in config.json`)
|
||||||
|
return serverConfig{
|
||||||
|
GrpcPort: 8080,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.Houston.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer() HoustonServer {
|
func NewServer() HoustonServer {
|
||||||
@ -144,7 +155,7 @@ func NewServer() HoustonServer {
|
|||||||
rpcServer: grpcServer,
|
rpcServer: grpcServer,
|
||||||
os: os,
|
os: os,
|
||||||
ms: ms,
|
ms: ms,
|
||||||
port: loadConfig().GrpcPort,
|
port: loadServerConfig().GrpcPort,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user