Skip to content

Commit

Permalink
Update pitr functions (#726)
Browse files Browse the repository at this point in the history
Signed-off-by: SayedTahsin <[email protected]>
  • Loading branch information
SayedTahsin authored Feb 13, 2025
1 parent 5e33e18 commit 5375aed
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 25 deletions.
48 changes: 43 additions & 5 deletions charts/kubedbcom-mariadb-editor-options/ui/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,44 @@ function getDefault({ getValue, model }, type) {
return val
}

function convertToISO(input) {
const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/
if (iso8601Regex.test(input)) {
return input
}

const date = new Date(input)

if (isNaN(date.getTime())) {
throw new Error('Invalid date format')
}

return date.toISOString()
}

function getComponentLogStats(snapshot) {
if (!snapshot || !snapshot.status || !snapshot.status.components) {
return null
}

const components = snapshot.status.components
const appKind = snapshot.spec?.appRef?.kind

if (appKind === 'MongoDB') {
for (const [key, value] of Object.entries(components)) {
if (key.endsWith('0') && value.logStats) {
return value.logStats
}
}
}

if (components['wal'] && components['wal'].logStats) {
return components['wal'].logStats
}

return null
}

let recoveryTimestampMiliSec = '000Z'
async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) {
const owner = storeGet('/route/params/user')
Expand Down Expand Up @@ -1126,26 +1164,26 @@ async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator,
force: true,
})

const resp = snapshotsResp.data.status?.components['wal-rs0']?.walSegments[0]
const recoveryTimestampArray = resp?.end.split('.')
const resp = getComponentLogStats(snapshotsResp.data)
const recoveryTimestampArray = convertToISO(resp?.end).split('.')

if (recoveryTimestampArray.length === 2) {
recoveryTimestampMiliSec = recoveryTimestampArray[1]
}

commit('wizard/model$update', {
path: `/spec/init/archiver/recoveryTimestamp`,
value: resp?.end.slice(0, -1),
value: convertToISO(resp?.end).slice(0, -1),
force: true,
})
commit('wizard/model$update', {
path: `/minDate`,
value: resp?.start.slice(0, -1),
value: convertToISO(resp?.start).slice(0, -1),
force: true,
})
commit('wizard/model$update', {
path: `/maxDate`,
value: resp?.end.slice(0, -1),
value: convertToISO(resp?.end).slice(0, -1),
force: true,
})
} catch (e) {
Expand Down
48 changes: 43 additions & 5 deletions charts/kubedbcom-mongodb-editor-options/ui/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,44 @@ function getDefault({ getValue, model }, type) {
return val
}

function convertToISO(input) {
const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/
if (iso8601Regex.test(input)) {
return input
}

const date = new Date(input)

if (isNaN(date.getTime())) {
throw new Error('Invalid date format')
}

return date.toISOString()
}

function getComponentLogStats(snapshot) {
if (!snapshot || !snapshot.status || !snapshot.status.components) {
return null
}

const components = snapshot.status.components
const appKind = snapshot.spec?.appRef?.kind

if (appKind === 'MongoDB') {
for (const [key, value] of Object.entries(components)) {
if (key.endsWith('0') && value.logStats) {
return value.logStats
}
}
}

if (components['wal'] && components['wal'].logStats) {
return components['wal'].logStats
}

return null
}

let recoveryTimestampMiliSec = '000Z'
async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) {
const owner = storeGet('/route/params/user')
Expand Down Expand Up @@ -1292,26 +1330,26 @@ async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator,
force: true,
})

const resp = snapshotsResp.data.status?.components['wal-rs0']?.walSegments[0]
const recoveryTimestampArray = resp?.end.split('.')
const resp = getComponentLogStats(snapshotsResp.data)
const recoveryTimestampArray = convertToISO(resp?.end).split('.')

if (recoveryTimestampArray.length === 2) {
recoveryTimestampMiliSec = recoveryTimestampArray[1]
}

commit('wizard/model$update', {
path: `/spec/init/archiver/recoveryTimestamp`,
value: resp?.end.slice(0, -1),
value: convertToISO(resp?.end).slice(0, -1),
force: true,
})
commit('wizard/model$update', {
path: `/minDate`,
value: resp?.start.slice(0, -1),
value: convertToISO(resp?.start).slice(0, -1),
force: true,
})
commit('wizard/model$update', {
path: `/maxDate`,
value: resp?.end.slice(0, -1),
value: convertToISO(resp?.end).slice(0, -1),
force: true,
})
} catch (e) {
Expand Down
48 changes: 43 additions & 5 deletions charts/kubedbcom-mssqlserver-editor-options/ui/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,44 @@ function onCustomPidChange({ getValue, discriminator, commit }) {
})
}

function convertToISO(input) {
const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/
if (iso8601Regex.test(input)) {
return input
}

const date = new Date(input)

if (isNaN(date.getTime())) {
throw new Error('Invalid date format')
}

return date.toISOString()
}

function getComponentLogStats(snapshot) {
if (!snapshot || !snapshot.status || !snapshot.status.components) {
return null
}

const components = snapshot.status.components
const appKind = snapshot.spec?.appRef?.kind

if (appKind === 'MongoDB') {
for (const [key, value] of Object.entries(components)) {
if (key.endsWith('0') && value.logStats) {
return value.logStats
}
}
}

if (components['wal'] && components['wal'].logStats) {
return components['wal'].logStats
}

return null
}

