优化 VPC 批量实例状态显示

go
codex 3 weeks ago
parent 00f6895895
commit f53c454ff2

@ -1098,7 +1098,7 @@ final class CloudVpcMembershipBatchService
private static function dto(CloudVpcMembershipBatch $batch): array
{
$items = CloudVpcMembershipBatchItem::query()
->where('batch_id', (int) $batch->id)->get();
->where('batch_id', (int) $batch->id)->orderBy('id')->get();
$vpc = CloudVpc::find((int) $batch->vpc_id);
return [
'batch_key' => (string) $batch->batch_key,
@ -1110,6 +1110,10 @@ final class CloudVpcMembershipBatchService
'succeeded' => $items->where('state', 'succeeded')->count(),
'failed' => $items->where('state', 'failed')->count(),
'unknown' => $items->where('state', 'unknown')->count(),
'items' => $items->map(static fn ($item): array => [
'instance_id' => (string) $item->instance_id,
'state' => (string) $item->state,
])->values()->all(),
'can_cancel' => (string) $batch->state === 'blocked'
&& self::canRetryAttachCleanup($batch, $items, false),
'task_id' => (string) $batch->parent_job_id,

@ -119,7 +119,7 @@ tbody tr:hover{background:#fcfefe}
.vm-identity{display:flex;align-items:center;gap:12px;min-width:160px}.vm-icon{width:38px;height:38px;border-radius:10px;background:#e9f8f8;color:#239eaa;display:flex;align-items:center;justify-content:center;font-size:19px;flex:none}.vm-name{display:block;color:#25384e;font-size:13px;font-weight:800;max-width:230px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.vm-uuid-row{display:flex;align-items:center;gap:5px;margin-top:6px;max-width:265px}.vm-id{display:block;min-width:0;color:#a6b1bf;font-size:10px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.vm-uuid-row .vm-copy-icon{width:21px;min-height:21px;padding:2px}.vm-uuid-row .vm-copy-icon svg{width:13px;height:13px}
.vm-public-ip{display:block;color:#16868f;font-size:10px;font-weight:700;margin-top:5px;white-space:nowrap}
.vm-name-link{display:block;max-width:230px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border:0;background:transparent;padding:2px 0;color:#25384e;font-size:13px;font-weight:800;text-align:left;text-decoration:underline;text-decoration-color:transparent;text-underline-offset:3px;cursor:pointer}.vm-name-link:not(:disabled):hover,.vm-name-link:not(:disabled):focus-visible{color:#118e98;text-decoration-color:currentColor}.vm-metadata{display:block;max-width:205px;color:#53647a;line-height:1.5;overflow-wrap:anywhere}.vm-ip{color:#16868f;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;white-space:nowrap}
.state-pill{display:inline-flex;align-items:center;gap:7px;padding:6px 9px;border-radius:6px;font-size:11px;font-weight:800;background:#f1f3f6;color:#758499;white-space:nowrap}.state-pill:before{content:"";width:6px;height:6px;background:currentColor;border-radius:50%}.state-pill.running{background:#e7f8ef;color:#20a46f}.state-pill.stopped{background:#f2f4f7;color:#8290a3}.state-pill.other{background:#fff4e5;color:#b98129}
.state-pill{display:inline-flex;align-items:center;gap:7px;padding:6px 9px;border-radius:6px;font-size:11px;font-weight:800;background:#f1f3f6;color:#758499;white-space:nowrap}.state-pill:before{content:"";width:6px;height:6px;background:currentColor;border-radius:50%}.state-pill.running{background:#e7f8ef;color:#20a46f}.state-pill.stopped{background:#f2f4f7;color:#8290a3}.state-pill.other{background:#fff4e5;color:#b98129}.state-pill.failed{background:#fff0f1;color:#bd4654}
.vm-spec{color:#53647a;white-space:nowrap}.vm-spec strong{color:#283a50;font-weight:700}.vm-spec small{display:block;color:#a2aeb9;font-size:10px;margin-top:5px}
.row-actions{display:flex;align-items:center;justify-content:flex-end;gap:5px;white-space:nowrap}.row-button{border:1px solid transparent;background:transparent;color:#577083;border-radius:7px;padding:7px 8px;min-height:31px;font-size:11px;font-weight:700}.row-button:not(:disabled):hover{background:#e8f7f7;color:#117f88}.row-button.primary{background:#e7f7f7;color:#118e98}.row-button.danger{color:#bf6470}.row-button.danger:not(:disabled):hover{background:#fff0f1;color:#ba3a49}
.empty-state{text-align:center;padding:65px 20px 72px}.empty-icon{margin:0 auto 16px;width:54px;height:54px;display:flex;align-items:center;justify-content:center;border-radius:16px;background:#eaf7f7;color:#17a3aa;font-size:28px}.empty-state h3{font-size:16px;color:#34465a;margin:0 0 8px}.empty-state p{font-size:12px;color:#a0aebe;margin:0}

@ -28,6 +28,14 @@ const PORT_STATE_LABELS = Object.freeze({
released: ['已断开', 'other'], migrating: ['正在迁移', 'other'],
});
const BATCH_ITEM_STATE_LABELS = Object.freeze({
waiting_route: ['等待中', 'other'],
queued: ['执行中', 'other'],
succeeded: ['已完成', 'running'],
failed: ['失败', 'failed'],
unknown: ['失败', 'failed'],
});
const state = {
items: [], instances: [], regions: [], maximum: 16, used: 0,
loading: false, controller: null, creating: false, initialized: false,
@ -237,6 +245,13 @@ function activeBatchForVpc(vpc) {
|| null;
}
function activeBatchItemForInstance(vpc, instance) {
const batch = activeBatchForVpc(vpc);
if (!batch || !Array.isArray(batch.items)) return null;
const id = instanceId(instance);
return batch.items.find(item => String(item?.instance_id || '') === id) || null;
}
function batchPendingStorageKey(vpc, action) {
return `virt-cloud:pending-vpc-batch:${state.userKey}:${vpcKey(vpc)}:${action}`;
}
@ -387,18 +402,21 @@ function renderInstanceRow(instance, vpc, joining, checkbox) {
privateAddress.append(details);
}
const [label, type] = joining
? (instance.can_attach === true ? ['可加入', 'running'] : ['暂不可加入', 'other'])
: PORT_STATE_LABELS[String(port.state || '')] || ['状态待确认', 'other'];
const batchItem = activeBatchItemForInstance(vpc, instance);
const [label, type] = batchItem
? BATCH_ITEM_STATE_LABELS[String(batchItem.state || '')] || ['等待中', 'other']
: joining
? (instance.can_attach === true ? ['可加入', 'running'] : ['暂不可加入', 'other'])
: PORT_STATE_LABELS[String(port.state || '')] || ['状态待确认', 'other'];
const status = tableCell('cloud-vpc-instance-status', '状态');
status.append(element('span', `state-pill ${type}`, label));
if (instance.action_unavailable_reason) {
if (!batchItem && instance.action_unavailable_reason) {
status.append(element('small', '', instance.action_unavailable_reason));
}
const action = portAction(instance);
if (taskId(instance.active_task)) {
if (!batchItem && taskId(instance.active_task)) {
status.append(taskCenterButton());
} else if (action === 'retry_attach' || action === 'retry_detach') {
} else if (!batchItem && (action === 'retry_attach' || action === 'retry_detach')) {
const retry = element('button', 'cloud-vpc-text-button',
action === 'retry_attach' ? '重试连接' : '重试清理');
retry.type = 'button';

@ -1,2 +1,2 @@
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
{assign var=venix_asset_version value='2026102910' scope='global'}
{assign var=venix_asset_version value='2026103001' scope='global'}

@ -243,6 +243,42 @@ async function submit(t) { await control(t, 'submit-selection').fire('click'); }
assert.equal(t.observations[1].receipt.task_id, '503');
assert.equal(mutations(t).length, 0);
}
{
const itemStates = ['waiting_route', 'queued', 'succeeded', 'failed'];
const data = fixtures();
data.instances = itemStates.map((itemState, index) => member(index + 1, {
can_retry_attach: index === 0,
active_task: {
task_id: String(600 + index),
status_url: `/api/v1/tasks/${600 + index}`,
},
}));
data.items[0].port_count = itemStates.length;
data.membership_batches = [{
vpc_key: A, state: 'ports', total: itemStates.length, succeeded: 1,
failed: 1, unknown: 0, action: 'attach', task_id: '599',
status_url: '/api/v1/tasks/599',
items: itemStates.map((itemState, index) => ({
instance_id: String(index + 1), state: itemState,
})),
}];
const t = await setup(href(A), data);
const manager = t.nodes.get('cloud-vpc-instance-manager');
const rowTaskButtons = manager.querySelectorAll('button')
.filter(button => button.textContent === '查看任务');
assert.equal(rowTaskButtons.length, 0,
'Batch rows must not duplicate the batch task-center action');
assert.equal(manager.querySelectorAll('button').filter(button =>
['重试连接', '重试清理'].includes(button.textContent)).length, 0,
'Batch rows must not expose per-instance retry actions');
for (const label of ['等待中', '执行中', '已完成', '失败']) {
assert.match(manager.textContent, new RegExp(label),
`Batch rows must render ${label}`);
}
assert.equal(t.nodes.get('cloud-vpc-batch-status').querySelectorAll('button')
.filter(button => button.textContent === '查看任务').length, 1,
'The batch must retain one task-center action');
}
{
const data = fixtures();
data.membership_batches = [{ vpc_key: A, batch_key: 'd'.repeat(32), state: 'blocked',

@ -26,6 +26,7 @@ namespace {
use App\Models\CloudVpc;
use App\Models\CloudVpcHostState;
use App\Models\CloudVpcMembershipBatch;
use App\Models\CloudVpcMembershipBatchItem;
use App\Models\CloudVpcPort;
use App\Services\Cloud\CloudSecrets;
use App\Services\Cloud\CloudJobService;
@ -1173,11 +1174,22 @@ namespace {
$retryDto = collect(
CloudVpcMembershipBatchService::activeForOwner(7)
)->firstWhere('batch_key', (string) $retryBatchRow->batch_key);
$expectedItemStates = CloudVpcMembershipBatchItem::query()
->where('batch_id', $retryBatchId)->orderBy('instance_id')->get()
->mapWithKeys(static fn ($item): array => [
(string) $item->instance_id => (string) $item->state,
])->all();
$projectedItemStates = collect($retryDto['items'] ?? [])
->mapWithKeys(static fn (array $item): array => [
(string) ($item['instance_id'] ?? '') =>
(string) ($item['state'] ?? ''),
])->all();
$assert((string) $retryBatchRow->state === 'blocked'
&& ($retryDto['can_cancel'] ?? false) === true
&& $projectedItemStates === $expectedItemStates
&& collect([30, 31])->every(static fn (int $id): bool =>
CloudJobService::blockingQueryForInstance($id)->exists()),
'Known-not-applied rollback failure did not expose a safe cancel exit.');
'Known-not-applied rollback failure did not expose item progress and a safe cancel exit.');
$retryResult = CloudVpcMembershipBatchService::cancelAttach(
['user_id' => 7],
(string) $vpc->vpc_key,

@ -77,27 +77,30 @@ $assert(str_contains($app, 'module.initialize();')
&& str_contains($javascript, "initializeSession('vpcs'")
&& !str_contains($javascript, 'await initializeSession();'),
'The VPC page module must expose the initialize contract used by cloud/app.js.');
$assert(str_contains($template, 'class="cloud-vpcs-stack"')
&& !str_contains($template, 'class="cloud-vpcs-grid"')
&& str_contains($template, 'class="inventory-panel cloud-vpc-create-panel"')
$assert(str_contains($template, 'id="cloud-vpcs-home"')
&& str_contains($template, 'id="cloud-vpcs-create"')
&& str_contains($template, 'id="cloud-vpcs-members"')
&& str_contains($template, 'class="inventory-panel cloud-vpc-list-panel"')
&& str_contains($template, 'class="inventory-panel cloud-vpc-create-panel"')
&& str_contains($template, 'class="inventory-panel cloud-vpc-members-panel"')
&& str_contains($template, 'class="cloud-vpc-create-form"')
&& str_contains($template, 'class="cloud-vpc-create-footer"')
&& str_contains($template, 'VPC 网络')
&& str_contains($styles, '.cloud-vpcs-stack')
&& !str_contains($styles, '.cloud-vpcs-grid')
&& str_contains($template, 'id="cloud-vpc-batch-status"')
&& str_contains($template, 'id="cloud-vpc-instance-manager"')
&& str_contains($template, 'VPC 私网')
&& str_contains($styles, '.cloud-vpc-create-form')
&& str_contains($styles, '.cloud-vpc-create-footer')
&& str_contains($styles, '.cloud-vpc-card')
&& str_contains($styles, '.cloud-vpc-instance-manager')
&& str_contains($styles, '.cloud-vpc-instance-table-head')
&& str_contains($styles, '.cloud-vpc-candidate-table-head')
&& str_contains($styles, '.cloud-vpc-candidate-list')
&& str_contains($styles, '.cloud-vpc-table')
&& str_contains($styles, '.cloud-vpc-member-table')
&& str_contains($styles, '.cloud-vpc-batch-status'),
'The VPC page must expose list, creation and member-management views.');
$assert(str_contains($javascript, 'function renderHome(')
&& str_contains($javascript, 'function renderInstanceManager(')
&& str_contains($javascript, 'function tableHeader(')
&& str_contains($javascript, "'已加入实例'")
&& str_contains($javascript, "'加入实例'")
&& str_contains($javascript, "element('details', 'cloud-vpc-card cloud-vpc-disclosure')")
&& str_contains($javascript, "'cloud-vpc-table cloud-vpc-network-table'")
&& str_contains($javascript, "'cloud-vpc-table cloud-vpc-member-table'")
&& str_contains($javascript, 'async function submitMembershipBatch(')
&& str_contains($javascript, 'async function cancelMembershipBatch(')
&& str_contains($javascript, 'batch?.can_cancel !== true')
@ -105,25 +108,29 @@ $assert(str_contains($template, 'class="cloud-vpcs-stack"')
&& str_contains($javascript, 'function observeActiveBatches(')
&& !str_contains($javascript, 'async function advanceBatchPlan(')
&& !str_contains($javascript, 'vpc-attach-batch')
&& str_contains($batchService, 'There is no selection-count limit')
&& str_contains($batchService, 'releaseAttachPortJobsLocked(')
&& str_contains($batchService, 'beginDetachCleanupLocked(')
&& str_contains($javascript, 'public_ipv4')
&& str_contains($portService, "'public_ipv4' => \$publicIpv4")
&& !str_contains($javascript, '可分配 ${region.available} 个子网'),
'The VPC page must use one responsive stack with instance management.');
'The VPC page must render and mutate member batches through the current table UI.');
$assert(str_contains($batchService, 'There is no selection-count limit')
&& str_contains($batchService, 'releaseAttachPortJobsLocked(')
&& str_contains($batchService, 'beginDetachCleanupLocked(')
&& str_contains($batchService, "'items' => \$items->map(")
&& str_contains($portService, "'public_ipv4' => \$publicIpv4"),
'The VPC service must expose item progress and public-address data without a batch limit.');
$assert(str_contains($styles,
'.cloud-vpc-instance-table-head,.cloud-vpc-instance-row{display:grid;grid-template-columns:42px')
'.cloud-vpc-table,.cloud-vpc-table tbody { display:block; }')
&& str_contains($styles,
'.cloud-vpc-candidate-table-head,.cloud-vpc-candidate-row{display:grid;grid-template-columns:42px')
'.cloud-vpc-table-address::before,.cloud-vpc-network-count::before { content:attr(data-label);')
&& str_contains($styles,
'.cloud-vpc-table-address code{color:#506a7d;font:650 10px/1.5')
'.cloud-vpc-member-table tr { grid-template-columns:20px')
&& str_contains($styles,
'@media(max-width:900px){.cloud-vpc-instance-table-head,.cloud-vpc-candidate-table-head{display:none}')
'.cloud-vpc-instance-status { grid-column:2/-1; grid-row:3;')
&& str_contains($styles,
'.cloud-vpc-table-address::before{content:attr(data-label)')
&& str_contains($javascript, "'私网 / MAC', '状态', '操作'")
&& str_contains($javascript, "'公网 IPv4', '可用状态'"),
'.cloud-vpc-table-select { grid-column:1; grid-row:1;')
&& str_contains($javascript,
"tableHeader(['', '实例', '公网 IPv4', joining ? '私网分配' : '私网 IPv4', '状态'])")
&& str_contains($javascript, "tableCell('cloud-vpc-table-address', '公网 IPv4')")
&& str_contains($javascript, "tableCell('cloud-vpc-instance-status', '状态')"),
'VPC instance and candidate rows must use responsive, labelled table layouts.');
$assert(!str_contains($detailTemplate, 'id="vm-settings-nav-vpc"')
&& !str_contains($detailTemplate, 'id="vm-settings-section-vpc"')

Loading…
Cancel
Save