From 8600e7b6e1949a463bf806e6c92c89cf38225cef Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Wed, 27 Jun 2018 12:09:53 -0700 Subject: [PATCH 01/10] Use `mostRecentRequest` to get the task details --- .../components/Migrations/MigrationsInProgressCard.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js index be5e5e2b47..5632b29745 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js @@ -52,12 +52,10 @@ const MigrationsInProgressCard = ({ plan, allRequestsWithTasks, reloadCard, hand // UX business rule 2: aggregrate the tasks across requests reflecting current status of all tasks, // (gather the last status for the vm, gather the last storage for use in UX bussiness rule 3) const tasks = {}; - requestsOfAssociatedPlan.forEach(request => { - request.miq_request_tasks.forEach(task => { - tasks[task.source_id] = tasks[task.source_id] || {}; - tasks[task.source_id].completed = task.status === 'Ok' && task.state === 'finished'; - tasks[task.source_id].virtv2v_disks = task.options.virtv2v_disks; - }); + if (mostRecentRequest) mostRecentRequest.miq_request_tasks.forEach(task => { + tasks[task.source_id] = tasks[task.source_id] || {}; + tasks[task.source_id].completed = task.status === 'Ok' && task.state === 'finished'; + tasks[task.source_id].virtv2v_disks = task.options.virtv2v_disks; }); let completedVMs = 0; From a2ef240f1edebadf86111efd74f1eca56f195649 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Fri, 29 Jun 2018 16:18:27 -0700 Subject: [PATCH 02/10] request and task math to get previous task records --- .../components/Migrations/Migrations.js | 1 + .../Migrations/MigrationsCompletedList.js | 47 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/Migrations.js b/app/javascript/react/screens/App/Overview/components/Migrations/Migrations.js index b2560f9c77..ea763ccaf5 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/Migrations.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/Migrations.js @@ -117,6 +117,7 @@ const Migrations = ({ request.miq_request_tasks)} retryClick={createTransformationPlanRequestClick} loading={isCreatingTransformationPlanRequest} redirectTo={redirectTo} diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js index d842a65253..37f3eac48f 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js @@ -8,6 +8,7 @@ import getMostRecentRequest from '../../../common/getMostRecentRequest'; const MigrationsCompletedList = ({ finishedTransformationPlans, allRequestsWithTasks, + allTasks, retryClick, loading, redirectTo, @@ -33,11 +34,52 @@ const MigrationsCompletedList = ({ const failed = mostRecentRequest && mostRecentRequest.status === 'Error'; const tasks = {}; - if (mostRecentRequest) - mostRecentRequest.miq_request_tasks.forEach(task => { + if (plan.options.config_info.vm_ids.length > 1) { + const flattenAllTasks = []; + allTasks.map(task => task.map(arrayElement => flattenAllTasks.push(arrayElement))); + + const planVMTasks = flattenAllTasks.filter(task => plan.options.config_info.vm_ids.indexOf(task.source_id) > -1); + + const groupBy = (items, key) => items.reduce( + (result, item) => ({ + ...result, + [item[key]]: [ + ...(result[item[key]] || []), + item, + ], + }), + {}, + ); + + const groupedArrReq = groupBy(planVMTasks, 'miq_request_id'); + + const getMostRecentTaskFromGroup = tasks2 => + tasks2.reduce((prev, current) => (prev.created_on > current.created_on ? prev : current)); + + const vmTasks = []; + // vmTasks.push(plan.options.config_info.vm_ids.map(vmId => getMostRecentTaskFromGroup(groupedArr[vmId]))); + vmTasks.push(plan.miq_requests.map(request => groupedArrReq[request.id])); + + const flattenVMTasks = []; + vmTasks.map(task => task.map(arrayElement => arrayElement.map(t => flattenVMTasks.push(t)))); + + const groupedByVMId = groupBy(flattenVMTasks, 'source_id'); + + const vmTasksForRequestOfPlan = []; + vmTasksForRequestOfPlan.push(plan.options.config_info.vm_ids.map(vmId => getMostRecentTaskFromGroup(groupedByVMId[vmId]))); + + const flattenVMTasksForRequestOfPlan = []; + vmTasksForRequestOfPlan.map(task => task.map(arrayElement => flattenVMTasksForRequestOfPlan.push(arrayElement))); + + flattenVMTasksForRequestOfPlan.forEach(task => { tasks[task.source_id] = task.status === 'Ok'; }); + } else if (mostRecentRequest) { + mostRecentRequest.miq_request_tasks.forEach(task => { + tasks[task.source_id] = task.status === 'Ok'; + }); + } let succeedCount = 0; Object.keys(tasks).forEach(key => { if (tasks[key]) succeedCount += 1; @@ -194,6 +236,7 @@ const MigrationsCompletedList = ({ MigrationsCompletedList.propTypes = { finishedTransformationPlans: PropTypes.array, allRequestsWithTasks: PropTypes.array, + allTasks: PropTypes.array, retryClick: PropTypes.func, loading: PropTypes.string, redirectTo: PropTypes.func, From 822de91ffed0f4e0f182cd47cb8693709b97912f Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Sat, 30 Jun 2018 08:22:54 -0700 Subject: [PATCH 03/10] create a helper for reusing utils like groupBy and flatten array --- .../components/Migrations/Migrations.js | 1 - .../Migrations/MigrationsCompletedList.js | 47 +++++-------------- .../Migrations/MigrationsInProgressCard.js | 11 +++-- .../App/common/commonUtilitiesHelper.js | 18 +++++++ 4 files changed, 37 insertions(+), 40 deletions(-) create mode 100644 app/javascript/react/screens/App/common/commonUtilitiesHelper.js diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/Migrations.js b/app/javascript/react/screens/App/Overview/components/Migrations/Migrations.js index ea763ccaf5..b2560f9c77 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/Migrations.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/Migrations.js @@ -117,7 +117,6 @@ const Migrations = ({ request.miq_request_tasks)} retryClick={createTransformationPlanRequestClick} loading={isCreatingTransformationPlanRequest} redirectTo={redirectTo} diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js index 37f3eac48f..75f0129b66 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js @@ -4,11 +4,11 @@ import { noop, Button, ListView, Grid, Spinner, Icon } from 'patternfly-react'; import { IsoElapsedTime } from '../../../../../../components/dates/IsoElapsedTime'; import OverviewEmptyState from '../OverviewEmptyState/OverviewEmptyState'; import getMostRecentRequest from '../../../common/getMostRecentRequest'; +import commonUtilitiesHelper from '../../../common/commonUtilitiesHelper'; const MigrationsCompletedList = ({ finishedTransformationPlans, allRequestsWithTasks, - allTasks, retryClick, loading, redirectTo, @@ -34,49 +34,29 @@ const MigrationsCompletedList = ({ const failed = mostRecentRequest && mostRecentRequest.status === 'Error'; const tasks = {}; - if (plan.options.config_info.vm_ids.length > 1) { - const flattenAllTasks = []; - allTasks.map(task => task.map(arrayElement => flattenAllTasks.push(arrayElement))); - - const planVMTasks = flattenAllTasks.filter(task => plan.options.config_info.vm_ids.indexOf(task.source_id) > -1); - - const groupBy = (items, key) => items.reduce( - (result, item) => ({ - ...result, - [item[key]]: [ - ...(result[item[key]] || []), - item, - ], - }), - {}, - ); - - const groupedArrReq = groupBy(planVMTasks, 'miq_request_id'); + if (requestsOfAssociatedPlan.length > 0) { + const allTasks = requestsOfAssociatedPlan.map(request => request.miq_request_tasks); - const getMostRecentTaskFromGroup = tasks2 => - tasks2.reduce((prev, current) => (prev.created_on > current.created_on ? prev : current)); - - const vmTasks = []; - // vmTasks.push(plan.options.config_info.vm_ids.map(vmId => getMostRecentTaskFromGroup(groupedArr[vmId]))); - vmTasks.push(plan.miq_requests.map(request => groupedArrReq[request.id])); - - const flattenVMTasks = []; - vmTasks.map(task => task.map(arrayElement => arrayElement.map(t => flattenVMTasks.push(t)))); + const flattenAllTasks = []; + commonUtilitiesHelper.flattenArray(allTasks, flattenAllTasks); - const groupedByVMId = groupBy(flattenVMTasks, 'source_id'); + const groupedByVMId = commonUtilitiesHelper.groupBy(flattenAllTasks, 'source_id'); const vmTasksForRequestOfPlan = []; - vmTasksForRequestOfPlan.push(plan.options.config_info.vm_ids.map(vmId => getMostRecentTaskFromGroup(groupedByVMId[vmId]))); + vmTasksForRequestOfPlan.push( + plan.options.config_info.vm_ids.map(vmId => + commonUtilitiesHelper.getMostRecentEntityByCreationDate(groupedByVMId[vmId]) + ) + ); const flattenVMTasksForRequestOfPlan = []; - vmTasksForRequestOfPlan.map(task => task.map(arrayElement => flattenVMTasksForRequestOfPlan.push(arrayElement))); + commonUtilitiesHelper.flattenArray(vmTasksForRequestOfPlan, flattenVMTasksForRequestOfPlan); flattenVMTasksForRequestOfPlan.forEach(task => { tasks[task.source_id] = task.status === 'Ok'; }); } else if (mostRecentRequest) { - - mostRecentRequest.miq_request_tasks.forEach(task => { + mostRecentRequest.miq_request_tasks.forEach(task => { tasks[task.source_id] = task.status === 'Ok'; }); } @@ -236,7 +216,6 @@ const MigrationsCompletedList = ({ MigrationsCompletedList.propTypes = { finishedTransformationPlans: PropTypes.array, allRequestsWithTasks: PropTypes.array, - allTasks: PropTypes.array, retryClick: PropTypes.func, loading: PropTypes.string, redirectTo: PropTypes.func, diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js index 5632b29745..825ee6c6ca 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js @@ -52,11 +52,12 @@ const MigrationsInProgressCard = ({ plan, allRequestsWithTasks, reloadCard, hand // UX business rule 2: aggregrate the tasks across requests reflecting current status of all tasks, // (gather the last status for the vm, gather the last storage for use in UX bussiness rule 3) const tasks = {}; - if (mostRecentRequest) mostRecentRequest.miq_request_tasks.forEach(task => { - tasks[task.source_id] = tasks[task.source_id] || {}; - tasks[task.source_id].completed = task.status === 'Ok' && task.state === 'finished'; - tasks[task.source_id].virtv2v_disks = task.options.virtv2v_disks; - }); + if (mostRecentRequest) + mostRecentRequest.miq_request_tasks.forEach(task => { + tasks[task.source_id] = tasks[task.source_id] || {}; + tasks[task.source_id].completed = task.status === 'Ok' && task.state === 'finished'; + tasks[task.source_id].virtv2v_disks = task.options.virtv2v_disks; + }); let completedVMs = 0; const totalVMs = Object.keys(tasks).length; diff --git a/app/javascript/react/screens/App/common/commonUtilitiesHelper.js b/app/javascript/react/screens/App/common/commonUtilitiesHelper.js new file mode 100644 index 0000000000..bf9663675a --- /dev/null +++ b/app/javascript/react/screens/App/common/commonUtilitiesHelper.js @@ -0,0 +1,18 @@ +const commonUtilitiesHelper = { + getMostRecentEntityByCreationDate: entities => + entities.reduce((prev, current) => (prev.created_on > current.created_on ? prev : current)), + + groupBy: (items, key) => + items.reduce( + (result, item) => ({ + ...result, + [item[key]]: [...(result[item[key]] || []), item] + }), + {} + ), + + flattenArray: (arrayItems, flattenedArray) => + arrayItems.map(task => task.map(arrayElement => flattenedArray.push(arrayElement))) +}; + +export default commonUtilitiesHelper; From dc3ea3129ab9f9cebd7c9fdff65a92a9a1f3d15f Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Tue, 3 Jul 2018 10:04:35 -0700 Subject: [PATCH 04/10] API now uses a new url to get tasks for all requests of a given plan Once we have all requests with tasks for a given plan, reuse functions from `commonUtilitiesHelper` to retrieve the most recent tasks from the requests object based on the VM id's --- app/javascript/components/index.js | 2 +- app/javascript/react/screens/App/Plan/Plan.js | 19 +- .../react/screens/App/Plan/PlanActions.js | 27 ++- .../react/screens/App/Plan/PlanConstants.js | 1 + .../react/screens/App/Plan/PlanReducer.js | 181 ++++++++++-------- 5 files changed, 127 insertions(+), 103 deletions(-) diff --git a/app/javascript/components/index.js b/app/javascript/components/index.js index c2ff8683ed..86c284f5ca 100644 --- a/app/javascript/components/index.js +++ b/app/javascript/components/index.js @@ -124,7 +124,7 @@ export const coreComponents = [ type: PlanContainer, data: { fetchPlanUrl: '/api/service_templates', - fetchPlanRequestUrl: '/api/service_requests' + fetchTasksForAllRequestsForPlanUrl: '/api/requests?expand=resource&attributes=miq_request_tasks' }, store: true }, diff --git a/app/javascript/react/screens/App/Plan/Plan.js b/app/javascript/react/screens/App/Plan/Plan.js index 7982eea4af..0b07e45ad1 100644 --- a/app/javascript/react/screens/App/Plan/Plan.js +++ b/app/javascript/react/screens/App/Plan/Plan.js @@ -43,8 +43,8 @@ class Plan extends React.Component { fetchPlanUrl, fetchPlanAction, planId, - fetchPlanRequestUrl, - fetchPlanRequestAction, + fetchTasksForAllRequestsForPlanUrl, + fetchTasksForAllRequestsForPlanAction, queryPlanVmsAction } = this.props; @@ -63,10 +63,9 @@ class Plan extends React.Component { if (miq_requests.length > 0) { const mostRecentRequest = getMostRecentRequest(miq_requests); - const planRequestId = mostRecentRequest.id; - fetchPlanRequestAction(fetchPlanRequestUrl, planRequestId); + fetchTasksForAllRequestsForPlanAction(fetchTasksForAllRequestsForPlanUrl, miq_requests); if (mostRecentRequest.request_state === 'active') { - this.startPolling(planRequestId); + this.startPolling(miq_requests); } else { this.setState(() => ({ planFinished: true @@ -84,10 +83,10 @@ class Plan extends React.Component { resetPlanStateAction(); } - startPolling = id => { - const { fetchPlanRequestAction, fetchPlanRequestUrl } = this.props; + startPolling = requests => { + const { fetchTasksForAllRequestsForPlanAction, fetchTasksForAllRequestsForPlanUrl } = this.props; this.pollingInterval = setInterval(() => { - fetchPlanRequestAction(fetchPlanRequestUrl, id); + fetchTasksForAllRequestsForPlanAction(fetchTasksForAllRequestsForPlanUrl, requests); }, 15000); }; @@ -198,8 +197,8 @@ class Plan extends React.Component { } } Plan.propTypes = { - fetchPlanRequestUrl: PropTypes.string.isRequired, - fetchPlanRequestAction: PropTypes.func.isRequired, + fetchTasksForAllRequestsForPlanUrl: PropTypes.string.isRequired, + fetchTasksForAllRequestsForPlanAction: PropTypes.func.isRequired, planName: PropTypes.string, planRequestFailed: PropTypes.bool, planArchived: PropTypes.bool, diff --git a/app/javascript/react/screens/App/Plan/PlanActions.js b/app/javascript/react/screens/App/Plan/PlanActions.js index 6a6a7f6903..0fc874dbee 100644 --- a/app/javascript/react/screens/App/Plan/PlanActions.js +++ b/app/javascript/react/screens/App/Plan/PlanActions.js @@ -4,8 +4,8 @@ import API from '../../../../common/API'; import http from '../../../../common/http'; import { - FETCH_V2V_PLAN_REQUEST, FETCH_V2V_PLAN, + FETCH_V2V_ALL_REQUESTS_WITH_TASKS_FOR_PLAN, QUERY_V2V_PLAN_VMS, RESET_PLAN_STATE, FETCH_V2V_MIGRATION_TASK_LOG, @@ -16,20 +16,27 @@ import { import { V2V_NOTIFICATION_ADD } from '../common/NotificationList/NotificationConstants'; // ***************************************************************************** -// * FETCH_V2V_PLAN_REQUEST +// * FETCH_V2V_ALL_REQUESTS_WITH_TASKS_FOR_PLAN // ***************************************************************************** -const _getPlanRequestActionCreator = url => dispatch => +const _getTasksForAllRequestsForPlanActionCreator = (url, allRequests) => dispatch => { dispatch({ - type: FETCH_V2V_PLAN_REQUEST, - payload: API.get(url) + type: FETCH_V2V_ALL_REQUESTS_WITH_TASKS_FOR_PLAN, + payload: new Promise((resolve, reject) => { + API.post(url, { + action: 'query', + resources: allRequests + }) + .then(response => { + resolve(response); + }) + .catch(e => reject(e)); + }) }); - -export const fetchPlanRequestAction = (url, id) => { - const uri = new URI(`${url}/${id}`); - uri.addSearch({ attributes: 'miq_request_tasks' }); - return _getPlanRequestActionCreator(uri.toString()); }; +export const fetchTasksForAllRequestsForPlanAction = (url, allRequests) => + _getTasksForAllRequestsForPlanActionCreator(url, allRequests); + // ***************************************************************************** // * QUERY_V2V_PLAN_VMS // ***************************************************************************** diff --git a/app/javascript/react/screens/App/Plan/PlanConstants.js b/app/javascript/react/screens/App/Plan/PlanConstants.js index 3efc6c6790..2d5cb6c224 100644 --- a/app/javascript/react/screens/App/Plan/PlanConstants.js +++ b/app/javascript/react/screens/App/Plan/PlanConstants.js @@ -1,5 +1,6 @@ export const FETCH_V2V_PLAN_REQUEST = 'FETCH_V2V_PLAN_REQUEST'; export const FETCH_V2V_PLAN = 'FETCH_V2V_PLAN'; +export const FETCH_V2V_ALL_REQUESTS_WITH_TASKS_FOR_PLAN = 'FETCH_V2V_ALL_REQUESTS_WITH_TASKS_FOR_PLAN'; export const QUERY_V2V_PLAN_VMS = 'QUERY_V2V_PLAN_VMS'; export const RESET_PLAN_STATE = 'RESET_PLAN_STATE'; export const FETCH_V2V_MIGRATION_TASK_LOG = 'FETCH_V2V_MIGRATION_TASK_LOG'; diff --git a/app/javascript/react/screens/App/Plan/PlanReducer.js b/app/javascript/react/screens/App/Plan/PlanReducer.js index dc08e9a610..e263898baf 100644 --- a/app/javascript/react/screens/App/Plan/PlanReducer.js +++ b/app/javascript/react/screens/App/Plan/PlanReducer.js @@ -1,9 +1,10 @@ import Immutable from 'seamless-immutable'; import numeral from 'numeral'; +import commonUtilitiesHelper from '../common/commonUtilitiesHelper'; import { - FETCH_V2V_PLAN_REQUEST, FETCH_V2V_PLAN, + FETCH_V2V_ALL_REQUESTS_WITH_TASKS_FOR_PLAN, QUERY_V2V_PLAN_VMS, RESET_PLAN_STATE, FETCH_V2V_MIGRATION_TASK_LOG, @@ -35,102 +36,88 @@ const excludeDownloadDoneTaskId = (allDownloadLogInProgressTaskIds, taskId) => const includeDownloadInProgressTaskId = (allDownloadLogInProgressTaskIds, taskId) => allDownloadLogInProgressTaskIds ? allDownloadLogInProgressTaskIds.concat(taskId) : [taskId]; -const _formatPlanRequestDetails = data => { +const processVMTasks = vmTasks => { const tasks = []; - if (data.miq_request_tasks && data.miq_request_tasks.length) { - data.miq_request_tasks.forEach(task => { - const taskDetails = { - id: task.id, - message: task.message, - transformation_host_name: task.options && task.options.transformation_host_name, - delivered_on: new Date(task.options.delivered_on), - updated_on: new Date(task.updated_on), - completed: task.message === 'VM Transformations completed' || task.message === 'VM Transformations failed', - state: task.state, - status: task.status, - options: {} - }; - - taskDetails.options.progress = task.options.progress; - taskDetails.options.virtv2v_wrapper = task.options.virtv2v_wrapper; - - if (!task.diskSpaceCompletedGb) { - taskDetails.diskSpaceCompletedGb = '0'; - } + vmTasks.forEach(task => { + const taskDetails = { + id: task.id, + message: task.message, + transformation_host_name: task.options && task.options.transformation_host_name, + delivered_on: new Date(task.options.delivered_on), + updated_on: new Date(task.updated_on), + completed: task.message === 'VM Transformations completed' || task.message === 'VM Transformations failed', + state: task.state, + status: task.status, + options: {} + }; + + taskDetails.options.progress = task.options.progress; + taskDetails.options.virtv2v_wrapper = task.options.virtv2v_wrapper; + + if (!task.diskSpaceCompletedGb) { + taskDetails.diskSpaceCompletedGb = '0'; + } - if (!task.percentComplete) { - taskDetails.percentComplete = 0; - } + if (!task.percentComplete) { + taskDetails.percentComplete = 0; + } - if (!task.totalDiskSpaceGb) { - taskDetails.totalDiskSpaceGb = '100%'; - } + if (!task.totalDiskSpaceGb) { + taskDetails.totalDiskSpaceGb = '100%'; + } - const grepVMName = task.description.match(/\[(.*?)\]/); + const grepVMName = task.description.match(/\[(.*?)\]/); - if (grepVMName) { - [taskDetails.descriptionPrefix, taskDetails.vmName] = grepVMName; - } + if (grepVMName) { + [taskDetails.descriptionPrefix, taskDetails.vmName] = grepVMName; + } - const startDateTime = taskDetails.delivered_on; - const lastUpdateDateTime = taskDetails.updated_on; - taskDetails.startDateTime = startDateTime; - taskDetails.lastUpdateDateTime = lastUpdateDateTime; + const startDateTime = taskDetails.delivered_on; + const lastUpdateDateTime = taskDetails.updated_on; + taskDetails.startDateTime = startDateTime; + taskDetails.lastUpdateDateTime = lastUpdateDateTime; - if (taskDetails.completed) { - taskDetails.completedSuccessfully = - task.options.progress.current_description === 'Virtual machine migrated' || - task.options.progress.current_description === 'Mark source as migrated'; - } - if (task.options && task.options.virtv2v_disks && task.options.virtv2v_disks.length) { - taskDetails.totalDiskSpace = task.options.virtv2v_disks.reduce((a, b) => a + b.size, 0); - taskDetails.totalDiskSpaceGb = numeral(taskDetails.totalDiskSpace).format('0.00b'); + if (taskDetails.completed) { + taskDetails.completedSuccessfully = + task.options.progress.current_description === 'Virtual machine migrated' || + task.options.progress.current_description === 'Mark source as migrated'; + } + if (task.options && task.options.virtv2v_disks && task.options.virtv2v_disks.length) { + taskDetails.totalDiskSpace = task.options.virtv2v_disks.reduce((a, b) => a + b.size, 0); + taskDetails.totalDiskSpaceGb = numeral(taskDetails.totalDiskSpace).format('0.00b'); - const percentComplete = - task.options.virtv2v_disks.reduce((a, b) => a + b.percent, 0) / (100 * task.options.virtv2v_disks.length); + const percentComplete = + task.options.virtv2v_disks.reduce((a, b) => a + b.percent, 0) / (100 * task.options.virtv2v_disks.length); - taskDetails.diskSpaceCompleted = percentComplete * taskDetails.totalDiskSpace; - taskDetails.diskSpaceCompletedGb = numeral(taskDetails.diskSpaceCompleted).format('0.00b'); - taskDetails.percentComplete = Math.round(percentComplete * 1000) / 10; - } - tasks.push(taskDetails); - }); - } + taskDetails.diskSpaceCompleted = percentComplete * taskDetails.totalDiskSpace; + taskDetails.diskSpaceCompletedGb = numeral(taskDetails.diskSpaceCompleted).format('0.00b'); + taskDetails.percentComplete = Math.round(percentComplete * 1000) / 10; + } + tasks.push(taskDetails); + }); return tasks; }; -const _deepCompare = (prevTasks, newTasks) => JSON.stringify(prevTasks) === JSON.stringify(newTasks); +const allVMTasksForRequestOfPlan = (vm_ids, requestWithTasks) => { + const allTasks = requestWithTasks.map(request => request.miq_request_tasks); + + const flattenAllTasks = []; + commonUtilitiesHelper.flattenArray(allTasks, flattenAllTasks); + + const groupedByVMId = commonUtilitiesHelper.groupBy(flattenAllTasks, 'source_id'); + + const vmTasksForRequestOfPlan = []; + vmTasksForRequestOfPlan.push( + vm_ids.map(vmId => commonUtilitiesHelper.getMostRecentEntityByCreationDate(groupedByVMId[vmId])) + ); + + const flattenVMTasksForRequestOfPlan = []; + commonUtilitiesHelper.flattenArray(vmTasksForRequestOfPlan, flattenVMTasksForRequestOfPlan); + return processVMTasks(flattenVMTasksForRequestOfPlan); +}; export default (state = initialState, action) => { switch (action.type) { - case `${FETCH_V2V_PLAN_REQUEST}_PENDING`: - return state.set('isFetchingPlanRequest', true).set('isRejectedPlanRequest', false); - case `${FETCH_V2V_PLAN_REQUEST}_FULFILLED`: { - const { payload } = action; - if (payload.data) { - const newTasks = _formatPlanRequestDetails(payload.data); - if (!_deepCompare(state.planRequestTasks, newTasks)) { - return state - .set('planRequestPreviouslyFetched', true) - .set('planRequestTasks', newTasks) - .set('planRequestFailed', payload.data.status === 'Error') - .set('isRejectedPlanRequest', false) - .set('errorPlanRequest', null) - .set('isFetchingPlanRequest', false); - } - } - return state - .set('planRequestPreviouslyFetched', true) - .set('isRejectedPlanRequest', false) - .set('errorPlanRequest', null) - .set('isFetchingPlanRequest', false); - } - case `${FETCH_V2V_PLAN_REQUEST}_REJECTED`: - return state - .set('errorPlanRequest', action.payload) - .set('isRejectedPlanRequest', true) - .set('isFetchingPlanRequest', false); - case `${FETCH_V2V_PLAN}_PENDING`: return state.set('isFetchingPlan', true).set('isRejectedPlan', false); case `${FETCH_V2V_PLAN}_FULFILLED`: @@ -147,6 +134,36 @@ export default (state = initialState, action) => { .set('isRejectedPlan', true) .set('errorPlan', action.payload); + case `${FETCH_V2V_ALL_REQUESTS_WITH_TASKS_FOR_PLAN}_PENDING`: + return state.set('isFetchingPlanRequest', true).set('isRejectedPlanRequest', false); + case `${FETCH_V2V_ALL_REQUESTS_WITH_TASKS_FOR_PLAN}_FULFILLED`: + if (action.payload.data) { + return state + .set( + 'planRequestTasks', + allVMTasksForRequestOfPlan(state.plan.options.config_info.vm_ids, action.payload.data.results) + ) + .set('allRequestsWithTasksForPlan', action.payload.data.results) + .set('planRequestPreviouslyFetched', true) + .set( + 'planRequestFailed', + commonUtilitiesHelper.getMostRecentEntityByCreationDate(action.payload.data.results).status === 'Error' + ) + .set('isRejectedPlanRequest', false) + .set('errorPlanRequest', null) + .set('isFetchingPlanRequest', false); + } + return state + .set('planRequestPreviouslyFetched', true) + .set('isRejectedPlanRequest', false) + .set('errorPlanRequest', null) + .set('isFetchingPlanRequest', false); + case `${FETCH_V2V_ALL_REQUESTS_WITH_TASKS_FOR_PLAN}_REJECTED`: + return state + .set('errorPlanRequest', action.payload) + .set('isRejectedPlanRequest', true) + .set('isFetchingPlanRequest', false); + case `${QUERY_V2V_PLAN_VMS}_PENDING`: return state.set('isQueryingVms', true).set('isRejectedVms', false); case `${QUERY_V2V_PLAN_VMS}_FULFILLED`: From 9cffc1f0be962100fafcdbfca52018fc857f409a Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Tue, 3 Jul 2018 16:49:30 -0700 Subject: [PATCH 05/10] fix tests --- .../Overview/overview.requestWithTasks.fixtures.js | 14 +++++++------- .../overview.transformationPlans.fixtures.js | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/javascript/react/screens/App/Overview/overview.requestWithTasks.fixtures.js b/app/javascript/react/screens/App/Overview/overview.requestWithTasks.fixtures.js index 889bbd61b6..94f4110b81 100644 --- a/app/javascript/react/screens/App/Overview/overview.requestWithTasks.fixtures.js +++ b/app/javascript/react/screens/App/Overview/overview.requestWithTasks.fixtures.js @@ -221,7 +221,7 @@ export const allRequestsWithTasks = Immutable({ phase_context: {}, request_state: 'Finished', request_type: 'transformation_plan', - source_id: '26', + source_id: '1', source_type: 'VmOrTemplate', state: 'finished', status: 'Error', @@ -556,7 +556,7 @@ export const allRequestsWithTasks = Immutable({ phase_context: {}, request_state: '', request_type: 'transformation_plan', - source_id: '26', + source_id: '3', source_type: 'VmOrTemplate', state: 'active', status: 'Ok', @@ -962,7 +962,7 @@ export const allRequestsWithTasks = Immutable({ phase_context: {}, request_state: 'Finished', request_type: 'transformation_plan', - source_id: '26', + source_id: '1', source_type: 'VmOrTemplate', state: 'finished', status: 'Ok', @@ -1156,7 +1156,7 @@ export const allRequestsWithTasks = Immutable({ phase_context: {}, request_state: 'Finished', request_type: 'transformation_plan', - source_id: '26', + source_id: '3', source_type: 'VmOrTemplate', state: 'finished', status: '', @@ -1369,7 +1369,7 @@ export const allRequestsWithTasks = Immutable({ phase_context: {}, request_state: 'Finished', request_type: 'transformation_plan', - source_id: '26', + source_id: '1', source_type: 'VmOrTemplate', state: 'finished', status: 'Ok', @@ -1563,7 +1563,7 @@ export const allRequestsWithTasks = Immutable({ phase_context: {}, request_state: 'Finished', request_type: 'transformation_plan', - source_id: '26', + source_id: '3', source_type: 'VmOrTemplate', state: 'finished', status: 'Ok', @@ -1969,7 +1969,7 @@ export const allRequestsWithTasks = Immutable({ phase_context: {}, request_state: 'Finished', request_type: 'transformation_plan', - source_id: '26', + source_id: '1', source_type: 'VmOrTemplate', state: 'finished', status: 'Error', diff --git a/app/javascript/react/screens/App/Overview/overview.transformationPlans.fixtures.js b/app/javascript/react/screens/App/Overview/overview.transformationPlans.fixtures.js index d5e8bd3629..ed1743a08e 100644 --- a/app/javascript/react/screens/App/Overview/overview.transformationPlans.fixtures.js +++ b/app/javascript/react/screens/App/Overview/overview.transformationPlans.fixtures.js @@ -17,7 +17,7 @@ export const transformationPlans = Immutable({ actions: [{ vm_id: '1' }, { vm_id: '3' }] } }, - created_at: '2018-05-01T12:15:00Z', + created_on: '2018-05-01T12:15:00Z', id: '10', miq_requests: [] }, @@ -81,7 +81,7 @@ export const transformationPlans = Immutable({ actions: [{ vm_id: '1' }, { vm_id: '3' }] } }, - created_at: '2018-05-01T12:13:50Z', + created_on: '2018-05-01T12:13:50Z', id: '30', miq_requests: [ { @@ -166,7 +166,7 @@ export const transformationPlans = Immutable({ actions: [{ vm_id: '1' }, { vm_id: '3' }] } }, - created_at: '2018-05-01T12:13:50', + created_on: '2018-05-01T12:13:50', id: '40', miq_requests: [ { @@ -217,7 +217,7 @@ export const transformationPlans = Immutable({ actions: [{ vm_id: '1' }, { vm_id: '3' }] } }, - created_at: '2018-05-01T12:13:50Z', + created_on: '2018-05-01T12:13:50Z', id: '50', miq_requests: [ { @@ -268,7 +268,7 @@ export const transformationPlans = Immutable({ actions: [{ vm_id: '1' }, { vm_id: '3' }] } }, - created_at: '2018-05-01T12:13:50Z', + created_on: '2018-05-01T12:13:50Z', id: '60', miq_requests: [ { From e00904f8efe55e67a16777ae865a46589636eb31 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Thu, 5 Jul 2018 15:03:31 -0700 Subject: [PATCH 06/10] Extract Task/Request logic in a helper (for reuse) --- .../Migrations/MigrationsCompletedList.js | 31 +++++-------------- .../getMostRecentVMTasksFromRequests.js | 22 +++++++++++++ 2 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js index 75f0129b66..556b39b922 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js @@ -4,7 +4,7 @@ import { noop, Button, ListView, Grid, Spinner, Icon } from 'patternfly-react'; import { IsoElapsedTime } from '../../../../../../components/dates/IsoElapsedTime'; import OverviewEmptyState from '../OverviewEmptyState/OverviewEmptyState'; import getMostRecentRequest from '../../../common/getMostRecentRequest'; -import commonUtilitiesHelper from '../../../common/commonUtilitiesHelper'; +import getMostRecentVMTasksFromRequests from './helpers/getMostRecentVMTasksFromRequests'; const MigrationsCompletedList = ({ finishedTransformationPlans, @@ -34,32 +34,15 @@ const MigrationsCompletedList = ({ const failed = mostRecentRequest && mostRecentRequest.status === 'Error'; const tasks = {}; + let tasksOfPlan = {}; if (requestsOfAssociatedPlan.length > 0) { - const allTasks = requestsOfAssociatedPlan.map(request => request.miq_request_tasks); - - const flattenAllTasks = []; - commonUtilitiesHelper.flattenArray(allTasks, flattenAllTasks); - - const groupedByVMId = commonUtilitiesHelper.groupBy(flattenAllTasks, 'source_id'); - - const vmTasksForRequestOfPlan = []; - vmTasksForRequestOfPlan.push( - plan.options.config_info.vm_ids.map(vmId => - commonUtilitiesHelper.getMostRecentEntityByCreationDate(groupedByVMId[vmId]) - ) - ); - - const flattenVMTasksForRequestOfPlan = []; - commonUtilitiesHelper.flattenArray(vmTasksForRequestOfPlan, flattenVMTasksForRequestOfPlan); - - flattenVMTasksForRequestOfPlan.forEach(task => { - tasks[task.source_id] = task.status === 'Ok'; - }); + tasksOfPlan = getMostRecentVMTasksFromRequests(requestsOfAssociatedPlan, plan.options.config_info.vm_ids); } else if (mostRecentRequest) { - mostRecentRequest.miq_request_tasks.forEach(task => { - tasks[task.source_id] = task.status === 'Ok'; - }); + tasksOfPlan = mostRecentRequest.miq_request_tasks; } + tasksOfPlan.forEach(task => { + tasks[task.source_id] = task.status === 'Ok'; + }); let succeedCount = 0; Object.keys(tasks).forEach(key => { if (tasks[key]) succeedCount += 1; diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js b/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js new file mode 100644 index 0000000000..ae3e291564 --- /dev/null +++ b/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js @@ -0,0 +1,22 @@ +import commonUtilitiesHelper from '../../../../common/commonUtilitiesHelper'; + +const getMostRecentVMTasksFromRequests = (requests, vm_ids) => { + const allTasks = requests.map(request => request.miq_request_tasks); + + const flattenAllTasks = []; + commonUtilitiesHelper.flattenArray(allTasks, flattenAllTasks); + + const groupedByVMId = commonUtilitiesHelper.groupBy(flattenAllTasks, 'source_id'); + + const vmTasksForRequestOfPlan = []; + vmTasksForRequestOfPlan.push( + vm_ids.map(vmId => commonUtilitiesHelper.getMostRecentEntityByCreationDate(groupedByVMId[vmId])) + ); + + const flattenVMTasksForRequestOfPlan = []; + commonUtilitiesHelper.flattenArray(vmTasksForRequestOfPlan, flattenVMTasksForRequestOfPlan); + + return flattenVMTasksForRequestOfPlan; +}; + +export default getMostRecentVMTasksFromRequests; From f689f89524a06b7b29b94a6252fc61d85e95e926 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Thu, 5 Jul 2018 15:23:04 -0700 Subject: [PATCH 07/10] Use the helper to get most recent VM tasks for Plan --- .../Migrations/MigrationsInProgressCard.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js index 825ee6c6ca..a5f0ca0fe1 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js @@ -14,6 +14,7 @@ import { } from 'patternfly-react'; import TickingIsoElapsedTime from '../../../../../../components/dates/TickingIsoElapsedTime'; import getMostRecentRequest from '../../../common/getMostRecentRequest'; +import getMostRecentVMTasksFromRequests from './helpers/getMostRecentVMTasksFromRequests'; const MigrationsInProgressCard = ({ plan, allRequestsWithTasks, reloadCard, handleClick }) => { const requestsOfAssociatedPlan = allRequestsWithTasks.filter(request => request.source_id === plan.id); @@ -52,12 +53,17 @@ const MigrationsInProgressCard = ({ plan, allRequestsWithTasks, reloadCard, hand // UX business rule 2: aggregrate the tasks across requests reflecting current status of all tasks, // (gather the last status for the vm, gather the last storage for use in UX bussiness rule 3) const tasks = {}; - if (mostRecentRequest) - mostRecentRequest.miq_request_tasks.forEach(task => { - tasks[task.source_id] = tasks[task.source_id] || {}; - tasks[task.source_id].completed = task.status === 'Ok' && task.state === 'finished'; - tasks[task.source_id].virtv2v_disks = task.options.virtv2v_disks; - }); + let tasksOfPlan = {}; + if (requestsOfAssociatedPlan.length > 0) { + tasksOfPlan = getMostRecentVMTasksFromRequests(requestsOfAssociatedPlan, plan.options.config_info.vm_ids); + } else if (mostRecentRequest) { + tasksOfPlan = mostRecentRequest.miq_request_tasks; + } + tasksOfPlan.forEach(task => { + tasks[task.source_id] = tasks[task.source_id] || {}; + tasks[task.source_id].completed = task.status === 'Ok' && task.state === 'finished'; + tasks[task.source_id].virtv2v_disks = task.options.virtv2v_disks; + }); let completedVMs = 0; const totalVMs = Object.keys(tasks).length; From a45a951ae276c2bb4c2cfd48241510e596670d63 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Thu, 5 Jul 2018 15:36:59 -0700 Subject: [PATCH 08/10] Use the helper in PlanReducer to get most recent VM tasks for Plan --- .../react/screens/App/Plan/PlanReducer.js | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/app/javascript/react/screens/App/Plan/PlanReducer.js b/app/javascript/react/screens/App/Plan/PlanReducer.js index e263898baf..5b4c4eb9a8 100644 --- a/app/javascript/react/screens/App/Plan/PlanReducer.js +++ b/app/javascript/react/screens/App/Plan/PlanReducer.js @@ -1,6 +1,7 @@ import Immutable from 'seamless-immutable'; import numeral from 'numeral'; import commonUtilitiesHelper from '../common/commonUtilitiesHelper'; +import getMostRecentVMTasksFromRequests from '../Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests'; import { FETCH_V2V_PLAN, @@ -98,22 +99,9 @@ const processVMTasks = vmTasks => { return tasks; }; -const allVMTasksForRequestOfPlan = (vm_ids, requestWithTasks) => { - const allTasks = requestWithTasks.map(request => request.miq_request_tasks); - - const flattenAllTasks = []; - commonUtilitiesHelper.flattenArray(allTasks, flattenAllTasks); - - const groupedByVMId = commonUtilitiesHelper.groupBy(flattenAllTasks, 'source_id'); - - const vmTasksForRequestOfPlan = []; - vmTasksForRequestOfPlan.push( - vm_ids.map(vmId => commonUtilitiesHelper.getMostRecentEntityByCreationDate(groupedByVMId[vmId])) - ); - - const flattenVMTasksForRequestOfPlan = []; - commonUtilitiesHelper.flattenArray(vmTasksForRequestOfPlan, flattenVMTasksForRequestOfPlan); - return processVMTasks(flattenVMTasksForRequestOfPlan); +const allVMTasksForRequestOfPlan = (requestWithTasks, vm_ids) => { + const tasksOfPlan = getMostRecentVMTasksFromRequests(requestWithTasks, vm_ids); + return processVMTasks(tasksOfPlan); }; export default (state = initialState, action) => { @@ -141,7 +129,7 @@ export default (state = initialState, action) => { return state .set( 'planRequestTasks', - allVMTasksForRequestOfPlan(state.plan.options.config_info.vm_ids, action.payload.data.results) + allVMTasksForRequestOfPlan(action.payload.data.results, state.plan.options.config_info.vm_ids) ) .set('allRequestsWithTasksForPlan', action.payload.data.results) .set('planRequestPreviouslyFetched', true) From 82286739e2ec6ca802692b722c812c258a1bebd8 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Thu, 5 Jul 2018 15:37:34 -0700 Subject: [PATCH 09/10] PR feedback - rename `flattenArray` to `flatten` --- .../Migrations/helpers/getMostRecentVMTasksFromRequests.js | 4 ++-- .../react/screens/App/common/commonUtilitiesHelper.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js b/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js index ae3e291564..a9c21c2ea1 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js @@ -4,7 +4,7 @@ const getMostRecentVMTasksFromRequests = (requests, vm_ids) => { const allTasks = requests.map(request => request.miq_request_tasks); const flattenAllTasks = []; - commonUtilitiesHelper.flattenArray(allTasks, flattenAllTasks); + commonUtilitiesHelper.flatten(allTasks, flattenAllTasks); const groupedByVMId = commonUtilitiesHelper.groupBy(flattenAllTasks, 'source_id'); @@ -14,7 +14,7 @@ const getMostRecentVMTasksFromRequests = (requests, vm_ids) => { ); const flattenVMTasksForRequestOfPlan = []; - commonUtilitiesHelper.flattenArray(vmTasksForRequestOfPlan, flattenVMTasksForRequestOfPlan); + commonUtilitiesHelper.flatten(vmTasksForRequestOfPlan, flattenVMTasksForRequestOfPlan); return flattenVMTasksForRequestOfPlan; }; diff --git a/app/javascript/react/screens/App/common/commonUtilitiesHelper.js b/app/javascript/react/screens/App/common/commonUtilitiesHelper.js index bf9663675a..1559bf1d74 100644 --- a/app/javascript/react/screens/App/common/commonUtilitiesHelper.js +++ b/app/javascript/react/screens/App/common/commonUtilitiesHelper.js @@ -11,7 +11,7 @@ const commonUtilitiesHelper = { {} ), - flattenArray: (arrayItems, flattenedArray) => + flatten: (arrayItems, flattenedArray) => arrayItems.map(task => task.map(arrayElement => flattenedArray.push(arrayElement))) }; From e6f6846e5c4cbc61775e74f864cca1ec073fd071 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Mon, 9 Jul 2018 14:47:02 -0700 Subject: [PATCH 10/10] Adjustments w.r.t the new structure of the `vm_id` array retrieval --- .../components/Migrations/MigrationsCompletedList.js | 5 ++++- .../components/Migrations/MigrationsInProgressCard.js | 2 +- .../Migrations/helpers/getMostRecentVMTasksFromRequests.js | 4 +++- app/javascript/react/screens/App/Plan/PlanReducer.js | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js index 556b39b922..015e0ac2d6 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsCompletedList.js @@ -36,7 +36,10 @@ const MigrationsCompletedList = ({ const tasks = {}; let tasksOfPlan = {}; if (requestsOfAssociatedPlan.length > 0) { - tasksOfPlan = getMostRecentVMTasksFromRequests(requestsOfAssociatedPlan, plan.options.config_info.vm_ids); + tasksOfPlan = getMostRecentVMTasksFromRequests( + requestsOfAssociatedPlan, + plan.options.config_info.actions + ); } else if (mostRecentRequest) { tasksOfPlan = mostRecentRequest.miq_request_tasks; } diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js index a5f0ca0fe1..08f0e8d4cf 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/MigrationsInProgressCard.js @@ -55,7 +55,7 @@ const MigrationsInProgressCard = ({ plan, allRequestsWithTasks, reloadCard, hand const tasks = {}; let tasksOfPlan = {}; if (requestsOfAssociatedPlan.length > 0) { - tasksOfPlan = getMostRecentVMTasksFromRequests(requestsOfAssociatedPlan, plan.options.config_info.vm_ids); + tasksOfPlan = getMostRecentVMTasksFromRequests(requestsOfAssociatedPlan, plan.options.config_info.actions); } else if (mostRecentRequest) { tasksOfPlan = mostRecentRequest.miq_request_tasks; } diff --git a/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js b/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js index a9c21c2ea1..fc612de5b8 100644 --- a/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js +++ b/app/javascript/react/screens/App/Overview/components/Migrations/helpers/getMostRecentVMTasksFromRequests.js @@ -1,6 +1,8 @@ import commonUtilitiesHelper from '../../../../common/commonUtilitiesHelper'; -const getMostRecentVMTasksFromRequests = (requests, vm_ids) => { +const getMostRecentVMTasksFromRequests = (requests, actions) => { + const vm_ids = actions.map(a => a.vm_id); + const allTasks = requests.map(request => request.miq_request_tasks); const flattenAllTasks = []; diff --git a/app/javascript/react/screens/App/Plan/PlanReducer.js b/app/javascript/react/screens/App/Plan/PlanReducer.js index 5b4c4eb9a8..4e496c1dae 100644 --- a/app/javascript/react/screens/App/Plan/PlanReducer.js +++ b/app/javascript/react/screens/App/Plan/PlanReducer.js @@ -99,8 +99,8 @@ const processVMTasks = vmTasks => { return tasks; }; -const allVMTasksForRequestOfPlan = (requestWithTasks, vm_ids) => { - const tasksOfPlan = getMostRecentVMTasksFromRequests(requestWithTasks, vm_ids); +const allVMTasksForRequestOfPlan = (requestWithTasks, actions) => { + const tasksOfPlan = getMostRecentVMTasksFromRequests(requestWithTasks, actions); return processVMTasks(tasksOfPlan); }; @@ -129,7 +129,7 @@ export default (state = initialState, action) => { return state .set( 'planRequestTasks', - allVMTasksForRequestOfPlan(action.payload.data.results, state.plan.options.config_info.vm_ids) + allVMTasksForRequestOfPlan(action.payload.data.results, state.plan.options.config_info.actions) ) .set('allRequestsWithTasksForPlan', action.payload.data.results) .set('planRequestPreviouslyFetched', true)