diff --git a/src/app/plan/duck/actions.ts b/src/app/plan/duck/actions.ts index d45d9714f..80bd9ce2a 100644 --- a/src/app/plan/duck/actions.ts +++ b/src/app/plan/duck/actions.ts @@ -383,33 +383,6 @@ const stopPlanStatusPolling = (planName: string) => ({ planName, }); -const startStagePolling = (params?: any) => ({ - type: PlanActionTypes.STAGE_POLL_START, - params, -}); - -const stopStagePolling = () => ({ - type: PlanActionTypes.STAGE_POLL_STOP, -}); - -const startMigrationPolling = (params?: any) => ({ - type: PlanActionTypes.MIGRATION_POLL_START, - params, -}); - -const stopMigrationPolling = () => ({ - type: PlanActionTypes.MIGRATION_POLL_STOP, -}); - -const startRollbackPolling = (params?: any) => ({ - type: PlanActionTypes.ROLLBACK_POLL_START, - params, -}); - -const stopRollbackPolling = () => ({ - type: PlanActionTypes.ROLLBACK_POLL_STOP, -}); - const startPlanPolling = (params?: any) => ({ type: PlanActionTypes.PLAN_POLL_START, params, @@ -642,12 +615,6 @@ export const PlanActions = { stopPlanPolling, resetCurrentPlan, setCurrentPlan, - startStagePolling, - stopStagePolling, - startMigrationPolling, - stopMigrationPolling, - startRollbackPolling, - stopRollbackPolling, /* Hook exports */ diff --git a/src/app/plan/duck/sagas.ts b/src/app/plan/duck/sagas.ts index f8cc1b830..c4d081d3f 100644 --- a/src/app/plan/duck/sagas.ts +++ b/src/app/plan/duck/sagas.ts @@ -696,50 +696,6 @@ function* getPVResourcesRequest(action) { /* Stage sagas */ /******************************************************************** */ -function getStageStatusCondition(updatedPlans, createMigRes) { - const matchingPlan = updatedPlans.updatedPlans.find( - (p) => p.MigPlan.metadata.name === createMigRes.data.spec.migPlanRef.name - ); - const statusObj = { status: null, planName: null, errorMessage: null }; - - if (matchingPlan && matchingPlan.Migrations) { - const matchingMigration = matchingPlan.Migrations.find( - (s) => s.metadata.name === createMigRes.data.metadata.name - ); - - if (matchingMigration && matchingMigration.status?.conditions) { - const hasSucceededCondition = !!matchingMigration.status.conditions.some( - (c) => c.type === 'Succeeded' - ); - if (hasSucceededCondition) { - statusObj.status = 'SUCCESS'; - } - - const hasErrorCondition = !!matchingMigration.status.conditions.some( - (c) => c.type === 'Failed' || c.category === 'Critical' - ); - const errorCondition = matchingMigration.status.conditions.find( - (c) => c.type === 'Failed' || c.category === 'Critical' - ); - if (hasErrorCondition) { - statusObj.status = 'FAILURE'; - statusObj.errorMessage = errorCondition.message; - } - - const hasWarnCondition = !!matchingMigration.status.conditions.some( - (c) => c.category === 'Warn' - ); - const warnCondition = matchingMigration.status.conditions.find((c) => c.category === 'Warn'); - - if (hasWarnCondition) { - statusObj.status = 'WARN'; - statusObj.errorMessage = warnCondition.message; - } - statusObj.planName = matchingPlan.MigPlan.metadata.name; - } - } - return statusObj; -} function* runStageSaga(action) { try { const state: IReduxState = yield select(); @@ -760,19 +716,10 @@ function* runStageSaga(action) { ); const migMigrationResource = new MigResource(MigResourceKind.MigMigration, migMeta.namespace); - //created migration response object - const createMigRes = yield client.create(migMigrationResource, migMigrationObj); + yield client.create(migMigrationResource, migMigrationObj); const migrationListResponse = yield client.list(migMigrationResource); const groupedPlan = planUtils.groupPlan(plan, migrationListResponse); - const params = { - fetchPlansGenerator: fetchPlansGenerator, - delay: PlanMigrationPollingInterval, - getStageStatusCondition: getStageStatusCondition, - createMigRes: createMigRes, - }; - - yield put(PlanActions.startStagePolling(params)); yield put(PlanActions.updatePlanMigrations(groupedPlan)); } catch (err) { yield put(AlertActions.alertErrorTimeout(err)); @@ -780,96 +727,10 @@ function* runStageSaga(action) { } } -function* stagePoll(action) { - const params = { ...action.params }; - while (true) { - const updatedPlans = yield call(params.fetchPlansGenerator); - const pollingStatusObj = params.getStageStatusCondition(updatedPlans, params.createMigRes); - - switch (pollingStatusObj.status) { - case 'SUCCESS': - yield put(PlanActions.stagingSuccess(pollingStatusObj.planName)); - yield put(AlertActions.alertSuccessTimeout('Staging Successful')); - yield put(PlanActions.stopStagePolling()); - break; - case 'FAILURE': - yield put(PlanActions.stagingFailure(pollingStatusObj.error)); - yield put( - AlertActions.alertErrorTimeout(`${pollingStatusObj.errorMessage || 'Staging Failed'}`) - ); - yield put(PlanActions.stopStagePolling()); - break; - case 'WARN': - yield put(PlanActions.stagingFailure(pollingStatusObj.error)); - yield put( - AlertActions.alertWarn( - `Staging succeeded with warnings. ${pollingStatusObj.errorMessage}` - ) - ); - yield put(PlanActions.stopStagePolling()); - break; - default: - break; - } - yield delay(params.delay); - } -} - /******************************************************************** */ /* Migration sagas */ /******************************************************************** */ -function getMigrationStatusCondition(updatedPlans, createMigRes) { - const matchingPlan = updatedPlans.updatedPlans.find( - (p) => p.MigPlan.metadata.name === createMigRes.data.spec.migPlanRef.name - ); - const statusObj = { status: null, planName: null, errorMessage: null }; - - if (matchingPlan && matchingPlan.Migrations) { - const matchingMigration = matchingPlan.Migrations.find( - (s) => s.metadata.name === createMigRes.data.metadata.name - ); - - if (matchingMigration && matchingMigration.status?.conditions) { - const hasSucceededCondition = !!matchingMigration.status.conditions.some( - (c) => c.type === 'Succeeded' - ); - const hasCanceledCondition = !!matchingMigration.status.conditions.some( - (c) => c.type === 'Canceled' - ); - if (hasCanceledCondition) { - statusObj.status = 'CANCELED'; - } else if (hasSucceededCondition) { - const hasWarnCondition = !!matchingMigration.status.conditions.some( - (c) => c.category === 'Warn' - ); - const warnCondition = matchingMigration.status.conditions.find( - (c) => c.category === 'Warn' - ); - - if (hasWarnCondition) { - statusObj.status = 'WARN'; - statusObj.errorMessage = warnCondition.message; - } else { - statusObj.status = 'SUCCESS'; - } - } - const hasErrorCondition = !!matchingMigration.status.conditions.some( - (c) => c.type === 'Failed' || c.category === 'Critical' - ); - const errorCondition = matchingMigration.status.conditions.find( - (c) => c.type === 'Failed' || c.category === 'Critical' - ); - if (hasErrorCondition) { - statusObj.status = 'FAILURE'; - statusObj.errorMessage = errorCondition.message; - } - statusObj.planName = matchingPlan.MigPlan.metadata.name; - } - } - return statusObj; -} - function* runMigrationSaga(action) { try { const { plan, enableQuiesce } = action; @@ -888,66 +749,17 @@ function* runMigrationSaga(action) { false ); const migMigrationResource = new MigResource(MigResourceKind.MigMigration, migMeta.namespace); - - //created migration response object - const createMigRes = yield client.create(migMigrationResource, migMigrationObj); + yield client.create(migMigrationResource, migMigrationObj); const migrationListResponse = yield client.list(migMigrationResource); const groupedPlan = planUtils.groupPlan(plan, migrationListResponse); - const params = { - fetchPlansGenerator: fetchPlansGenerator, - delay: PlanMigrationPollingInterval, - getMigrationStatusCondition: getMigrationStatusCondition, - createMigRes: createMigRes, - }; - - yield put(PlanActions.startMigrationPolling(params)); yield put(PlanActions.updatePlanMigrations(groupedPlan)); } catch (err) { yield put(AlertActions.alertErrorTimeout(err)); yield put(PlanActions.migrationFailure(err)); } } -function* migrationPoll(action) { - const params = { ...action.params }; - while (true) { - const updatedPlans = yield call(params.fetchPlansGenerator); - const pollingStatusObj = params.getMigrationStatusCondition(updatedPlans, params.createMigRes); - - switch (pollingStatusObj.status) { - case 'CANCELED': - yield put(AlertActions.alertSuccessTimeout('Migration canceled')); - yield put(PlanActions.stopMigrationPolling()); - break; - case 'SUCCESS': - yield put(PlanActions.migrationSuccess(pollingStatusObj.planName)); - yield put(AlertActions.alertSuccessTimeout('Migration Successful')); - yield put(PlanActions.stopMigrationPolling()); - break; - case 'FAILURE': - yield put(PlanActions.migrationFailure(pollingStatusObj.error)); - yield put( - AlertActions.alertErrorTimeout(`${pollingStatusObj.errorMessage || 'Migration Failed'}`) - ); - yield put(PlanActions.stopMigrationPolling()); - break; - case 'WARN': - yield put(PlanActions.migrationFailure(pollingStatusObj.error)); - yield put( - AlertActions.alertWarn( - `Migration succeeded with warnings. ${pollingStatusObj.errorMessage}` - ) - ); - yield put(PlanActions.stopMigrationPolling()); - break; - - default: - break; - } - yield delay(params.delay); - } -} /******************************************************************** */ //Rollback sagas @@ -1018,18 +830,10 @@ function* runRollbackSaga(action) { const migMigrationResource = new MigResource(MigResourceKind.MigMigration, migMeta.namespace); //created migration response object - const createMigRes = yield client.create(migMigrationResource, migMigrationObj); + yield client.create(migMigrationResource, migMigrationObj); const migrationListResponse = yield client.list(migMigrationResource); const groupedPlan = planUtils.groupPlan(plan, migrationListResponse); - const params = { - fetchPlansGenerator: fetchPlansGenerator, - delay: PlanMigrationPollingInterval, - getRollbackStatusCondition: getRollbackStatusCondition, - createMigRes: createMigRes, - }; - - yield put(PlanActions.startRollbackPolling(params)); yield put(PlanActions.updatePlanMigrations(groupedPlan)); } catch (err) { yield put(AlertActions.alertErrorTimeout(err)); @@ -1037,46 +841,6 @@ function* runRollbackSaga(action) { } } -function* rollbackPoll(action) { - const params = { ...action.params }; - while (true) { - const updatedPlans = yield call(params.fetchPlansGenerator); - const pollingStatusObj = params.getRollbackStatusCondition(updatedPlans, params.createMigRes); - - switch (pollingStatusObj.status) { - case 'CANCELED': - yield put(AlertActions.alertSuccessTimeout('Rollback canceled')); - yield put(PlanActions.stopRollbackPolling()); - break; - case 'SUCCESS': - yield put(PlanActions.migrationSuccess(pollingStatusObj.planName)); - yield put(AlertActions.alertSuccessTimeout('Rollback Successful')); - yield put(PlanActions.stopRollbackPolling()); - break; - case 'FAILURE': - yield put(PlanActions.migrationFailure(pollingStatusObj.error)); - yield put( - AlertActions.alertErrorTimeout(`${pollingStatusObj.errorMessage || 'Rollback Failed'}`) - ); - yield put(PlanActions.stopRollbackPolling()); - break; - case 'WARN': - yield put(PlanActions.migrationFailure(pollingStatusObj.error)); - yield put( - AlertActions.alertWarn( - `Rollback succeeded with warnings. ${pollingStatusObj.errorMessage}` - ) - ); - yield put(PlanActions.stopRollbackPolling()); - break; - - default: - break; - } - yield delay(params.delay); - } -} - /******************************************************************** */ //Hooks sagas /******************************************************************** */ @@ -1391,27 +1155,6 @@ function* watchAddHookRequest() { yield takeLatest(PlanActionTypes.ADD_HOOK_REQUEST, addHookSaga); } -function* watchStagePolling() { - while (true) { - const data = yield take(PlanActionTypes.STAGE_POLL_START); - yield race([call(stagePoll, data), take(PlanActionTypes.STAGE_POLL_STOP)]); - } -} - -function* watchMigrationPolling() { - while (true) { - const data = yield take(PlanActionTypes.MIGRATION_POLL_START); - yield race([call(migrationPoll, data), take(PlanActionTypes.MIGRATION_POLL_STOP)]); - } -} - -function* watchRollbackPolling() { - while (true) { - const data = yield take(PlanActionTypes.ROLLBACK_POLL_START); - yield race([call(rollbackPoll, data), take(PlanActionTypes.ROLLBACK_POLL_STOP)]); - } -} - function* watchMigrationCancel() { yield takeEvery(PlanActionTypes.MIGRATION_CANCEL_REQUEST, migrationCancel); } @@ -1500,9 +1243,6 @@ function* watchUpdatePlanHookList() { } export default { - watchStagePolling, - watchMigrationPolling, - watchRollbackPolling, fetchHooksGenerator, fetchPlansGenerator, watchRunStageRequest, diff --git a/src/sagas.ts b/src/sagas.ts index 45b9ac986..0016d0a26 100644 --- a/src/sagas.ts +++ b/src/sagas.ts @@ -45,9 +45,6 @@ export default function* rootSaga() { commonSagas.watchStoragePolling(), commonSagas.watchHookPolling(), commonSagas.watchAlerts(), - planSagas.watchStagePolling(), - planSagas.watchMigrationPolling(), - planSagas.watchRollbackPolling(), planSagas.watchAddPlanRequest(), planSagas.watchAddAnalyticRequest(), planSagas.watchDeleteAnalyticRequest(),