Search in sources :

Example 71 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class CreateDatabaseWizard method performFinish.

/**
	 * Called when user clicks Finish
	 * 
	 * @return boolean
	 */
public boolean performFinish() {
    isCanFinished = true;
    isOverride = true;
    final String databaseName = generalInfoPage.getDatabaseName();
    String pageSize = generalInfoPage.getPageSize();
    String logPageSize = generalInfoPage.getLogPageSize();
    String generalPageNum = generalInfoPage.getGenericPageNum();
    String generalVolumePath = generalInfoPage.getGenericVolumePath();
    String charset = generalInfoPage.getCharset();
    final boolean isAutoStart = generalInfoPage.isAutoStart();
    TaskJobExecutor taskExcutor = new TaskJobExecutor() {

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

                public void run() {
                    getShell().setVisible(false);
                }
            });
            if (monitor.isCanceled()) {
                isCanFinished = true;
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        cancel();
                        close();
                    }
                });
                return Status.CANCEL_STATUS;
            }
            List<String> cubridConfContentList = null;
            for (ITask task : taskList) {
                if (task instanceof CreateDbTask) {
                    CreateDbTask createDbTask = (CreateDbTask) task;
                    createDbTask.setOverwriteConfigFile(isOverride);
                } else if (task instanceof SetCubridConfParameterTask) {
                    if (cubridConfContentList == null) {
                        continue;
                    } else {
                        SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
                        setParaTask.setConfContents(cubridConfContentList);
                    }
                }
                task.execute();
                final String msg = task.getErrorMsg();
                if (monitor.isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            cancel();
                            close();
                        }
                    });
                    isCanFinished = true;
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                    //start database failed
                    if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.START_DB_TASK_NAME)) {
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                CommonUITool.openErrorBox(getShell(), msg + StringUtil.NEWLINE + Messages.createDBFailedMsg);
                            }
                        });
                        return Status.OK_STATUS;
                    }
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            CommonUITool.openErrorBox(getShell(), msg);
                            isCanFinished = false;
                            getShell().setVisible(true);
                        }
                    });
                    return Status.CANCEL_STATUS;
                }
                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.getDefault().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.getDefault().syncExec(new Runnable() {

                            public void run() {
                                OverrideFileDialog dialog = new OverrideFileDialog(getShell());
                                dialog.setFiles(files);
                                isOverride = dialog.open() == IDialogConstants.OK_ID;
                                getShell().setVisible(!isOverride);
                            }
                        });
                    }
                } else if (task instanceof GetCubridConfParameterTask) {
                    GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
                    List<String> cubridConfContentListCandidate1 = null;
                    if (isAutoStart) {
                        cubridConfContentListCandidate1 = CoreUtils.addDatabaseToServiceServer(getCubridConfParameterTask, null, databaseName);
                    }
                    List<String> cubridConfContentListCandidate2 = null;
                    if (CompatibleUtil.isNeedCheckHAModeOnNewDb(server.getServerInfo())) {
                        cubridConfContentListCandidate2 = CoreUtils.changeHAModeFromCubridConf(getCubridConfParameterTask, cubridConfContentListCandidate1, databaseName);
                    }
                    if (cubridConfContentListCandidate2 == null) {
                        cubridConfContentList = cubridConfContentListCandidate1;
                    } else {
                        cubridConfContentList = cubridConfContentListCandidate2;
                    }
                }
                if (!isCanFinished) {
                    return Status.CANCEL_STATUS;
                }
                if (monitor.isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

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

        public void cancel() {
            super.cancel();
            GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(server.getServerInfo());
            getDatabaseListTask.execute();
            boolean isExist = false;
            List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
            if (databaseInfoList != null) {
                for (int i = 0; i < databaseInfoList.size(); i++) {
                    DatabaseInfo dbInfo = databaseInfoList.get(i);
                    String dbName = dbInfo.getDbName();
                    if (dbName.equals(databaseName)) {
                        isExist = true;
                    }
                }
            }
            if (isExist) {
                CommonUpdateTask deleteTask = new CommonUpdateTask(CommonTaskName.DELETE_DATABASE_TASK_NAME, server.getServerInfo(), CommonSendMsg.getDeletedbSendMsg());
                deleteTask.setDbName(databaseName);
                deleteTask.setDelbackup(YesNoType.Y);
                deleteTask.execute();
            }
        }

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

                    public void run() {
                        completeAll();
                        close();
                    }
                });
            }
        }
    };
    CheckDirTask checkDirTask = new CheckDirTask(server.getServerInfo());
    CheckFileTask checkFileTask = new CheckFileTask(server.getServerInfo());
    CreateDbTask createDbTask = new CreateDbTask(server.getServerInfo());
    List<String> checkedDirsList = new ArrayList<String>();
    List<String> checkedFilesList = new ArrayList<String>();
    // add checked directory(general volume path)
    addVolumePath(checkedDirsList, generalVolumePath);
    String logPageNum = generalInfoPage.getLogPageNum();
    String logVolumePath = generalInfoPage.getLogVolumePath();
    // add checked directory(log volume path)
    addVolumePath(checkedDirsList, logVolumePath);
    List<Map<String, String>> volumeList = volumeInfoPage.getVolumeList();
    for (int i = 0; i < volumeList.size(); i++) {
        Map<String, String> map = volumeList.get(i);
        String volumeName = map.get("0");
        String volumePath = map.get("4");
        // add checked directory(additional volume path)
        addVolumePath(checkedDirsList, volumePath);
        // add checked file(additional volume)
        addVolumePath(checkedFilesList, volumePath + server.getServerInfo().getPathSeparator() + volumeName);
    }
    String[] dirs = new String[checkedDirsList.size()];
    checkDirTask.setDirectory(checkedDirsList.toArray(dirs));
    String[] files = new String[checkedFilesList.size()];
    checkFileTask.setFile(checkedFilesList.toArray(files));
    createDbTask.setDbName(databaseName);
    createDbTask.setPageSize(pageSize);
    if (logPageSize != null) {
        createDbTask.setLogPageSize(logPageSize);
    }
    if (charset != null) {
        createDbTask.setCharset(charset);
    }
    createDbTask.setNumPage(generalPageNum);
    createDbTask.setGeneralVolumePath(generalVolumePath);
    createDbTask.setLogSize(logPageNum);
    createDbTask.setLogVolumePath(logVolumePath);
    createDbTask.setExVolumes(volumeList);
    if (!checkedDirsList.isEmpty()) {
        taskExcutor.addTask(checkDirTask);
    }
    if (!checkedFilesList.isEmpty()) {
        taskExcutor.addTask(checkFileTask);
    }
    taskExcutor.addTask(createDbTask);
    //add set auto added volume
    GetAutoAddVolumeInfo returnInfo = setAutoAddVolumeInfoPage.getAutoAddVolumeInfo();
    if (returnInfo != null) {
        SetAutoAddVolumeTask setTask = new SetAutoAddVolumeTask(server.getServerInfo());
        setTask.setDbname(databaseName);
        setTask.setData(returnInfo.getData());
        setTask.setDataWarnOutofspace(returnInfo.getData_warn_outofspace());
        setTask.setDataExtPage(returnInfo.getData_ext_page());
        setTask.setIndex(returnInfo.getIndex());
        setTask.setIndexWarnOutofspace(returnInfo.getIndex_warn_outofspace());
        setTask.setIndexExtPage(returnInfo.getIndex_ext_page());
        taskExcutor.addTask(setTask);
    }
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(server.getServerInfo());
    taskExcutor.addTask(getCubridConfParameterTask);
    SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(server.getServerInfo());
    taskExcutor.addTask(setCubridConfParameterTask);
    //start database
    CommonUpdateTask startDbTask = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, server.getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
    startDbTask.setDbName(databaseName);
    taskExcutor.addTask(startDbTask);
    //set dba password
    UpdateAddUserTask updateUserTask = new UpdateAddUserTask(server.getServerInfo(), false);
    UserSendObj userSendObj = new UserSendObj();
    userSendObj.setDbname(databaseName);
    userSendObj.setUsername("dba");
    String password = setDbaPasswordPage.getPassword();
    userSendObj.setUserpass(password);
    updateUserTask.setUserSendObj(userSendObj);
    taskExcutor.addTask(updateUserTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = server.getName();
    jobFamily.setServerName(serverName);
    String jobName = Messages.msgCreateDbrearJobName + " - " + serverName;
    taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
    //the close is in the job
    return false;
}
Also used : ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) UserSendObj(com.cubrid.cubridmanager.core.cubrid.database.model.UserSendObj) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) SetAutoAddVolumeTask(com.cubrid.cubridmanager.core.cubrid.dbspace.task.SetAutoAddVolumeTask) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) OverrideFileDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.OverrideFileDialog) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CreateDirDialog(com.cubrid.cubridmanager.ui.cubrid.database.dialog.CreateDirDialog) SetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask) UpdateAddUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.UpdateAddUserTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CreateDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.CreateDbTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Map(java.util.Map) GetAutoAddVolumeInfo(com.cubrid.cubridmanager.core.cubrid.dbspace.model.GetAutoAddVolumeInfo)

