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

🐞 when migration task isn't completed but the migration is successful, mark task as successful #1324

Merged
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 @@ -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';
Expand Down Expand Up @@ -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 };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 };
};
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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));
Original file line number Diff line number Diff line change
Expand Up @@ -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