| | |
| | | package service |
| | | |
| | | import ( |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/bhomeclient.git" |
| | | "basic.com/valib/bhomedbapi.git" |
| | | "encoding/json" |
| | | "time" |
| | | "vamicro/config" |
| | | "vamicro/extend/util" |
| | | "vamicro/system-service/models" |
| | | ) |
| | | |
| | | type ResourceConfigService struct { |
| | | |
| | | } |
| | | |
| | | func WatchEsAndWeedfsIp(bk bhomeclient.Broker) { |
| | | for { |
| | | initEsAndWeedfsIp(bk) |
| | | |
| | | InitAppPermissions() |
| | | |
| | | time.Sleep(3 * time.Second) |
| | | } |
| | | } |
| | | |
| | | func initEsAndWeedfsIp(bk bhomeclient.Broker) { |
| | | devTyp := GetDevType(config.Server.DeviceType) |
| | | bp := false |
| | | if devTyp == DevType_Analysis { //只做分析(盒子),盒子必须加入集群才能正常工作 |
| | | var clusterE models.Cluster |
| | | clusters, err := clusterE.FindAll() |
| | | if err ==nil && clusters !=nil && len(clusters) >0 { |
| | | c := clusters[0] |
| | | var nodeE models.Node |
| | | nodes, e := nodeE.FindNodesByClusterId(c.ClusterId) |
| | | if e == nil && nodes !=nil && len(nodes) >0 { |
| | | var ipArr []string |
| | | for _,n :=range nodes { |
| | | if !n.IsDelete { |
| | | typ := GetDevType(n.DeviceType) |
| | | if typ == DevType_Storage || typ == DevType_Analysis_Storage { |
| | | if ip,b := util.IpCheck(n.NodeIp);b { |
| | | ipArr = append(ipArr, ip) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if len(ipArr) > 0 { |
| | | var localConf models.LocalConfig |
| | | err := localConf.Select() |
| | | if err == nil { |
| | | found := false |
| | | for _,ipStr := range ipArr { |
| | | if ipStr == localConf.AlarmIp { |
| | | found = true |
| | | break |
| | | } |
| | | } |
| | | if !found { //当前设置的ip不可用,设置一个新的ip |
| | | localConf.AlarmIp = ipArr[0] |
| | | localConf.WebPicIp = ipArr[0] |
| | | localConf.Update() |
| | | bp = true |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } else if devTyp == DevType_Storage || devTyp == DevType_Analysis_Storage { //分析带存储或者只存储,取本机即可 |
| | | localIp, _, _ := util.GetLocalIP(config.Server.NetworkAdapter) |
| | | if localIp != "" { |
| | | var localConf models.LocalConfig |
| | | err := localConf.Select() |
| | | if err == nil { |
| | | if localConf.AlarmIp != localIp || localConf.WebPicIp != localIp { |
| | | localConf.AlarmIp = localIp |
| | | localConf.WebPicIp = localIp |
| | | localConf.Update() |
| | | bp = true |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if bp { |
| | | pMsg := protomsg.DbChangeMessage{ |
| | | Table:protomsg.TableChanged_T_Server, |
| | | Action:protomsg.DbAction_Update, |
| | | } |
| | | pb, _ := json.Marshal(pMsg) |
| | | bk.Publish(ProcName, pb) |
| | | } |
| | | } |
| | | |
| | | func (rcs *ResourceConfigService) Save(reqBody models.ResourceConfig) bool { |
| | | b := false |
| | | if reqBody.IpType == models.IpType_Local { |
| | | localIp, _, _ := util.GetLocalIP(config.Server.NetworkAdapter) |
| | | if localIp != reqBody.ServiceIp { |
| | | reqBody.ServiceIp = localIp |
| | | } |
| | | } |
| | | |
| | | var tmpConfig models.ResourceConfig |
| | | err := tmpConfig.Select() |
| | | if err == nil { |
| | | if reqBody.Update() { |
| | | b = true |
| | | } |
| | | } else { |
| | | if reqBody.Insert() { |
| | | b = true |
| | | } |
| | | } |
| | | if b { |
| | | gbIp := reqBody.ServiceIp //要么是本机ip,要么是漂移ip |
| | | if gbIp != "" { |
| | | //判断是否需要刷新国标,条件国标服务ip有变化 |
| | | var gbApi bhomedbapi.Gb28181Api |
| | | flag, gbConfig := gbApi.Show() |
| | | if flag { |
| | | gbApi.Gb28181TreeRefresh(gbConfig.Id) |
| | | } |
| | | } |
| | | } |
| | | return b |
| | | } |
| | | package service
|
| | |
|
| | | import (
|
| | | "basic.com/pubsub/protomsg.git"
|
| | | "basic.com/valib/bhomeclient.git"
|
| | | "basic.com/valib/bhomedbapi.git"
|
| | | "encoding/json"
|
| | | "time"
|
| | | "vamicro/config"
|
| | | "vamicro/extend/util"
|
| | | "vamicro/system-service/models"
|
| | | )
|
| | |
|
| | | type ResourceConfigService struct {
|
| | |
|
| | | }
|
| | |
|
| | | func WatchEsAndWeedfsIp(bk bhomeclient.Broker) {
|
| | | for {
|
| | | initEsAndWeedfsIp(bk)
|
| | |
|
| | | InitAppPermissions()
|
| | |
|
| | | time.Sleep(3 * time.Second)
|
| | | }
|
| | | }
|
| | |
|
| | | func initEsAndWeedfsIp(bk bhomeclient.Broker) {
|
| | | devTyp := GetDevType(config.Server.DeviceType)
|
| | | bp := false
|
| | | if devTyp == DevType_Analysis { //只做分析(盒子),盒子必须加入集群才能正常工作
|
| | | var clusterE models.Cluster
|
| | | clusters, err := clusterE.FindAll()
|
| | | if err ==nil && clusters !=nil && len(clusters) >0 {
|
| | | c := clusters[0]
|
| | | var nodeE models.Node
|
| | | nodes, e := nodeE.FindNodesByClusterId(c.ClusterId)
|
| | | if e == nil && nodes !=nil && len(nodes) >0 {
|
| | | var ipArr []string
|
| | | for _,n :=range nodes {
|
| | | if !n.IsDelete {
|
| | | typ := GetDevType(n.DeviceType)
|
| | | if typ == DevType_Storage || typ == DevType_Analysis_Storage {
|
| | | if ip,b := util.IpCheck(n.NodeIp);b {
|
| | | ipArr = append(ipArr, ip)
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | if len(ipArr) > 0 {
|
| | | var localConf models.LocalConfig
|
| | | err := localConf.Select()
|
| | | if err == nil {
|
| | | found := false
|
| | | for _,ipStr := range ipArr {
|
| | | if ipStr == localConf.AlarmIp {
|
| | | found = true
|
| | | break
|
| | | }
|
| | | }
|
| | | if !found { //当前设置的ip不可用,设置一个新的ip
|
| | | localConf.AlarmIp = ipArr[0]
|
| | | localConf.WebPicIp = ipArr[0]
|
| | | localConf.Update()
|
| | | bp = true
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | } else if devTyp == DevType_Storage || devTyp == DevType_Analysis_Storage { //分析带存储或者只存储,取本机即可
|
| | | localIp, _, _ := util.GetLocalIP(config.Server.NetworkAdapter)
|
| | | if localIp != "" {
|
| | | var localConf models.LocalConfig
|
| | | err := localConf.Select()
|
| | | if err == nil {
|
| | | if localConf.AlarmIp != localIp || localConf.WebPicIp != localIp {
|
| | | localConf.AlarmIp = localIp
|
| | | localConf.WebPicIp = localIp
|
| | | localConf.Update()
|
| | | bp = true
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | if bp {
|
| | | pMsg := protomsg.DbChangeMessage{
|
| | | Table:protomsg.TableChanged_T_Server,
|
| | | Action:protomsg.DbAction_Update,
|
| | | }
|
| | | pb, _ := json.Marshal(pMsg)
|
| | | bk.Publish(ProcName, pb)
|
| | | }
|
| | | }
|
| | |
|
| | | func (rcs *ResourceConfigService) Save(reqBody models.ResourceConfig) bool {
|
| | | b := false
|
| | | if reqBody.IpType == models.IpType_Local {
|
| | | localIp, _, _ := util.GetLocalIP(config.Server.NetworkAdapter)
|
| | | if localIp != reqBody.ServiceIp {
|
| | | reqBody.ServiceIp = localIp
|
| | | }
|
| | | }
|
| | |
|
| | | var tmpConfig models.ResourceConfig
|
| | | err := tmpConfig.Select()
|
| | | if err == nil {
|
| | | if reqBody.Update() {
|
| | | b = true
|
| | | }
|
| | | } else {
|
| | | if reqBody.Insert() {
|
| | | b = true
|
| | | }
|
| | | }
|
| | | if b {
|
| | | gbIp := reqBody.ServiceIp //要么是本机ip,要么是漂移ip
|
| | | if gbIp != "" {
|
| | | //判断是否需要刷新国标,条件国标服务ip有变化
|
| | | var gbApi bhomedbapi.Gb28181Api
|
| | | flag, gbConfig := gbApi.Show()
|
| | | if flag {
|
| | | gbApi.Gb28181TreeRefresh(gbConfig.Id)
|
| | | }
|
| | | }
|
| | | }
|
| | | return b
|
| | | }
|