|
|
|
|
@ -10,12 +10,15 @@ const state = {
|
|
|
|
|
loading: false,
|
|
|
|
|
pendingAction: '',
|
|
|
|
|
outcomeUnknownRegionIds: new Set(),
|
|
|
|
|
operationsByRegion: new Map(),
|
|
|
|
|
operationPollTimer: 0,
|
|
|
|
|
operationPollFailures: 0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const workflowStages = new Set([
|
|
|
|
|
'engine_unavailable', 'no_hosts', 'needs_probe', 'blocked',
|
|
|
|
|
'ready_to_apply', 'needs_reconcile', 'active',
|
|
|
|
|
'migration_required', 'recovery_required',
|
|
|
|
|
'migration_required', 'recovery_required', 'operation_running',
|
|
|
|
|
]);
|
|
|
|
|
const workflowStageCopy = {
|
|
|
|
|
engine_unavailable: {
|
|
|
|
|
@ -45,6 +48,9 @@ const workflowStageCopy = {
|
|
|
|
|
recovery_required: {
|
|
|
|
|
title: '需要恢复固定方案', help: '请按服务端恢复指引处理,向导不会重新生成 desired state。', step: 'reconcile',
|
|
|
|
|
},
|
|
|
|
|
operation_running: {
|
|
|
|
|
title: '宿主机任务执行中', help: '页面正在只读轮询 operation 状态;请勿重复提交。', step: 'apply',
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const stateLabels = {
|
|
|
|
|
@ -85,6 +91,15 @@ const errorLabels = {
|
|
|
|
|
fabric_membership_conflict: '参与宿主机集合冲突',
|
|
|
|
|
fabric_readback_invalid: 'Fabric 回读无效',
|
|
|
|
|
fabric_remote_command_failed: '宿主机远程配置命令失败',
|
|
|
|
|
fabric_operation_busy: '该 Fabric 已有宿主机任务正在执行',
|
|
|
|
|
fabric_operation_invalid: 'Fabric operation 标识或类型无效',
|
|
|
|
|
fabric_operation_limit: '宿主机 Fabric operation 记录已达安全上限',
|
|
|
|
|
fabric_operation_not_found: '宿主机已无法读取该 Fabric operation 状态',
|
|
|
|
|
fabric_operation_reconcile_required: '上次 Fabric operation 结果仍需按原标识核对',
|
|
|
|
|
fabric_operation_status_invalid: '宿主机 Fabric operation 状态记录无效',
|
|
|
|
|
fabric_operation_status_timeout: 'Fabric operation 状态回读超时,请按原标识继续核对',
|
|
|
|
|
fabric_operation_interrupted: 'Fabric operation 协调过程被中断,请按原标识重新核对',
|
|
|
|
|
fabric_readback_mismatch: '宿主机 Fabric 最终回读与固定方案不一致',
|
|
|
|
|
fabric_revision_conflict: 'Fabric revision 冲突',
|
|
|
|
|
};
|
|
|
|
|
const lastErrorPhaseLabels = {
|
|
|
|
|
@ -92,6 +107,32 @@ const lastErrorPhaseLabels = {
|
|
|
|
|
observe: 'observe(回读)',
|
|
|
|
|
apply: 'apply(应用)',
|
|
|
|
|
};
|
|
|
|
|
const operationKindLabels = {
|
|
|
|
|
apply: '自动配置', reconcile: '重新核对', unknown: '未知操作',
|
|
|
|
|
};
|
|
|
|
|
const operationStatusLabels = {
|
|
|
|
|
queued: 'queued(等待执行)', pending: 'pending(等待执行)',
|
|
|
|
|
running: 'running(执行中)', succeeded: 'succeeded(成功)',
|
|
|
|
|
failed: 'failed(失败)', uncertain: 'uncertain(待核对)',
|
|
|
|
|
interrupted: 'interrupted(已中断)', skipped: 'skipped(已跳过)',
|
|
|
|
|
unknown: '未知状态',
|
|
|
|
|
};
|
|
|
|
|
const operationCheckpointLabels = {
|
|
|
|
|
dispatch: '下发任务', host_lock: '宿主机互斥锁', identity: '身份核验',
|
|
|
|
|
journal_recovery: '事务恢复', preflight: '执行前检查', transaction: '事务准备',
|
|
|
|
|
nft_install: '安装 nft 规则', network_activate: '激活网络',
|
|
|
|
|
persistence: '安装持久化恢复', final_readback: '最终回读', complete: '完成',
|
|
|
|
|
unknown: '未知检查点',
|
|
|
|
|
};
|
|
|
|
|
const operationReasonLabels = {
|
|
|
|
|
none: '无', tool_missing: '缺少必要工具', ownership_conflict: '资源归属冲突',
|
|
|
|
|
journal_conflict: '事务记录冲突', firewall_conflict: '防火墙配置冲突',
|
|
|
|
|
underlay_conflict: '传输网络冲突', network_manager_failed: '网络管理器操作失败',
|
|
|
|
|
nft_failed: 'nftables 操作失败', systemd_failed: 'systemd 任务失败',
|
|
|
|
|
readback_failed: '最终回读失败', command_failed: '宿主机命令失败',
|
|
|
|
|
transport_failed: '宿主机传输失败', status_invalid: '状态记录无效',
|
|
|
|
|
unknown: '未识别原因(已隐藏原始值)',
|
|
|
|
|
};
|
|
|
|
|
const reasonLabels = {
|
|
|
|
|
host_disabled: '宿主机未启用',
|
|
|
|
|
host_record_missing: '面板宿主机记录缺失',
|
|
|
|
|
@ -186,6 +227,7 @@ const reasonLabels = {
|
|
|
|
|
platform_gate_failed: '地区或宿主机平台门禁未通过',
|
|
|
|
|
fresh_probe_failed: 'fresh 宿主机检测未通过',
|
|
|
|
|
fabric_reconcile_required: '固定 desired state 需要重新核对',
|
|
|
|
|
fabric_operation_running: 'Fabric 宿主机任务正在执行',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function el(tag, className, value) {
|
|
|
|
|
@ -213,6 +255,48 @@ function lastErrorPhaseLabel(value) {
|
|
|
|
|
return Object.prototype.hasOwnProperty.call(lastErrorPhaseLabels, value)
|
|
|
|
|
? lastErrorPhaseLabels[value] : null;
|
|
|
|
|
}
|
|
|
|
|
function operationOf(value, node = false) {
|
|
|
|
|
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
|
|
|
const id = typeof value.id === 'string' && /^[0-9a-f]{32}$/.test(value.id)
|
|
|
|
|
? value.id : null;
|
|
|
|
|
const rootStates = ['queued', 'running', 'succeeded', 'failed', 'uncertain', 'interrupted'];
|
|
|
|
|
const nodeStates = ['pending', 'running', 'succeeded', 'failed', 'uncertain', 'skipped'];
|
|
|
|
|
const states = node ? nodeStates : rootStates;
|
|
|
|
|
const operation = {
|
|
|
|
|
id,
|
|
|
|
|
status: states.includes(value.status) ? value.status : 'unknown',
|
|
|
|
|
started_at: Number.isInteger(value.started_at) && value.started_at > 0
|
|
|
|
|
? value.started_at : null,
|
|
|
|
|
updated_at: Number.isInteger(value.updated_at) && value.updated_at > 0
|
|
|
|
|
? value.updated_at : null,
|
|
|
|
|
finished_at: Number.isInteger(value.finished_at) && value.finished_at > 0
|
|
|
|
|
? value.finished_at : null,
|
|
|
|
|
};
|
|
|
|
|
if (!node) {
|
|
|
|
|
operation.kind = ['apply', 'reconcile'].includes(value.kind)
|
|
|
|
|
? value.kind : 'unknown';
|
|
|
|
|
return operation;
|
|
|
|
|
}
|
|
|
|
|
operation.phase = Object.prototype.hasOwnProperty.call(lastErrorPhaseLabels, value.phase)
|
|
|
|
|
? value.phase : 'unknown';
|
|
|
|
|
operation.checkpoint = Object.prototype.hasOwnProperty.call(
|
|
|
|
|
operationCheckpointLabels, value.checkpoint) ? value.checkpoint : 'unknown';
|
|
|
|
|
operation.reason = Object.prototype.hasOwnProperty.call(
|
|
|
|
|
operationReasonLabels, value.reason) ? value.reason : 'unknown';
|
|
|
|
|
return operation;
|
|
|
|
|
}
|
|
|
|
|
function operationRunning(operation) {
|
|
|
|
|
return Boolean(operation && ['queued', 'running'].includes(operation.status));
|
|
|
|
|
}
|
|
|
|
|
function operationStatusLabel(value) {
|
|
|
|
|
return operationStatusLabels[value] || operationStatusLabels.unknown;
|
|
|
|
|
}
|
|
|
|
|
function operationForHost(region, host) {
|
|
|
|
|
const rootOperation = operationOf(region && region.operation);
|
|
|
|
|
const hostOperation = operationOf(host && host.operation, true);
|
|
|
|
|
return rootOperation && rootOperation.id && hostOperation
|
|
|
|
|
&& hostOperation.id === rootOperation.id ? hostOperation : null;
|
|
|
|
|
}
|
|
|
|
|
function sysctl(value, enabledValue) {
|
|
|
|
|
if (value === null || value === undefined || value === '' || typeof value === 'boolean') {
|
|
|
|
|
return '未检测';
|
|
|
|
|
@ -425,6 +509,8 @@ function syncControls() {
|
|
|
|
|
const region = selectedRegion();
|
|
|
|
|
const hasRegion = region !== null;
|
|
|
|
|
const workflow = workflowOf(region);
|
|
|
|
|
const currentOperation = operationOf(region && region.operation)
|
|
|
|
|
|| state.operationsByRegion.get(regionIdOf(region)) || null;
|
|
|
|
|
const permissions = {
|
|
|
|
|
probe: workflow.can_probe,
|
|
|
|
|
apply: workflow.can_apply,
|
|
|
|
|
@ -437,11 +523,14 @@ function syncControls() {
|
|
|
|
|
const allowed = outcomeUnknown
|
|
|
|
|
? action === 'reconcile' : permissions[action] === true;
|
|
|
|
|
button.disabled = !canManage || !hasRegion || !allowed
|
|
|
|
|
|| state.loading || state.pendingAction !== '';
|
|
|
|
|
|| state.loading || state.pendingAction !== '' || operationRunning(currentOperation);
|
|
|
|
|
button.setAttribute('aria-disabled', button.disabled ? 'true' : 'false');
|
|
|
|
|
if (!canManage) button.title = '仅超级管理员可以执行此操作';
|
|
|
|
|
else if (!hasRegion) button.title = '请先选择地区';
|
|
|
|
|
else if (state.pendingAction) button.title = '请等待当前操作返回';
|
|
|
|
|
else if (operationRunning(currentOperation)) {
|
|
|
|
|
button.title = '宿主机任务正在执行,请等待只读状态回传';
|
|
|
|
|
}
|
|
|
|
|
else if (outcomeUnknown && action !== 'reconcile') {
|
|
|
|
|
button.title = '上次写操作结果未知,请先重新核对,切勿重复配置';
|
|
|
|
|
} else if (!allowed) button.title = '服务端尚未允许执行此步骤';
|
|
|
|
|
@ -471,12 +560,23 @@ function wizardProgress(stage) {
|
|
|
|
|
}
|
|
|
|
|
function renderWizardSteps(region) {
|
|
|
|
|
const workflow = workflowOf(region);
|
|
|
|
|
const stage = region ? workflow.stage : '';
|
|
|
|
|
const copy = workflowStageCopy[stage] || {
|
|
|
|
|
const trackedOperation = operationOf(region && region.operation)
|
|
|
|
|
|| state.operationsByRegion.get(regionIdOf(region)) || null;
|
|
|
|
|
const stage = region
|
|
|
|
|
? (operationRunning(trackedOperation) ? 'operation_running' : workflow.stage) : '';
|
|
|
|
|
let copy = workflowStageCopy[stage] || {
|
|
|
|
|
title: '请选择地区',
|
|
|
|
|
help: '选择地区后,向导会显示服务端给出的下一步。',
|
|
|
|
|
step: 'select',
|
|
|
|
|
};
|
|
|
|
|
if (stage === 'operation_running' && trackedOperation) {
|
|
|
|
|
copy = {
|
|
|
|
|
...copy,
|
|
|
|
|
help: 'operation ' + text(trackedOperation.id, '标识未确认')
|
|
|
|
|
+ ' 正在执行;页面会自动读取安全阶段状态。',
|
|
|
|
|
step: trackedOperation.kind === 'reconcile' ? 'reconcile' : 'apply',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
const unknown = region && state.outcomeUnknownRegionIds.has(regionIdOf(region));
|
|
|
|
|
byId('fabric-wizard-stage').textContent = unknown ? '操作结果尚未确认' : copy.title;
|
|
|
|
|
byId('fabric-wizard-stage-help').textContent = unknown
|
|
|
|
|
@ -484,7 +584,9 @@ function renderWizardSteps(region) {
|
|
|
|
|
: copy.help;
|
|
|
|
|
|
|
|
|
|
const order = ['select', 'probe', 'apply', 'reconcile'];
|
|
|
|
|
const currentIndex = region ? wizardProgress(stage) : 0;
|
|
|
|
|
const currentIndex = region ? (stage === 'operation_running'
|
|
|
|
|
? (trackedOperation && trackedOperation.kind === 'reconcile' ? 3 : 2)
|
|
|
|
|
: wizardProgress(stage)) : 0;
|
|
|
|
|
document.querySelectorAll('[data-fabric-wizard-step]').forEach(item => {
|
|
|
|
|
const index = order.indexOf(String(item.dataset.fabricWizardStep || ''));
|
|
|
|
|
item.classList.remove('is-complete', 'is-current', 'is-blocked');
|
|
|
|
|
@ -509,15 +611,21 @@ function renderWizardSteps(region) {
|
|
|
|
|
else if (['ready_to_apply', 'needs_reconcile', 'active'].includes(stage)) probeState = '检测已通过';
|
|
|
|
|
else if (stage === 'engine_unavailable') probeState = '引擎不可用';
|
|
|
|
|
else if (stage === 'no_hosts') probeState = '没有宿主机';
|
|
|
|
|
else if (stage === 'operation_running') probeState = '检测已通过';
|
|
|
|
|
byId('fabric-step-probe-state').textContent = probeState;
|
|
|
|
|
byId('fabric-step-apply-state').textContent = stage === 'ready_to_apply'
|
|
|
|
|
? '等待执行' : ['needs_reconcile', 'active'].includes(stage)
|
|
|
|
|
? '等待执行' : stage === 'operation_running'
|
|
|
|
|
? (trackedOperation && trackedOperation.kind === 'reconcile'
|
|
|
|
|
? '固定方案已存在' : '宿主机任务执行中')
|
|
|
|
|
: ['needs_reconcile', 'active'].includes(stage)
|
|
|
|
|
? '已提交固定方案' : stage === 'migration_required'
|
|
|
|
|
? '需要显式迁移' : stage === 'recovery_required'
|
|
|
|
|
? '不能重新生成' : '等待检测通过';
|
|
|
|
|
byId('fabric-step-reconcile-state').textContent = stage === 'active'
|
|
|
|
|
? '权威回读已通过' : ['needs_reconcile', 'recovery_required'].includes(stage)
|
|
|
|
|
? '等待重新核对' : unknown ? '结果未知' : '等待配置';
|
|
|
|
|
? '等待重新核对' : stage === 'operation_running'
|
|
|
|
|
&& trackedOperation && trackedOperation.kind === 'reconcile'
|
|
|
|
|
? '宿主机任务执行中' : unknown ? '结果未知' : '等待配置';
|
|
|
|
|
}
|
|
|
|
|
function renderWizardBlockers(region) {
|
|
|
|
|
const box = byId('fabric-wizard-blockers');
|
|
|
|
|
@ -655,11 +763,23 @@ function renderHosts(region) {
|
|
|
|
|
const fabric = el('td');
|
|
|
|
|
const lastErrorPhase = host.last_error_code
|
|
|
|
|
? lastErrorPhaseLabel(host.last_error_phase) : null;
|
|
|
|
|
const currentHostOperation = operationForHost(region, host);
|
|
|
|
|
const operationLines = currentHostOperation ? [
|
|
|
|
|
'本轮 operation:' + text(currentHostOperation.id),
|
|
|
|
|
'本轮状态:' + operationStatusLabel(currentHostOperation.status),
|
|
|
|
|
'本轮阶段:' + (lastErrorPhaseLabel(currentHostOperation.phase) || '未知阶段'),
|
|
|
|
|
'本轮检查点:' + (operationCheckpointLabels[currentHostOperation.checkpoint]
|
|
|
|
|
|| operationCheckpointLabels.unknown),
|
|
|
|
|
'本轮原因:' + (operationReasonLabels[currentHostOperation.reason]
|
|
|
|
|
|| operationReasonLabels.unknown),
|
|
|
|
|
'本轮更新时间:' + date(currentHostOperation.updated_at),
|
|
|
|
|
] : [];
|
|
|
|
|
fabric.append(compactLines([
|
|
|
|
|
'成员:' + flag(host.fabric_member),
|
|
|
|
|
'状态:' + stateLabel(host.fabric_state),
|
|
|
|
|
'Transport:' + flag(host.transport_verified, '已验证', '未验证'),
|
|
|
|
|
'Observed revision:' + text(host.observed_revision),
|
|
|
|
|
...operationLines,
|
|
|
|
|
...(lastErrorPhase ? ['上次 Fabric 失败阶段:' + lastErrorPhase] : []),
|
|
|
|
|
]));
|
|
|
|
|
row.append(identity, platform, probe, manager, wireguard, publicPath, fabric,
|
|
|
|
|
@ -678,6 +798,8 @@ function renderReadback(region) {
|
|
|
|
|
const conflicts = Array.isArray(region.fabric_conflicts)
|
|
|
|
|
? region.fabric_conflicts.filter(item => item && item.fabric_id).slice(0, 8)
|
|
|
|
|
: [];
|
|
|
|
|
const operation = operationOf(region.operation)
|
|
|
|
|
|| state.operationsByRegion.get(regionIdOf(region)) || null;
|
|
|
|
|
const values = [
|
|
|
|
|
['Fabric ID', text(region.fabric_id, '尚未自动配置')],
|
|
|
|
|
['Fabric 地区', text(region.fabric_region)],
|
|
|
|
|
@ -690,6 +812,16 @@ function renderReadback(region) {
|
|
|
|
|
['未映射 Fabric 冲突', conflicts.length
|
|
|
|
|
? conflicts.map(item => String(item.fabric_id)).join('、')
|
|
|
|
|
: '无'],
|
|
|
|
|
['本轮 operation', operation ? text(operation.id, '标识无效') : '无'],
|
|
|
|
|
['本轮操作 / 状态', operation
|
|
|
|
|
? (operationKindLabels[operation.kind] || operationKindLabels.unknown)
|
|
|
|
|
+ ' / ' + operationStatusLabel(operation.status)
|
|
|
|
|
: '无'],
|
|
|
|
|
['本轮更新时间', operation ? date(operation.updated_at) : '无'],
|
|
|
|
|
['宿主机日志命令', operation && operation.id
|
|
|
|
|
? 'journalctl --utc -u virt-cloud-fabric-apply-' + operation.id
|
|
|
|
|
+ '.service --no-pager -o short-iso-precise'
|
|
|
|
|
: '无'],
|
|
|
|
|
];
|
|
|
|
|
values.forEach(pair => {
|
|
|
|
|
const column = el('div', 'col-sm-6 col-xl-3');
|
|
|
|
|
@ -740,6 +872,114 @@ function mergeRegionProjection(region) {
|
|
|
|
|
else state.regions[index] = region;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
function rememberOperation(regionId, value) {
|
|
|
|
|
const operation = operationOf(value);
|
|
|
|
|
if (!regionId || !operation || !operation.id) return null;
|
|
|
|
|
if (operationRunning(operation)) state.operationsByRegion.set(regionId, operation);
|
|
|
|
|
else state.operationsByRegion.delete(regionId);
|
|
|
|
|
return operation;
|
|
|
|
|
}
|
|
|
|
|
function adoptRegionOperations() {
|
|
|
|
|
state.regions.forEach(region => {
|
|
|
|
|
const regionId = regionIdOf(region);
|
|
|
|
|
const operation = operationOf(region.operation);
|
|
|
|
|
if (operation && operation.id) rememberOperation(regionId, operation);
|
|
|
|
|
});
|
|
|
|
|
if (state.operationsByRegion.size) scheduleOperationPoll();
|
|
|
|
|
}
|
|
|
|
|
function scheduleOperationPoll(delay = 2000) {
|
|
|
|
|
if (state.operationPollTimer || !state.operationsByRegion.size) return;
|
|
|
|
|
state.operationPollTimer = window.setTimeout(() => {
|
|
|
|
|
state.operationPollTimer = 0;
|
|
|
|
|
pollOperations();
|
|
|
|
|
}, delay);
|
|
|
|
|
}
|
|
|
|
|
function terminalOperationMessage(region, operation) {
|
|
|
|
|
const prefix = regionName(region) + ':operation ' + operation.id + ' ';
|
|
|
|
|
if (operation.status === 'succeeded') {
|
|
|
|
|
return {
|
|
|
|
|
kind: 'success',
|
|
|
|
|
text: prefix + (region && region.ready === true
|
|
|
|
|
? '已成功并通过全部门禁。'
|
|
|
|
|
: operation.kind === 'apply'
|
|
|
|
|
? '宿主机任务已成功;请按当前向导重新检测并完成地区映射核对。'
|
|
|
|
|
: '宿主机任务已成功;请按当前向导完成最终回读确认。'),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
kind: 'error',
|
|
|
|
|
text: prefix + operationStatusLabel(operation.status)
|
|
|
|
|
+ ';请查看宿主机清单中的阶段、检查点和安全原因。',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
async function pollOperations() {
|
|
|
|
|
if (!state.operationsByRegion.size) return;
|
|
|
|
|
try {
|
|
|
|
|
const payload = await api('/api/v1/admin/fabric');
|
|
|
|
|
const regions = regionsOf(payload);
|
|
|
|
|
if (payload && payload.engine_available === false) {
|
|
|
|
|
throw new Error(text(payload.engine_error, 'Fabric 引擎状态暂时无法读取。'));
|
|
|
|
|
}
|
|
|
|
|
// An empty list is still an authoritative successful projection. If a
|
|
|
|
|
// region disappears while an operation is being tracked, retaining the
|
|
|
|
|
// previous list would poll that stale operation forever instead of
|
|
|
|
|
// stopping with an outcome-unknown readback.
|
|
|
|
|
state.regions = regions;
|
|
|
|
|
renderRegionOptions(state.regions);
|
|
|
|
|
state.operationPollFailures = 0;
|
|
|
|
|
const terminal = [];
|
|
|
|
|
const mismatched = [];
|
|
|
|
|
for (const [regionId, tracked] of [...state.operationsByRegion.entries()]) {
|
|
|
|
|
const region = state.regions.find(item => regionIdOf(item) === regionId) || null;
|
|
|
|
|
const observed = operationOf(region && region.operation);
|
|
|
|
|
if (!observed || observed.id !== tracked.id) {
|
|
|
|
|
// The tracked write can no longer be correlated to the authoritative
|
|
|
|
|
// projection. Stop polling this stale ID and require a fresh, explicit
|
|
|
|
|
// readback; never adopt a replacement operation or submit another POST.
|
|
|
|
|
state.operationsByRegion.delete(regionId);
|
|
|
|
|
state.outcomeUnknownRegionIds.add(regionId);
|
|
|
|
|
mismatched.push({ region, operation: tracked });
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (operationRunning(observed)) {
|
|
|
|
|
state.operationsByRegion.set(regionId, observed);
|
|
|
|
|
} else {
|
|
|
|
|
state.operationsByRegion.delete(regionId);
|
|
|
|
|
state.outcomeUnknownRegionIds.delete(regionId);
|
|
|
|
|
terminal.push({ region, operation: observed });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
renderSelectedRegion();
|
|
|
|
|
const selectedTerminal = terminal.find(item =>
|
|
|
|
|
regionIdOf(item.region) === state.selectedRegionId);
|
|
|
|
|
const selectedMismatch = mismatched.find(item =>
|
|
|
|
|
regionIdOf(item.region) === state.selectedRegionId);
|
|
|
|
|
if (selectedMismatch) {
|
|
|
|
|
notice(regionName(selectedMismatch.region) + ':operation '
|
|
|
|
|
+ selectedMismatch.operation.id
|
|
|
|
|
+ ' 已无法与服务端当前回读对应;已停止自动轮询,且不会重复提交。请刷新后按向导重新核对。',
|
|
|
|
|
'error');
|
|
|
|
|
} else if (selectedTerminal) {
|
|
|
|
|
const message = terminalOperationMessage(
|
|
|
|
|
selectedTerminal.region, selectedTerminal.operation
|
|
|
|
|
);
|
|
|
|
|
notice(message.text, message.kind);
|
|
|
|
|
} else if (state.operationsByRegion.has(state.selectedRegionId)) {
|
|
|
|
|
const operation = state.operationsByRegion.get(state.selectedRegionId);
|
|
|
|
|
notice(regionName(selectedRegion()) + ':operation ' + operation.id
|
|
|
|
|
+ ' ' + operationStatusLabel(operation.status) + ';正在自动读取状态。');
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
state.operationPollFailures += 1;
|
|
|
|
|
if (state.operationPollFailures >= 12) {
|
|
|
|
|
notice('Fabric operation 状态连续读取失败;任务不会被重复提交,请刷新页面继续只读核对。', 'error');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (state.operationsByRegion.size) {
|
|
|
|
|
scheduleOperationPoll(state.operationPollFailures ? 5000 : 2000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function applyActionProjection(payload, originRegionId, originSelectionVersion) {
|
|
|
|
|
const regions = regionsOf(payload);
|
|
|
|
|
let applied = false;
|
|
|
|
|
@ -766,6 +1006,7 @@ async function load() {
|
|
|
|
|
if (version !== state.loadVersion) return false;
|
|
|
|
|
state.regions = regionsOf(payload);
|
|
|
|
|
renderRegionOptions(state.regions);
|
|
|
|
|
adoptRegionOperations();
|
|
|
|
|
if (payload && payload.engine_available === false) {
|
|
|
|
|
notice(text(payload.engine_error,
|
|
|
|
|
'Fabric 引擎状态暂时无法读取。'), 'error');
|
|
|
|
|
@ -848,19 +1089,40 @@ async function runRegionAction(action) {
|
|
|
|
|
try {
|
|
|
|
|
const payload = await api('/api/v1/admin/fabric/regions/' + encodeURIComponent(regionId) + '/' + action,
|
|
|
|
|
{ method: 'POST', body: '{}' });
|
|
|
|
|
if (!applyActionProjection(payload, regionId, originSelectionVersion)
|
|
|
|
|
&& !(await load())) {
|
|
|
|
|
throw new Error('操作响应已返回,但最新 readiness 未能读取,请使用“重新核对”确认状态。');
|
|
|
|
|
}
|
|
|
|
|
if (payload && payload.engine_available === false) {
|
|
|
|
|
throw new Error(text(payload.engine_error,
|
|
|
|
|
'操作已返回,但 Fabric 引擎最新状态无法读取;请稍后重新核对。'));
|
|
|
|
|
}
|
|
|
|
|
const projected = state.regions.find(item => regionIdOf(item) === regionId) || null;
|
|
|
|
|
const appliedProjection = applyActionProjection(
|
|
|
|
|
payload, regionId, originSelectionVersion
|
|
|
|
|
);
|
|
|
|
|
let projected = state.regions.find(item => regionIdOf(item) === regionId) || null;
|
|
|
|
|
const acceptedOperation = operationOf(payload && payload.operation);
|
|
|
|
|
if (acceptedOperation && acceptedOperation.id && projected) {
|
|
|
|
|
state.outcomeUnknownRegionIds.delete(regionId);
|
|
|
|
|
projected.operation = acceptedOperation;
|
|
|
|
|
rememberOperation(regionId, acceptedOperation);
|
|
|
|
|
if (state.selectedRegionId === regionId) renderSelectedRegion();
|
|
|
|
|
if (operationRunning(acceptedOperation)) {
|
|
|
|
|
scheduleOperationPoll();
|
|
|
|
|
notice(originName + ':已受理 operation ' + acceptedOperation.id
|
|
|
|
|
+ ',宿主机任务将异步执行;页面正在只读轮询状态。', 'success');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!appliedProjection && !(await load())) {
|
|
|
|
|
throw new Error('操作响应已返回,但最新 readiness 未能读取,请使用“重新核对”确认状态。');
|
|
|
|
|
}
|
|
|
|
|
projected = state.regions.find(item => regionIdOf(item) === regionId) || null;
|
|
|
|
|
if (!projected) {
|
|
|
|
|
throw new Error('操作已返回,但目标地区的权威状态缺失,请刷新后重新核对。');
|
|
|
|
|
}
|
|
|
|
|
state.outcomeUnknownRegionIds.delete(regionId);
|
|
|
|
|
if (acceptedOperation && acceptedOperation.id) {
|
|
|
|
|
const terminal = terminalOperationMessage(projected, acceptedOperation);
|
|
|
|
|
notice(terminal.text, terminal.kind);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (state.selectedRegionId === regionId) renderSelectedRegion();
|
|
|
|
|
const outcome = actionOutcome(action, projected);
|
|
|
|
|
const suffix = state.selectionVersion === originSelectionVersion
|
|
|
|
|
|