From 71e9552e3dea964cf7e09fad0689cde0b746fefa Mon Sep 17 00:00:00 2001 From: barnett <576501057@qq.com> Date: Thu, 6 Dec 2018 13:00:41 +0800 Subject: [PATCH] [FIX] fix hostid file can not create bug in windows and hide task api --- node/api/controller/cluster_controller.go | 2 +- node/api/router/router.go | 48 +++++++++++------------ util/comman.go | 9 ++++- util/disk/disk_darwin.go | 2 +- util/disk/disk_windows.go | 17 ++++++++ 5 files changed, 50 insertions(+), 28 deletions(-) diff --git a/node/api/controller/cluster_controller.go b/node/api/controller/cluster_controller.go index defc89434..1215a57ff 100644 --- a/node/api/controller/cluster_controller.go +++ b/node/api/controller/cluster_controller.go @@ -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{ diff --git a/node/api/router/router.go b/node/api/router/router.go index 03b1a0538..26d9bffdc 100644 --- a/node/api/router/router.go +++ b/node/api/router/router.go @@ -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 diff --git a/util/comman.go b/util/comman.go index 7705ea2af..2dbab7e9d 100644 --- a/util/comman.go +++ b/util/comman.go @@ -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 diff --git a/util/disk/disk_darwin.go b/util/disk/disk_darwin.go index 14829a3d5..65741d53b 100644 --- a/util/disk/disk_darwin.go +++ b/util/disk/disk_darwin.go @@ -18,7 +18,7 @@ package disk -// disk usage of path/disk +//DiskUsage disk usage of path/disk func DiskUsage(path string) (disk Status) { return } diff --git a/util/disk/disk_windows.go b/util/disk/disk_windows.go index 14829a3d5..0e79cb050 100644 --- a/util/disk/disk_windows.go +++ b/util/disk/disk_windows.go @@ -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 }