diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx index 3dcc55adbe61d..4cd4bf3f76629 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/backup_step/backup_step.test.tsx @@ -5,7 +5,10 @@ * 2.0. */ -import { CLOUD_BACKUP_STATUS_POLL_INTERVAL_MS } from '../../../../common/constants'; +import { + CLOUD_BACKUP_STATUS_POLL_INTERVAL_MS, + CLOUD_SNAPSHOT_REPOSITORY, +} from '../../../../common/constants'; import { setupEnvironment, advanceTime } from '../../helpers'; import { OverviewTestBed, setupOverviewPage } from '../overview.helpers'; @@ -89,6 +92,22 @@ describe('Overview - Backup Step', () => { testBed.component.update(); expect(exists('cloudBackupRetryButton')).toBe(true); }); + + test('loads on prem if missing found-snapshots repository', async () => { + httpRequestsMockHelpers.setLoadCloudBackupStatusResponse(undefined, { + statusCode: 404, + message: `[${CLOUD_SNAPSHOT_REPOSITORY}] missing`, + }); + + testBed = await setupCloudOverviewPage(); + + const { exists } = testBed; + + testBed.component.update(); + + expect(exists('snapshotRestoreLink')).toBe(true); + expect(exists('cloudBackupErrorCallout')).toBe(false); + }); }); describe('success state', () => { diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx index 46b11aee15b33..1825b04717311 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/backup_step.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React from 'react'; +import React, { useState } from 'react'; import { i18n } from '@kbn/i18n'; import type { EuiStepProps } from '@elastic/eui/src/components/steps/step'; @@ -22,24 +22,29 @@ interface Props extends OverviewStepProps { cloud?: CloudSetup; } -export const getBackupStep = ({ cloud, isComplete, setIsComplete }: Props): EuiStepProps => { - const status = isComplete ? 'complete' : 'incomplete'; - - if (cloud?.isCloudEnabled) { - return { - status, - title, - 'data-test-subj': `backupStep-${status}`, - children: ( - - ), - }; +const BackupStep = ({ cloud, setIsComplete }: Omit) => { + const [forceOnPremStep, setForceOnPremStep] = useState(false); + + if (cloud?.isCloudEnabled && !forceOnPremStep) { + return ( + + ); } + return ; +}; + +export const getBackupStep = ({ cloud, isComplete, setIsComplete }: Props): EuiStepProps => { + const status = cloud?.isCloudEnabled ? (isComplete ? 'complete' : 'incomplete') : 'incomplete'; + return { title, - 'data-test-subj': 'backupStep-incomplete', - status: 'incomplete', - children: , + status, + 'data-test-subj': `backupStep-${status}`, + children: , }; }; diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/cloud_backup.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/cloud_backup.tsx index fc87f1a620930..fdb5aa32147e0 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/cloud_backup.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/cloud_backup.tsx @@ -21,17 +21,25 @@ import { EuiCallOut, } from '@elastic/eui'; +import { CLOUD_SNAPSHOT_REPOSITORY } from '../../../../../common/constants'; import { useAppContext } from '../../../app_context'; +import { ResponseError } from '../../../../../common/types'; import { uiMetricService, UIM_BACKUP_DATA_CLOUD_CLICK } from '../../../lib/ui_metric'; interface Props { cloudSnapshotsUrl: string; setIsComplete: (isComplete: boolean) => void; + setForceOnPremStep: (forceOnPrem: boolean) => void; } +const isMissingFoundSnapshotsRepo = (error: ResponseError) => { + return error.statusCode === 404 && error.message.toString().includes(CLOUD_SNAPSHOT_REPOSITORY); +}; + export const CloudBackup: React.FunctionComponent = ({ cloudSnapshotsUrl, setIsComplete, + setForceOnPremStep, }) => { const { services: { api }, @@ -46,10 +54,18 @@ export const CloudBackup: React.FunctionComponent = ({ if (!isLoading) { // An error should invalidate the previous state. setIsComplete((!error && data?.isBackedUp) ?? false); + // If snapshots are not enabled, as it could happen in an ECE installation, the + // cloud backup status api will return a 404 error saying that the found-snapshots + // repository is missing. If that were to happen, we should force the users to see + // the on prem backup step instead. + if (error && isMissingFoundSnapshotsRepo(error)) { + setForceOnPremStep(true); + } } + // Depending upon setIsComplete would create an infinite loop. // eslint-disable-next-line react-hooks/exhaustive-deps - }, [error, isLoading, data]); + }, [error, isLoading, data, setForceOnPremStep]); if (isInitialRequest && isLoading) { return ;