@@ -26,10 +26,6 @@ func getNodeStatusOld(node *models.Node) {
26
26
27
27
func GetNodeStatus (node * models.Node , defaultEnabledPolicy bool ) {
28
28
29
- if time .Since (node .LastCheckIn ) > models .LastCheckInThreshold {
30
- node .Status = models .OfflineSt
31
- return
32
- }
33
29
if node .IsStatic {
34
30
if ! node .StaticNode .Enabled {
35
31
node .Status = models .OfflineSt
@@ -53,6 +49,10 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {
53
49
node .Status = models .UnKnown
54
50
return
55
51
}
52
+ if time .Since (node .LastCheckIn ) > models .LastCheckInThreshold {
53
+ node .Status = models .OfflineSt
54
+ return
55
+ }
56
56
host , err := logic .GetHost (node .HostID .String ())
57
57
if err != nil {
58
58
node .Status = models .UnKnown
@@ -71,11 +71,15 @@ func GetNodeStatus(node *models.Node, defaultEnabledPolicy bool) {
71
71
if err != nil {
72
72
return
73
73
}
74
- if metrics == nil || metrics .Connectivity == nil {
74
+ if metrics == nil || metrics .Connectivity == nil || len ( metrics . Connectivity ) == 0 {
75
75
if time .Since (node .LastCheckIn ) < models .LastCheckInThreshold {
76
76
node .Status = models .OnlineSt
77
77
return
78
78
}
79
+ if node .LastCheckIn .IsZero () {
80
+ node .Status = models .OfflineSt
81
+ return
82
+ }
79
83
}
80
84
// if node.IsFailOver {
81
85
// if time.Since(node.LastCheckIn) < models.LastCheckInThreshold {
@@ -133,9 +137,12 @@ func checkPeerStatus(node *models.Node, defaultAclPolicy bool) {
133
137
if err != nil {
134
138
continue
135
139
}
136
- allowed , _ := logic .IsNodeAllowedToCommunicate (* node , peer , false )
137
- if ! defaultAclPolicy && ! allowed {
138
- continue
140
+
141
+ if ! defaultAclPolicy {
142
+ allowed , _ := logic .IsNodeAllowedToCommunicate (* node , peer , false )
143
+ if ! allowed {
144
+ continue
145
+ }
139
146
}
140
147
141
148
if time .Since (peer .LastCheckIn ) > models .LastCheckInThreshold {
@@ -154,7 +161,7 @@ func checkPeerStatus(node *models.Node, defaultAclPolicy bool) {
154
161
node .Status = models .OnlineSt
155
162
return
156
163
}
157
- if peerNotConnectedCnt == len (metrics .Connectivity ) {
164
+ if len ( metrics . Connectivity ) > 0 && peerNotConnectedCnt == len (metrics .Connectivity ) {
158
165
node .Status = models .ErrorSt
159
166
return
160
167
}
@@ -168,9 +175,12 @@ func checkPeerConnectivity(node *models.Node, metrics *models.Metrics, defaultAc
168
175
if err != nil {
169
176
continue
170
177
}
171
- allowed , _ := logic .IsNodeAllowedToCommunicate (* node , peer , false )
172
- if ! defaultAclPolicy && ! allowed {
173
- continue
178
+
179
+ if ! defaultAclPolicy {
180
+ allowed , _ := logic .IsNodeAllowedToCommunicate (* node , peer , false )
181
+ if ! allowed {
182
+ continue
183
+ }
174
184
}
175
185
176
186
if time .Since (peer .LastCheckIn ) > models .LastCheckInThreshold {
@@ -181,19 +191,22 @@ func checkPeerConnectivity(node *models.Node, metrics *models.Metrics, defaultAc
181
191
}
182
192
// check if peer is in error state
183
193
checkPeerStatus (& peer , defaultAclPolicy )
184
- if peer .Status == models .ErrorSt {
194
+ if peer .Status == models .ErrorSt || peer . Status == models . WarningSt {
185
195
continue
186
196
}
187
197
peerNotConnectedCnt ++
188
198
189
199
}
190
- if peerNotConnectedCnt == 0 {
191
- node .Status = models .OnlineSt
200
+ if peerNotConnectedCnt > len ( metrics . Connectivity ) / 2 {
201
+ node .Status = models .WarningSt
192
202
return
193
203
}
194
- if peerNotConnectedCnt == len (metrics .Connectivity ) {
204
+
205
+ if len (metrics .Connectivity ) > 0 && peerNotConnectedCnt == len (metrics .Connectivity ) {
195
206
node .Status = models .ErrorSt
196
207
return
197
208
}
198
- node .Status = models .WarningSt
209
+
210
+ node .Status = models .OnlineSt
211
+
199
212
}
0 commit comments