Create & Init Project...
This commit is contained in:
43
app/admin/ep/merlin/model/BUILD
Normal file
43
app/admin/ep/merlin/model/BUILD
Normal file
@ -0,0 +1,43 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"bilihub.go",
|
||||
"constants.go",
|
||||
"dashboard.go",
|
||||
"device.go",
|
||||
"dto.go",
|
||||
"merlin.go",
|
||||
"paas.go",
|
||||
"tree.go",
|
||||
"wechat.go",
|
||||
],
|
||||
importpath = "go-common/app/admin/ep/merlin/model",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//vendor/github.com/jinzhu/gorm:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
66
app/admin/ep/merlin/model/bilihub.go
Normal file
66
app/admin/ep/merlin/model/bilihub.go
Normal file
@ -0,0 +1,66 @@
|
||||
package model
|
||||
|
||||
// SearchHubResponse Search Hub Response.
|
||||
type SearchHubResponse struct {
|
||||
Repository []*HubRepo `json:"repository"`
|
||||
}
|
||||
|
||||
// HubRepo HubRepo.
|
||||
type HubRepo struct {
|
||||
ProjectID int `json:"project_id"`
|
||||
ProjectName string `json:"project_name"`
|
||||
ProjectPublic bool `json:"project_public"`
|
||||
RepositoryName string `json:"repository_name"`
|
||||
TagsCount int `json:"tags_count"`
|
||||
}
|
||||
|
||||
// HubProject HubProject.
|
||||
type HubProject struct {
|
||||
ProjectID int `json:"project_id"`
|
||||
Name string `json:"name"`
|
||||
RepoCount int `json:"repo_count"`
|
||||
}
|
||||
|
||||
// GetHubProjectDetailResponse GetHubProjectDetailResponse.
|
||||
type GetHubProjectDetailResponse struct {
|
||||
ProjectID int `json:"project_id"`
|
||||
ProjectName string `json:"name"`
|
||||
RepoCount int `json:"repo_count"`
|
||||
}
|
||||
|
||||
// PaginateProjectRepoRecord PaginateProjectRepoRecord.
|
||||
type PaginateProjectRepoRecord struct {
|
||||
Total int `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
ProjectRepository []*ProjectRepository `json:"project_repositories"`
|
||||
}
|
||||
|
||||
// ProjectRepositoryRequest ProjectRepositoryRequest.
|
||||
type ProjectRepositoryRequest struct {
|
||||
ProjectRepository []*ProjectRepository
|
||||
}
|
||||
|
||||
// ProjectRepository ProjectRepository.
|
||||
type ProjectRepository struct {
|
||||
RepositoryID int `json:"id"`
|
||||
RepositoryName string `json:"name"`
|
||||
TagCount int `json:"tags_count"`
|
||||
CreateTime string `json:"creation_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
}
|
||||
|
||||
// RepositoryTagResponse Repository Tag Response.
|
||||
type RepositoryTagResponse struct {
|
||||
Digest string `json:"digest"`
|
||||
Name string `json:"name"`
|
||||
OS string `json:"os"`
|
||||
Size int64 `json:"size"`
|
||||
Created string `json:"created"`
|
||||
}
|
||||
|
||||
// RepositoryTag Repository Tag.
|
||||
type RepositoryTag struct {
|
||||
RepositoryTagResponse
|
||||
ImageFullName string `json:"image_full_name"`
|
||||
}
|
210
app/admin/ep/merlin/model/constants.go
Normal file
210
app/admin/ep/merlin/model/constants.go
Normal file
@ -0,0 +1,210 @@
|
||||
package model
|
||||
|
||||
//merlin machine status.
|
||||
const (
|
||||
// ImmediatelyFailedMachineInMerlin Paas immediately returns failed, when you create some new machines.
|
||||
ImmediatelyFailedMachineInMerlin = -200
|
||||
// InitializedFailedMachineInMerlin Scheduled detected that paas failed to execute Initialized task.
|
||||
InitializedFailedMachineInMerlin = -201
|
||||
// PodScheduledFailedMachineInMerlin Scheduled detected that paas failed to execute PodScheduled task.
|
||||
PodScheduledFailedMachineInMerlin = -202
|
||||
// ReadyFailedMachineInMerlin Scheduled detected that paas failed to execute Ready task.
|
||||
ReadyFailedMachineInMerlin = -203
|
||||
// ReadyFailedMachineInMerlin Scheduled detected that paas failed to sync the node of tree service.
|
||||
SynTreeFailedMachineInMerlin = -204
|
||||
// CreateTagFailedMachineInMerlin detected that merlin failed to create tag.
|
||||
CreateTagFailedMachineInMerlin = -205
|
||||
|
||||
// RemovedMachineInMerlin the user removed the machine.
|
||||
RemovedMachineInMerlin = -100
|
||||
|
||||
// CreatingMachineInMerlin Paas is creating the machine now.
|
||||
CreatingMachineInMerlin = 0
|
||||
// InitializeMachineInMerlin Paas is executing Initialize task.
|
||||
InitializeMachineInMerlin = 1
|
||||
// InitializeMachineInMerlin Paas is executing PodScheduled task.
|
||||
PodScheduledMachineInMerlin = 2
|
||||
// InitializeMachineInMerlin Paas is executing Ready task.
|
||||
ReadyMachineInMerlin = 3
|
||||
// InitializeMachineInMerlin Paas is syncing the node of tree service.
|
||||
SynTreeMachineInMerlin = 4
|
||||
|
||||
// BootMachineInMerlin The machine is turned on.
|
||||
BootMachineInMerlin = 100
|
||||
|
||||
// ShutdownMachineInMerlin The machine is off state.
|
||||
ShutdownMachineInMerlin = 200
|
||||
)
|
||||
|
||||
// paas return response status.
|
||||
const (
|
||||
// CreateFailedMachineInPaas Paas created the machine failed
|
||||
CreateFailedMachineInPaas = 0
|
||||
// CreatingMachineInPass Paas is creating the machine now
|
||||
CreatingMachineInPass = 1
|
||||
|
||||
// SuccessDeletePaasMachines success deleted paas machine
|
||||
SuccessDeletePaasMachines = 1
|
||||
)
|
||||
|
||||
// pagination.
|
||||
const (
|
||||
DefaultPageSize = 5
|
||||
DefaultPageNum = 1
|
||||
)
|
||||
|
||||
// snapshot status
|
||||
const (
|
||||
SnapshotInit = "快照初始化"
|
||||
SnapshotDoing = "快照进行中"
|
||||
SnapshotSuccess = "快照已完成"
|
||||
SnapShotFailed = "快照失败"
|
||||
)
|
||||
|
||||
// machine log.
|
||||
const (
|
||||
GenForMachineLog = "创建"
|
||||
DeleteForMachineLog = "删除"
|
||||
TransferForMachineLog = "转移"
|
||||
|
||||
OperationSuccessForMachineLog = "成功"
|
||||
OperationFailedForMachineLog = "失败"
|
||||
|
||||
MBStartLog = "移动设备启动"
|
||||
MBShutDownLog = "移动设备关闭"
|
||||
MBBindLog = "移动设备绑定"
|
||||
MBReleaseLog = "移动设备释放"
|
||||
MBLendOutLog = "移动设备借出"
|
||||
MBReturnLog = "移动设备归还"
|
||||
)
|
||||
|
||||
// mobile machine usage.
|
||||
const (
|
||||
MBInUse = 1
|
||||
MBFree = 2
|
||||
MBNoConnect = 3
|
||||
)
|
||||
|
||||
// mobile machine usage.
|
||||
const (
|
||||
MBOnline = 1 //在线
|
||||
MBOffline = -1 //离线
|
||||
MBHostDel = -2 //删除
|
||||
)
|
||||
|
||||
// is Simulator or RealMachine.
|
||||
const (
|
||||
MBSimulator = 1 //虚拟机
|
||||
MBReal = 0 //真机
|
||||
)
|
||||
|
||||
// is real machine on site or not.
|
||||
const (
|
||||
MBOnSite = 0 //归还
|
||||
MBLendOut = 1 //借出
|
||||
)
|
||||
|
||||
// machine suffix.
|
||||
const (
|
||||
MachinePodNameSuffix = "-0"
|
||||
)
|
||||
|
||||
// delay log.
|
||||
const (
|
||||
DelayMachineEndTime = "手动延期"
|
||||
CancelDelayMachineEndTime = "取消延期"
|
||||
AuditDelayMachineEndTime = "审批延期"
|
||||
)
|
||||
|
||||
// delay status.
|
||||
const (
|
||||
DelayStatusInit = 0 //延期状态初始化
|
||||
DelayStatusAuto = 1 //可自动延期
|
||||
DelayStatusApply = 2 //可申请延期
|
||||
DelayStatusDisable = 3 //不可申请延期
|
||||
)
|
||||
|
||||
// apply status.
|
||||
const (
|
||||
ApplyDelayInit = "申请延期中"
|
||||
ApplyDelayCancel = "申请延期取消"
|
||||
ApplyDelayApprove = "申请延期通过"
|
||||
ApplyDelayDecline = "申请延期驳回"
|
||||
)
|
||||
|
||||
// task.
|
||||
const (
|
||||
DeleteMachine = "DeleteMachine" // 删除机器
|
||||
)
|
||||
|
||||
// task status.
|
||||
const (
|
||||
TaskInit = 0 //未开始
|
||||
TaskDone = 1 //已执行成功
|
||||
TaskFailed = 2 //已执行失败
|
||||
TaskDeleted = -1 //任务删除
|
||||
)
|
||||
|
||||
// machine expired status.
|
||||
const (
|
||||
MailTypeMachineWillExpired = 1 //机器将要过期
|
||||
MailTypeMachineDeleted = 2 //机器已被删除
|
||||
MailTypeMachineTransfer = 5 //机器转移
|
||||
MailTypeTaskDeleteMachineFailed = 11 //删除机器任务失败
|
||||
|
||||
MailTypeApplyDelayMachineEndTime = 3 //申请延长机器过期时间
|
||||
MailTypeAuditDelayMachineEndTime = 4 //审核延长机器过期时间
|
||||
|
||||
)
|
||||
|
||||
// image operate type.
|
||||
const (
|
||||
ImageNoSnapshot = 0
|
||||
ImagePullAndPush = 1
|
||||
ImagePull = 2
|
||||
ImageTag = 3
|
||||
ImagePush = 4
|
||||
ImageMachine2Image = 5
|
||||
)
|
||||
|
||||
// image operate err
|
||||
const (
|
||||
ImageSuccess = 0
|
||||
ImageInit = -1
|
||||
ImagePullErr = -2
|
||||
ImageReTagErr = -3
|
||||
ImagePushErr = -4
|
||||
)
|
||||
|
||||
// time format.
|
||||
const (
|
||||
TimeFormat = "2006-01-02 15:04:05"
|
||||
)
|
||||
|
||||
// bool str.
|
||||
const (
|
||||
False = "False"
|
||||
True = "True"
|
||||
)
|
||||
|
||||
// tree role admin.
|
||||
const (
|
||||
TreeRoleAdmin = 1
|
||||
)
|
||||
|
||||
// image status.
|
||||
const (
|
||||
AliveImageStatus = 1
|
||||
DeletedImageStatus = 2
|
||||
)
|
||||
|
||||
// other
|
||||
const (
|
||||
Success = "success"
|
||||
)
|
||||
|
||||
// machine ratio
|
||||
const (
|
||||
CPURatio = 1000
|
||||
MemoryRatio = 1024
|
||||
)
|
86
app/admin/ep/merlin/model/dashboard.go
Normal file
86
app/admin/ep/merlin/model/dashboard.go
Normal file
@ -0,0 +1,86 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// MachineLifeCycle Machine Life Cycle.
|
||||
type MachineLifeCycle struct {
|
||||
Duration string `json:"duration_day"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
// MachineCountGroupByBusiness Machine Count Group By App.
|
||||
type MachineCountGroupByBusiness struct {
|
||||
BusinessUnit string
|
||||
Count int
|
||||
}
|
||||
|
||||
// MachineCountGroupResponse Machine Count Group Response.
|
||||
type MachineCountGroupResponse struct {
|
||||
BusinessUnits []string `json:"departmentList"`
|
||||
Items []*MachineCountGroupItem `json:"items"`
|
||||
}
|
||||
|
||||
// MachineCountGroupItem Machine Count Group Item.
|
||||
type MachineCountGroupItem struct {
|
||||
Type string `json:"type"`
|
||||
Data []int `json:"data"`
|
||||
}
|
||||
|
||||
// MachineCreatedAndEndTime Machine Created And End Time.
|
||||
type MachineCreatedAndEndTime struct {
|
||||
ID int64 `json:"id"`
|
||||
MachineName string `json:"machine_name"`
|
||||
App string `json:"app"`
|
||||
Username string `json:"username"`
|
||||
CreateTime string `json:"created_time"`
|
||||
EndTime string `json:"end_time"`
|
||||
}
|
||||
|
||||
// MachineUsage Machine Usage.
|
||||
type MachineUsage struct {
|
||||
ID int64 `json:"id"`
|
||||
MachineName string `json:"machine_name"`
|
||||
App string `json:"app"`
|
||||
Username string `json:"username"`
|
||||
CPURequest int `json:"cpu_request"`
|
||||
MemoryRequest int `json:"memory_request"`
|
||||
}
|
||||
|
||||
// MobileMachineUserUsageCount Mobile Machine user Usage Count.
|
||||
type MobileMachineUserUsageCount struct {
|
||||
Username string `json:"username"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
// MobileMachineUsageCount Mobile Machine Usage Count.
|
||||
type MobileMachineUsageCount struct {
|
||||
MobileMachineID string `json:"mobile_machine_id"`
|
||||
MobileMachineName string `json:"mobile_machine_name"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
// MobileMachineTypeCount Mobile Machine Type Count.
|
||||
type MobileMachineTypeCount struct {
|
||||
ModeName string `json:"mode_name"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
// MobileMachineUsageTime Mobile Machine Usage Time.
|
||||
type MobileMachineUsageTime struct {
|
||||
//MobileMachineID int64 `json:"mobile_machine_id"`
|
||||
//MobileMachineName string `json:"mobile_machine_name"`
|
||||
//ModeName string `json:"mode_name"`
|
||||
Username string `json:"username"`
|
||||
StartTime time.Time `json:"start_time"`
|
||||
EndTime time.Time `json:"end_time"`
|
||||
Duration float64 `json:"duration_minutes"`
|
||||
}
|
||||
|
||||
// MobileMachineUsageTimeResponse Mobile Machine Usage Time Response.
|
||||
type MobileMachineUsageTimeResponse struct {
|
||||
MobileMachineID int64 `json:"mobile_machine_id"`
|
||||
MobileMachineName string `json:"mobile_machine_name"`
|
||||
ModeName string `json:"mode_name"`
|
||||
TotalDuration float64 `json:"total_duration_minutes"`
|
||||
MobileMachinesUsageTime []*MobileMachineUsageTime `json:"machine_usage_record"`
|
||||
}
|
75
app/admin/ep/merlin/model/device.go
Normal file
75
app/admin/ep/merlin/model/device.go
Normal file
@ -0,0 +1,75 @@
|
||||
package model
|
||||
|
||||
// DeviceListResponse Device List Response.
|
||||
type DeviceListResponse struct {
|
||||
Status *DeviceResponseStatus `json:"status"`
|
||||
Data *DeviceListData `json:"data"`
|
||||
}
|
||||
|
||||
// DeviceListDetailResponse Device List Detail Response.
|
||||
type DeviceListDetailResponse struct {
|
||||
Status *DeviceResponseStatus `json:"status"`
|
||||
Data *DeviceListDetailData `json:"data"`
|
||||
}
|
||||
|
||||
// DeviceBootResponse Device Boot Response.
|
||||
type DeviceBootResponse struct {
|
||||
Status *DeviceResponseStatus `json:"status"`
|
||||
Data *DeviceBootData `json:"data"`
|
||||
}
|
||||
|
||||
// DeviceShutDownResponse Device Shut Down Response.
|
||||
type DeviceShutDownResponse struct {
|
||||
Status *DeviceResponseStatus `json:"status"`
|
||||
}
|
||||
|
||||
// DeviceBootData Device Boot Data.
|
||||
type DeviceBootData struct {
|
||||
WSRUL string `json:"wsurl"`
|
||||
UploadURL string `json:"uploadURL"`
|
||||
}
|
||||
|
||||
// DeviceListDetailData Device List Detail Data.
|
||||
type DeviceListDetailData struct {
|
||||
Devices *Device `json:"device"`
|
||||
}
|
||||
|
||||
// DeviceListData Device List Data.
|
||||
type DeviceListData struct {
|
||||
Devices []*Device `json:"devices"`
|
||||
}
|
||||
|
||||
// DeviceResponseStatus Device Response Status.
|
||||
type DeviceResponseStatus struct {
|
||||
Code int `json:"code"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// Device Device.
|
||||
type Device struct {
|
||||
Serial string `json:"serial"`
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Mode string `json:"mode"`
|
||||
Version string `json:"version"`
|
||||
CPU string `json:"cpu"`
|
||||
IsSimulator bool `json:"isSimulator"`
|
||||
}
|
||||
|
||||
// DeviceBootRequest Device Boot Request.
|
||||
type DeviceBootRequest struct {
|
||||
Serial string `json:"serial"`
|
||||
}
|
||||
|
||||
// MobileDeviceCategoryResponse MobileDeviceCategory Response.
|
||||
type MobileDeviceCategoryResponse struct {
|
||||
Name string `json:"name"`
|
||||
Label string `json:"label"`
|
||||
Values []interface{} `json:"values"`
|
||||
}
|
||||
|
||||
// MobileMachineResponse MobileMachine Response.
|
||||
type MobileMachineResponse struct {
|
||||
*MobileMachine
|
||||
ImageSrc string `json:"image_src"`
|
||||
}
|
333
app/admin/ep/merlin/model/dto.go
Normal file
333
app/admin/ep/merlin/model/dto.go
Normal file
@ -0,0 +1,333 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
// Machine Machine.
|
||||
type Machine struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
Name string `json:"name" gorm:"column:name"`
|
||||
PodName string `json:"pod_name,omitempty" gorm:"column:pod_name"`
|
||||
Status int `json:"status" gorm:"column:status"`
|
||||
Username string `json:"username" gorm:"column:username"`
|
||||
BusinessUnit string `json:"business_unit,omitempty" gorm:"column:business_unit"`
|
||||
Project string `json:"project,omitempty" gorm:"column:project"`
|
||||
App string `json:"app,omitempty" gorm:"column:app"`
|
||||
ClusterID int64 `json:"cluster_id,omitempty" gorm:"column:cluster_id"`
|
||||
NetworkID int64 `json:"network_id,omitempty" gorm:"column:network_id"`
|
||||
Ctime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
|
||||
Utime time.Time `json:"utime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
UpdateBy string `json:"update_by" gorm:"column:update_by"`
|
||||
EndTime time.Time `json:"end_time" gorm:"column:end_time"`
|
||||
Comment string `json:"comment" gorm:"column:comment"`
|
||||
DelayStatus int `json:"delay_status" gorm:"column:delay_status"`
|
||||
}
|
||||
|
||||
// AfterCreate After Create.
|
||||
func (m *Machine) AfterCreate(db *gorm.DB) (err error) {
|
||||
if err = db.Model(m).Where("name = ?", m.Name).Find(&m).Error; err != nil {
|
||||
return
|
||||
}
|
||||
m.EndTime = m.Ctime.AddDate(0, 3, 0)
|
||||
if err = db.Model(&Machine{}).Where("id = ?", m.ID).Update("end_time", m.EndTime).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AfterCreate After Create.
|
||||
func (h *HubImageLog) AfterCreate(db *gorm.DB) (err error) {
|
||||
err = db.Model(h).Where("imagetag = ?", h.ImageTag).Find(&h).Error
|
||||
return
|
||||
}
|
||||
|
||||
// IsFailed Is Failed.
|
||||
func (m *Machine) IsFailed() bool {
|
||||
return m.Status >= ImmediatelyFailedMachineInMerlin && m.Status < RemovedMachineInMerlin
|
||||
}
|
||||
|
||||
// IsDeleted Is Deleted.
|
||||
func (m *Machine) IsDeleted() bool {
|
||||
return m.Status >= RemovedMachineInMerlin && m.Status < CreatingMachineInMerlin
|
||||
}
|
||||
|
||||
// IsCreating Is Creating.
|
||||
func (m *Machine) IsCreating() bool {
|
||||
return m.Status >= CreatingMachineInMerlin && m.Status < BootMachineInMerlin
|
||||
}
|
||||
|
||||
// IsBoot Is Boot.
|
||||
func (m *Machine) IsBoot() bool {
|
||||
return m.Status >= BootMachineInMerlin && m.Status < ShutdownMachineInMerlin
|
||||
}
|
||||
|
||||
// IsShutdown Is Shutdown.
|
||||
func (m *Machine) IsShutdown() bool {
|
||||
return m.Status >= ShutdownMachineInMerlin && m.Status < 300
|
||||
}
|
||||
|
||||
// ToTreeNode return Tree node.
|
||||
func (m *Machine) ToTreeNode() *TreeNode {
|
||||
return &TreeNode{
|
||||
BusinessUnit: m.BusinessUnit,
|
||||
Project: m.Project,
|
||||
App: m.App,
|
||||
}
|
||||
}
|
||||
|
||||
// ToMachineLog generate a machine log struct.
|
||||
func (m *Machine) ToMachineLog() (ml *MachineLog) {
|
||||
ml = &MachineLog{
|
||||
OperateType: GenForMachineLog,
|
||||
Username: m.Username,
|
||||
MachineID: m.ID,
|
||||
}
|
||||
if m.Status == CreatingMachineInMerlin {
|
||||
ml.OperateResult = OperationSuccessForMachineLog
|
||||
} else if m.Status == ImmediatelyFailedMachineInMerlin {
|
||||
ml.OperateResult = OperationFailedForMachineLog
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MachineLog Machine Log.
|
||||
type MachineLog struct {
|
||||
ID int64 `json:"-" gorm:"column:id"`
|
||||
Username string `json:"username" gorm:"column:username"`
|
||||
MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
|
||||
OperateType string `json:"operate_type" gorm:"column:operation_type"`
|
||||
OperateResult string `json:"operate_result" gorm:"column:operation_result"`
|
||||
OperateTime time.Time `json:"operate_time" gorm:"column:ctime;default:current_timestamp"`
|
||||
UTime time.Time `json:"-" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// MobileMachineLog Mobile Machine Log.
|
||||
type MobileMachineLog struct {
|
||||
ID int64 `json:"-" gorm:"column:id"`
|
||||
Username string `json:"username" gorm:"column:username"`
|
||||
MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
|
||||
OperateType string `json:"operate_type" gorm:"column:operation_type"`
|
||||
OperateResult string `json:"operate_result" gorm:"column:operation_result"`
|
||||
OperateTime time.Time `json:"operate_time" gorm:"column:ctime;default:current_timestamp"`
|
||||
UTime time.Time `json:"-" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// MobileMachineErrorLog Mobile Machine Error Log.
|
||||
type MobileMachineErrorLog struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
|
||||
SerialName string `json:"serial" gorm:"column:serial"`
|
||||
ErrorMessage string `json:"error_message" gorm:"column:error_message"`
|
||||
ErrorCode int `json:"error_code" gorm:"column:error_code"`
|
||||
CTime time.Time `json:"create_time" gorm:"column:ctime;default:current_timestamp"`
|
||||
UTime time.Time `json:"-" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// Snapshot Snapshot.
|
||||
type Snapshot struct {
|
||||
ID int64 `gorm:"column:id"`
|
||||
Name string `gorm:"column:name"`
|
||||
MachineID int64 `gorm:"column:machine_id"`
|
||||
UserID int64 `gorm:"column:user_id"`
|
||||
Ctime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
|
||||
Utime time.Time `json:"utime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
UpdateBy int `gorm:"column:update_by"`
|
||||
Comment string `gorm:"column:comment"`
|
||||
}
|
||||
|
||||
// SnapshotLog Snapshot Log.
|
||||
type SnapshotLog struct {
|
||||
ID int64 `gorm:"column:id"`
|
||||
UserID int64 `gorm:"column:user_id"`
|
||||
SnapshotID int64 `gorm:"column:snapshot_id"`
|
||||
OperateType string `gorm:"column:operation_type"`
|
||||
OperateResult int `gorm:"column:operation_result"`
|
||||
OperateTime time.Time `gorm:"column:operation_time;default:current_timestamp"`
|
||||
}
|
||||
|
||||
// Task Task.
|
||||
type Task struct {
|
||||
ID int64 `gorm:"column:id"`
|
||||
TYPE string `gorm:"column:type"`
|
||||
ExecuteTime time.Time `gorm:"column:execute_time"`
|
||||
MachineID int64 `gorm:"column:machine_id"`
|
||||
Status int `gorm:"column:status"`
|
||||
Ctime time.Time `gorm:"column:ctime;default:current_timestamp"`
|
||||
UTime time.Time `gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// User User.
|
||||
type User struct {
|
||||
ID int64 `json:"id" gorm:"auto_increment;primary_key;column:id"`
|
||||
Name string `json:"username" gorm:"column:name"`
|
||||
EMail string `json:"email" gorm:"column:email"`
|
||||
CTime time.Time `gorm:"column:ctime;default:current_timestamp"`
|
||||
UTime time.Time `gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// Image Image.
|
||||
type Image struct {
|
||||
ID int64 `json:"id" gorm:"auto_increment;primary_key;column:id"`
|
||||
Name string `json:"name" gorm:"varchar(100);column:name"`
|
||||
Status int `json:"status" gorm:"not null;column:status"`
|
||||
OS string `json:"os" gorm:"not null;column:os"`
|
||||
Version string `json:"version" gorm:"not null;column:version"`
|
||||
Description string `json:"description" gorm:"column:description"`
|
||||
CreatedBy string `json:"created_by" gorm:"column:created_by"`
|
||||
UpdatedBy string `json:"updated_by" gorm:"column:updated_by"`
|
||||
Ctime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
|
||||
Utime time.Time `json:"utime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// MachinePackage MachinePackage.
|
||||
type MachinePackage struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
Name string `json:"name" gorm:"column:name"`
|
||||
CPUCore int `json:"cpu_request" gorm:"column:cpu_core"`
|
||||
Memory int `json:"memory_request" gorm:"column:memory"`
|
||||
StorageCapacity int `json:"disk_request" gorm:"column:storage_capacity"`
|
||||
CTime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
|
||||
UTime time.Time `json:"utime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// MailLog MailLog.
|
||||
type MailLog struct {
|
||||
ID int64 `gorm:"column:id"`
|
||||
ReceiverName string `gorm:"column:receiver_name"`
|
||||
MailType int `gorm:"column:mail_type"`
|
||||
SendHead string `gorm:"column:send_head"`
|
||||
SendContext string `gorm:"column:send_context"`
|
||||
SendTime time.Time `gorm:"column:ctime;default:current_timestamp"`
|
||||
UTime time.Time `gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// ToPaasQueryAndDelMachineRequest To Paas Query And Del Machine Request.
|
||||
func (m *Machine) ToPaasQueryAndDelMachineRequest() (pqadmr *PaasQueryAndDelMachineRequest) {
|
||||
pqadmr = &PaasQueryAndDelMachineRequest{}
|
||||
pqadmr.Name = m.Name
|
||||
pqadmr.BusinessUnit = m.BusinessUnit
|
||||
pqadmr.Project = m.Project
|
||||
pqadmr.App = m.App
|
||||
pqadmr.ClusterID = m.ClusterID
|
||||
return
|
||||
}
|
||||
|
||||
// ApplicationRecord ApplicationRecord.
|
||||
type ApplicationRecord struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
Applicant string `json:"applicant" gorm:"column:applicant"`
|
||||
MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
|
||||
ApplyEndTime time.Time `json:"apply_end_time" gorm:"column:apply_end_time"`
|
||||
Status string `json:"status" gorm:"column:status"`
|
||||
Auditor string `json:"auditor" gorm:"column:auditor"`
|
||||
CTime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
|
||||
UTime time.Time `json:"utime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// MachineNode the node is associated with machine.
|
||||
type MachineNode struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
|
||||
BusinessUnit string `json:"business_unit" gorm:"column:business_unit"`
|
||||
Project string `json:"project" gorm:"column:project"`
|
||||
App string `json:"app" gorm:"column:app"`
|
||||
TreeID int64 `json:"tree_id,omitempty" gorm:"column:tree_id"`
|
||||
CTime time.Time `json:"create_time" gorm:"column:ctime;default:current_timestamp"`
|
||||
}
|
||||
|
||||
// HubImageLog Hub Image Log
|
||||
type HubImageLog struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
|
||||
UserName string `json:"username" gorm:"column:username"`
|
||||
ImageSrc string `json:"image_src" gorm:"column:imagesrc"`
|
||||
ImageTag string `json:"image_tag" gorm:"column:imagetag"`
|
||||
Status int `json:"status" gorm:"column:status"`
|
||||
OperateType int `json:"operate_type" gorm:"column:operate_type"`
|
||||
CTime time.Time `json:"create_time" gorm:"column:ctime;default:current_timestamp"`
|
||||
UTime time.Time `json:"update_time" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// MobileMachine the node is associated with MobileMachine.
|
||||
type MobileMachine struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
Serial string `json:"serial" gorm:"column:serial"`
|
||||
Name string `json:"name" gorm:"column:name"`
|
||||
CPU string `json:"cpu" gorm:"column:cpu"`
|
||||
Version string `json:"version" gorm:"column:version"`
|
||||
Mode string `json:"mode" gorm:"column:mode"`
|
||||
State string `json:"state" gorm:"column:state"`
|
||||
Host string `json:"host" gorm:"column:host"`
|
||||
CTime time.Time `json:"create_time" gorm:"column:ctime;default:current_timestamp"`
|
||||
MTime time.Time `json:"update_time" gorm:"column:mtime;default:current_timestamp"`
|
||||
LastBindTime time.Time `json:"last_bind_time" gorm:"column:last_bind_time;default:current_timestamp"`
|
||||
OwnerName string `json:"owner_name" gorm:"column:owner_name"`
|
||||
Username string `json:"username" gorm:"column:username"`
|
||||
Type int `json:"type" gorm:"column:type"`
|
||||
EndTime time.Time `json:"end_time" gorm:"column:end_time"`
|
||||
Alias string `json:"alias" gorm:"column:alias"`
|
||||
Comment string `json:"comment" gorm:"column:comment"`
|
||||
WsURL string `json:"wsurl" gorm:"column:wsurl"`
|
||||
UploadURL string `json:"upload_url" gorm:"column:upload_url"`
|
||||
Action int `json:"action" gorm:"column:action"`
|
||||
IsLendOut int `json:"is_lendout" gorm:"column:is_lendout"`
|
||||
UUID string `json:"uuid" gorm:"column:uuid"`
|
||||
}
|
||||
|
||||
// MobileImage Mobile Image.
|
||||
type MobileImage struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
Mode string `json:"mode" gorm:"column:mode"`
|
||||
CTime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
|
||||
MTime time.Time `json:"mtime" gorm:"column:mtime;default:current_timestamp"`
|
||||
ImageSrc string `json:"image_src" gorm:"column:image_src"`
|
||||
}
|
||||
|
||||
// MobileSyncLog MobileSyncLog.
|
||||
type MobileSyncLog struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
UUID string `json:"uuid" gorm:"column:uuid"`
|
||||
AddCnt int `json:"add_count" gorm:"column:add_count"`
|
||||
UpdateCnt int `json:"update_count" gorm:"column:update_count"`
|
||||
DeleteCnt int `json:"delete_count" gorm:"column:delete_count"`
|
||||
TotalCnt int `json:"total_count" gorm:"column:total_count"`
|
||||
Status int `json:"status" gorm:"column:status"`
|
||||
CTime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
|
||||
MTime time.Time `json:"mtime" gorm:"column:mtime;default:current_timestamp"`
|
||||
}
|
||||
|
||||
// MobileCategory MobileCategory.
|
||||
type MobileCategory struct {
|
||||
CPUs []string `json:"cpus"`
|
||||
Versions []string `json:"versions"`
|
||||
Modes []string `json:"modes"`
|
||||
States []string `json:"states"`
|
||||
Types []int `json:"types"`
|
||||
Usages []int `json:"usages"`
|
||||
}
|
||||
|
||||
// SnapshotRecord Snapshot Record
|
||||
type SnapshotRecord struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
MachineID int64 `json:"machine_id" gorm:"column:machine_id"`
|
||||
Username string `json:"username" gorm:"column:username"`
|
||||
ImageName string `json:"image_name" gorm:"column:image_name"`
|
||||
Status string `json:"status" gorm:"column:status"`
|
||||
Ctime time.Time `json:"ctime" gorm:"column:ctime;default:current_timestamp"`
|
||||
MTime time.Time `json:"mtime" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
||||
|
||||
// HubImageConf Hub Image Conf
|
||||
type HubImageConf struct {
|
||||
ID int64 `json:"id" gorm:"column:id"`
|
||||
ImageName string `json:"image_name" gorm:"column:image_name"`
|
||||
UpdateBy string `json:"update_by" gorm:"column:update_by"`
|
||||
Command string `json:"command" gorm:"column:command"`
|
||||
Envs string `json:"environments" gorm:"column:environments"`
|
||||
Hosts string `json:"hosts" gorm:"column:hosts"`
|
||||
CTime time.Time `json:"create_time" gorm:"column:ctime;default:current_timestamp"`
|
||||
UTime time.Time `json:"update_time" gorm:"column:mtime;default:current_timestamp on update current_timestamp"`
|
||||
}
|
448
app/admin/ep/merlin/model/merlin.go
Normal file
448
app/admin/ep/merlin/model/merlin.go
Normal file
@ -0,0 +1,448 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go-common/library/ecode"
|
||||
)
|
||||
|
||||
// Env Env.
|
||||
type Env struct {
|
||||
ClusterID int64 `json:"cluster_id"`
|
||||
NetworkID int64 `json:"network_id"`
|
||||
}
|
||||
|
||||
// Node Node.
|
||||
type Node struct {
|
||||
BusinessUnit string `json:"business_unit"`
|
||||
Project string `json:"project"`
|
||||
App string `json:"app"`
|
||||
TreeID int64 `json:"tree_id"`
|
||||
}
|
||||
|
||||
// GenMachinesRequest Gen Machines Request.
|
||||
type GenMachinesRequest struct {
|
||||
Env
|
||||
PaasMachine
|
||||
PaasMachineSystem
|
||||
Nodes []*Node `json:"nodes"`
|
||||
Comment string `json:"comment"`
|
||||
Amount int `json:"amount"`
|
||||
}
|
||||
|
||||
// Verify verify GenMachinesRequest.
|
||||
func (g *GenMachinesRequest) Verify() error {
|
||||
if g.Amount < 1 {
|
||||
return ecode.MerlinInvalidMachineAmountErr
|
||||
}
|
||||
l := len(g.Nodes)
|
||||
if l < 1 || l > 10 {
|
||||
return ecode.MerlinInvalidNodeAmountErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Mutator Mutator.
|
||||
func (g *GenMachinesRequest) Mutator(m *Machine) {
|
||||
m.BusinessUnit = g.Nodes[0].BusinessUnit
|
||||
m.Project = g.Nodes[0].Project
|
||||
m.App = g.Nodes[0].App
|
||||
m.ClusterID = g.ClusterID
|
||||
m.NetworkID = g.NetworkID
|
||||
m.Comment = g.Comment
|
||||
}
|
||||
|
||||
// ToMachineNode to machine node.
|
||||
func (g *GenMachinesRequest) ToMachineNode(mID int64) (treeNodes []*MachineNode) {
|
||||
for _, node := range g.Nodes {
|
||||
treeNodes = append(treeNodes, &MachineNode{
|
||||
MachineID: mID,
|
||||
BusinessUnit: node.BusinessUnit,
|
||||
Project: node.Project,
|
||||
App: node.App,
|
||||
TreeID: node.TreeID,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PaasMachineSystem Paas Machine System.
|
||||
type PaasMachineSystem struct {
|
||||
Command string `json:"command"`
|
||||
Envs []*EnvVariable `json:"envs"`
|
||||
HostAlias []*Host `json:"host_alias"`
|
||||
}
|
||||
|
||||
// Host Host.
|
||||
type Host struct {
|
||||
IP string `json:"ip"`
|
||||
Hostnames []string `json:"hostnames"`
|
||||
}
|
||||
|
||||
// EnvVariable EnvVariable.
|
||||
type EnvVariable struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// GenMachine GenMachine.
|
||||
type GenMachine struct {
|
||||
Machine
|
||||
IP string `json:"ip"`
|
||||
ClusterName string `json:"cluster_name"`
|
||||
NetworkName string `json:"network_name"`
|
||||
}
|
||||
|
||||
// MachineDetail Machine Detail.
|
||||
type MachineDetail struct {
|
||||
Machine
|
||||
PaasMachineDetail
|
||||
Nodes []*MachineNode `json:"nodes"`
|
||||
NetworkName string `json:"network_name"`
|
||||
Name string `json:"name"`
|
||||
IsSnapShot bool `json:"is_support_snapshot"`
|
||||
}
|
||||
|
||||
// PaginateMachine Paginate Machine.
|
||||
type PaginateMachine struct {
|
||||
Total int64 `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
Machines []GenMachine `json:"machines"`
|
||||
}
|
||||
|
||||
// PaginateMachineLog Paginate Machine Log.
|
||||
type PaginateMachineLog struct {
|
||||
Total int64 `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
MachineLogs []*AboundMachineLog `json:"machine_logs"`
|
||||
}
|
||||
|
||||
// PaginateMobileMachineLog Paginate Mobile Machine Log.
|
||||
type PaginateMobileMachineLog struct {
|
||||
Total int64 `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
MachineLogs []*AboundMobileMachineLog `json:"machine_logs"`
|
||||
}
|
||||
|
||||
// PaginateMobileMachineLendOutLog Paginate Mobile Machine Lend Out Log.
|
||||
type PaginateMobileMachineLendOutLog struct {
|
||||
Total int64 `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
MachineLendOutRecords []*MachineLendOutRecord `json:"machine_lendout_records"`
|
||||
}
|
||||
|
||||
// MachineLendOutRecord Machine Lend Out Record.
|
||||
type MachineLendOutRecord struct {
|
||||
MachineID int64 `json:"machine_id"`
|
||||
Lender string `json:"lender"`
|
||||
Status int `json:"status"`
|
||||
LendTime time.Time `json:"lend_time"`
|
||||
EnableReturn bool `json:"enable_return"`
|
||||
}
|
||||
|
||||
// PaginateMobileMachineErrorLog Paginate Mobile Machine Error Log.
|
||||
type PaginateMobileMachineErrorLog struct {
|
||||
Total int64 `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
MachineLogs []*MobileMachineErrorLog `json:"machine_logs"`
|
||||
}
|
||||
|
||||
// PaginateApplicationRecord Paginate Application Record.
|
||||
type PaginateApplicationRecord struct {
|
||||
Total int64 `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
ApplicationRecords []*ApplicationRecord `json:"application_records"`
|
||||
}
|
||||
|
||||
// ToPaasGenMachineRequest to Paas GenMachine Request.
|
||||
func (g GenMachinesRequest) ToPaasGenMachineRequest(machineLimitRatio float32) *PaasGenMachineRequest {
|
||||
var (
|
||||
pms = make([]PaasMachine, g.Amount)
|
||||
treeIDs []int64
|
||||
fn = g.Nodes[0]
|
||||
)
|
||||
g.CPULimit = g.CPURequest * CPURatio
|
||||
g.MemoryLimit = g.MemoryRequest * MemoryRatio
|
||||
|
||||
g.CPURequest = g.CPURequest * CPURatio / machineLimitRatio
|
||||
g.MemoryRequest = g.MemoryRequest * MemoryRatio / machineLimitRatio
|
||||
|
||||
for i := 0; i < g.Amount; i++ {
|
||||
pms[i] = g.PaasMachine
|
||||
pms[i].Name = g.Name + "-" + strconv.Itoa(i+1)
|
||||
pms[i].PaasMachineSystem = g.PaasMachineSystem
|
||||
}
|
||||
for _, node := range g.Nodes {
|
||||
treeIDs = append(treeIDs, node.TreeID)
|
||||
}
|
||||
return &PaasGenMachineRequest{
|
||||
BusinessUnit: fn.BusinessUnit,
|
||||
Project: fn.Project,
|
||||
App: fn.App,
|
||||
TreeIDs: treeIDs,
|
||||
Env: g.Env,
|
||||
Machines: pms,
|
||||
}
|
||||
}
|
||||
|
||||
// Pagination Pagination.
|
||||
type Pagination struct {
|
||||
PageSize int `form:"page_size" json:"page_size"`
|
||||
PageNum int `form:"page_num" json:"page_num"`
|
||||
}
|
||||
|
||||
// Verify verify the value of pageNum and pageSize.
|
||||
func (p *Pagination) Verify() error {
|
||||
if p.PageNum < 0 {
|
||||
return ecode.MerlinIllegalPageNumErr
|
||||
} else if p.PageNum == 0 {
|
||||
p.PageNum = DefaultPageNum
|
||||
}
|
||||
if p.PageSize < 0 {
|
||||
return ecode.MerlinIllegalPageSizeErr
|
||||
} else if p.PageSize == 0 {
|
||||
p.PageSize = DefaultPageSize
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryMachineRequest Query Machine Request.
|
||||
type QueryMachineRequest struct {
|
||||
Pagination
|
||||
TreeNode
|
||||
MachineName string `form:"machine_name"`
|
||||
Username string `form:"username"`
|
||||
Requester string
|
||||
}
|
||||
|
||||
// QueryMachineLogRequest Query Machine Log Request.
|
||||
type QueryMachineLogRequest struct {
|
||||
Pagination
|
||||
MachineID int64 `form:"machine_id"`
|
||||
MachineName string `form:"machine_name"`
|
||||
OperateUser string `form:"operate_user"`
|
||||
OperateType string `form:"operate_type"`
|
||||
}
|
||||
|
||||
// QueryMobileMachineLogRequest Query Mobile Machine Log Request.
|
||||
type QueryMobileMachineLogRequest struct {
|
||||
Pagination
|
||||
MachineID int64 `form:"machine_id"`
|
||||
Serial string `form:"serial"`
|
||||
OperateUser string `form:"operate_user"`
|
||||
OperateType string `form:"operate_type"`
|
||||
}
|
||||
|
||||
// QueryMobileMachineErrorLogRequest Query Mobile Machine Error Log Request.
|
||||
type QueryMobileMachineErrorLogRequest struct {
|
||||
Pagination
|
||||
MachineID int64 `form:"machine_id"`
|
||||
}
|
||||
|
||||
// AboundMachineLog Abound Machine Log.
|
||||
type AboundMachineLog struct {
|
||||
MachineLog
|
||||
Name string `json:"machine_name"`
|
||||
}
|
||||
|
||||
// AboundMobileMachineLog Abound mobile Machine Log.
|
||||
type AboundMobileMachineLog struct {
|
||||
MobileMachineLog
|
||||
Serial string `json:"serial"`
|
||||
}
|
||||
|
||||
// ApplyEndTimeRequest Apply End Time Request.
|
||||
type ApplyEndTimeRequest struct {
|
||||
MachineID int64 `json:"machine_id"`
|
||||
ApplyEndTime string `json:"apply_end_time"`
|
||||
Auditor string `json:"auditor"`
|
||||
}
|
||||
|
||||
// AuditEndTimeRequest Audit End Time Request.
|
||||
type AuditEndTimeRequest struct {
|
||||
AuditID int64 `json:"audit_id"`
|
||||
AuditResult bool `json:"audit_result"`
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
// BeforeDelMachineFunc Before DelMachine Func.
|
||||
type BeforeDelMachineFunc func(c context.Context, id int64, username string) error
|
||||
|
||||
// MachineStatusResponse Machine Status Response.
|
||||
type MachineStatusResponse struct {
|
||||
Initialized string `json:"initialized"`
|
||||
PodScheduled string `json:"pod_scheduled"`
|
||||
Ready string `json:"ready"`
|
||||
SynTree string `json:"syn_tree"`
|
||||
RetryCount int `json:"retry_count"`
|
||||
Log string `json:"log"`
|
||||
MachineEvent []string `json:"events"`
|
||||
}
|
||||
|
||||
// CreatingMachineStatus Creating Machine Status.
|
||||
func (msr *MachineStatusResponse) CreatingMachineStatus() int {
|
||||
if msr.Initialized == False {
|
||||
return CreatingMachineInMerlin
|
||||
}
|
||||
if msr.PodScheduled == False {
|
||||
return InitializeMachineInMerlin
|
||||
}
|
||||
if msr.Ready == False {
|
||||
return ReadyMachineInMerlin
|
||||
}
|
||||
if msr.SynTree == False {
|
||||
return SynTreeMachineInMerlin
|
||||
}
|
||||
return BootMachineInMerlin
|
||||
}
|
||||
|
||||
// FailedMachineStatus Failed Machine Status.
|
||||
func (msr *MachineStatusResponse) FailedMachineStatus() int {
|
||||
if msr.Initialized == False {
|
||||
return InitializedFailedMachineInMerlin
|
||||
}
|
||||
if msr.PodScheduled == False {
|
||||
return PodScheduledFailedMachineInMerlin
|
||||
}
|
||||
if msr.Ready == False {
|
||||
return ReadyFailedMachineInMerlin
|
||||
}
|
||||
if msr.SynTree == False {
|
||||
return SynTreeFailedMachineInMerlin
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// InstanceMachineStatusResponse Instance Machine Status Response.
|
||||
func InstanceMachineStatusResponse(machineStatus int) *MachineStatusResponse {
|
||||
switch machineStatus {
|
||||
case ImmediatelyFailedMachineInMerlin:
|
||||
return &MachineStatusResponse{}
|
||||
case InitializedFailedMachineInMerlin:
|
||||
return &MachineStatusResponse{Initialized: False, PodScheduled: False, Ready: False, SynTree: False, RetryCount: 0}
|
||||
case PodScheduledFailedMachineInMerlin:
|
||||
return &MachineStatusResponse{Initialized: True, PodScheduled: False, Ready: False, SynTree: False, RetryCount: 0}
|
||||
case ReadyFailedMachineInMerlin:
|
||||
return &MachineStatusResponse{Initialized: True, PodScheduled: True, Ready: False, SynTree: False, RetryCount: 0}
|
||||
case SynTreeFailedMachineInMerlin:
|
||||
return &MachineStatusResponse{Initialized: True, PodScheduled: True, Ready: True, SynTree: False, RetryCount: 0}
|
||||
case BootMachineInMerlin:
|
||||
return &MachineStatusResponse{Initialized: True, PodScheduled: True, Ready: True, SynTree: True, RetryCount: 0}
|
||||
case ShutdownMachineInMerlin:
|
||||
return &MachineStatusResponse{Initialized: True, PodScheduled: True, Ready: True, SynTree: True, RetryCount: 0}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TreeNode tree node struct for merlin.
|
||||
type TreeNode struct {
|
||||
BusinessUnit string `form:"business_unit"`
|
||||
Project string `form:"project"`
|
||||
App string `form:"app"`
|
||||
}
|
||||
|
||||
// VerifyFieldValue verify that all fields is not empty.
|
||||
func (t TreeNode) VerifyFieldValue() (err error) {
|
||||
if t.BusinessUnit == "" || t.Project == "" || t.App == "" {
|
||||
err = ecode.MerlinShouldTreeFullPath
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// TreePath join all fields.
|
||||
func (t *TreeNode) TreePath() string {
|
||||
return t.BusinessUnit + "." + t.Project + "." + t.App
|
||||
}
|
||||
|
||||
// TreePathWithoutEmptyField join all fields except empty.
|
||||
func (t *TreeNode) TreePathWithoutEmptyField() (treePath string) {
|
||||
if t.BusinessUnit == "" {
|
||||
return
|
||||
}
|
||||
treePath = "bilibili." + t.BusinessUnit
|
||||
if t.Project == "" {
|
||||
return
|
||||
}
|
||||
treePath = treePath + "." + t.Project
|
||||
if t.App == "" {
|
||||
return
|
||||
}
|
||||
treePath = treePath + "." + t.App
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateMachineNodeRequest request struct for updating machine node.
|
||||
type UpdateMachineNodeRequest struct {
|
||||
MachineID int64 `json:"machine_id"`
|
||||
Nodes []*MachineNode `json:"nodes"`
|
||||
}
|
||||
|
||||
// VerifyNodes verify the Nodes field of UpdateMachineNodeRequest
|
||||
func (u *UpdateMachineNodeRequest) VerifyNodes() error {
|
||||
l := len(u.Nodes)
|
||||
if l < 1 || l > 10 {
|
||||
return ecode.MerlinInvalidNodeAmountErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ToMachineNodes convert to machine nodes with injecting machine id.
|
||||
func (u UpdateMachineNodeRequest) ToMachineNodes() []*MachineNode {
|
||||
for _, n := range u.Nodes {
|
||||
n.MachineID = u.MachineID
|
||||
}
|
||||
return u.Nodes
|
||||
}
|
||||
|
||||
// QueryMobileDeviceRequest Query Device Farm Request.
|
||||
type QueryMobileDeviceRequest struct {
|
||||
Pagination
|
||||
MobileID int64 `json:"mobile_id"`
|
||||
Serial string `json:"serial"`
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
OwnerName string `json:"owner_name"`
|
||||
CPU string `json:"cpu"`
|
||||
Version string `json:"version"`
|
||||
Mode string `json:"mode"`
|
||||
Type int `json:"type"`
|
||||
State string `json:"state"`
|
||||
Usage int `json:"usage"`
|
||||
Online bool `json:"online"`
|
||||
}
|
||||
|
||||
// PaginateMobileMachines Paginate Device.
|
||||
type PaginateMobileMachines struct {
|
||||
Total int64 `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
MobileMachines []*MobileMachineResponse `json:"mobile_devices"`
|
||||
}
|
||||
|
||||
// QueryMachine2ImageLogRequest Query Machine to Image Log Request.
|
||||
type QueryMachine2ImageLogRequest struct {
|
||||
Pagination
|
||||
MachineID int64 `form:"machine_id"`
|
||||
}
|
||||
|
||||
// PaginateHubImageLog Paginate Hub Image Log.
|
||||
type PaginateHubImageLog struct {
|
||||
Total int64 `json:"total"`
|
||||
PageNum int `json:"page_num"`
|
||||
PageSize int `json:"page_size"`
|
||||
HubImageLogs []*HubImageLog `json:"hub_image_logs"`
|
||||
}
|
||||
|
||||
// ImageConfiguration Image Configuration.
|
||||
type ImageConfiguration struct {
|
||||
ImageFullName string `json:"image_full_name"`
|
||||
PaasMachineSystem
|
||||
}
|
325
app/admin/ep/merlin/model/paas.go
Normal file
325
app/admin/ep/merlin/model/paas.go
Normal file
@ -0,0 +1,325 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"go-common/library/ecode"
|
||||
"go-common/library/log"
|
||||
)
|
||||
|
||||
// PaasConf conf of paas.
|
||||
type PaasConf struct {
|
||||
Host string
|
||||
Token string
|
||||
MachineTimeout string
|
||||
MachineLimitRatio float32
|
||||
}
|
||||
|
||||
// PaasMachine machine in paas.
|
||||
type PaasMachine struct {
|
||||
PaasMachineSystem
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
CPURequest float32 `json:"cpu_request"`
|
||||
MemoryRequest float32 `json:"memory_request"`
|
||||
|
||||
CPULimit float32 `json:"cpu_limit"`
|
||||
MemoryLimit float32 `json:"memory_limit"`
|
||||
|
||||
DiskRequest int `json:"disk_request"`
|
||||
VolumnMount string `json:"volumn_mount"`
|
||||
Snapshot bool `json:"snapshot"`
|
||||
ForcePullImage bool `json:"force_pull_image"`
|
||||
}
|
||||
|
||||
// ToMachine convert PaasMachine to Machine.
|
||||
func (pm *PaasMachine) ToMachine(u string, gmr *GenMachinesRequest) (m *Machine) {
|
||||
m = &Machine{
|
||||
Username: u,
|
||||
Name: pm.Name,
|
||||
PodName: pm.Name + MachinePodNameSuffix,
|
||||
Status: CreatingMachineInMerlin,
|
||||
}
|
||||
gmr.Mutator(m)
|
||||
return
|
||||
}
|
||||
|
||||
// PaasGenMachineRequest create machine request in paas.
|
||||
type PaasGenMachineRequest struct {
|
||||
Env
|
||||
BusinessUnit string `json:"business_unit"`
|
||||
Project string `json:"project"`
|
||||
App string `json:"app"`
|
||||
TreeIDs []int64 `json:"tree_id"`
|
||||
Machines []PaasMachine `json:"machines"`
|
||||
}
|
||||
|
||||
// ExcludeDataResponse no data field response.
|
||||
type ExcludeDataResponse struct {
|
||||
Status int `json:"status"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// CheckStatus check status.
|
||||
func (e *ExcludeDataResponse) CheckStatus() (err error) {
|
||||
if e.Status >= http.StatusMultipleChoices || e.Status < http.StatusOK {
|
||||
log.Error("The status(%d) of paas may represent a request error(%s)", e.Status, e.Message)
|
||||
err = ecode.MerlinPaasRequestErr
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Instance instance.
|
||||
type Instance struct {
|
||||
InstanceName string `json:"instance_name"`
|
||||
}
|
||||
|
||||
// CreateInstance create instance.
|
||||
type CreateInstance struct {
|
||||
Instance
|
||||
InstanceCreateStatus int `json:"instance_create_status"`
|
||||
}
|
||||
|
||||
// ReleaseInstance release instance.
|
||||
type ReleaseInstance struct {
|
||||
Instance
|
||||
InstanceReleaseStatus int `json:"instance_release_status"`
|
||||
}
|
||||
|
||||
// PaasGenMachineResponse create machine response in paas.
|
||||
type PaasGenMachineResponse struct {
|
||||
ExcludeDataResponse
|
||||
Data []*CreateInstance `json:"data"`
|
||||
}
|
||||
|
||||
// PaasDelMachineResponse delete machine response in paas.
|
||||
type PaasDelMachineResponse struct {
|
||||
ExcludeDataResponse
|
||||
Data ReleaseInstance `json:"data"`
|
||||
}
|
||||
|
||||
// PaasSnapshotMachineResponse Paas Snapshot Machine Response.
|
||||
type PaasSnapshotMachineResponse struct {
|
||||
ExcludeDataResponse
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
// DetailCondition detail condition.
|
||||
type DetailCondition struct {
|
||||
Initialized string `json:"Initialized"`
|
||||
PodScheduled string `json:"PodScheduled"`
|
||||
Ready string `json:"Ready"`
|
||||
}
|
||||
|
||||
// MachineStatus machine status.
|
||||
type MachineStatus struct {
|
||||
Condition string `json:"condition"`
|
||||
Message string `json:"message"`
|
||||
DetailCondition DetailCondition `json:"detail_conditions"`
|
||||
InstanceIP string `json:"instance_ip"`
|
||||
RestartCount int `json:"restart_count"`
|
||||
Log string `json:"log"`
|
||||
MachineEvent MachineEvent `json:"events"`
|
||||
}
|
||||
|
||||
// MachineEvent MachineEvent.
|
||||
type MachineEvent struct {
|
||||
MachinesItems []*MachinesItem `json:"Items"`
|
||||
}
|
||||
|
||||
// MachinesItem MachinesItem.
|
||||
type MachinesItem struct {
|
||||
Kind string `json:"Kind"`
|
||||
Name string `json:"Name"`
|
||||
Namespace string `json:"Namespace"`
|
||||
Reason string `json:"Reason"`
|
||||
Message string `json:"Message"`
|
||||
Count int `json:"Count"`
|
||||
LastTime string `json:"LastTime"`
|
||||
}
|
||||
|
||||
// ToMachineStatusResponse convert MachineStatus to MachineStatusResponse.
|
||||
func (ms *MachineStatus) ToMachineStatusResponse() (msr *MachineStatusResponse) {
|
||||
var events []string
|
||||
for _, item := range ms.MachineEvent.MachinesItems {
|
||||
mJSON, _ := json.Marshal(item)
|
||||
events = append(events, string(mJSON))
|
||||
}
|
||||
|
||||
return &MachineStatusResponse{
|
||||
Initialized: ms.DetailCondition.Initialized,
|
||||
PodScheduled: ms.DetailCondition.PodScheduled,
|
||||
Ready: ms.DetailCondition.Ready,
|
||||
Log: ms.Log,
|
||||
MachineEvent: events,
|
||||
}
|
||||
}
|
||||
|
||||
// PaasQueryMachineStatusResponse query machine status response.
|
||||
type PaasQueryMachineStatusResponse struct {
|
||||
ExcludeDataResponse
|
||||
Data MachineStatus `json:"data"`
|
||||
}
|
||||
|
||||
// PaasQueryClustersResponse query cluster response.
|
||||
type PaasQueryClustersResponse struct {
|
||||
ExcludeDataResponse
|
||||
Data Clusters `json:"data"`
|
||||
}
|
||||
|
||||
// PaasQueryClusterResponse query cluster response.
|
||||
type PaasQueryClusterResponse struct {
|
||||
ExcludeDataResponse
|
||||
Data *Cluster `json:"data"`
|
||||
}
|
||||
|
||||
// PaasMachineDetail machine detail.
|
||||
type PaasMachineDetail struct {
|
||||
Condition string `json:"condition"`
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
|
||||
CPURequest float32 `json:"cpu_request"`
|
||||
MemoryRequest float32 `json:"memory_request"`
|
||||
|
||||
CPULimit float32 `json:"cpu_limit"`
|
||||
MemoryLimit float32 `json:"memory_limit"`
|
||||
|
||||
DiskRequest int `json:"disk_request"`
|
||||
VolumnMount string `json:"volumn_mount"`
|
||||
ClusterName string `json:"cluster_name"`
|
||||
Env string `json:"env"`
|
||||
IP string `json:"ip"`
|
||||
PaasMachineSystem
|
||||
}
|
||||
|
||||
// ConvertUnits convert units of cpu and memory.
|
||||
func (p PaasMachineDetail) ConvertUnits() PaasMachineDetail {
|
||||
p.CPURequest = p.CPURequest / CPURatio
|
||||
p.MemoryRequest = p.MemoryRequest / MemoryRatio
|
||||
p.CPULimit = p.CPULimit / CPURatio
|
||||
p.MemoryLimit = p.MemoryLimit / MemoryRatio
|
||||
return p
|
||||
}
|
||||
|
||||
// PaasQueryMachineResponse query machine response.
|
||||
type PaasQueryMachineResponse struct {
|
||||
ExcludeDataResponse
|
||||
Data PaasMachineDetail `json:"data"`
|
||||
}
|
||||
|
||||
// Clusters clusters.
|
||||
type Clusters struct {
|
||||
Items []*Cluster `json:"items"`
|
||||
}
|
||||
|
||||
// Network network.
|
||||
type Network struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Subnet string `json:"subnet"`
|
||||
Capacity float64 `json:"capacity"`
|
||||
}
|
||||
|
||||
// Resource resource.
|
||||
type Resource struct {
|
||||
CPUUsage float64 `json:"cpu_usage"` //集群总体CPU使用率
|
||||
MemUsage float64 `json:"mem_usage"` //集群总体内存使用率
|
||||
PodTotal int `json:"pod_total"` //集群实例总数
|
||||
PodCapacity int `json:"pod_capacity"` //集群实例容量
|
||||
NodesNum int `json:"nodes_num"` //集群节点数量
|
||||
}
|
||||
|
||||
// Cluster cluster.
|
||||
type Cluster struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
IsSupportSnapShot bool `json:"is_support_snapshot"`
|
||||
Desc string `json:"desc"`
|
||||
IDc string `json:"idc"`
|
||||
Networks []Network `json:"networks"`
|
||||
Resources Resource `json:"resources"`
|
||||
}
|
||||
|
||||
// Verify verify cluster
|
||||
func (c *Cluster) Verify() error {
|
||||
if c.Name == "" || len(c.Networks) < 1 || c.Networks[0].Name == "" {
|
||||
return ecode.MerlinInvalidClusterErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ToMachine convert CreateInstance to Machine.
|
||||
func (i *CreateInstance) ToMachine(u string, gmr *GenMachinesRequest) (m *Machine) {
|
||||
var status int
|
||||
switch i.InstanceCreateStatus {
|
||||
case CreateFailedMachineInPaas:
|
||||
status = ImmediatelyFailedMachineInMerlin
|
||||
case CreatingMachineInPass:
|
||||
status = CreatingMachineInMerlin
|
||||
}
|
||||
m = &Machine{
|
||||
Username: u,
|
||||
Name: i.InstanceName,
|
||||
PodName: i.InstanceName + MachinePodNameSuffix,
|
||||
Status: status,
|
||||
}
|
||||
gmr.Mutator(m)
|
||||
return
|
||||
}
|
||||
|
||||
// PaasQueryAndDelMachineRequest query and del machines request.
|
||||
type PaasQueryAndDelMachineRequest struct {
|
||||
BusinessUnit string `json:"business_unit"`
|
||||
Project string `json:"project"`
|
||||
App string `json:"app"`
|
||||
ClusterID int64 `json:"cluster_id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// PaasAuthRequest auth request.
|
||||
type PaasAuthRequest struct {
|
||||
APIToken string `json:"api_token"`
|
||||
PlatformID string `json:"platform_id"`
|
||||
}
|
||||
|
||||
// PaasAuthResponse auth response.
|
||||
type PaasAuthResponse struct {
|
||||
ExcludeDataResponse
|
||||
Data PaasAuthInfo `json:"data"`
|
||||
}
|
||||
|
||||
// PaasAuthInfo auth information.
|
||||
type PaasAuthInfo struct {
|
||||
Token string `json:"token"`
|
||||
PlatformID string `json:"platform_id"`
|
||||
Username string `json:"user_name"`
|
||||
Secret string `json:"secret"`
|
||||
Expired int64 `json:"expired"`
|
||||
Admin bool `json:"admin"`
|
||||
}
|
||||
|
||||
// PaasUpdateMachineNodeRequest update machine request.
|
||||
type PaasUpdateMachineNodeRequest struct {
|
||||
PaasQueryAndDelMachineRequest
|
||||
TreeID []int64 `json:"tree_id"`
|
||||
}
|
||||
|
||||
// NewPaasUpdateMachineNodeRequest new PaasUpdateMachineNodeRequest
|
||||
func NewPaasUpdateMachineNodeRequest(p *PaasQueryAndDelMachineRequest, ns []*MachineNode) *PaasUpdateMachineNodeRequest {
|
||||
var treeIDs []int64
|
||||
for _, n := range ns {
|
||||
treeIDs = append(treeIDs, n.TreeID)
|
||||
}
|
||||
return &PaasUpdateMachineNodeRequest{
|
||||
TreeID: treeIDs,
|
||||
PaasQueryAndDelMachineRequest: *p,
|
||||
}
|
||||
}
|
||||
|
||||
// PaasUpdateMachineNodeResponse update machine response.
|
||||
type PaasUpdateMachineNodeResponse struct {
|
||||
ExcludeDataResponse
|
||||
Data string `json:"data"`
|
||||
}
|
116
app/admin/ep/merlin/model/tree.go
Normal file
116
app/admin/ep/merlin/model/tree.go
Normal file
@ -0,0 +1,116 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const _query = "query"
|
||||
|
||||
// TreeResponse Tree Response.
|
||||
type TreeResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data UserTree `json:"data"`
|
||||
}
|
||||
|
||||
// UserTree User Tree.
|
||||
type UserTree struct {
|
||||
Bilibili map[string]interface{} `json:"bilibili"`
|
||||
}
|
||||
|
||||
// TreeMachinesResponse Tree Machines Response.
|
||||
type TreeMachinesResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data []string `json:"data"`
|
||||
}
|
||||
|
||||
// TreeSonResponse Tree Son Response.
|
||||
type TreeSonResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// TreeRoleResponse Tree Role Response.
|
||||
type TreeRoleResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data []*TreeRole `json:"data"`
|
||||
}
|
||||
|
||||
// TreeInstancesResponse Tree Instance Response.
|
||||
type TreeInstancesResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data map[string]*TreeInstance `json:"data"`
|
||||
}
|
||||
|
||||
// TreeInstance Tree Instance.
|
||||
type TreeInstance struct {
|
||||
HostName string `json:"hostname"`
|
||||
IP string `json:"ip"`
|
||||
InstanceType string `json:"instance_type"`
|
||||
InternalIP string `json:"internal_ip"`
|
||||
ServiceIP string `json:"service_ip"`
|
||||
ExtendIP string `json:"extend_ip"`
|
||||
}
|
||||
|
||||
// TreeAppInstanceRequest Tree App Instance Request.
|
||||
type TreeAppInstanceRequest struct {
|
||||
Paths []string `json:"paths"`
|
||||
}
|
||||
|
||||
// TreeAppInstanceResponse Tree App Instance Response.
|
||||
type TreeAppInstanceResponse struct {
|
||||
Code int `json:"code"`
|
||||
Data map[string][]*TreeAppInstance `json:"data"`
|
||||
}
|
||||
|
||||
// TreeAppInstance Tree App Instance.
|
||||
type TreeAppInstance struct {
|
||||
HostName string `json:"hostname"`
|
||||
}
|
||||
|
||||
// TreePlatformTokenRequest Tree Platform Token Request.
|
||||
type TreePlatformTokenRequest struct {
|
||||
UserName string `json:"user_name"`
|
||||
PlatformID string `json:"platform_id"`
|
||||
}
|
||||
|
||||
// TreeRole Tree Role.
|
||||
type TreeRole struct {
|
||||
UserName string `json:"user_name"`
|
||||
Role int `json:"role"`
|
||||
OldRole int `json:"old_role"`
|
||||
RdSre bool `json:"rd_sre"`
|
||||
}
|
||||
|
||||
// TreeConf tree conf.
|
||||
type TreeConf struct {
|
||||
Host string
|
||||
Key string
|
||||
Secret string
|
||||
}
|
||||
|
||||
// TreeInstanceRequest request for hostname.
|
||||
type TreeInstanceRequest struct {
|
||||
Path string `query:"path"`
|
||||
PathFuzzy string `query:"path_fuzzy"`
|
||||
Hostname string `query:"hostname"`
|
||||
HostnameFuzzy string `query:"hostname_fuzzy"`
|
||||
HostnameRegex string `query:"hostname_regex"`
|
||||
}
|
||||
|
||||
// ToQueryURI convert field to uri.
|
||||
func (tir TreeInstanceRequest) ToQueryURI() string {
|
||||
var (
|
||||
params = &url.Values{}
|
||||
t = reflect.TypeOf(tir)
|
||||
v = reflect.ValueOf(tir)
|
||||
fv string
|
||||
)
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
fv = v.Field(i).Interface().(string)
|
||||
if fv != "" {
|
||||
params.Set(t.Field(i).Tag.Get(_query), fv)
|
||||
}
|
||||
}
|
||||
return params.Encode()
|
||||
}
|
28
app/admin/ep/merlin/model/wechat.go
Normal file
28
app/admin/ep/merlin/model/wechat.go
Normal file
@ -0,0 +1,28 @@
|
||||
package model
|
||||
|
||||
// MsgSendReq message send request of wechat
|
||||
type MsgSendReq struct {
|
||||
Chatid string `json:"chatid" form:"chatid"`
|
||||
Msgtype string `json:"msgtype" form:"msgtype"`
|
||||
Text MsgSendReqText `json:"text" form:"test"`
|
||||
Safe int `json:"safe" form:"safe"`
|
||||
}
|
||||
|
||||
// MsgSendReqText MegSendReq test
|
||||
type MsgSendReqText struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// MsgSendRes message send response
|
||||
type MsgSendRes struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
TTL int `json:"ttl"`
|
||||
Data WechatMegSendResData `json:"data"`
|
||||
}
|
||||
|
||||
// WechatMegSendResData message send response data of wechat
|
||||
type WechatMegSendResData struct {
|
||||
Errcode int `json:"errcode"`
|
||||
Errmsg string `json:"errmsg"`
|
||||
}
|
Reference in New Issue
Block a user