diff --git a/internal/auth/base.go b/internal/auth/base.go index 77a809c..0814c17 100644 --- a/internal/auth/base.go +++ b/internal/auth/base.go @@ -261,7 +261,6 @@ func GetNRDMS(params *models.ProviderConfig) (*nrdbc.NRDBController, error) { if err != nil { return nil, err } - NRDBC, err = nrdbc.New(ncpmgdb.New(ncpnrdb, params.DatabaseName)) if err != nil { return nil, err diff --git a/models/basicTask.go b/models/basicTask.go index 4be2655..0c01fb2 100644 --- a/models/basicTask.go +++ b/models/basicTask.go @@ -54,7 +54,7 @@ type Schedule struct { } type GenarateTask struct { - Task + Task `json:"inline"` TargetPoint GenTaskTarget `json:"targetPoint"` } diff --git a/models/genDataParams.go b/models/genDataParams.go index 9a11d1a..1fd9d15 100644 --- a/models/genDataParams.go +++ b/models/genDataParams.go @@ -30,7 +30,7 @@ type GenDataParams struct { type GenFileParams struct { Directory string `json:"Directory,omitempty" swaggerignore:"true"` - DummyPath string `json:"dummyPath,omitempty" swaggerignore:"true"` + DummyPath string `json:"path,omitempty" swaggerignore:"true"` FileFormatParams FileSizeParams } diff --git a/pkg/rdbms/mysql/mysql.go b/pkg/rdbms/mysql/mysql.go index 74a7743..23f39cc 100644 --- a/pkg/rdbms/mysql/mysql.go +++ b/pkg/rdbms/mysql/mysql.go @@ -74,7 +74,7 @@ func (d *MysqlDBMS) Exec(query string) error { if err != nil { log.Error().Err(err).Str("query", query).Msg("Failed to execute SQL query") } - log.Info().Str("query", query).Msg("SQL query executed successfully") + log.Debug().Str("query", query).Msg("SQL query executed successfully") return err } @@ -106,13 +106,16 @@ func (d *MysqlDBMS) DeleteDB(dbName string) error { func (d *MysqlDBMS) ListDB(dst *[]string) error { rows, err := d.db.Query("SHOW DATABASES") if err != nil { + log.Error().Err(err).Msgf("SQL query executed failed %v", rows) return err } + defer rows.Close() for rows.Next() { var dbName string if err := rows.Scan(&dbName); err != nil { + log.Error().Err(err).Msgf("SQL query executed failed %v", rows) return err } @@ -127,6 +130,7 @@ func (d *MysqlDBMS) ListDB(dst *[]string) error { func (d *MysqlDBMS) ListTable(dbName string, dst *[]string) error { _, err := d.db.Exec(fmt.Sprintf("USE %s;", dbName)) if err != nil { + log.Error().Err(err).Msgf("SQL query executed failed") return err } @@ -150,6 +154,7 @@ func (d *MysqlDBMS) ListTable(dbName string, dst *[]string) error { func (d *MysqlDBMS) ShowCreateDBSql(dbName string, dbCreateSql *string) error { err := d.db.QueryRow(fmt.Sprintf("SHOW CREATE DATABASE %s;", dbName)).Scan(&dbName, dbCreateSql) if err != nil { + log.Error().Err(err).Msgf("SQL query executed failed") return err } @@ -173,9 +178,11 @@ func (d *MysqlDBMS) ShowCreateDBSql(dbName string, dbCreateSql *string) error { // Get table create sql func (d *MysqlDBMS) ShowCreateTableSql(dbName, tableName string, tableCreateSql *string) error { if err := d.Exec(fmt.Sprintf("USE %s;", dbName)); err != nil { + log.Error().Err(err).Msgf("SQL query executed failed") return err } if err := d.db.QueryRow(fmt.Sprintf("SHOW CREATE TABLE %s;", tableName)).Scan(&tableName, tableCreateSql); err != nil { + log.Error().Err(err).Msgf("SQL query executed failed") return err } *tableCreateSql = removeSequenceOption(*tableCreateSql) @@ -188,6 +195,7 @@ func (d *MysqlDBMS) ShowCreateTableSql(dbName, tableName string, tableCreateSql func (d *MysqlDBMS) GetInsert(dbName, tableName string, insertSql *[]string) error { colRows, err := d.db.Query("SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?", dbName, tableName) if err != nil { + log.Error().Err(err).Msgf("SQL query executed failed") return err } defer colRows.Close() @@ -196,6 +204,7 @@ func (d *MysqlDBMS) GetInsert(dbName, tableName string, insertSql *[]string) err for colRows.Next() { var columnName string if err := colRows.Scan(&columnName); err != nil { + log.Error().Err(err).Msgf("SQL query executed failed") return err } columns = append(columns, columnName) @@ -210,6 +219,7 @@ func (d *MysqlDBMS) GetInsert(dbName, tableName string, insertSql *[]string) err selectQuery := "SELECT " + strings.Join(escapedColumns, ", ") + " FROM " + tableName selRows, err := d.db.Query(selectQuery) if err != nil { + log.Error().Err(err).Msgf("SQL query executed failed") return err } defer selRows.Close() @@ -225,7 +235,7 @@ func (d *MysqlDBMS) GetInsert(dbName, tableName string, insertSql *[]string) err err := selRows.Scan(valuePtrs...) if err != nil { - + log.Error().Err(err).Msgf("SQL query executed failed") return err } diff --git a/service/rdbc/rdbc.go b/service/rdbc/rdbc.go index 2da9c9b..b72c55d 100644 --- a/service/rdbc/rdbc.go +++ b/service/rdbc/rdbc.go @@ -79,7 +79,7 @@ func New(rdb RDBMS, opts ...Option) (*RDBController, error) { func (rdb *RDBController) ListDB(dst *[]string) error { err := rdb.client.ListDB(dst) if err != nil { - log.Info().Msgf("RDB", *dst) + log.Error().Err(err).Msgf("RDB %v", *dst) return err } return nil diff --git a/web/js/scripts.js b/web/js/scripts.js index b8e41c7..e0759b3 100644 --- a/web/js/scripts.js +++ b/web/js/scripts.js @@ -32,9 +32,56 @@ window.addEventListener('DOMContentLoaded', event => { if (document.getElementById('backForm')) { backUpFormSubmit(); } + if (document.getElementById('restoreForm')) { + RestoreFormSubmit(); + } }); +function convertCheckboxParams(obj) { + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + if (obj[key] === "on") { + obj[key] = true; + } else if (obj[key] === "off") { + obj[key] = false; + } else if (typeof obj[key] === "object" && !Array.isArray(obj[key])) { + convertCheckboxParams(obj[key]); + } + } + } + return obj; +} + +function formDataToObject(formData) { + const data = {}; + formData.forEach((value, key) => { + const match = key.match(/(\w+)\[(\w+)\]/); + if (match) { + const objName = match[1]; + const paramName = match[2]; + if (!data[objName]) { + data[objName] = {}; + } + data[objName][paramName] = value; + } else { + data[key] = value; + } + }); + return data; + } + + function getInputValue(id) { + const element = document.getElementById(id); + if (!element) { + // console.warn(`Element with id '${id}' not found.`); + return null; + } + + const value = element.value.trim(); + return value !== "" ? value : null; + } + function generateFormSubmit() { const form = document.getElementById('genForm'); @@ -45,41 +92,52 @@ function generateFormSubmit() { resultCollpase(); const payload = new FormData(form); - let jsonData = JSON.stringify(Object.fromEntries(payload)); - console.log(jsonData); + let jsonData = Object.fromEntries(payload); + jsonData=convertCheckboxParams(jsonData) + jsonData.targetPoint = { + ...jsonData + }; + console.log(jsonData) + jsonData.targetPoint.provider = document.getElementById('provider').value; + const target = document.getElementById('genTarget').value; - const target= document.getElementById('genTarget').value; + if ( (jsonData.targetPoint.provider =="ncp") && (jsonData.targetPoint.endpoint =="") ) { + jsonData.targetPoint.endpoint ="https://kr.object.ncloudstorage.com" + } const url = "/generate/" + target; - console.log(url); - let req; - if (target == "gcp" || target == "firestore") { - req = { method: 'POST', body: payload }; - } else { - req = { method: 'POST', body: jsonData }; - } + + req = { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(jsonData) + }; fetch(url, req) .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } return response.json(); }) .then(json => { const resultText = document.getElementById('resultText'); resultText.value = json.Result; console.log(json); - console.log("generate done."); + console.log("Generate done."); }) .catch(reason => { - console.log(reason); - alert(reason); + console.error("Error during generate:", reason); + alert(reason.message || reason); }) .finally(() => { loadingButtonOff(); }); - console.log("generate progressing..."); - + console.log("Generate progressing..."); }); } @@ -92,19 +150,39 @@ function migrationFormSubmit() { resultCollpase(); const payload = new FormData(form); + let jsonData= formDataToObject(payload) + console.log(jsonData) const dest = document.getElementById('migDest').value; const source = document.getElementById('migSource').value; + jsonData.targetPoint.provider = getInputValue('targetPoint[provider]'); + jsonData.sourcePoint.provider = getInputValue('sourcePoint[provider]'); + + let url = "/migration/" + source; if (source != dest) { url = url + "/" + dest; } + if ( (jsonData.targetPoint.provider =="ncp") && (jsonData.targetPoint.endpoint =="") ) { + jsonData.targetPoint.endpoint ="https://kr.object.ncloudstorage.com" + } + if ( (jsonData.sourcePoint.provider =="ncp") && (jsonData.sourcePoint.endpoint =="") ) { + jsonData.sourcePoint.endpoint ="https://kr.object.ncloudstorage.com" + } + console.log(url); - fetch(url, { + let req; + + req = { method: 'POST', - body: payload - }) + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(jsonData) + }; + + fetch(url, req) .then(response => { return response.json(); }) @@ -135,16 +213,32 @@ function backUpFormSubmit() { resultCollpase(); const payload = new FormData(form); - const dest = document.getElementById('backDest').value; - const source = document.getElementById('backSource').value; - let url = "/backup/" + source; + var service = document.getElementById('srcService').value; + let url = "/backup/" + service; console.log(url); - fetch(url, { + + let jsonData= formDataToObject(payload) + console.log(jsonData) + + + if ( (jsonData.targetPoint.provider =="ncp") && (jsonData.targetPoint.endpoint =="") ) { + jsonData.targetPoint.endpoint ="https://kr.object.ncloudstorage.com" + } + if ( (jsonData.sourcePoint.provider =="ncp") && (jsonData.sourcePoint.endpoint =="") ) { + jsonData.sourcePoint.endpoint ="https://kr.object.ncloudstorage.com" + } + + let req= { method: 'POST', - body: payload - }) + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(jsonData) + }; + + fetch(url, req ) .then(response => { return response.json(); }) @@ -166,6 +260,63 @@ function backUpFormSubmit() { }); } +function RestoreFormSubmit() { + const form = document.getElementById('restoreForm'); + + form.addEventListener('submit', (e) => { + e.preventDefault(); + loadingButtonOn(); + resultCollpase(); + + const payload = new FormData(form); + + var service = document.getElementById('srcService').value; + let url = "/restore/" + service; + console.log(url); + + + let jsonData= formDataToObject(payload) + console.log(jsonData) + + + if ( (jsonData.targetPoint.provider =="ncp") && (jsonData.targetPoint.endpoint =="") ) { + jsonData.targetPoint.endpoint ="https://kr.object.ncloudstorage.com" + } + if ( (jsonData.sourcePoint.provider =="ncp") && (jsonData.sourcePoint.endpoint =="") ) { + jsonData.sourcePoint.endpoint ="https://kr.object.ncloudstorage.com" + } + + let req= { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(jsonData) + }; + + fetch(url, req ) + .then(response => { + return response.json(); + }) + .then(json => { + const resultText = document.getElementById('resultText'); + resultText.value = json.Result; + console.log(json); + console.log("restore done."); + }) + .catch(reason => { + console.log(reason); + alert(reason); + }) + .finally(() => { + loadingButtonOff(); + }); + + console.log("restore progressing..."); + }); +} + + function loadingButtonOn() { let btn = document.getElementById('submitBtn'); btn.disabled = true; diff --git a/web/templates/back-backup.html b/web/templates/back-backup.html index 000a8e4..a07a7a4 100644 --- a/web/templates/back-backup.html +++ b/web/templates/back-backup.html @@ -10,48 +10,291 @@