use of com.cubrid.cubridmanager.core.shard.model.Shards in project cubrid-manager by CUBRID.
the class HaShardDemo method registerServiceAndBuildInfo.
/**
* For HA, right now, we cannot get the host name from CMS, so need
* specified by user.
*
* @param ip
* @param port
* @param userName
* @param password
* @param serviceName
* @param connectName
* @param nodeName Node name that registered in /etc/hosts.
* @return
*/
public void registerServiceAndBuildInfo(String ip, int port, String userName, String password, String serviceName, String connectName, String nodeName) {
HaShardManager haShardManager = HaShardManager.getInstance();
//build server info
ServerInfo serverInfo = ServerManager.getInstance().getServer(ip, port, userName);
if (serverInfo == null) {
serverInfo = new ServerInfo();
serverInfo.setHostAddress(ip);
serverInfo.setHostMonPort(port);
serverInfo.setHostJSPort(port + 1);
serverInfo.setUserName(userName);
}
serverInfo.setServerName(connectName);
serverInfo.setUserPassword(password);
serverInfo.setJdbcDriverVersion("Auto Detect");
// connect to server
addServer(serverInfo);
MonitoringTask monitoringTask = serverInfo.getMonitoringTask();
String clientVersion = "9.3.0";
serverInfo = monitoringTask.connectServer(clientVersion, 1000);
if (serverInfo.isConnected()) {
addServer(serverInfo);
GetDatabasesParameterTask getDatabasesParameterTask = new GetDatabasesParameterTask(serverInfo);
getDatabasesParameterTask.execute();
if (!getDatabasesParameterTask.isSuccess()) {
return;
}
List<Map<String, String>> dbParamMapList = getDatabasesParameterTask.getConfParameters();
List<DbLocationInfo> dbLocationInfoList = new ArrayList<DbLocationInfo>();
CMServiceAnalysisUtil.addDbLocaltionInfos(dbParamMapList, dbLocationInfoList);
// get required info from server and build NodeInfo
NodeInfo info = getRequiredInfo(serverInfo, dbLocationInfoList);
if (info != null) {
info.setDbLocationInfoList(dbLocationInfoList);
info.setServiceName(serviceName);
info.setCmConnectName(connectName);
info.setIp(ip);
info.setHostName(nodeName);
info.setServerInfo(serverInfo);
if (info instanceof ShardNode) {
Shards shards = ((ShardNode) info).getShards();
Shard shard = shards.getShardList().get(0);
List<String> connections = shard.getShardConnectionFile().getConnections();
for (String s : connections) {
String[] ar = s.split(",");
if (ip.equals(ar[2]) || nodeName.equals(ar[2])) {
//???
((ShardNode) info).setSeverStatus("Shard #" + ar[0]);
//???
((ShardNode) info).genStatus();
}
}
}
haShardManager.add(info);
}
} else {
removeServer(serverInfo);
}
}
use of com.cubrid.cubridmanager.core.shard.model.Shards in project cubrid-manager by CUBRID.
the class HaShardDemo method getShardNodeIndo92.
protected NodeInfo getShardNodeIndo92(ServerInfo serverInfo) {
ShardNode info = null;
GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo);
getBrokerConfParameterTask.execute();
if (!getBrokerConfParameterTask.isSuccess()) {
return null;
}
Shards shards = new Shards();
Map<String, Map<String, String>> confParams = getBrokerConfParameterTask.getConfParameters();
List<Map<String, String>> shardParamsList = new ArrayList<Map<String, String>>();
for (Entry<String, Map<String, String>> entry : confParams.entrySet()) {
String brokerName = entry.getKey();
Map<String, String> params = entry.getValue();
if (StringUtils.equalsIgnoreCase(params.get("SHARD"), "ON")) {
shardParamsList.add(params);
Shard shard = new Shard();
shard.setName(brokerName.toLowerCase(Locale.getDefault()));
shard.setProperties(params);
ShardConnection shardConnection = new ShardConnection();
shard.setShardConnectionFile(shardConnection);
GetShardConfTask<ShardConnection> getShardConnectionConfTask = new GetShardConfTask<ShardConnection>(serverInfo, shardConnection);
getShardConnectionConfTask.execute();
getShardConnectionConfTask.loadDataToModel();
shard.setShardConnectionFile(shardConnection);
shards.addShard(shard);
}
}
if (shardParamsList.size() == 0) {
return null;
}
info = new ShardNode();
for (Map<String, String> params : shardParamsList) {
String shardDbName = params.get("SHARD_DB_NAME");
info.addDatabase(shardDbName);
}
GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
getDatabaseListTask.execute();
List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
int shardDbCnt = info.getDatabases().size();
int matchedCnt = 0;
for (DatabaseInfo dbInfo : databaseInfoList) {
for (String dbName : info.getDatabases()) {
if (dbInfo.getDbName().equals(dbName)) {
if (DbRunningType.CS.equals(dbInfo.getRunningType())) {
info.setDbStatus(dbName, "ON");
} else {
info.setDbStatus(dbName, "OFF");
}
matchedCnt++;
if (shardDbCnt <= matchedCnt) {
break;
} else {
continue;
}
}
}
}
info.setShards(shards);
return info;
}
use of com.cubrid.cubridmanager.core.shard.model.Shards in project cubrid-manager by CUBRID.
the class ShardEnvStatusView method refresh.
/**
* Refreshes this view
*
* @param isUpdateTable
* whether update table
* @param isRefreshChanged
* whether refresh changed
*
*/
public void refresh() {
ServerInfo site = cubridNode.getServer().getServerInfo();
Shards shards = new Shards();
GetShardConfTask<Shards> getShardConfTask = new GetShardConfTask<Shards>(site, shards);
getShardConfTask.execute();
if (!getShardConfTask.isSuccess()) {
CommonUITool.openErrorBox(getShardConfTask.getErrorMsg());
return;
}
getShardConfTask.loadDataToModel();
GetShardStatusTask getShardStatusTask = new GetShardStatusTask(site, null);
getShardStatusTask.execute();
if (!getShardStatusTask.isSuccess()) {
CommonUITool.openErrorBox(getShardStatusTask.getErrorMsg());
return;
}
ShardsStatus shardsStatus = getShardStatusTask.getShardsStatus();
Map<String, ShardStatus> tmpCache = new HashMap<String, ShardStatus>();
List<ShardStatus> newShardInfoList = shardsStatus.getShardStatuss();
if (newShardInfoList == null) {
LOGGER.error("The newShardInfoList is a null.");
return;
}
for (int i = 0; newShardInfoList != null && i < newShardInfoList.size(); i++) {
ShardStatus shard = newShardInfoList.get(i);
tmpCache.put(shard.getName(), shard);
}
List<Shard> shardList = shards.getShardList();
for (int i = 0; shardList != null && i < shardList.size(); i++) {
Shard shard = shardList.get(i);
ShardStatus newShardInfo = tmpCache.get(shard.getName());
if (newShardInfo == null) {
newShardInfo = new ShardStatus();
newShardInfo.setName(shard.getName());
newShardInfo.setStatus(OnOffType.OFF.getText());
newShardInfo.setPort(shard.getValue(CubridShardConfParaConstants.BROKER_PORT));
newShardInfoList.add(newShardInfo);
} else {
newShardInfo.setStatus(OnOffType.ON.getText());
}
}
tableViewer.setInput(newShardInfoList);
tableViewer.refresh();
}
use of com.cubrid.cubridmanager.core.shard.model.Shards in project cubrid-manager by CUBRID.
the class CubridBrokersFolderLoader method load.
/**
*
* Load children object for parent
*
* @param parent the parent node
* @param monitor the IProgressMonitor object
*/
public void load(ICubridNode parent, final IProgressMonitor monitor) {
synchronized (this) {
if (isLoaded()) {
return;
}
ServerInfo serverInfo = parent.getServer().getServerInfo();
ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
if (userInfo == null || CasAuthType.AUTH_NONE == userInfo.getCasAuth()) {
parent.removeAllChild();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
return;
}
BrokerInfos brokerInfos = new BrokerInfos();
final CommonQueryTask<BrokerInfos> task = new CommonQueryTask<BrokerInfos>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), brokerInfos);
monitorCancel(monitor, new ITask[] { task });
task.execute();
final String errorMsg = task.getErrorMsg();
if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
parent.removeAllChild();
Display display = Display.getDefault();
display.syncExec(new Runnable() {
public void run() {
CommonUITool.openErrorBox(errorMsg);
}
});
setLoaded(true);
return;
}
if (monitor.isCanceled()) {
setLoaded(true);
return;
}
brokerInfos = task.getResultModel();
List<ICubridNode> oldNodeList = parent.getChildren();
parent.removeAllChild();
List<BrokerInfo> brokerInfoList = (brokerInfos == null || brokerInfos.getBorkerInfoList() == null) ? null : brokerInfos.getBorkerInfoList().getBrokerInfoList();
for (int i = 0; brokerInfoList != null && i < brokerInfoList.size(); i++) {
BrokerInfo brokerInfo = brokerInfoList.get(i);
String id = parent.getId() + NODE_SEPARATOR + brokerInfo.getName();
ICubridNode brokerInfoNode = isContained(oldNodeList, id);
if (brokerInfoNode == null) {
brokerInfoNode = new CubridBroker(id, brokerInfo.getName(), "icons/navigator/broker.png");
((CubridBroker) brokerInfoNode).setStartedIconPath("icons/navigator/broker_started.png");
brokerInfoNode.setType(CubridNodeType.BROKER);
brokerInfoNode.setContainer(true);
brokerInfoNode.setModelObj(brokerInfo);
brokerInfoNode.setViewId(BrokerStatusView.ID);
brokerInfoNode.setLoader(new CubridBrokerFolderLoader());
} else {
brokerInfoNode.setModelObj(brokerInfo);
if (brokerInfoNode.getLoader() != null && brokerInfoNode.getLoader().isLoaded()) {
brokerInfoNode.getLoader().setLoaded(false);
brokerInfoNode.getChildren(monitor);
}
}
parent.addChild(brokerInfoNode);
}
serverInfo.setBrokerInfos(brokerInfos);
// For the Shard Broker Folder
if (CompatibleUtil.isSupportShard(serverInfo)) {
Shards shards = new Shards();
GetShardConfTask<Shards> getShardConfTask = new GetShardConfTask<Shards>(serverInfo, shards);
getShardConfTask.execute();
// !"File(?) open error".equals(errorMsg.trim())) {
if (getShardConfTask.isSuccess()) {
GetShardStatusTask getShardStatusTask = new GetShardStatusTask(serverInfo, null);
getShardStatusTask.execute();
boolean runningShard = getShardStatusTask.isSuccess();
serverInfo.setShards(shards);
shards.setRunning(runningShard);
String shardFolderId = parent.getId() + NODE_SEPARATOR + SHARD_FOLDER_ID;
ICubridNode shardFolder = parent.getChild(shardFolderId);
if (shardFolder == null) {
shardFolder = new CubridShardFolder(shardFolderId, SHARD_FOLDER_NAME);
ICubridNodeLoader loader = new CubridShardsFolderLoader((CubridShardFolder) shardFolder);
loader.setLevel(getLevel());
shardFolder.setLoader(loader);
parent.addChild(shardFolder);
// shardFolder.getChildren(monitor);
} else {
if (shardFolder.getLoader() != null && shardFolder.getLoader().isLoaded()) {
shardFolder.getLoader().setLoaded(false);
shardFolder.getChildren(monitor);
}
}
}
}
Collections.sort(parent.getChildren());
setLoaded(true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
use of com.cubrid.cubridmanager.core.shard.model.Shards in project cubrid-manager by CUBRID.
the class CubridBrokerLogFolderLoader method load.
/**
*
* Load children object for parent
*
* @param parent the parent node
* @param monitor the IProgressMonitor object
*/
public void load(ICubridNode parent, final IProgressMonitor monitor) {
synchronized (this) {
if (isLoaded()) {
return;
}
// add access and error and admin log folder to broker logs folder
String[] brokerLogIdArr = { ACCESS_LOG_FOLDER_ID, ERROR_LOG_FOLDER_ID, ADMIN_LOG_FOLDER_ID };
String[] brokerLogNameArr = { ACCESS_LOG_FOLDER_NAME, ERROR_LOG_FOLDER_NAME, ADMIN_LOG_FOLDER_NAME };
String[] brokerLogTypeArr = { CubridNodeType.LOGS_BROKER_ACCESS_LOG_FOLDER, CubridNodeType.LOGS_BROKER_ERROR_LOG_FOLDER, CubridNodeType.LOGS_BROKER_ADMIN_LOG_FOLDER };
String[] iconArr = { "icons/navigator/folder.png", "icons/navigator/folder.png", "icons/navigator/folder.png" };
ICubridNode[] logFoldrNodeArr = new ICubridNode[3];
for (int i = 0; i < brokerLogNameArr.length; i++) {
String id = parent.getId() + NODE_SEPARATOR + brokerLogIdArr[i];
logFoldrNodeArr[i] = parent.getChild(id);
if (logFoldrNodeArr[i] == null) {
logFoldrNodeArr[i] = new DefaultCubridNode(id, brokerLogNameArr[i], iconArr[i]);
logFoldrNodeArr[i].setType(brokerLogTypeArr[i]);
logFoldrNodeArr[i].setContainer(true);
parent.addChild(logFoldrNodeArr[i]);
if (i == 2) {
ICubridNodeLoader loader = new CubridAdminLogFolderLoader();
loader.setLevel(getLevel());
logFoldrNodeArr[i].setLoader(loader);
if (getLevel() == DEFINITE_LEVEL) {
logFoldrNodeArr[i].getChildren(monitor);
}
}
} else {
if (logFoldrNodeArr[i].getLoader() != null) {
logFoldrNodeArr[i].getLoader().setLoaded(false);
logFoldrNodeArr[i].getChildren(monitor);
}
}
}
ServerInfo serverInfo = parent.getServer().getServerInfo();
BrokerInfos brokerInfos = serverInfo.getBrokerInfos();
Shards shards = serverInfo.getShards();
monitorCancel(monitor, new ITask[] { loadBrokersTask, loadBrokrLogInfoTask });
if (brokerInfos == null && !monitor.isCanceled()) {
// load all borkers
brokerInfos = new BrokerInfos();
loadBrokersTask = new CommonQueryTask<BrokerInfos>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), brokerInfos);
loadBrokersTask.execute();
final String errorMsg = loadBrokersTask.getErrorMsg();
if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
logFoldrNodeArr[0].removeAllChild();
logFoldrNodeArr[1].removeAllChild();
openErrorBox(errorMsg);
setLoaded(true);
return;
}
brokerInfos = loadBrokersTask.getResultModel();
serverInfo.setBrokerInfos(brokerInfos);
}
if (monitor.isCanceled()) {
setLoaded(true);
return;
}
// load broker log file information
List<BrokerLogInfos> brokerLogInfosList = new ArrayList<BrokerLogInfos>();
if (brokerInfos != null) {
BrokerInfoList list = brokerInfos.getBorkerInfoList();
if (list != null && list.getBrokerInfoList() != null) {
List<BrokerInfo> brokerInfoList = list.getBrokerInfoList();
for (int i = 0; !monitor.isCanceled() && brokerInfoList != null && i < brokerInfoList.size(); i++) {
BrokerInfo brokerInfo = brokerInfoList.get(i);
BrokerLogInfos brokerLogInfos = new BrokerLogInfos();
loadBrokrLogInfoTask = new CommonQueryTask<BrokerLogInfos>(serverInfo, CommonSendMsg.getGetBrokerLogFileInfoMSGItems(), brokerLogInfos);
loadBrokrLogInfoTask.setBroker(brokerInfo.getName());
loadBrokrLogInfoTask.execute();
final String errorMsg = loadBrokrLogInfoTask.getErrorMsg();
if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
logFoldrNodeArr[0].removeAllChild();
logFoldrNodeArr[1].removeAllChild();
openErrorBox(errorMsg);
setLoaded(true);
return;
}
brokerLogInfos = loadBrokrLogInfoTask.getResultModel();
brokerLogInfosList.add(brokerLogInfos);
}
}
}
// load shard broker log file information
if (shards != null) {
List<Shard> shardList = shards.getShardList();
if (shardList != null) {
for (int i = 0; i < shardList.size(); i++) {
Shard shard = shardList.get(i);
BrokerLogInfos brokerLogInfos = new BrokerLogInfos();
loadBrokrLogInfoTask = new CommonQueryTask<BrokerLogInfos>(serverInfo, CommonSendMsg.getGetBrokerLogFileInfoMSGItems(), brokerLogInfos);
loadBrokrLogInfoTask.setBroker(shard.getName());
loadBrokrLogInfoTask.execute();
final String errorMsg = loadBrokrLogInfoTask.getErrorMsg();
if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
logFoldrNodeArr[0].removeAllChild();
logFoldrNodeArr[1].removeAllChild();
openErrorBox(errorMsg);
setLoaded(true);
return;
}
brokerLogInfos = loadBrokrLogInfoTask.getResultModel();
brokerLogInfosList.add(brokerLogInfos);
}
}
}
if (monitor.isCanceled()) {
setLoaded(true);
return;
}
logFoldrNodeArr[0].removeAllChild();
logFoldrNodeArr[1].removeAllChild();
for (BrokerLogInfos brokerLogInfos : brokerLogInfosList) {
List<LogInfo> logInfoList = brokerLogInfos.getBrokerLogInfoList().getLogFileInfoList();
if (logInfoList != null && !logInfoList.isEmpty()) {
for (LogInfo logInfo : logInfoList) {
ICubridNode logInfoNode = new DefaultCubridNode("", logInfo.getName(), "");
logInfoNode.setContainer(false);
logInfoNode.setModelObj(logInfo);
logInfoNode.setEditorId(LogEditorPart.ID);
if (LogType.ACCESS.getText().toLowerCase().equals(logInfo.getType())) {
String id = logFoldrNodeArr[0].getId() + NODE_SEPARATOR + logInfo.getName();
logInfoNode.setId(id);
logInfoNode.setType(CubridNodeType.LOGS_BROKER_ACCESS_LOG);
logInfoNode.setIconPath("icons/navigator/log_item.png");
logFoldrNodeArr[0].addChild(logInfoNode);
} else if (LogType.ERROR.getText().toLowerCase().equals(logInfo.getType())) {
String id = logFoldrNodeArr[1].getId() + NODE_SEPARATOR + logInfo.getName();
logInfoNode.setId(id);
logInfoNode.setType(CubridNodeType.LOGS_BROKER_ERROR_LOG);
logInfoNode.setIconPath("icons/navigator/log_item.png");
logFoldrNodeArr[1].addChild(logInfoNode);
}
}
}
}
Collections.sort(logFoldrNodeArr[0].getChildren());
Collections.sort(logFoldrNodeArr[1].getChildren());
setLoaded(true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(logFoldrNodeArr[0], CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(logFoldrNodeArr[1], CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
Aggregations