Example 72 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class DatabaseStatusEditor method loadData.

/**
	 *
	 * Load data
	 *
	 * @return <code>true</code> whether it is successful;<code>false</code>
	 *         otherwise
	 */
public boolean loadData() {
    TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {

        @SuppressWarnings("unchecked")
        @Override
        public IStatus exec(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            for (ITask t : taskList) {
                t.execute();
                final String msg = t.getErrorMsg();
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                } else {
                    final DbSpaceInfoList dbSpaceInfoList = ((CommonQueryTask<? extends DbSpaceInfoList>) t).getResultModel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            database.getDatabaseInfo().setDbSpaceInfoList(dbSpaceInfoList);
                            if (scrolledComp == null || scrolledComp.isDisposed()) {
                                return;
                            }
                            initial();
                            paintComp();
                            scrolledComp.setContent(parentComp);
                            scrolledComp.setExpandHorizontal(true);
                            scrolledComp.setExpandVertical(true);
                        }
                    });
                }
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }
    };
    CommonQueryTask<? extends DbSpaceInfoList> task = DbSpaceInfoList.useOld(database.getServer().getServerInfo().getEnvInfo()) ? new CommonQueryTask<DbSpaceInfoListOld>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoListOld()) : new CommonQueryTask<DbSpaceInfoListNew>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoListNew());
    task.setDbName(database.getName());
    taskJobExecutor.addTask(task);
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    String jobName = Messages.viewDbStatusJobName + " - " + dbName + "@" + serverName;
    taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
    return true;
}
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) DbSpaceInfoListOld(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoListOld) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DbSpaceInfoListNew(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoListNew) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask)

