Search in sources :

Example 16 with CommonQueryTask

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

Example 17 with CommonQueryTask

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

the class DatabaseLogListDialog 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
	 * 
	 */
@SuppressWarnings("unchecked")
public IStatus postTaskFinished(ITask task) {
    if (task instanceof CommonQueryTask) {
        CommonQueryTask<DbLogInfos> getLogListTask = (CommonQueryTask<DbLogInfos>) task;
        DbLogInfos dbLogInfos = getLogListTask.getResultModel();
        DbLogInfoList dbLogInfoList = dbLogInfos == null ? null : dbLogInfos.getDbLogInfoList();
        List<LogInfo> logInfoList = dbLogInfoList == null ? null : dbLogInfoList.getDbLogInfoList();
        for (int i = 0; logInfoList != null && i < logInfoList.size(); i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            LogInfo logInfo = logInfoList.get(i);
            map.put("0", logInfo.getName());
            map.put("1", logInfo);
            dbLogList.add(map);
        }
        if (dbLogTable != null && !dbLogTable.isDisposed()) {
            dbLogTableViewer.refresh();
            for (int i = 0; i < dbLogTable.getColumnCount(); i++) {
                dbLogTable.getColumn(i).pack();
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : DbLogInfos(com.cubrid.cubridmanager.core.logs.model.DbLogInfos) LogInfo(com.cubrid.cubridmanager.core.logs.model.LogInfo) DbLogInfoList(com.cubrid.cubridmanager.core.logs.model.DbLogInfoList) HashMap(java.util.HashMap) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask)

Example 18 with CommonQueryTask

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

the class BrokerEnvStatusView method refresh.

/**
	 * Refreshes this view
	 *
	 * @param isUpdateTable whether update table
	 * @param isRefreshChanged whether refresh changed
	 *
	 */
public void refresh(boolean isUpdateTable, boolean isRefreshChanged) {
    ServerInfo site = cubridNode.getServer().getServerInfo();
    BrokerInfos brokerInfos = new BrokerInfos();
    final CommonQueryTask<BrokerInfos> task = new CommonQueryTask<BrokerInfos>(site, CommonSendMsg.getCommonSimpleSendMsg(), brokerInfos);
    task.execute();
    brokerInfos = task.getResultModel();
    List<BrokerInfo> newBrokerInfoList = null;
    if (null != brokerInfos) {
        BrokerInfoList list = brokerInfos.getBorkerInfoList();
        if (list != null && list.getBrokerInfoList() != null) {
            newBrokerInfoList = list.getBrokerInfoList();
        }
    }
    List<BrokerInfo> changedBrokerInfoList = new ArrayList<BrokerInfo>();
    for (int i = 0; newBrokerInfoList != null && i < newBrokerInfoList.size(); i++) {
        BrokerInfo newBrokerInfo = newBrokerInfoList.get(i);
        BrokerInfo changedBrokerInfo = newBrokerInfo.clone();
        for (int j = 0; oldBrokerInfoList != null && j < oldBrokerInfoList.size(); j++) {
            BrokerInfo oldBrokerInfo = oldBrokerInfoList.get(j);
            if (newBrokerInfo.getName().equalsIgnoreCase(oldBrokerInfo.getName())) {
                // FIXME more simple
                long newTran = StringUtil.intValue(newBrokerInfo.getTran());
                long newQuery = StringUtil.intValue(newBrokerInfo.getQuery());
                long newLongTran = StringUtil.longValue(newBrokerInfo.getLong_tran());
                long newLongQuery = StringUtil.longValue(newBrokerInfo.getLong_query());
                long newErrQuery = StringUtil.intValue(newBrokerInfo.getError_query());
                long oldTran = StringUtil.intValue(oldBrokerInfo.getTran());
                long oldQuery = StringUtil.intValue(oldBrokerInfo.getQuery());
                long oldLongTran = StringUtil.longValue(oldBrokerInfo.getLong_tran());
                long oldLongQuery = StringUtil.longValue(oldBrokerInfo.getLong_query());
                long oldErrQuery = StringUtil.intValue(oldBrokerInfo.getError_query());
                long changedTran = newTran - oldTran;
                long changedQuery = newQuery - oldQuery;
                long changedLongTran = newLongTran - oldLongTran;
                long changedLongQuery = newLongQuery - oldLongQuery;
                long changedErrQuery = newErrQuery - oldErrQuery;
                changedBrokerInfo.setTran(String.valueOf(changedTran > 0 ? changedTran : 0));
                changedBrokerInfo.setQuery(String.valueOf(changedQuery > 0 ? changedQuery : 0));
                changedBrokerInfo.setLong_tran(String.valueOf(changedLongTran > 0 ? changedLongTran : 0));
                changedBrokerInfo.setLong_query(String.valueOf(changedLongQuery > 0 ? changedLongQuery : 0));
                changedBrokerInfo.setError_query(String.valueOf(changedErrQuery > 0 ? changedErrQuery : 0));
                break;
            }
        }
        changedBrokerInfoList.add(changedBrokerInfo);
    }
    oldBrokerInfoList = newBrokerInfoList;
    if (isUpdateTable) {
        if (isRefreshChanged) {
            tableViewer.setInput(changedBrokerInfoList);
        } else {
            tableViewer.setInput(oldBrokerInfoList);
        }
        tableViewer.refresh();
    }
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) ArrayList(java.util.ArrayList) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) BrokerInfoList(com.cubrid.cubridmanager.core.broker.model.BrokerInfoList) BrokerInfo(com.cubrid.cubridmanager.core.broker.model.BrokerInfo)

Example 19 with CommonQueryTask

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

the class LockInfoDialog method loadData.

/**
	 * load the init data from the server
	 * 
	 * @param shell the shell
	 * @return <code>true</code> if load successfully;<code>false</code>
	 *         otherwise
	 */
public boolean loadData(Shell shell) {
    CommonQueryTask<DatabaseLockInfo> task = new CommonQueryTask<DatabaseLockInfo>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DatabaseLockInfo());
    task.setDbName(database.getName());
    execTask(-1, new SocketTask[] { task }, true, shell);
    if (task.getErrorMsg() != null) {
        return false;
    }
    setDatabaseLockInfo(task.getResultModel());
    return true;
}
Also used : DatabaseLockInfo(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DatabaseLockInfo) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask)

