Skip to content

Commit 5a0cff1

Browse files
author
Normalnoise
authored
Merge pull request #201 from swanchain/fea-sync-mining-status
Add sync mining task status and show `rejected` tasks
2 parents 4845e81 + fea89cd commit 5a0cff1

File tree

19 files changed

+453
-142
lines changed

19 files changed

+453
-142
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ spec:
298298
spec:
299299
containers:
300300
- name: resource-exporter
301-
image: filswan/resource-exporter:v11.3.1
301+
image: filswan/resource-exporter:v11.3.2
302302
imagePullPolicy: IfNotPresent
303303
securityContext:
304304
privileged: true
@@ -355,6 +355,7 @@ make install
355355
WalletBlackList = "" # CP reject user addresses from this blacklist for space deployment
356356
Pricing = "true" # default True, indicating acceptance of smart pricing orders, which may include orders priced lower than self-determined pricing.
357357
AutoDeleteImage = false # Default false, automatically delete unused images
358+
ClearLogDuration = 24 # The interval for automatically clearing the log, the unit is hours
358359
PortRange= ["40000-40050","40070"] # Externally exposed port number for deploying ECP image tasks
359360
360361
[UBI]

build/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ var CurrentCommit string
1010

1111
var NetWorkTag string
1212

13-
const BuildVersion = "1.0.1"
13+
const BuildVersion = "1.0.2"
1414

1515
const UBITaskImageIntelCpu = "filswan/ubi-worker-cpu-intel:latest"
1616
const UBITaskImageIntelGpu = "filswan/ubi-worker-gpu-intel:latest"
1717
const UBITaskImageAmdCpu = "filswan/ubi-worker-cpu-amd:latest"
1818
const UBITaskImageAmdGpu = "filswan/ubi-worker-gpu-amd:latest"
19-
const UBIResourceExporterDockerImage = "filswan/resource-exporter:v11.3.1"
19+
const UBIResourceExporterDockerImage = "filswan/resource-exporter:v11.3.2"
2020
const TraefikServerDockerImage = "traefik:v2.10"
2121

