183 lines
5.1 KiB
Go
183 lines
5.1 KiB
Go
package infra
|
|
|
|
import (
|
|
"encoding/json"
|
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
|
"git.loafle.net/overflow/overflow_service/proxy/meta"
|
|
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
|
"git.loafle.net/overflow/overflow_service/proxy/utils"
|
|
)
|
|
|
|
type InfraService struct {
|
|
}
|
|
|
|
type Infra struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
MetaInfraType meta.MetaInfraType `json:"type,omitempty"`
|
|
ChildId json.Number `json:"childId,omitempty"`
|
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
}
|
|
|
|
type InfraMachine struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
Probe probe.Probe `json:"probe,omitempty"`
|
|
Meta string `json:"meta,omitempty"`
|
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
}
|
|
|
|
type InfraHost struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
InfraOS InfraOS `json:"os,omitempty"`
|
|
Ip json.Number `json:"ip,omitempty"`
|
|
Mac json.Number `json:"mac,omitempty"`
|
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
}
|
|
|
|
type InfraOS struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
InfraMachine InfraMachine `json:"machine,omitempty"`
|
|
Meta string `json:"meta,omitempty"`
|
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
MetaInfraVendor meta.MetaInfraVendor `json:"vendor,omitempty"`
|
|
}
|
|
|
|
type InfraOSApplication struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
InfraOS InfraOS `json:"os,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
}
|
|
|
|
type InfraOSDaemon struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
InfraOS InfraOS `json:"os,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
}
|
|
|
|
type InfraOSPort struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
InfraOS InfraOS `json:"os,omitempty"`
|
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
Port json.Number `json:"port,omitempty"`
|
|
PortType string `json:"portType,omitempty"`
|
|
MetaInfraVendor meta.MetaInfraVendor `json:"vendor,omitempty"`
|
|
TlsType bool `json:"tlsType,omitempty"`
|
|
}
|
|
|
|
type InfraServiceApplication struct {
|
|
Id json.Number `json:"id,Number,omitempty"`
|
|
InfraHost InfraHost `json:"host,omitempty"`
|
|
PortType string `json:"portType,omitempty"`
|
|
Port json.Number `json:"port,omitempty"`
|
|
MetaInfraVendor meta.MetaInfraVendor `json:"vendor,omitempty"`
|
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
TlsType bool `json:"tlsType,omitempty"`
|
|
}
|
|
|
|
func NewInfraService() *InfraService {
|
|
return &InfraService{}
|
|
}
|
|
|
|
func (is *InfraService) Regist(infra *Infra) (string, error) {
|
|
out, err := utils.InvokeDBByModel("infra", "save", infra, utils.MODEL_INFRA)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (is *InfraService) RegistMachine(i *InfraMachine) (string, error) {
|
|
out, err := utils.InvokeDBByModel("infraMachine", "save", i, utils.MODEL_INFRA_MACHINE)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (is *InfraService) RegistHost(i *InfraHost) (string, error) {
|
|
out, err := utils.InvokeDBByModel("infraHost", "save", i, utils.MODEL_INFRA_HOST)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (is *InfraService) RegistOS(i *InfraOS) (string, error) {
|
|
out, err := utils.InvokeDBByModel("InfraOS", "save", i, utils.MODEL_INFRA_OS)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (is *InfraService) RegistOSApplication(i *InfraOSApplication) (string, error) {
|
|
out, err := utils.InvokeDBByModel("InfraOSApplication", "save", i, utils.MODEL_INFRA_OS_APPLICATION)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (is *InfraService) RegistOSDaemon(i *InfraOSDaemon) (string, error) {
|
|
out, err := utils.InvokeDBByModel("InfraOSDaemon", "save", i, utils.MODEL_INFRA_OS_DAEMON)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (is *InfraService) RegistOSPort(i *InfraOSPort) (string, error) {
|
|
out, err := utils.InvokeDBByModel("InfraOSPort", "save", i, utils.MODEL_INFRA_OS_PORT)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (is *InfraService) RegistService(i *InfraService) (string, error) {
|
|
out, err := utils.InvokeDBByModel("InfraService", "save", i, utils.MODEL_INFRA_SERVICE)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (is *InfraService) Read(id string) (string, error) {
|
|
|
|
out, err := utils.InvokeDBByModel("infra", "findOne", id, utils.MODEL_LONG)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|
|
|
|
func (is *InfraService) ReadChild(infraType, id string) (string, error) {
|
|
|
|
out, err := utils.InvokeDBByModel(infraType, "findOne", id, utils.MODEL_LONG)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return out, nil
|
|
}
|