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
42ba8102
Commit
42ba8102
authored
Apr 01, 2024
by
duanjinfei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into test
parents
37c62ece
aa3f3228
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
64 deletions
+59
-64
config.go
conf/config.go
+20
-19
config.json
config.json
+2
-1
const.go
models/const.go
+20
-21
task_handler.go
nm/task_handler.go
+17
-23
No files found.
conf/config.go
View file @
42ba8102
...
...
@@ -9,25 +9,26 @@ import (
)
type
Config
struct
{
SignPrv
string
SignPub
string
DockerServer
string
BenefitAddress
string
HeartRespTimeMillis
int64
ExternalIp
string
SignPublicAddress
common
.
Address
SignPrivateKey
*
ecdsa
.
PrivateKey
NmSeed
string
`json:"nm_seed"`
HeartRespTimeSecond
int64
`json:"heart_response"`
TaskValidatorTime
float64
`json:"task_validator_time"`
ContainerNum
int64
`json:"container_num"`
NodeManagerNum
int64
`json:"node_manager_num"`
ChainID
int64
`json:"chain_id"`
ApiUrl
string
`json:"api_url"`
ValidatorUrl
string
`json:"validator_url"`
OssUrl
string
`json:"oss_url"`
WaitLastTaskExecTime
int64
`json:"wait_last_task_exec_time"`
OpSys
string
`json:"op_sys"`
SignPrv
string
SignPub
string
DockerServer
string
BenefitAddress
string
HeartRespTimeMillis
int64
ExternalIp
string
SignPublicAddress
common
.
Address
SignPrivateKey
*
ecdsa
.
PrivateKey
NmSeed
string
`json:"nm_seed"`
HeartRespTimeSecond
int64
`json:"heart_response"`
TaskValidatorTime
float64
`json:"task_validator_time"`
ContainerNum
int64
`json:"container_num"`
NodeManagerNum
int64
`json:"node_manager_num"`
ChainID
int64
`json:"chain_id"`
ApiUrl
string
`json:"api_url"`
ValidatorUrl
string
`json:"validator_url"`
OssUrl
string
`json:"oss_url"`
WaitLastTaskExecTime
int64
`json:"wait_last_task_exec_time"`
OpSys
string
`json:"op_sys"`
ReplicateImageNameSuffix
string
`json:"replicate_image_name_suffix"`
}
var
_cfg
*
Config
=
nil
...
...
config.json
View file @
42ba8102
...
...
@@ -9,5 +9,6 @@
"validator_url"
:
"18.167.203.17:20011"
,
"oss_url"
:
"https://tmp-file.aigic.ai/api/v1/upload"
,
"wait_last_task_exec_time"
:
60
,
"op_sys"
:
"linux"
"op_sys"
:
"linux"
,
"replicate_image_name_suffix"
:
"docker.aigic.ai/ai"
}
\ No newline at end of file
models/const.go
View file @
42ba8102
package
models
const
(
TaskType
=
"taskType"
ContainerSign
=
"container"
MinerSign
=
"miner"
ReqHash
=
"reqHash"
RespHash
=
"respHash"
ResultFileExpiresDB
=
"expires"
ContentType
=
"type"
RedirectCode
=
303
UseFileCache
=
"Use-File-Cache"
UseRedirect
=
"Use-Redirect"
Prefer
=
"Prefer"
Async
=
"respond-async"
MaxExecTime
=
"MaxExecTime"
HealthCheckAPI
=
"/health-check"
ReplicateImageNameSuffix
=
"docker.agicoin.ai/agicoin"
READY
=
"READY"
ZeroHost
=
"0.0.0.0"
ModelPublishStatusYes
=
1
ModelPublishStatusNo
=
2
DefaultMaxExecTime
=
300
DefaultTaskTimer
=
2
TaskType
=
"taskType"
ContainerSign
=
"container"
MinerSign
=
"miner"
ReqHash
=
"reqHash"
RespHash
=
"respHash"
ResultFileExpiresDB
=
"expires"
ContentType
=
"type"
RedirectCode
=
303
UseFileCache
=
"Use-File-Cache"
UseRedirect
=
"Use-Redirect"
Prefer
=
"Prefer"
Async
=
"respond-async"
MaxExecTime
=
"MaxExecTime"
HealthCheckAPI
=
"/health-check"
READY
=
"READY"
ZeroHost
=
"0.0.0.0"
ModelPublishStatusYes
=
1
ModelPublishStatusNo
=
2
DefaultMaxExecTime
=
300
DefaultTaskTimer
=
2
)
nm/task_handler.go
View file @
42ba8102
...
...
@@ -197,25 +197,6 @@ func (t *TaskWorker) ComputeTaskHandler(taskMsg *nodeManagerV1.PushTaskMessage)
log
.
Info
(
"Container ports:"
,
internalPort
)
log
.
WithField
(
"ApiUrl"
,
taskOp
.
taskCmd
.
ApiUrl
)
.
Info
(
"The image is running"
)
}
reqContainerBody
:=
bytes
.
NewReader
(
taskOp
.
taskParam
.
Body
)
if
len
(
taskOp
.
taskParam
.
Queries
)
>
0
{
queryString
:=
utils
.
MatchContainerQueryString
(
taskOp
.
taskParam
.
Queries
)
taskOp
.
taskCmd
.
ApiUrl
=
fmt
.
Sprintf
(
"%s?%s"
,
taskOp
.
taskCmd
.
ApiUrl
,
queryString
)
log
.
WithField
(
"ApiUrl"
,
taskOp
.
taskCmd
.
ApiUrl
)
.
Info
(
"The task param query str not empty"
)
}
taskOp
.
request
,
err
=
http
.
NewRequest
(
"POST"
,
taskOp
.
taskCmd
.
ApiUrl
,
reqContainerBody
)
if
err
!=
nil
{
log
.
WithField
(
"error:"
,
err
)
.
Error
(
"New container request failed"
)
taskOp
.
taskExecResult
.
TaskExecError
=
fmt
.
Sprintf
(
"%s,%s"
,
"Http client new container request failed"
,
err
.
Error
())
t
.
ExecTaskIdIsSuccess
.
Store
(
taskMsg
.
TaskId
,
true
)
return
}
taskOp
.
request
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
if
err
=
taskOp
.
validateWebHook
();
err
!=
nil
{
taskOp
.
taskExecResult
.
TaskExecError
=
fmt
.
Sprintf
(
"%s"
,
err
.
Error
())
t
.
ExecTaskIdIsSuccess
.
Store
(
taskMsg
.
TaskId
,
true
)
return
}
if
err
=
taskOp
.
waitReqContainerOk
(
t
.
DockerOp
);
err
!=
nil
{
taskOp
.
taskExecResult
.
TaskExecError
=
fmt
.
Sprintf
(
"%s"
,
err
.
Error
())
t
.
ExecTaskIdIsSuccess
.
Store
(
taskMsg
.
TaskId
,
true
)
...
...
@@ -476,7 +457,7 @@ func (op *TaskOp) waitContainerRunning(handler *TaskWorker, imageId string) erro
if
!
running
{
continue
}
if
isMatch
:=
strings
.
HasPrefix
(
op
.
taskCmd
.
ImageName
,
models
.
ReplicateImageNameSuffix
);
isMatch
{
if
isMatch
:=
strings
.
HasPrefix
(
op
.
taskCmd
.
ImageName
,
conf
.
GetConfig
()
.
ReplicateImageNameSuffix
);
isMatch
{
if
isReqSuccess
,
err
:=
op
.
checkContainerHealthy
(
internalIp
,
internalPort
);
err
!=
nil
{
log
.
WithField
(
"err"
,
err
)
.
Errorf
(
"check container healthy failed"
)
return
fmt
.
Errorf
(
"%s-%s"
,
"check container healthy failed"
,
err
.
Error
())
...
...
@@ -537,12 +518,25 @@ func (op *TaskOp) waitReqContainerOk(dockerOp *operate.DockerOp) error {
log
.
Errorf
(
"%s"
,
"The maximum execution time for this task has been exceeded"
)
return
fmt
.
Errorf
(
"%s"
,
"The maximum execution time for this task has been exceeded"
)
}
newQuest
:=
utils
.
CloneRequest
(
op
.
request
)
post
,
err
:=
op
.
httpClient
.
Do
(
newQuest
)
reqContainerBody
:=
bytes
.
NewReader
(
op
.
taskParam
.
Body
)
if
len
(
op
.
taskParam
.
Queries
)
>
0
{
queryString
:=
utils
.
MatchContainerQueryString
(
op
.
taskParam
.
Queries
)
op
.
taskCmd
.
ApiUrl
=
fmt
.
Sprintf
(
"%s?%s"
,
op
.
taskCmd
.
ApiUrl
,
queryString
)
log
.
WithField
(
"ApiUrl"
,
op
.
taskCmd
.
ApiUrl
)
.
Info
(
"The task param query str not empty"
)
}
op
.
request
,
err
=
http
.
NewRequest
(
"POST"
,
op
.
taskCmd
.
ApiUrl
,
reqContainerBody
)
if
err
!=
nil
{
log
.
WithField
(
"error:"
,
err
)
.
Error
(
"New container request failed"
)
return
fmt
.
Errorf
(
"%s,%s"
,
"Http client new container request failed"
,
err
.
Error
())
}
op
.
request
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
if
err
=
op
.
validateWebHook
();
err
!=
nil
{
return
fmt
.
Errorf
(
"%s"
,
err
.
Error
())
}
post
,
err
:=
op
.
httpClient
.
Do
(
op
.
request
)
if
err
!=
nil
{
log
.
WithField
(
"error:"
,
err
)
.
Error
(
"Http client post request container failed"
)
return
fmt
.
Errorf
(
"%s,%s"
,
"Http client post request container failed"
,
err
.
Error
())
//continue
}
log
.
WithField
(
"StatusCode"
,
post
.
StatusCode
)
.
WithField
(
"taskId"
,
op
.
taskMsg
.
TaskId
)
.
Info
(
"Exec task result"
)
if
post
.
StatusCode
==
http
.
StatusOK
{
...
...
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