Search in sources :

Example 1 with CheckDirTask

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

the class AddVolumeDialog method postTaskFinished.

/**
	 * After a task has been executed, do some thing such as refresh.
	 * 
	 * @param task the task
	 * @return IStatus if complete refresh false if run into error
	 * 
	 */
public IStatus postTaskFinished(ITask task) {
    if (task instanceof CheckDirTask) {
        CheckDirTask checkDirTask = (CheckDirTask) task;
        final String[] dirs = checkDirTask.getNoExistDirectory();
        if (dirs != null && dirs.length > 0) {
            isCreateDir = true;
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    CreateDirDialog dialog = new CreateDirDialog(getShell());
                    dialog.setDirs(dirs);
                    if (dialog.open() != IDialogConstants.OK_ID) {
                        isCreateDir = false;
                    }
                }
            });
            if (!isCreateDir) {
                return Status.CANCEL_STATUS;
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : CreateDirDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.CreateDirDialog) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)

Example 2 with CheckDirTask

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

the class AddVolumeDialog method performTask.

/**
	 * perform the task
	 * 
	 * @param addVolumeDbInfo AddVolumeDbInfo
	 */
private void performTask(AddVolumeDbInfo addVolumeDbInfo) {
    // Checks the path
    String sPathText = pathText.getText().trim();
    ServerInfo serverInfo = selection.getServer().getServerInfo();
    CheckDirTask checkDirTask = new CheckDirTask(serverInfo);
    checkDirTask.setDirectory(new String[] { sPathText });
    CubridDatabase database = selection.getDatabase();
    AddVolumeDbTask addVolumeTask = new AddVolumeDbTask(database.getServer().getServerInfo());
    addVolumeTask.setDbname(database.getName());
    addVolumeTask.setVolname(addVolumeDbInfo.getVolname());
    addVolumeTask.setPurpose(addVolumeDbInfo.getPurpose());
    addVolumeTask.setPath(addVolumeDbInfo.getPath());
    addVolumeTask.setNumberofpages(addVolumeDbInfo.getNumberofpage());
    addVolumeTask.setSizeNeedMb(addVolumeDbInfo.getSize_need_mb());
    // Gets the database space info
    DbSpaceInfoList dbSpaceInfo = new DbSpaceInfoList();
    final CommonQueryTask<DbSpaceInfoList> dbSpaceInfoTask = new CommonQueryTask<DbSpaceInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), dbSpaceInfo);
    dbSpaceInfoTask.setDbName(database.getLabel());
    JobFamily jobFamily = new JobFamily();
    String serverName = selection.getServer().getName();
    String dbName = selection.getDatabase().getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    jobName = Messages.msgAddVolRearJobName + " - " + dbName + "@" + serverName;
    TaskJobExecutor taskExec = new CommonTaskJobExec(this);
    taskExec.addTask(checkDirTask);
    taskExec.addTask(addVolumeTask);
    taskExec.addTask(dbSpaceInfoTask);
    taskExec.schedule(dbName, jobFamily, true, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) AddVolumeDbTask(com.cubrid.cubridmanager.core.cubrid.dbspace.task.AddVolumeDbTask) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)

Example 3 with CheckDirTask

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

the class RestoreDatabaseDialog method postTaskFinished.

/**
	 * After a task has been executed, do some thing such as refresh.
	 * 
	 * @param task the task
	 * @return IStatus if complete refresh false if run into error
	 * 
	 */
public IStatus postTaskFinished(ITask task) {
    if (task instanceof CheckFileTask) {
        CheckFileTask checkFileTask = (CheckFileTask) task;
        final String[] files = checkFileTask.getExistFiles();
        if (files == null || files.length == 0) {
            String filePath = (String) checkFileTask.getData("filePath");
            return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, Messages.bind(Messages.errBackupFileNoExist, filePath));
        }
    } else if (task instanceof CheckDirTask) {
        CheckDirTask checkDirTask = (CheckDirTask) task;
        final String[] dirs = checkDirTask.getNoExistDirectory();
        if (dirs != null && dirs.length > 0) {
            CreateDirDialog dialog = new CreateDirDialog(getShell());
            dialog.setDirs(dirs);
            if (dialog.open() != IDialogConstants.OK_ID) {
                return Status.CANCEL_STATUS;
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)

Example 4 with CheckDirTask

use of com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask 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)

Example 5 with CheckDirTask

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

the class CopyDatabaseDialog method getCheckDirsTask.

/**
	 * Check the directory of server
	 * 
	 * 
	 * @return the SocketTask
	 */
private SocketTask getCheckDirsTask() {
    StringBuffer requestMsg = new StringBuffer();
    String tmp = "";
    if (copyVolButton.getSelection()) {
        for (int i = 0; i < copyDBVolList.getItemCount(); i++) {
            TableItem ti = copyDBVolList.getItem(i);
            tmp = ti.getText(2) + "\n";
            if (requestMsg.indexOf(tmp) < 0) {
                requestMsg.append(tmp);
            }
        }
    } else {
        requestMsg.append(destinationDBDirPathText.getText()).append("\n");
        if (!volumePathText.getText().equals(destinationDBDirPathText.getText())) {
            requestMsg.append(volumePathText.getText()).append("\n");
        }
    }
    tmp = destinationDBLogPathText.getText() + "\n";
    if (requestMsg.indexOf(tmp) < 0) {
        requestMsg.append(tmp);
    }
    newDirectories = requestMsg.toString().split("\n");
    CheckDirTask task = new CheckDirTask(database.getServer().getServerInfo());
    task.setDirectory(newDirectories);
    return task;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) Point(org.eclipse.swt.graphics.Point)

Aggregations

CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)9 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)6 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)6 CheckFileTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask)5 ITask (com.cubrid.common.core.task.ITask)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)4 ArrayList (java.util.ArrayList)3 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)2 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)2 GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)2 SetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask)2 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)2 CreateDirDialog (com.cubrid.cubridmanager.ui.cubrid.database.dialog.CreateDirDialog)2 List (java.util.List)2 Map (java.util.Map)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)1