Skip to content

Commit

Permalink
handle edge case of VM not found
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Schuler <[email protected]>
  • Loading branch information
jschuler committed Jan 17, 2025
1 parent 0eafaf8 commit a95afef
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { PlanEditAction } from 'src/modules/Plans/utils/types/PlanEditAction';
import { PlanEditPage } from 'src/modules/Plans/views/edit/PlanEditPage';
import { useModal } from 'src/modules/Providers/modals';
import { useInventoryVms } from 'src/modules/Providers/views';
import { useInventoryVms, VmData } from 'src/modules/Providers/views';
import { useForkliftTranslation } from 'src/utils/i18n';

import {
Expand All @@ -11,6 +11,7 @@ import {
StorageMapModelGroupVersionKind,
V1beta1NetworkMap,
V1beta1Plan,
V1beta1PlanSpecVms,
V1beta1Provider,
V1beta1StorageMap,
} from '@kubev2v/types';
Expand Down Expand Up @@ -80,8 +81,17 @@ export const PlanVMsEditModal: React.FC<PlanVMsEditModalProps> = ({ plan, editAc
sourceProviderLoaded,
sourceProviderLoadError,
);
const initialSelectedIds = plan.spec.vms.map((specVm) => specVm.id);
const selectedVMs = vmData.filter((vm) => initialSelectedIds.includes(vm.vm.id));
const selectedVMs: VmData[] = [];
const notFoundPlanVMs: V1beta1PlanSpecVms[] = [];
plan.spec.vms.forEach((planVm) => {
const providerVm = vmData.find((vm) => vm.vm.id === planVm.id);
if (providerVm) {
selectedVMs.push(providerVm);
} else {
// Edge case: plan VM not found in list of provider VMs
notFoundPlanVMs.push(planVm);
}
});

const planNetworkMaps = networkMaps
? networkMaps.find((net) => net?.metadata?.name === plan?.spec?.map?.network?.name)
Expand Down Expand Up @@ -133,6 +143,7 @@ export const PlanVMsEditModal: React.FC<PlanVMsEditModalProps> = ({ plan, editAc
editAction={editAction}
onClose={toggleModal}
selectedVMs={selectedVMs}
notFoundPlanVMs={notFoundPlanVMs}
planNetworkMaps={planNetworkMaps}
planStorageMaps={planStorageMaps}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import { useFetchEffects } from 'src/modules/Providers/views/migrate/useFetchEff
import { useUpdateEffect } from 'src/modules/Providers/views/migrate/useUpdateEffect';
import { useForkliftTranslation } from 'src/utils/i18n';

import { V1beta1NetworkMap, V1beta1Plan, V1beta1Provider, V1beta1StorageMap } from '@kubev2v/types';
import { PageSection, Title } from '@patternfly/react-core';
import {
V1beta1NetworkMap,
V1beta1Plan,
V1beta1PlanSpecVms,
V1beta1Provider,
V1beta1StorageMap,
} from '@kubev2v/types';
import { Alert, PageSection, Text, TextContent, Title } from '@patternfly/react-core';
import { Wizard } from '@patternfly/react-core/deprecated';

import { findProviderByID } from '../create/components';
Expand All @@ -29,7 +35,8 @@ export const PlanEditPage: React.FC<{
targetProvider: V1beta1Provider;
projectName: string;
onClose: () => void;
selectedVMs?: VmData[];
selectedVMs: VmData[];
notFoundPlanVMs: V1beta1PlanSpecVms[];
editAction: PlanEditAction;
planNetworkMaps: V1beta1NetworkMap;
planStorageMaps: V1beta1StorageMap;
Expand All @@ -41,6 +48,7 @@ export const PlanEditPage: React.FC<{
projectName,
onClose,
selectedVMs,
notFoundPlanVMs,
editAction,
planNetworkMaps,
planStorageMaps,
Expand Down Expand Up @@ -110,17 +118,29 @@ export const PlanEditPage: React.FC<{
id: 'step-1',
name: editAction === 'VMS' ? t('Select virtual machines') : t('Select source provider'),
component: (
<SelectSourceProvider
projectName={projectName}
filterState={filterState}
filterDispatch={filterDispatch}
state={state}
dispatch={dispatch}
providers={providers}
selectedProvider={selectedProvider}
hideProviderSection={editAction === 'VMS'}
disabledVmIds={migratedVmIds}
/>
<>
{notFoundPlanVMs.length > 0 && (
<Alert
title="The following VMs do not exist on the source provider and will be removed from the plan"
variant="danger"
>
<TextContent className="forklift-providers-list-header__alert">
<Text component="p">{notFoundPlanVMs.map((vm) => `${vm.name} `)}</Text>
</TextContent>
</Alert>
)}
<SelectSourceProvider
projectName={projectName}
filterState={filterState}
filterDispatch={filterDispatch}
state={state}
dispatch={dispatch}
providers={providers}
selectedProvider={selectedProvider}
hideProviderSection={editAction === 'VMS'}
disabledVmIds={migratedVmIds}
/>
</>
),
enableNext: filterState?.selectedVMs?.length > 0,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import { PlanMappingsSectionState } from 'src/modules/Plans/views/details/tabs/Mappings/PlanMappingsSection';
import { useForkliftTranslation } from 'src/utils/i18n';

import { LoadingDots } from '@kubev2v/common';
import { V1beta1NetworkMap, V1beta1StorageMap } from '@kubev2v/types';
import { Alert } from '@patternfly/react-core';
import { Alert, Title } from '@patternfly/react-core';

import { PlansUpdateForm } from './components/PlansUpdateForm';
import { CreateVmMigration, PageAction } from './reducer/actions';
Expand All @@ -30,6 +31,7 @@ const ProvidersUpdateVmMigrationPage: React.FC<{
planNetworkMaps,
planStorageMaps,
}) => {
const { t } = useForkliftTranslation();
if (emptyContext) {
// display empty node and wait for redirect triggered from useEffect
// the redirect should be triggered right after the first render()
Expand All @@ -56,7 +58,11 @@ const ProvidersUpdateVmMigrationPage: React.FC<{
planMappingsDispatch={planMappingsDispatch}
planNetworkMaps={planNetworkMaps}
planStorageMaps={planStorageMaps}
/>
>
<Title headingLevel="h2" className="forklift--create-plan--title">
{t('Update mappings')}
</Title>
</PlansUpdateForm>
);
};

Expand Down

0 comments on commit a95afef

Please sign in to comment.