mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Ensure that Utilities(Backup/Restore/Maintenence/Import-Export) should not be started
if binary path is wrong and also added 'Stop Process' button to cancel the process.
This commit is contained in:
@@ -19,7 +19,7 @@ from flask_babelex import gettext as _
|
||||
from flask_security import login_required, current_user
|
||||
from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc
|
||||
from pgadmin.utils import PgAdminModule, get_storage_directory, html, \
|
||||
fs_short_path, document_dir
|
||||
fs_short_path, document_dir, is_utility_exists
|
||||
from pgadmin.utils.ajax import make_json_response, bad_request
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
@@ -63,7 +63,8 @@ class BackupModule(PgAdminModule):
|
||||
Returns:
|
||||
list: URL endpoints for backup module
|
||||
"""
|
||||
return ['backup.create_server_job', 'backup.create_object_job']
|
||||
return ['backup.create_server_job', 'backup.create_object_job',
|
||||
'backup.utility_exists']
|
||||
|
||||
|
||||
# Create blueprint for BackupModule class
|
||||
@@ -320,6 +321,13 @@ def create_backup_objects_job(sid):
|
||||
utility = manager.utility('backup') if backup_obj_type == 'objects' \
|
||||
else manager.utility('backup_server')
|
||||
|
||||
ret_val = is_utility_exists(utility)
|
||||
if ret_val:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=ret_val
|
||||
)
|
||||
|
||||
args = [
|
||||
'--file',
|
||||
backup_file,
|
||||
@@ -461,3 +469,44 @@ def create_backup_objects_job(sid):
|
||||
return make_json_response(
|
||||
data={'job_id': jid, 'Success': 1}
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route(
|
||||
'/utility_exists/<int:sid>/<backup_obj_type>', endpoint='utility_exists'
|
||||
)
|
||||
@login_required
|
||||
def check_utility_exists(sid, backup_obj_type):
|
||||
"""
|
||||
This function checks the utility file exist on the given path.
|
||||
|
||||
Args:
|
||||
sid: Server ID
|
||||
backup_obj_type: Type of the object
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
server = Server.query.filter_by(
|
||||
id=sid, user_id=current_user.id
|
||||
).first()
|
||||
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_("Could not find the specified server.")
|
||||
)
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||
manager = driver.connection_manager(server.id)
|
||||
|
||||
utility = manager.utility('backup') if backup_obj_type == 'objects' \
|
||||
else manager.utility('backup_server')
|
||||
|
||||
ret_val = is_utility_exists(utility)
|
||||
if ret_val:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=ret_val
|
||||
)
|
||||
|
||||
return make_json_response(success=1)
|
||||
|
@@ -10,6 +10,8 @@
|
||||
import gettext from '../../../../static/js/gettext';
|
||||
import Backform from '../../../../static/js/backform.pgadmin';
|
||||
import {Dialog} from '../../../../static/js/alertify/dialog';
|
||||
import url_for from 'sources/url_for';
|
||||
import axios from 'axios/index';
|
||||
|
||||
export class BackupDialog extends Dialog {
|
||||
constructor(pgBrowser, $, alertify, BackupModel, backform = Backform) {
|
||||
@@ -19,6 +21,13 @@ export class BackupDialog extends Dialog {
|
||||
);
|
||||
}
|
||||
|
||||
url_for_utility_exists(id, params){
|
||||
return url_for('backup.utility_exists', {
|
||||
'sid': id,
|
||||
'backup_obj_type': params == null ? 'objects' : 'servers',
|
||||
});
|
||||
}
|
||||
|
||||
draw(action, aciTreeItem, params) {
|
||||
const serverInformation = this.retrieveAncestorOfTypeServer(aciTreeItem);
|
||||
|
||||
@@ -30,17 +39,40 @@ export class BackupDialog extends Dialog {
|
||||
return;
|
||||
}
|
||||
|
||||
const typeOfDialog = BackupDialog.typeOfDialog(params);
|
||||
const baseUrl = this.url_for_utility_exists(serverInformation._id, params);
|
||||
// Check pg_dump or pg_dumpall utility exists or not.
|
||||
let that = this;
|
||||
let service = axios.create({});
|
||||
service.get(
|
||||
baseUrl
|
||||
).then(function(res) {
|
||||
if (!res.data.success) {
|
||||
that.alertify.alert(
|
||||
gettext('Utility not found'),
|
||||
res.data.errormsg
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.canExecuteOnCurrentDatabase(aciTreeItem)) {
|
||||
const typeOfDialog = BackupDialog.typeOfDialog(params);
|
||||
|
||||
if (!that.canExecuteOnCurrentDatabase(aciTreeItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dialog = that.createOrGetDialog(
|
||||
BackupDialog.dialogTitle(typeOfDialog),
|
||||
typeOfDialog
|
||||
);
|
||||
|
||||
dialog(true).resizeTo('60%', '50%');
|
||||
}).catch(function() {
|
||||
that.alertify.alert(
|
||||
gettext('Utility not found'),
|
||||
gettext('Failed to fetch Utility information')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const dialog = this.createOrGetDialog(
|
||||
BackupDialog.dialogTitle(typeOfDialog),
|
||||
typeOfDialog
|
||||
);
|
||||
dialog(true).resizeTo('60%', '50%');
|
||||
});
|
||||
}
|
||||
|
||||
static typeOfDialog(params) {
|
||||
|
@@ -147,9 +147,16 @@ export class BackupDialogWrapper extends DialogWrapper {
|
||||
service.post(
|
||||
baseUrl,
|
||||
this.view.model.toJSON()
|
||||
).then(function () {
|
||||
dialog.alertify.success(gettext('Backup job created.'), 5);
|
||||
dialog.pgBrowser.Events.trigger('pgadmin-bgprocess:created', dialog);
|
||||
).then(function (res) {
|
||||
if (res.data.success) {
|
||||
dialog.alertify.success(gettext('Backup job created.'), 5);
|
||||
dialog.pgBrowser.Events.trigger('pgadmin-bgprocess:created', dialog);
|
||||
} else {
|
||||
dialog.alertify.alert(
|
||||
gettext('Backup job creation failed.'),
|
||||
res.data.errormsg
|
||||
);
|
||||
}
|
||||
}).catch(function (error) {
|
||||
try {
|
||||
const err = error.response.data;
|
||||
|
@@ -10,10 +10,11 @@
|
||||
|
||||
import sys
|
||||
import simplejson as json
|
||||
import os
|
||||
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
from regression import parent_node_dict
|
||||
from pgadmin.utils import server_utils as server_utils
|
||||
from pgadmin.utils import server_utils as server_utils, is_utility_exists
|
||||
from pgadmin.browser.server_groups.servers.databases.tests import utils as \
|
||||
database_utils
|
||||
|
||||
@@ -639,13 +640,22 @@ class BackupCreateJobTest(BaseTestGenerator):
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
if self.server['default_binary_paths'] is None:
|
||||
if 'default_binary_paths' not in self.server or \
|
||||
self.server['type'] not in self.server['default_binary_paths'] or \
|
||||
self.server['default_binary_paths'][self.server['type']] == '':
|
||||
self.skipTest(
|
||||
"default_binary_paths is not set for the server {0}".format(
|
||||
self.server['name']
|
||||
)
|
||||
)
|
||||
|
||||
binary_path = os.path.join(
|
||||
self.server['default_binary_paths'][self.server['type']],
|
||||
'pg_dump')
|
||||
retVal = is_utility_exists(binary_path)
|
||||
if retVal is not None:
|
||||
self.skipTest(retVal)
|
||||
|
||||
@patch('pgadmin.tools.backup.Server')
|
||||
@patch('pgadmin.tools.backup.BackupMessage')
|
||||
@patch('pgadmin.tools.backup.filename_with_file_manager_path')
|
||||
|
@@ -11,6 +11,7 @@ import os
|
||||
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
from regression import parent_node_dict
|
||||
from pgadmin.utils import is_utility_exists
|
||||
import pgadmin.tools.backup.tests.test_backup_utils as backup_utils
|
||||
|
||||
|
||||
@@ -38,13 +39,22 @@ class BackupJobTest(BaseTestGenerator):
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
if self.server['default_binary_paths'] is None:
|
||||
if 'default_binary_paths' not in self.server or \
|
||||
self.server['type'] not in self.server['default_binary_paths'] or\
|
||||
self.server['default_binary_paths'][self.server['type']] == '':
|
||||
self.skipTest(
|
||||
"default_binary_paths is not set for the server {0}".format(
|
||||
self.server['name']
|
||||
)
|
||||
)
|
||||
|
||||
binary_path = os.path.join(
|
||||
self.server['default_binary_paths'][self.server['type']],
|
||||
'pg_dump')
|
||||
retVal = is_utility_exists(binary_path)
|
||||
if retVal is not None:
|
||||
self.skipTest(retVal)
|
||||
|
||||
def runTest(self):
|
||||
self.server_id = parent_node_dict["server"][-1]["server_id"]
|
||||
url = self.url.format(self.server_id)
|
||||
|
@@ -17,7 +17,7 @@ from flask_babelex import gettext as _
|
||||
from flask_security import login_required, current_user
|
||||
from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc
|
||||
from pgadmin.utils import PgAdminModule, get_storage_directory, html, \
|
||||
fs_short_path, document_dir, IS_WIN
|
||||
fs_short_path, document_dir, IS_WIN, is_utility_exists
|
||||
from pgadmin.utils.ajax import make_json_response, bad_request
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
@@ -58,7 +58,7 @@ class ImportExportModule(PgAdminModule):
|
||||
Returns:
|
||||
list: URL endpoints for backup module
|
||||
"""
|
||||
return ['import_export.create_job']
|
||||
return ['import_export.create_job', 'import_export.utility_exists']
|
||||
|
||||
|
||||
blueprint = ImportExportModule(MODULE_NAME, __name__)
|
||||
@@ -231,6 +231,12 @@ def create_import_export_job(sid):
|
||||
|
||||
# Get the utility path from the connection manager
|
||||
utility = manager.utility('sql')
|
||||
ret_val = is_utility_exists(utility)
|
||||
if ret_val:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=ret_val
|
||||
)
|
||||
|
||||
# Get the storage path from preference
|
||||
storage_dir = get_storage_directory()
|
||||
@@ -323,3 +329,41 @@ def create_import_export_job(sid):
|
||||
return make_json_response(
|
||||
data={'job_id': jid, 'success': 1}
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route(
|
||||
'/utility_exists/<int:sid>', endpoint='utility_exists'
|
||||
)
|
||||
@login_required
|
||||
def check_utility_exists(sid):
|
||||
"""
|
||||
This function checks the utility file exist on the given path.
|
||||
|
||||
Args:
|
||||
sid: Server ID
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
server = Server.query.filter_by(
|
||||
id=sid, user_id=current_user.id
|
||||
).first()
|
||||
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_("Could not find the specified server.")
|
||||
)
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||
manager = driver.connection_manager(server.id)
|
||||
|
||||
utility = manager.utility('sql')
|
||||
ret_val = is_utility_exists(utility)
|
||||
if ret_val:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=ret_val
|
||||
)
|
||||
|
||||
return make_json_response(success=1)
|
||||
|
@@ -534,6 +534,11 @@ Backform, commonUtils, supportedNodes
|
||||
if (res.success) {
|
||||
Alertify.success(gettext('Import/export job created.'), 5);
|
||||
pgBrowser.Events.trigger('pgadmin-bgprocess:created', self);
|
||||
} else {
|
||||
Alertify.alert(
|
||||
gettext('Import/export job creation failed.'),
|
||||
res.errormsg
|
||||
);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr) {
|
||||
@@ -652,12 +657,38 @@ Backform, commonUtils, supportedNodes
|
||||
});
|
||||
}
|
||||
|
||||
// Open the Alertify dialog for the import/export module
|
||||
Alertify.ImportDialog(
|
||||
S(
|
||||
gettext('Import/Export data - table \'%s\'')
|
||||
).sprintf(treeInfo.table.label).value(), node, i, d
|
||||
).set('resizable', true).resizeTo('70%', '80%');
|
||||
const baseUrl = url_for('import_export.utility_exists', {
|
||||
'sid': server_data._id,
|
||||
});
|
||||
|
||||
// Check psql utility exists or not.
|
||||
$.ajax({
|
||||
url: baseUrl,
|
||||
type:'GET',
|
||||
})
|
||||
.done(function(res) {
|
||||
if (!res.success) {
|
||||
Alertify.alert(
|
||||
gettext('Utility not found'),
|
||||
res.errormsg
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Open the Alertify dialog for the import/export module
|
||||
Alertify.ImportDialog(
|
||||
S(
|
||||
gettext('Import/Export data - table \'%s\'')
|
||||
).sprintf(treeInfo.table.label).value(), node, i, d
|
||||
).set('resizable', true).resizeTo('70%', '80%');
|
||||
})
|
||||
.fail(function() {
|
||||
Alertify.alert(
|
||||
gettext('Utility not found'),
|
||||
gettext('Failed to fetch Utility information')
|
||||
);
|
||||
return;
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -13,9 +13,9 @@ import simplejson as json
|
||||
|
||||
from flask import url_for, Response, render_template, request, current_app
|
||||
from flask_babelex import gettext as _
|
||||
from flask_security import login_required
|
||||
from flask_security import login_required, current_user
|
||||
from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc
|
||||
from pgadmin.utils import PgAdminModule, html
|
||||
from pgadmin.utils import PgAdminModule, html, is_utility_exists
|
||||
from pgadmin.utils.ajax import bad_request, make_json_response
|
||||
from pgadmin.utils.driver import get_driver
|
||||
|
||||
@@ -68,7 +68,7 @@ class MaintenanceModule(PgAdminModule):
|
||||
Returns:
|
||||
list: URL endpoints for backup module
|
||||
"""
|
||||
return ['maintenance.create_job']
|
||||
return ['maintenance.create_job', 'maintenance.utility_exists']
|
||||
|
||||
|
||||
blueprint = MaintenanceModule(MODULE_NAME, __name__)
|
||||
@@ -214,6 +214,12 @@ def create_maintenance_job(sid, did):
|
||||
)
|
||||
|
||||
utility = manager.utility('sql')
|
||||
ret_val = is_utility_exists(utility)
|
||||
if ret_val:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=ret_val
|
||||
)
|
||||
|
||||
# Create the command for the vacuum operation
|
||||
query = render_template(
|
||||
@@ -262,3 +268,41 @@ def create_maintenance_job(sid, did):
|
||||
data={'job_id': jid, 'status': True,
|
||||
'info': 'Maintenance job created.'}
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route(
|
||||
'/utility_exists/<int:sid>', endpoint='utility_exists'
|
||||
)
|
||||
@login_required
|
||||
def check_utility_exists(sid):
|
||||
"""
|
||||
This function checks the utility file exist on the given path.
|
||||
|
||||
Args:
|
||||
sid: Server ID
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
server = Server.query.filter_by(
|
||||
id=sid, user_id=current_user.id
|
||||
).first()
|
||||
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_("Could not find the specified server.")
|
||||
)
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||
manager = driver.connection_manager(server.id)
|
||||
|
||||
utility = manager.utility('sql')
|
||||
ret_val = is_utility_exists(utility)
|
||||
if ret_val:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=ret_val
|
||||
)
|
||||
|
||||
return make_json_response(success=1)
|
||||
|
@@ -392,7 +392,10 @@ define([
|
||||
Alertify.success(res.data.info);
|
||||
pgBrowser.Events.trigger('pgadmin-bgprocess:created', self);
|
||||
} else {
|
||||
Alertify.error(res.data.errmsg);
|
||||
Alertify.alert(
|
||||
gettext('Maintenance job creation failed.'),
|
||||
res.errormsg
|
||||
);
|
||||
}
|
||||
})
|
||||
.fail(function() {
|
||||
@@ -467,8 +470,33 @@ define([
|
||||
});
|
||||
}
|
||||
|
||||
// Open the Alertify dialog
|
||||
Alertify.MaintenanceDialog('Maintenance...').set('resizable', true).resizeTo('60%', '80%');
|
||||
const baseUrl = url_for('maintenance.utility_exists', {
|
||||
'sid': server_data._id,
|
||||
});
|
||||
|
||||
// Check psql utility exists or not.
|
||||
$.ajax({
|
||||
url: baseUrl,
|
||||
type:'GET',
|
||||
})
|
||||
.done(function(res) {
|
||||
if (!res.success) {
|
||||
Alertify.alert(
|
||||
gettext('Utility not found'),
|
||||
res.errormsg
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Open the Alertify dialog
|
||||
Alertify.MaintenanceDialog('Maintenance...').set('resizable', true).resizeTo('60%', '80%');
|
||||
})
|
||||
.fail(function() {
|
||||
Alertify.alert(
|
||||
gettext('Utility not found'),
|
||||
gettext('Failed to fetch Utility information')
|
||||
);
|
||||
return;
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
@@ -10,9 +10,11 @@
|
||||
import time
|
||||
import random
|
||||
import simplejson as json
|
||||
import os
|
||||
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
from regression import parent_node_dict
|
||||
from pgadmin.utils import is_utility_exists
|
||||
|
||||
|
||||
class MaintenanceJobTest(BaseTestGenerator):
|
||||
@@ -38,13 +40,21 @@ class MaintenanceJobTest(BaseTestGenerator):
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
if self.server['default_binary_paths'] is None:
|
||||
if 'default_binary_paths' not in self.server or \
|
||||
self.server['type'] not in self.server['default_binary_paths'] or\
|
||||
self.server['default_binary_paths'][self.server['type']] == '':
|
||||
self.skipTest(
|
||||
"default_binary_paths is not set for the server {0}".format(
|
||||
self.server['name']
|
||||
)
|
||||
)
|
||||
|
||||
binary_path = os.path.join(
|
||||
self.server['default_binary_paths'][self.server['type']], 'psql')
|
||||
retVal = is_utility_exists(binary_path)
|
||||
if retVal is not None:
|
||||
self.skipTest(retVal)
|
||||
|
||||
def runTest(self):
|
||||
self.server_id = parent_node_dict["database"][-1]["server_id"]
|
||||
self.db_id = parent_node_dict["database"][-1]["db_id"]
|
||||
|
@@ -8,11 +8,12 @@
|
||||
##########################################################################
|
||||
|
||||
import sys
|
||||
import os
|
||||
import simplejson as json
|
||||
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
from regression import parent_node_dict
|
||||
from pgadmin.utils import server_utils as server_utils
|
||||
from pgadmin.utils import server_utils as server_utils, is_utility_exists
|
||||
from pgadmin.browser.server_groups.servers.databases.tests import utils as \
|
||||
database_utils
|
||||
|
||||
@@ -128,13 +129,21 @@ class MaintenanceCreateJobTest(BaseTestGenerator):
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
if self.server['default_binary_paths'] is None:
|
||||
if 'default_binary_paths' not in self.server or \
|
||||
self.server['type'] not in self.server['default_binary_paths'] or\
|
||||
self.server['default_binary_paths'][self.server['type']] == '':
|
||||
self.skipTest(
|
||||
"default_binary_paths is not set for the server {0}".format(
|
||||
self.server['name']
|
||||
)
|
||||
)
|
||||
|
||||
binary_path = os.path.join(
|
||||
self.server['default_binary_paths'][self.server['type']], 'psql')
|
||||
retVal = is_utility_exists(binary_path)
|
||||
if retVal is not None:
|
||||
self.skipTest(retVal)
|
||||
|
||||
@patch('pgadmin.tools.maintenance.Server')
|
||||
@patch('pgadmin.tools.maintenance.Message')
|
||||
@patch('pgadmin.tools.maintenance.BatchProcess')
|
||||
|
@@ -18,7 +18,7 @@ from flask_babelex import gettext as _
|
||||
from flask_security import login_required, current_user
|
||||
from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc
|
||||
from pgadmin.utils import PgAdminModule, get_storage_directory, html, \
|
||||
fs_short_path, document_dir
|
||||
fs_short_path, document_dir, is_utility_exists
|
||||
from pgadmin.utils.ajax import make_json_response, bad_request
|
||||
|
||||
from config import PG_DEFAULT_DRIVER
|
||||
@@ -56,7 +56,7 @@ class RestoreModule(PgAdminModule):
|
||||
Returns:
|
||||
list: URL endpoints for backup module
|
||||
"""
|
||||
return ['restore.create_job']
|
||||
return ['restore.create_job', 'restore.utility_exists']
|
||||
|
||||
|
||||
# Create blueprint for RestoreModule class
|
||||
@@ -231,6 +231,12 @@ def create_restore_job(sid):
|
||||
)
|
||||
|
||||
utility = manager.utility('restore')
|
||||
ret_val = is_utility_exists(utility)
|
||||
if ret_val:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=ret_val
|
||||
)
|
||||
|
||||
args = []
|
||||
|
||||
@@ -365,7 +371,39 @@ def create_restore_job(sid):
|
||||
)
|
||||
|
||||
|
||||
"""
|
||||
TODO://
|
||||
Add browser tree
|
||||
"""
|
||||
@blueprint.route(
|
||||
'/utility_exists/<int:sid>', endpoint='utility_exists'
|
||||
)
|
||||
@login_required
|
||||
def check_utility_exists(sid):
|
||||
"""
|
||||
This function checks the utility file exist on the given path.
|
||||
|
||||
Args:
|
||||
sid: Server ID
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
server = Server.query.filter_by(
|
||||
id=sid, user_id=current_user.id
|
||||
).first()
|
||||
|
||||
if server is None:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=_("Could not find the specified server.")
|
||||
)
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||
manager = driver.connection_manager(server.id)
|
||||
|
||||
utility = manager.utility('restore')
|
||||
ret_val = is_utility_exists(utility)
|
||||
if ret_val:
|
||||
return make_json_response(
|
||||
success=0,
|
||||
errormsg=ret_val
|
||||
)
|
||||
|
||||
return make_json_response(success=1)
|
||||
|
@@ -11,6 +11,8 @@ import gettext from '../../../../static/js/gettext';
|
||||
import {sprintf} from 'sprintf-js';
|
||||
import Backform from '../../../../static/js/backform.pgadmin';
|
||||
import {Dialog} from '../../../../static/js/alertify/dialog';
|
||||
import url_for from 'sources/url_for';
|
||||
import axios from 'axios/index';
|
||||
|
||||
export class RestoreDialog extends Dialog {
|
||||
constructor(pgBrowser, $, alertify, RestoreModel, backform = Backform) {
|
||||
@@ -19,6 +21,12 @@ export class RestoreDialog extends Dialog {
|
||||
pgBrowser, $, alertify, RestoreModel, backform);
|
||||
}
|
||||
|
||||
url_for_utility_exists(id){
|
||||
return url_for('restore.utility_exists', {
|
||||
'sid': id,
|
||||
});
|
||||
}
|
||||
|
||||
draw(action, aciTreeItem) {
|
||||
|
||||
const serverInformation = this.retrieveAncestorOfTypeServer(aciTreeItem);
|
||||
@@ -31,23 +39,43 @@ export class RestoreDialog extends Dialog {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.canExecuteOnCurrentDatabase(aciTreeItem)) {
|
||||
const baseUrl = this.url_for_utility_exists(serverInformation._id);
|
||||
// Check pg_restore utility exists or not.
|
||||
let that = this;
|
||||
let service = axios.create({});
|
||||
service.get(
|
||||
baseUrl
|
||||
).then(function(res) {
|
||||
if (!res.data.success) {
|
||||
that.alertify.alert(
|
||||
gettext('Utility not found'),
|
||||
res.data.errormsg
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!that.canExecuteOnCurrentDatabase(aciTreeItem)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let aciTreeItem1 = aciTreeItem || that.pgBrowser.treeMenu.selected();
|
||||
let item = that.pgBrowser.treeMenu.findNodeByDomElement(aciTreeItem1);
|
||||
const data = item.getData();
|
||||
const node = that.pgBrowser.Nodes[data._type];
|
||||
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
let title = sprintf(gettext('Restore (%s: %s)'), node.label, data.label);
|
||||
that.createOrGetDialog(title, 'restore');
|
||||
that.alertify.pg_restore(title, aciTreeItem1, data, node).resizeTo('65%', '60%');
|
||||
}).catch(function() {
|
||||
that.alertify.alert(
|
||||
gettext('Utility not found'),
|
||||
gettext('Failed to fetch Utility information')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let aciTreeItem1 = aciTreeItem || this.pgBrowser.treeMenu.selected();
|
||||
let item = this.pgBrowser.treeMenu.findNodeByDomElement(aciTreeItem1);
|
||||
const data = item.getData();
|
||||
const node = this.pgBrowser.Nodes[data._type];
|
||||
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
let title = sprintf(gettext('Restore (%s: %s)'), node.label, data.label);
|
||||
|
||||
this.createOrGetDialog(title, 'restore');
|
||||
|
||||
this.alertify.pg_restore(title, aciTreeItem1, data, node).resizeTo('65%', '60%');
|
||||
});
|
||||
}
|
||||
|
||||
dialogName() {
|
||||
|
@@ -136,9 +136,16 @@ export class RestoreDialogWrapper extends DialogWrapper {
|
||||
service.post(
|
||||
baseUrl,
|
||||
this.view.model.toJSON()
|
||||
).then(function () {
|
||||
dialogWrapper.alertify.success(gettext('Restore job created.'), 5);
|
||||
dialogWrapper.pgBrowser.Events.trigger('pgadmin-bgprocess:created', dialogWrapper);
|
||||
).then(function (res) {
|
||||
if (res.data.success) {
|
||||
dialogWrapper.alertify.success(gettext('Restore job created.'), 5);
|
||||
dialogWrapper.pgBrowser.Events.trigger('pgadmin-bgprocess:created', dialogWrapper);
|
||||
} else {
|
||||
dialogWrapper.alertify.alert(
|
||||
gettext('Restore job creation failed.'),
|
||||
res.data.errormsg
|
||||
);
|
||||
}
|
||||
}).catch(function (error) {
|
||||
try {
|
||||
const err = error.response.data;
|
||||
|
@@ -17,7 +17,7 @@ import simplejson as json
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
from regression import parent_node_dict
|
||||
from regression.python_test_utils import test_utils as utils
|
||||
from pgadmin.utils import server_utils as server_utils
|
||||
from pgadmin.utils import server_utils as server_utils, is_utility_exists
|
||||
import pgadmin.tools.backup.tests.test_backup_utils as backup_utils
|
||||
|
||||
|
||||
@@ -62,13 +62,22 @@ class RestoreJobTest(BaseTestGenerator):
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
if self.server['default_binary_paths'] is None:
|
||||
if 'default_binary_paths' not in self.server or \
|
||||
self.server['type'] not in self.server['default_binary_paths'] or\
|
||||
self.server['default_binary_paths'][self.server['type']] == '':
|
||||
self.skipTest(
|
||||
"default_binary_paths is not set for the server {0}".format(
|
||||
self.server['name']
|
||||
)
|
||||
)
|
||||
|
||||
binary_path = os.path.join(
|
||||
self.server['default_binary_paths'][self.server['type']],
|
||||
'pg_restore')
|
||||
retVal = is_utility_exists(binary_path)
|
||||
if retVal is not None:
|
||||
self.skipTest(retVal)
|
||||
|
||||
def create_backup(self):
|
||||
url = self.backup_options['url'].format(self.server_id)
|
||||
job_id = backup_utils.create_backup_job(self.tester, url,
|
||||
|
@@ -9,10 +9,11 @@
|
||||
|
||||
import sys
|
||||
import simplejson as json
|
||||
import os
|
||||
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
from regression import parent_node_dict
|
||||
from pgadmin.utils import server_utils as server_utils
|
||||
from pgadmin.utils import server_utils as server_utils, is_utility_exists
|
||||
from pgadmin.browser.server_groups.servers.databases.tests import utils as \
|
||||
database_utils
|
||||
|
||||
@@ -291,13 +292,22 @@ class RestoreCreateJobTest(BaseTestGenerator):
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
if self.server['default_binary_paths'] is None:
|
||||
if 'default_binary_paths' not in self.server or \
|
||||
self.server['type'] not in self.server['default_binary_paths'] or\
|
||||
self.server['default_binary_paths'][self.server['type']] == '':
|
||||
self.skipTest(
|
||||
"default_binary_paths is not set for the server {0}".format(
|
||||
self.server['name']
|
||||
)
|
||||
)
|
||||
|
||||
binary_path = os.path.join(
|
||||
self.server['default_binary_paths'][self.server['type']],
|
||||
'pg_restore')
|
||||
retVal = is_utility_exists(binary_path)
|
||||
if retVal is not None:
|
||||
self.skipTest(retVal)
|
||||
|
||||
@patch('pgadmin.tools.restore.Server')
|
||||
@patch('pgadmin.tools.restore.current_user')
|
||||
@patch('pgadmin.tools.restore.RestoreMessage')
|
||||
|
Reference in New Issue
Block a user