2222
func UserVersion() string {

cmd/computing-provider/ubi.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ var daemonCmd = &cli.Command{
239239
func getStatusColor(taskStatus int) []tablewriter.Colors {
240240
var rowColor []tablewriter.Colors
241241
switch taskStatus {
242+
case models.TASK_REJECTED_STATUS:
243+
rowColor = []tablewriter.Colors{{tablewriter.Bold, tablewriter.FgRedColor}}
242244
case models.TASK_RECEIVED_STATUS:
243245
rowColor = []tablewriter.Colors{{tablewriter.Bold, tablewriter.FgYellowColor}}
244246
case models.TASK_RUNNING_STATUS:

conf/config.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ type ComputeNode struct {
4646
}
4747

4848
type API struct {
49-
Port int
50-
MultiAddress string
51-
Domain string
52-
NodeName string
53-
WalletWhiteList string
54-
WalletBlackList string
55-
Pricing Pricing `toml:"pricing"`
56-
AutoDeleteImage bool `toml:"AutoDeleteImage"`
57-
PortRange []string `toml:"PortRange"`
49+
Port int
50+
MultiAddress string
51+
Domain string
52+
NodeName string
53+
WalletWhiteList string
54+
WalletBlackList string
55+
Pricing Pricing `toml:"pricing"`
56+
AutoDeleteImage bool `toml:"AutoDeleteImage"`
57+
ClearLogDuration int `toml:"ClearLogDuration"`
58+
PortRange []string `toml:"PortRange"`
5859
}
5960
type UBI struct {
6061
UbiEnginePk string
@@ -71,7 +72,6 @@ type LOG struct {
7172
}
7273

7374
type HUB struct {
74-
AccessToken string
7575
BalanceThreshold float64
7676
OrchestratorPk string
7777
VerifySign bool
@@ -216,6 +216,9 @@ func getConfigByHeight() {
216216
config.UBI.EdgeUrl = ncCopy.Config.EdgeUrl
217217
config.CONTRACT.ZkCollateralUbiZero = ncCopy.Config.ZkCollateralUbiZeroContract
218218
config.CONTRACT.JobCollateralUbiZero = ncCopy.Config.OrchestratorCollateralUbiZeroContract
219+
if config.API.ClearLogDuration == 0 {
220+
config.API.ClearLogDuration = 24
221+
}
219222
}
220223
}
221224
}

config.toml.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ WalletWhiteList = "" # CP ac
77
WalletBlackList = "" # CP reject user addresses from this blacklist for space deployment
88
Pricing = "true" # Default True, indicating acceptance of smart pricing orders, which may include orders priced lower than self-determined pricing.
99
AutoDeleteImage = false # Default false, automatically delete unused images
10+
ClearLogDuration = 24 # Delete logs at intervals after the job is finished, the unit is hours
1011
PortRange = ["40000-40050","40070"] # Externally exposed port number for deploying multi-port image tasks
1112

1213

constants/utils.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
package constants
22

3-
const StatusActive = "Active"
4-
const StatusOffline = "Offline"
5-
6-
// bidding status
7-
const BiddingCreated string = "created"
8-
const BiddingAccepting string = "accepting_bids"
9-
const BiddingProcessing string = "processing"
10-
const BiddingSubmitted string = "submitted"
11-
const BiddingCompleted string = "completed"
12-
const BiddingCancelled string = "cancelled"
13-
143
const K8S_NAMESPACE_NAME_PREFIX = "ns-"
154
const K8S_CONTAINER_NAME_PREFIX = "pod-"
165
const K8S_PRIVATE_CONTAINER_PREFIX = "vm-"
@@ -29,3 +18,10 @@ const (
2918
BidMode_Private
3019
BidMode_None
3120
)
21+
22+
const (
23+
BUILD_IMAGE_PATH_PREFIX = "build"
24+
LOG_PATH_PREFIX = "logs"
25+
BUILD_LOG_NAME = "build.log"
26+
Container_LOG_NAME = "container.log"
27+
)

internal/computing/buildspace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func BuildImagesByDockerfile(jobUuid, spaceName, imagePath string) (string, stri
122122
log.Printf("Image path: %s", imagePath)
123123

124124
dockerService := NewDockerService()
125-
if err := dockerService.BuildImage(imagePath, imageName); err != nil {
125+
if err := dockerService.BuildImage(jobUuid, imagePath, imageName); err != nil {
126126
logs.GetLogger().Errorf("Error building Docker image: %v", err)
127127
return "", ""
128128
}

internal/computing/cron_task.go

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"fmt"
66
"github.com/swanchain/go-computing-provider/internal/contract"
7+
"os"
8+
"path/filepath"
79
"strconv"
810
"strings"
911
"sync"
@@ -45,6 +47,9 @@ func (task *CronTask) RunTask() {
4547
task.checkJobReward()
4648
task.cleanImageResource()
4749
task.CheckCpBalance()
50+
task.UpdateContainerLog()
51+
task.DeleteSpaceLog()
52+
4853
}
4954

5055
func CheckClusterNetworkPolicy() {
@@ -566,7 +571,7 @@ func addNodeLabel() {
566571

567572
func (task *CronTask) CheckCpBalance() {
568573
c := cron.New(cron.WithSeconds())
569-
c.AddFunc("* 0/30 * * * ?", func() {
574+
c.AddFunc("0 0/30 * * * ?", func() {
570575
defer func() {
571576
if err := recover(); err != nil {
572577
logs.GetLogger().Errorf("check cp balance catch panic error: %+v", err)
@@ -577,6 +582,60 @@ func (task *CronTask) CheckCpBalance() {
577582
c.Start()
578583
}
579584

585+
func (task *CronTask) UpdateContainerLog() {
586+
c := cron.New(cron.WithSeconds())
587+
c.AddFunc("* 0/10 * * * ?", func() {
588+
defer func() {
589+
if err := recover(); err != nil {
590+
logs.GetLogger().Errorf("update container log catch panic error: %+v", err)
591+
}
592+
}()
593+
594+
jobList, err := NewJobService().GetJobList(models.UN_DELETEED_FLAG, -1)
595+
if err != nil {
596+
logs.GetLogger().Errorf("failed to get job data, error: %+v", err)
597+
return
598+
}
599+
600+
for _, job := range jobList {
601+
NewK8sService().UpdateContainerLogToFile(job.JobUuid)
602+
}
603+
})
604+
c.Start()
605+
}
606+
607+
func (task *CronTask) DeleteSpaceLog() {
608+
c := cron.New(cron.WithSeconds())
609+
c.AddFunc("0 0/30 * * * ?", func() {
610+
defer func() {
611+
if err := recover(); err != nil {
612+
logs.GetLogger().Errorf("update container log catch panic error: %+v", err)
613+
}
614+
}()
615+
616+
jobList, err := NewJobService().GetJobList(models.DELETED_FLAG, -1)
617+
if err != nil {
618+
logs.GetLogger().Errorf("failed to get job data, error: %+v", err)
619+
return
620+
}
621+
cpRepoPath, _ := os.LookupEnv("CP_PATH")
622+
623+
for _, job := range jobList {
624+
if job.CreateTime+int64(24*7*3600) < time.Now().Unix() {
625+
continue
626+
}
627+
if job.ExpireTime+int64(conf.GetConfig().API.ClearLogDuration)*3600 < time.Now().Unix() {
628+
err := os.RemoveAll(filepath.Join(cpRepoPath, constants.LOG_PATH_PREFIX, job.JobUuid))
629+
if err != nil {
630+
logs.GetLogger().Errorf("failed to delete logs, job_uuid: %s, error: %v", job.JobUuid, err)
631+
continue
632+
}
633+
}
634+
}
635+
})
636+
c.Start()
637+
}
638+
580639
func reportJobStatus(jobUuid string, deployStatus int) bool {
581640
var job = new(models.JobEntity)
582641
job.JobUuid = jobUuid
@@ -659,7 +718,8 @@ func checkFcpJobInfoInChain(job *models.JobEntity) {
659718
type TaskGroup struct {
660719
Items []*models.TaskEntity
661720
Ids []int64
662-
Type int // 1: contract 2: sequncer
721+
Uuids []string
722+
Type int // 1: contract 2: sequncer 3: mining
663723
}
664724

665725
func handleTasksToGroup(list []*models.TaskEntity) []TaskGroup {
@@ -695,3 +755,23 @@ func handleTasksToGroup(list []*models.TaskEntity) []TaskGroup {
695755
}
696756
return groups
697757
}
758+
759+
func handleTasksToGroupForMining(list []*models.TaskEntity) []TaskGroup {
760+
var groups []TaskGroup
761+
var group TaskGroup
762+
763+
const batchSize = 10
764+
for i := 0; i < len(list); i++ {
765+
if len(group.Items) > batchSize {
766+
groups = append(groups, group)
767+
group = TaskGroup{}
768+
}
769+
group.Items = append(group.Items, list[i])
770+
group.Uuids = append(group.Uuids, list[i].Uuid)
771+
group.Type = 3
772+
}
773+
if len(group.Items) > 0 {
774+
groups = append(groups, group)
775+
}
776+
return groups
777+
}

internal/computing/deploy.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ func (d *Deploy) ModelInferenceToK8s() error {
419419

420420
imageName := "lagrange/" + modelInfo.Framework + ":v1.0"
421421

422-
logFile := filepath.Join(d.SpacePath, BuildFileName)
422+
logDir := filepath.Join(cpPath, constants.LOG_PATH_PREFIX, d.originalJobUuid)
423+
os.MkdirAll(logDir, os.ModePerm)
424+
425+
logFile := filepath.Join(logDir, constants.BUILD_LOG_NAME)
423426
if _, err = os.Create(logFile); err != nil {
424427
return err
425428
}

internal/computing/docker_service.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/docker/docker/api/types/registry"
1818
"github.com/filswan/go-mcs-sdk/mcs/api/common/logs"
1919
"github.com/swanchain/go-computing-provider/build"
20+
"github.com/swanchain/go-computing-provider/constants"
2021
"io"
2122
"os"
2223
"os/exec"
@@ -32,8 +33,6 @@ import (
3233
"github.com/docker/docker/client"
3334
)
3435

35-
const BuildFileName = "build.log"
36-
3736
type DockerService struct {
3837
c *client.Client
3938
}
@@ -75,7 +74,7 @@ func ExtractExposedPort(dockerfilePath string) (string, error) {
7574
return exposedPort, nil
7675
}
7776

78-
func (ds *DockerService) BuildImage(buildPath, imageName string) error {
77+
func (ds *DockerService) BuildImage(jobUuid, buildPath, imageName string) error {
7978
// Create a buffer
8079
buf := new(bytes.Buffer)
8180
tw := tar.NewWriter(buf)
@@ -120,7 +119,11 @@ func (ds *DockerService) BuildImage(buildPath, imageName string) error {
120119
}
121120
defer buildResponse.Body.Close()
122121

123-
logFile, err := os.Create(filepath.Join(buildPath, BuildFileName))
122+
cpRepoPath, _ := os.LookupEnv("CP_PATH")
123+
logDir := filepath.Join(cpRepoPath, constants.LOG_PATH_PREFIX, jobUuid)
124+
os.MkdirAll(logDir, os.ModePerm)
125+
126+
logFile, err := os.Create(filepath.Join(logDir, constants.BUILD_LOG_NAME))
124127
if err != nil {
125128
return err
126129
}

0 commit comments

Comments
 (0)