use of com.cubrid.cubridmanager.core.shard.model.ShardStatus in project cubrid-manager by CUBRID.
the class GetShardStatusTask method setFieldValueNew.
private static void setFieldValueNew(TreeNode node, final ShardsStatus shardsStatus) {
if (node == null || shardsStatus == null) {
return;
}
if (node.getChildren() == null || node.getChildren().isEmpty()) {
return;
}
for (TreeNode shard : node.getChildren()) {
ShardStatus shardStatus = new ShardStatus();
Class<?> clazz = shardStatus.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
Column column = field.getAnnotation(Column.class);
if (column == null || !column.enable()) {
continue;
}
String propertyName = column.name();
String value = shard.getValue(propertyName);
field.setAccessible(true);
try {
field.set(shardStatus, field.getType().cast(value));
} catch (IllegalArgumentException e) {
LOGGER.error(e.getMessage(), e);
} catch (IllegalAccessException e) {
LOGGER.error(e.getMessage(), e);
}
}
shardsStatus.addShardStatus(shardStatus);
}
}
use of com.cubrid.cubridmanager.core.shard.model.ShardStatus 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.ShardStatus in project cubrid-manager by CUBRID.
the class CubridShardsFolderLoader 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();
if (serverInfo == null) {
LOGGER.error("The serverInfo is a null.");
return;
}
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;
}
Display display = Display.getDefault();
boolean statusTag = false;
boolean confTag = false;
Shards shards = new Shards();
GetShardConfTask<Shards> getShardConfTask = new GetShardConfTask<Shards>(serverInfo, shards);
monitorCancel(monitor, new ITask[] { getShardConfTask });
getShardConfTask.execute();
if (!monitor.isCanceled() && !getShardConfTask.isSuccess()) {
final String errorMsg = getShardConfTask.getErrorMsg();
confTag = false;
cubridShardFolder.setEnable(false);
parent.removeAllChild();
display.syncExec(new Runnable() {
public void run() {
CommonUITool.openErrorBox(errorMsg);
}
});
setLoaded(true);
// return;
} else {
confTag = true;
getShardConfTask.loadDataToModel();
serverInfo.setShards(shards);
}
GetShardStatusTask getShardStatusTask = new GetShardStatusTask(serverInfo, null);
monitorCancel(monitor, new ITask[] { getShardStatusTask });
getShardStatusTask.execute();
ShardsStatus shardsStatus = null;
if (getShardStatusTask.isSuccess()) {
shardsStatus = getShardStatusTask.getShardsStatus();
cubridShardFolder.setRunning(true);
statusTag = true;
} else {
final String errorMsg = getShardStatusTask.getErrorMsg();
if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
statusTag = false;
if (errorMsg.trim().contains("cubrid shard is not running")) {
cubridShardFolder.setRunning(false);
parent.removeAllChild();
// return;
} else {
display.syncExec(new Runnable() {
public void run() {
CommonUITool.openErrorBox(errorMsg);
}
});
}
}
}
if (monitor.isCanceled()) {
setLoaded(true);
return;
}
List<ICubridNode> oldNodeList = parent.getChildren();
parent.removeAllChild();
Map<String, ShardStatus> tmpCache = new HashMap<String, ShardStatus>();
if (statusTag) {
List<ShardStatus> shardStatuss = (shardsStatus == null || shardsStatus.getShardStatuss() == null) ? null : shardsStatus.getShardStatuss();
for (int i = 0; shardStatuss != null && i < shardStatuss.size(); i++) {
ShardStatus shard = shardStatuss.get(i);
tmpCache.put(shard.getName(), shard);
}
}
if (confTag) {
List<Shard> shardList = (shards == null || shards.getShardList() == null) ? null : shards.getShardList();
for (int i = 0; shardList != null && i < shardList.size(); i++) {
Shard shard = shardList.get(i);
//
ShardConnection shardConnection = new ShardConnection();
shard.setShardConnectionFile(shardConnection);
GetShardConfTask<ShardConnection> getShardConnectionConfTask = new GetShardConfTask<ShardConnection>(serverInfo, shardConnection);
getShardConnectionConfTask.execute();
getShardConnectionConfTask.loadDataToModel();
ShardKeys shardKeys = new ShardKeys();
shard.setShardKeysFile(shardKeys);
GetShardConfTask<ShardKeys> getShardKeyConfTask = new GetShardConfTask<ShardKeys>(serverInfo, shardKeys);
getShardKeyConfTask.execute();
getShardKeyConfTask.loadDataToModel();
//
String id = parent.getId() + NODE_SEPARATOR + shard.getName();
ICubridNode shardNode = isContained(oldNodeList, id);
ShardStatus shardStatus = tmpCache.get(shard.getName());
String shardLabel = shardStatus != null ? " (" + shardStatus.getPort() + "," + shardStatus.getAccessMode() + ")" : "";
if (shardNode == null) {
shardNode = new CubridShard(id, shard.getName() + shardLabel);
((CubridShard) shardNode).setName(shard.getName());
shardNode.setType(CubridNodeType.SHARD);
shardNode.setContainer(true);
shardNode.setModelObj(shard);
shardNode.setLoader(new CubridShardFolderLoader());
} else {
shardNode.setModelObj(shard);
if (shardNode.getLoader() != null && shardNode.getLoader().isLoaded()) {
shardNode.getLoader().setLoaded(false);
shardNode.getChildren(monitor);
}
}
((CubridShard) shardNode).setRunning(shardStatus != null);
parent.addChild(shardNode);
}
}
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.ShardStatus in project cubrid-manager by CUBRID.
the class ShardNode method genBrokerInfo.
public void genBrokerInfo() {
StringBuilder sb = new StringBuilder();
if (shardsStatus != null) {
int count = 0;
for (ShardStatus shardStatus : shardsStatus.getShardStatuss()) {
if (shardStatus != null) {
//sb.append(brokerInfo.getName()).append("[");
sb.append(shardStatus.getPort()).append(":");
sb.append(shardStatus.getStatus()).append(", ");
count++;
}
}
if (count > 0) {
sb.delete(sb.length() - 2, sb.length());
}
}
super.setBrokerInfo(sb.toString());
}
Aggregations