use of com.cubrid.cubridmanager.core.replication.task.StartReplServerTask in project cubrid-manager by CUBRID.
the class ReplServerDialog method execute.
/**
* excute the task.
*
* @param buttonId int
*/
private void execute(final int buttonId) {
final String ip = ipText.getText();
final String port = portText.getText();
final String userName = userNameText.getText();
final String password = passwordText.getText();
final String mdbName = mdbNameText.getText();
final String replServerPort = replServerPortText.getText();
TaskExecutor taskExcutor = new TaskExecutor() {
public void disConnect() {
ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
}
public boolean exec(final IProgressMonitor monitor) {
Display display = Display.getDefault();
if (monitor.isCanceled()) {
return false;
}
boolean isConnected = false;
MonitorDashboardPreference monPref = new MonitorDashboardPreference();
for (ITask task : taskList) {
if (task instanceof MonitoringTask) {
MonitoringTask monitoringTask = (MonitoringTask) task;
monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
isConnected = true;
} else if (task instanceof GetReplServerStatusTask) {
GetReplServerStatusTask getReplServerStatusTask = (GetReplServerStatusTask) task;
getReplServerStatusTask.execute();
isActive = getReplServerStatusTask.isActive();
} else if (task instanceof StartReplServerTask) {
if (isActive) {
openErrorBox(getShell(), Messages.msgReplServerStarted, monitor);
} else {
StartReplServerTask startReplServerTask = (StartReplServerTask) task;
startReplServerTask.execute();
if (task.isSuccess()) {
openInformationgBox(getShell(), com.cubrid.cubridmanager.ui.common.Messages.titleSuccess, Messages.msgReplServerStartedSuccess, monitor);
}
}
} else if (task instanceof StopReplServerTask) {
if (isActive) {
StopReplServerTask stopReplServerTask = (StopReplServerTask) task;
stopReplServerTask.execute();
if (task.isSuccess()) {
openInformationgBox(getShell(), com.cubrid.cubridmanager.ui.common.Messages.titleSuccess, Messages.msgReplServerStopedSuccess, monitor);
}
} else {
openErrorBox(getShell(), Messages.msgReplServerStoped, monitor);
}
}
if (monitor.isCanceled()) {
if (isConnected) {
disConnect();
}
return false;
}
final String msg = task.getErrorMsg();
if (openErrorBox(getShell(), msg, monitor)) {
if (isConnected) {
ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
}
return false;
}
}
if (isConnected) {
disConnect();
}
if (!monitor.isCanceled()) {
display.syncExec(new Runnable() {
public void run() {
setReturnCode(buttonId);
close();
}
});
}
return true;
}
};
boolean isConnected = ServerManager.getInstance().isConnected(ip, Integer.parseInt(port), userName);
ServerInfo serverInfo = new ServerInfo();
if (isConnected) {
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(userName);
serverInfo.setUserPassword(password);
CMHostNodePersistManager.getInstance().addServer(ip, Integer.parseInt(port), userName, serverInfo);
MonitoringTask monitoringTask = new MonitoringTask(serverInfo);
taskExcutor.addTask(monitoringTask);
}
GetReplServerStatusTask getReplServerStatusTask = new GetReplServerStatusTask(serverInfo);
getReplServerStatusTask.setDbName(mdbName);
taskExcutor.addTask(getReplServerStatusTask);
if (isStartReplServer) {
StartReplServerTask task = new StartReplServerTask(serverInfo);
task.setDbName(mdbName);
task.setServerPort(replServerPort);
taskExcutor.addTask(task);
} else {
StopReplServerTask task = new StopReplServerTask(serverInfo);
task.setDbName(mdbName);
taskExcutor.addTask(task);
}
new ExecTaskWithProgress(taskExcutor).exec();
}
use of com.cubrid.cubridmanager.core.replication.task.StartReplServerTask in project cubrid-manager by CUBRID.
the class CreateReplicationUtil method createReplServerTaskGroup.
/**
*
* Fill in the related tasks of replication server to executor
*
* @param master MasterNode
* @param executor CreateReplicationJobExecutor
* @return null or error message
*/
public static String createReplServerTaskGroup(MasterNode master, CreateReplicationJobExecutor executor) {
TaskGroup taskGroup = new TaskGroup(IConstants.REPL_GROUP_NAME_START_REPL_SERVER);
taskGroup.setTarget(master.getDbName());
HostNode masterHost = (HostNode) master.getParent();
final String ip = masterHost.getIp();
final String port = masterHost.getPort();
final String userName = masterHost.getUserName();
final String password = masterHost.getPassword();
boolean isConnected = ServerManager.getInstance().isConnected(ip, Integer.parseInt(port), userName);
ServerInfo serverInfo = new ServerInfo();
if (isConnected) {
serverInfo = ServerManager.getInstance().getServer(ip, Integer.parseInt(port), userName);
if (!serverInfo.getLoginedUserInfo().isAdmin()) {
return Messages.bind(Messages.errInvalidUser, ip);
}
} else {
serverInfo.setHostAddress(ip);
serverInfo.setHostMonPort(Integer.parseInt(port));
serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
serverInfo.setUserName(userName);
serverInfo.setUserPassword(password);
MonitoringTask monitoringTask = new MonitoringTask(serverInfo);
taskGroup.addTask(monitoringTask);
}
StartReplServerTask startReplServerTask = new StartReplServerTask(serverInfo);
startReplServerTask.setDbName(master.getDbName());
startReplServerTask.setServerPort(master.getReplServerPort());
taskGroup.addTask(startReplServerTask);
executor.addGroupTask(taskGroup);
return null;
}
Aggregations