Skip to content

Commit

Permalink
Merge pull request #4 from ralfyang/master
Browse files Browse the repository at this point in the history
z
  • Loading branch information
folimy committed Jul 10, 2020
2 parents 49d54e4 + 942b631 commit 471d90d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 46 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![klevr_logo.png](./src/klevr_logo.png)
# Kloud-native everywhere
## Interconnector for every SaaS delivery.
# Klevr: Kloud-native everywhere
## Interconnector for the Platform based SaaS delivery
* Asynchronous distributed infrastructure management console and agent for separated networks.
* Supports for:
* Baremetal server in the On-premise datacenter
Expand All @@ -21,7 +21,7 @@ docker-compose up -d

## Features
* **[Agent](./agent/)**
* Provisioning: Docker, Micro K8s, Vagrant, VirtualBox
* Provisioning: Docker, Kubernetes, Micro K8s(on Linux laptop) with Vagrant & VirtualBox, Prometheus
* Get & Run: Hypervisor(via libvirt container), Terraform, Prometheus, Beacon
* Metric data aggregate & delivery
* **[Web console](./webconsole/)**
Expand Down
4 changes: 2 additions & 2 deletions agent/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.14

require (
github.com/jasonlvhit/gocron v0.0.0-20200423141508-ab84337f7963
github.com/ralfyang/klevr/communicator v0.0.0-20200706121907-b61b0dbd6ab8
github.com/ralfyang/klevr/communicator v0.0.0-20200709225318-1391c536f387
github.com/zcalusic/sysinfo v0.0.0-20200228145645-a159d7cc708b
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect
golang.org/x/text v0.3.3 // indirect
k8s.io/apimachinery v0.18.5
)
6 changes: 6 additions & 0 deletions agent/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ github.com/ralfyang/klevr/communicator v0.0.0-20200706033238-3e0b2b29d2c4 h1:sf5
github.com/ralfyang/klevr/communicator v0.0.0-20200706033238-3e0b2b29d2c4/go.mod h1:BH9TPJUPxr0jnsE57zmTQ7sia27bV13VgIaBUQsbhVM=
github.com/ralfyang/klevr/communicator v0.0.0-20200706121907-b61b0dbd6ab8 h1:LJXos/tPKArcBVY8ZSm09zRteckMwxd19fC3jf8vcBg=
github.com/ralfyang/klevr/communicator v0.0.0-20200706121907-b61b0dbd6ab8/go.mod h1:BH9TPJUPxr0jnsE57zmTQ7sia27bV13VgIaBUQsbhVM=
github.com/ralfyang/klevr/communicator v0.0.0-20200709104352-f53057a802de h1:HPP5NFZzI6beW2/DffxeYzmXl3LkVLyQsMEAsdoGLJ8=
github.com/ralfyang/klevr/communicator v0.0.0-20200709104352-f53057a802de/go.mod h1:BH9TPJUPxr0jnsE57zmTQ7sia27bV13VgIaBUQsbhVM=
github.com/ralfyang/klevr/communicator v0.0.0-20200709225318-1391c536f387 h1:u1tuQ4h5m0j6mVlo0LIvC3GmDqsh3HapPUQzec58inQ=
github.com/ralfyang/klevr/communicator v0.0.0-20200709225318-1391c536f387/go.mod h1:BH9TPJUPxr0jnsE57zmTQ7sia27bV13VgIaBUQsbhVM=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -81,6 +85,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZ
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
Binary file modified agent/klevr
Binary file not shown.
75 changes: 52 additions & 23 deletions agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
netutil "k8s.io/apimachinery/pkg/util/net"
"github.com/zcalusic/sysinfo"
"encoding/json"
"encoding/base64"
//"github.com/mackerelio/go-osstat/memory"
//"github.com/mackerelio/go-osstat/cpu"
//"github.com/mackerelio/go-osstat/disk"
Expand Down Expand Up @@ -347,40 +348,46 @@ func Resource_info()string{


func Secondary_scanner(){
Secondary_raw_file, _ := ioutil.ReadFile(Primary_communication_result)
raw_string_parse := strings.Split(string(Secondary_raw_file),"\n")
secondary_raw_file, _ := ioutil.ReadFile(Primary_communication_result)
raw_string_parse := strings.Split(string(secondary_raw_file),"\n")
var quee_host string
for i := 1; i < len(raw_string_parse)-2; i++ {
var fin_res string = ""
target_raw := raw_string_parse[i]
strr1 := strings.Split(target_raw, "&")
raw_result_split := strings.Split(strr1[1], "=")

Target_secondary_hosts := "http://"+raw_result_split[1]+":18800"
fin_res = communicator.Get_http(Target_secondary_hosts+"/status", "")
if fin_res == "OK" {
// println("77777777777777777777777777777777777777 Secondary_raw_fileSecondary_raw_file: ", fin_res) /// for test result
if i == len(raw_string_parse)-3{
quee_host = quee_host+Target_secondary_hosts+": "+fin_res
}else{
quee_host = quee_host+Target_secondary_hosts+": "+fin_res+"\n"
for i := 1; i < len(raw_string_parse); i++ {
if strings.Contains(raw_string_parse[i], "last_check") == true {
var fin_res string = ""
target_raw := raw_string_parse[i]
strr1 := strings.Split(target_raw, "&")
raw_result_split := strings.Split(strr1[1], "=")

Target_secondary_hosts := "http://"+raw_result_split[1]+":18800"
fin_res = communicator.Get_http(Target_secondary_hosts+"/status", "")
if fin_res == "OK" {
// quee_host = quee_host+"{\"hostname\":\""+raw_result_split[1]+"\", \"status\":\""+fin_res+"\"}" //for sample
quee_host = quee_host+raw_result_split[1]+":"+fin_res+"\n"
}
}
}
// regex, _ := regexp.Compile("\n\n")
// flat_quee_host := regex.ReplaceAllString(quee_host, "\n")
flat_quee_host := strings.Replace(quee_host, "\n\n", "\n", -1)
println("8888888888888888888888888888888888888888888888888888888888")
println(flat_quee_host)
println("9999999999999999999999999999999999999999999999999999999999")
flat_quee_host := strings.ReplaceAll(quee_host, "\n\n", "")
flat_enc := base64.StdEncoding.EncodeToString([]byte(flat_quee_host))
// println("88888888888888888888888888888==",flat_enc)
Hosts_alive_list(flat_enc)
}


func Hosts_alive_list(alive_list string) {
// Hosts alive list klevr/groups/klevr-a-team/users/ralf/zones/dev/platforms/baremetal/alive_hosts
uri := fmt.Sprint(Klevr_console+"/groups/"+Klevr_company+"/users/"+User_account_id+"/zones/"+Klevr_zone+"/platforms/"+Platform_type+"/aliveagent")
Debug(uri) /// log output
alive_conv := fmt.Sprintf("%s",alive_list)
communicator.Put_http(uri, alive_conv, Api_key_string)
}


func RnR(){
Check_primary()
if AM_I_PRIMARY == "PRIMARY" {
// Put master alive time to stamp
// Put primary alive time to stamp
ack_timecheck_from_api := communicator.Get_http(Klevr_console+"/group/"+Klevr_company+"/user/"+User_account_id+"/zone/"+Klevr_zone+"/platform/"+Platform_type+"/ackprimary", Api_key_string)

// Write done the information about of Final result time & hostlists
Expand Down Expand Up @@ -448,6 +455,22 @@ func Docker_runner(image_name, service_name, options string){
}
}

func Primary_works_check()string{
var primary_latest_check string
primary_raw_file, _ := ioutil.ReadFile(Primary_communication_result)
raw_string_parse := strings.Split(string(primary_raw_file),"\n")
if strings.Contains(raw_string_parse[0], "get_timestamp") == true {
strr1 := strings.Split(raw_string_parse[0], ": ")
primary_latest_check = strr1[1]
}else{
log.Println("Primary uptime is not recognized")
primary_latest_check = ""
}
return primary_latest_check
}




func main(){
// Docker image define
Expand Down Expand Up @@ -494,13 +517,19 @@ func main(){
<- s.Start()
}()

///Http listen for host info get
/// Http listen for host info get
http.HandleFunc("/info", func(w http.ResponseWriter, req *http.Request) {
Resource_info()
w.Write([]byte(System_info))
})

///Http listen for beacon
/// Http listen for primary latest working time
http.HandleFunc("/primaryworks", func(w http.ResponseWriter, req *http.Request) {
primary_uptime := Primary_works_check()
w.Write([]byte(primary_uptime))
})

/// Http listen for beacon
http.HandleFunc("/status", func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("OK"))
})
Expand Down
44 changes: 26 additions & 18 deletions webconsole/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import (
"fmt"
"net/http"
"log"
_"bytes"
"bytes"
_ "os/exec"
_"os"
_ "io"
_"io"
_"io/ioutil"
"strings"
"strconv"
"time"
"flag"
_"regexp"
"encoding/json"
"encoding/base64"
"github.com/gorilla/mux"
"github.com/ralfyang/klevr/communicator"
)
Expand Down Expand Up @@ -354,22 +355,6 @@ func main() {
fmt.Fprintf(w, "\nResult: \n%s\n", Buffer_result)
})

/// Agent alive status receiver
r.HandleFunc("/group/{G}/user/{U}/zone/{Z}/platform/{P}/aliveagent", func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
user := vars["U"]
platform := vars["P"]
group := vars["G"]
zone := vars["Z"]
// Put_alive_agent(user, platform)
// Get_task_list(user, platform)
/// Export result to web
fmt.Fprintf(w, "Group: %s\n", group)
fmt.Fprintf(w, "User: %s\n", user)
fmt.Fprintf(w, "Zone: %s\n", zone)
fmt.Fprintf(w, "Platform: %s\n", platform)
fmt.Fprintf(w, "\n\nHost(s) info.: \n%s\n", Hostlist)
})

// http://10.10.33.2:8000/group/klevr-a-team/user/ralf/zone/dev/platform/baremetal/hostname/2db8c6cf4329e44bda97a72f7f9127125d991ba2/192.168.15.50/1594257516/ok
/// receive json data to KV store
Expand Down Expand Up @@ -410,6 +395,29 @@ func main() {
fmt.Fprintf(w, "%s", Primary_info)
})

/// Agent alive status receiver
/// http://192.168.2.100:8000/groups/klevr-a-team/users/ralf/zones/dev/platforms/baremetal/alive_hosts
r.HandleFunc("/groups/{G}/users/{U}/zones/{Z}/platforms/{P}/aliveagent", func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
user := vars["U"]
platform := vars["P"]
group := vars["G"]
zone := vars["Z"]

data_buffer := new(bytes.Buffer)
data_buffer.ReadFrom(r.Body)
data_Str := data_buffer.String()

/// Get string from r.Body via bytes buffer
// data := base64.NewDecoder(base64.StdEncoding, r.Body)
data,_ := base64.StdEncoding.DecodeString(data_Str)
plan_data := fmt.Sprintf("%s",data)
println("datadatadatadatadata:", plan_data)
ure := "/v1/kv/klevr/groups/"+group+"/users/"+user+"/zones/"+zone+"/platforms/"+platform+"/aliveagent"
communicator.Put_http(API_url+ure, plan_data, API_key_string)
fmt.Fprintf(w, "%s", plan_data)
})

// Bind to a port and pass our router in
println("Service port:",Service_port)
println("Target API Server:",API_url)
Expand Down

0 comments on commit 471d90d

Please sign in to comment.