Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feet: Add disk count coloun indicating the completed disks transfered #1201

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
"Description": "Description",
"Details": "Details",
"Determines the frequency with which the system checks the status of snapshot creation or removal during oVirt warm migration. The default value is 10 seconds.": "Determines the frequency with which the system checks the status of snapshot creation or removal during oVirt warm migration. The default value is 10 seconds.",
"Disk Transfer": "Disk Transfer",
"Disk counter": "Disk counter",
"Disk transfer": "Disk transfer",
"Do not try to preserve the static IPs of VMs with Windows guest operating system from vSphere.": "Do not try to preserve the static IPs of VMs with Windows guest operating system from vSphere.",
"Domain": "Domain",
"Domain name": "Domain name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,20 @@ const fieldsMetadataFactory: ResourceFieldFactory = (t) => [
? diskTransfer?.progress?.completed / diskTransfer?.progress?.total
: 0;
},
label: t('Disk Transfer'),
label: t('Disk transfer'),
isVisible: true,
sortable: true,
},
{
resourceFieldId: 'diskCounter',
jsonPath: (obj: VMData) => {
const diskTransfer = obj.statusVM?.pipeline.find((p) => p.name === 'DiskTransfer');

return diskTransfer && diskTransfer?.progress?.total
? diskTransfer?.progress?.completed / diskTransfer?.progress?.total
: 0;
},
label: t('Disk counter'),
isVisible: true,
sortable: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,26 @@ const cellRenderers: Record<string, React.FC<PlanVMsCellProps>> = {
p?.name?.startsWith('DiskTransfer'),
);
const annotations: { unit: string } = diskTransfer?.annotations as undefined;
const { completed, total } = getTransferProgress(diskTransfer);

return annotations?.unit ? (
<>
{diskTransfer?.progress?.completed || '-'} / {diskTransfer?.progress?.total || '-'}{' '}
{annotations?.unit || '-'}
{completed} / {total} {annotations?.unit || '-'}
</>
) : (
<>-</>
);
},
diskCounter: (props: PlanVMsCellProps) => {
const diskTransfer = props.data.statusVM?.pipeline.find((p) =>
p?.name?.startsWith('DiskTransfer'),
);

const { totalTasks, completedTasks } = countTasks(diskTransfer);

return totalTasks ? (
<>
{completedTasks || '-'} / {totalTasks || '-'} Discs
</>
) : (
<>-</>
Expand Down Expand Up @@ -200,3 +215,26 @@ export const getIcon: GetIconType = (p) => {
return undefined;
}
};

const countTasks = (diskTransfer: V1beta1PlanStatusMigrationVmsPipeline) => {
if (!diskTransfer || !Array.isArray(diskTransfer?.tasks)) {
return { totalTasks: 0, completedTasks: 0 };
}

const totalTasks = diskTransfer.tasks.length;
const completedTasks = diskTransfer.tasks.filter((task) => task.phase === 'Completed').length;

return { totalTasks, completedTasks };
};

const getTransferProgress = (diskTransfer) => {
if (!diskTransfer || !diskTransfer.progress) {
return { completed: '-', total: '-' };
}

const { completed, total } = diskTransfer.progress;
return {
completed: completed !== undefined ? completed : '-',
total: total !== undefined ? total : '-',
};
};