dao

package
v0.0.0-...-1782032 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DBClient    Interface
	JwtMgr      *helper.JWTManager
	Cfg         *Config
	BillingTask *helper.TaskQueue
	Debug       bool
)

Functions

func Init

func Init(ctx context.Context) error

Types

type Account

type Account struct {
	*MongoDB
	*Cockroach
}

func (*Account) ActiveBilling

func (m *Account) ActiveBilling(req resources.ActiveBilling) error

func (*Account) ApplyInvoice

func (m *Account) ApplyInvoice(req *helper.ApplyInvoiceReq) (invoice types.Invoice, payments []types.Payment, err error)

func (*Account) ArchiveHourlyBilling

func (m *Account) ArchiveHourlyBilling(hourStart, hourEnd time.Time) error

func (*Account) ChargeBilling

func (m *Account) ChargeBilling(req *helper.AdminChargeBillingReq) error

func (*Account) Disconnect

func (m *Account) Disconnect(ctx context.Context) error

func (*Account) GetBillingHistoryNamespaceList

func (m *Account) GetBillingHistoryNamespaceList(req *helper.NamespaceBillingHistoryReq) ([][]string, error)

func (*Account) GetInvoice

func (m *Account) GetInvoice(req *helper.GetInvoiceReq) ([]types.Invoice, types.LimitResp, error)

func (*Account) GetInvoicePayments

func (m *Account) GetInvoicePayments(invoiceID string) ([]types.Payment, error)

func (*Account) GetRechargeDiscount

func (m *Account) GetRechargeDiscount(req helper.AuthReq) (helper.RechargeDiscountResp, error)

func (*Account) GetUserRealNameInfo

func (m *Account) GetUserRealNameInfo(req *helper.GetRealNameInfoReq) (*types.UserRealNameInfo, error)

func (*Account) InitDB

func (m *Account) InitDB() error

func (*Account) ProcessPendingTaskRewards

func (m *Account) ProcessPendingTaskRewards() error

func (*Account) ReconcileActiveBilling

func (m *Account) ReconcileActiveBilling(startTime, endTime time.Time) error

func (*Account) ReconcileUnsettledLLMBilling

func (m *Account) ReconcileUnsettledLLMBilling(startTime, endTime time.Time) error

func (*Account) SetStatusInvoice

func (m *Account) SetStatusInvoice(req *helper.SetInvoiceStatusReq) error

func (*Account) UseGiftCode

func (m *Account) UseGiftCode(req *helper.UseGiftCodeReq) (*types.GiftCode, error)

type ActiveBillingReconcile

type ActiveBillingReconcile struct {
	StartTime, EndTime time.Time
}

func (*ActiveBillingReconcile) Execute

func (a *ActiveBillingReconcile) Execute() error

type ActiveBillingReq

type ActiveBillingReq struct {
	resources.ActiveBilling
}

func ParseAdminActiveBillingReq

func ParseAdminActiveBillingReq(c *gin.Context) (*ActiveBillingReq, error)

func (*ActiveBillingReq) Execute

func (a *ActiveBillingReq) Execute() error

type ArchiveBillingReconcile

type ArchiveBillingReconcile struct {
	StartTime time.Time
}

func (*ArchiveBillingReconcile) Execute

func (a *ArchiveBillingReconcile) Execute() error

type Cockroach

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

func (*Cockroach) GetAccount

func (g *Cockroach) GetAccount(ops types.UserQueryOpts) (*types.Account, error)

func (*Cockroach) GetAccountWithWorkspace

func (g *Cockroach) GetAccountWithWorkspace(workspace string) (*types.Account, error)

func (*Cockroach) GetLocalRegion

func (g *Cockroach) GetLocalRegion() types.Region

func (*Cockroach) GetPayment

func (*Cockroach) GetRechargeAmount

func (g *Cockroach) GetRechargeAmount(ops types.UserQueryOpts, startTime, endTime time.Time) (int64, error)

func (*Cockroach) GetRegions

func (g *Cockroach) GetRegions() ([]types.Region, error)

func (*Cockroach) GetTransfer

func (g *Cockroach) GetTransfer(ops *types.GetTransfersReq) (*types.GetTransfersResp, error)

func (*Cockroach) GetUserCrName

func (g *Cockroach) GetUserCrName(ops types.UserQueryOpts) (string, error)

func (*Cockroach) GetUserID

func (g *Cockroach) GetUserID(ops types.UserQueryOpts) (string, error)

func (*Cockroach) GetWorkspaceName

func (g *Cockroach) GetWorkspaceName(namespaces []string) ([][]string, error)

func (*Cockroach) SetPaymentInvoice

func (g *Cockroach) SetPaymentInvoice(req *helper.SetPaymentInvoiceReq) error

func (*Cockroach) Transfer

func (g *Cockroach) Transfer(req *helper.TransferAmountReq) error

type Config

type Config struct {
	LocalRegionDomain string   `json:"localRegionDomain"`
	Regions           []Region `json:"regions"`
	InvoiceToken      string   `json:"invoiceToken"`
}

type Interface

