mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-22 22:40:29 +08:00
对服务增加基础的数据统计/部分代码分Package
This commit is contained in:
@@ -2,7 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/acme"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
@@ -24,7 +24,7 @@ func (this *ACMEAuthenticationService) FindACMEAuthenticationKeyWithToken(ctx co
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
auth, err := models.SharedACMEAuthenticationDAO.FindAuthWithToken(tx, req.Token)
|
||||
auth, err := acme.SharedACMEAuthenticationDAO.FindAuthWithToken(tx, req.Token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/acme"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
acmemodels "github.com/TeaOSLab/EdgeAPI/internal/db/models/acme"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
@@ -24,7 +26,7 @@ func (this *ACMETaskService) CountAllEnabledACMETasksWithACMEUserId(ctx context.
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
count, err := models.SharedACMETaskDAO.CountACMETasksWithACMEUserId(tx, req.AcmeUserId)
|
||||
count, err := acmemodels.SharedACMETaskDAO.CountACMETasksWithACMEUserId(tx, req.AcmeUserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -42,7 +44,7 @@ func (this *ACMETaskService) CountEnabledACMETasksWithDNSProviderId(ctx context.
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
count, err := models.SharedACMETaskDAO.CountACMETasksWithDNSProviderId(tx, req.DnsProviderId)
|
||||
count, err := acmemodels.SharedACMETaskDAO.CountACMETasksWithDNSProviderId(tx, req.DnsProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -58,7 +60,7 @@ func (this *ACMETaskService) CountAllEnabledACMETasks(ctx context.Context, req *
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
count, err := models.SharedACMETaskDAO.CountAllEnabledACMETasks(tx, req.AdminId, req.UserId)
|
||||
count, err := acmemodels.SharedACMETaskDAO.CountAllEnabledACMETasks(tx, req.AdminId, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -74,7 +76,7 @@ func (this *ACMETaskService) ListEnabledACMETasks(ctx context.Context, req *pb.L
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
tasks, err := models.SharedACMETaskDAO.ListEnabledACMETasks(tx, req.AdminId, req.UserId, req.Offset, req.Size)
|
||||
tasks, err := acmemodels.SharedACMETaskDAO.ListEnabledACMETasks(tx, req.AdminId, req.UserId, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -82,7 +84,7 @@ func (this *ACMETaskService) ListEnabledACMETasks(ctx context.Context, req *pb.L
|
||||
result := []*pb.ACMETask{}
|
||||
for _, task := range tasks {
|
||||
// ACME用户
|
||||
acmeUser, err := models.SharedACMEUserDAO.FindEnabledACMEUser(tx, int64(task.AcmeUserId))
|
||||
acmeUser, err := acmemodels.SharedACMEUserDAO.FindEnabledACMEUser(tx, int64(task.AcmeUserId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -99,7 +101,7 @@ func (this *ACMETaskService) ListEnabledACMETasks(ctx context.Context, req *pb.L
|
||||
var pbProvider *pb.DNSProvider
|
||||
if task.AuthType == acme.AuthTypeDNS {
|
||||
// DNS
|
||||
provider, err := models.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, int64(task.DnsProviderId))
|
||||
provider, err := dns.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, int64(task.DnsProviderId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -135,7 +137,7 @@ func (this *ACMETaskService) ListEnabledACMETasks(ctx context.Context, req *pb.L
|
||||
|
||||
// 最近一条日志
|
||||
var pbTaskLog *pb.ACMETaskLog = nil
|
||||
taskLog, err := models.SharedACMETaskLogDAO.FindLatestACMETasKLog(tx, int64(task.Id))
|
||||
taskLog, err := acmemodels.SharedACMETaskLogDAO.FindLatestACMETasKLog(tx, int64(task.Id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -178,7 +180,7 @@ func (this *ACMETaskService) CreateACMETask(ctx context.Context, req *pb.CreateA
|
||||
}
|
||||
|
||||
tx := this.NullTx()
|
||||
taskId, err := models.SharedACMETaskDAO.CreateACMETask(tx, adminId, userId, req.AuthType, req.AcmeUserId, req.DnsProviderId, req.DnsDomain, req.Domains, req.AutoRenew)
|
||||
taskId, err := acmemodels.SharedACMETaskDAO.CreateACMETask(tx, adminId, userId, req.AuthType, req.AcmeUserId, req.DnsProviderId, req.DnsDomain, req.Domains, req.AutoRenew)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -194,7 +196,7 @@ func (this *ACMETaskService) UpdateACMETask(ctx context.Context, req *pb.UpdateA
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
canAccess, err := models.SharedACMETaskDAO.CheckACMETask(tx, adminId, userId, req.AcmeTaskId)
|
||||
canAccess, err := acmemodels.SharedACMETaskDAO.CheckACMETask(tx, adminId, userId, req.AcmeTaskId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -202,7 +204,7 @@ func (this *ACMETaskService) UpdateACMETask(ctx context.Context, req *pb.UpdateA
|
||||
return nil, this.PermissionError()
|
||||
}
|
||||
|
||||
err = models.SharedACMETaskDAO.UpdateACMETask(tx, req.AcmeTaskId, req.AcmeUserId, req.DnsProviderId, req.DnsDomain, req.Domains, req.AutoRenew)
|
||||
err = acmemodels.SharedACMETaskDAO.UpdateACMETask(tx, req.AcmeTaskId, req.AcmeUserId, req.DnsProviderId, req.DnsDomain, req.Domains, req.AutoRenew)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -218,7 +220,7 @@ func (this *ACMETaskService) DeleteACMETask(ctx context.Context, req *pb.DeleteA
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
canAccess, err := models.SharedACMETaskDAO.CheckACMETask(tx, adminId, userId, req.AcmeTaskId)
|
||||
canAccess, err := acmemodels.SharedACMETaskDAO.CheckACMETask(tx, adminId, userId, req.AcmeTaskId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -226,7 +228,7 @@ func (this *ACMETaskService) DeleteACMETask(ctx context.Context, req *pb.DeleteA
|
||||
return nil, this.PermissionError()
|
||||
}
|
||||
|
||||
err = models.SharedACMETaskDAO.DisableACMETask(tx, req.AcmeTaskId)
|
||||
err = acmemodels.SharedACMETaskDAO.DisableACMETask(tx, req.AcmeTaskId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -242,7 +244,7 @@ func (this *ACMETaskService) RunACMETask(ctx context.Context, req *pb.RunACMETas
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
canAccess, err := models.SharedACMETaskDAO.CheckACMETask(tx, adminId, userId, req.AcmeTaskId)
|
||||
canAccess, err := acmemodels.SharedACMETaskDAO.CheckACMETask(tx, adminId, userId, req.AcmeTaskId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -250,7 +252,7 @@ func (this *ACMETaskService) RunACMETask(ctx context.Context, req *pb.RunACMETas
|
||||
return nil, this.PermissionError()
|
||||
}
|
||||
|
||||
isOk, msg, certId := models.SharedACMETaskDAO.RunTask(tx, req.AcmeTaskId)
|
||||
isOk, msg, certId := acmemodels.SharedACMETaskDAO.RunTask(tx, req.AcmeTaskId)
|
||||
|
||||
return &pb.RunACMETaskResponse{
|
||||
IsOk: isOk,
|
||||
@@ -268,7 +270,7 @@ func (this *ACMETaskService) FindEnabledACMETask(ctx context.Context, req *pb.Fi
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
canAccess, err := models.SharedACMETaskDAO.CheckACMETask(tx, adminId, userId, req.AcmeTaskId)
|
||||
canAccess, err := acmemodels.SharedACMETaskDAO.CheckACMETask(tx, adminId, userId, req.AcmeTaskId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -276,7 +278,7 @@ func (this *ACMETaskService) FindEnabledACMETask(ctx context.Context, req *pb.Fi
|
||||
return nil, this.PermissionError()
|
||||
}
|
||||
|
||||
task, err := models.SharedACMETaskDAO.FindEnabledACMETask(tx, req.AcmeTaskId)
|
||||
task, err := acmemodels.SharedACMETaskDAO.FindEnabledACMETask(tx, req.AcmeTaskId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -287,7 +289,7 @@ func (this *ACMETaskService) FindEnabledACMETask(ctx context.Context, req *pb.Fi
|
||||
// 用户
|
||||
var pbACMEUser *pb.ACMEUser = nil
|
||||
if task.AcmeUserId > 0 {
|
||||
acmeUser, err := models.SharedACMEUserDAO.FindEnabledACMEUser(tx, int64(task.AcmeUserId))
|
||||
acmeUser, err := acmemodels.SharedACMEUserDAO.FindEnabledACMEUser(tx, int64(task.AcmeUserId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -303,7 +305,7 @@ func (this *ACMETaskService) FindEnabledACMETask(ctx context.Context, req *pb.Fi
|
||||
|
||||
// DNS
|
||||
var pbProvider *pb.DNSProvider
|
||||
provider, err := models.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, int64(task.DnsProviderId))
|
||||
provider, err := dns.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, int64(task.DnsProviderId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
acmemodels "github.com/TeaOSLab/EdgeAPI/internal/db/models/acme"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ func (this *ACMEUserService) CreateACMEUser(ctx context.Context, req *pb.CreateA
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
acmeUserId, err := models.SharedACMEUserDAO.CreateACMEUser(tx, adminId, userId, req.Email, req.Description)
|
||||
acmeUserId, err := acmemodels.SharedACMEUserDAO.CreateACMEUser(tx, adminId, userId, req.Email, req.Description)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func (this *ACMEUserService) UpdateACMEUser(ctx context.Context, req *pb.UpdateA
|
||||
tx := this.NullTx()
|
||||
|
||||
// 检查是否有权限
|
||||
b, err := models.SharedACMEUserDAO.CheckACMEUser(tx, req.AcmeUserId, adminId, userId)
|
||||
b, err := acmemodels.SharedACMEUserDAO.CheckACMEUser(tx, req.AcmeUserId, adminId, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func (this *ACMEUserService) UpdateACMEUser(ctx context.Context, req *pb.UpdateA
|
||||
return nil, this.PermissionError()
|
||||
}
|
||||
|
||||
err = models.SharedACMEUserDAO.UpdateACMEUser(tx, req.AcmeUserId, req.Description)
|
||||
err = acmemodels.SharedACMEUserDAO.UpdateACMEUser(tx, req.AcmeUserId, req.Description)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func (this *ACMEUserService) DeleteACMEUser(ctx context.Context, req *pb.DeleteA
|
||||
tx := this.NullTx()
|
||||
|
||||
// 检查是否有权限
|
||||
b, err := models.SharedACMEUserDAO.CheckACMEUser(tx, req.AcmeUserId, adminId, userId)
|
||||
b, err := acmemodels.SharedACMEUserDAO.CheckACMEUser(tx, req.AcmeUserId, adminId, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (this *ACMEUserService) DeleteACMEUser(ctx context.Context, req *pb.DeleteA
|
||||
return nil, this.PermissionError()
|
||||
}
|
||||
|
||||
err = models.SharedACMEUserDAO.DisableACMEUser(tx, req.AcmeUserId)
|
||||
err = acmemodels.SharedACMEUserDAO.DisableACMEUser(tx, req.AcmeUserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func (this *ACMEUserService) CountACMEUsers(ctx context.Context, req *pb.CountAc
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
count, err := models.SharedACMEUserDAO.CountACMEUsersWithAdminId(tx, adminId, userId)
|
||||
count, err := acmemodels.SharedACMEUserDAO.CountACMEUsersWithAdminId(tx, adminId, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func (this *ACMEUserService) ListACMEUsers(ctx context.Context, req *pb.ListACME
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
acmeUsers, err := models.SharedACMEUserDAO.ListACMEUsers(tx, adminId, userId, req.Offset, req.Size)
|
||||
acmeUsers, err := acmemodels.SharedACMEUserDAO.ListACMEUsers(tx, adminId, userId, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func (this *ACMEUserService) FindEnabledACMEUser(ctx context.Context, req *pb.Fi
|
||||
tx := this.NullTx()
|
||||
|
||||
// 检查是否有权限
|
||||
b, err := models.SharedACMEUserDAO.CheckACMEUser(tx, req.AcmeUserId, adminId, userId)
|
||||
b, err := acmemodels.SharedACMEUserDAO.CheckACMEUser(tx, req.AcmeUserId, adminId, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func (this *ACMEUserService) FindEnabledACMEUser(ctx context.Context, req *pb.Fi
|
||||
return nil, this.PermissionError()
|
||||
}
|
||||
|
||||
acmeUser, err := models.SharedACMEUserDAO.FindEnabledACMEUser(tx, req.AcmeUserId)
|
||||
acmeUser, err := acmemodels.SharedACMEUserDAO.FindEnabledACMEUser(tx, req.AcmeUserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func (this *ACMEUserService) FindAllACMEUsers(ctx context.Context, req *pb.FindA
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
acmeUsers, err := models.SharedACMEUserDAO.FindAllACMEUsers(tx, adminId, userId)
|
||||
acmeUsers, err := acmemodels.SharedACMEUserDAO.FindAllACMEUsers(tx, adminId, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
@@ -29,7 +30,7 @@ func (this *DNSDomainService) CreateDNSDomain(ctx context.Context, req *pb.Creat
|
||||
tx := this.NullTx()
|
||||
|
||||
// 查询Provider
|
||||
provider, err := models.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, req.DnsProviderId)
|
||||
provider, err := dns.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, req.DnsProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -41,7 +42,7 @@ func (this *DNSDomainService) CreateDNSDomain(ctx context.Context, req *pb.Creat
|
||||
return nil, err
|
||||
}
|
||||
|
||||
domainId, err := models.SharedDNSDomainDAO.CreateDomain(tx, adminId, userId, req.DnsProviderId, req.Name)
|
||||
domainId, err := dns.SharedDNSDomainDAO.CreateDomain(tx, adminId, userId, req.DnsProviderId, req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -67,7 +68,7 @@ func (this *DNSDomainService) CreateDNSDomain(ctx context.Context, req *pb.Creat
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = models.SharedDNSDomainDAO.UpdateDomainRoutes(tx, domainId, routesJSON)
|
||||
err = dns.SharedDNSDomainDAO.UpdateDomainRoutes(tx, domainId, routesJSON)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -80,7 +81,7 @@ func (this *DNSDomainService) CreateDNSDomain(ctx context.Context, req *pb.Creat
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = models.SharedDNSDomainDAO.UpdateDomainRecords(tx, domainId, recordsJSON)
|
||||
err = dns.SharedDNSDomainDAO.UpdateDomainRecords(tx, domainId, recordsJSON)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -99,7 +100,7 @@ func (this *DNSDomainService) UpdateDNSDomain(ctx context.Context, req *pb.Updat
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
err = models.SharedDNSDomainDAO.UpdateDomain(tx, req.DnsDomainId, req.Name, req.IsOn)
|
||||
err = dns.SharedDNSDomainDAO.UpdateDomain(tx, req.DnsDomainId, req.Name, req.IsOn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -116,7 +117,7 @@ func (this *DNSDomainService) DeleteDNSDomain(ctx context.Context, req *pb.Delet
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
err = models.SharedDNSDomainDAO.DisableDNSDomain(tx, req.DnsDomainId)
|
||||
err = dns.SharedDNSDomainDAO.DisableDNSDomain(tx, req.DnsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -133,7 +134,7 @@ func (this *DNSDomainService) FindEnabledDNSDomain(ctx context.Context, req *pb.
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
domain, err := models.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, req.DnsDomainId)
|
||||
domain, err := dns.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, req.DnsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -155,7 +156,7 @@ func (this *DNSDomainService) FindEnabledBasicDNSDomain(ctx context.Context, req
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
domain, err := models.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, req.DnsDomainId)
|
||||
domain, err := dns.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, req.DnsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -181,7 +182,7 @@ func (this *DNSDomainService) CountAllEnabledDNSDomainsWithDNSProviderId(ctx con
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
count, err := models.SharedDNSDomainDAO.CountAllEnabledDomainsWithProviderId(tx, req.DnsProviderId)
|
||||
count, err := dns.SharedDNSDomainDAO.CountAllEnabledDomainsWithProviderId(tx, req.DnsProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -198,7 +199,7 @@ func (this *DNSDomainService) FindAllEnabledDNSDomainsWithDNSProviderId(ctx cont
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
domains, err := models.SharedDNSDomainDAO.FindAllEnabledDomainsWithProviderId(tx, req.DnsProviderId)
|
||||
domains, err := dns.SharedDNSDomainDAO.FindAllEnabledDomainsWithProviderId(tx, req.DnsProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -225,7 +226,7 @@ func (this *DNSDomainService) FindAllEnabledBasicDNSDomainsWithDNSProviderId(ctx
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
domains, err := models.SharedDNSDomainDAO.FindAllEnabledDomainsWithProviderId(tx, req.DnsProviderId)
|
||||
domains, err := dns.SharedDNSDomainDAO.FindAllEnabledDomainsWithProviderId(tx, req.DnsProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -262,7 +263,7 @@ func (this *DNSDomainService) FindAllDNSDomainRoutes(ctx context.Context, req *p
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
routes, err := models.SharedDNSDomainDAO.FindDomainRoutes(tx, req.DnsDomainId)
|
||||
routes, err := dns.SharedDNSDomainDAO.FindDomainRoutes(tx, req.DnsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -288,7 +289,7 @@ func (this *DNSDomainService) ExistAvailableDomains(ctx context.Context, req *pb
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
exist, err := models.SharedDNSDomainDAO.ExistAvailableDomains(tx)
|
||||
exist, err := dns.SharedDNSDomainDAO.ExistAvailableDomains(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -296,7 +297,7 @@ func (this *DNSDomainService) ExistAvailableDomains(ctx context.Context, req *pb
|
||||
}
|
||||
|
||||
// 转换域名信息
|
||||
func (this *DNSDomainService) convertDomainToPB(domain *models.DNSDomain) (*pb.DNSDomain, error) {
|
||||
func (this *DNSDomainService) convertDomainToPB(domain *dns.DNSDomain) (*pb.DNSDomain, error) {
|
||||
domainId := int64(domain.Id)
|
||||
|
||||
records := []*dnsclients.Record{}
|
||||
@@ -547,7 +548,7 @@ func (this *DNSDomainService) syncClusterDNS(req *pb.SyncDNSDomainDataRequest) (
|
||||
}
|
||||
|
||||
// 域名信息
|
||||
domain, err := models.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, req.DnsDomainId)
|
||||
domain, err := dns.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, req.DnsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -558,7 +559,7 @@ func (this *DNSDomainService) syncClusterDNS(req *pb.SyncDNSDomainDataRequest) (
|
||||
domainName := domain.Name
|
||||
|
||||
// 服务商信息
|
||||
provider, err := models.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, int64(domain.ProviderId))
|
||||
provider, err := dns.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, int64(domain.ProviderId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -592,7 +593,7 @@ func (this *DNSDomainService) syncClusterDNS(req *pb.SyncDNSDomainDataRequest) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = models.SharedDNSDomainDAO.UpdateDomainRoutes(tx, domainId, routesJSON)
|
||||
err = dns.SharedDNSDomainDAO.UpdateDomainRoutes(tx, domainId, routesJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -617,7 +618,7 @@ func (this *DNSDomainService) syncClusterDNS(req *pb.SyncDNSDomainDataRequest) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = models.SharedDNSDomainDAO.UpdateDomainRecords(tx, domainId, recordsJSON)
|
||||
err = dns.SharedDNSDomainDAO.UpdateDomainRecords(tx, domainId, recordsJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -665,7 +666,7 @@ func (this *DNSDomainService) syncClusterDNS(req *pb.SyncDNSDomainDataRequest) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = models.SharedDNSDomainDAO.UpdateDomainRecords(tx, domainId, recordsJSON)
|
||||
err = dns.SharedDNSDomainDAO.UpdateDomainRecords(tx, domainId, recordsJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -685,7 +686,7 @@ func (this *DNSDomainService) ExistDNSDomainRecord(ctx context.Context, req *pb.
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
isOk, err := models.SharedDNSDomainDAO.ExistDomainRecord(tx, req.DnsDomainId, req.Name, req.Type, req.Route, req.Value)
|
||||
isOk, err := dns.SharedDNSDomainDAO.ExistDomainRecord(tx, req.DnsDomainId, req.Name, req.Type, req.Route, req.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
@@ -23,7 +23,7 @@ func (this *DNSProviderService) CreateDNSProvider(ctx context.Context, req *pb.C
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
providerId, err := models.SharedDNSProviderDAO.CreateDNSProvider(tx, adminId, userId, req.Type, req.Name, req.ApiParamsJSON)
|
||||
providerId, err := dns.SharedDNSProviderDAO.CreateDNSProvider(tx, adminId, userId, req.Type, req.Name, req.ApiParamsJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func (this *DNSProviderService) UpdateDNSProvider(ctx context.Context, req *pb.U
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
err = models.SharedDNSProviderDAO.UpdateDNSProvider(tx, req.DnsProviderId, req.Name, req.ApiParamsJSON)
|
||||
err = dns.SharedDNSProviderDAO.UpdateDNSProvider(tx, req.DnsProviderId, req.Name, req.ApiParamsJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (this *DNSProviderService) CountAllEnabledDNSProviders(ctx context.Context,
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
count, err := models.SharedDNSProviderDAO.CountAllEnabledDNSProviders(tx, req.AdminId, req.UserId)
|
||||
count, err := dns.SharedDNSProviderDAO.CountAllEnabledDNSProviders(tx, req.AdminId, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func (this *DNSProviderService) ListEnabledDNSProviders(ctx context.Context, req
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
providers, err := models.SharedDNSProviderDAO.ListEnabledDNSProviders(tx, req.AdminId, req.UserId, req.Offset, req.Size)
|
||||
providers, err := dns.SharedDNSProviderDAO.ListEnabledDNSProviders(tx, req.AdminId, req.UserId, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func (this *DNSProviderService) FindAllEnabledDNSProviders(ctx context.Context,
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
providers, err := models.SharedDNSProviderDAO.FindAllEnabledDNSProviders(tx, req.AdminId, req.UserId)
|
||||
providers, err := dns.SharedDNSProviderDAO.FindAllEnabledDNSProviders(tx, req.AdminId, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func (this *DNSProviderService) DeleteDNSProvider(ctx context.Context, req *pb.D
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
err = models.SharedDNSProviderDAO.DisableDNSProvider(tx, req.DnsProviderId)
|
||||
err = dns.SharedDNSProviderDAO.DisableDNSProvider(tx, req.DnsProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -156,7 +156,7 @@ func (this *DNSProviderService) FindEnabledDNSProvider(ctx context.Context, req
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
provider, err := models.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, req.DnsProviderId)
|
||||
provider, err := dns.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, req.DnsProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func (this *DNSProviderService) FindAllEnabledDNSProvidersWithType(ctx context.C
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
providers, err := models.SharedDNSProviderDAO.FindAllEnabledDNSProvidersWithType(tx, req.ProviderTypeCode)
|
||||
providers, err := dns.SharedDNSProviderDAO.FindAllEnabledDNSProvidersWithType(tx, req.ProviderTypeCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/iplibrary"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
@@ -192,12 +193,12 @@ func (this *IPLibraryService) LookupIPRegion(ctx context.Context, req *pb.Lookup
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
countryId, err := models.SharedRegionCountryDAO.FindCountryIdWithCountryName(tx, result.Country)
|
||||
countryId, err := regions.SharedRegionCountryDAO.FindCountryIdWithNameCacheable(tx, result.Country)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
provinceId, err := models.SharedRegionProvinceDAO.FindProvinceIdWithProvinceName(tx, result.Province)
|
||||
provinceId, err := regions.SharedRegionProvinceDAO.FindProvinceIdWithNameCacheable(tx, countryId, result.Province)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/events"
|
||||
@@ -179,7 +180,7 @@ func (this *NodeService) ListEnabledNodesMatch(ctx context.Context, req *pb.List
|
||||
if clusterDNS != nil {
|
||||
dnsDomainId = int64(clusterDNS.DnsDomainId)
|
||||
if clusterDNS.DnsDomainId > 0 {
|
||||
domainRoutes, err = models.SharedDNSDomainDAO.FindDomainRoutes(tx, dnsDomainId)
|
||||
domainRoutes, err = dns.SharedDNSDomainDAO.FindDomainRoutes(tx, dnsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1086,7 +1087,7 @@ func (this *NodeService) FindAllEnabledNodesDNSWithClusterId(ctx context.Context
|
||||
}
|
||||
dnsDomainId := int64(clusterDNS.DnsDomainId)
|
||||
|
||||
routes, err := models.SharedDNSDomainDAO.FindDomainRoutes(tx, dnsDomainId)
|
||||
routes, err := dns.SharedDNSDomainDAO.FindDomainRoutes(tx, dnsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1164,7 +1165,7 @@ func (this *NodeService) FindEnabledNodeDNS(ctx context.Context, req *pb.FindEna
|
||||
}
|
||||
|
||||
dnsDomainId := int64(clusterDNS.DnsDomainId)
|
||||
dnsDomainName, err := models.SharedDNSDomainDAO.FindDNSDomainName(tx, dnsDomainId)
|
||||
dnsDomainName, err := dns.SharedDNSDomainDAO.FindDNSDomainName(tx, dnsDomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1177,7 +1178,7 @@ func (this *NodeService) FindEnabledNodeDNS(ctx context.Context, req *pb.FindEna
|
||||
}
|
||||
|
||||
for _, routeCode := range routeCodes {
|
||||
routeName, err := models.SharedDNSDomainDAO.FindDomainRouteName(tx, dnsDomainId, routeCode)
|
||||
routeName, err := dns.SharedDNSDomainDAO.FindDomainRouteName(tx, dnsDomainId, routeCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
@@ -412,7 +413,7 @@ func (this *NodeClusterService) FindEnabledNodeClusterDNS(ctx context.Context, r
|
||||
}, nil
|
||||
}
|
||||
|
||||
domain, err := models.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, int64(dnsInfo.DnsDomainId))
|
||||
domain, err := dns.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, int64(dnsInfo.DnsDomainId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -429,7 +430,7 @@ func (this *NodeClusterService) FindEnabledNodeClusterDNS(ctx context.Context, r
|
||||
IsOn: domain.IsOn == 1,
|
||||
}
|
||||
|
||||
provider, err := models.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, int64(domain.ProviderId))
|
||||
provider, err := dns.SharedDNSProviderDAO.FindEnabledDNSProvider(tx, int64(domain.ProviderId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -568,7 +569,7 @@ func (this *NodeClusterService) CheckNodeClusterDNSChanges(ctx context.Context,
|
||||
}
|
||||
|
||||
domainId := int64(cluster.DnsDomainId)
|
||||
domain, err := models.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, domainId)
|
||||
domain, err := dns.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, domainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
@@ -23,7 +23,7 @@ func (this *RegionCountryService) FindAllEnabledRegionCountries(ctx context.Cont
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
countries, err := models.SharedRegionCountryDAO.FindAllEnabledCountriesOrderByPinyin(tx)
|
||||
countries, err := regions.SharedRegionCountryDAO.FindAllEnabledCountriesOrderByPinyin(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func (this *RegionCountryService) FindEnabledRegionCountry(ctx context.Context,
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
country, err := models.SharedRegionCountryDAO.FindEnabledRegionCountry(tx, req.CountryId)
|
||||
country, err := regions.SharedRegionCountryDAO.FindEnabledRegionCountry(tx, req.CountryId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
@@ -22,7 +22,7 @@ func (this *RegionProvinceService) FindAllEnabledRegionProvincesWithCountryId(ct
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
provinces, err := models.SharedRegionProvinceDAO.FindAllEnabledProvincesWithCountryId(tx, req.CountryId)
|
||||
provinces, err := regions.SharedRegionProvinceDAO.FindAllEnabledProvincesWithCountryId(tx, req.CountryId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func (this *RegionProvinceService) FindEnabledRegionProvince(ctx context.Context
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
province, err := models.SharedRegionProvinceDAO.FindEnabledRegionProvince(tx, req.ProvinceId)
|
||||
province, err := regions.SharedRegionProvinceDAO.FindEnabledRegionProvince(tx, req.ProvinceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/dns"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
@@ -1065,7 +1068,7 @@ func (this *ServerService) FindEnabledServerDNS(ctx context.Context, req *pb.Fin
|
||||
if clusterDNS != nil {
|
||||
domainId := int64(clusterDNS.DnsDomainId)
|
||||
if domainId > 0 {
|
||||
domain, err := models.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, domainId)
|
||||
domain, err := dns.SharedDNSDomainDAO.FindEnabledDNSDomain(tx, domainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1234,3 +1237,157 @@ func (this *ServerService) UpdateEnabledUserServerBasic(ctx context.Context, req
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 上传待统计数据
|
||||
func (this *ServerService) UploadServerHTTPRequestStat(ctx context.Context, req *pb.UploadServerHTTPRequestStatRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
// 全局
|
||||
month := req.Month
|
||||
if len(month) != 6 {
|
||||
return nil, errors.New("invalid month '" + month + "'")
|
||||
}
|
||||
|
||||
// 区域
|
||||
for _, result := range req.RegionCities {
|
||||
// IP => 地理位置
|
||||
err := func() error {
|
||||
// 区域
|
||||
if len(result.CountryName) > 0 {
|
||||
countryId, err := regions.SharedRegionCountryDAO.FindCountryIdWithNameCacheable(tx, result.CountryName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if countryId > 0 {
|
||||
key := fmt.Sprintf("%d@%d@%s", result.ServerId, countryId, month)
|
||||
serverStatLocker.Lock()
|
||||
serverHTTPCountryStatMap[key] += result.Count
|
||||
serverStatLocker.Unlock()
|
||||
|
||||
// 省份
|
||||
if len(result.ProvinceName) > 0 {
|
||||
provinceId, err := regions.SharedRegionProvinceDAO.FindProvinceIdWithNameCacheable(tx, countryId, result.ProvinceName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if provinceId > 0 {
|
||||
key := fmt.Sprintf("%d@%d@%s", result.ServerId, provinceId, month)
|
||||
serverStatLocker.Lock()
|
||||
serverHTTPProvinceStatMap[key] += result.Count
|
||||
serverStatLocker.Unlock()
|
||||
|
||||
// 城市
|
||||
if len(result.CityName) > 0 {
|
||||
cityId, err := regions.SharedRegionCityDAO.FindCityIdWithNameCacheable(tx, provinceId, result.CityName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if cityId > 0 {
|
||||
key := fmt.Sprintf("%d@%d@%s", result.ServerId, cityId, month)
|
||||
serverStatLocker.Lock()
|
||||
serverHTTPCityStatMap[key] += result.Count
|
||||
serverStatLocker.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// 运营商
|
||||
for _, result := range req.RegionProviders {
|
||||
// IP => 地理位置
|
||||
err := func() error {
|
||||
if len(result.Name) == 0 {
|
||||
return nil
|
||||
}
|
||||
providerId, err := regions.SharedRegionProviderDAO.FindProviderIdWithNameCacheable(tx, result.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if providerId > 0 {
|
||||
key := fmt.Sprintf("%d@%d@%s", result.ServerId, providerId, month)
|
||||
serverStatLocker.Lock()
|
||||
serverHTTPProviderStatMap[key] += result.Count
|
||||
serverStatLocker.Unlock()
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// OS
|
||||
for _, result := range req.Systems {
|
||||
err := func() error {
|
||||
if len(result.Name) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
systemId, err := models.SharedClientSystemDAO.FindSystemIdWithNameCacheable(tx, result.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if systemId == 0 {
|
||||
// TODO 失败时,需要查询一次确认是否已添加
|
||||
systemId, err = models.SharedClientSystemDAO.CreateSystem(tx, result.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
key := fmt.Sprintf("%d@%d@%s@%s", result.ServerId, systemId, result.Version, month)
|
||||
serverStatLocker.Lock()
|
||||
serverHTTPSystemStatMap[key] += result.Count
|
||||
serverStatLocker.Unlock()
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Browser
|
||||
for _, result := range req.Browsers {
|
||||
err := func() error {
|
||||
if len(result.Name) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
browserId, err := models.SharedClientBrowserDAO.FindBrowserIdWithNameCacheable(tx, result.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if browserId == 0 {
|
||||
// TODO 失败时,需要查询一次确认是否已添加
|
||||
browserId, err = models.SharedClientBrowserDAO.CreateBrowser(tx, result.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
key := fmt.Sprintf("%d@%d@%s@%s", result.ServerId, browserId, result.Version, month)
|
||||
serverStatLocker.Lock()
|
||||
serverHTTPBrowserStatMap[key] += result.Count
|
||||
serverStatLocker.Unlock()
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
155
internal/rpc/services/service_server_.go
Normal file
155
internal/rpc/services/service_server_.go
Normal file
@@ -0,0 +1,155 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// HTTP请求统计缓存队列
|
||||
var serverHTTPCountryStatMap = map[string]int64{} // serverId@countryId@month => count
|
||||
var serverHTTPProvinceStatMap = map[string]int64{} // serverId@provinceId@month => count
|
||||
var serverHTTPCityStatMap = map[string]int64{} // serverId@cityId@month => count
|
||||
var serverHTTPProviderStatMap = map[string]int64{} // serverId@providerId@month => count
|
||||
var serverHTTPSystemStatMap = map[string]int64{} // serverId@systemId@version@month => count
|
||||
var serverHTTPBrowserStatMap = map[string]int64{} // serverId@browserId@version@month => count
|
||||
var serverStatLocker = sync.Mutex{}
|
||||
|
||||
func init() {
|
||||
var service = new(ServerService)
|
||||
|
||||
dbs.OnReadyDone(func() {
|
||||
// 导入统计数据
|
||||
go func() {
|
||||
var duration = 30 * time.Minute
|
||||
if Tea.IsTesting() {
|
||||
// 测试条件下缩短时间,以便进行观察
|
||||
duration = 1 * time.Minute
|
||||
}
|
||||
ticker := time.NewTicker(duration)
|
||||
for range ticker.C {
|
||||
err := service.dumpServerHTTPStats()
|
||||
if err != nil {
|
||||
remotelogs.Error("SERVER_SERVICE", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
func (this *ServerService) dumpServerHTTPStats() error {
|
||||
// 地区
|
||||
{
|
||||
serverStatLocker.Lock()
|
||||
m := serverHTTPCountryStatMap
|
||||
serverHTTPCountryStatMap = map[string]int64{}
|
||||
serverStatLocker.Unlock()
|
||||
for k, count := range m {
|
||||
pieces := strings.Split(k, "@")
|
||||
if len(pieces) != 3 {
|
||||
continue
|
||||
}
|
||||
err := stats.SharedServerRegionCountryMonthlyStatDAO.IncreaseMonthlyCount(nil, types.Int64(pieces[0]), types.Int64(pieces[1]), pieces[2], count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 省份
|
||||
{
|
||||
serverStatLocker.Lock()
|
||||
m := serverHTTPProvinceStatMap
|
||||
serverHTTPProvinceStatMap = map[string]int64{}
|
||||
serverStatLocker.Unlock()
|
||||
for k, count := range m {
|
||||
pieces := strings.Split(k, "@")
|
||||
if len(pieces) != 3 {
|
||||
continue
|
||||
}
|
||||
err := stats.SharedServerRegionProvinceMonthlyStatDAO.IncreaseMonthlyCount(nil, types.Int64(pieces[0]), types.Int64(pieces[1]), pieces[2], count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 城市
|
||||
{
|
||||
serverStatLocker.Lock()
|
||||
m := serverHTTPCityStatMap
|
||||
serverHTTPCityStatMap = map[string]int64{}
|
||||
serverStatLocker.Unlock()
|
||||
for k, count := range m {
|
||||
pieces := strings.Split(k, "@")
|
||||
if len(pieces) != 3 {
|
||||
continue
|
||||
}
|
||||
err := stats.SharedServerRegionCityMonthlyStatDAO.IncreaseMonthlyCount(nil, types.Int64(pieces[0]), types.Int64(pieces[1]), pieces[2], count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 运营商
|
||||
{
|
||||
serverStatLocker.Lock()
|
||||
m := serverHTTPProviderStatMap
|
||||
serverHTTPProviderStatMap = map[string]int64{}
|
||||
serverStatLocker.Unlock()
|
||||
for k, count := range m {
|
||||
pieces := strings.Split(k, "@")
|
||||
if len(pieces) != 3 {
|
||||
continue
|
||||
}
|
||||
err := stats.SharedServerRegionProviderMonthlyStatDAO.IncreaseMonthlyCount(nil, types.Int64(pieces[0]), types.Int64(pieces[1]), pieces[2], count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 操作系统
|
||||
{
|
||||
serverStatLocker.Lock()
|
||||
m := serverHTTPSystemStatMap
|
||||
serverHTTPSystemStatMap = map[string]int64{}
|
||||
serverStatLocker.Unlock()
|
||||
for k, count := range m {
|
||||
pieces := strings.Split(k, "@")
|
||||
if len(pieces) != 4 {
|
||||
continue
|
||||
}
|
||||
err := stats.SharedServerClientSystemMonthlyStatDAO.IncreaseMonthlyCount(nil, types.Int64(pieces[0]), types.Int64(pieces[1]), pieces[2], pieces[3], count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 浏览器
|
||||
{
|
||||
serverStatLocker.Lock()
|
||||
m := serverHTTPBrowserStatMap
|
||||
serverHTTPBrowserStatMap = map[string]int64{}
|
||||
serverStatLocker.Unlock()
|
||||
for k, count := range m {
|
||||
pieces := strings.Split(k, "@")
|
||||
if len(pieces) != 4 {
|
||||
continue
|
||||
}
|
||||
err := stats.SharedServerClientBrowserMonthlyStatDAO.IncreaseMonthlyCount(nil, types.Int64(pieces[0]), types.Int64(pieces[1]), pieces[2], pieces[3], count)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
// 操作系统统计
|
||||
type ServerClientBrowserMonthlyStatService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 查找前N个操作系统
|
||||
func (this *ServerClientBrowserMonthlyStatService) FindTopServerClientBrowserMonthlyStats(ctx context.Context, req *pb.FindTopServerClientBrowserMonthlyStatsRequest) (*pb.FindTopServerClientBrowserMonthlyStatsResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
statList, err := stats.SharedServerClientBrowserMonthlyStatDAO.ListStats(tx, req.ServerId, req.Month, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbStats := []*pb.FindTopServerClientBrowserMonthlyStatsResponse_Stat{}
|
||||
for _, stat := range statList {
|
||||
pbStat := &pb.FindTopServerClientBrowserMonthlyStatsResponse_Stat{
|
||||
Count: int64(stat.Count),
|
||||
Version: stat.Version,
|
||||
}
|
||||
browser, err := models.SharedClientBrowserDAO.FindEnabledClientBrowser(tx, int64(stat.BrowserId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if browser == nil {
|
||||
continue
|
||||
}
|
||||
pbStat.ClientBrowser = &pb.ClientBrowser{
|
||||
Id: int64(browser.Id),
|
||||
Name: browser.Name,
|
||||
}
|
||||
|
||||
pbStats = append(pbStats, pbStat)
|
||||
}
|
||||
return &pb.FindTopServerClientBrowserMonthlyStatsResponse{Stats: pbStats}, nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
// 操作系统统计
|
||||
type ServerClientSystemMonthlyStatService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 查找前N个操作系统
|
||||
func (this *ServerClientSystemMonthlyStatService) FindTopServerClientSystemMonthlyStats(ctx context.Context, req *pb.FindTopServerClientSystemMonthlyStatsRequest) (*pb.FindTopServerClientSystemMonthlyStatsResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
statList, err := stats.SharedServerClientSystemMonthlyStatDAO.ListStats(tx, req.ServerId, req.Month, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbStats := []*pb.FindTopServerClientSystemMonthlyStatsResponse_Stat{}
|
||||
for _, stat := range statList {
|
||||
pbStat := &pb.FindTopServerClientSystemMonthlyStatsResponse_Stat{
|
||||
Count: int64(stat.Count),
|
||||
Version: stat.Version,
|
||||
}
|
||||
system, err := models.SharedClientSystemDAO.FindEnabledClientSystem(tx, int64(stat.SystemId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if system == nil {
|
||||
continue
|
||||
}
|
||||
pbStat.ClientSystem = &pb.ClientSystem{
|
||||
Id: int64(system.Id),
|
||||
Name: system.Name,
|
||||
}
|
||||
pbStats = append(pbStats, pbStat)
|
||||
}
|
||||
return &pb.FindTopServerClientSystemMonthlyStatsResponse{Stats: pbStats}, nil
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
// 城市月份统计
|
||||
type ServerRegionCityMonthlyStatService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 查找前N个城市
|
||||
func (this *ServerRegionCityMonthlyStatService) FindTopServerRegionCityMonthlyStats(ctx context.Context, req *pb.FindTopServerRegionCityMonthlyStatsRequest) (*pb.FindTopServerRegionCityMonthlyStatsResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
statList, err := stats.SharedServerRegionCityMonthlyStatDAO.ListStats(tx, req.ServerId, req.Month, req.CountryId, req.ProvinceId, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbStats := []*pb.FindTopServerRegionCityMonthlyStatsResponse_Stat{}
|
||||
for _, stat := range statList {
|
||||
pbStat := &pb.FindTopServerRegionCityMonthlyStatsResponse_Stat{
|
||||
Count: int64(stat.Count),
|
||||
}
|
||||
if stat.CityId == 0 {
|
||||
continue
|
||||
}
|
||||
city, err := regions.SharedRegionCityDAO.FindEnabledRegionCity(tx, int64(stat.CityId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if city == nil {
|
||||
continue
|
||||
}
|
||||
province, err := regions.SharedRegionProvinceDAO.FindEnabledRegionProvince(tx, int64(city.ProvinceId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if province == nil {
|
||||
continue
|
||||
}
|
||||
country, err := regions.SharedRegionCountryDAO.FindEnabledRegionCountry(tx, int64(province.CountryId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if country == nil {
|
||||
continue
|
||||
}
|
||||
pbStat.RegionCountry = &pb.RegionCountry{
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
}
|
||||
pbStat.RegionProvince = &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
}
|
||||
pbStat.RegionCity = &pb.RegionCity{
|
||||
Id: int64(city.Id),
|
||||
Name: city.Name,
|
||||
}
|
||||
pbStats = append(pbStats, pbStat)
|
||||
}
|
||||
return &pb.FindTopServerRegionCityMonthlyStatsResponse{Stats: pbStats}, nil
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
// 地区月份统计
|
||||
type ServerRegionCountryMonthlyStatService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 查找前N个地区
|
||||
func (this *ServerRegionCountryMonthlyStatService) FindTopServerRegionCountryMonthlyStats(ctx context.Context, req *pb.FindTopServerRegionCountryMonthlyStatsRequest) (*pb.FindTopServerRegionCountryMonthlyStatsResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
statList, err := stats.SharedServerRegionCountryMonthlyStatDAO.ListStats(tx, req.ServerId, req.Month, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbStats := []*pb.FindTopServerRegionCountryMonthlyStatsResponse_Stat{}
|
||||
for _, stat := range statList {
|
||||
pbStat := &pb.FindTopServerRegionCountryMonthlyStatsResponse_Stat{
|
||||
Count: int64(stat.Count),
|
||||
}
|
||||
|
||||
country, err := regions.SharedRegionCountryDAO.FindEnabledRegionCountry(tx, int64(stat.CountryId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if country == nil {
|
||||
continue
|
||||
}
|
||||
pbStat.RegionCountry = &pb.RegionCountry{
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
}
|
||||
|
||||
pbStats = append(pbStats, pbStat)
|
||||
}
|
||||
|
||||
return &pb.FindTopServerRegionCountryMonthlyStatsResponse{Stats: pbStats}, nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
// 运营商月份统计
|
||||
type ServerRegionProviderMonthlyStatService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 查找前N个运营商
|
||||
func (this *ServerRegionProviderMonthlyStatService) FindTopServerRegionProviderMonthlyStats(ctx context.Context, req *pb.FindTopServerRegionProviderMonthlyStatsRequest) (*pb.FindTopServerRegionProviderMonthlyStatsResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
statList, err := stats.SharedServerRegionProviderMonthlyStatDAO.ListStats(tx, req.ServerId, req.Month, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbStats := []*pb.FindTopServerRegionProviderMonthlyStatsResponse_Stat{}
|
||||
for _, stat := range statList {
|
||||
pbStat := &pb.FindTopServerRegionProviderMonthlyStatsResponse_Stat{
|
||||
Count: int64(stat.Count),
|
||||
}
|
||||
provider, err := regions.SharedRegionProviderDAO.FindEnabledRegionProvider(tx, stat.ProviderId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if provider == nil {
|
||||
continue
|
||||
}
|
||||
pbStat.RegionProvider = &pb.RegionProvider{
|
||||
Id: int64(provider.Id),
|
||||
Name: provider.Name,
|
||||
}
|
||||
pbStats = append(pbStats, pbStat)
|
||||
}
|
||||
return &pb.FindTopServerRegionProviderMonthlyStatsResponse{Stats: pbStats}, nil
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
// 省份月份统计
|
||||
type ServerRegionProvinceMonthlyStatService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 查找前N个省份
|
||||
func (this *ServerRegionProvinceMonthlyStatService) FindTopServerRegionProvinceMonthlyStats(ctx context.Context, req *pb.FindTopServerRegionProvinceMonthlyStatsRequest) (*pb.FindTopServerRegionProvinceMonthlyStatsResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
statList, err := stats.SharedServerRegionProvinceMonthlyStatDAO.ListStats(tx, req.ServerId, req.Month, req.CountryId, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbStats := []*pb.FindTopServerRegionProvinceMonthlyStatsResponse_Stat{}
|
||||
for _, stat := range statList {
|
||||
pbStat := &pb.FindTopServerRegionProvinceMonthlyStatsResponse_Stat{
|
||||
Count: int64(stat.Count),
|
||||
}
|
||||
province, err := regions.SharedRegionProvinceDAO.FindEnabledRegionProvince(tx, int64(stat.ProvinceId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if province == nil {
|
||||
continue
|
||||
}
|
||||
country, err := regions.SharedRegionCountryDAO.FindEnabledRegionCountry(tx, int64(province.CountryId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if country == nil {
|
||||
continue
|
||||
}
|
||||
pbStat.RegionCountry = &pb.RegionCountry{
|
||||
Id: int64(country.Id),
|
||||
Name: country.Name,
|
||||
}
|
||||
pbStat.RegionProvince = &pb.RegionProvince{
|
||||
Id: int64(province.Id),
|
||||
Name: province.Name,
|
||||
}
|
||||
pbStats = append(pbStats, pbStat)
|
||||
}
|
||||
return &pb.FindTopServerRegionProvinceMonthlyStatsResponse{Stats: pbStats}, nil
|
||||
}
|
||||
85
internal/rpc/services/service_server_test.go
Normal file
85
internal/rpc/services/service_server_test.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestServerService_UploadServerHTTPRequestStat(t *testing.T) {
|
||||
dbs.NotifyReady()
|
||||
|
||||
service := new(ServerService)
|
||||
_, err := service.UploadServerHTTPRequestStat(rpcutils.NewMockNodeContext(1), &pb.UploadServerHTTPRequestStatRequest{
|
||||
Month: timeutil.Format("Ym"),
|
||||
RegionCities: []*pb.UploadServerHTTPRequestStatRequest_RegionCity{
|
||||
{
|
||||
ServerId: 1,
|
||||
CountryName: "中国",
|
||||
ProvinceName: "安徽省",
|
||||
CityName: "阜阳市",
|
||||
Count: 1,
|
||||
},
|
||||
},
|
||||
RegionProviders: []*pb.UploadServerHTTPRequestStatRequest_RegionProvider{
|
||||
{
|
||||
ServerId: 1,
|
||||
Name: "电信",
|
||||
Count: 1,
|
||||
},
|
||||
},
|
||||
Systems: []*pb.UploadServerHTTPRequestStatRequest_System{
|
||||
{
|
||||
ServerId: 1,
|
||||
Name: "Mac OS X",
|
||||
Count: 1,
|
||||
Version: "20",
|
||||
},
|
||||
},
|
||||
Browsers: []*pb.UploadServerHTTPRequestStatRequest_Browser{
|
||||
{
|
||||
ServerId: 1,
|
||||
Name: "Chrome",
|
||||
Count: 1,
|
||||
Version: "70",
|
||||
},
|
||||
{
|
||||
ServerId: 1,
|
||||
Name: "Firefox",
|
||||
Count: 1,
|
||||
Version: "30",
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Log("===countries===")
|
||||
logs.PrintAsJSON(serverHTTPCountryStatMap, t)
|
||||
|
||||
t.Log("===provinces===")
|
||||
logs.PrintAsJSON(serverHTTPProvinceStatMap, t)
|
||||
|
||||
t.Log("===cities===")
|
||||
logs.PrintAsJSON(serverHTTPCityStatMap, t)
|
||||
|
||||
t.Log("===providers===")
|
||||
logs.PrintAsJSON(serverHTTPProviderStatMap, t)
|
||||
|
||||
t.Log("===systems===")
|
||||
logs.PrintAsJSON(serverHTTPSystemStatMap, t)
|
||||
|
||||
t.Log("===browsers===")
|
||||
logs.PrintAsJSON(serverHTTPBrowserStatMap, t)
|
||||
|
||||
err = service.dumpServerHTTPStats()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("ok")
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/acme"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/sslconfigs"
|
||||
)
|
||||
@@ -111,7 +112,7 @@ func (this *SSLCertService) DeleteSSLCert(ctx context.Context, req *pb.DeleteSSL
|
||||
}
|
||||
|
||||
// 停止相关ACME任务
|
||||
err = models.SharedACMETaskDAO.DisableAllTasksWithCertId(tx, req.SslCertId)
|
||||
err = acme.SharedACMETaskDAO.DisableAllTasksWithCertId(tx, req.SslCertId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user