biz

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 23 Imported by: 0

README

Biz

Documentation

Index

Constants

View Source
const (
	InstanceStatusStarting int8 = iota
	InstanceStatusRunning
	InstanceStatusTerminal
	InstanceStatusExpire
)

Variables

View Source
var (
	// ErrUserNotFound is user not found.
	ErrUserNotFound = errors.NotFound(v1.ErrorReason_USER_NOT_FOUND.String(), "user not found")
)

ProviderSet is biz providers.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	ID             uuid.UUID
	PeerId         string
	Active         bool
	LastUpdateTime time.Time
}

type AgentRepo

type AgentRepo interface {
	//db
	ListAgent(ctx context.Context) ([]*Agent, error)
	GetAgent(ctx context.Context, id uuid.UUID) (*Agent, error)
	CreateAgent(ctx context.Context, agent *Agent) error
	UpdateAgent(ctx context.Context, id uuid.UUID, agent *Agent) error
	DeleteAgent(ctx context.Context, id uuid.UUID) error
	FindByPeerId(ctx context.Context, peerId string) (*Agent, error)
	FindOneActiveAgent(ctx context.Context, cpu string, memory string) (*Agent, error)
}

type AgentUsecase

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

func NewAgentUsecase

func NewAgentUsecase(repo AgentRepo, logger log.Logger) *AgentUsecase

func (*AgentUsecase) Create

func (uc *AgentUsecase) Create(ctx context.Context, agent *Agent) error

func (*AgentUsecase) Delete

func (uc *AgentUsecase) Delete(ctx context.Context, id uuid.UUID) error

func (*AgentUsecase) FindOneActiveAgent added in v0.0.2

func (uc *AgentUsecase) FindOneActiveAgent(ctx context.Context, cpu string, memory string) (*Agent, error)

func (*AgentUsecase) Get

func (uc *AgentUsecase) Get(ctx context.Context, id uuid.UUID) (p *Agent, err error)

func (*AgentUsecase) List

func (uc *AgentUsecase) List(ctx context.Context) (ps []*Agent, err error)

func (*AgentUsecase) Update

func (uc *AgentUsecase) Update(ctx context.Context, id uuid.UUID, agent *Agent) error

type ComputeImage

type ComputeImage struct {
	// ID of the ent.
	ID int32 `json:"id,omitempty"`
	// 显示名
	Name string `json:"name,omitempty"`
	// 镜像名
	Image string `json:"image,omitempty"`
	// 版本名
	Tag string `json:"tag,omitempty"`
	// 端口号
	Port    int32 `json:"port,omitempty"`
	Command string
}

type ComputeImageRepo

type ComputeImageRepo interface {
	List(ctx context.Context) ([]*ComputeImage, error)
	Get(ctx context.Context, id int32) (*ComputeImage, error)
}

type ComputeInstance

type ComputeInstance struct {
	// ID of the ent.
	ID uuid.UUID `json:"id,omitempty"`
	// Owner holds the value of the "owner" field.
	Owner string `json:"owner,omitempty"`
	// Name holds the value of the "name" field.
	Name string `json:"name,omitempty"`
	// Core holds the value of the "core" field.
	Core string `json:"core,omitempty"`
	// Memory holds the value of the "memory" field.
	Memory string `json:"memory,omitempty"`
	// Image holds the value of the "image" field.
	Image string `json:"image,omitempty"`
	Port  string `json:"port,omitempty"`
	// ExpirationTime holds the value of the "expiration_time" field.
	ExpirationTime time.Time `json:"expiration_time,omitempty"`
	// 0: 启动中,1:运行中,2:连接中断, 3:过期
	Status int8 `json:"status,omitempty"`
	// 容器id
	ContainerID string `json:"container_id,omitempty"`
	// p2p agent Id
	PeerID  string                `json:"peer_id,omitempty"`
	Command string                `json:"command,omitempty"`
	Stats   []*ComputeInstanceRds `json:"stats"`
}

type ComputeInstanceCreate

type ComputeInstanceCreate struct {
	SpecId   int32
	ImageId  int32
	Duration int32
	Name     string
}

type ComputeInstanceRds added in v0.0.3

type ComputeInstanceRds struct {
	ID          string    `json:"id"`
	CpuUsage    uint64    `json:"cpuUsage"`
	MemoryUsage uint64    `json:"memoryUsage"`
	StatsTime   time.Time `json:"statsTime"`
}

func (*ComputeInstanceRds) MarshalBinary added in v0.0.3

func (m *ComputeInstanceRds) MarshalBinary() (data []byte, err error)

