[FIX] fix hostid file can not create bug in windows and hide task api

This commit is contained in:
barnett 2018-12-06 13:00:41 +08:00
parent 7985b67820
commit 71e9552e3d
5 changed files with 50 additions and 28 deletions

View File

@ -343,7 +343,7 @@ func ClusterInfo(w http.ResponseWriter, r *http.Request) {
if runtime.GOOS != "windows" {
diskstauts = disk.DiskUsage("/grdata")
} else {
diskstauts = disk.DiskUsage(`c:\\grdata`)
diskstauts = disk.DiskUsage(`z:\\`)
}
podMemRequestMB := memR / 1024 / 1024
result := &model.ClusterResource{

View File

@ -109,30 +109,30 @@ func Routers(mode string) *chi.Mux {
//TODO:
//任务执行框架相关API
//任务
r.Route("/tasks", func(r chi.Router) {
r.Post("/", controller.CreateTask)
r.Get("/", controller.GetTasks)
r.Get("/{task_id}", controller.GetTask)
r.Delete("/{task_id}", controller.DeleteTask)
r.Post("/{task_id}/exec", controller.ExecTask)
r.Get("/{task_id}/status", controller.GetTaskStatus)
})
//任务模版
r.Route("/tasktemps", func(r chi.Router) {
r.Post("/", controller.CreateTaskTemp)
r.Put("/{temp_id}", controller.UpdateTaskTemp)
r.Delete("/{temp_id}", controller.DeleteTaskTemp)
})
//任务组
r.Route("/taskgroups", func(r chi.Router) {
r.Post("/", controller.CreateTaskGroup)
r.Get("/", controller.GetTaskGroups)
r.Get("/{group_id}", controller.GetTaskGroup)
r.Delete("/{group_id}", controller.DeleteTaskGroup)
r.Post("/{group_id}/exec", controller.ExecTaskGroup)
r.Get("/{group_id}/status", controller.GetTaskGroupStatus)
})
r.Put("/tasks/taskreload", controller.ReloadStaticTasks)
// r.Route("/tasks", func(r chi.Router) {
// r.Post("/", controller.CreateTask)
// r.Get("/", controller.GetTasks)
// r.Get("/{task_id}", controller.GetTask)
// r.Delete("/{task_id}", controller.DeleteTask)
// r.Post("/{task_id}/exec", controller.ExecTask)
// r.Get("/{task_id}/status", controller.GetTaskStatus)
// })
// //任务模版
// r.Route("/tasktemps", func(r chi.Router) {
// r.Post("/", controller.CreateTaskTemp)
// r.Put("/{temp_id}", controller.UpdateTaskTemp)
// r.Delete("/{temp_id}", controller.DeleteTaskTemp)
// })
// //任务组
// r.Route("/taskgroups", func(r chi.Router) {
// r.Post("/", controller.CreateTaskGroup)
// r.Get("/", controller.GetTaskGroups)
// r.Get("/{group_id}", controller.GetTaskGroup)
// r.Delete("/{group_id}", controller.DeleteTaskGroup)
// r.Post("/{group_id}/exec", controller.ExecTaskGroup)
// r.Get("/{group_id}/status", controller.GetTaskGroupStatus)
// })
// r.Put("/tasks/taskreload", controller.ReloadStaticTasks)
}
})
return r

View File

@ -30,6 +30,7 @@ import (
"path"
"path/filepath"
"reflect"
"runtime"
"strconv"
"strings"
"sync"
@ -194,11 +195,15 @@ func CmdRunWithTimeout(cmd *exec.Cmd, timeout time.Duration) (bool, error) {
//ID是节点的唯一标识acp_node将把ID与机器信息的绑定关系维护于etcd中
func ReadHostID(filePath string) (string, error) {
if filePath == "" {
filePath = "/opt/rainbond/etc/node/node_host_uuid.conf"
if runtime.GOOS == "windows" {
filePath = "c:\\rainbond\\node_host_uuid.conf"
} else {
filePath = "/opt/rainbond/etc/node/node_host_uuid.conf"
}
}
_, err := os.Stat(filePath)
if err != nil {
if strings.HasSuffix(err.Error(), "no such file or directory") {
if os.IsNotExist(err) {
uid, err := CreateHostID()
if err != nil {
return "", err

View File

@ -18,7 +18,7 @@
package disk
// disk usage of path/disk
//DiskUsage disk usage of path/disk
func DiskUsage(path string) (disk Status) {
return
}

View File

@ -18,7 +18,24 @@
package disk
import (
"syscall"
"unsafe"
)
// disk usage of path/disk
func DiskUsage(path string) (disk Status) {
h := syscall.MustLoadDLL("kernel32.dll")
c := h.MustFindProc("GetDiskFreeSpaceExW")
lpFreeBytesAvailable := int64(0)
lpTotalNumberOfBytes := int64(0)
lpTotalNumberOfFreeBytes := int64(0)
r2, _, err := c.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("F:"))),
uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)))
disk.All = uint64(lpTotalNumberOfBytes)
disk.Free = uint64(lpTotalNumberOfFreeBytes)
disk.Used = uint64(lpTotalNumberOfBytes - lpTotalNumberOfFreeBytes)
return
}