use of com.cubrid.cubridmanager.core.replication.task.GetReplAgentStatusTask in project cubrid-manager by CUBRID.
the class CreateReplicationUtil method createAgentTaskGroup.
/**
*
* Fill in the related tasks of agent to executor
*
* @param dist DistributorNode
* @param executor CreateReplicationJobExecutor
* @return null or error message
*/
public static String createAgentTaskGroup(DistributorNode dist, CreateReplicationJobExecutor executor) {
TaskGroup taskGroup = new TaskGroup(IConstants.REPL_GROUP_NAME_START_AGENT);
taskGroup.setTarget(dist.getDbName());
HostNode distdbHost = (HostNode) dist.getParent();
final String ip = distdbHost.getIp();
final String port = distdbHost.getPort();
final String userName = distdbHost.getUserName();
final String password = distdbHost.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);
}
GetReplAgentStatusTask getReplAgentStatusTask = new GetReplAgentStatusTask(serverInfo);
getReplAgentStatusTask.setDbName(dist.getDbName());
taskGroup.addTask(getReplAgentStatusTask);
StopReplicationAgentTask stopReplicationAgentTask = new StopReplicationAgentTask(serverInfo);
stopReplicationAgentTask.setDbName(dist.getDbName());
taskGroup.addTask(stopReplicationAgentTask);
StartReplicationAgentTask startReplicationAgentTask = new StartReplicationAgentTask(serverInfo);
startReplicationAgentTask.setDbName(dist.getDbName());
startReplicationAgentTask.setDbaPasswd(dist.getDbaPassword());
taskGroup.addTask(startReplicationAgentTask);
executor.addGroupTask(taskGroup);
return null;
}
use of com.cubrid.cubridmanager.core.replication.task.GetReplAgentStatusTask in project cubrid-manager by CUBRID.
the class CubridDatabaseLoader method loadReplication.
/**
*
* Load replication function
*
* @param parent the parent node
* @param monitor the monitor object
* @return <code>true</code> it can be loaded;<code>false</code> otherwise
*/
private boolean loadReplication(final ICubridNode parent, final IProgressMonitor monitor) {
CubridDatabase database = (CubridDatabase) parent;
ServerInfo serverInfo = parent.getServer().getServerInfo();
ServerUserInfo serverUserInfo = serverInfo.getLoginedUserInfo();
if (serverUserInfo == null || !serverUserInfo.isAdmin()) {
return true;
}
DbUserInfo dbUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
if (dbUserInfo == null || dbUserInfo.getName() == null || !dbUserInfo.getName().trim().equalsIgnoreCase("DBA")) {
return true;
}
String dbPassword = dbUserInfo.getNoEncryptPassword();
//add for replication support,only can be supported after version 8.2.2 and in linux OS
if (serverInfo.isSupportReplication() == 0) {
final CheckDistributorDbTask checkDistributorDbTask = new CheckDistributorDbTask(serverInfo);
checkDistributorDbTask.setDistDbName(database.getLabel());
checkDistributorDbTask.setDbaPassword(dbPassword);
checkDistributorDbTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
final GetReplicationInfoTask getReplicationInfoTask = new GetReplicationInfoTask(serverInfo);
getReplicationInfoTask.setDistDbName(database.getLabel());
getReplicationInfoTask.setDbaPassword(dbPassword);
getReplicationInfoTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
final GetReplicatedTablesTask getReplicatedTablesTask = new GetReplicatedTablesTask(serverInfo);
getReplicatedTablesTask.setDistdbName(database.getLabel());
getReplicatedTablesTask.setDistdbPassword(dbPassword);
getReplicatedTablesTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
final GetReplicationParamTask getReplicationParamTask = new GetReplicationParamTask(serverInfo);
getReplicationParamTask.setDistDbName(database.getLabel());
getReplicationParamTask.setDistDbDbaPasswd(dbPassword);
getReplicationParamTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
final GetReplAgentStatusTask getReplAgentStatusTask = new GetReplAgentStatusTask(serverInfo);
getReplAgentStatusTask.setDbName(database.getLabel());
monitorCancel(monitor, new ITask[] { checkDistributorDbTask, getReplicationInfoTask, getReplicatedTablesTask, getReplicationParamTask, getReplAgentStatusTask });
checkDistributorDbTask.execute();
if (!checkResult(checkDistributorDbTask, monitor)) {
return false;
}
boolean isDistdb = checkDistributorDbTask.isDistributorDb();
database.getDatabaseInfo().setDistributorDb(isDistdb);
if (isDistdb) {
getReplicationInfoTask.execute();
if (!checkResult(getReplicationInfoTask, monitor)) {
return false;
}
ReplicationInfo replInfo = getReplicationInfoTask.getReplicationInfo();
database.getDatabaseInfo().setReplInfo(replInfo);
if (replInfo != null && replInfo.getDistInfo() != null) {
replInfo.getDistInfo().setDistDbPath(database.getDatabaseInfo().getDbDir());
}
if (replInfo != null && replInfo.getMasterList() != null && replInfo.getMasterList().size() > 0 && replInfo.getSlaveList() != null && replInfo.getSlaveList().size() > 0) {
MasterInfo masterInfo = replInfo.getMasterList().get(0);
SlaveInfo slaveInfo = replInfo.getSlaveList().get(0);
getReplicatedTablesTask.setMasterdbName(masterInfo.getMasterDbName());
getReplicatedTablesTask.setSlavedbName(slaveInfo.getSlaveDbName());
getReplicatedTablesTask.execute();
if (!checkResult(getReplicatedTablesTask, monitor)) {
return false;
}
String[] classNames = getReplicatedTablesTask.getReplicatedTables();
boolean isReplAll = getReplicatedTablesTask.isReplicateAll();
if (classNames != null && classNames.length > 0) {
masterInfo.setReplTableList(Arrays.asList(classNames));
}
masterInfo.setReplAllTable(isReplAll);
getReplicationParamTask.setMasterDbName(masterInfo.getMasterDbName());
getReplicationParamTask.setSlaveDbName(replInfo.getSlaveList().get(0).getSlaveDbName());
getReplicationParamTask.execute();
if (!checkResult(getReplicationParamTask, monitor)) {
return false;
}
ReplicationParamInfo paramInfo = getReplicationParamTask.getReplicationParams();
slaveInfo.setParamInfo(paramInfo);
}
getReplAgentStatusTask.execute();
if (!checkResult(getReplAgentStatusTask, monitor)) {
return false;
}
boolean isActive = getReplAgentStatusTask.isActive();
replInfo.getDistInfo().setAgentActive(isActive);
}
}
return true;
}
use of com.cubrid.cubridmanager.core.replication.task.GetReplAgentStatusTask in project cubrid-manager by CUBRID.
the class DeleteDatabaseDialog method deleteDatabase.
/**
*
* Delete the database
*
* @return <code>true</code> if successful;<code>false</code> otherwise
*/
private boolean deleteDatabase() {
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
String taskName = Messages.bind(Messages.delDbTaskName, database.getName());
monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
boolean isActiveReplServer = false;
boolean isActiveReplAgent = false;
List<String> cubridConfContentList = null;
for (ITask task : taskList) {
if (task instanceof GetReplServerStatusTask) {
GetReplServerStatusTask getReplServerStatusTask = (GetReplServerStatusTask) task;
getReplServerStatusTask.execute();
isActiveReplServer = getReplServerStatusTask.isActive();
} else if (task instanceof StopReplServerTask) {
if (isActiveReplServer) {
task.execute();
}
} else if (task instanceof GetReplAgentStatusTask) {
GetReplAgentStatusTask getReplAgentStatusTask = (GetReplAgentStatusTask) task;
getReplAgentStatusTask.execute();
isActiveReplAgent = getReplAgentStatusTask.isActive();
} else if (task instanceof StopReplicationAgentTask) {
if (isActiveReplAgent) {
task.execute();
}
} else if (task instanceof SetCubridConfParameterTask) {
if (cubridConfContentList == null) {
continue;
} else {
SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
setParaTask.setConfContents(cubridConfContentList);
setParaTask.execute();
}
} else {
task.execute();
}
final String msg = task.getErrorMsg();
if (openErrorBox(getShell(), msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
if (task instanceof GetCubridConfParameterTask) {
GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
cubridConfContentList = CoreUtils.deleteDatabaseFromServiceServer(getCubridConfParameterTask, cubridConfContentList, database.getName());
}
}
return true;
}
};
ServerInfo serverInfo = database.getServer().getServerInfo();
//check the replication server and agent
if (serverInfo.isSupportReplication() == 0) {
if (database.isDistributorDb()) {
GetReplAgentStatusTask getReplAgentStatusTask = new GetReplAgentStatusTask(serverInfo);
getReplAgentStatusTask.setDbName(database.getLabel());
taskExcutor.addTask(getReplAgentStatusTask);
StopReplicationAgentTask stopReplAgentTask = new StopReplicationAgentTask(serverInfo);
stopReplAgentTask.setDbName(database.getLabel());
taskExcutor.addTask(stopReplAgentTask);
} else {
GetReplServerStatusTask getReplServerStatusTask = new GetReplServerStatusTask(serverInfo);
getReplServerStatusTask.setDbName(database.getLabel());
taskExcutor.addTask(getReplServerStatusTask);
StopReplServerTask stopReplServerTask = new StopReplServerTask(serverInfo);
stopReplServerTask.setDbName(database.getLabel());
taskExcutor.addTask(stopReplServerTask);
}
}
CommonUpdateTask deleteDbtask = new CommonUpdateTask(CommonTaskName.DELETE_DATABASE_TASK_NAME, serverInfo, CommonSendMsg.getDeletedbSendMsg());
deleteDbtask.setDbName(database.getName());
if (deleteBackupVolumesButton.getSelection()) {
deleteDbtask.setDelbackup(YesNoType.Y);
} else {
deleteDbtask.setDelbackup(YesNoType.N);
}
taskExcutor.addTask(deleteDbtask);
GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
taskExcutor.addTask(getCubridConfParameterTask);
SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(serverInfo);
taskExcutor.addTask(setCubridConfParameterTask);
new ExecTaskWithProgress(taskExcutor).exec(true, false);
if (taskExcutor.isSuccess()) {
setReturnCode(DELETE_ID);
close();
return true;
} else {
return false;
}
}
use of com.cubrid.cubridmanager.core.replication.task.GetReplAgentStatusTask in project cubrid-manager by CUBRID.
the class CreateReplicationJobExecutor method startAgent.
/**
* start agent service
*
* @param agentName String
* @param monitor IProgressMonitor
* @param taskList List<ITask>
* @return status
*/
private IStatus startAgent(String agentName, final IProgressMonitor monitor, List<ITask> taskList) {
monitor.subTask(Messages.bind(Messages.startAgentJobName, agentName));
MonitoringTask monitoringTask = null;
boolean isExecuteStopAgentTask = 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 StopReplicationAgentTask) {
if (isExecuteStopAgentTask) {
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 GetReplAgentStatusTask) {
GetReplAgentStatusTask getReplAgentStatusTask = (GetReplAgentStatusTask) task;
isExecuteStopAgentTask = getReplAgentStatusTask.isActive();
}
}
disConnect(monitoringTask);
return Status.OK_STATUS;
}
use of com.cubrid.cubridmanager.core.replication.task.GetReplAgentStatusTask in project cubrid-manager by CUBRID.
the class ChangeSlaveDbWizard method createSlaveTaskGroup.
/**
* create slave database task group
*
* @param executor CreateReplicationSlaveDbJobExecutor
* @return boolean
*/
public boolean createSlaveTaskGroup(CreateReplicationSlaveDbJobExecutor executor) {
TaskGroup taskGroup = new TaskGroup(REPL_GROUP_NAME_CREATE_SLAVE);
taskGroup.setTarget(slaveDbInfoPage.getSlaveDbName());
CreateReplicationUtil.addCheckDbTaskGroup(database.getServer().getServerInfo(), slaveDbInfoPage.getSlaveDbName(), taskGroup);
GetReplAgentStatusTask getReplAgentStatusTask = new GetReplAgentStatusTask(database.getServer().getServerInfo());
getReplAgentStatusTask.setDbName(database.getLabel());
taskGroup.addTask(getReplAgentStatusTask);
StopReplicationAgentTask stopReplicationAgentTask = new StopReplicationAgentTask(database.getServer().getServerInfo());
stopReplicationAgentTask.setDbName(database.getLabel());
taskGroup.addTask(stopReplicationAgentTask);
CreateSlaveDbTask createSlaveDbTask = new CreateSlaveDbTask(database.getServer().getServerInfo());
createSlaveDbTask.setSlaveDbName(slaveDbInfoPage.getSlaveDbName());
createSlaveDbTask.setSlaveDbPath(slaveDbInfoPage.getSlaveDbPath());
createSlaveDbTask.setSlaveDbUser(slaveDbInfoPage.getSlaveDbUser());
createSlaveDbTask.setSlaveDbPassword(slaveDbInfoPage.getSlaveDbaPassword());
createSlaveDbTask.setMasterDbName(slaveDbInfoPage.getMasterDbName());
createSlaveDbTask.setMasterDbPassword(slaveDbInfoPage.getMasterDbDbaPassword());
createSlaveDbTask.setDistDbName(database.getLabel());
createSlaveDbTask.setDistDbaPassword(database.getPassword());
taskGroup.addTask(createSlaveDbTask);
SetReplicationParamTask setReplicationParamTask = new SetReplicationParamTask(database.getServer().getServerInfo());
setReplicationParamTask.setMasterDbName(slaveDbInfoPage.getMasterDbName());
setReplicationParamTask.setSlaveDbName(slaveDbInfoPage.getSlaveDbName());
setReplicationParamTask.setDistDbName(database.getLabel());
setReplicationParamTask.setDistDbDbaPasswd(database.getPassword());
setReplicationParamTask.setParameterMap(setReplicationParamPage.getParamMap());
setReplicationParamTask.setRunningMode(true);
taskGroup.addTask(setReplicationParamTask);
ChangeReplTablesTask changeReplTablesTask = new ChangeReplTablesTask(database.getServer().getServerInfo());
changeReplTablesTask.setDistdbName(database.getLabel());
changeReplTablesTask.setDistdbPassword(database.getPassword());
changeReplTablesTask.setMdbName(slaveDbInfoPage.getMasterDbName());
changeReplTablesTask.setMdbUserId("dba");
changeReplTablesTask.setMdbPass(slaveDbInfoPage.getMasterDbDbaPassword());
if (selectTablesPage.isReplAllTables()) {
changeReplTablesTask.setReplAllClasses(selectTablesPage.isReplAllTables());
} else if (selectTablesPage.getReplTableList() != null && selectTablesPage.getReplTableList().size() > 0) {
changeReplTablesTask.setReplicatedClasses(selectTablesPage.getReplTableList());
} else {
changeReplTablesTask.setReplNoneClasses(true);
}
taskGroup.addTask(changeReplTablesTask);
executor.addGroupTask(taskGroup);
return true;
}
Aggregations