type Interface interface {
	GetBillingHistoryNamespaceList(req *helper.NamespaceBillingHistoryReq) ([][]string, error)
	GetAccountWithWorkspace(workspace string) (*types.Account, error)
	GetProperties() ([]common.PropertyQuery, error)
	GetCosts(req helper.ConsumptionRecordReq) (common.TimeCostsMap, error)
	GetAppCosts(req *helper.AppCostsReq) (*common.AppCosts, error)
	ChargeBilling(req *helper.AdminChargeBillingReq) error
	GetAppCostTimeRange(req helper.GetCostAppListReq) (helper.TimeRange, error)
	GetCostOverview(req helper.GetCostAppListReq) (helper.CostOverviewResp, error)
	GetBasicCostDistribution(req helper.GetCostAppListReq) (map[string]int64, error)
	GetCostAppList(req helper.GetCostAppListReq) (helper.CostAppListResp, error)
	Disconnect(ctx context.Context) error
	GetConsumptionAmount(req helper.ConsumptionRecordReq) (int64, error)
	GetRechargeAmount(ops types.UserQueryOpts, startTime, endTime time.Time) (int64, error)
	GetPropertiesUsedAmount(user string, startTime, endTime time.Time) (map[string]int64, error)
	GetAccount(ops types.UserQueryOpts) (*types.Account, error)
	GetPayment(ops *types.UserQueryOpts, req *helper.GetPaymentReq) ([]types.Payment, types.LimitResp, error)
	GetMonitorUniqueValues(startTime, endTime time.Time, namespaces []string) ([]common.Monitor, error)
	ApplyInvoice(req *helper.ApplyInvoiceReq) (invoice types.Invoice, payments []types.Payment, err error)
	GetInvoice(req *helper.GetInvoiceReq) ([]types.Invoice, types.LimitResp, error)
	GetInvoicePayments(invoiceID string) ([]types.Payment, error)
	SetStatusInvoice(req *helper.SetInvoiceStatusReq) error
	GetWorkspaceName(namespaces []string) ([][]string, error)
	SetPaymentInvoice(req *helper.SetPaymentInvoiceReq) error
	Transfer(req *helper.TransferAmountReq) error
	GetTransfer(ops *types.GetTransfersReq) (*types.GetTransfersResp, error)
	GetUserID(ops types.UserQueryOpts) (string, error)
	GetUserCrName(ops types.UserQueryOpts) (string, error)
	GetRegions() ([]types.Region, error)
	GetLocalRegion() types.Region
	UseGiftCode(req *helper.UseGiftCodeReq) (*types.GiftCode, error)
	GetRechargeDiscount(req helper.AuthReq) (helper.RechargeDiscountResp, error)
	ProcessPendingTaskRewards() error
	GetUserRealNameInfo(req *helper.GetRealNameInfoReq) (*types.UserRealNameInfo, error)
	ReconcileUnsettledLLMBilling(startTime, endTime time.Time) error
	ReconcileActiveBilling(startTime, endTime time.Time) error
	ArchiveHourlyBilling(hourStart, hourEnd time.Time) error
	ActiveBilling(req resources.ActiveBilling) error
}

func NewAccountInterface

func NewAccountInterface(mongoURI, globalCockRoachURI, localCockRoachURI string) (Interface, error)

type MongoDB

type MongoDB struct {
	Client            *mongo.Client
	AccountDBName     string
	BillingConn       string
	ActiveBillingConn string
	PropertiesConn    string
	Properties        *resources.PropertyTypeLS
}

func (*MongoDB) GetAppCostTimeRange

func (m *MongoDB) GetAppCostTimeRange(req helper.GetCostAppListReq) (helper.TimeRange, error)

func (*MongoDB) GetAppCosts

func (m *MongoDB) GetAppCosts(req *helper.AppCostsReq) (results *common.AppCosts, rErr error)

func (*MongoDB) GetAppCostsByOrderIDAndAppName

func (m *MongoDB) GetAppCostsByOrderIDAndAppName(req *helper.AppCostsReq) ([]common.AppCost, error)

func (*MongoDB) GetBasicCostDistribution

func (m *MongoDB) GetBasicCostDistribution(req helper.GetCostAppListReq) (map[string]int64, error)

GetBasicCostDistribution cost: map[string]int64: key: property type (cpu,memory,storage,network,nodeport: 0,1,2,3,4), value: used amount

func (*MongoDB) GetConsumptionAmount

func (m *MongoDB) GetConsumptionAmount(req helper.ConsumptionRecordReq) (int64, error)

func (*MongoDB) GetCostAppList

func (m *MongoDB) GetCostAppList(req helper.GetCostAppListReq) (resp helper.CostAppListResp, rErr error)

func (*MongoDB) GetCostOverview

func (m *MongoDB) GetCostOverview(req helper.GetCostAppListReq) (resp helper.CostOverviewResp, rErr error)

func (*MongoDB) GetCosts

func (*MongoDB) GetMonitorUniqueValues

func (m *MongoDB) GetMonitorUniqueValues(startTime, endTime time.Time, namespaces []string) ([]common.Monitor, error)

func (*MongoDB) GetProperties

func (m *MongoDB) GetProperties() ([]common.PropertyQuery, error)

func (*MongoDB) GetPropertiesUsedAmount

func (m *MongoDB) GetPropertiesUsedAmount(user string, startTime, endTime time.Time) (map[string]int64, error)

func (*MongoDB) SaveActiveBillings

func (m *MongoDB) SaveActiveBillings(billing ...*resources.ActiveBilling) error

func (*MongoDB) SaveBillings

func (m *MongoDB) SaveBillings(billing ...*resources.Billing) error

func (*MongoDB) UpdateBillingStatus

func (m *MongoDB) UpdateBillingStatus(orderID string, status resources.BillingStatus) error

type Region

type Region struct {
	Domain     string `json:"domain"`
	AccountSvc string `json:"accountSvc"`
	UID        string `json:"uid"`
	// zh: region name, en: region name
	Name map[string]string `json:"name"`
}

Jump to

Keyboard shortcuts

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