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:
Akshay Joshi
2018-10-22 12:35:21 +05:30
parent 370df47042
commit 6bc6bc7f60
49 changed files with 731 additions and 101 deletions

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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')

View File

@@ -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)