use of com.cubrid.cubridmanager.core.replication.model.ReplicationInfo in project cubrid-manager by CUBRID.
the class GetReplicationInfoTask method getReplicationInfo.
/**
*
* Get replication information
*
* @return the ReplicationInfo obj
*/
public ReplicationInfo getReplicationInfo() {
TreeNode response = getResponse();
if (response == null || (this.getErrorMsg() != null && getErrorMsg().trim().length() > 0)) {
return null;
}
ReplicationInfo replInfo = new ReplicationInfo();
DistributorInfo distInfo = new DistributorInfo();
String agentPort = response.getValue("agent_port");
String copyLogPath = response.getValue("copy_log_path");
String trailLogPath = response.getValue("trail_log_path");
String errorLogPath = response.getValue("error_log_path");
String delayTimeLogSize = response.getValue("delay_time_log_size");
String retryConnect = response.getValue("retry_connect");
distInfo.setDistDbName(distDbName);
distInfo.setAgentPort(agentPort);
distInfo.setCopyLogPath(copyLogPath);
distInfo.setTrailLogPath(trailLogPath);
distInfo.setErrorLogPath(errorLogPath);
distInfo.setDelayTimeLogSize(delayTimeLogSize);
distInfo.setRestartReplWhenError(retryConnect.equalsIgnoreCase("Y"));
replInfo.setDistInfo(distInfo);
MasterInfo masterInfo = new MasterInfo();
String masterDbName = response.getValue("master_db_name");
String masterIP = response.getValue("master_ip");
String replServerPort = response.getValue("repl_server_port");
masterInfo.setMasterDbName(masterDbName);
masterInfo.setMasterIp(masterIP);
masterInfo.setReplServerPort(replServerPort);
replInfo.addMasterInfo(masterInfo);
SlaveInfo slaveInfo = new SlaveInfo();
String slaveName = response.getValue("slave_db_name");
String slaveIP = response.getValue("slave_ip");
String userId = response.getValue("slave_userid");
String password = response.getValue("slave_pass");
slaveInfo.setSlaveDbName(slaveName);
slaveInfo.setSlaveIP(slaveIP);
slaveInfo.setDbUser(userId);
slaveInfo.setPassword(password);
replInfo.addSlaveInfo(slaveInfo);
return replInfo;
}
use of com.cubrid.cubridmanager.core.replication.model.ReplicationInfo in project cubrid-manager by CUBRID.
the class StopSlaveDbAction method run.
/**
* Stop database and refresh navigator
*/
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
final ISchemaNode schemaNode = (ISchemaNode) obj[0];
ReplicationInfo replInfo = (ReplicationInfo) schemaNode.getAdapter(ReplicationInfo.class);
Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
for (int j = 0; j < replInfo.getSlaveList().size(); j++) {
CubridDatabase database = StartSlaveDbAction.getDatabaseByName(schemaNode.getParent(), replInfo.getSlaveList().get(j).getSlaveDbName());
databaseSet.add(database);
}
StringBuffer dbNamesBuffer = new StringBuffer("");
Iterator<SlaveInfo> it = replInfo.getSlaveList().iterator();
while (it.hasNext()) {
dbNamesBuffer.append(it.next().getSlaveDbName()).append(",");
}
String dbNames = dbNamesBuffer.toString().substring(0, dbNamesBuffer.toString().length() - 1);
boolean isStop = CommonUITool.openConfirmBox(getShell(), Messages.bind(Messages.msgConfirmStopDatabase, dbNames));
if (!isStop) {
return;
}
final Object[] dbObjectArr = new Object[databaseSet.size()];
databaseSet.toArray(dbObjectArr);
ISelectionProvider provider = getSelectionProvider();
final Shell shell = getShell();
if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
final TreeViewer viewer = (TreeViewer) provider;
TaskExecutor taskExcutor = new TaskExecutor() {
public boolean exec(final IProgressMonitor monitor) {
Display display = Display.getDefault();
if (monitor.isCanceled()) {
return false;
}
for (int i = 0; i < taskList.size(); i++) {
ISchemaNode node = (ISchemaNode) dbObjectArr[i];
final CubridDatabase database = node.getDatabase();
ITask task = taskList.get(i);
task.execute();
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
database.removeAllChild();
if (database.getLoader() != null) {
database.getLoader().setLoaded(false);
}
database.setRunningType(DbRunningType.STANDALONE);
display.syncExec(new Runnable() {
public void run() {
viewer.refresh(database, true);
}
});
if (monitor.isCanceled()) {
return false;
}
}
return true;
}
};
for (int i = 0; i < dbObjectArr.length; i++) {
ISchemaNode node = (ISchemaNode) dbObjectArr[i];
CubridDatabase database = node.getDatabase();
CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.STOP_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
task.setDbName(database.getLabel());
taskExcutor.addTask(task);
}
new ExecTaskWithProgress(taskExcutor).exec();
if (taskExcutor.isSuccess()) {
for (int i = 0; i < dbObjectArr.length; i++) {
CubridDatabase database = (CubridDatabase) dbObjectArr[i];
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_STOP));
}
ActionManager.getInstance().fireSelectionChanged(getSelection());
}
}
}
use of com.cubrid.cubridmanager.core.replication.model.ReplicationInfo in project cubrid-manager by CUBRID.
the class StopSlaveDbAction method isSupportedNode.
/**
* @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java
* .lang.Object)
* @param obj Object
* @return boolean(whether to support)
*/
public static boolean isSupportedNode(Object obj) {
if (obj instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) obj;
if (!database.isLogined()) {
return false;
}
ServerUserInfo serverUserInfo = database.getServer().getServerInfo().getLoginedUserInfo();
if (serverUserInfo == null || !serverUserInfo.isAdmin()) {
return false;
}
if (!database.isDistributorDb()) {
return false;
}
ReplicationInfo replInfo = (ReplicationInfo) database.getAdapter(ReplicationInfo.class);
boolean isSupported = false;
if (replInfo != null && replInfo.getSlaveList() != null) {
for (int i = 0; i < replInfo.getSlaveList().size(); i++) {
DatabaseInfo dbInfo = serverUserInfo.getDatabaseInfo(replInfo.getSlaveList().get(i).getSlaveDbName());
if (dbInfo == null || dbInfo.getRunningType() == DbRunningType.STANDALONE) {
isSupported = false;
break;
} else {
isSupported = true;
}
}
}
return isSupported;
}
return false;
}
use of com.cubrid.cubridmanager.core.replication.model.ReplicationInfo in project cubrid-manager by CUBRID.
the class ReplicationEditor method createDiagram.
/**
* create the diagram
*
* @param input IEditorInput
*/
private void createDiagram(IEditorInput input) {
diagram = new Diagram();
if (input instanceof ICubridNode) {
ICubridNode node = (ICubridNode) input;
if (NodeType.DATABASE.equals(node.getType())) {
isEditable = false;
CubridServer server = node.getServer();
int x = 100;
int y = 20;
int hostVertSpan = 100;
if (server != null) {
ReplicationInfo replicationInfo = (ReplicationInfo) node.getAdapter(ReplicationInfo.class);
if (replicationInfo != null) {
//distributor component
DistributorInfo distInfo = replicationInfo.getDistInfo();
DistributorNode dist = null;
if (distInfo != null) {
dist = new DistributorNode();
dist.setDbName(distInfo.getDistDbName());
dist.setDbPath(distInfo.getDistDbPath());
dist.setCopyLogPath(distInfo.getCopyLogPath());
dist.setErrorLogPath(distInfo.getErrorLogPath());
dist.setTrailLogPath(distInfo.getTrailLogPath());
dist.setReplAgentPort(distInfo.getAgentPort());
dist.setDelayTimeLogSize(distInfo.getDelayTimeLogSize());
dist.setRestartWhenError(distInfo.isRestartReplWhenError());
dist.setName(distInfo.getDistDbName());
dist.setLocation(new Point(30, 30));
dist.setSize(new Dimension(120, 40));
}
//master component
List<MasterInfo> masterList = replicationInfo.getMasterList();
MasterNode master = null;
for (int i = 0; masterList != null && i < masterList.size(); i++) {
MasterInfo masterInfo = masterList.get(i);
if (masterInfo != null) {
master = new MasterNode();
String ip = masterInfo.getMasterIp();
String masterDbName = masterInfo.getMasterDbName();
String replServerPort = masterInfo.getReplServerPort();
boolean isReplAll = masterInfo.isReplAllTable();
List<String> tableList = masterInfo.getReplTableList();
HostNode mdbHost = new HostNode();
mdbHost.setIp(ip);
mdbHost.setUserName("admin");
mdbHost.setName(ip);
mdbHost.setLocation(new Point(x, y));
y += mdbHost.getSize().height + hostVertSpan;
mdbHost.setParent(diagram);
diagram.addNode(mdbHost);
master.setDbName(masterDbName);
master.setReplServerPort(replServerPort);
master.setReplicateAll(isReplAll);
master.setReplicatedClassList(tableList);
master.setName(masterDbName);
master.setLocation(new Point(30, 80));
master.setSize(new Dimension(120, 40));
master.setParent(mdbHost);
mdbHost.addChildNode(master);
}
}
//distributor host component
HostNode distdbhost = new HostNode();
distdbhost.setIp(server.getHostAddress());
distdbhost.setPort(server.getMonPort());
distdbhost.setUserName(server.getUserName());
distdbhost.setPassword(server.getPassword());
distdbhost.setName(server.getHostAddress() + ":" + server.getMonPort());
distdbhost.setLocation(new Point(x, y));
distdbhost.setParent(diagram);
diagram.addNode(distdbhost);
//distributor component
if (dist != null) {
dist.setParent(distdbhost);
distdbhost.addChildNode(dist);
}
//slave component
List<SlaveInfo> slaveInfoList = replicationInfo.getSlaveList();
SlaveNode slave = null;
for (int i = 0; slaveInfoList != null && i < slaveInfoList.size(); i++) {
SlaveInfo slaveInfo = slaveInfoList.get(i);
if (slaveInfo != null) {
slave = new SlaveNode();
slave.setDbName(slaveInfo.getSlaveDbName());
slave.setDbPath(slaveInfo.getSlaveDbPath());
slave.setDbUser(slaveInfo.getDbUser());
slave.setDbPassword(slaveInfo.getPassword());
ReplicationParamInfo replParaInfo = slaveInfo.getParamInfo();
if (replParaInfo != null) {
slave.setParamMap(replParaInfo.getParamMap());
}
slave.setName(slaveInfo.getSlaveDbName());
slave.setLocation(new Point(30, 150));
slave.setSize(new Dimension(120, 40));
slave.setParent(distdbhost);
distdbhost.addChildNode(slave);
}
}
}
}
}
}
}
use of com.cubrid.cubridmanager.core.replication.model.ReplicationInfo in project cubrid-manager by CUBRID.
the class StartReplicationAgentAction method isSupportedNode.
/**
* @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java
* .lang.Object)
* @param obj Object
* @return boolean(whether to support)
*/
public static boolean isSupportedNode(Object obj) {
if (obj instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) obj;
if (!database.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
return false;
}
ServerUserInfo serverUserInfo = database.getServer().getServerInfo().getLoginedUserInfo();
if (serverUserInfo == null || !serverUserInfo.isAdmin()) {
return false;
}
if (!database.isDistributorDb()) {
return false;
}
ReplicationInfo replInfo = (ReplicationInfo) database.getAdapter(ReplicationInfo.class);
for (int i = 0; replInfo != null && replInfo.getSlaveList() != null && i < replInfo.getSlaveList().size(); i++) {
DatabaseInfo dbInfo = serverUserInfo.getDatabaseInfo(replInfo.getSlaveList().get(i).getSlaveDbName());
if (dbInfo == null || dbInfo.getRunningType() == DbRunningType.STANDALONE) {
return false;
}
}
if (replInfo != null && replInfo.getDistInfo() != null) {
return !replInfo.getDistInfo().isAgentActive();
}
return false;
}
return false;
}
Aggregations