97 lines
4.4 KiB
Go
97 lines
4.4 KiB
Go
package node
|
|
|
|
import (
|
|
"git.inspur.com/sbg-jszt/cfn/cfn-schedule/internal/model"
|
|
"git.inspur.com/sbg-jszt/cfn/cfn-schedule/internal/pkg/secure"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type MachineNode struct {
|
|
model.BaseUserModifyDbModel
|
|
Name string `gorm:"column:name" json:"name"`
|
|
HostName string `gorm:"column:hostname" json:"hostName"`
|
|
OsName string `gorm:"column:os_name" json:"osName"`
|
|
OsOccupyCpu float64 `gorm:"column:os_occupy_cpu" json:"osOccupyCpu"`
|
|
OsOccupyMemory float64 `gorm:"column:os_occupy_memory" json:"osOccupyMemory"`
|
|
OsOccupyDisk float64 `gorm:"column:os_occupy_disk" json:"osOccupyDisk"`
|
|
HostIpv4s string `gorm:"column:host_ipv4s" json:"hostIpv4s"`
|
|
Status int `gorm:"column:status" json:"status,omitempty"` // 假设可以为null
|
|
StatusMsg string `gorm:"column:status_msg" json:"statusMsg"`
|
|
TransportMode int `gorm:"column:transport_mode" json:"transportMode,omitempty"`
|
|
CfnAgentUrl string `gorm:"column:cfn_agent_url" json:"cfnAgentUrl"`
|
|
CfnAgentUsername string `gorm:"column:cfn_agent_username" json:"cfnAgentUsername"`
|
|
CfnAgentPassword string `gorm:"column:cfn_agent_password" json:"cfnAgentPassword"`
|
|
CfnAgentProtocol string `gorm:"column:cfn_agent_protocol" json:"cfnAgentProtocol"`
|
|
CfnAgentTimeout int `gorm:"column:cfn_agent_timeout" json:"cfnAgentTimeout,omitempty"`
|
|
CfnAgentHttpProxy string `gorm:"column:cfn_agent_http_proxy" json:"cfnAgentHttpProxy"`
|
|
CfnAgentHttpProxyType string `gorm:"column:cfn_agent_http_proxy_type" json:"cfnAgentHttpProxyType"`
|
|
CfnAgentVersion string `gorm:"column:cfn_agent_version" json:"cfnAgentVersion"`
|
|
CfnAgentUptime int64 `gorm:"column:cfn_agent_uptime" json:"cfnAgentUptime"`
|
|
CfnAgentBuildTime int64 `gorm:"column:cfn_agent_build_time" json:"cfnAgentBuildTime"`
|
|
CfnAgentProjectCount int `gorm:"column:cfn_agent_project_count" json:"cfnAgentProjectCount,omitempty"`
|
|
CfnAgentScriptCount int `gorm:"column:cfn_agent_script_count" json:"cfnAgentScriptCount,omitempty"`
|
|
JavaVersion string `gorm:"column:java_version" json:"javaVersion"`
|
|
JvmTotalMemory int64 `gorm:"column:jvm_total_memory" json:"jvmTotalMemory,omitempty"`
|
|
JvmFreeMemory int64 `gorm:"column:jvm_free_memory" json:"jvmFreeMemory,omitempty"`
|
|
TemplateNode int `gorm:"column:template_node" json:"templateNode,omitempty"`
|
|
InstallId string `gorm:"column:install_id" json:"installId"`
|
|
TransportEncryption int `gorm:"column:transport_encryption" json:"transportEncryption,omitempty"` // 传输加密方式 0 不加密 1 BASE64 2 AES
|
|
Group string `gorm:"column:group_name" json:"groupName"`
|
|
}
|
|
|
|
func NewMachine() *MachineNode {
|
|
n := &MachineNode{}
|
|
n.Handler = n
|
|
return n
|
|
}
|
|
|
|
func (*MachineNode) TableName() string {
|
|
return "sched_machine_node_info"
|
|
}
|
|
|
|
func (m *MachineNode) ListGroup() ([]string, error) {
|
|
var result []string
|
|
tx := model.DB().Table(m.TableName()).Select("group_name").Distinct().Scan(&result)
|
|
return result, tx.Error
|
|
}
|
|
|
|
func (*MachineNode) FindResult(db *gorm.DB) (interface{}, error) {
|
|
var result []MachineNode
|
|
if db == nil {
|
|
return result, nil
|
|
}
|
|
err := db.Find(&result).Error
|
|
return result, err
|
|
}
|
|
|
|
func (m *MachineNode) Authorize() string {
|
|
return secure.Sha1Encrypt(m.CfnAgentUsername + "@" + m.CfnAgentPassword)
|
|
}
|
|
|
|
// 根据Name查询MachineNode是否存在
|
|
func (m *MachineNode) ExistMachineNodeByName(name string) (bool, error) {
|
|
var count int64
|
|
tx := model.DB().Table(m.TableName()).Where("name = ?", name).Count(&count)
|
|
return count > 0, tx.Error
|
|
}
|
|
|
|
// 根据CfnAgentUrl查询MachineNode是否存在
|
|
func (m *MachineNode) ExistMachineNodeByCfnAgentUrl(url string) (bool, error) {
|
|
var count int64
|
|
tx := model.DB().Table(m.TableName()).Where("cfn_agent_url = ?", url).Count(&count)
|
|
return count > 0, tx.Error
|
|
}
|
|
|
|
// 根据CfnAgentUrl查询MachineNode
|
|
func (m *MachineNode) GetMachineNodeByCfnAgentUrl(url string) (*MachineNode, error) {
|
|
var result MachineNode
|
|
tx := model.DB().Table(m.TableName()).Where("cfn_agent_url = ?", url).First(&result)
|
|
return &result, tx.Error
|
|
}
|
|
|
|
// 更新MachineNode的CfnAgentPassword
|
|
func (m *MachineNode) UpdateMachineNodeCfnAgentPassword(url, password string) error {
|
|
tx := model.DB().Table(m.TableName()).Where("cfn_agent_url = ?", url).Update("cfn_agent_password", password)
|
|
return tx.Error
|
|
}
|