Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
power-node
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
power-node
Commits
0a0dbbda
Commit
0a0dbbda
authored
Mar 19, 2024
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update task handler
parent
559ca15b
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
183 additions
and
61 deletions
+183
-61
const.go
models/const.go
+2
-0
node_manager.go
models/node_manager.go
+11
-0
msg_resp.go
nm/msg_resp.go
+2
-1
start.go
nm/start.go
+3
-0
task_msg.go
nm/task_msg.go
+149
-60
util.go
utils/util.go
+16
-0
No files found.
models/const.go
View file @
0a0dbbda
...
@@ -10,6 +10,8 @@ const (
...
@@ -10,6 +10,8 @@ const (
ContentType
=
"type"
ContentType
=
"type"
RedirectCode
=
303
RedirectCode
=
303
UseFileCache
=
"USE-FILE-CACHE"
UseFileCache
=
"USE-FILE-CACHE"
Prefer
=
"Prefer"
Async
=
"respond-async"
ModelPublishStatusYes
=
1
ModelPublishStatusYes
=
1
ModelPublishStatusNo
=
2
ModelPublishStatusNo
=
2
)
)
models/node_manager.go
View file @
0a0dbbda
...
@@ -30,12 +30,17 @@ type TaskParam struct {
...
@@ -30,12 +30,17 @@ type TaskParam struct {
Body
[]
byte
`json:"body"`
Body
[]
byte
`json:"body"`
}
}
type
ContainerRequest
struct
{
WebHook
string
`json:"webhook"`
}
type
TaskResult
struct
{
type
TaskResult
struct
{
TaskHttpHeaders
[]
byte
TaskHttpHeaders
[]
byte
TaskExecTime
int64
TaskExecTime
int64
TaskHttpStatusCode
int32
TaskHttpStatusCode
int32
TaskRespBody
[]
byte
TaskRespBody
[]
byte
TaskIsSuccess
bool
TaskIsSuccess
bool
TaskExecError
string
}
}
type
ApiResp
struct
{
type
ApiResp
struct
{
...
@@ -72,6 +77,12 @@ type ModelInfo struct {
...
@@ -72,6 +77,12 @@ type ModelInfo struct {
PublishStatus
int
`json:"publish_status"`
PublishStatus
int
`json:"publish_status"`
}
}
type
FileCacheResult
struct
{
Code
int
`json:"code"`
Msg
string
`json:"msg"`
Data
string
`json:"data"`
}
type
ComputeResult
struct
{
type
ComputeResult
struct
{
Code
string
`json:"code"`
Code
string
`json:"code"`
Msg
string
`json:"msg"`
Msg
string
`json:"msg"`
...
...
nm/msg_resp.go
View file @
0a0dbbda
...
@@ -239,7 +239,8 @@ func SubmitResultResp(params ...interface{}) *nodemanagerV1.WorkerMessage {
...
@@ -239,7 +239,8 @@ func SubmitResultResp(params ...interface{}) *nodemanagerV1.WorkerMessage {
TaskId
:
taskId
,
TaskId
:
taskId
,
ContainerSignature
:
containerSign
,
ContainerSignature
:
containerSign
,
MinerSignature
:
minerSign
,
MinerSignature
:
minerSign
,
TaskResultCode
:
taskExecResult
.
TaskHttpStatusCode
,
TaskExecuteCode
:
taskExecResult
.
TaskHttpStatusCode
,
TaskExecuteError
:
taskExecResult
.
TaskExecError
,
TaskResultHeader
:
taskExecResult
.
TaskHttpHeaders
,
TaskResultHeader
:
taskExecResult
.
TaskHttpHeaders
,
TaskExecuteDuration
:
uint64
(
taskExecResult
.
TaskExecTime
),
TaskExecuteDuration
:
uint64
(
taskExecResult
.
TaskExecTime
),
IsSuccessed
:
isSuccess
,
IsSuccessed
:
isSuccess
,
...
...
nm/start.go
View file @
0a0dbbda
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"example.com/m/operate"
"example.com/m/operate"
"example.com/m/utils"
"example.com/m/utils"
"example.com/m/validator"
"example.com/m/validator"
"fmt"
nodeManagerV1
"github.com/odysseus/odysseus-protocol/gen/proto/go/nodemanager/v1"
nodeManagerV1
"github.com/odysseus/odysseus-protocol/gen/proto/go/nodemanager/v1"
"google.golang.org/grpc"
"google.golang.org/grpc"
"time"
"time"
...
@@ -293,6 +294,7 @@ func handlerMsg(nodeManager *models.NodeManagerClient,
...
@@ -293,6 +294,7 @@ func handlerMsg(nodeManager *models.NodeManagerClient,
TaskHttpHeaders
:
nil
,
TaskHttpHeaders
:
nil
,
TaskIsSuccess
:
false
,
TaskIsSuccess
:
false
,
TaskExecTime
:
0
,
TaskExecTime
:
0
,
TaskExecError
:
""
,
}
}
if
taskExecResInterface
!=
nil
{
if
taskExecResInterface
!=
nil
{
taskExecRes
=
taskExecResInterface
.
(
*
models
.
TaskResult
)
taskExecRes
=
taskExecResInterface
.
(
*
models
.
TaskResult
)
...
@@ -302,6 +304,7 @@ func handlerMsg(nodeManager *models.NodeManagerClient,
...
@@ -302,6 +304,7 @@ func handlerMsg(nodeManager *models.NodeManagerClient,
if
containerSign
==
nil
||
len
(
containerSign
)
==
0
{
if
containerSign
==
nil
||
len
(
containerSign
)
==
0
{
log
.
Error
(
"Container signing failed................"
)
log
.
Error
(
"Container signing failed................"
)
isSuccess
=
false
isSuccess
=
false
taskExecRes
.
TaskExecError
=
fmt
.
Sprintf
(
"%s,%s"
,
taskExecRes
.
TaskExecError
,
"Container sign failed"
)
}
}
reqHash
,
respHash
,
minerSign
:=
taskMsgWorker
.
GetMinerSign
(
taskMsg
,
taskExecRes
.
TaskRespBody
)
reqHash
,
respHash
,
minerSign
:=
taskMsgWorker
.
GetMinerSign
(
taskMsg
,
taskExecRes
.
TaskRespBody
)
params
:=
buildParams
(
taskMsg
.
TaskId
,
containerSign
,
minerSign
,
taskExecRes
,
isSuccess
)
params
:=
buildParams
(
taskMsg
.
TaskId
,
containerSign
,
minerSign
,
taskExecRes
,
isSuccess
)
...
...
nm/task_msg.go
View file @
0a0dbbda
This diff is collapsed.
Click to expand it.
utils/util.go
View file @
0a0dbbda
package
utils
package
utils
import
(
import
(
"bytes"
"crypto/ecdsa"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/elliptic"
"crypto/rand"
"crypto/rand"
"encoding/base64"
"encoding/base64"
"encoding/json"
"example.com/m/log"
"example.com/m/log"
"example.com/m/models"
"example.com/m/models"
"fmt"
"fmt"
...
@@ -110,6 +112,7 @@ func IsBase64ImageStr(imageStr string) (bool, []byte, string, string) {
...
@@ -110,6 +112,7 @@ func IsBase64ImageStr(imageStr string) (bool, []byte, string, string) {
}
}
decodeBytes
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
base64Code
)
decodeBytes
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
base64Code
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"base64 decode string failed"
)
return
false
,
nil
,
""
,
""
return
false
,
nil
,
""
,
""
}
}
formatStr
:=
strings
.
Split
(
strings
.
Split
(
base64CodePrefix
,
";"
)[
0
],
":"
)[
1
]
formatStr
:=
strings
.
Split
(
strings
.
Split
(
base64CodePrefix
,
";"
)[
0
],
":"
)[
1
]
...
@@ -151,3 +154,16 @@ func MatchContainerQueryString(params map[string]string) string {
...
@@ -151,3 +154,16 @@ func MatchContainerQueryString(params map[string]string) string {
}
}
return
values
.
Encode
()
return
values
.
Encode
()
}
}
func
EncodeJsonEscapeHTML
(
apiRes
any
)
[]
byte
{
apiResBody
:=
bytes
.
NewBuffer
([]
byte
{})
encoder
:=
json
.
NewEncoder
(
apiResBody
)
encoder
.
SetEscapeHTML
(
false
)
err
:=
encoder
.
Encode
(
apiRes
)
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"encoder Encode"
)
return
apiResBody
.
Bytes
()
}
log
.
WithField
(
"apiResBody"
,
string
(
apiResBody
.
Bytes
()))
.
Info
(
"model resp"
)
return
apiResBody
.
Bytes
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment