Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sync backup volume option to allow users to manually synchronize backup volume #725

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/models/backup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { query, queryBackupList, execAction, restore, deleteBackup, createVolume, deleteAllBackups, getNodeTags, getDiskTags, queryTarget } from '../services/backup'
import { query, queryBackupList, execAction, restore, deleteBackup, syncBackupVolume, syncAllBackupVolumes, createVolume, deleteAllBackups, getNodeTags, getDiskTags, queryTarget } from '../services/backup'
import { message } from 'antd'
import { wsChanges } from '../utils/websocket'
import queryString from 'query-string'
Expand Down Expand Up @@ -246,6 +246,23 @@ export default {
const search = yield select(store => { return store.backup.search })
yield put({ type: 'query', payload: { ...search } })
},
*syncBackupVolume({
payload,
}, { call }) {
const backVolName = payload.name
const resp = yield call(syncBackupVolume, backVolName)
if (resp && resp.status === 200) {
message.success(`Successfully trigger backup volume ${backVolName} synchronization`, 5)
}
},
*syncAllBackupVolumes({
// eslint-disable-next-line no-unused-vars
_payload }, { call }) {
const resp = yield call(syncAllBackupVolumes)
if (resp && resp.status === 200) {
message.success('Successfully trigger all backup volumes synchronization', 5)
}
},
*bulkCreateVolume({
payload,
}, { call, put, select }) {
Expand Down
7 changes: 6 additions & 1 deletion src/routes/backup/BackupBulkActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import { Button } from 'antd'
import style from './BackupBulkActions.less'

function bulkActions({ selectedRows, restoreLatestBackup, showBulkCreateDisasterRecoveryVolume }) {
function bulkActions({ selectedRows, backupVolumes, restoreLatestBackup, showBulkCreateDisasterRecoveryVolume, syncAllBackupVolumes }) {
const handleClick = (action) => {
switch (action) {
case 'restoreLatestBackup':
Expand All @@ -12,13 +12,17 @@ function bulkActions({ selectedRows, restoreLatestBackup, showBulkCreateDisaster
case 'bulkCreateDisasterRecoveryVolume':
showBulkCreateDisasterRecoveryVolume(selectedRows)
break
case 'syncAllBackupVolumes':
syncAllBackupVolumes()
break
default:
}
}

const allActions = [
{ key: 'restoreLatestBackup', name: 'Restore Latest Backup', disabled() { return selectedRows.length === 0 || selectedRows.some(record => !record.lastBackupName || (record.messages && record.messages.error)) } },
{ key: 'bulkCreateDisasterRecoveryVolume', name: 'Create Disaster Recovery Volume', disabled() { return selectedRows.length === 0 || selectedRows.some(record => !record.lastBackupName || (record.messages && record.messages.error)) } },
{ key: 'syncAllBackupVolumes', name: 'Sync All Backup Volumes', disabled() { return backupVolumes.length === 0 } },
]

return (
Expand All @@ -37,6 +41,7 @@ function bulkActions({ selectedRows, restoreLatestBackup, showBulkCreateDisaster

bulkActions.propTypes = {
selectedRows: PropTypes.array,
backupVolumes: PropTypes.array,
restoreLatestBackup: PropTypes.func,
showBulkCreateDisasterRecoveryVolume: PropTypes.func,
}
Expand Down
4 changes: 4 additions & 0 deletions src/routes/backup/BackupVolumeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class List extends React.Component {
this.props.DeleteAllBackups(record)
} else if (e.key === 'restoreLatestBackup') {
this.props.restoreLatestBackup(record)
} else if (e.key === 'syncBackupVolume') {
this.props.syncBackupVolume(record)
} else if (e.key === 'backingImageInfo') {
this.props.showBackingImageInfo(record)
}
Expand Down Expand Up @@ -248,6 +250,7 @@ class List extends React.Component {
<DropOption menuOptions={[
{ key: 'recovery', name: 'Create Disaster Recovery Volume', disabled: !record.lastBackupName || (record.messages && record.messages.error) },
{ key: 'restoreLatestBackup', name: 'Restore Latest Backup', disabled: !record.lastBackupName || (record.messages && record.messages.error) },
{ key: 'syncBackupVolume', name: 'Sync Backup Volume' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Not sure about the wording.

{ key: 'deleteAll', name: 'Delete All Backups' },
{ key: 'backingImageInfo', name: 'Backing Image Info', disabled: !hasBackingImage, tooltip: hasBackingImage ? '' : 'No backing image is used' },
]}
Expand Down Expand Up @@ -313,6 +316,7 @@ List.propTypes = {
DeleteAllBackups: PropTypes.func,
dispatch: PropTypes.func,
restoreLatestBackup: PropTypes.func,
syncBackupVolume: PropTypes.func,
showBackingImageInfo: PropTypes.func,
showWorkloadsStatusDetail: PropTypes.func,
}
Expand Down
12 changes: 12 additions & 0 deletions src/routes/backup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ function Backup({ host, backup, loading, setting, backingImage, dispatch, locati
showBackingImageInfo(record) {
showBackingImageInfo(record)
},
syncBackupVolume(record) {
dispatch({
type: 'backup/syncBackupVolume',
payload: record,
})
},
restoreLatestBackup(record) {
dispatch({
type: 'backup/restoreLatestBackup',
Expand Down Expand Up @@ -202,6 +208,7 @@ function Backup({ host, backup, loading, setting, backingImage, dispatch, locati

const backupBulkActionsProps = {
selectedRows,
backupVolumes,
restoreLatestBackup() {
dispatch({
type: 'backup/queryBackupDetailBulkData',
Expand All @@ -219,6 +226,11 @@ function Backup({ host, backup, loading, setting, backingImage, dispatch, locati
},
})
},
syncAllBackupVolumes() {
dispatch({
type: 'backup/syncAllBackupVolumes',
})
},
}

const createVolumeStandModalProps = {
Expand Down
20 changes: 20 additions & 0 deletions src/services/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ export async function createVolume(params) {
})
}

export async function syncBackupVolume(volumeName) {
return request({
url: `/v1/backupvolumes/${volumeName}?action=backupVolumeSync`,
method: 'post',
data: {
syncBackupVolume: true,
},
})
}

export async function syncAllBackupVolumes() {
return request({
url: '/v1/backupvolumes',
method: 'put',
data: {
syncAllBackupVolumes: true,
},
})
}

export async function execAction(url, params) {
return request({
url,
Expand Down