func (*ComputeInstanceRds) UnmarshalBinary added in v0.0.3

func (m *ComputeInstanceRds) UnmarshalBinary(data []byte) error

type ComputeInstanceRepo

type ComputeInstanceRepo interface {
	List(ctx context.Context, owner string) ([]*ComputeInstance, error)
	ListAll(ctx context.Context) ([]*ComputeInstance, error)
	Create(ctx context.Context, instance *ComputeInstance) error
	Delete(ctx context.Context, id uuid.UUID) error
	Update(ctx context.Context, id uuid.UUID, instance *ComputeInstance) error
	Get(ctx context.Context, id uuid.UUID) (*ComputeInstance, error)
	SaveInstanceStats(ctx context.Context, id uuid.UUID, rdbInstance *ComputeInstanceRds) error
	GetInstanceStats(ctx context.Context, id uuid.UUID) ([]*ComputeInstanceRds, error)
}

type ComputeInstanceUsercase

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

func NewComputeInstanceUsercase

func NewComputeInstanceUsercase(
	specRepo ComputeSpecRepo,
	instanceRepo ComputeInstanceRepo,
	imageRepo ComputeImageRepo,
	agentRepo AgentRepo,
	p2pClient *goipfsp2p.P2pClient,
	logger log.Logger) *ComputeInstanceUsercase

func (*ComputeInstanceUsercase) Create

func (*ComputeInstanceUsercase) CreateInstanceOnAgent added in v0.0.2

func (uc *ComputeInstanceUsercase) CreateInstanceOnAgent(peerId string, instance *ComputeInstance)

func (*ComputeInstanceUsercase) Delete

func (uc *ComputeInstanceUsercase) Delete(ctx context.Context, id uuid.UUID) error

func (*ComputeInstanceUsercase) Get added in v0.0.3

func (*ComputeInstanceUsercase) ListComputeImage

func (uc *ComputeInstanceUsercase) ListComputeImage(ctx context.Context) ([]*ComputeImage, error)

func (*ComputeInstanceUsercase) ListComputeInstance added in v0.0.3

func (uc *ComputeInstanceUsercase) ListComputeInstance(ctx context.Context, owner string) ([]*ComputeInstance, error)

func (*ComputeInstanceUsercase) ListComputeSpec

func (uc *ComputeInstanceUsercase) ListComputeSpec(ctx context.Context) ([]*ComputeSpec, error)

func (*ComputeInstanceUsercase) Start added in v0.0.3

func (*ComputeInstanceUsercase) Stop added in v0.0.3

func (*ComputeInstanceUsercase) SyncContainerStats added in v0.0.3

func (uc *ComputeInstanceUsercase) SyncContainerStats()

func (*ComputeInstanceUsercase) Terminal added in v0.0.3

type ComputeSpec

type ComputeSpec struct {
	// ID of the ent.
	ID int32 `json:"id,omitempty"`
	// Core holds the value of the "core" field.
	Core string `json:"core,omitempty"`
	// Memory holds the value of the "memory" field.
	Memory string `json:"memory,omitempty"`
}

type ComputeSpecRepo

type ComputeSpecRepo interface {
	List(ctx context.Context) ([]*ComputeSpec, error)
	Get(ctx context.Context, id int32) (*ComputeSpec, error)
}

type Greeter

type Greeter struct {
	Hello string
}

Greeter is a Greeter model.

type GreeterRepo

type GreeterRepo interface {
	Save(context.Context, *Greeter) (*Greeter, error)
	Update(context.Context, *Greeter) (*Greeter, error)
	FindByID(context.Context, int64) (*Greeter, error)
	ListByHello(context.Context, string) ([]*Greeter, error)
	ListAll(context.Context) ([]*Greeter, error)
}

GreeterRepo is a Greater repo.

type GreeterUsecase

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

GreeterUsecase is a Greeter usecase.

func NewGreeterUsecase

func NewGreeterUsecase(repo GreeterRepo, logger log.Logger) *GreeterUsecase

NewGreeterUsecase new a Greeter usecase.

func (*GreeterUsecase) CreateGreeter

func (uc *GreeterUsecase) CreateGreeter(ctx context.Context, g *Greeter) (*Greeter, error)

CreateGreeter creates a Greeter, and returns the new Greeter.

type Script added in v0.0.3

