-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide osd migration status alert for dr brownfield
Signed-off-by: Timothy Asir Jeyasingh <[email protected]>
- Loading branch information
1 parent
5117053
commit 862c3ac
Showing
11 changed files
with
262 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/mco/components/modals/app-failover-relocate/error-messages.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/mco/components/modals/app-failover-relocate/subscriptions/error-messages.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './disaster-recovery'; | ||
export * from './common'; | ||
export * from './doc-utils'; |
82 changes: 82 additions & 0 deletions
82
...cs/dashboards/persistent-internal/status-card/osd-migration/osd-migration-status.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
import { BLUESTORE, BLUESTORE_RDR } from '@odf/core/constants'; | ||
import { cleanup, render, screen, waitFor } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import * as migrationStatus from '../../../../utils/osd-migration'; | ||
import { OSDMigration } from './osd-migration-status'; | ||
|
||
jest.mock('@odf/shared/status/icons', () => ({ | ||
RedExclamationCircleIcon: 'div', | ||
})); | ||
|
||
jest.mock('@openshift-console/dynamic-plugin-sdk-internal', () => ({ | ||
HealthBody: 'div', | ||
HealthItem: ({ title }) => <div>{title}</div>, | ||
ViewDocumentation: ({ text, doclink }) => <a href={doclink}>{text}</a>, | ||
HealthState: { | ||
OK: 'OK', | ||
}, | ||
})); | ||
|
||
jest.mock('../../../../utils/osd-migration'); | ||
afterEach(cleanup); | ||
|
||
describe('OSDMigrationStatus', () => { | ||
test('renders the component with COMPLETED status', async () => { | ||
const cephData = { | ||
status: { | ||
storage: { | ||
osd: { | ||
storeType: { | ||
[BLUESTORE_RDR]: 5, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
migrationStatus.getOSDMigrationStatus.mockReturnValue('Completed'); | ||
|
||
render( | ||
<MemoryRouter> | ||
<OSDMigration cephData={cephData} /> | ||
</MemoryRouter> | ||
); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByText('Cluster ready for Regional-DR setup.') | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('renders the component with PENDING status', async () => { | ||
const cephData = { | ||
status: { | ||
storage: { | ||
osd: { | ||
storeType: { | ||
[BLUESTORE]: 10, | ||
[BLUESTORE_RDR]: 5, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
migrationStatus.getOSDMigrationStatus.mockReturnValue('In Progress'); | ||
|
||
render( | ||
<MemoryRouter> | ||
<OSDMigration cephData={cephData} /> | ||
</MemoryRouter> | ||
); | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByText('Cluster OSDs are being migrated') | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
119 changes: 119 additions & 0 deletions
119
...ges/ocs/dashboards/persistent-internal/status-card/osd-migration/osd-migration-status.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import * as React from 'react'; | ||
import { | ||
OSDMigrationStatus, | ||
BLUESTORE, | ||
BLUESTORE_RDR, | ||
} from '@odf/core/constants'; | ||
import { DOC_LINKS, ViewDocumentation } from '@odf/shared/doc/doc-utils'; | ||
import { RedExclamationCircleIcon } from '@odf/shared/status/icons'; | ||
import { CephClusterKind } from '@odf/shared/types'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import { HealthState } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { | ||
HealthBody, | ||
HealthItem, | ||
} from '@openshift-console/dynamic-plugin-sdk-internal'; | ||
import { Divider, Flex, FlexItem } from '@patternfly/react-core'; | ||
import { InProgressIcon } from '@patternfly/react-icons'; | ||
import { getOSDMigrationStatus } from '../../../../utils/osd-migration'; | ||
|
||
const calculateOSDMigration = ( | ||
cephData: CephClusterKind | ||
): [number, number, number] => { | ||
const migratedDevices = | ||
cephData?.status?.storage?.osd?.storeType?.[BLUESTORE_RDR] || 0; | ||
const totalOsd = | ||
(cephData?.status?.storage?.osd?.storeType?.[BLUESTORE] || 0) + | ||
migratedDevices; | ||
const percentageComplete = | ||
totalOsd !== 0 ? Math.round((migratedDevices / totalOsd) * 100) : 0; | ||
|
||
return [migratedDevices, totalOsd, percentageComplete]; | ||
}; | ||
|
||
export const OSDMigration: React.FC<OSDMigrationStatusProps> = ({ | ||
cephData, | ||
}) => { | ||
const { t } = useCustomTranslation(); | ||
const [migratedDevices, totalOsd, percentageComplete] = | ||
calculateOSDMigration(cephData); | ||
const migrationStatus: string = getOSDMigrationStatus(cephData); | ||
|
||
return ( | ||
<> | ||
{migrationStatus !== OSDMigrationStatus.COMPLETED && <Divider />} | ||
<HealthBody> | ||
<Flex alignItems={{ default: 'alignItemsCenter' }}> | ||
{migrationStatus === OSDMigrationStatus.COMPLETED && ( | ||
<> | ||
<HealthItem | ||
title={t('Cluster ready for Regional-DR setup.')} | ||
state={HealthState.OK} | ||
/> | ||
<ViewDocumentation | ||
text={t('Setting up disaster recovery')} | ||
doclink={DOC_LINKS.APPLY_POLICY} | ||
/> | ||
</> | ||
)} | ||
|
||
{migrationStatus === OSDMigrationStatus.IN_PROGRESS && ( | ||
<> | ||
<FlexItem> | ||
<HealthItem | ||
icon={<InProgressIcon className="co-dashboard-icon" />} | ||
state={HealthState.OK} | ||
title={t('Cluster OSDs are being migrated')} | ||
/> | ||
</FlexItem> | ||
<FlexItem> | ||
{t( | ||
'{{ percentageComplete }}% completed ({{ migratedDevices }}/ {{ totalOsd }} remaining)', | ||
{ | ||
percentageComplete, | ||
migratedDevices, | ||
totalOsd, | ||
} | ||
)} | ||
</FlexItem> | ||
</> | ||
)} | ||
|
||
{migrationStatus === OSDMigrationStatus.FAILED && ( | ||
<> | ||
<FlexItem> | ||
<HealthItem | ||
state={HealthState.OK} | ||
icon={ | ||
<RedExclamationCircleIcon className="co-dashboard-icon" /> | ||
} | ||
title={t('Could not migrate cluster OSDs.')} | ||
/> | ||
</FlexItem> | ||
<FlexItem> | ||
<ViewDocumentation | ||
text={t('Check documentation')} | ||
doclink={DOC_LINKS.APPLY_POLICY} | ||
/> | ||
</FlexItem> | ||
<FlexItem align={{ default: 'alignRight' }}> | ||
{t( | ||
'{{ percentageComplete }}% completed ({{ migratedDevices }}/ {{ totalOsd }} remaining)', | ||
{ | ||
percentageComplete, | ||
migratedDevices, | ||
totalOsd, | ||
} | ||
)} | ||
</FlexItem> | ||
</> | ||
)} | ||
</Flex> | ||
</HealthBody> | ||
</> | ||
); | ||
}; | ||
|
||
type OSDMigrationStatusProps = { | ||
cephData?: CephClusterKind; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
BLUESTORE, | ||
BLUESTORE_RDR, | ||
DISASTER_RECOVERY_TARGET_ANNOTATION, | ||
OSDMigrationStatus, | ||
} from '@odf/core/constants'; | ||
import { getAnnotations } from '@odf/shared/selectors'; | ||
import { CephClusterKind } from '@odf/shared/types'; | ||
|
||
export const getOSDMigrationStatus = (ceph: CephClusterKind) => { | ||
if (!!ceph) { | ||
const bluestoreCount = ceph?.status?.storage?.osd?.storeType?.[BLUESTORE]; | ||
const bluestoreRdrCount = | ||
ceph?.status?.storage?.osd?.storeType?.[BLUESTORE_RDR]; | ||
|
||
const isDisasterRecoveryTarget = | ||
getAnnotations(ceph)?.[DISASTER_RECOVERY_TARGET_ANNOTATION] === 'true'; | ||
|
||
if (bluestoreCount > 0) { | ||
if (bluestoreRdrCount > 0 || isDisasterRecoveryTarget) { | ||
return OSDMigrationStatus.IN_PROGRESS; | ||
} else { | ||
return OSDMigrationStatus.PENDING; | ||
} | ||
} else if (bluestoreRdrCount > 0) { | ||
return OSDMigrationStatus.COMPLETED; | ||
} | ||
} else { | ||
return OSDMigrationStatus.FAILED; | ||
} // TODO Add condition for migration failure | ||
|
||
return ''; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
export const DISASTER_RECOVERY_TARGET_ANNOTATION = | ||
'ocs.openshift.io/clusterIsDisasterRecoveryTarget'; | ||
|
||
export enum OSDMigrationStatus { | ||
IN_PROGRESS = 'In Progress', | ||
PENDING = 'Pending', | ||
COMPLETED = 'Completed', | ||
FAILED = 'Failed', | ||
} | ||
|
||
export const BLUESTORE_RDR = 'bluestore-rdr'; | ||
export const BLUESTORE = 'bluestore'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters