computing

package
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 86 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceCpu     string = "cpu"
	ResourceMem     string = "mem"
	ResourceStorage string = "storage"
)
View Source
const (
	PingMsg    = "ping"
	PingPeriod = 3 * time.Second
)
View Source
const BuildFileName = "build.log"

Variables

View Source
var TaskMap sync.Map

Functions

func BlackList added in v0.6.0

func BlackList(c *gin.Context)

func BuildImagesByDockerfile

func BuildImagesByDockerfile(jobUuid, spaceUuid, spaceName, imagePath string) (string, string)

func CancelJob

func CancelJob(c *gin.Context)

func CheckWalletBlackList added in v0.6.0

func CheckWalletBlackList(jobSourceURI string) bool

func CheckWalletWhiteList added in v0.4.6

func CheckWalletWhiteList(jobSourceURI string) bool

func CronTaskForEcp added in v0.5.0

func CronTaskForEcp()

func DeleteJob added in v0.6.5

func DeleteJob(namespace, jobUuid string, msg string) error

func DeploySpaceTask

func DeploySpaceTask(jobData models.JobData, deployParam DeployParam, hostName string, gpuProductName string)

func DoProof

func DoProof(c *gin.Context)

func DoUbiTaskForDocker added in v0.4.6

func DoUbiTaskForDocker(c *gin.Context)

func DoUbiTaskForK8s added in v0.4.6

func DoUbiTaskForK8s(c *gin.Context)

func ExtractExposedPort

func ExtractExposedPort(dockerfilePath string) (string, error)

func GenerateNodeID

func GenerateNodeID(cpRepoPath string) (string, string, string)

func GeneratePriceConfig added in v0.6.5

func GeneratePriceConfig() error

func GetAggregatedTaskInfo added in v0.6.2

func GetAggregatedTaskInfo(taskContract string) (string, error)

func GetCpResource added in v0.4.6

func GetCpResource(c *gin.Context)

func GetJobStatus added in v0.5.0

func GetJobStatus(c *gin.Context)

func GetNodeId

func GetNodeId(cpRepoPath string) string

func GetNodeResource

func GetNodeResource(allPods []corev1.Pod, node *corev1.Node) (map[string]int64, map[string]int64, *models.NodeResource)

func GetOwnerAddressAndWorkerAddress added in v0.5.0

func GetOwnerAddressAndWorkerAddress() (string, string, error)

func GetPrice added in v0.6.5

func GetPrice(c *gin.Context)

func GetPublicKey added in v0.6.4

func GetPublicKey(c *gin.Context)

func GetServiceProviderInfo

func GetServiceProviderInfo(c *gin.Context)

func GetSpaceLog

func GetSpaceLog(c *gin.Context)

func GetTaskInfoOnChain added in v0.5.0

func GetTaskInfoOnChain(taskContract string) (models.EcpTaskInfo, error)

func GetToken added in v0.6.2

func GetToken() (string, error)

func ImportImageToContainerd added in v0.6.5

func ImportImageToContainerd(tarFile string) error

func InitComputingProvider

func InitComputingProvider(cpRepoPath string) string

func ReNewJob

func ReNewJob(c *gin.Context)

func ReceiveJob

func ReceiveJob(c *gin.Context)

func ReceiveUbiProof

func ReceiveUbiProof(c *gin.Context)

func RestartResourceExporter added in v0.5.0

func RestartResourceExporter() error

func StatisticalSources

func StatisticalSources(c *gin.Context)

func SyncCpAccountInfo added in v0.5.0

func SyncCpAccountInfo()

func WhiteList added in v0.5.0

func WhiteList(c *gin.Context)

Types

type Config added in v0.6.5

type Config struct {
	Resources map[string]string `toml:"-"`
}

type CpInfoService added in v0.5.0

type CpInfoService struct {
	*gorm.DB
}

func NewCpInfoService added in v0.5.0

func NewCpInfoService() CpInfoService

func (CpInfoService) GetCpInfoEntityByAccountAddress added in v0.5.0

func (cpServ CpInfoService) GetCpInfoEntityByAccountAddress(accountAddress string) (*models.CpInfoEntity, error)

func (CpInfoService) SaveCpInfoEntity added in v0.5.0

func (cpServ CpInfoService) SaveCpInfoEntity(cp *models.CpInfoEntity) (err error)

func (CpInfoService) UpdateCpInfoByNodeId added in v0.5.0

func (cpServ CpInfoService) UpdateCpInfoByNodeId(cp *models.CpInfoEntity) (err error)

type CpResourceSummary added in v0.5.0

type CpResourceSummary struct {
	ClusterInfo []*models.NodeResource
}

type CronTask

type CronTask struct {
	// contains filtered or unexported fields
}

func NewCronTask

func NewCronTask(nodeId string) *CronTask

func (*CronTask) RunTask

func (task *CronTask) RunTask()

type Deploy

type Deploy struct {
	SpacePath string
	TaskType  string
	// contains filtered or unexported fields
}

func NewDeploy

func NewDeploy(jobUuid, hostName, walletAddress, hardwareDesc string, duration int64, spaceType string) *Deploy

func (*Deploy) DockerfileToK8s

func (d *Deploy) DockerfileToK8s()

func (*Deploy) ModelInferenceToK8s

func (d *Deploy) ModelInferenceToK8s() error

func (*Deploy) WithDockerfile

func (d *Deploy) WithDockerfile(image, dockerfilePath string) *Deploy

func (*Deploy) WithGpuProductName

func (d *Deploy) WithGpuProductName(gpuProductName string) *Deploy

func (*Deploy) WithHardware added in v0.4.6

func (d *Deploy) WithHardware(cpu, memory, storage int, gpuModel string, gpuNum int) *Deploy

func (*Deploy) WithImage added in v0.4.6

func (d *Deploy) WithImage(images string) *Deploy

func (*Deploy) WithModelSettingFile

func (d *Deploy) WithModelSettingFile(modelsSettingFile string) *Deploy

func (*Deploy) WithSpaceName added in v0.6.5

func (d *Deploy) WithSpaceName(spaceName string) *Deploy

func (*Deploy) WithSpacePath

func (d *Deploy) WithSpacePath(spacePath string) *Deploy

func (*Deploy) WithYamlInfo

func (d *Deploy) WithYamlInfo(yamlPath string) *Deploy

func (*Deploy) YamlToK8s

func (d *Deploy) YamlToK8s() error

type DeployParam added in v0.6.4

type DeployParam struct {
	ContainsYaml          bool
	YamlFilePath          string
	BuildImagePath        string
	ModelsSettingFilePath string
}

func DownloadSpaceResources added in v0.6.5

func DownloadSpaceResources(jobUuid string, files []models.SpaceFile) (DeployParam, error)

type DockerService

type DockerService struct {
	// contains filtered or unexported fields
}

func NewDockerService

func NewDockerService() *DockerService

func (*DockerService) BuildImage

func (ds *DockerService) BuildImage(buildPath, imageName string) error

func (*DockerService) CheckRunningContainer added in v0.5.0

func (ds *DockerService) CheckRunningContainer(containerName string) (bool, error)

func (*DockerService) CleanResourceForDocker added in v0.6.4

func (ds *DockerService) CleanResourceForDocker()

func (*DockerService) CleanResourceForK8s added in v0.6.4

func (ds *DockerService) CleanResourceForK8s()

func (*DockerService) ContainerCreateAndStart added in v0.4.6

func (ds *DockerService) ContainerCreateAndStart(config *container.Config, hostConfig *container.HostConfig, containerName string) error

func (*DockerService) ContainerLogs added in v0.4.6

func (ds *DockerService) ContainerLogs(containerName string) (string, error)

func (*DockerService) GetContainerLogStream added in v0.4.8

func (ds *DockerService) GetContainerLogStream(containerName string) (io.ReadCloser, error)

func (*DockerService) IsExistContainer added in v0.6.0

func (ds *DockerService) IsExistContainer(containerName string) bool

func (*DockerService) PullImage added in v0.4.6

func (ds *DockerService) PullImage(imageName string) error

func (*DockerService) PushImage

func (ds *DockerService) PushImage(imagesName string) error

func (*DockerService) RemoveContainerByName added in v0.5.0

func (ds *DockerService) RemoveContainerByName(containerName string) error

func (*DockerService) RemoveImage

func (ds *DockerService) RemoveImage(imageId string) error

func (*DockerService) SaveDockerImage added in v0.6.5

func (ds *DockerService) SaveDockerImage(imageName string) (string, error)

type ErrorLine

type ErrorLine struct {
	Error       string `json:"error"`
	ErrorDetail struct {
		Message string `json:"message"`
	} `json:"errorDetail"`
}

type HardwareField added in v0.6.5

type HardwareField struct {
	TagValue int
	Name     string
	Value    string
}

func GetStructByTag added in v0.6.5

func GetStructByTag(v interface{}) ([]HardwareField, error)

type HardwarePrice added in v0.6.5

