Skip to content

Commit

Permalink
improve bulk restore latest backup and bulk create DR volume actions
Browse files Browse the repository at this point in the history
Signed-off-by: andy.lee <andy.lee@suse.com>
  • Loading branch information
a110605 committed Aug 9, 2024
1 parent 94f0a43 commit 4c86dfb
Show file tree
Hide file tree
Showing 10 changed files with 826 additions and 372 deletions.
380 changes: 191 additions & 189 deletions src/components/ReactCron/ReactCron.js

Large diffs are not rendered by default.

76 changes: 36 additions & 40 deletions src/models/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ export default {
selectedRows: [],
workloadDetailModalItem: {},
backupStatus: {},
currentItem: {},
currentItem: [],
currentBackupVolume: {},
lastBackupUrl: '',
baseImage: '',
volumeName: '',
backupTargetMessage: '',
previousChecked: false,
Expand All @@ -28,10 +27,8 @@ export default {
backupLabel: {},
nodeTags: [],
diskTags: [],
bulkRestoreData: [],
backupVolumesForBulkCreate: [],
search: {},
isBulkRestore: false,
restoreBackupModalVisible: false,
backupTargetAvailable: false,
workloadDetailModalVisible: false,
Expand Down Expand Up @@ -140,22 +137,21 @@ export default {
params.backupName = lastBackup.id
params.numberOfReplicas = payload.numberOfReplicas
params.volumeName = lastBackup.volumeName
params.backingImage = payload.backingImage ? payload.backingImage : ''
params.backingImage = payload.backingImage || ''

yield put({ type: 'showRestoreBackupModal', payload: { currentItem: params } })
yield put({ type: 'queryDiskTagsAndgetNodeTags' })
yield put({ type: 'showRestoreBackupModal', payload: { currentItem: [params] } })
yield put({ type: 'queryDiskTagsAndGetNodeTags' })
}
},
*beforeShowRestoreBackupModal({
payload,
}, { put }) {
yield put({ type: 'showRestoreBackupModal', payload })
yield put({ type: 'queryDiskTagsAndgetNodeTags' })
yield put({ type: 'queryDiskTagsAndGetNodeTags' })
},
*queryBackupDetailBulkData({
payload,
}, { call, put }) {
// const data = yield call(execAction, payload.url)
if (payload && payload.selectedRows && payload.selectedRows.length > 0) {
let data = []

Expand All @@ -173,19 +169,19 @@ export default {
}
}
}

if (data && data.length > 0) {
yield put({ type: 'showRestoreBulkBackupModal',
payload: {
currentItem: {
name: '<Volume Name>',
currentItem: data.map(d => ({
backupName: d.name,
backingImage: d.volumeBackingImageName,
fromBackup: d.url,
volumeName: d.volumeName,
numberOfReplicas: payload.numberOfReplicas,
},
bulkRestoreData: data,
})),
},
})

yield put({ type: 'queryDiskTagsAndgetNodeTags' })
yield put({ type: 'queryDiskTagsAndGetNodeTags' })
}
}
},
Expand All @@ -197,7 +193,7 @@ export default {
const search = yield select(store => { return store.backup.search })
yield put({ type: 'query', payload: { ...search } })
},
*queryDiskTagsAndgetNodeTags({
*queryDiskTagsAndGetNodeTags({
payload,
}, { call, put }) {
const nodeTags = yield call(getNodeTags, payload)
Expand All @@ -212,20 +208,13 @@ export default {
*restoreBulkBackup({
payload,
}, { call, put, select }) {
let restoreBulkBackup = []
yield put({ type: 'hideRestoreBackupModal' })
if (payload.bulkRestoreData && payload.selectedBackup) {
payload.bulkRestoreData.forEach((item) => {
let params = {}
Object.assign(params, payload.selectedBackup)
params.name = item.volumeName
params.fromBackup = item.url
restoreBulkBackup.push(params)
})
}
if (restoreBulkBackup.length > 0) {
for (let i = 0; i < restoreBulkBackup.length; i++) {
yield call(restore, restoreBulkBackup[i])
if (payload.length > 0) {
for (let i = 0; i < payload.length; i++) {
const resp = yield call(restore, payload[i])
if (resp && resp.status === 200) {
message.success(`Successfully restore backup volume ${payload[i].name}`, 3)
}
}
}
const search = yield select(store => { return store.backup.search })
Expand Down Expand Up @@ -267,7 +256,14 @@ export default {
payload,
}, { call, put, select }) {
yield put({ type: 'hideBulkCreateVolumeStandModalVisible' })
yield payload.map((item) => call(createVolume, item))
if (payload.length > 0) {
for (let i = 0; i < payload.length; i++) {
const resp = yield call(createVolume, payload[i])
if (resp && resp.status === 200) {
message.success(`Successfully create DR volume ${payload[i].name}`, 3)
}
}
}
const search = yield select(store => { return store.backup.search })
yield put({ type: 'query', payload: { ...search } })
},
Expand All @@ -280,26 +276,26 @@ export default {
// For DR Volume
yield put({ type: 'initModalUrl', found, payload })
yield put({ type: 'showCreateVolumeStandModalVisible' })
yield put({ type: 'queryDiskTagsAndgetNodeTags' })
yield put({ type: 'queryDiskTagsAndGetNodeTags' })
},
*BulkCreateStandVolume({
payload,
}, { call, put }) {
const data = yield payload.backupVolume.map((item) => call(execAction, item.actions.backupList))
const volumes = data.map((item, index) => {
const volume = payload.backupVolume[index]
const found = item.data.find((backup) => backup.id === volume.lastBackupName)
const lastBackup = item.data.find((backup) => backup.id === volume.lastBackupName)
return {
lastBackupUrl: found.url,
volumeName: volume.id,
baseImage: volume.baseImage,
size: found.volumeSize,
lastBackupUrl: lastBackup.url,
size: lastBackup.volumeSize,
backingImage: lastBackup.volumeBackingImageName,
}
})
// For DR Volume
yield put({ type: 'initBulkCreateModalUrl', volumes })
yield put({ type: 'showBulkCreateVolumeStandModalVisible' })
yield put({ type: 'queryDiskTagsAndgetNodeTags' })
yield put({ type: 'queryDiskTagsAndGetNodeTags' })
},
*deleteAllBackups({
payload,
Expand Down Expand Up @@ -426,7 +422,7 @@ export default {
return { ...state, showBackuplabelsModalVisible: false, createVolumeStandModalKey: Math.random() }
},
initModalUrl(state, action) {
return { ...state, lastBackupUrl: action.found.url, volumeName: action.payload.name, baseImage: action.payload.baseImage, size: action.found.volumeSize }
return { ...state, lastBackupUrl: action.found.url, volumeName: action.payload.name, size: action.found.volumeSize }
},
initBulkCreateModalUrl(state, action) {
return { ...state, backupVolumesForBulkCreate: action.volumes }
Expand All @@ -435,10 +431,10 @@ export default {
return { ...state, ...action.payload, restoreBackupModalVisible: true, restoreBackupModalKey: Math.random() }
},
showRestoreBulkBackupModal(state, action) {
return { ...state, ...action.payload, isBulkRestore: true, restoreBackupModalVisible: true, restoreBackupModalKey: Math.random() }
return { ...state, ...action.payload, restoreBackupModalVisible: true, restoreBackupModalKey: Math.random() }
},
hideRestoreBackupModal(state) {
return { ...state, previousChecked: false, tagsLoading: true, restoreBackupModalVisible: false, isBulkRestore: false }
return { ...state, previousChecked: false, tagsLoading: true, restoreBackupModalVisible: false }
},
updateSorter(state, action) {
saveSorter('backupList.sorter', action.payload)
Expand Down
17 changes: 7 additions & 10 deletions src/routes/backup/BackupDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import PropTypes from 'prop-types'
import { connect } from 'dva'
import queryString from 'query-string'
import { Modal } from 'antd'
import RestoreBackup from './RestoreBackup'
import RestoreBackupModal from './RestoreBackupModal'
import { DropOption } from '../../components'
import BackupList from './BackupList'
import { sortBackups } from '../../utils/sort'
import ShowBackupLabels from './ShowBackupLabels'
import CreateStandbyVolume from './CreateStandbyVolume'
import CreateStandbyVolumeModal from './CreateStandbyVolumeModal'
import WorkloadDetailModal from '../volume/WorkloadDetailModal'

const { confirm } = Modal

function Backup({ host, backup, volume, setting, backingImage, loading, location, dispatch }) {
function Backup({ backup, volume, setting, backingImage, loading, location, dispatch }) {
const { backupVolumes, backupData, restoreBackupModalVisible, restoreBackupModalKey, currentItem, sorter, showBackupLabelsModalKey, backupLabel, showBackuplabelsModalVisible, createVolumeStandModalKey, createVolumeStandModalVisible, baseImage, size, lastBackupUrl, workloadDetailModalVisible, workloadDetailModalItem, workloadDetailModalKey, previousChecked, tagsLoading, nodeTags, diskTags } = backup
const hosts = host.data
const volumeList = volume.data
const settings = setting.data
const backingImages = backingImage.data
Expand Down Expand Up @@ -82,7 +81,6 @@ function Backup({ host, backup, volume, setting, backingImage, loading, location

const restoreBackupModalProps = {
item: currentItem,
hosts,
previousChecked,
tagsLoading,
nodeTags,
Expand Down Expand Up @@ -207,9 +205,9 @@ function Backup({ host, backup, volume, setting, backingImage, loading, location
/>
</div>
<BackupList {...backupProps} />
{ restoreBackupModalVisible ? <RestoreBackup key={restoreBackupModalKey} {...restoreBackupModalProps} /> : ''}
{ restoreBackupModalVisible ? <RestoreBackupModal key={restoreBackupModalKey} {...restoreBackupModalProps} /> : ''}
{ showBackuplabelsModalVisible ? <ShowBackupLabels key={showBackupLabelsModalKey} {...showBackupLabelsModalProps} /> : ''}
{ createVolumeStandModalVisible ? <CreateStandbyVolume key={createVolumeStandModalKey} {...createVolumeStandModalProps} /> : ''}
{ createVolumeStandModalVisible ? <CreateStandbyVolumeModal key={createVolumeStandModalKey} {...createVolumeStandModalProps} /> : ''}
{ workloadDetailModalVisible ? <WorkloadDetailModal key={workloadDetailModalKey} {...workloadDetailModalProps} /> : ''}
</div>
)
Expand All @@ -220,14 +218,13 @@ Backup.propTypes = {
location: PropTypes.object,
dispatch: PropTypes.func,
loading: PropTypes.bool,
host: PropTypes.object,
setting: PropTypes.object,
volume: PropTypes.object,
backingImage: PropTypes.object,
}

export default connect(({
host, backup, setting, loading, volume, backingImage,
backup, setting, loading, volume, backingImage,
}) => ({
host, backup, setting, loading: loading.models.backup, volume, backingImage,
backup, setting, loading: loading.models.backup, volume, backingImage,
}))(Backup)
Loading

0 comments on commit 4c86dfb

Please sign in to comment.