type Script struct {
	ID            int32     `json:"id,omitempty"`
	UserId        string    `json:"userId,omitempty"`
	TaskNumber    int32     `json:"taskNumber,omitempty"`
	ScriptName    string    `json:"scriptName,omitempty"`
	FileAddress   string    `json:"fileAddress,omitempty"`
	ScriptContent string    `json:"scriptContent,omitempty"`
	CreateTime    time.Time `json:"createTime,omitempty"`
	UpdateTime    time.Time `json:"updateTime,omitempty"`
}

Script is a Script model.

type ScriptExecutionRecord added in v0.0.3

type ScriptExecutionRecord struct {
	ID            int32     `json:"id,omitempty"`
	UserID        string    `json:"user_id,omitempty"`
	FkScriptID    int32     `json:"fk_script_id,omitempty"`
	TaskNumber    int32     `json:"taskNumber,omitempty"`
	ScriptContent string    `json:"fk_script_content,omitempty"`
	ScriptName    string    `json:"scriptName,omitempty"`
	FileAddress   string    `json:"fileAddress,omitempty"`
	ExecuteState  int32     `json:"execute_state,omitempty"`
	ExecuteResult string    `json:"execute_result,omitempty"`
	CreateTime    time.Time `json:"create_time,omitempty"`
	UpdateTime    time.Time `json:"update_time,omitempty"`
}

ScriptExecutionRecord is a ScriptExecutionRecord model.

type ScriptExecutionRecordRepo added in v0.0.3

ScriptExecutionRecordRepo is a ScriptExecutionRecord repo.

type ScriptRepo added in v0.0.3

type ScriptRepo interface {
	Save(context.Context, *Script) (*Script, error)
	Update(context.Context, *Script) (*Script, error)
	FindByID(context.Context, int32) (*Script, error)
	PageByUserID(context.Context, string, int32, int32) ([]*Script, int32, error)
}

ScriptRepo is a Script repo.

type ScriptUseCase added in v0.0.3

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

ScriptUseCase is a Script UseCase.

func NewScriptUseCase added in v0.0.3

func NewScriptUseCase(repo ScriptRepo, scriptExecutionRecordRepo ScriptExecutionRecordRepo, agentRepo AgentRepo, p2pClient *goipfsp2p.P2pClient, logger log.Logger) *ScriptUseCase

NewScriptUseCase new a Script UseCase.

func (*ScriptUseCase) CancelExecPythonPackage added in v0.0.3

func (uc *ScriptUseCase) CancelExecPythonPackage(ctx context.Context, scriptId int32) (*ScriptExecutionRecord, error)

func (*ScriptUseCase) CreateScript added in v0.0.3

func (uc *ScriptUseCase) CreateScript(ctx context.Context, s *Script) (*Script, error)

CreateScript creates a Script, and returns the new Script.

func (*ScriptUseCase) GetScriptExecutionRecordInfo added in v0.0.5

func (uc *ScriptUseCase) GetScriptExecutionRecordInfo(ctx context.Context, id int32) (*ScriptExecutionRecord, error)

func (*ScriptUseCase) GetScriptExecutionRecordPage added in v0.0.5

func (uc *ScriptUseCase) GetScriptExecutionRecordPage(ctx context.Context, userId string, page, size int32) ([]*ScriptExecutionRecord, int32, error)

func (*ScriptUseCase) RunPythonPackage added in v0.0.3

func (uc *ScriptUseCase) RunPythonPackage(ctx context.Context, id int32, userId string) (*ScriptExecutionRecord, error)

func (*ScriptUseCase) RunPythonPackageOnAgent added in v0.0.5

func (uc *ScriptUseCase) RunPythonPackageOnAgent(peerId string, record *ScriptExecutionRecord)

type Storage

type Storage struct {
	ID uuid.UUID `json:"id,omitempty"`
	// Owner holds the value of the "owner" field.
	Owner string `json:"owner,omitempty"`
	// 0: DIR, 1:file
	Type int32 `json:"type,omitempty"`
	// Name holds the value of the "name" field.
	Name string `json:"name,omitempty"`
	// Cid holds the value of the "cid" field.
	Cid string `json:"cid,omitempty"`
	// size
	Size int32 `json:"size,omitempty"`
	// LastModify holds the value of the "last_modify" field.
	LastModify time.Time `json:"last_modify,omitempty"`

	// ParentID holds the value of the "parent_id" field.
	ParentID string `json:"parent_id,omitempty"`
}

type StorageRepo

type StorageRepo interface {
	ListStorage(ctx context.Context, owner string, parentId string) ([]*Storage, error)
	GetStorage(ctx context.Context, id uuid.UUID) (*Storage, error)
	CreateStorage(ctx context.Context, storage *Storage) error
	UpdateStorage(ctx context.Context, id uuid.UUID, storage *Storage) error
	DeleteStorage(ctx context.Context, id uuid.UUID) error
}

