feat(collect): remove power-on/off, add skip-hung for Redfish collection
Remove power-on and power-off functionality from the Redfish collector;
keep host power-state detection and show a warning in the UI when the
host is powered off before collection starts.
Add a "Пропустить зависшие" (skip hung) button that lets the user abort
stuck Redfish collection phases without losing already-collected data.
Introduces a two-level context model in Collect(): the outer job context
covers the full lifecycle including replay; an inner collectCtx covers
snapshot, prefetch, and plan-B phases only. Closing the skipCh cancels
collectCtx immediately — aborts all in-flight HTTP requests and exits
plan-B loops — then replay runs on whatever rawTree was collected.
Signal path: UI → POST /api/collect/{id}/skip → JobManager.SkipJob()
→ close(skipCh) → goroutine in Collect() → cancelCollect().
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -211,8 +211,6 @@ main {
|
||||
}
|
||||
|
||||
#api-connect-btn,
|
||||
#api-power-on-collect-btn,
|
||||
#api-collect-off-btn,
|
||||
#convert-folder-btn,
|
||||
#convert-run-btn,
|
||||
#cancel-job-btn,
|
||||
@@ -229,8 +227,6 @@ main {
|
||||
}
|
||||
|
||||
#api-connect-btn:hover,
|
||||
#api-power-on-collect-btn:hover,
|
||||
#api-collect-off-btn:hover,
|
||||
#convert-folder-btn:hover,
|
||||
#convert-run-btn:hover,
|
||||
#cancel-job-btn:hover,
|
||||
@@ -241,8 +237,6 @@ main {
|
||||
#convert-run-btn:disabled,
|
||||
#convert-folder-btn:disabled,
|
||||
#api-connect-btn:disabled,
|
||||
#api-power-on-collect-btn:disabled,
|
||||
#api-collect-off-btn:disabled,
|
||||
#cancel-job-btn:disabled,
|
||||
.upload-area button:disabled {
|
||||
opacity: 0.6;
|
||||
@@ -311,64 +305,19 @@ main {
|
||||
border-top: 1px solid #e2e8f0;
|
||||
}
|
||||
|
||||
.api-confirm-modal-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
.api-host-off-warning {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.api-confirm-modal {
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
padding: 1.5rem 1.75rem;
|
||||
max-width: 380px;
|
||||
width: 90%;
|
||||
box-shadow: 0 8px 32px rgba(0,0,0,0.18);
|
||||
}
|
||||
|
||||
.api-confirm-modal p {
|
||||
margin-bottom: 1.1rem;
|
||||
font-size: 0.95rem;
|
||||
color: #333;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.api-confirm-modal-actions {
|
||||
display: flex;
|
||||
gap: 0.6rem;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.api-confirm-modal-actions button {
|
||||
border: none;
|
||||
gap: 0.4rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background: #fef3c7;
|
||||
border: 1px solid #f59e0b;
|
||||
border-radius: 6px;
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
font-size: 0.875rem;
|
||||
color: #92400e;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.api-confirm-modal-actions .btn-cancel {
|
||||
background: #e2e8f0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.api-confirm-modal-actions .btn-cancel:hover {
|
||||
background: #cbd5e1;
|
||||
}
|
||||
|
||||
.api-confirm-modal-actions .btn-confirm {
|
||||
background: #dc3545;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.api-confirm-modal-actions .btn-confirm:hover {
|
||||
background: #b02a37;
|
||||
}
|
||||
|
||||
.api-connect-status {
|
||||
margin-top: 0.75rem;
|
||||
@@ -445,6 +394,33 @@ main {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.job-status-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
#skip-hung-btn {
|
||||
background: #f59e0b;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
padding: 0.5rem 0.9rem;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease, opacity 0.2s ease;
|
||||
}
|
||||
|
||||
#skip-hung-btn:hover {
|
||||
background: #d97706;
|
||||
}
|
||||
|
||||
#skip-hung-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.job-status-meta {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
|
||||
|
||||
@@ -91,9 +91,9 @@ function initApiSource() {
|
||||
}
|
||||
|
||||
const cancelJobButton = document.getElementById('cancel-job-btn');
|
||||
const skipHungButton = document.getElementById('skip-hung-btn');
|
||||
const connectButton = document.getElementById('api-connect-btn');
|
||||
const collectButton = document.getElementById('api-collect-btn');
|
||||
const powerOffCheckbox = document.getElementById('api-power-off');
|
||||
const fieldNames = ['host', 'port', 'username', 'password'];
|
||||
|
||||
apiForm.addEventListener('submit', (event) => {
|
||||
@@ -110,6 +110,11 @@ function initApiSource() {
|
||||
cancelCollectionJob();
|
||||
});
|
||||
}
|
||||
if (skipHungButton) {
|
||||
skipHungButton.addEventListener('click', () => {
|
||||
skipHungCollectionJob();
|
||||
});
|
||||
}
|
||||
if (connectButton) {
|
||||
connectButton.addEventListener('click', () => {
|
||||
startApiProbe();
|
||||
@@ -120,22 +125,6 @@ function initApiSource() {
|
||||
startCollectionWithOptions();
|
||||
});
|
||||
}
|
||||
if (powerOffCheckbox) {
|
||||
powerOffCheckbox.addEventListener('change', () => {
|
||||
if (!powerOffCheckbox.checked) {
|
||||
return;
|
||||
}
|
||||
// If host was already on when probed, warn before enabling shutdown
|
||||
if (apiProbeResult && apiProbeResult.host_powered_on) {
|
||||
showConfirmModal(
|
||||
'Хост был включён до начала сбора. Вы уверены, что хотите выключить его после завершения сбора?',
|
||||
() => { /* confirmed — leave checked */ },
|
||||
() => { powerOffCheckbox.checked = false; }
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fieldNames.forEach((fieldName) => {
|
||||
const field = apiForm.elements.namedItem(fieldName);
|
||||
if (!field) {
|
||||
@@ -163,36 +152,6 @@ function initApiSource() {
|
||||
renderCollectionJob();
|
||||
}
|
||||
|
||||
function showConfirmModal(message, onConfirm, onCancel) {
|
||||
const backdrop = document.createElement('div');
|
||||
backdrop.className = 'api-confirm-modal-backdrop';
|
||||
backdrop.innerHTML = `
|
||||
<div class="api-confirm-modal" role="dialog" aria-modal="true">
|
||||
<p>${escapeHtml(message)}</p>
|
||||
<div class="api-confirm-modal-actions">
|
||||
<button class="btn-cancel">Отмена</button>
|
||||
<button class="btn-confirm">Да, выключить</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(backdrop);
|
||||
|
||||
const close = () => document.body.removeChild(backdrop);
|
||||
backdrop.querySelector('.btn-cancel').addEventListener('click', () => {
|
||||
close();
|
||||
if (onCancel) onCancel();
|
||||
});
|
||||
backdrop.querySelector('.btn-confirm').addEventListener('click', () => {
|
||||
close();
|
||||
if (onConfirm) onConfirm();
|
||||
});
|
||||
backdrop.addEventListener('click', (e) => {
|
||||
if (e.target === backdrop) {
|
||||
close();
|
||||
if (onCancel) onCancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function startApiProbe() {
|
||||
const { isValid, payload, errors } = validateCollectForm();
|
||||
@@ -255,11 +214,7 @@ function startCollectionWithOptions() {
|
||||
return;
|
||||
}
|
||||
|
||||
const powerOnCheckbox = document.getElementById('api-power-on');
|
||||
const powerOffCheckbox = document.getElementById('api-power-off');
|
||||
const debugPayloads = document.getElementById('api-debug-payloads');
|
||||
payload.power_on_if_host_off = powerOnCheckbox ? powerOnCheckbox.checked : false;
|
||||
payload.stop_host_after_collect = powerOffCheckbox ? powerOffCheckbox.checked : false;
|
||||
payload.debug_payloads = debugPayloads ? debugPayloads.checked : false;
|
||||
startCollectionJob(payload);
|
||||
}
|
||||
@@ -268,8 +223,6 @@ function renderApiProbeState() {
|
||||
const connectButton = document.getElementById('api-connect-btn');
|
||||
const probeOptions = document.getElementById('api-probe-options');
|
||||
const status = document.getElementById('api-connect-status');
|
||||
const powerOnCheckbox = document.getElementById('api-power-on');
|
||||
const powerOffCheckbox = document.getElementById('api-power-off');
|
||||
if (!connectButton || !probeOptions || !status) {
|
||||
return;
|
||||
}
|
||||
@@ -283,7 +236,6 @@ function renderApiProbeState() {
|
||||
}
|
||||
|
||||
const hostOn = apiProbeResult.host_powered_on;
|
||||
const powerControlAvailable = apiProbeResult.power_control_available;
|
||||
|
||||
if (hostOn) {
|
||||
status.textContent = apiProbeResult.message || 'Связь с BMC есть, host включён.';
|
||||
@@ -295,25 +247,15 @@ function renderApiProbeState() {
|
||||
|
||||
probeOptions.classList.remove('hidden');
|
||||
|
||||
// "Включить" checkbox
|
||||
if (powerOnCheckbox) {
|
||||
const hostOffWarning = document.getElementById('api-host-off-warning');
|
||||
if (hostOffWarning) {
|
||||
if (hostOn) {
|
||||
// Host already on — checkbox is checked and disabled
|
||||
powerOnCheckbox.checked = true;
|
||||
powerOnCheckbox.disabled = true;
|
||||
hostOffWarning.classList.add('hidden');
|
||||
} else {
|
||||
// Host off — default: checked (will power on), enabled
|
||||
powerOnCheckbox.checked = true;
|
||||
powerOnCheckbox.disabled = !powerControlAvailable;
|
||||
hostOffWarning.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// "Выключить" checkbox — default: unchecked
|
||||
if (powerOffCheckbox) {
|
||||
powerOffCheckbox.checked = false;
|
||||
powerOffCheckbox.disabled = !powerControlAvailable;
|
||||
}
|
||||
|
||||
connectButton.textContent = 'Переподключиться';
|
||||
}
|
||||
|
||||
@@ -535,6 +477,36 @@ function pollCollectionJobStatus() {
|
||||
});
|
||||
}
|
||||
|
||||
function skipHungCollectionJob() {
|
||||
if (!collectionJob || isCollectionJobTerminal(collectionJob.status)) {
|
||||
return;
|
||||
}
|
||||
const btn = document.getElementById('skip-hung-btn');
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Пропуск...';
|
||||
}
|
||||
fetch(`/api/collect/${encodeURIComponent(collectionJob.id)}/skip`, {
|
||||
method: 'POST'
|
||||
})
|
||||
.then(async (response) => {
|
||||
const body = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
throw new Error(body.error || 'Не удалось пропустить зависшие запросы');
|
||||
}
|
||||
syncServerLogs(body.logs);
|
||||
renderCollectionJob();
|
||||
})
|
||||
.catch((err) => {
|
||||
appendJobLog(`Ошибка пропуска: ${err.message}`);
|
||||
if (btn) {
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Пропустить зависшие';
|
||||
}
|
||||
renderCollectionJob();
|
||||
});
|
||||
}
|
||||
|
||||
function cancelCollectionJob() {
|
||||
if (!collectionJob || isCollectionJobTerminal(collectionJob.status)) {
|
||||
return;
|
||||
@@ -671,6 +643,19 @@ function renderCollectionJob() {
|
||||
)).join('');
|
||||
|
||||
cancelButton.disabled = isTerminal;
|
||||
|
||||
const skipBtn = document.getElementById('skip-hung-btn');
|
||||
if (skipBtn) {
|
||||
const isCollecting = !isTerminal && collectionJob.status === 'running';
|
||||
if (isCollecting) {
|
||||
skipBtn.classList.remove('hidden');
|
||||
} else {
|
||||
skipBtn.classList.add('hidden');
|
||||
skipBtn.disabled = false;
|
||||
skipBtn.textContent = 'Пропустить зависшие';
|
||||
}
|
||||
}
|
||||
|
||||
setApiFormBlocked(!isTerminal);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,15 +80,9 @@
|
||||
</div>
|
||||
<div id="api-connect-status" class="api-connect-status"></div>
|
||||
<div id="api-probe-options" class="api-probe-options hidden">
|
||||
<label class="api-form-checkbox" for="api-power-on">
|
||||
<input id="api-power-on" name="power_on_if_host_off" type="checkbox">
|
||||
<span>Включить перед сбором</span>
|
||||
</label>
|
||||
<label class="api-form-checkbox" for="api-power-off">
|
||||
<input id="api-power-off" name="stop_host_after_collect" type="checkbox">
|
||||
<span>Выключить после сбора</span>
|
||||
</label>
|
||||
<div class="api-probe-options-separator"></div>
|
||||
<div id="api-host-off-warning" class="api-host-off-warning hidden">
|
||||
⚠ Host выключен — данные инвентаря могут быть неполными
|
||||
</div>
|
||||
<label class="api-form-checkbox" for="api-debug-payloads">
|
||||
<input id="api-debug-payloads" name="debug_payloads" type="checkbox">
|
||||
<span>Сбор расширенных метрик для отладки</span>
|
||||
@@ -102,7 +96,10 @@
|
||||
<section id="api-job-status" class="job-status hidden" aria-live="polite">
|
||||
<div class="job-status-header">
|
||||
<h4>Статус задачи сбора</h4>
|
||||
<button id="cancel-job-btn" type="button">Отменить</button>
|
||||
<div class="job-status-actions">
|
||||
<button id="skip-hung-btn" type="button" class="hidden" title="Прервать зависшие запросы и перейти к анализу собранных данных">Пропустить зависшие</button>
|
||||
<button id="cancel-job-btn" type="button">Отменить</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="job-status-meta">
|
||||
<div><span class="meta-label">jobId:</span> <code id="job-id-value">-</code></div>
|
||||
|
||||
Reference in New Issue
Block a user