2019-03-04 09:19:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
2019-03-20 03:14:07 +00:00
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
2019-03-04 09:19:55 +00:00
|
|
|
)
|
|
|
|
|
2019-03-25 07:36:30 +00:00
|
|
|
const (
|
|
|
|
Created = 0
|
|
|
|
Starting = 1
|
|
|
|
Running = 2
|
|
|
|
Stopped = 3
|
|
|
|
Finished = 4
|
|
|
|
)
|
|
|
|
|
2019-04-12 09:21:09 +00:00
|
|
|
type MsgSubmit struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type MsgSummary struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
JobsFinished int `json:"jobs_finished"`
|
|
|
|
JobsRunning int `json:"jobs_running"`
|
|
|
|
JobsPending int `json:"jobs_pending"`
|
|
|
|
FreeGPU int `json:"gpu_free"`
|
|
|
|
UsingGPU int `json:"gpu_using"`
|
|
|
|
}
|
|
|
|
|
2019-03-25 07:36:30 +00:00
|
|
|
type MsgJobList struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Jobs []*Job `json:"jobs"`
|
|
|
|
}
|
|
|
|
|
2019-03-20 03:14:07 +00:00
|
|
|
type MsgLog struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Logs string `json:"logs"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type MsgTaskStatus struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Status TaskStatus `json:"status"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type MsgJobStatus struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Status []TaskStatus `json:"status"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type MsgCreate struct {
|
|
|
|
Code int `json:"code"`
|
|
|
|
Error string `json:"error"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type TaskStatus struct {
|
|
|
|
Id string `json:"id"`
|
2019-04-12 09:21:09 +00:00
|
|
|
Name string `json:"name"`
|
2019-04-16 08:59:19 +00:00
|
|
|
Node string `json:"node"`
|
2019-03-20 03:14:07 +00:00
|
|
|
Image string `json:"image"`
|
|
|
|
ImageDigest string `json:"image_digest"`
|
|
|
|
Command string `json:"command"`
|
|
|
|
CreatedAt string `json:"created_at"`
|
|
|
|
FinishedAt string `json:"finished_at"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type JobStatus struct {
|
|
|
|
Name string
|
|
|
|
tasks map[string]TaskStatus
|
|
|
|
}
|
|
|
|
|
2019-04-16 08:59:19 +00:00
|
|
|
type GPUStatus struct {
|
2019-03-04 09:19:55 +00:00
|
|
|
UUID string `json:"uuid"`
|
|
|
|
ProductName string `json:"product_name"`
|
|
|
|
PerformanceState string `json:"performance_state"`
|
|
|
|
MemoryTotal int `json:"emory_total"`
|
|
|
|
MemoryFree int `json:"memory_free"`
|
2019-03-20 03:14:07 +00:00
|
|
|
MemoryAllocated int `json:"memory_allocated"`
|
2019-03-04 09:19:55 +00:00
|
|
|
MemoryUsed int `json:"memory_used"`
|
|
|
|
UtilizationGPU int `json:"utilization_gpu"`
|
|
|
|
UtilizationMem int `json:"utilization_mem"`
|
|
|
|
TemperatureGPU int `json:"temperature_gpu"`
|
|
|
|
PowerDraw int `json:"power_draw"`
|
|
|
|
}
|
|
|
|
|
2019-04-16 08:59:19 +00:00
|
|
|
type NodeStatus struct {
|
|
|
|
ClientID int `json:"code"`
|
|
|
|
ClientHost string `json:"host"`
|
|
|
|
Status []GPUStatus `json:"status"`
|
2019-03-20 03:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Job struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Tasks []Task `json:"tasks"`
|
2019-04-12 09:21:09 +00:00
|
|
|
Workspace string `json:"workspace"`
|
2019-03-20 03:14:07 +00:00
|
|
|
Cluster int `json:"virtual_cluster"`
|
|
|
|
Priority int `json:"priority"`
|
|
|
|
RunBefore int `json:"run_before"`
|
|
|
|
CreatedAt int `json:"created_at"`
|
|
|
|
UpdatedAt int `json:"updated_at"`
|
|
|
|
CreatedBy int `json:"created_by"`
|
|
|
|
Status int `json:"status"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Task struct {
|
|
|
|
Name string `json:"name"`
|
2019-04-12 09:21:09 +00:00
|
|
|
Image string `json:"image"`
|
2019-03-20 03:14:07 +00:00
|
|
|
Cmd string `json:"cmd"`
|
|
|
|
NumberCPU int `json:"cpu_number"`
|
|
|
|
Memory int `json:"memory"`
|
|
|
|
NumberGPU int `json:"gpu_number"`
|
|
|
|
MemoryGPU int `json:"gpu_memory"`
|
2019-03-04 09:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func str2int(str string, defaultValue int) int {
|
|
|
|
i, err := strconv.Atoi(str)
|
|
|
|
if err == nil {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
return defaultValue
|
|
|
|
}
|
2019-03-20 03:14:07 +00:00
|
|
|
|
|
|
|
func getUA() string {
|
|
|
|
rand.Seed(time.Now().Unix())
|
|
|
|
UAs := []string{
|
|
|
|
"Mozilla/5.0 (X11; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0",
|
|
|
|
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0",
|
|
|
|
"Mozilla/5.0 (X11; Linux i586; rv:63.0) Gecko/20100101 Firefox/63.0",
|
|
|
|
"Mozilla/5.0 (Windows NT 6.2; WOW64; rv:63.0) Gecko/20100101 Firefox/63.0",
|
|
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:10.0) Gecko/20100101 Firefox/62.0",
|
|
|
|
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.13; ko; rv:1.9.1b2) Gecko/20081201 Firefox/60.0",
|
|
|
|
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/58.0",
|
|
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14931",
|
|
|
|
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
|
|
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9",
|
|
|
|
}
|
|
|
|
return UAs[rand.Intn(len(UAs))]
|
|
|
|
}
|
|
|
|
|
|
|
|
func doRequest(method string, url string, r io.Reader, contentType string, referer string) (*http.Response, error) {
|
|
|
|
client := &http.Client{}
|
|
|
|
req, err := http.NewRequest(method, url, r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Header.Set("Content-Type", contentType)
|
|
|
|
req.Header.Set("User-Agent", getUA())
|
|
|
|
req.Header.Set("Referer", referer)
|
|
|
|
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
return resp, err
|
|
|
|
}
|