type Storagecase

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

func NewStorageUsecase

func NewStorageUsecase(repo StorageRepo, logger log.Logger) *Storagecase

func (*Storagecase) Create

func (uc *Storagecase) Create(ctx context.Context, storage *Storage) error

func (*Storagecase) Delete

func (uc *Storagecase) Delete(ctx context.Context, id uuid.UUID) error

func (*Storagecase) Get

func (uc *Storagecase) Get(ctx context.Context, id uuid.UUID) (p *Storage, err error)

func (*Storagecase) List

func (uc *Storagecase) List(ctx context.Context, owner string, parentId string) (ps []*Storage, err error)

func (*Storagecase) Update

func (uc *Storagecase) Update(ctx context.Context, id uuid.UUID, storage *Storage) error

type User

type User struct {
	ID uuid.UUID `json:"id,omitempty"`
	// CountryCallCoding holds the value of the "country_call_coding" field.
	CountryCallCoding string `json:"country_call_coding,omitempty"`
	// TelephoneNumber holds the value of the "telephone_number" field.
	TelephoneNumber string `json:"telephone_number,omitempty"`
	// Password holds the value of the "password" field.
	Password string `json:"password,omitempty"`
	// CreateDate holds the value of the "create_date" field.
	CreateDate time.Time `json:"create_date,omitempty"`
	// LastLoginDate holds the value of the "last_login_date" field.
	LastLoginDate time.Time `json:"last_login_date,omitempty"`
	ValidateCode  string    `json:"validate_code"`
	// 用户名
	Name string `json:"name,omitempty"`
	// 头像地址
	Icon string `json:"icon,omitempty"`
	//是否配置过密码
	PwdConfig bool
}

func (*User) GetFullTelephone

func (u *User) GetFullTelephone() string

type UserRepo

type UserRepo interface {
	ListUser(ctx context.Context, entity User) ([]*User, error)
	GetUser(ctx context.Context, id uuid.UUID) (*User, error)
	CreateUser(ctx context.Context, user *User) error
	UpdateUser(ctx context.Context, id uuid.UUID, user *User) error
	UpdateUserTelephone(ctx context.Context, id uuid.UUID, user *User) error
	UpdateUserPassword(ctx context.Context, id uuid.UUID, user *User) error
	DeleteUser(ctx context.Context, id uuid.UUID) error
	SendValidateCode(ctx context.Context, entity User) error
	GetValidateCode(ctx context.Context, user User) (string, error)
	DeleteValidateCode(ctx context.Context, user User)
	FindUserByFullTelephone(ctx context.Context, countryCallCoding string, telephone string) (*User, error)
}

type UserUsercase

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

func NewUserUsecase

func NewUserUsecase(conf *conf.Auth, repo UserRepo, logger log.Logger) *UserUsercase

func (*UserUsercase) Create

func (uc *UserUsercase) Create(ctx context.Context, user *User) error

func (*UserUsercase) Delete

func (uc *UserUsercase) Delete(ctx context.Context, id uuid.UUID) error

func (*UserUsercase) Get

func (uc *UserUsercase) Get(ctx context.Context, id uuid.UUID) (p *User, err error)

func (*UserUsercase) GetValidateCode

func (uc *UserUsercase) GetValidateCode(ctx context.Context, user User) (string, error)

func (*UserUsercase) List

func (uc *UserUsercase) List(ctx context.Context, entity User) (ps []*User, err error)

func (*UserUsercase) Login

func (uc *UserUsercase) Login(ctx context.Context, user *User) (string, error)

func (*UserUsercase) LoginWithValidateCode

func (uc *UserUsercase) LoginWithValidateCode(ctx context.Context, user *User) (string, error)

func (*UserUsercase) SendValidateCode

func (uc *UserUsercase) SendValidateCode(ctx context.Context, entity User) error

func (*UserUsercase) Update

func (uc *UserUsercase) Update(ctx context.Context, id uuid.UUID, user *User) error

func (*UserUsercase) UpdateUserPassword added in v0.0.3

func (uc *UserUsercase) UpdateUserPassword(ctx context.Context, id uuid.UUID, oldPassword, newPassword string) error

func (*UserUsercase) UpdateUserTelephone added in v0.0.3

func (uc *UserUsercase) UpdateUserTelephone(ctx context.Context, id uuid.UUID, user *User) error

Jump to

Keyboard shortcuts

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