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" "reflect" ) 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"` } func NewInfra(id json.Number, o interface{}) *Infra { ty := reflect.TypeOf(o) var mit meta.MetaInfraType strType := ty.String() if strType == "*infra.InfraMachine" { mit.Id = "1" } else if strType == "*infra.InfraHost" { mit.Id = "2" } else if strType == "*infra.InfraOS" { mit.Id = "3" } else if strType == "*infra.InfraOSApplication" { mit.Id = "4" } else if strType == "*infra.InfraOSDaemon" { mit.Id = "5" } else if strType == "*infra.InfraOSPort" { mit.Id = "6" } else if strType == "*infra.InfraServiceApplication" { mit.Id = "7" } else { return nil } return &Infra{ MetaInfraType:&mit, ChildId:id, } } 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 *InfraServiceApplication) (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 }