fix: primary node failover

This commit is contained in:
2025-08-29 19:06:12 +02:00
parent d7c70cf636
commit ae061bbbc9
3 changed files with 72 additions and 18 deletions

View File

@@ -18,6 +18,7 @@ class PrimaryNodeComponent extends Component {
this.subscribeToProperty('primaryNode', this.render.bind(this));
this.subscribeToProperty('clientInitialized', this.render.bind(this));
this.subscribeToProperty('totalNodes', this.render.bind(this));
this.subscribeToProperty('onlineNodes', this.render.bind(this));
this.subscribeToProperty('error', this.render.bind(this));
}
@@ -25,6 +26,7 @@ class PrimaryNodeComponent extends Component {
const primaryNode = this.viewModel.get('primaryNode');
const clientInitialized = this.viewModel.get('clientInitialized');
const totalNodes = this.viewModel.get('totalNodes');
const onlineNodes = this.viewModel.get('onlineNodes');
const error = this.viewModel.get('error');
if (error) {
@@ -44,7 +46,9 @@ class PrimaryNodeComponent extends Component {
}
const status = clientInitialized ? '✅' : '⚠️';
const nodeCount = totalNodes > 1 ? ` (${totalNodes} nodes)` : '';
const nodeCount = (onlineNodes && onlineNodes > 0)
? ` (${onlineNodes}/${totalNodes} online)`
: (totalNodes > 1 ? ` (${totalNodes} nodes)` : '');
this.setText('#primary-node-ip', `${status} ${primaryNode}${nodeCount}`);
this.setClass('#primary-node-ip', 'error', false);

View File

@@ -13,7 +13,8 @@ class ClusterViewModel extends ViewModel {
error: null,
expandedCards: new Map(),
activeTabs: new Map(), // Store active tab for each node
lastUpdateTime: null
lastUpdateTime: null,
onlineNodes: 0
});
// Initialize cluster status after a short delay to allow components to subscribe
@@ -39,10 +40,16 @@ class ClusterViewModel extends ViewModel {
const response = await window.apiClient.getClusterMembers();
console.log('ClusterViewModel: Got response:', response);
const members = response.members || [];
const onlineNodes = Array.isArray(members)
? members.filter(m => m && m.status === 'active').length
: 0;
// Use batch update to preserve UI state
this.batchUpdate({
members: response.members || [],
lastUpdateTime: new Date().toISOString()
members: members,
lastUpdateTime: new Date().toISOString(),
onlineNodes: onlineNodes
}, { preserveUIState: true });
// Restore expanded cards and active tabs