use of com.cubrid.cubridmanager.core.common.task.MonitoringTask 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.core.common.task.MonitoringTask 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.core.common.task.MonitoringTask in project cubrid-manager by CUBRID.
the class SetHostInfoDialog method connect.
/**
* connect the host
*
* @param buttonId int
*/
private void connect(final int buttonId) {
final String ip = ipText.getText();
final String port = portText.getText();
final String userName = userNameText.getText();
final String password = passwordText.getText();
boolean isConnected = ServerManager.getInstance().isConnected(ip, Integer.parseInt(port), userName);
if (isConnected && hostInfo != null) {
ServerInfo serverInfo = CMHostNodePersistManager.getInstance().getServerInfo(ip, Integer.parseInt(port), userName);
if (!serverInfo.getLoginedUserInfo().isAdmin()) {
CommonUITool.openErrorBox(Messages.bind(Messages.errInvalidUser, ip));
return;
}
hostInfo.setIp(ip);
hostInfo.setPort(port);
hostInfo.setUserName(userName);
hostInfo.setPassword(password);
hostInfo.setName(ip + ":" + port);
List<DatabaseInfo> databaseInfoList = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
hostInfo.setDatabaseInfoList(databaseInfoList);
hostInfo.setDbPath(serverInfo.getEnvInfo().getDatabaseDir());
hostInfo.setOsInfoType(serverInfo.getServerOsInfo());
setReturnCode(buttonId);
close();
return;
}
if (!isConnected) {
final ServerInfo serverInfo = new ServerInfo();
serverInfo.setHostAddress(ip);
serverInfo.setHostMonPort(Integer.parseInt(port));
serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
serverInfo.setUserName(userName);
serverInfo.setUserPassword(password);
TaskExecutor taskExcutor = new ConnectHostTaskExecutor(serverInfo, buttonId);
MonitoringTask monitoringTask = new MonitoringTask(serverInfo);
taskExcutor.addTask(monitoringTask);
GetEnvInfoTask getEnvInfoTask = new GetEnvInfoTask(serverInfo);
taskExcutor.addTask(getEnvInfoTask);
GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo);
taskExcutor.addTask(getCMConfParameterTask);
GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
taskExcutor.addTask(getDatabaseListTask);
new ExecTaskWithProgress(taskExcutor).exec(true, true);
}
}
use of com.cubrid.cubridmanager.core.common.task.MonitoringTask in project cubrid-manager by CUBRID.
the class SetupEnvTestCase method setupDatabaseInfo831.
/**
* * Setup database 8.3.1
*
*/
private void setupDatabaseInfo831() {
/*Setting Cubrid 8.3.1*/
serverInfo831 = new ServerInfo();
serverInfo831.setHostAddress(host831);
serverInfo831.setHostMonPort(monport831);
serverInfo831.setHostJSPort(jpport831);
serverInfo831.setUserName(userName831);
serverInfo831.setUserPassword(passwd831);
serverInfo831.setJdbcDriverVersion(serverVersion831);
ServerManager.getInstance().addServer(host831, monport831, userName831, serverInfo831);
MonitoringTask monTask = new MonitoringTask(serverInfo831);
serverInfo831 = monTask.connectServer(serverVersion831, 1000);
// get the latest token
token831 = serverInfo831.getHostToken();
//get evnInfo
if (envInfo831 == null) {
GetEnvInfoTask envTask = new GetEnvInfoTask(serverInfo831);
envTask.loadEnvInfo();
envTask.execute();
envInfo831 = envTask.loadEnvInfo();
serverInfo831.setEnvInfo(envInfo831);
}
assertNotNull(envInfo831);
serverPath831 = envInfo831.getRootDir();
dbRootDir831 = envInfo831.getDatabaseDir();
//get server type
GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo831);
getCMConfParameterTask.execute();
assertEquals(null, getCMConfParameterTask.getErrorMsg());
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 (serverInfo831 != null) {
serverInfo831.setServerType(serverType);
}
//Get database list task
if (serverType == ServerType.DATABASE || serverType == ServerType.BOTH) {
final GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo831);
getDatabaseListTask.execute();
assertEquals(null, getDatabaseListTask.getErrorMsg());
List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
for (DatabaseInfo dbInfo : databaseInfoList) {
if (dbInfo.getDbName().equals(testDbName831)) {
databaseInfo831 = dbInfo;
break;
}
}
if (databaseInfo831 == null) {
return;
}
}
//get CubridManager user list task
GetCMUserListTask getUserInfoTask = new GetCMUserListTask(serverInfo831);
getUserInfoTask.execute();
assertEquals(null, getUserInfoTask.getErrorMsg());
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(serverInfo831.getUserName())) {
serverInfo831.setLoginedUserInfo(userInfo);
break;
}
}
List<DatabaseInfo> databaseInfoList = serverInfo831.getLoginedUserInfo().getDatabaseInfoList();
String dbDir = databaseInfo831.getDbDir();
DbRunningType type = databaseInfo831.getRunningType();
for (int i = 0; databaseInfoList != null && i < databaseInfoList.size(); i++) {
if (testDbName831.equalsIgnoreCase(databaseInfoList.get(i).getDbName())) {
databaseInfo831 = databaseInfoList.get(i);
databaseInfo831.setDbDir(dbDir);
databaseInfo831.setBrokerIP(host831);
databaseInfo831.setBrokerPort(port831);
databaseInfo831.setCharSet(charset831);
databaseInfo831.setRunningType(type);
break;
}
}
//get CUBRID conf parameter
GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo831);
getCubridConfParameterTask.execute();
assertEquals(null, getCubridConfParameterTask.getErrorMsg());
Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
if (serverInfo831 != null) {
serverInfo831.setCubridConfParaMap(confParas);
}
//get broker Info
GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo831);
getBrokerConfParameterTask.execute();
assertEquals(null, getBrokerConfParameterTask.getErrorMsg());
confParas = getBrokerConfParameterTask.getConfParameters();
if (serverInfo831 != null) {
serverInfo831.setBrokerConfParaMap(confParas);
}
//Set JDBC driver
String filePath = this.getFilePathInPlugin("/lib/JDBC-8.3.0.1004-cubrid.jar");
if (filePath != null) {
String version = JdbcClassLoaderFactory.validateJdbcFile(filePath);
if (version != null) {
JdbcClassLoaderFactory.registerClassLoader(filePath);
serverInfo831.setJdbcDriverVersion(version);
}
}
filePath = this.getFilePathInPlugin("/lib/JDBC-8.3.1.0173-cubrid.jar");
if (filePath != null) {
String version = JdbcClassLoaderFactory.validateJdbcFile(filePath);
if (version != null) {
JdbcClassLoaderFactory.registerClassLoader(filePath);
serverInfo831.setJdbcDriverVersion(version);
}
}
}
use of com.cubrid.cubridmanager.core.common.task.MonitoringTask in project cubrid-manager by CUBRID.
the class DataProvider method setDefaultValue.
/**
*
* Set the default value
*
*/
private void setDefaultValue() {
boolean isOldExecuteHostStatTask = isExecuteHostStatTask;
isExecuteHostStatTask = false;
isExecuteHeartbeatTask = false;
isExecuteBrokerStatTask = false;
isExecuteDbModeTask = false;
errorMsg = "";
getHeartbeatNodeInfoTask = null;
hostNodeList.clear();
connectedHostNode = null;
uniqueDbNodeList.clear();
uniqueBrokerNodeList.clear();
List<DataUpdateListener> listenerList = generator.getListeners();
for (DataUpdateListener listener : listenerList) {
addHaNode(listener.getModel());
}
if (connectedHostNode == null && !hostNodeList.isEmpty()) {
connectedHostNode = hostNodeList.get(0);
}
if (connectedHostNode == null) {
return;
}
filterDatabaseDataProvider();
if (!uniqueBrokerNodeList.isEmpty()) {
brokerDataProvider.setDataGenerator(generator);
brokerDataProvider.setBrokerNodeList(uniqueBrokerNodeList);
}
//Connect host and set time out
if (!connectedHostNode.isConnected() && !connectedHostNode.isConnecting()) {
for (final HostNode hostNode : hostNodeList) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
hostNode.setConnected(false);
}
});
}
ConnectionManager.connectHost(connectedHostNode, true, !isFirstConnected);
}
final boolean isCanConnected = connectedHostNode.isConnected();
for (final HostNode hostNode : hostNodeList) {
if (hostNode != connectedHostNode) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
hostNode.setConnected(isCanConnected);
hostNode.setErrorMsg(connectedHostNode.getLastErrorMsg());
}
});
}
}
if (isCanConnected) {
isFirstConnected = true;
serverInfo = connectedHostNode.getServerInfo();
if (serverInfo != null) {
MonitoringTask monitoringTask = serverInfo.getMonitoringTask();
monitoringTask.setTimeout(DataProvider.TIME_OUT_MILL);
}
} else {
isFirstConnected = false;
}
for (DataUpdateListener listener : listenerList) {
if (listener instanceof HostMonitorPartHelper) {
isExecuteHostStatTask = isCanConnected;
isExecuteHeartbeatTask = isCanConnected;
} else if (listener instanceof DatabaseMonitorPartHelper) {
isExecuteHostStatTask = isCanConnected;
isExecuteHeartbeatTask = isCanConnected;
isExecuteDbModeTask = isCanConnected;
} else if (listener instanceof HostDashboardViewPart) {
isExecuteHostStatTask = isCanConnected;
isExecuteBrokerStatTask = isCanConnected;
} else if (listener instanceof DatabaseDashboardViewPart) {
isExecuteHostStatTask = isCanConnected;
isExecuteHeartbeatTask = isCanConnected;
isExecuteDbModeTask = isCanConnected;
}
}
ServerType serverType = serverInfo == null ? null : serverInfo.getServerType();
isExecuteBrokerStatTask = isExecuteBrokerStatTask && (serverType == ServerType.BOTH || serverType == ServerType.BROKER);
if (isOldExecuteHostStatTask != isExecuteHostStatTask) {
hostStatRequestCount = 0;
}
}
Aggregations