type HardwarePrice struct {
	TARGET_CPU          string `toml:"TARGET_CPU" tag:"1"`
	TARGET_MEMORY       string `toml:"TARGET_MEMORY" tag:"2"`
	TARGET_HD_EPHEMERAL string `toml:"TARGET_HD_EPHEMERAL" tag:"3"`
	TARGET_GPU_DEFAULT  string `toml:"TARGET_GPU_DEFAULT" tag:"4"`
	GpusPrice           map[string]string
}

func ReadPriceConfig added in v0.6.5

func ReadPriceConfig() (HardwarePrice, error)

type HttpClient added in v0.6.2

type HttpClient struct {
	// contains filtered or unexported fields
}

func NewHttpClient added in v0.6.2

func NewHttpClient(host string, header http.Header) *HttpClient

func (*HttpClient) Get added in v0.6.2

func (c *HttpClient) Get(api string, queries url.Values, dest any) error

func (*HttpClient) PostForm added in v0.6.2

func (c *HttpClient) PostForm(api string, data url.Values, dest any) error

func (*HttpClient) PostJSON added in v0.6.2

func (c *HttpClient) PostJSON(api string, data any, dest any) error

func (*HttpClient) Request added in v0.6.2

func (c *HttpClient) Request(method string, api string, body io.Reader, dest any, contentType ...string) (err error)

type JobService added in v0.5.0

type JobService struct {
	*gorm.DB
}

func NewJobService added in v0.5.0

func NewJobService() JobService

func (JobService) DeleteJobEntityByJobUuId added in v0.6.5

func (jobServ JobService) DeleteJobEntityByJobUuId(jobUuid string, jobStatus int) error

func (JobService) DeleteJobEntityBySpaceUuId added in v0.5.0

func (jobServ JobService) DeleteJobEntityBySpaceUuId(spaceUuid, jobUuid string, jobStatus int) error

func (JobService) GetJobEntityByJobUuid added in v0.5.0

func (jobServ JobService) GetJobEntityByJobUuid(jobUuid string) (models.JobEntity, error)

func (JobService) GetJobEntityBySpaceUuid added in v0.5.0

func (jobServ JobService) GetJobEntityBySpaceUuid(spaceUuid string) int64

func (JobService) GetJobEntityByTaskUuid added in v0.5.0

func (jobServ JobService) GetJobEntityByTaskUuid(taskUuid string) (models.JobEntity, error)

func (JobService) GetJobList added in v0.5.0

func (jobServ JobService) GetJobList(status int) (list []*models.JobEntity, err error)

func (JobService) GetJobListByNoReward added in v0.6.2

func (jobServ JobService) GetJobListByNoReward() (list []*models.JobEntity, err error)

func (JobService) SaveJobEntity added in v0.5.0

func (jobServ JobService) SaveJobEntity(job *models.JobEntity) (err error)

func (JobService) UpdateJobEntityByJobUuid added in v0.5.0

func (jobServ JobService) UpdateJobEntityByJobUuid(job *models.JobEntity) (err error)

func (JobService) UpdateJobResultUrlByJobUuid added in v0.5.0

func (jobServ JobService) UpdateJobResultUrlByJobUuid(jobUuid string, resultUrl string) (err error)

func (JobService) UpdateJobReward added in v0.6.2

func (jobServ JobService) UpdateJobReward(taskUuid string, amount string) (err error)

func (JobService) UpdateJobScannedBlock added in v0.6.2

func (jobServ JobService) UpdateJobScannedBlock(taskUuid string, end uint64) (err error)

type K8sService

type K8sService struct {
	Version string
	// contains filtered or unexported fields
}

func NewK8sService

func NewK8sService() *K8sService

func (*K8sService) AddNodeLabel

func (s *K8sService) AddNodeLabel(nodeName, key string) error

func (*K8sService) CreateConfigMap

func (s *K8sService) CreateConfigMap(ctx context.Context, k8sNameSpace, jobUuid, basePath, configName string) (*coreV1.ConfigMap, error)

func (*K8sService) CreateDeployment

func (s *K8sService) CreateDeployment(ctx context.Context, nameSpace string, deploy *appV1.Deployment) (result *appV1.Deployment, err error)

func (*K8sService) CreateIngress

func (s *K8sService) CreateIngress(ctx context.Context, k8sNameSpace, spaceUuid, hostName string, port int32) (*networkingv1.Ingress, error)

func (*K8sService) CreateNameSpace

func (s *K8sService) CreateNameSpace(ctx context.Context, nameSpace *coreV1.Namespace, opts metaV1.CreateOptions) (result *coreV1.Namespace, err error)

