Search in sources :

Example 1 with GetBackupVolInfoTask

use of com.cubrid.cubridmanager.core.cubrid.database.task.GetBackupVolInfoTask in project cubrid-manager by CUBRID.

the class RestoreDatabaseDialog method showBackupVolumeInfo.

/**
	 * 
	 * Show backup volume information
	 * 
	 * @param level the level
	 * @param path the path
	 */
private void showBackupVolumeInfo(String level, String path) {
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            Display display = Display.getDefault();
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.loadBackupVolInfo, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(getShell(), msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (task instanceof GetBackupVolInfoTask) {
                    GetBackupVolInfoTask getBackupVolInfoTask = (GetBackupVolInfoTask) task;
                    final String backupVolInfo = getBackupVolInfoTask.getDbBackupVolInfo();
                    if (backupVolInfo != null && backupVolInfo.length() > 0) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                BackupDbVolumeInfoDialog backupDbResultInfoDialog = new BackupDbVolumeInfoDialog(getShell());
                                backupDbResultInfoDialog.setResultInfoStr(backupVolInfo);
                                backupDbResultInfoDialog.open();
                            }
                        });
                    }
                }
            }
            return true;
        }
    };
    String databaseName = databaseNameText.getText();
    GetBackupVolInfoTask getBackupVolInfoTask = new GetBackupVolInfoTask(database.getServer().getServerInfo());
    getBackupVolInfoTask.setDbName(databaseName);
    getBackupVolInfoTask.setLevel(level);
    getBackupVolInfoTask.setPath(path);
    taskExcutor.addTask(getBackupVolInfoTask);
    new ExecTaskWithProgress(taskExcutor).exec(true, true);
}
Also used : TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) GetBackupVolInfoTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetBackupVolInfoTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) Display(org.eclipse.swt.widgets.Display)

Example 2 with GetBackupVolInfoTask

use of com.cubrid.cubridmanager.core.cubrid.database.task.GetBackupVolInfoTask in project cubrid-manager by CUBRID.

the class BackupDatabaseDialog method backupDb.

/**
	 *
	 * Execute task and backup database
	 *
	 * @param buttonId the button id
	 */
private void backupDb(final int buttonId) {
    isCanFinished = true;
    TaskJobExecutor taskExcutor = new TaskJobExecutor() {

        private String backupVolInfo;

        public IStatus exec(final IProgressMonitor monitor) {
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    getShell().setVisible(false);
                }
            });
            if (monitor.isCanceled()) {
                cancel();
                display.syncExec(new Runnable() {

                    public void run() {
                        setReturnCode(buttonId);
                        close();
                    }
                });
                return Status.CANCEL_STATUS;
            }
            for (ITask task : taskList) {
                if (!(task instanceof GetBackupVolInfoTask) || database.getRunningType() != DbRunningType.CS) {
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                getShell().setVisible(true);
                            }
                        });
                        return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                    }
                }
                if (isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (task instanceof CheckDirTask) {
                    CheckDirTask checkDirTask = (CheckDirTask) task;
                    final String[] dirs = checkDirTask.getNoExistDirectory();
                    if (dirs != null && dirs.length > 0) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                CreateDirDialog dialog = new CreateDirDialog(getShell());
                                dialog.setDirs(dirs);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                    getShell().setVisible(true);
                                }
                            }
                        });
                    }
                } else if (task instanceof CheckFileTask) {
                    CheckFileTask checkFileTask = (CheckFileTask) task;
                    final String[] files = checkFileTask.getExistFiles();
                    if (files != null && files.length > 0) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                OverrideFileDialog dialog = new OverrideFileDialog(getShell());
                                dialog.setFiles(files);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                    getShell().setVisible(true);
                                }
                            }
                        });
                    }
                } else if (task instanceof GetBackupVolInfoTask && database.getRunningType() == DbRunningType.STANDALONE) {
                    GetBackupVolInfoTask getBackupVolInfoTask = (GetBackupVolInfoTask) task;
                    backupVolInfo = getBackupVolInfoTask.getDbBackupVolInfo();
                }
                if (!isCanFinished) {
                    return Status.CANCEL_STATUS;
                }
                if (monitor.isCanceled()) {
                    cancel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            close();
                        }
                    });
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }

        public void done(IJobChangeEvent event) {
            if (event.getResult() == Status.OK_STATUS) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        if (database.getRunningType() == DbRunningType.CS) {
                            Display.getDefault().syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgBackupSuccess);
                                }
                            });
                        } else {
                            if (backupVolInfo != null && backupVolInfo.length() > 0) {
                                Display.getDefault().syncExec(new Runnable() {

                                    public void run() {
                                        BackupDbVolumeInfoDialog backupDbResultInfoDialog = new BackupDbVolumeInfoDialog(getShell());
                                        backupDbResultInfoDialog.setResultInfoStr(backupVolInfo);
                                        backupDbResultInfoDialog.open();
                                    }
                                });
                            }
                        }
                        close();
                    }
                });
            }
        }
    };
    String backupDir = backupDirText.getText();
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    checkDirTask.setDirectory(new String[] { backupDir });
    CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
    String fileName = backupDirText.getText() + database.getServer().getServerInfo().getPathSeparator() + volumeNameText.getText();
    checkFileTask.setFile(new String[] { fileName });
    String databaseName = databaseNameText.getText();
    String level = backupLevelCombo.getText().replaceAll("Level", "");
    String volName = volumeNameText.getText();
    boolean isRemoveLog = archiveLogButton.getSelection();
    boolean isCheckDbCons = consistentButton.getSelection();
    boolean isZip = useCompressButton.getSelection();
    boolean isSafeReplication = safeBackupButton.getSelection();
    int threadNum = spnThreadNum.getSelection();
    BackupDbTask backupDbTask = new BackupDbTask(database.getServer().getServerInfo());
    backupDbTask.setDbName(databaseName);
    backupDbTask.setLevel(level);
    backupDbTask.setVolumeName(volName);
    backupDbTask.setBackupDir(backupDir);
    backupDbTask.setRemoveLog(isRemoveLog);
    backupDbTask.setCheckDatabaseConsist(isCheckDbCons);
    backupDbTask.setThreadCount(String.valueOf(threadNum));
    backupDbTask.setZiped(isZip);
    backupDbTask.setSafeReplication(isSafeReplication);
    GetBackupVolInfoTask getBackupVolInfoTask = new GetBackupVolInfoTask(database.getServer().getServerInfo());
    getBackupVolInfoTask.setDbName(databaseName);
    taskExcutor.addTask(checkDirTask);
    taskExcutor.addTask(checkFileTask);
    taskExcutor.addTask(backupDbTask);
    taskExcutor.addTask(getBackupVolInfoTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgBackupDBRearJobName + " - " + dbName + "@" + serverName;
    taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITask(com.cubrid.common.core.task.ITask) GetBackupVolInfoTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetBackupVolInfoTask) BackupDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.BackupDbTask) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) Display(org.eclipse.swt.widgets.Display)

Aggregations

ITask (com.cubrid.common.core.task.ITask)2 GetBackupVolInfoTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetBackupVolInfoTask)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Display (org.eclipse.swt.widgets.Display)2 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)1 BackupDbTask (com.cubrid.cubridmanager.core.cubrid.database.task.BackupDbTask)1 CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)1 CheckFileTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1