use of com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode in project cubrid-manager by CUBRID.
the class SelectDbPage method createControl.
/**
* Create the control for this page
*
* @param parent Composite
*/
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 10;
layout.marginWidth = 10;
composite.setLayout(layout);
GridData gridData = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(gridData);
Group dbInfoGroup = new Group(composite, SWT.NONE);
dbInfoGroup.setText(Messages.grpSelectDb);
gridData = new GridData(GridData.FILL_HORIZONTAL);
dbInfoGroup.setLayoutData(gridData);
layout = new GridLayout();
layout.numColumns = 2;
dbInfoGroup.setLayout(layout);
Label dbNameLabel = new Label(dbInfoGroup, SWT.LEFT);
dbNameLabel.setText(Messages.lblDbName);
dbNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
dbNameCombo = new Combo(dbInfoGroup, SWT.LEFT | SWT.BORDER | SWT.READ_ONLY);
dbNameCombo.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, 100, -1));
dbNameCombo.addModifyListener(this);
Label nickNameLable = new Label(dbInfoGroup, SWT.LEFT);
nickNameLable.setText(Messages.lblNickName);
nickNameLable.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
nickNameText = new Text(dbInfoGroup, SWT.LEFT | SWT.BORDER);
nickNameText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
Label dbaPasswordLabel = new Label(dbInfoGroup, SWT.LEFT);
dbaPasswordLabel.setText(Messages.lblDbaPassword);
dbaPasswordLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
dbaPasswordText = new Text(dbInfoGroup, SWT.LEFT | SWT.BORDER | SWT.PASSWORD);
dbaPasswordText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, 100, -1));
Composite btnComposite = new Composite(composite, SWT.NONE);
RowLayout rowLayout = new RowLayout();
rowLayout.spacing = 5;
btnComposite.setLayout(rowLayout);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalAlignment = GridData.END;
btnComposite.setLayoutData(gridData);
addButton = new Button(btnComposite, SWT.NONE);
addButton.setText(Messages.btnAddDb);
addButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
String dbName = dbNameCombo.getText();
String dbaPassword = dbaPasswordText.getText();
String nickName = nickNameText.getText();
if (nickName.trim().length() == 0) {
nickName = dbName;
}
//check whether this database already be added
if (isExist(dbName, hostNode)) {
CommonUITool.openErrorBox(Messages.bind(Messages.errDbExist, dbName));
return;
}
DatabaseInfo dbInfo = serverInfo.getLoginedUserInfo().getDatabaseInfo(dbName);
TaskExecutor executor = new CommonTaskExec(null);
VerifyDbUserPasswordTask verifyDbUserPasswordTask = null;
if (dbInfo.isLogined() && dbInfo.getAuthLoginedDbUserInfo().getName().equalsIgnoreCase("dba")) {
String password = dbInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
if (!dbaPassword.equals(password)) {
CommonUITool.openErrorBox(Messages.errDbaPassowrd);
return;
}
} else {
verifyDbUserPasswordTask = new VerifyDbUserPasswordTask(serverInfo);
verifyDbUserPasswordTask.setDbName(dbName);
verifyDbUserPasswordTask.setDbUser("dba");
verifyDbUserPasswordTask.setDbPassword(dbaPassword);
executor.addTask(verifyDbUserPasswordTask);
}
GetHeartbeatNodeInfoTask getHeartbeatNodeInfoTask = new GetHeartbeatNodeInfoTask(serverInfo);
getHeartbeatNodeInfoTask.setAllDb(false);
List<String> dbList = new ArrayList<String>();
dbList.add(dbName);
getHeartbeatNodeInfoTask.setDbList(dbList);
executor.addTask(getHeartbeatNodeInfoTask);
new ExecTaskWithProgress(executor).exec(true, true);
if (!executor.isSuccess()) {
if (verifyDbUserPasswordTask != null && !verifyDbUserPasswordTask.isSuccess()) {
dbaPasswordText.selectAll();
dbaPasswordText.setFocus();
}
return;
}
List<HAHostStatusInfo> haHostStatusInfoList = getHeartbeatNodeInfoTask.getHAHostStatusList();
HADatabaseStatusInfo haDbStatusInfo = getHeartbeatNodeInfoTask.getDatabaseStatusInfo(dbName);
HAHostStatusInfo haHostStatusInfo = getHeartbeatNodeInfoTask.getHostStatusInfo(serverInfo.getHostAddress());
//if this database is HA Mode,will get it's active database or standby database
List<DatabaseNode> haDbNodeList = getHADatabaseList(haDbStatusInfo, haHostStatusInfoList, true);
if (haHostStatusInfo == null) {
haHostStatusInfo = HAUtil.getHAHostStatusInfo(serverInfo);
if (haDbStatusInfo != null) {
haHostStatusInfo.addHADatabaseStatus(haDbStatusInfo);
}
}
if (haDbStatusInfo == null) {
haDbStatusInfo = HAUtil.getHADatabaseStatusInfo(dbName, haHostStatusInfo, serverInfo);
}
DatabaseNode dbNode = new DatabaseNode();
hostNode.setHostStatusInfo(haHostStatusInfo);
dbNode.setParent(hostNode);
dbNode.setDbName(dbName);
dbNode.setDbUser("dba");
dbNode.setDbPassword(dbaPassword);
dbNode.setName(nickName);
dbNode.setHaDatabaseStatus(haDbStatusInfo);
dbNode.setConnected(true);
if (haDbNodeList == null) {
haDbNodeList = new ArrayList<DatabaseNode>();
}
if (dbNode.getDbStatusType() == DBStatusType.ACTIVE || dbNode.getDbStatusType() == DBStatusType.TO_BE_ACTIVE) {
haDbNodeList.add(0, dbNode);
} else {
haDbNodeList.add(dbNode);
}
addDbNodeToTable(haDbNodeList, haHostStatusInfoList);
}
});
haModeBtn = new Button(dbInfoGroup, SWT.LEFT | SWT.CHECK);
haModeBtn.setText(Messages.btnHAMode);
haModeBtn.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, 100, -1));
haModeBtn.setEnabled(false);
createTable(composite);
dbNameCombo.setFocus();
setTitle(Messages.titleSelectDbPage);
setMessage(Messages.msgSelectDbPage);
setControl(composite);
}
use of com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode in project cubrid-manager by CUBRID.
the class DbDashboardHistoryAction method run.
/**
* Open monitor host detail windows.
*/
public void run() {
if (getSelectedObj() == null || getSelectedObj().length == 0) {
return;
}
Object obj = getSelectedObj()[0];
if (!(obj instanceof DatabaseMonitorPart)) {
return;
}
DatabaseMonitorPart part = (DatabaseMonitorPart) obj;
DatabaseNode dn = (DatabaseNode) part.getModel();
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
IWorkbenchPage page = window.getActivePage();
if (page == null) {
return;
}
HostNode hn = dn.getParent();
String secondaryId = new StringBuffer(dn.getDbName()).append("&").append(hn.getUserName()).append("&").append(hn.getIp()).append("&").append(hn.getPort()).toString();
IViewReference viewReference = page.findViewReference(DbDashboardHistoryViewPart.ID, secondaryId);
if (viewReference == null) {
try {
IViewPart viewPart = page.showView(DbDashboardHistoryViewPart.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
((DbDashboardHistoryViewPart) viewPart).init((DatabaseNode) part.getModel());
} catch (PartInitException ex) {
viewReference = null;
}
} else {
IViewPart viewPart = viewReference.getView(false);
window.getActivePage().bringToTop(viewPart);
((DbDashboardHistoryViewPart) viewPart).init((DatabaseNode) part.getModel());
}
}
use of com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode in project cubrid-manager by CUBRID.
the class MonitorDetailAction method isSupported.
/**
*
*
* @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java.lang.Object)
* @param obj Object
* @return is supported.
*/
public boolean isSupported(Object obj) {
HostNode hostNode = null;
if (obj instanceof HostMonitorPart) {
hostNode = (HostNode) ((HostMonitorPart) obj).getModel();
} else if (obj instanceof BrokerMonitorPart) {
BrokerNode brokerNode = (BrokerNode) ((BrokerMonitorPart) obj).getModel();
hostNode = brokerNode.getParent();
}
if (hostNode != null) {
return hostNode.isConnected();
}
if (obj instanceof DatabaseMonitorPart) {
DatabaseNode dbNode = (DatabaseNode) ((DatabaseMonitorPart) obj).getModel();
hostNode = dbNode.getParent();
return hostNode.isConnected() && dbNode.isConnected();
}
return false;
}
use of com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode in project cubrid-manager by CUBRID.
the class DataGeneratorPool method isHasConnection.
/**
*
* Return whether has connection
*
* @param ip String
* @param port String
* @param userName String
* @return boolean
*/
public boolean isHasConnection(String ip, String port, String userName) {
Iterator<DataGenerator> it = map.values().iterator();
while (it.hasNext()) {
DataGenerator generator = it.next();
List<DataUpdateListener> listenerList = generator.getListeners();
for (DataUpdateListener listener : listenerList) {
HostNode hostNode = null;
if (listener.getModel() instanceof HostNode) {
hostNode = (HostNode) listener.getModel();
} else if (listener.getModel() instanceof DatabaseNode) {
hostNode = ((DatabaseNode) listener.getModel()).getParent();
} else if (listener.getModel() instanceof BrokerNode) {
hostNode = ((BrokerNode) listener.getModel()).getParent();
}
if (hostNode != null && hostNode.isConnected() && ip.equals(hostNode.getIp()) && port.equals(hostNode.getPort()) && userName.equals(hostNode.getUserName())) {
return true;
}
}
}
return false;
}
use of com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode in project cubrid-manager by CUBRID.
the class DataProvider method getUpdateValue.
/**
* Get the newest update data
*
* @return DataChangedEvent
*/
public DataChangedEvent getUpdateValue() {
setDefaultValue();
DataChangedEvent dataChangedEvent = new DataChangedEvent(this);
Set<MondashDataResult> resultSet = new HashSet<MondashDataResult>();
try {
executeInThread();
} catch (InterruptedException e) {
LOGGER.error("", e);
}
// handle with the data
//get host status
Map<IDiagPara, String> hostMap = new HashMap<IDiagPara, String>();
if (isExecuteHostStatTask) {
performHostStatTask(hostMap);
}
//get broker status
if (isExecuteBrokerStatTask) {
performBrokerDiagTask(hostMap);
}
if (isExecuteHostStatTask || isExecuteBrokerStatTask) {
MondashDataResult hostResult = new MondashDataResult();
hostResult.setName(generator.getName());
hostResult.putUpdateMap(hostMap);
resultSet.add(hostResult);
}
//get HA node status
List<HAHostStatusInfo> haHostStatusInfoList = null;
if (isExecuteHeartbeatTask) {
performHeartbeatNodeInfoTask();
haHostStatusInfoList = getHeartbeatNodeInfoTask == null ? null : getHeartbeatNodeInfoTask.getHAHostStatusList();
}
//get database status
List<HADatabaseStatusInfo> dbStatusInfoList = null;
String dbStatusErrorInfo = null;
if (isExecuteDbModeTask) {
dbStatusErrorInfo = getDbModeTask.getErrorMsg();
if (dbStatusErrorInfo != null && dbStatusErrorInfo.trim().length() > 0) {
dbStatusErrorInfo += ", can not get database status.";
}
dbStatusInfoList = getDbModeTask.getDbModes();
}
//get some broker status
DataChangedEvent event = brokerDataProvider == null ? null : brokerDataProvider.getUpdateValue();
for (int i = 0; i < uniqueBrokerNodeList.size(); i++) {
BrokerNode brokerNode = uniqueBrokerNodeList.get(i);
if (event != null) {
String brokerName = brokerNode.getBrokerName();
dataChangedEvent.getBrokerInfosMap().put(brokerName, event.getBrokerInfosMap().get(brokerName));
dataChangedEvent.getBrokerStatusInfosMap().put(brokerName, event.getBrokerStatusInfosMap().get(brokerName));
dataChangedEvent.getBrokerDiagDataMap().put(brokerName, event.getBrokerDiagDataMap().get(brokerName));
}
}
//get some databases status
for (int i = 0; i < dbDataProviderList.size(); i++) {
Set<MondashDataResult> dbResultSet = dbDataProviderList.get(i).getUpdateValue().getResultSet();
if (dbResultSet != null) {
resultSet.addAll(dbResultSet);
}
//set error
DatabaseNode dbNode = dbDataProviderList.get(i).getDatabaseNode();
if (StringUtil.isNotEmpty(dbStatusErrorInfo) && dbNode.getParent().isConnected()) {
dbNode.setErrorMsg(dbStatusErrorInfo);
}
HADatabaseStatusInfo dbStatusInfo = HAUtil.getDatabaseStatusInfo(dbStatusInfoList, dbNode.getDbName());
String errorInfo = dbStatusInfo == null ? null : dbStatusInfo.getErrorInfo();
if (StringUtil.isNotEmpty(errorInfo) && dbNode.getParent().isConnected()) {
dbNode.setErrorMsg(errorInfo);
}
}
if (requestCount < 2) {
requestCount++;
}
dataChangedEvent.setResultSet(resultSet);
dataChangedEvent.setHaHostStatusInfoList(haHostStatusInfoList);
dataChangedEvent.setDbStatusInfoList(dbStatusInfoList);
setErrorMsg(errorMsg);
if (errorMsg != null && errorMsg.trim().length() > 0) {
LOGGER.error(errorMsg);
}
return dataChangedEvent;
}
Aggregations