Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

[#437] Resolve all Retry Migration issues #468

Merged
merged 10 commits into from
Jul 9, 2018
2 changes: 1 addition & 1 deletion app/javascript/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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 getMostRecentVMTasksFromRequests from './helpers/getMostRecentVMTasksFromRequests';

const MigrationsCompletedList = ({
finishedTransformationPlans,
Expand Down Expand Up @@ -33,11 +34,18 @@ const MigrationsCompletedList = ({
const failed = mostRecentRequest && mostRecentRequest.status === 'Error';

const tasks = {};
if (mostRecentRequest)
mostRecentRequest.miq_request_tasks.forEach(task => {
tasks[task.source_id] = task.status === 'Ok';
});

let tasksOfPlan = {};
if (requestsOfAssociatedPlan.length > 0) {
tasksOfPlan = getMostRecentVMTasksFromRequests(
requestsOfAssociatedPlan,
plan.options.config_info.actions
);
} else if (mostRecentRequest) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -52,12 +53,16 @@ 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;
});
let tasksOfPlan = {};
if (requestsOfAssociatedPlan.length > 0) {
tasksOfPlan = getMostRecentVMTasksFromRequests(requestsOfAssociatedPlan, plan.options.config_info.actions);
} 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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still haven't extracted these task statuses to constants... since the number of places these are used is increasing, and we have pre/post playbook support upcoming, i think it would be nice to move those to constants in a future PR

tasks[task.source_id].virtv2v_disks = task.options.virtv2v_disks;
});

let completedVMs = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import commonUtilitiesHelper from '../../../../common/commonUtilitiesHelper';

const getMostRecentVMTasksFromRequests = (requests, actions) => {
const vm_ids = actions.map(a => a.vm_id);

const allTasks = requests.map(request => request.miq_request_tasks);

const flattenAllTasks = [];
commonUtilitiesHelper.flatten(allTasks, flattenAllTasks);

const groupedByVMId = commonUtilitiesHelper.groupBy(flattenAllTasks, 'source_id');

const vmTasksForRequestOfPlan = [];
vmTasksForRequestOfPlan.push(
vm_ids.map(vmId => commonUtilitiesHelper.getMostRecentEntityByCreationDate(groupedByVMId[vmId]))
);

const flattenVMTasksForRequestOfPlan = [];
commonUtilitiesHelper.flatten(vmTasksForRequestOfPlan, flattenVMTasksForRequestOfPlan);

return flattenVMTasksForRequestOfPlan;
};

export default getMostRecentVMTasksFromRequests;
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -556,7 +556,7 @@ export const allRequestsWithTasks = Immutable({
phase_context: {},
request_state: '<SOMETHING>',
request_type: 'transformation_plan',
source_id: '26',
source_id: '3',
source_type: 'VmOrTemplate',
state: 'active',
status: 'Ok',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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: '<REQUEST_TASK_FAILED>',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
},
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down
19 changes: 9 additions & 10 deletions app/javascript/react/screens/App/Plan/Plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Plan extends React.Component {
fetchPlanUrl,
fetchPlanAction,
planId,
fetchPlanRequestUrl,
fetchPlanRequestAction,
fetchTasksForAllRequestsForPlanUrl,
fetchTasksForAllRequestsForPlanAction,
queryPlanVmsAction
} = this.props;

Expand All @@ -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
Expand All @@ -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);
};

Expand Down Expand Up @@ -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,
Expand Down
27 changes: 17 additions & 10 deletions app/javascript/react/screens/App/Plan/PlanActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
// *****************************************************************************
Expand Down
1 change: 1 addition & 0 deletions app/javascript/react/screens/App/Plan/PlanConstants.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Loading