Example 73 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class UnloadDatabaseDialog method unloadDatabase.

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

        private List<String> unloadResultList = null;

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

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

                    public void run() {
                        setReturnCode(buttonId);
                        close();
                    }
                });
                isCanFinished = true;
                return Status.CANCEL_STATUS;
            }
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (monitor.isCanceled()) {
                    cancel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                    isCanFinished = true;
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            getShell().setVisible(true);
                        }
                    });
                    isCanFinished = false;
                    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.getDefault().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.getDefault().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 UnloadDatabaseTask) {
                    UnloadDatabaseTask unloadDatabaseTask = (UnloadDatabaseTask) task;
                    if (!isSchemaOnly) {
                        unloadResultList = unloadDatabaseTask.getUnloadDbResult();
                    }
                }
                if (!isCanFinished) {
                    return Status.CANCEL_STATUS;
                }
                if (monitor.isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

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

        /**
			 * Notification that a job has completed execution,
			 * 
			 * @param event the event details
			 */
        public void done(IJobChangeEvent event) {
            if (event.getResult() == Status.OK_STATUS) {
                if (isSchemaOnly) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgSuccessUnload);
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                } else {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            UnloadDatabaseResultDialog dialog = new UnloadDatabaseResultDialog(getShell());
                            dialog.setUnloadResulList(unloadResultList);
                            dialog.open();
                            setReturnCode(buttonId);
                            close();
                        }
                    });
                }
            }
        }
    };
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
    final UnloadDatabaseTask unloadDatabaseTask = new UnloadDatabaseTask(database.getServer().getServerInfo(), database.getDatabaseInfo().getCharSet());
    fillTask(taskExcutor, checkDirTask, checkFileTask, unloadDatabaseTask);
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    String jobName = Messages.msgUnloadDbRearJobName + " - " + dbName + "@" + serverName;
    JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    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) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) List(java.util.List) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) UnloadDatabaseTask(com.cubrid.cubridmanager.core.cubrid.database.task.UnloadDatabaseTask)