Example 20 with CommonQueryTask

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

the class KillTransactionDialog method killTransaction.

/**
	 * 
	 * Kill the transaction
	 * 
	 * @param type the transaction type
	 * @param parameter the parameter
	 */
private void killTransaction(KillTranType type, String parameter) {
    CommonQueryTask<KillTransactionList> task = new CommonQueryTask<KillTransactionList>(database.getServer().getServerInfo(), CommonSendMsg.getKillTransactionMSGItems(), new KillTransactionList());
    task.setDbName(database.getName());
    task.setKillTranType(type);
    task.setKillTranParameter(parameter);
    executeKillTrans(-1, new SocketTask[] { task }, true, getShell());
    if (task.getErrorMsg() != null) {
        isSuccess = false;
        return;
    }
    isSuccess = true;
    CommonUITool.openInformationBox(parentComp.getShell(), Messages.titleSuccess, Messages.msgKillSuccess);
    killTransactionList = task.getResultModel();
}
Also used : KillTransactionList(com.cubrid.cubridmanager.core.cubrid.database.model.transaction.KillTransactionList) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask)

Aggregations

CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)60 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)19 ITask (com.cubrid.common.core.task.ITask)14 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)12 IStatus (org.eclipse.core.runtime.IStatus)12 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)11 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)11 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)11 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)8 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)7 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)7 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)7 ArrayList (java.util.ArrayList)7 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)6 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)6 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)6 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)6 LogInfo (com.cubrid.cubridmanager.core.logs.model.LogInfo)6 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)5 GetBrokerConfParameterTask (com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask)5