-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1263 from arenadata/develop
Release 2021.11.17
- Loading branch information
Showing
443 changed files
with
108,688 additions
and
27,989 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package status | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
) | ||
|
||
type StatusHolder struct { | ||
cluster Status | ||
service Status | ||
component Status | ||
host Status | ||
hostComp Status | ||
} | ||
|
||
type StatusEvent struct { | ||
db map[string]StatusHolder | ||
mutex sync.Mutex | ||
} | ||
|
||
func newStatusEvent() *StatusEvent { | ||
return &StatusEvent{ | ||
db: map[string]StatusHolder{}, | ||
} | ||
} | ||
|
||
func (se *StatusEvent) save_hc(h Hub, hostId int, compId int, hc ClusterService) { | ||
sh := fill_hc_status(h, hostId, compId, hc) | ||
se.write(fmt.Sprintf("hc.%d.%d", hostId, compId), sh) | ||
se.write(fmt.Sprintf("cluster.%d", hc.Cluster), sh) | ||
} | ||
|
||
func (se *StatusEvent) save_host(h Hub, hostId int, clusterId int) { | ||
sh := fill_host_status(h, hostId, clusterId) | ||
se.write(fmt.Sprintf("host.%d", hostId), sh) | ||
se.write(fmt.Sprintf("cluster.%d", clusterId), sh) | ||
} | ||
|
||
func (se *StatusEvent) check_hc(h Hub, hostId int, compId int, hc ClusterService) { | ||
key := fmt.Sprintf("hc.%d.%d", hostId, compId) | ||
cluster_key := fmt.Sprintf("cluster.%d", hc.Cluster) | ||
old := se.read(key) | ||
new := fill_hc_status(h, hostId, compId, hc) | ||
if old.hostComp.Status != new.hostComp.Status { | ||
h.EventWS.send2ws(newEventMsg4(new.hostComp.Status, "hostcomponent", hostId, compId)) | ||
} | ||
if old.component.Status != new.component.Status { | ||
h.EventWS.send2ws(newEventMsg(new.component.Status, "component", compId)) | ||
} | ||
if old.service.Status != new.service.Status { | ||
h.EventWS.send2ws(newEventMsg(new.service.Status, "service", hc.Service)) | ||
} | ||
old = se.read(cluster_key) | ||
if old.cluster.Status != new.cluster.Status { | ||
h.EventWS.send2ws(newEventMsg(new.cluster.Status, "cluster", hc.Cluster)) | ||
} | ||
se.write(key, new) | ||
se.write(cluster_key, new) | ||
} | ||
|
||
func (se *StatusEvent) check_host(h Hub, hostId int, clusterId int) { | ||
key := fmt.Sprintf("host.%d", hostId) | ||
cluster_key := fmt.Sprintf("cluster.%d", clusterId) | ||
old := se.read(key) | ||
new := fill_host_status(h, hostId, clusterId) | ||
if old.host.Status != new.host.Status { | ||
h.EventWS.send2ws(newEventMsg(new.host.Status, "host", hostId)) | ||
} | ||
old = se.read(cluster_key) | ||
if old.cluster.Status != new.cluster.Status { | ||
h.EventWS.send2ws(newEventMsg(new.cluster.Status, "cluster", clusterId)) | ||
} | ||
se.write(key, new) | ||
se.write(cluster_key, new) | ||
} | ||
|
||
func (se *StatusEvent) write(key string, sh StatusHolder) { | ||
se.mutex.Lock() | ||
defer se.mutex.Unlock() | ||
se.db[key] = sh | ||
} | ||
|
||
func (se *StatusEvent) read(key string) StatusHolder { | ||
se.mutex.Lock() | ||
defer se.mutex.Unlock() | ||
return se.db[key] | ||
} | ||
|
||
func fill_hc_status(h Hub, hostId int, compId int, hc ClusterService) StatusHolder { | ||
sh := StatusHolder{} | ||
sh.component, _ = getComponentStatus(h, compId) | ||
sh.service, _ = getServiceStatus(h, hc.Cluster, hc.Service) | ||
sh.cluster = getClusterStatus(h, hc.Cluster) | ||
sh.hostComp, _ = h.HostComponentStorage.get(hostId, compId) | ||
return sh | ||
} | ||
|
||
func fill_host_status(h Hub, hostId int, clusterId int) StatusHolder { | ||
ClusterStatus := getClusterStatus(h, clusterId) | ||
HostStatus, _ := h.HostStorage.get(ALL, hostId) | ||
return StatusHolder{ | ||
cluster: ClusterStatus, | ||
host: HostStatus, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.