Example 74 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class OptimizeDialog method exec.

/**
	 *
	 * Execute to optimize the table
	 *
	 * @param buttonId the button id
	 * @param task the task
	 * @param cancelable whether it is cancelable
	 * @param shell the shell
	 */
public void exec(final int buttonId, final SocketTask task, boolean cancelable, Shell shell) {
    TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {

        @Override
        public IStatus exec(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            for (final ITask t : taskList) {
                t.execute();
                final String msg = t.getErrorMsg();
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                } else {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            TableItem item = new TableItem(volumeTable, SWT.NONE);
                            if (t.getErrorMsg() == null) {
                                item.setText(Messages.bind(Messages.errOptimizeSuccess, className.getText()));
                            } else {
                                CommonUITool.openInformationBox(getShell(), Messages.titleFailure, Messages.bind(Messages.errOptimizeFail, className.getText(), task.getErrorMsg()));
                                item.setText(Messages.errOptimizeFail + className.getText() + "-" + task.getErrorMsg());
                            }
                            volumeTable.getColumn(0).pack();
                        }
                    });
                }
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }
    };
    taskJobExecutor.addTask(task);
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    String jobName = Messages.titleOptimizeDbDialog + " - " + dbName + "@" + serverName;
    taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) TableItem(org.eclipse.swt.widgets.TableItem)

Example 75 with ITask

use of com.cubrid.common.core.task.ITask in project cubrid-manager by CUBRID.

the class SetDatabaseInfoPage method modifyText.

/**
	 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
	 * @param event ModifyEvent
	 */
