Skip to content

Commit

Permalink
update set-pitr
Browse files Browse the repository at this point in the history
Signed-off-by: SayedTahsin <[email protected]>
  • Loading branch information
SayedTahsin authored and ArnobKumarSaha committed Feb 12, 2025
1 parent 0656e86 commit 9efa976
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 25 deletions.
38 changes: 33 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,34 @@ 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(status) {
if (!status || !status.components) return null

const componentKeys = Object.keys(status.components)

let firstComponent = status.components[componentKeys[0]]

if (componentKeys.includes('wal-rs0')) firstComponent = status.components['wal-rs0']
else if (componentKeys.includes('wal-shard0')) firstComponent = status.components['wal-shard0']

return firstComponent.logStats || null
}

let recoveryTimestampMiliSec = '000Z'
async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) {
const owner = storeGet('/route/params/user')
Expand Down Expand Up @@ -1126,26 +1154,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?.status)
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
38 changes: 33 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,34 @@ 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(status) {
if (!status || !status.components) return null

const componentKeys = Object.keys(status.components)

let firstComponent = status.components[componentKeys[0]]

if (componentKeys.includes('wal-rs0')) firstComponent = status.components['wal-rs0']
else if (componentKeys.includes('wal-shard0')) firstComponent = status.components['wal-shard0']

return firstComponent.logStats || null
}

let recoveryTimestampMiliSec = '000Z'
async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) {
const owner = storeGet('/route/params/user')
Expand Down Expand Up @@ -1292,26 +1320,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?.status)
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
38 changes: 33 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,34 @@ 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(status) {
if (!status || !status.components) return null

const componentKeys = Object.keys(status.components)

let firstComponent = status.components[componentKeys[0]]

if (componentKeys.includes('wal-rs0')) firstComponent = status.components['wal-rs0']
else if (componentKeys.includes('wal-shard0')) firstComponent = status.components['wal-shard0']

return firstComponent.logStats || null
}

let recoveryTimestampMiliSec = '000Z'
async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) {
const owner = storeGet('/route/params/user')
Expand Down Expand Up @@ -1159,26 +1187,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?.status)
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
38 changes: 33 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,34 @@ 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(status) {
if (!status || !status.components) return null

const componentKeys = Object.keys(status.components)

let firstComponent = status.components[componentKeys[0]]

if (componentKeys.includes('wal-rs0')) firstComponent = status.components['wal-rs0']
else if (componentKeys.includes('wal-shard0')) firstComponent = status.components['wal-shard0']

return firstComponent.logStats || null
}

let recoveryTimestampMiliSec = '000Z'
async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) {
const owner = storeGet('/route/params/user')
Expand Down Expand Up @@ -1125,26 +1153,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?.status)
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
38 changes: 33 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,34 @@ 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(status) {
if (!status || !status.components) return null

const componentKeys = Object.keys(status.components)

let firstComponent = status.components[componentKeys[0]]

if (componentKeys.includes('wal-rs0')) firstComponent = status.components['wal-rs0']
else if (componentKeys.includes('wal-shard0')) firstComponent = status.components['wal-shard0']

return firstComponent.logStats || null
}

let recoveryTimestampMiliSec = '000Z'
async function setPointInTimeRecovery({ commit, axios, storeGet, discriminator, getValue }) {
const owner = storeGet('/route/params/user')
Expand Down Expand Up @@ -1320,26 +1348,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?.status)
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 9efa976

Please sign in to comment.