@@ -1053,6 +1053,9 @@ USER_CENTER_HOST = http://192.168.202.73:31441 | |||
CLIENT_ID = 3Z377wcplxeE2qpycpjv | |||
CLIENT_SECRET = J5ykfVl2kcxW0H9cawSL | |||
REST_SERVER_HOST = http://192.168.202.73 | |||
JOB_PATH = /datasets/minio/data/opendata/jobs/ | |||
DEBUG_SERVER_HOST = http://192.168.202.73/ | |||
IMAGE_SERVER_HOST = http://192.168.202.73/ | |||
; cloudbrain visit opendata | |||
USER = cW4cMtH24eoWPE7X | |||
PWD = 4BPmgvK2hb2Eywwyp4YZRY4B7yQf4DAC | |||
@@ -1,7 +1,6 @@ | |||
package models | |||
import ( | |||
"code.gitea.io/gitea/modules/log" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
@@ -26,11 +25,12 @@ const ( | |||
type Cloudbrain struct { | |||
ID int64 `xorm:"pk autoincr"` | |||
JobID string `xorm:"INDEX NOT NULL"` | |||
JobName string | |||
JobName string `xorm:"INDEX"` | |||
Status string `xorm:"INDEX"` | |||
UserID int64 `xorm:"INDEX"` | |||
RepoID int64 `xorm:"INDEX"` | |||
SubTaskName string `xorm:"INDEX"` | |||
ContainerID string | |||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | |||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | |||
CanDebug bool `xorm:"-"` | |||
@@ -218,13 +218,16 @@ type ImageInfo struct { | |||
PlaceView string | |||
} | |||
type CommitImageParams struct { | |||
Ip string `json:"ip"` | |||
TaskContainerId string `json:"taskContainerId"` | |||
ImageDescription string `json:"imageDescription"` | |||
} | |||
func ConvertToImagesResultPayload(input map[string]ImageInfo) (ImagesResultPayload, error) { | |||
for _,info := range input { | |||
log.Info(info.Name) | |||
} | |||
var res ImagesResultPayload | |||
return res, nil | |||
type CommitImageResult struct { | |||
Code string `json:"code"` | |||
Msg string `json:"msg"` | |||
Payload map[string]interface{} `json:"payload"` | |||
} | |||
func Cloudbrains(opts *CloudbrainsOptions) ([]*Cloudbrain, int64, error) { | |||
@@ -331,6 +334,6 @@ func UpdateJob(job *Cloudbrain) error { | |||
func updateJob(e Engine, job *Cloudbrain) error { | |||
var sess *xorm.Session | |||
sess = e.Where("job_id = ?", job.JobID) | |||
_, err := sess.Cols("status").Update(job) | |||
_, err := sess.Cols("status", "container_id").Update(job) | |||
return err | |||
} |
@@ -1,12 +1,11 @@ | |||
package cloudbrain | |||
import ( | |||
"code.gitea.io/gitea/modules/log" | |||
"fmt" | |||
"code.gitea.io/gitea/models" | |||
"code.gitea.io/gitea/modules/setting" | |||
resty "github.com/go-resty/resty/v2" | |||
"github.com/go-resty/resty/v2" | |||
) | |||
var ( | |||
@@ -63,8 +62,6 @@ func CreateJob(jobName string, createJobParams models.CreateJobParams) (*models. | |||
retry := 0 | |||
log.Info("", createJobParams.Volumes) | |||
sendjob: | |||
res, err := client.R(). | |||
SetHeader("Content-Type", "application/json"). | |||
@@ -106,7 +103,7 @@ sendjob: | |||
Get(HOST + "/rest-server/api/v1/jobs/" + jobID) | |||
if err != nil { | |||
return nil, fmt.Errorf("resty GetJob: %s", err) | |||
return nil, fmt.Errorf("resty GetJob: %v", err) | |||
} | |||
if getJobResult.Code == "S401" && retry < 1 { | |||
@@ -137,7 +134,7 @@ sendjob: | |||
Get(HOST + "/rest-server/api/v1/image/list/") | |||
if err != nil { | |||
return nil, fmt.Errorf("resty GetJob: %s", err) | |||
return nil, fmt.Errorf("resty GetImages: %v", err) | |||
} | |||
if getImagesResult.Code == "S401" && retry < 1 { | |||
@@ -152,3 +149,35 @@ sendjob: | |||
return &getImagesResult, nil | |||
} | |||
func CommitImage(jobID string, params models.CommitImageParams) (*models.CommitImageResult, error) { | |||
checkSetting() | |||
client := getRestyClient() | |||
var result models.CommitImageResult | |||
retry := 0 | |||
sendjob: | |||
res, err := client.R(). | |||
SetHeader("Content-Type", "application/json"). | |||
SetAuthToken(TOKEN). | |||
SetBody(params). | |||
SetResult(&result). | |||
Post(HOST + "/rest-server/api/v1/jobs/" + jobID + "/commitImage") | |||
if err != nil { | |||
return nil, fmt.Errorf("resty CommitImage: %v", err) | |||
} | |||
if result.Code == "S401" && retry < 1 { | |||
retry++ | |||
_ = loginCloudbrain() | |||
goto sendjob | |||
} | |||
if result.Code != Success { | |||
return &result, fmt.Errorf("CommitImage err: %s", res.String()) | |||
} | |||
return &result, nil | |||
} |
@@ -440,6 +440,7 @@ var ( | |||
RestServerHost string | |||
JobPath string | |||
DebugServerHost string | |||
ImageServerHost string | |||
) | |||
// DateLang transforms standard language locale name to corresponding value in datetime plugin. | |||
@@ -1117,6 +1118,7 @@ func NewContext() { | |||
RestServerHost = sec.Key("REST_SERVER_HOST").MustString("http://192.168.202.73") | |||
JobPath = sec.Key("JOB_PATH").MustString("/datasets/minio/data/opendata/jobs/") | |||
DebugServerHost = sec.Key("DEBUG_SERVER_HOST").MustString("http://192.168.202.73") | |||
ImageServerHost = sec.Key("IMAGE_SERVER_HOST").MustString("http://192.168.202.73") | |||
} | |||
func loadInternalToken(sec *ini.Section) string { | |||
@@ -163,6 +163,7 @@ func CloudBrainShow(ctx *context.Context) { | |||
taskRes, _ := models.ConvertToTaskPod(taskRoles["task1"].(map[string]interface{})) | |||
ctx.Data["taskRes"] = taskRes | |||
task.Status = taskRes.TaskStatuses[0].State | |||
task.ContainerID = taskRes.TaskStatuses[0].ContainerID | |||
err = models.UpdateJob(task) | |||
if err != nil { | |||
ctx.Data["error"] = err.Error() | |||
@@ -174,8 +175,6 @@ func CloudBrainShow(ctx *context.Context) { | |||
} | |||
func CloudBrainDebug(ctx *context.Context) { | |||
ctx.Data["PageIsCloudBrain"] = true | |||
var jobID = ctx.Params(":jobid") | |||
task, err := models.GetCloudbrainByJobID(jobID) | |||
if err != nil { | |||
@@ -187,6 +186,33 @@ func CloudBrainDebug(ctx *context.Context) { | |||
ctx.Redirect(debugUrl) | |||
} | |||
func CloudBrainCommitImage(ctx *context.Context) { | |||
var jobID = ctx.Params(":jobid") | |||
var description = ctx.Query("description") | |||
log.Info(description) | |||
task, err := models.GetCloudbrainByJobID(jobID) | |||
if err != nil { | |||
ctx.ServerError("GetCloudbrainByJobID failed", err) | |||
return | |||
} | |||
jobResult, err := cloudbrain.CommitImage(jobID, models.CommitImageParams{ | |||
Ip: setting.ImageServerHost, | |||
TaskContainerId: task.ContainerID, | |||
ImageDescription: description, | |||
}) | |||
if err != nil { | |||
log.Error("CommitImage failed:", err.Error()) | |||
return | |||
} | |||
if jobResult.Code != cloudbrain.Success { | |||
log.Error("CommitImage(%s) failed:%s", jobID, jobResult.Msg) | |||
return | |||
} | |||
ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") | |||
} | |||
func downloadCode(repo *models.Repository, codePath string) error { | |||
/* | |||
if err := git.Clone(repo.RepoPath(), codePath, git.CloneRepoOptions{ | |||
@@ -896,6 +896,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
m.Get("", reqRepoCloudBrainReader, repo.CloudBrainIndex) | |||
m.Get("/:jobid", reqRepoCloudBrainReader, repo.CloudBrainShow) | |||
m.Get("/:jobid/debug", reqRepoCloudBrainReader, repo.CloudBrainDebug) | |||
m.Post("/:jobid/commit_image", reqRepoCloudBrainReader, repo.CloudBrainCommitImage) | |||
m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainNew) | |||
m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) | |||
}, context.RepoRef()) | |||
@@ -54,9 +54,9 @@ | |||
</a> | |||
</span> | |||
</div> | |||
<div class="one wide column" style="{{if not .CanDebug}}visibility: hidden;{{end}}"> | |||
<div class="one wide column"> | |||
<span class="ui text center clipboard"> | |||
<a class="title" href="{{$.Link}}/{{.JobID}}/debug"> | |||
<a class="title" href="{{if not .CanDebug}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/debug{{end}}" style="{{if not .CanDebug}}color:#CCCCCC{{end}}"> | |||
<span class="fitted">调试</span> | |||
</a> | |||
</span> | |||
@@ -68,6 +68,7 @@ | |||
</a> | |||
</span> | |||
</div> | |||
</div> | |||
</div> | |||
{{end}} | |||
@@ -98,4 +99,5 @@ $( document ).ready(function() { | |||
}); | |||
}); | |||
}); | |||
</script> |