public void modifyText(ModifyEvent event) {
    final String port = portText.getText();
    String password = passwordText.getText();
    String mdbPassword = masteDbaPasswordText.getText();
    String distdbPassword = distDbaPasswordText.getText();
    boolean isValidPort = ValidateUtil.isNumber(port);
    if (isValidPort) {
        int portVal = Integer.parseInt(port);
        if (portVal < 1024 || portVal > 65535) {
            isValidPort = false;
        }
    }
    if (!isValidPort) {
        setErrorMessage(Messages.errInvalidPort);
        setPageComplete(false);
        return;
    }
    boolean isValidPassword = password.length() >= 4 && password.indexOf(" ") < 0;
    if (!isValidPassword) {
        setErrorMessage(Messages.errInvalidPassword);
        setPageComplete(false);
        return;
    }
    boolean isValidMdbPassword = mdbPassword.length() >= 4 && mdbPassword.indexOf(" ") < 0;
    if (!isValidMdbPassword) {
        setErrorMessage(Messages.errInvalidMdbPassword);
        setPageComplete(false);
        return;
    }
    boolean isValidDistdbPassword = distdbPassword.length() >= 4 && distdbPassword.indexOf(" ") < 0;
    if (!isValidDistdbPassword) {
        setErrorMessage(Messages.errInvalidDistdbPassword);
        setPageComplete(false);
        return;
    }
    boolean isValid = isValidPort && isValidPassword && isValidMdbPassword && isValidDistdbPassword;
    setPageComplete(false);
    if (isValid) {
        final String ip = ipText.getText();
        final String userName = userNameText.getText();
        final MonitorDashboardPreference monPref = new MonitorDashboardPreference();
        TaskExecutor taskExcutor = new TaskExecutor() {

            public boolean exec(final IProgressMonitor monitor) {
                Display display = getShell().getDisplay();
                if (monitor.isCanceled()) {
                    return false;
                }
                boolean isConnected = false;
                for (ITask task : taskList) {
                    if (task instanceof MonitoringTask) {
                        MonitoringTask monitoringTask = (MonitoringTask) task;
                        monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
                        isConnected = true;
                    } else if (task instanceof LoginDatabaseTask) {
                        task.execute();
                    }
                    final String msg = task.getErrorMsg();
                    if (monitor.isCanceled()) {
                        if (isConnected) {
                            ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
                        }
                        return false;
                    }
                    if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                        monitor.done();
                        display.syncExec(new Runnable() {

                            public void run() {
                                setErrorMessage(msg);
                            }
                        });
                        if (isConnected) {
                            ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
                        }
                        return false;
                    }
                }
                if (!monitor.isCanceled()) {
                    if (isConnected) {
                        ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
                    }
                    display.syncExec(new Runnable() {

                        public void run() {
                            setErrorMessage(null);
                            setPageComplete(true);
                        }
                    });
                }
                return true;
            }
        };
        ServerInfo serverInfo = new ServerInfo();
        if (ServerManager.getInstance().isConnected(ip, Integer.parseInt(port), userName)) {
            serverInfo = CMHostNodePersistManager.getInstance().getServerInfo(ip, Integer.parseInt(port), userName);
        } else {
            serverInfo.setHostAddress(ip);
            serverInfo.setHostMonPort(Integer.parseInt(port));
            serverInfo.setHostJSPort(Integer.parseInt(port + 1));
            serverInfo.setUserName(userNameText.getText());
            serverInfo.setUserPassword(password);
            CMHostNodePersistManager.getInstance().addServer(ip, Integer.parseInt(port), userName, serverInfo);
            MonitoringTask monitoringTask = new MonitoringTask(serverInfo);
            taskExcutor.addTask(monitoringTask);
        }
        LoginDatabaseTask loginMDbTask = new LoginDatabaseTask(serverInfo);
        loginMDbTask.setCMUser("admin");
        loginMDbTask.setDbName(masterDbNameText.getText());
        loginMDbTask.setDbUser("dba");
        loginMDbTask.setDbPassword(masteDbaPasswordText.getText());
        taskExcutor.addTask(loginMDbTask);
        LoginDatabaseTask loginDistdbTask = new LoginDatabaseTask(replNode.getServer().getServerInfo());
        loginDistdbTask.setCMUser("admin");
        loginDistdbTask.setDbName(distDbNameText.getText());
        loginDistdbTask.setDbUser("dba");
        loginDistdbTask.setDbPassword(distDbaPasswordText.getText());
        taskExcutor.addTask(loginDistdbTask);
        new ExecTaskWithProgress(taskExcutor).exec(true, true);
    }
}
Also used : MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) LoginDatabaseTask(com.cubrid.cubridmanager.core.cubrid.database.task.LoginDatabaseTask) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) Display(org.eclipse.swt.widgets.Display)

Aggregations

ITask (com.cubrid.common.core.task.ITask)85 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)49 IStatus (org.eclipse.core.runtime.IStatus)37 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)35 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)35 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)28 ArrayList (java.util.ArrayList)27 Status (org.eclipse.core.runtime.Status)23 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)20 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)17 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)15 Map (java.util.Map)15 Display (org.eclipse.swt.widgets.Display)15 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)14 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)14 List (java.util.List)14 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)13 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)13 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)12 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)11