From c774a55b9e5dac4969189bd0e167ac7c27e45aca Mon Sep 17 00:00:00 2001 From: Sharon Gratch Date: Thu, 12 Sep 2024 14:54:20 +0300 Subject: [PATCH] If a migration task isn't completed but the migration is successful, mark task as successful, Reference: https://github.com/kubev2v/forklift-console-plugin/issues/1305 In case a migraiton task is not marked as finished (i.e. task.phase is undefined), but its pipeline step is marked as completed succesfully then mark the task as completed succesfully as well. Signed-off-by: Sharon Gratch --- .../Migration/MigrationVirtualMachinesRow.tsx | 7 ++++++- .../MigrationVirtualMachinesRowExtended.tsx | 5 ++++- .../details/utils/hasPipelineCompleted.tsx | 10 ++++++++++ .../views/details/utils/hasTaskCompleted.tsx | 18 ++++++++++++++++++ .../modules/Plans/views/details/utils/index.ts | 2 ++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasPipelineCompleted.tsx create mode 100644 packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasTaskCompleted.tsx diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRow.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRow.tsx index e0e60fa75..f0ffbba5b 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRow.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRow.tsx @@ -8,6 +8,7 @@ import { FlexItem, Popover, ProgressStep, ProgressStepper } from '@patternfly/re import { ResourcesAlmostFullIcon, ResourcesFullIcon } from '@patternfly/react-icons'; import { Table, Tr } from '@patternfly/react-table'; +import { hasTaskCompleted } from '../../../utils'; import { PlanVMsCellProps } from '../components'; import { NameCellRenderer } from '../components/NameCellRenderer'; import { VMData } from '../types'; @@ -222,7 +223,11 @@ const countTasks = (diskTransfer: V1beta1PlanStatusMigrationVmsPipeline) => { } const totalTasks = diskTransfer.tasks.length; - const completedTasks = diskTransfer.tasks.filter((task) => task.phase === 'Completed').length; + + // search num of completed tasks (either tasks that completed successfully or ones that aren't finished but their pipeline step is). + const completedTasks = diskTransfer.tasks.filter((task) => + hasTaskCompleted(task.phase, diskTransfer), + ).length; return { totalTasks, completedTasks }; }; diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRowExtended.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRowExtended.tsx index 86cf9466e..320248bcb 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRowExtended.tsx +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/tabs/VirtualMachines/Migration/MigrationVirtualMachinesRowExtended.tsx @@ -26,6 +26,7 @@ import { } from '@patternfly/react-core'; import { TaskIcon } from '@patternfly/react-icons'; +import { hasTaskCompleted } from '../../../utils'; import { PipelineTasksModal } from '../modals'; import { VMData } from '../types'; @@ -352,7 +353,9 @@ const getJobPhase = (job: IoK8sApiBatchV1Job) => { const getPipelineTasks = (pipeline: V1beta1PlanStatusMigrationVmsPipeline) => { const tasks = pipeline?.tasks || []; - const tasksCompleted = tasks.filter((c) => c.phase === 'Completed'); + + // search for all completed tasks (either tasks that completed successfully or ones that aren't finished but their pipeline step is). + const tasksCompleted = tasks.filter((c) => hasTaskCompleted(c.phase, pipeline)); return { total: tasks.length, completed: tasksCompleted.length, name: pipeline.name }; }; diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasPipelineCompleted.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasPipelineCompleted.tsx new file mode 100644 index 000000000..2c45d6ec6 --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasPipelineCompleted.tsx @@ -0,0 +1,10 @@ +import { V1beta1PlanStatusMigrationVmsPipeline } from '@kubev2v/types'; + +/** + * Check if a given migration's pipeline step has completed successfully. + * + * @param {V1beta1PlanStatusMigrationVmsPipeline} pipeline - A given migration's pipeline step + * @returns {boolean} - True if the migration step has completed successfully, false otherwise. + */ +export const hasPipelineCompleted = (pipeline: V1beta1PlanStatusMigrationVmsPipeline) => + !pipeline?.error && pipeline?.phase === 'Completed'; diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasTaskCompleted.tsx b/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasTaskCompleted.tsx new file mode 100644 index 000000000..936389d8b --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/hasTaskCompleted.tsx @@ -0,0 +1,18 @@ +import { V1beta1PlanStatusMigrationVmsPipeline } from '@kubev2v/types'; + +import { hasPipelineCompleted } from './hasPipelineCompleted'; + +/** + * Check if a given task within a pipeline has completed. + * + * A task if marked as completed successfully if its phase is marked as completed or if + * its phase is not set but its contained pipeline step has completed successfully. + * + * @param {string } taskPhase A given task's phase + * @param {V1beta1PlanStatusMigrationVmsPipeline} pipeline - A given migration's pipeline step which includes the task + * @returns {boolean} - Returns true if the task has completed. + */ +export const hasTaskCompleted = ( + taskPhase: string, + pipeline: V1beta1PlanStatusMigrationVmsPipeline, +) => taskPhase === 'Completed' || (taskPhase === undefined && hasPipelineCompleted(pipeline)); diff --git a/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/index.ts b/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/index.ts index 01f07bcea..7756ce20f 100644 --- a/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/index.ts +++ b/packages/forklift-console-plugin/src/modules/Plans/views/details/utils/index.ts @@ -4,8 +4,10 @@ export * from './constants'; export * from './getInventoryApiUrl'; export * from './getValueByJsonPath'; export * from './hasObjectChangedInGivenFields'; +export * from './hasPipelineCompleted'; export * from './hasPlanEditable'; export * from './hasPlanMappingsChanged'; +export * from './hasTaskCompleted'; export * from './mapMappingsIdsToLabels'; export * from './patchPlanMappingsData'; // @endindex