Skip to content

Commit

Permalink
allow input secret/secretNamespace when restore bbi
Browse files Browse the repository at this point in the history
Signed-off-by: andy.lee <andy.lee@suse.com>
  • Loading branch information
a110605 authored and derekbit committed Jul 10, 2024
1 parent 4ebb877 commit b5d8515
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 27 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"linebreak-style": [0 ,"error", "windows"],
"react/no-access-state-in-setstate": 0,
"react/jsx-first-prop-new-line": 0,
"react/jsx-props-no-spreading": 0,
"import/prefer-default-export": 0,
"react/jsx-filename-extension": 0,
"react/jsx-props-no-spreading": 0,
Expand Down
30 changes: 22 additions & 8 deletions src/models/backingImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
deleteBackingImage,
deleteBackupBackingImage,
execAction,
queryBbiList,
queryBackupBackingImageList,
query,
deleteDisksOnBackingImage,
uploadChunk,
Expand All @@ -27,6 +27,7 @@ export default {
data: [],
bbiData: [], // backupBackingImage data
selected: {},
bbiSelected: {},
selectedRows: [],
nodeTags: [],
diskTags: [],
Expand All @@ -37,6 +38,7 @@ export default {
createBackingImageModalKey: Math.random(),
diskStateMapDetailModalVisible: false,
diskStateMapDetailModalKey: Math.random(),
restoreBackupBackingImageModalVisible: false,
diskStateMapDeleteDisabled: true,
diskStateMapDeleteLoading: false,
selectedDiskStateMapRows: [],
Expand Down Expand Up @@ -73,7 +75,7 @@ export default {
// eslint-disable-next-line no-unused-vars
_payload,
}, { call, put }) {
const resp = yield call(queryBbiList)
const resp = yield call(queryBackupBackingImageList)
if (resp && resp.data) {
const bbiData = resp.data
sortByCreatedTime(bbiData)
Expand Down Expand Up @@ -148,11 +150,17 @@ export default {
*restoreBackingImage({
payload,
}, { call, put }) {
const resp = yield call(execAction, payload.actions.backupBackingImageRestore)
if (resp && resp.status === 200) {
message.success(`Successfully restore ${payload.name} backing image`)
yield put({ type: 'hideRestoreBackingImageModal' })
const restoreUrl = payload.item?.actions?.backupBackingImageRestore
if (restoreUrl) {
const resp = yield call(execAction, restoreUrl, payload.params)
if (resp && resp.status === 200) {
message.success(`Successfully restore ${payload.item.name} backing image`)
}
yield put({ type: 'query' })
} else {
message.error('Missing restore backup backing image url')
}
yield put({ type: 'query' })
},
*deleteBackupBackingImage({
payload,
Expand Down Expand Up @@ -186,7 +194,7 @@ export default {
if (payload && payload.length > 0) {
yield payload.map(item => call(deleteBackupBackingImage, item))
}
yield delay(2000)
yield delay(3000)
yield put({ type: 'queryBackupBackingImage' })
},
*bulkBackup({
Expand All @@ -200,7 +208,7 @@ export default {
}
}
}
yield delay(4000)
yield delay(3000)
yield put({ type: 'queryBackupBackingImage' })
},
*bulkDownload({
Expand Down Expand Up @@ -321,6 +329,9 @@ export default {
}
}
},
showRestoreBackingImage(state, action) {
return { ...state, ...action.payload, restoreBackupBackingImageModalVisible: true }
},
showCreateBackingImageModal(state, action) {
return { ...state, ...action.payload, createBackingImageModalVisible: true, createBackingImageModalKey: Math.random() }
},
Expand All @@ -331,6 +342,9 @@ export default {
selected: action.payload,
}
},
hideRestoreBackingImageModal(state, action) {
return { ...state, ...action.payload, restoreBackupBackingImageModalVisible: false, bbiSelected: {} }
},
hideCreateBackingImageModal(state) {
return { ...state, createBackingImageModalVisible: false }
},
Expand Down
2 changes: 1 addition & 1 deletion src/routes/backingImage/BackingImageBulkActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function bulkActions({ selectedRows, deleteBackingImages, downloadSelectedBackin
const allActions = [
{ key: 'delete', name: 'Delete', disabled() { return selectedRows.length === 0 } },
{ key: 'download', name: 'Download', disabled() { return (selectedRows.length === 0 || selectedRows.every(row => !hasReadyBackingDisk(row))) } },
{ key: 'backup', name: 'Backup', disabled() { return selectedRows.length === 0 } },
{ key: 'backup', name: 'Backup', disabled() { return selectedRows.length === 0 || selectedRows.every(row => !hasReadyBackingDisk(row)) } },
]

return (
Expand Down
76 changes: 76 additions & 0 deletions src/routes/backingImage/RestoreBackupBackingImageModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Form, Input } from 'antd'
import { ModalBlur } from '../../components'

const FormItem = Form.Item

const formItemLayout = {
labelCol: {
span: 10,
},
wrapperCol: {
span: 12,
},
}

const modal = ({
item,
visible,
onOk,
onCancel,
form: {
getFieldDecorator,
validateFields,
getFieldValue,
},
}) => {
function handleOk() {
validateFields((errors) => {
if (errors) {
return
}
const data = {
secret: getFieldValue('secret') || '',
secretNamespace: getFieldValue('secretNamespace') || '',
}
onOk(item, data)
})
}

const modalOpts = {
title: `Restore ${item.name} Backup Backing Image`,
visible,
onCancel,
onOk: handleOk,
}
if (!item) {
return null
}
return (
<ModalBlur {...modalOpts}>
<Form layout="horizontal">
<FormItem label="Secret" hasFeedback {...formItemLayout}>
{getFieldDecorator('secret', {
initialValue: '',
})(<Input />)}
</FormItem>
<FormItem label="Secret Namespace" hasFeedback {...formItemLayout}>
{getFieldDecorator('secretNamespace', {
initialValue: '',
})(<Input />)}
</FormItem>
</Form>
</ModalBlur>
)
}

modal.propTypes = {
form: PropTypes.object.isRequired,
visible: PropTypes.bool,
onCancel: PropTypes.func,
item: PropTypes.object,
onOk: PropTypes.func,
}

export default Form.create()(modal)
33 changes: 30 additions & 3 deletions src/routes/backingImage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Filter } from '../../components/index'
import BackingImageBulkActions from './BackingImageBulkActions'
import UpdateMinCopiesCount from './UpdateMinCopiesCount'
import BackupBackingImageBulkActions from './BackupBackingImageBulkActions'
import RestoreBackupBackingImageModal from './RestoreBackupBackingImageModal'
import style from './BackingImage.less'

const filterBackingImage = (data, field, value) => {
Expand All @@ -21,9 +22,11 @@ const filterBackingImage = (data, field, value) => {
case 'name':
case 'uuid':
case 'minNumberOfCopies':
backingImages = backingImages.filter((image) => (value ? image[field].toString().includes(value.toString().trim()) : true))
break
case 'diskSelector':
case 'nodeSelector':
backingImages = backingImages.filter((image) => (value ? image[field].toString().includes(value.toString().trim()) : true))
backingImages = backingImages.filter((image) => (value ? image[field]?.toString().includes(value.trim()) || false : true))
break
case 'sourceType':
backingImages = backingImages.filter((image) => (value ? image.sourceType === value.trim() : true))
Expand Down Expand Up @@ -132,10 +135,12 @@ class BackingImage extends React.Component {
bbiSearchField,
bbiSearchValue,
selected,
bbiSelected,
nodeTags,
diskTags,
tagsLoading,
minCopiesCountModalVisible,
restoreBackupBackingImageModalVisible,
createBackingImageModalVisible,
createBackingImageModalKey,
diskStateMapDetailModalVisible,
Expand Down Expand Up @@ -169,8 +174,10 @@ class BackingImage extends React.Component {
},
restoreBackingImage(record) {
dispatch({
type: 'backingImage/restoreBackingImage',
payload: record,
type: 'backingImage/showRestoreBackingImage',
payload: {
bbiSelected: record,
},
})
},
rowSelection: {
Expand Down Expand Up @@ -286,6 +293,25 @@ class BackingImage extends React.Component {
},
}

const restoreBBiModalProps = {
item: bbiSelected,
visible: restoreBackupBackingImageModalVisible,
onOk(item, params) {
dispatch({
type: 'backingImage/restoreBackingImage',
payload: {
item,
params,
},
})
},
onCancel() {
dispatch({
type: 'backingImage/hideRestoreBackingImageModal',
})
},
}

const diskStateMapDetailModalProps = {
selected,
backingImages,
Expand Down Expand Up @@ -475,6 +501,7 @@ class BackingImage extends React.Component {
<span>Uploading</span>
</div>
)}
{ restoreBackupBackingImageModalVisible && <RestoreBackupBackingImageModal {...restoreBBiModalProps} />}
{ minCopiesCountModalVisible && <UpdateMinCopiesCount {...minCopiesCountProps} />}
{ createBackingImageModalVisible ? <CreateBackingImage key={createBackingImageModalKey} {...createBackingImageModalProps} /> : ''}
{ diskStateMapDetailModalVisible ? <DiskStateMapDetail key={diskStateMapDetailModalKey} {...diskStateMapDetailModalProps} /> : ''}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/systemBackups/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class SystemBackups extends React.Component {
<SystemBackupsList {...systemBackupsListProps} />
</div>
<div className={style.systemRestores}>
<Icon type="file-done" className="ant-breadcrumb anticon" style={{ display: 'flex', alignItems: 'center' }} />
<Icon type="file-done" />
<span style={{ marginLeft: '4px' }}>System Restore</span>
</div>
<div id="systemRestoresTable" style={{ height: '43%', padding: '8px 12px 0px' }}>
Expand Down
2 changes: 1 addition & 1 deletion src/services/backingImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function execAction(url, params) {
})
}

export async function queryBbiList() {
export async function queryBackupBackingImageList() {
return request({
url: '/v1/backupbackingimages',
method: 'get',
Expand Down
6 changes: 1 addition & 5 deletions src/utils/dataDependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ const dependency = {
}, {
ns: 'setting',
key: 'settings',
}, {
ns: 'backup',
key: 'backup',
}],
},
settings: {
Expand Down Expand Up @@ -170,7 +167,7 @@ const httpDataDependency = {
'/volume': ['volume', 'host', 'setting', 'backingImage', 'engineimage', 'recurringJob', 'backup'],
'/engineimage': ['engineimage'],
'/recurringJob': ['recurringJob'],
'/backingImage': ['volume', 'backingImage', 'setting', 'backup'],
'/backingImage': ['volume', 'backingImage', 'setting'],
'/setting': ['setting'],
'/backup': ['host', 'setting', 'backingImage', 'backup'],
'/instanceManager': ['volume', 'instanceManager'],
Expand All @@ -186,7 +183,6 @@ export function getDataDependency(pathName) {
}
return false
})
// console.log('🚀 ~ keys ~ keys:', keys)

if (keys && keys.length === 1) {
let modal = dependency[keys[0]]
Expand Down
7 changes: 0 additions & 7 deletions src/utils/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export function constructWebsocketURL(type, period) {
}

export function wsChanges(dispatch, type, period, ns, search) {
console.log('🚀 ~ wsChanges ~ type:', type)
const url = constructWebsocketURL(type, period)
const options = {
timeout: 4000,
Expand Down Expand Up @@ -77,9 +76,6 @@ export function wsChanges(dispatch, type, period, ns, search) {
}, 30000)
// TODO: can refactor this to use a single event listener and dispatch to the correct action
rws.addEventListener('message', (msg) => {
if (ns === 'backingImage') {
console.log('message rws.addEventListener ~ type =', backupType, ' msg:', JSON.parse(msg.data))
}
recentWrite = true
if (ns === 'backup') {
if (backupType === 'backupvolumes') {
Expand All @@ -95,16 +91,13 @@ export function wsChanges(dispatch, type, period, ns, search) {
})
}
} else if (ns === 'backingImage') {
console.log('message data ns:', ns, 'backupType:', backupType)
if (backupType === 'backingimages') {
console.log('message backupType === backingimages call ns/updateBackground', JSON.parse(msg.data).data)
dispatch({
type: `${ns}/updateBackground`,
payload: JSON.parse(msg.data),
})
}
if (backupType === 'backupbackingimages') {
console.log('message backupType === backupbackingimages call ns/updateBackgroundBBi', JSON.parse(msg.data).data)
dispatch({
type: `${ns}/updateBackgroundBBi`,
payload: JSON.parse(msg.data),
Expand Down

0 comments on commit b5d8515

Please sign in to comment.