func (*K8sService) CreateNetworkPolicy

func (s *K8sService) CreateNetworkPolicy(ctx context.Context, namespace string) (*networkingv1.NetworkPolicy, error)

func (*K8sService) CreateService

func (s *K8sService) CreateService(ctx context.Context, nameSpace, spaceUuid string, containerPort int32) (result *coreV1.Service, err error)

func (*K8sService) CreateServiceByNodePort added in v0.4.6

func (s *K8sService) CreateServiceByNodePort(ctx context.Context, nameSpace, taskUuid string, containerPort int32) (result *coreV1.Service, err error)

func (*K8sService) DeleteDeployRs

func (s *K8sService) DeleteDeployRs(ctx context.Context, namespace, jobUuid string) error

func (*K8sService) DeleteDeployment

func (s *K8sService) DeleteDeployment(ctx context.Context, namespace, deploymentName string) error

func (*K8sService) DeleteIngress

func (s *K8sService) DeleteIngress(ctx context.Context, nameSpace, ingressName string) error

func (*K8sService) DeleteNameSpace

func (s *K8sService) DeleteNameSpace(ctx context.Context, nameSpace string) error

func (*K8sService) DeletePod

func (s *K8sService) DeletePod(ctx context.Context, namespace, spaceUuid string) error

func (*K8sService) DeleteService

func (s *K8sService) DeleteService(ctx context.Context, namespace, serviceName string) error

func (*K8sService) GetAPIServerEndpoint

func (s *K8sService) GetAPIServerEndpoint() string

func (*K8sService) GetAllActivePod

func (s *K8sService) GetAllActivePod(ctx context.Context) ([]coreV1.Pod, error)

func (*K8sService) GetClusterRuntime added in v0.6.5

func (s *K8sService) GetClusterRuntime() (string, error)

func (*K8sService) GetDeploymentActiveCount

func (s *K8sService) GetDeploymentActiveCount() (int, error)

func (*K8sService) GetDeploymentImages

func (s *K8sService) GetDeploymentImages(ctx context.Context, namespace, deploymentName string) ([]string, error)

func (*K8sService) GetDeploymentStatus

func (s *K8sService) GetDeploymentStatus(namespace, spaceUuid string) (string, error)

func (*K8sService) GetNameSpace

func (s *K8sService) GetNameSpace(ctx context.Context, nameSpace string, opts metaV1.GetOptions) (result *coreV1.Namespace, err error)

func (*K8sService) GetNodeGpuSummary

func (s *K8sService) GetNodeGpuSummary(ctx context.Context) (map[string]map[string]int64, error)

func (*K8sService) GetPodLogByPodName added in v0.4.5

func (s *K8sService) GetPodLogByPodName(namespace, podName string, podLogOptions *coreV1.PodLogOptions) (string, error)

func (*K8sService) GetPods

func (s *K8sService) GetPods(namespace, jobUuid string) (bool, error)

func (*K8sService) GetResourceExporterPodLog

func (s *K8sService) GetResourceExporterPodLog(ctx context.Context) (map[string]models.CollectNodeInfo, error)

func (*K8sService) GetServiceByName

func (s *K8sService) GetServiceByName(ctx context.Context, namespace, serviceName string, opts metaV1.GetOptions) (result *coreV1.Service, err error)

func (*K8sService) ListNamespace

func (s *K8sService) ListNamespace(ctx context.Context) ([]string, error)

func (*K8sService) ListUsedImage

func (s *K8sService) ListUsedImage(ctx context.Context, nameSpace string) ([]string, error)

func (*K8sService) PodDoCommand

func (s *K8sService) PodDoCommand(namespace, podName, containerName string, podCmd []string) error

func (*K8sService) StatisticalSources

func (s *K8sService) StatisticalSources(ctx context.Context) ([]*models.NodeResource, error)

func (*K8sService) WaitForPodRunningByHttp added in v0.4.6

func (s *K8sService) WaitForPodRunningByHttp(namespace, jobUuid, serviceIp string) (string, error)

func (*K8sService) WaitForPodRunningByTcp added in v0.4.6

func (s *K8sService) WaitForPodRunningByTcp(namespace, taskUuid string) (string, error)

type ResultChecker added in v0.6.2

type ResultChecker interface {
	Check() error
}

type SendProofResp added in v0.6.2

type SendProofResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		BlockHash string `json:"block_hash"`
		Sign      string `json:"sign"`
	} `json:"data"`
}

type SequenceTask added in v0.6.2