let recoveryTimestampMiliSec = '000Z'
async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) {
const owner = storeGet('/route/params/user')
Expand Down Expand Up @@ -1159,26 +1197,26 @@ async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator,
force: true,
})

const resp = snapshotsResp.data.status?.components['wal-rs0']?.walSegments[0]
const recoveryTimestampArray = resp?.end.split('.')
const resp = getComponentLogStats(snapshotsResp.data)
const recoveryTimestampArray = convertToISO(resp?.end).split('.')

if (recoveryTimestampArray.length === 2) {
recoveryTimestampMiliSec = recoveryTimestampArray[1]
}

commit('wizard/model$update', {
path: `/spec/init/archiver/recoveryTimestamp`,
value: resp?.end.slice(0, -1),
value: convertToISO(resp?.end).slice(0, -1),
force: true,
})
commit('wizard/model$update', {
path: `/minDate`,
value: resp?.start.slice(0, -1),
value: convertToISO(resp?.start).slice(0, -1),
force: true,
})
commit('wizard/model$update', {
path: `/maxDate`,
value: resp?.end.slice(0, -1),
value: convertToISO(resp?.end).slice(0, -1),
force: true,
})
} catch (e) {
Expand Down
48 changes: 43 additions & 5 deletions charts/kubedbcom-mysql-editor-options/ui/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,44 @@ function getDefault({ getValue, model }, type) {
return val
}

function convertToISO(input) {
const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/
if (iso8601Regex.test(input)) {
return input
}

const date = new Date(input)

if (isNaN(date.getTime())) {
throw new Error('Invalid date format')
}

return date.toISOString()
}

function getComponentLogStats(snapshot) {
if (!snapshot || !snapshot.status || !snapshot.status.components) {
return null
}

const components = snapshot.status.components
const appKind = snapshot.spec?.appRef?.kind

if (appKind === 'MongoDB') {
for (const [key, value] of Object.entries(components)) {
if (key.endsWith('0') && value.logStats) {
return value.logStats
}
}
}

if (components['wal'] && components['wal'].logStats) {
return components['wal'].logStats
}

return null
}

let recoveryTimestampMiliSec = '000Z'
async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) {
const owner = storeGet('/route/params/user')
Expand Down Expand Up @@ -1125,26 +1163,26 @@ async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator,
force: true,
})

const resp = snapshotsResp.data.status?.components['wal-rs0']?.walSegments[0]
const recoveryTimestampArray = resp?.end.split('.')
const resp = getComponentLogStats(snapshotsResp.data)
const recoveryTimestampArray = convertToISO(resp?.end).split('.')

if (recoveryTimestampArray.length === 2) {
recoveryTimestampMiliSec = recoveryTimestampArray[1]
}

commit('wizard/model$update', {
path: `/spec/init/archiver/recoveryTimestamp`,
value: resp?.end.slice(0, -1),
value: convertToISO(resp?.end).slice(0, -1),
force: true,
})
commit('wizard/model$update', {
path: `/minDate`,
value: resp?.start.slice(0, -1),
value: convertToISO(resp?.start).slice(0, -1),
force: true,
})
commit('wizard/model$update', {
path: `/maxDate`,
value: resp?.end.slice(0, -1),
value: convertToISO(resp?.end).slice(0, -1),
force: true,
})
} catch (e) {
Expand Down
48 changes: 43 additions & 5 deletions charts/kubedbcom-postgres-editor-options/ui/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,44 @@ function getDefault({ getValue, model }, type) {
return val
}

function convertToISO(input) {
const iso8601Regex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/
if (iso8601Regex.test(input)) {
return input
}

const date = new Date(input)

if (isNaN(date.getTime())) {
throw new Error('Invalid date format')
}

return date.toISOString()
}

function getComponentLogStats(snapshot) {
if (!snapshot || !snapshot.status || !snapshot.status.components) {
return null
}

const components = snapshot.status.components
const appKind = snapshot.spec?.appRef?.kind

if (appKind === 'MongoDB') {
for (const [key, value] of Object.entries(components)) {
if (key.endsWith('0') && value.logStats) {
return value.logStats
}
}
}

if (components['wal'] && components['wal'].logStats) {
return components['wal'].logStats
}

return null
}

let recoveryTimestampMiliSec = '000Z'
async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) {
const owner = storeGet('/route/params/user')
Expand Down Expand Up @@ -1320,26 +1358,26 @@ async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator,
force: true,
})

const resp = snapshotsResp.data.status?.components['wal-rs0']?.walSegments[0]
const recoveryTimestampArray = resp?.end.split('.')
const resp = getComponentLogStats(snapshotsResp.data)
const recoveryTimestampArray = convertToISO(resp?.end).split('.')

if (recoveryTimestampArray.length === 2) {
recoveryTimestampMiliSec = recoveryTimestampArray[1]
}

commit('wizard/model$update', {
path: `/spec/init/archiver/recoveryTimestamp`,
value: resp?.end.slice(0, -1),
value: convertToISO(resp?.end).slice(0, -1),
force: true,
})
commit('wizard/model$update', {
path: `/minDate`,
value: resp?.start.slice(0, -1),
value: convertToISO(resp?.start).slice(0, -1),
force: true,
})
commit('wizard/model$update', {
path: `/maxDate`,
value: resp?.end.slice(0, -1),
value: convertToISO(resp?.end).slice(0, -1),
force: true,
})
} catch (e) {
Expand Down

0 comments on commit 5375aed

Please sign in to comment.