Commit 90a434c0 authored by duanjinfei's avatar duanjinfei

upload image

parent 471e84fb
...@@ -38,8 +38,10 @@ type TaskResult struct { ...@@ -38,8 +38,10 @@ type TaskResult struct {
TaskIsSuccess bool TaskIsSuccess bool
} }
type ModelResponse struct { type ApiResp struct {
Output []string `json:"output"` Code int32 `json:"code"`
Msg string `json:"msg"`
Res interface{} `json:"res"`
} }
type HardwareRequire struct { type HardwareRequire struct {
......
...@@ -235,18 +235,21 @@ func SubmitResultResp(params ...interface{}) *nodemanagerV1.WorkerMessage { ...@@ -235,18 +235,21 @@ func SubmitResultResp(params ...interface{}) *nodemanagerV1.WorkerMessage {
minerSign := params[2].([]byte) minerSign := params[2].([]byte)
taskExecResult := params[3].(*models.TaskResult) taskExecResult := params[3].(*models.TaskResult)
isSuccess := params[4].(bool) isSuccess := params[4].(bool)
n := &nodemanagerV1.SubmitTaskResult{
TaskId: taskId,
ContainerSignature: containerSign,
MinerSignature: minerSign,
TaskResultCode: taskExecResult.TaskHttpStatusCode,
TaskResultHeader: taskExecResult.TaskHttpHeaders,
TaskExecuteDuration: uint64(taskExecResult.TaskExecTime),
IsSuccessed: isSuccess,
}
if taskExecResult.TaskHttpStatusCode == 200 {
n.TaskResultBody = taskExecResult.TaskRespBody
}
submitResultMsgRes := &nodemanagerV1.WorkerMessage{ submitResultMsgRes := &nodemanagerV1.WorkerMessage{
Message: &nodemanagerV1.WorkerMessage_SubmitTaskResult{ Message: &nodemanagerV1.WorkerMessage_SubmitTaskResult{
SubmitTaskResult: &nodemanagerV1.SubmitTaskResult{ SubmitTaskResult: n,
TaskId: taskId,
ContainerSignature: containerSign,
MinerSignature: minerSign,
TaskResultCode: taskExecResult.TaskHttpStatusCode,
TaskResultHeader: taskExecResult.TaskHttpHeaders,
TaskResultBody: taskExecResult.TaskRespBody,
TaskExecuteDuration: uint64(taskExecResult.TaskExecTime),
IsSuccessed: isSuccess,
},
}, },
} }
log.Info("---------------------------------------Send task result msg ------------------------------------") log.Info("---------------------------------------Send task result msg ------------------------------------")
......
...@@ -19,7 +19,6 @@ import ( ...@@ -19,7 +19,6 @@ import (
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "time"
) )
...@@ -220,6 +219,7 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage) ...@@ -220,6 +219,7 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage)
log.Error("received error: ", err) log.Error("received error: ", err)
return return
} }
taskExecResult.TaskRespBody = readBody
isUseFileCache := true isUseFileCache := true
if taskMsg.TaskKind != baseV1.TaskKind_StandardTask { if taskMsg.TaskKind != baseV1.TaskKind_StandardTask {
for key, value := range taskParam.Headers { for key, value := range taskParam.Headers {
...@@ -232,22 +232,16 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage) ...@@ -232,22 +232,16 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage)
} }
log.WithField("isUseFileCache", isUseFileCache).Info("is use file cache") log.WithField("isUseFileCache", isUseFileCache).Info("is use file cache")
if isUseFileCache && readBody != nil { if isUseFileCache && readBody != nil {
respBody := make([]byte, 0) base64ImageStrArr := make([]string, 0)
base64ImageStr := ""
data := parseData(readBody) data := parseData(readBody)
if data != nil { if data != nil {
switch v := data.(type) { switch v := data.(type) {
case [][]string: case [][]string:
{ {
res := data.([][]string) res := data.([][]string)
if len(res) == 1 {
if len(res[0]) == 1 {
base64ImageStr = res[0][0]
}
}
for _, innerSlice := range res { for _, innerSlice := range res {
for _, str := range innerSlice { for _, str := range innerSlice {
respBody = append(respBody, []byte(str)...) base64ImageStrArr = append(base64ImageStrArr, str)
} }
} }
log.Info("data is [][]string type") log.Info("data is [][]string type")
...@@ -255,23 +249,22 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage) ...@@ -255,23 +249,22 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage)
case []string: case []string:
{ {
res := data.([]string) res := data.([]string)
if len(res) == 1 { for _, slice := range res {
base64ImageStr = res[0] base64ImageStrArr = append(base64ImageStrArr, slice)
} }
respBody = []byte(strings.Join(res, ""))
log.Info("data is []string type") log.Info("data is []string type")
} }
case string: case string:
{ {
res := data.(string) res := data.(string)
base64ImageStr = res base64ImageStrArr = append(base64ImageStrArr, res)
respBody = []byte(res)
log.Info("data is string type") log.Info("data is string type")
} }
default: default:
log.Error("data is unknown type", v) log.Error("data is unknown type", v)
} }
if base64ImageStr != "" { apiRes := make([]string, 0)
for _, base64ImageStr := range base64ImageStrArr {
isBase64, decodeByte, respFormat, suffix := utils.IsBase64ImageStr(base64ImageStr) isBase64, decodeByte, respFormat, suffix := utils.IsBase64ImageStr(base64ImageStr)
if isBase64 { if isBase64 {
log.WithField("taskId", taskMsg.TaskId).WithField("format", respFormat).WithField("suffix", suffix).Info("Parse container resp") log.WithField("taskId", taskMsg.TaskId).WithField("format", respFormat).WithField("suffix", suffix).Info("Parse container resp")
...@@ -282,12 +275,28 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage) ...@@ -282,12 +275,28 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage)
return return
} }
log.WithField("uri", ossUri).Info("upload image OSS successful") log.WithField("uri", ossUri).Info("upload image OSS successful")
if ossUri != "" { if ossUri != "" && len(base64ImageStrArr) == 1 {
taskExecResult.TaskHttpStatusCode = models.RedirectCode taskExecResult.TaskHttpStatusCode = models.RedirectCode
post.Header.Set("Location", ossUri) post.Header.Set("Location", ossUri)
} }
if ossUri != "" {
apiRes = append(apiRes, ossUri)
}
} }
} }
if len(apiRes) > 1 {
res := &models.ApiResp{
Code: 200,
Msg: "success",
Res: apiRes,
}
apiResBody, err := json.Marshal(res)
if err != nil {
log.WithError(err).Error("json marshal upload oss uri")
return
}
taskExecResult.TaskRespBody = apiResBody
}
} }
} }
} }
...@@ -297,7 +306,6 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage) ...@@ -297,7 +306,6 @@ func (t *TaskHandler) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage)
return return
} }
log.WithField("headers", post.Header).Info("return task http headers") log.WithField("headers", post.Header).Info("return task http headers")
taskExecResult.TaskRespBody = readBody
taskExecResult.TaskHttpHeaders = headers taskExecResult.TaskHttpHeaders = headers
taskExecResult.TaskIsSuccess = true taskExecResult.TaskIsSuccess = true
taskExecResult.TaskExecTime = endAfterTaskTime.Microseconds() taskExecResult.TaskExecTime = endAfterTaskTime.Microseconds()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment