Skip to content

Commit

Permalink
Add the Service Address Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
powerkimhub committed Jul 19, 2021
1 parent 5079349 commit cb09032
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 67 deletions.
2 changes: 1 addition & 1 deletion api-runtime/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewInfoCmd() *cobra.Command {
Use: "info",
Run: func(cmd *cobra.Command, args []string) {
client := resty.New()
resp, err := client.R().Get("http://" + cr.HostIPorName + cr.ServicePort + "/spider/endpointinfo")
resp, err := client.R().Get("http://" + cr.ServiceIPorName + cr.ServicePort + "/spider/endpointinfo")
if err != nil {
fmt.Printf("%v\n", err)
} else {
Expand Down
13 changes: 12 additions & 1 deletion api-runtime/common-runtime/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ const SG_DELIMITER string = "-deli-"
var StartTime string
var MiddleStartTime string
var ShortStartTime string
var HostIPorName string


//// CB-Spider Servcie Address Configuration
//// cf) https://github.com/cloud-barista/cb-spider/wiki/CB-Spider-Service-Address-Configuration
// REST and GO SERVER_ADDRESS since v0.4.4
var ServerIPorName string
var ServerPort string

// REST SERVICE_ADDRESS for AdminWeb since v0.4.4
var ServiceIPorName string
var ServicePort string

// GO Service Port
var GoServicePort string
2 changes: 1 addition & 1 deletion api-runtime/grpc-runtime/CBSpiderGRPCRuntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func RunServer() {

//fmt.Printf("\n\n => grpc server started on %s\n\n", spidersrv.Addr)
cr.GoServicePort = spidersrv.Addr
spiderBanner(cr.HostIPorName + spidersrv.Addr)
spiderBanner(cr.ServiceIPorName + spidersrv.Addr)

if err := gs.Serve(conn); err != nil {
logger.Error("failed to serve: ", err)
Expand Down
4 changes: 2 additions & 2 deletions api-runtime/meerkat-runtime/MeerkatRuntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ( port = ":4096")


func init() {
myServerID = cr.HostIPorName + port + "-" + cr.MiddleStartTime
myServerID = cr.ServiceIPorName + port + "-" + cr.MiddleStartTime
childkat.MyServerID = myServerID
}
/*
Expand Down Expand Up @@ -66,7 +66,7 @@ func RunServer() {
// Register reflection service on gRPC server.
reflection.Register(s)

spiderBanner(cr.HostIPorName + port)
spiderBanner(cr.ServiceIPorName + port)

// register this server status into SpiderHub's registry
strY := itsMe()
Expand Down
85 changes: 54 additions & 31 deletions api-runtime/rest-runtime/CBSpiderRuntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ func init() {
cr.StartTime = currentTime.Format("2006.01.02 15:04:05 Mon")
cr.MiddleStartTime = currentTime.Format("2006.01.02.15:04:05")
cr.ShortStartTime = fmt.Sprintf("T%02d:%02d:%02d", currentTime.Hour(), currentTime.Minute(), currentTime.Second())
cr.HostIPorName = getHostIPorName()
cr.ServicePort = getServicePort()

// REST and GO SERVER_ADDRESS since v0.4.4
cr.ServerIPorName = getServerIPorName("SERVER_ADDRESS")
cr.ServerPort = getServerPort("SERVER_ADDRESS")

// REST SERVICE_ADDRESS for AdminWeb since v0.4.4
cr.ServiceIPorName = getServiceIPorName("SERVICE_ADDRESS")
cr.ServicePort = getServicePort("SERVICE_ADDRESS")
}

// REST API Return struct for boolean type
Expand All @@ -81,28 +87,26 @@ type SimpleMsg struct {
Message string `json:"message" example:"Any message"`
}

//====== temporary trick for shared public IP Host or VirtualBox VM, etc.
//====== user can setup spider server's IP manually.

// unset # default: like 'curl ifconfig.co':1024
// LOCALHOST="OFF" # default: like 'curl ifconfig.co':1024
// LOCALHOST="ON" # => localhost:1024
// LOCALHOST="1.2.3.4" # => 1.2.3.4:1024
// LOCALHOST="1.2.3.4:31024" # => 1.2.3.4:31024
// LOCALHOST=":31024" # => like 'curl ifconfig.co':31024
func getHostIPorName() string {
//// CB-Spider Servcie Address Configuration
//// cf) https://github.com/cloud-barista/cb-spider/wiki/CB-Spider-Service-Address-Configuration

hostEnv := os.Getenv("LOCALHOST")
// REST and GO SERVER_ADDRESS since v0.4.4

if hostEnv == "ON" {
return "localhost"
}
// unset # default: like 'curl ifconfig.co':1024
// SERVER_ADDRESS="1.2.3.4:3000" # => 1.2.3.4:3000
// SERVER_ADDRESS=":3000" # => like 'curl ifconfig.co':3000
// SERVER_ADDRESS="localhost" # => localhost:1024
// SERVER_ADDRESS="1.2.3.4:3000" # => 1.2.3.4::3000
func getServerIPorName(env string) string {

if hostEnv == "" || hostEnv=="OFF" {
hostEnv := os.Getenv(env) // SERVER_ADDRESS or SERVICE_ADDRESS

if hostEnv == "" {
return getPublicIP()
}

// "1.2.3.4"
// "1.2.3.4" or "localhost"
if !strings.Contains(hostEnv, ":") {
return hostEnv
}
Expand All @@ -111,7 +115,7 @@ func getHostIPorName() string {
fmt.Println(len(strs))
if strs[0] =="" { // ":31024"
return getPublicIP()
}else { // "1.2.3.4:31024"
}else { // "1.2.3.4:31024" or "localhost:31024"
return strs[0]
}
}
Expand All @@ -130,26 +134,45 @@ func getPublicIP() string {
return ip.String()
}

func getServicePort() string {
func getServerPort(env string) string {
// default REST Service Port
servicePort := ":1024"

hostEnv := os.Getenv("LOCALHOST")
if hostEnv == "" || hostEnv=="OFF" || hostEnv=="ON" {
hostEnv := os.Getenv(env) // SERVER_ADDRESS or SERVICE_ADDRESS
if hostEnv == "" {
return servicePort
}

// "1.2.3.4"
// "1.2.3.4" or "localhost"
if !strings.Contains(hostEnv, ":") {
return servicePort
}

// ":31024" or "1.2.3.4:31024"
// ":31024" or "1.2.3.4:31024" or "localhost:31024"
strs := strings.Split(hostEnv, ":")
servicePort = ":" + strs[1]

return servicePort
}

// unset SERVER_ADDRESS => SERVICE_ADDRESS
func getServiceIPorName(env string) string {
hostEnv := os.Getenv(env)
if hostEnv == "" {
return cr.ServerIPorName
}
return getServerIPorName(env)
}

// unset SERVER_ADDRESS => SERVICE_ADDRESS
func getServicePort(env string) string {
hostEnv := os.Getenv(env)
if hostEnv == "" {
return cr.ServerPort
}
return getServerPort(env)
}

func RunServer() {

//======================================= setup routes
Expand Down Expand Up @@ -345,7 +368,7 @@ func ApiServer(routes []route) {

spiderBanner()

e.Logger.Fatal(e.Start(cr.ServicePort))
e.Logger.Fatal(e.Start(cr.ServerPort))
}

//================ API Info
Expand All @@ -361,13 +384,13 @@ func endpointInfo(c echo.Context) error {
cblog.Info("call endpointInfo()")

endpointInfo := fmt.Sprintf("\n <CB-Spider> Multi-Cloud Infrastructure Federation Framework\n")
adminWebURL := "http://" + cr.HostIPorName + cr.ServicePort + "/spider/adminweb"
adminWebURL := "http://" + cr.ServiceIPorName + cr.ServicePort + "/spider/adminweb"
endpointInfo += fmt.Sprintf(" - AdminWeb: %s\n", adminWebURL)
restEndPoint := "http://" + cr.HostIPorName + cr.ServicePort + "/spider"
restEndPoint := "http://" + cr.ServiceIPorName + cr.ServicePort + "/spider"
endpointInfo += fmt.Sprintf(" - REST API: %s\n", restEndPoint)
// swaggerURL := "http://" + cr.HostIPorName + cr.ServicePort + "/spider/swagger/index.html"
// swaggerURL := "http://" + cr.ServiceIPorName + cr.ServicePort + "/spider/swagger/index.html"
// endpointInfo += fmt.Sprintf(" - Swagger : %s\n", swaggerURL)
gRPCServer := "grpc://" + cr.HostIPorName + cr.GoServicePort
gRPCServer := "grpc://" + cr.ServiceIPorName + cr.GoServicePort
endpointInfo += fmt.Sprintf(" - Go API: %s\n", gRPCServer)

return c.String(http.StatusOK, endpointInfo)
Expand All @@ -377,14 +400,14 @@ func spiderBanner() {
fmt.Println("\n <CB-Spider> Multi-Cloud Infrastructure Federation Framework")

// AdminWeb
adminWebURL := "http://" + cr.HostIPorName + cr.ServicePort + "/spider/adminweb"
adminWebURL := "http://" + cr.ServiceIPorName + cr.ServicePort + "/spider/adminweb"
fmt.Printf(" - AdminWeb: %s\n", adminWebURL)

// REST API EndPoint
restEndPoint := "http://" + cr.HostIPorName + cr.ServicePort + "/spider"
restEndPoint := "http://" + cr.ServiceIPorName + cr.ServicePort + "/spider"
fmt.Printf(" - REST API: %s\n", restEndPoint)

// Swagger
// swaggerURL := "http://" + cr.HostIPorName + cr.ServicePort + "/spider/swagger/index.html"
// swaggerURL := "http://" + cr.ServiceIPorName + cr.ServicePort + "/spider/swagger/index.html"
// fmt.Printf(" - Swagger : %s\n", swaggerURL)
}
8 changes: 4 additions & 4 deletions api-runtime/rest-runtime/admin-web/AdminWeb-CCM-MGMT.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func makeDeleteVPCMgmtFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://" + cr.HostIPorName + cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://" + cr.ServiceIPorName + cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand Down Expand Up @@ -226,7 +226,7 @@ func makeDeleteSecurityGroupMgmtFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://" + cr.HostIPorName + cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://" + cr.ServiceIPorName + cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand Down Expand Up @@ -344,7 +344,7 @@ func makeDeleteKeyPairMgmtFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://" + cr.HostIPorName + cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://" + cr.ServiceIPorName + cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand Down Expand Up @@ -462,7 +462,7 @@ func makeDeleteVMMgmtFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://" + cr.HostIPorName + cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://" + cr.ServiceIPorName + cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand Down
20 changes: 10 additions & 10 deletions api-runtime/rest-runtime/admin-web/AdminWeb-CCM.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func makePostVPCFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.HostIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.ServiceIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand All @@ -178,7 +178,7 @@ func makePostSubnetFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.HostIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.ServiceIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand All @@ -202,7 +202,7 @@ func makeDeleteVPCFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.HostIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.ServiceIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand All @@ -223,7 +223,7 @@ func makeDeleteSubnetFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.HostIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.ServiceIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand Down Expand Up @@ -446,7 +446,7 @@ func makePostSecurityGroupFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.HostIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.ServiceIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand All @@ -470,7 +470,7 @@ func makeDeleteSecurityGroupFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.HostIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.ServiceIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand Down Expand Up @@ -689,7 +689,7 @@ func makePostKeyPairFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.HostIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.ServiceIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand All @@ -714,7 +714,7 @@ func makeDeleteKeyPairFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.HostIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.ServiceIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand Down Expand Up @@ -1033,7 +1033,7 @@ func makePostVMFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.HostIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.ServiceIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand All @@ -1057,7 +1057,7 @@ func makeDeleteVMFunc_js() string {
location.reload();
}
`
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.HostIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
strFunc = strings.ReplaceAll(strFunc, "$$SPIDER_SERVER$$", "http://"+cr.ServiceIPorName+cr.ServicePort) // cr.ServicePort = ":1024"
return strFunc
}

Expand Down
Loading

0 comments on commit cb09032

Please sign in to comment.