fix(xo-server,xo-web/metadata-backups): handle null retentions (#4133)

Introduced by fea5117ed8
This commit is contained in:
badrAZ 2019-04-11 11:00:04 +02:00 committed by Pierre Donias
parent f581e93b88
commit 88160bae1d
3 changed files with 32 additions and 9 deletions

View File

@ -24,6 +24,8 @@ const METADATA_BACKUP_JOB_TYPE = 'metadataBackup'
const compareTimestamp = (a, b) => a.timestamp - b.timestamp
const DEFAULT_RETENTION = 0
type Settings = {|
retentionXoMetadata?: number,
retentionPoolMetadata?: number,
@ -454,8 +456,18 @@ export default class metadataBackup {
throw new Error('no metadata mode found')
}
const { retentionXoMetadata = 0, retentionPoolMetadata = 0 } =
let { retentionXoMetadata, retentionPoolMetadata } =
job.settings[schedule.id] || {}
// it also replaces null retentions introduced by the commit
// https://github.com/vatesfr/xen-orchestra/commit/fea5117ed83b58d3a57715b32d63d46e3004a094#diff-c02703199db2a4c217943cf8e02b91deR40
if (retentionXoMetadata == null) {
retentionXoMetadata = DEFAULT_RETENTION
}
if (retentionPoolMetadata == null) {
retentionPoolMetadata = DEFAULT_RETENTION
}
if (
(retentionPoolMetadata === 0 && retentionXoMetadata === 0) ||
(!job.xoMetadata && retentionPoolMetadata === 0) ||

View File

@ -1,6 +1,5 @@
import _ from 'intl'
import decorate from 'apply-decorators'
import defined from '@xen-orchestra/defined'
import Icon from 'icon'
import React from 'react'
import Scheduler, { SchedulePreview } from 'scheduling'
@ -35,9 +34,9 @@ export default decorate([
name: value.trim() === '' ? null : value,
})
},
setRetention: ({ setSchedule }, value, { name }) => () => {
setRetention({ setSchedule }, value, { name }) {
setSchedule({
[name]: defined(value, null),
[name]: value,
})
},
},
@ -66,7 +65,6 @@ export default decorate([
value={schedule.name}
/>
</FormGroup>
{/* retentions effects are defined on initialize() */}
{retentions.map(({ name, valuePath }) => (
<FormGroup key={valuePath}>
<label>
@ -76,6 +74,7 @@ export default decorate([
data-name={valuePath}
min='0'
onChange={effects.setRetention}
required
value={schedule[valuePath]}
/>
</FormGroup>

View File

@ -38,7 +38,6 @@ import Schedules from '../_schedules'
// A retention can be:
// - number: set by user
// - undefined: will be replaced by the default value in the display(table + modal) and on submitting the form
// - null: when a user voluntarily deletes its value.
const DEFAULT_RETENTION = 1
const RETENTION_POOL_METADATA = {
@ -207,7 +206,20 @@ export default decorate([
schedules: ({ _schedules }, { schedules }) =>
defined(_schedules, schedules),
settings: ({ _settings }, { job }) =>
defined(_settings, () => job.settings),
// it replaces null retentions introduced by the commit
// https://github.com/vatesfr/xen-orchestra/commit/fea5117ed83b58d3a57715b32d63d46e3004a094#diff-c02703199db2a4c217943cf8e02b91deR40
defined(_settings, () =>
mapValues(job.settings, setting => {
const newSetting = { ...setting }
if (newSetting.retentionPoolMetadata === null) {
newSetting.retentionPoolMetadata = 0
}
if (newSetting.retentionXoMetadata === null) {
newSetting.retentionXoMetadata = 0
}
return newSetting
})
),
remotes: ({ _remotes }, { job }) =>
defined(_remotes, () => destructPattern(job.remotes), []),
remotesPredicate: ({ remotes }) => ({ id }) => !remotes.includes(id),
@ -227,13 +239,13 @@ export default decorate([
state.modePoolMetadata &&
every(
state.settings,
({ retentionPoolMetadata }) => retentionPoolMetadata === null
({ retentionPoolMetadata }) => retentionPoolMetadata === 0
),
missingRetentionXoMetadata: state =>
state.modeXoMetadata &&
every(
state.settings,
({ retentionXoMetadata }) => retentionXoMetadata === null
({ retentionXoMetadata }) => retentionXoMetadata === 0
),
missingSchedules: state => isEmpty(state.schedules),
},