use of com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference in project cubrid-manager by CUBRID.
the class CreateReplicationJobExecutor method createDistributor.
/**
* create distributor database
*
* @param dbName String
* @param monitor IProgressMonitor
* @param taskList List<ITask>
* @return status
*/
private IStatus createDistributor(String dbName, final IProgressMonitor monitor, List<ITask> taskList) {
monitor.subTask(Messages.bind(Messages.createDistJobName, dbName));
Display display = Display.getDefault();
MonitoringTask monitoringTask = null;
boolean isExecuteStopDbTask = true;
MonitorDashboardPreference monPref = new MonitorDashboardPreference();
for (ITask task : taskList) {
if (task instanceof MonitoringTask) {
monitoringTask = (MonitoringTask) task;
ServerInfo serverInfo = monitoringTask.getServerInfo();
CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
} else if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.STOP_DB_TASK_NAME)) {
if (isDeleteDb && isExecuteStopDbTask) {
task.execute();
} else {
continue;
}
} else if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.DELETE_DATABASE_TASK_NAME)) {
if (isDeleteDb) {
task.execute();
} else {
continue;
}
} else {
task.execute();
}
if (monitor.isCanceled()) {
disConnect(monitoringTask);
return Status.CANCEL_STATUS;
}
final String msg = task.getErrorMsg();
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
disConnect(monitoringTask);
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
}
if (task instanceof GetDatabaseListTask) {
GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
final String distdbName = (String) getDatabaseListTask.getData("dbName");
List<DatabaseInfo> dbInfoList = getDatabaseListTask.loadDatabaseInfo();
boolean isDbExist = false;
for (int i = 0; i < dbInfoList.size(); i++) {
DatabaseInfo dbInfo = dbInfoList.get(i);
if (dbName.equalsIgnoreCase(dbInfo.getDbName())) {
isDbExist = true;
display.syncExec(new Runnable() {
public void run() {
isDeleteDb = CommonUITool.openConfirmBox(Messages.bind(Messages.msgConfirmDeleteDb, distdbName));
}
});
if (dbInfo.getRunningType() == DbRunningType.CS) {
isExecuteStopDbTask = true;
}
break;
}
}
if (isDbExist && !isDeleteDb) {
disConnect(monitoringTask);
return Status.CANCEL_STATUS;
}
}
}
disConnect(monitoringTask);
isDeleteDb = false;
return Status.OK_STATUS;
}
use of com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference in project cubrid-manager by CUBRID.
the class CreateReplicationJobExecutor method startReplServer.
/**
* start replication server
*
* @param serverName String
* @param monitor IProgressMonitor
* @param taskList List<ITask
* @return status
*/
private IStatus startReplServer(String serverName, final IProgressMonitor monitor, List<ITask> taskList) {
monitor.subTask(Messages.bind(Messages.startReplServerJobName, serverName));
MonitoringTask monitoringTask = null;
MonitorDashboardPreference monPref = new MonitorDashboardPreference();
for (ITask task : taskList) {
if (task instanceof MonitoringTask) {
monitoringTask = (MonitoringTask) task;
ServerInfo serverInfo = monitoringTask.getServerInfo();
CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
} else {
task.execute();
}
if (monitor.isCanceled()) {
disConnect(monitoringTask);
return Status.CANCEL_STATUS;
}
final String msg = task.getErrorMsg();
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
disConnect(monitoringTask);
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
}
}
disConnect(monitoringTask);
return Status.OK_STATUS;
}
use of com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference in project cubrid-manager by CUBRID.
the class ConnectHostJobExecutor method connectHost.
/**
*
* Connect host
*
* @param task The MonitoringTask
* @return IStatus
*/
private IStatus connectHost(MonitoringTask task) {
MonitorDashboardPreference monPref = new MonitorDashboardPreference();
while (!serverInfo.isConnected() && isContinue) {
serverInfo = task.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
final String msg = task.getErrorMsg();
if (this.isPing && msg != null && msg.length() > 0) {
return Status.CANCEL_STATUS;
}
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (msg != null && msg.length() > 0) {
ConnectHostNodeDialog dialog = new ConnectHostNodeDialog(null, hostNode, msg);
if (dialog.open() == IDialogConstants.OK_ID) {
serverInfo.setHostMonPort(Integer.parseInt(dialog.getPort()));
serverInfo.setUserPassword(dialog.getPassword());
} else {
isContinue = false;
}
}
}
});
}
if (serverInfo.isConnected()) {
CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
}
changePassword();
if (!isContinue) {
disConnect();
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference in project cubrid-manager by CUBRID.
the class FinishTask method call.
public Integer call() {
ProgressBar bar = (ProgressBar) item.getData(MultiHostConnectionDialog.KEY_BAR);
MonitorDashboardPreference monPref = new MonitorDashboardPreference();
boolean isRunUpdateCmUserTask = false;
BrokerInfos brokerInfos = null;
int size = tasks.size();
int taskIdx = 1;
for (ITask task : tasks) {
if (task instanceof MonitoringTask) {
if (!serverInfo.isConnected()) {
CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
MonitoringTask monitoringTask = (MonitoringTask) task;
serverInfo = monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
if (serverInfo.isConnected()) {
CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
} else {
CMHostNodePersistManager.getInstance().removeServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName());
}
}
} else if ((task instanceof UpdateCMUserTask)) {
updateCMUserAuthInfo(task, isRunUpdateCmUserTask);
} else {
task.execute();
}
final String msg = task.getErrorMsg();
if (msg != null && msg.length() > 0) {
item.setText(3, msg);
disConnect();
isFinished = true;
updateIcon();
return 1;
}
if (task instanceof GetEnvInfoTask) {
GetEnvInfoTask getEnvInfoTask = (GetEnvInfoTask) task;
EnvInfo envInfo = getEnvInfoTask.loadEnvInfo();
serverInfo.setEnvInfo(envInfo);
String clientVersion = getClientVerion();
if (!isClientSupport(clientVersion)) {
item.setText(3, Messages.bind(Messages.errNoSupportServerVersion, clientVersion));
disConnect();
isFinished = true;
updateIcon();
return 2;
}
String jdbcVersion = serverInfo.getJdbcDriverVersion();
if (serverInfo.validateJdbcVersion(jdbcVersion)) {
if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
serverInfo.setJdbcDriverVersion(ServerInfo.getAutoDetectJdbcVersion(serverInfo.getFullServerVersionKey()));
}
} else {
if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
item.setText(3, Messages.errNoSupportDriver);
} else {
item.setText(3, Messages.errSelectSupportDriver);
}
disConnect();
isFinished = true;
updateIcon();
return 3;
}
} 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(CubridManagerConfParaConstants.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 FinishTask) {
isSuccess = true;
server.getLoader().setLoaded(false);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
}
bar.setSelection(taskIdx++ / size * 100);
if (isCanceled()) {
isFinished = true;
updateIcon();
return 4;
}
}
bar.setSelection(100);
item.setText(3, Messages.msgConneted);
isFinished = true;
return 0;
}
use of com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference in project cubrid-manager by CUBRID.
the class ConnectHostExecutor method runLoop.
private boolean runLoop(final IProgressMonitor monitor) {
MonitorDashboardPreference monPref = new MonitorDashboardPreference();
isContinue = true;
boolean isRunUpdateCmUserTask = false;
BrokerInfos brokerInfos = null;
/*To avoid invalid thread access exception*/
beginTask(monitor);
for (ITask task : taskList) {
if (task instanceof MonitoringTask) {
if (!serverInfo.isConnected()) {
addServerInHashMap(serverInfo);
MonitoringTask monitoringTask = (MonitoringTask) task;
serverInfo = monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
if (serverInfo.isConnected()) {
addServerInHashMap(serverInfo);
} else {
removeServerFromHashMap(serverInfo);
}
}
changePassword();
} else if ((task instanceof UpdateCMUserTask)) {
updateCMUserAuthInfo(task, isRunUpdateCmUserTask);
} else {
task.execute();
}
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
disConnect();
return false;
}
if (msg != null) {
boolean emptyMsg = StringUtil.isEmpty(msg);
// for TOOLS-2142 logging
try {
if (task instanceof MonitoringTask) {
String request = ((MonitoringTask) task).getRequest();
char[] requestCharArray = request.toCharArray();
int sp = request.indexOf("id:");
if (sp != -1) {
sp += "id:".length();
for (int i = sp; i < requestCharArray.length; i++) {
if (requestCharArray[i] == '\n') {
break;
}
requestCharArray[i] = '*';
}
}
sp = request.indexOf("password:");
if (sp != -1) {
sp += "password:".length();
for (int i = sp; i < requestCharArray.length; i++) {
if (requestCharArray[i] == '\n') {
break;
}
requestCharArray[i] = '*';
}
}
LOGGER.debug("CMS request : \n" + new String(requestCharArray));
LOGGER.debug("CMS error : \n" + task.getErrorMsg());
LOGGER.debug("CMS warn : \n" + task.getWarningMsg());
}
} catch (Exception e) {
LOGGER.error("", e);
}
String lowerMsg = msg.toLowerCase();
// Connection refused: connect
if (lowerMsg.indexOf("connection refused: connect") != -1) {
String localizedMsg = Messages.errConnectionRefused;
if (!prepareMessage(monitor, localizedMsg)) {
return false;
}
} else //the socket "Connection reset" occasional error is unnecessary to display, and it will affect user experience.
if (lowerMsg.indexOf("connection reset") != -1) {
String localizedMsg = Messages.errConnectionReset;
if (!prepareMessage(monitor, localizedMsg)) {
return false;
}
} else // connect timed out
if (lowerMsg.indexOf("connect timed out") != -1) {
String localizedMsg = Messages.errConnectTimedOut;
if (!prepareMessage(monitor, localizedMsg)) {
return false;
}
} else // user not found
if (lowerMsg.indexOf("user not found") != -1) {
String localizedMsg = Messages.errUserNotFound;
if (!prepareMessage(monitor, localizedMsg)) {
return false;
}
} else // Incorrect password
if (lowerMsg.indexOf("incorrect password") != -1) {
String localizedMsg = Messages.errUserPasswordConnect;
if (!prepareMessage(monitor, localizedMsg)) {
return false;
}
} else // No route to host connect
if (lowerMsg.indexOf("no route to host connect") != -1) {
String localizedMsg = Messages.errConnectAddress;
if (!prepareMessage(monitor, localizedMsg)) {
return false;
}
} else // There is no error message but there have some error about brokers.
if (emptyMsg && StringUtil.isEqual(task.getTaskname(), BrokerInfos.TASK_NAME)) {
String localizedMsg = Messages.errConnectionByBrokerConfig;
if (!prepareMessage(monitor, localizedMsg)) {
return false;
}
} else {
String localizedMsg = Messages.bind(Messages.errConnectionFailed, msg);
if (!prepareMessage(monitor, localizedMsg)) {
return false;
}
}
}
if (task instanceof GetEnvInfoTask) {
GetEnvInfoTask getEnvInfoTask = (GetEnvInfoTask) task;
EnvInfo envInfo = getEnvInfoTask.loadEnvInfo();
serverInfo.setEnvInfo(envInfo);
String clientVersion = getClientVerion();
if (!isClientSupport(clientVersion)) {
openErrorBox(shell, Messages.bind(Messages.errNoSupportServerVersion, clientVersion), monitor);
}
//for multi host monitor statistic and monitor dashboard
if (isCheckJdbc) {
String jdbcVersion = serverInfo.getJdbcDriverVersion();
if (serverInfo.validateJdbcVersion(jdbcVersion)) {
if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
serverInfo.setJdbcDriverVersion(ServerInfo.getAutoDetectJdbcVersion(serverInfo.getFullServerVersionKey()));
}
} else {
if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
openErrorBox(shell, Messages.errNoSupportDriver, monitor);
} else {
openErrorBox(shell, Messages.errSelectSupportDriver, monitor);
}
disConnect();
return false;
}
}
} 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;
}
}
String supportMonStatistic = confParameters.get(ConfConstants.SUPPORT_MON_STATISTIC);
if ("yes".equalsIgnoreCase(supportMonStatistic)) {
serverInfo.setSupportMonitorStatistic(true);
} else {
serverInfo.setSupportMonitorStatistic(false);
}
}
if (serverInfo != null) {
serverInfo.setServerType(serverType);
}
} else if (task instanceof CommonQueryTask) {
@SuppressWarnings("unchecked") 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);
}
}
if (monitor.isCanceled() || !isContinue) {
disConnect();
return false;
}
}
return true;
}
Aggregations