Search in sources :

Example 51 with IStatus

use of org.eclipse.core.runtime.IStatus 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 52 with IStatus

use of org.eclipse.core.runtime.IStatus in project cubrid-manager by CUBRID.

the class DBSpaceLabelProvider method loadDbServerData.

public void loadDbServerData() {
    final GetEnvInfoTask getEnvInfoTask = new GetEnvInfoTask(serverInfo);
    TaskJobExecutor taskJobExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            EnvInfo envInfo = getEnvInfoTask.loadEnvInfo();
            StringBuilder sb = new StringBuilder();
            if (envInfo != null) {
                sb.append(" ").append(Messages.lblHost + serverInfo.getHostAddress() + ":" + serverInfo.getHostMonPort()).append(StringUtil.NEWLINE);
                sb.append(" ").append(Messages.lblDBVersion + envInfo.getServerVersion()).append(StringUtil.NEWLINE);
                sb.append(" ").append(Messages.lblBrokerVersion + envInfo.getBrokerVersion()).append(StringUtil.NEWLINE);
                sb.append(" ").append(Messages.lblCubridPath + envInfo.getRootDir()).append(StringUtil.NEWLINE);
                sb.append(" ").append(Messages.lblDBPath + envInfo.getDatabaseDir()).append(StringUtil.NEWLINE);
            }
            setDbServerData(sb.toString());
            finishedCount++;
            updateToolBar();
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    taskJobExec.addTask(getEnvInfoTask);
    String serverName = serverInfo.getServerName();
    String jobName = Messages.taskGetServerInfo + serverName;
    JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(serverName);
    taskJobExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask) EnvInfo(com.cubrid.cubridmanager.core.common.model.EnvInfo)

Example 53 with IStatus

use of org.eclipse.core.runtime.IStatus in project cubrid-manager by CUBRID.

the class DBSpaceLabelProvider method loadBrokerData.

public void loadBrokerData() {
    BrokerInfos brokerInfos = new BrokerInfos();
    final CommonQueryTask<BrokerInfos> task = new CommonQueryTask<BrokerInfos>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), brokerInfos);
    TaskJobExecutor taskJobExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            BrokerInfos brokerInfos = task.getResultModel();
            List<BrokerInfo> newBrokerInfoList = null;
            if (null != brokerInfos) {
                BrokerInfoList list = brokerInfos.getBorkerInfoList();
                if (list != null && list.getBrokerInfoList() != null) {
                    newBrokerInfoList = list.getBrokerInfoList();
                }
            }
            setBrokerData(newBrokerInfoList);
            finishedCount++;
            updateToolBar();
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    taskJobExec.addTask(task);
    String serverName = serverInfo.getServerName();
    String jobName = Messages.taskGetBrokerInfo + serverName;
    JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(serverName);
    taskJobExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) BrokerInfoList(com.cubrid.cubridmanager.core.broker.model.BrokerInfoList) List(java.util.List) ArrayList(java.util.ArrayList) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) BrokerInfoList(com.cubrid.cubridmanager.core.broker.model.BrokerInfoList)

Example 54 with IStatus

use of org.eclipse.core.runtime.IStatus in project cubrid-manager by CUBRID.

the class ConnectDatabaseNodeJobExecutor method exec.

/**
	 * Execute to connect database
	 * 
	 * @param monitor the IProgressMonitor
	 * @return <code>true</code> if successful;<code>false</code>otherwise;
	 */
public IStatus exec(final IProgressMonitor monitor) {
    monitor.subTask(Messages.bind(com.cubrid.cubridmanager.ui.mondashboard.Messages.jobConnectDatabase, dbNode.getDbName()));
    //Check this database whether exist
    List<String> realDbNameList = serverInfo.getAllDatabaseList();
    if (!realDbNameList.contains(dbNode.getDbName())) {
        return Status.CANCEL_STATUS;
    }
    for (ITask task : taskList) {
        if (task instanceof VerifyDbUserPasswordTask) {
            IStatus status = connectDatabase((VerifyDbUserPasswordTask) task);
            if (status == Status.CANCEL_STATUS) {
                return Status.CANCEL_STATUS;
            }
        } else {
            task.execute();
        }
        final String msg = task.getErrorMsg();
        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
            return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
        }
        if (monitor.isCanceled()) {
            return Status.CANCEL_STATUS;
        }
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) VerifyDbUserPasswordTask(com.cubrid.cubridmanager.core.mondashboard.task.VerifyDbUserPasswordTask)

Example 55 with IStatus

use of org.eclipse.core.runtime.IStatus in project cubrid-manager by CUBRID.

the class ConnectHostJobExecutor method exec.

/**
	 * Execute to connect host
	 * 
	 * @param monitor the IProgressMonitor
	 * @return <code>true</code> if successful;<code>false</code>otherwise;
	 */
@SuppressWarnings("unchecked")
public IStatus exec(final IProgressMonitor monitor) {
    monitor.subTask(Messages.bind(com.cubrid.cubridmanager.ui.mondashboard.Messages.jobConnectHost, serverInfo.getHostAddress()));
    isContinue = true;
    boolean isRunUpdateCmUserTask = false;
    BrokerInfos brokerInfos = null;
    errorMsg = null;
    for (ITask task : taskList) {
        if (task instanceof MonitoringTask) {
            IStatus status = connectHost((MonitoringTask) task);
            if (Status.OK_STATUS != status) {
                return status;
            }
        } else if ((task instanceof UpdateCMUserTask)) {
            updateCMUserAuthInfo(task, isRunUpdateCmUserTask);
        } else if ((task instanceof GetHeartbeatNodeInfoTask) && !CompatibleUtil.isSupportHA(serverInfo)) {
            continue;
        } else {
            task.execute();
        }
        final String msg = task.getErrorMsg();
        if (monitor.isCanceled()) {
            disConnect();
            return Status.CANCEL_STATUS;
        }
        if (!hostNode.isConnecting()) {
            return Status.CANCEL_STATUS;
        }
        if (msg != null && msg.length() > 0) {
            disConnect();
            if (isPing) {
                errorMsg = msg;
                return Status.CANCEL_STATUS;
            }
            return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
        }
        if (task instanceof GetEnvInfoTask) {
            GetEnvInfoTask getEnvInfoTask = (GetEnvInfoTask) task;
            EnvInfo envInfo = getEnvInfoTask.loadEnvInfo();
            serverInfo.setEnvInfo(envInfo);
            String clientVersion = Version.buildVersionId.substring(0, Version.buildVersionId.lastIndexOf("."));
            if (!CompatibleUtil.isSupportCMServer(serverInfo, clientVersion)) {
                disConnect();
                errorMsg = Messages.bind(Messages.errNoSupportServerVersion, clientVersion);
                if (isPing) {
                    return Status.CANCEL_STATUS;
                }
                return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, errorMsg);
            }
            if (!serverInfo.validateJdbcVersion(serverInfo.getJdbcDriverVersion())) {
                disConnect();
                if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(serverInfo.getJdbcDriverVersion())) {
                    errorMsg = Messages.errNoSupportDriver;
                } else {
                    errorMsg = Messages.errSelectSupportDriver;
                }
                if (isPing) {
                    return Status.CANCEL_STATUS;
                }
                return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, errorMsg);
            }
        } else if (task instanceof GetDatabaseListTask) {
            GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
            List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
            if (databaseInfoList != null) {
                allDatabaseInfoList.addAll(databaseInfoList);
            }
        } else if (task instanceof GetCMConfParameterTask) {
            GetCMConfParameterTask getCMConfParameterTask = (GetCMConfParameterTask) task;
            Map<String, String> confParameters = getCMConfParameterTask.getConfParameters();
            ServerType serverType = ServerType.BOTH;
            if (confParameters != null) {
                String target = confParameters.get(ConfConstants.CM_TARGET);
                if (target != null) {
                    if (target.indexOf("broker") >= 0 && target.indexOf("server") >= 0) {
                        serverType = ServerType.BOTH;
                    } else if (target.indexOf("broker") >= 0) {
                        serverType = ServerType.BROKER;
                    } else if (target.indexOf("server") >= 0) {
                        serverType = ServerType.DATABASE;
                    }
                }
            }
            if (serverInfo != null) {
                serverInfo.setServerType(serverType);
            }
        } else if (task instanceof CommonQueryTask) {
            CommonQueryTask<BrokerInfos> getBrokerTask = (CommonQueryTask<BrokerInfos>) task;
            brokerInfos = getBrokerTask.getResultModel();
            if (serverInfo != null) {
                serverInfo.setBrokerInfos(brokerInfos);
            }
        } else if (task instanceof GetCMUserListTask) {
            if (serverInfo != null && serverInfo.isConnected()) {
                GetCMUserListTask getUserInfoTask = (GetCMUserListTask) task;
                List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
                for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
                    ServerUserInfo userInfo = serverUserInfoList.get(i);
                    if (userInfo != null && userInfo.getUserName().equals(serverInfo.getUserName())) {
                        serverInfo.setLoginedUserInfo(userInfo);
                        break;
                    }
                }
                List<DatabaseInfo> databaseInfoList = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
                if (databaseInfoList != null) {
                    authDatabaseList.addAll(databaseInfoList);
                }
                isRunUpdateCmUserTask = CubridDatabasesFolderLoader.filterDatabaseList(serverInfo, allDatabaseInfoList, authDatabaseList);
                if (isRunUpdateCmUserTask) {
                    serverInfo.getLoginedUserInfo().setDatabaseInfoList(authDatabaseList);
                }
            }
        } else if (task instanceof GetCubridConfParameterTask) {
            GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
            Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
            if (serverInfo != null) {
                serverInfo.setCubridConfParaMap(confParas);
            }
        } else if (task instanceof GetBrokerConfParameterTask) {
            GetBrokerConfParameterTask getBrokerConfParameterTask = (GetBrokerConfParameterTask) task;
            Map<String, Map<String, String>> confParas = getBrokerConfParameterTask.getConfParameters();
            if (serverInfo != null) {
                serverInfo.setBrokerConfParaMap(confParas);
            }
        } else if (task instanceof GetHeartbeatNodeInfoTask) {
            GetHeartbeatNodeInfoTask getHeartbeatNodeInfoTask = (GetHeartbeatNodeInfoTask) task;
            haHostStatusInfo = getHeartbeatNodeInfoTask.getHostStatusInfo(serverInfo.getHostAddress());
        }
        if (monitor.isCanceled() || !isContinue) {
            disConnect();
            return Status.CANCEL_STATUS;
        }
    }
    return Status.OK_STATUS;
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) GetHeartbeatNodeInfoTask(com.cubrid.cubridmanager.core.mondashboard.task.GetHeartbeatNodeInfoTask) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) ArrayList(java.util.ArrayList) List(java.util.List) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) Map(java.util.Map) EnvInfo(com.cubrid.cubridmanager.core.common.model.EnvInfo)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)1423 Status (org.eclipse.core.runtime.Status)500 CoreException (org.eclipse.core.runtime.CoreException)369 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)270 File (java.io.File)169 IOException (java.io.IOException)154 ArrayList (java.util.ArrayList)141 IPath (org.eclipse.core.runtime.IPath)138 IFile (org.eclipse.core.resources.IFile)130 Job (org.eclipse.core.runtime.jobs.Job)123 MultiStatus (org.eclipse.core.runtime.MultiStatus)113 InvocationTargetException (java.lang.reflect.InvocationTargetException)106 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)85 IProject (org.eclipse.core.resources.IProject)84 List (java.util.List)83 Path (org.eclipse.core.runtime.Path)52 Test (org.junit.Test)52 IResource (org.eclipse.core.resources.IResource)51 SubMonitor (org.eclipse.core.runtime.SubMonitor)51 Composite (org.eclipse.swt.widgets.Composite)44