type SequenceTask struct {
	Id                 int    `json:"id"`
	Type               int    `json:"type"`
	InputParam         string `json:"input_param"`
	VerifyParam        string `json:"verify_param"`
	ResourceType       int    `json:"resource_type"`
	Deadline           int    `json:"deadline"`
	Proof              string `json:"proof"`
	CheckCode          string `json:"check_code"`
	Reward             string `json:"reward"`
	Status             string `json:"status"`
	SequenceCid        string `json:"sequence_cid"`
	SettlementCid      string `json:"settlement_cid"`
	SequenceTaskAddr   string `json:"sequence_task_addr"`
	SettlementTaskAddr string `json:"settlement_task_addr"`
}

type Sequencer added in v0.6.2

type Sequencer struct {
	// contains filtered or unexported fields
}

func NewSequencer added in v0.6.2

func NewSequencer() *Sequencer

func (*Sequencer) GetToken added in v0.6.2

func (s *Sequencer) GetToken() error

func (*Sequencer) QueryTask added in v0.6.2

func (s *Sequencer) QueryTask(taskType int, taskIds ...int64) (TaskListResp, error)

func (*Sequencer) SendTaskProof added in v0.6.2

func (s *Sequencer) SendTaskProof(data []byte) (SendProofResp, error)

type StorageService

type StorageService struct {
	McsApiKey      string `json:"mcs_api_key"`
	McsAccessToken string `json:"mcs_access_token"`
	NetWork        string `json:"net_work"`
	BucketName     string `json:"bucket_name"`
	// contains filtered or unexported fields
}

func NewStorageService

func NewStorageService() (*StorageService, error)

func (*StorageService) CreateBucket

func (storage *StorageService) CreateBucket(bucketName string)

func (*StorageService) CreateFolder

func (storage *StorageService) CreateFolder(folderName string)

func (*StorageService) DeleteBucket

func (storage *StorageService) DeleteBucket(bucketName string) error

func (*StorageService) GetGatewayUrl

func (storage *StorageService) GetGatewayUrl() (*string, error)

func (*StorageService) UploadFileToBucket

func (storage *StorageService) UploadFileToBucket(objectName, filePath string, replace bool) (*bucket.OssFile, error)

type TaskGroup added in v0.6.2

type TaskGroup struct {
	Items []*models.TaskEntity
	Ids   []int64
	Type  int // 1: contract  2: sequncer
}

type TaskListResp added in v0.6.2

type TaskListResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Total int            `json:"total"`
		List  []SequenceTask `json:"list"`
	} `json:"data"`
}

type TaskManagerContract added in v0.6.2

type TaskManagerContract struct {
	// contains filtered or unexported fields
}

func NewTaskManagerContract added in v0.6.2

func NewTaskManagerContract(job *models.JobEntity) *TaskManagerContract

func (*TaskManagerContract) Scan added in v0.6.2

func (taskManager *TaskManagerContract) Scan()

func (*TaskManagerContract) ScannedBlock added in v0.6.2

func (taskManager *TaskManagerContract) ScannedBlock(job *models.JobEntity) uint64

type TaskService added in v0.5.0

type TaskService struct {
	*gorm.DB
}

func NewTaskService added in v0.5.0

func NewTaskService() TaskService

func (TaskService) GetTaskEntity added in v0.5.0

func (taskServ TaskService) GetTaskEntity(taskId int64) (*models.TaskEntity, error)

func (TaskService) GetTaskList added in v0.5.0

func (taskServ TaskService) GetTaskList(tailNum int, taskStatus ...int) (list []*models.TaskEntity, err error)

func (TaskService) GetTaskListNoReward added in v0.5.0

func (taskServ TaskService) GetTaskListNoReward() (list []*models.TaskEntity, err error)

func (TaskService) SaveTaskEntity added in v0.5.0

func (taskServ TaskService) SaveTaskEntity(task *models.TaskEntity) (err error)

func (TaskService) UpdateTaskEntityByTaskId added in v0.6.2

func (taskServ TaskService) UpdateTaskEntityByTaskId(task *models.TaskEntity) (err error)

type TokenResp added in v0.6.2

type TokenResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Token string `json:"token"`
	} `json:"data"`
}

type WsClient

type WsClient struct {
	// contains filtered or unexported fields
}

func NewWsClient

func NewWsClient(client *websocket.Conn) *WsClient

func (*WsClient) Close

func (ws *WsClient) Close()

func (*WsClient) HandleLogs

func (ws *WsClient) HandleLogs(reader io.Reader)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL