use of com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode in project tis by qlangtech.
the class CoreAction method getCoreNodeMap.
private Map<String, CoreNode> getCoreNodeMap(boolean isAppNameAware) {
CoreNode[] nodelist = SelectableServer.getCoreNodeInfo(this.getRequest(), this, false, isAppNameAware);
Map<String, CoreNode> result = new HashMap<String, CoreNode>();
for (CoreNode node : nodelist) {
result.put(node.getNodeName(), node);
}
return result;
}
use of com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode in project tis by qlangtech.
the class CoreAction method parseIps.
//
// /**
// * @param context
// * @param serverSuffix
// * @param isAppNameAware
// * @param mustSelectMoreOneReplicAtLeast
// * 每一组至少选一个副本(在创建core的时候,每组至少要选一个以上的副本, <br/>
// * 但是在减少副本的时候每组可以一个副本都不选)
// * @return
// */
private ParseIpResult parseIps(Context context, String serverSuffix, boolean isAppNameAware, boolean mustSelectMoreOneReplicAtLeast) {
ParseIpResult result = new ParseIpResult();
result.valid = false;
List<String> parseips = new ArrayList<String>();
String[] ips = this.getRequest().getParameterValues("selectedServer" + StringUtils.trimToEmpty(serverSuffix));
if (ips == null) {
return result;
}
if (mustSelectMoreOneReplicAtLeast && ips.length < 1) {
addErrorMessage(context, "请" + (StringUtils.isNotEmpty(serverSuffix) ? "为第" + serverSuffix + "组" : StringUtils.EMPTY) + "选择服务器");
return result;
}
// StringBuffer ipLiteria = new StringBuffer();
result.ipLiteria.append("[");
Matcher matcher = null;
final Map<String, CoreNode> serverdetailMap = getCoreNodeMap(isAppNameAware);
CoreNode nodeinfo = null;
CoreNode current = null;
for (String ip : ips) {
matcher = this.isValidIpPattern(ip);
if (!matcher.matches()) {
this.addErrorMessage(context, "IP:" + ip + "不符合格式规范");
return result;
}
// ▼▼▼ 校验组内服务器lucene版本是否一致
current = serverdetailMap.get(ip);
if (current == null) {
this.addErrorMessage(context, "服务器" + ip + ",不在可选集合之内");
return result;
}
if (nodeinfo != null) {
if (current.getLuceneSpecVersion() != nodeinfo.getLuceneSpecVersion()) {
this.addErrorMessage(context, (StringUtils.isNotEmpty(serverSuffix) ? "第" + serverSuffix + "组" : StringUtils.EMPTY) + "服务器Lucene版本不一致");
return result;
}
}
nodeinfo = current;
// ▲▲▲ 校验组内服务器lucene版本是否一致
// matcher.group(group)
parseips.add(matcher.group(0));
result.ipLiteria.append(ip).append(",");
}
result.ipLiteria.append("]");
result.ips = parseips.toArray(new String[parseips.size()]);
result.valid = true;
return result;
}
use of com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode in project tis by qlangtech.
the class CreateIndexConfirmModel method getCoreNodeCandidate.
/**
* 取得服务器的候选地址
*
* @return
*/
public String[] getCoreNodeCandidate() {
if (this.coreNode == null) {
throw new IllegalStateException("prop coreNode can not be null");
}
String[] result = new String[this.coreNode.getHosts().length];
int i = 0;
for (CoreNode node : this.coreNode.getHosts()) {
result[i++] = node.getHostName();
}
return result;
// if (coreNode == null || StringUtils.isBlank(coreNode.getNodeName())) {
// throw new IllegalStateException("coreNode can not be null");
// }
// // return new String[] {
// // StringUtils.substringBefore(coreNode.getNodeName(), "_") };
// return new String[]{coreNode.getNodeName()};
}
use of com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode in project tis by qlangtech.
the class TISZkStateReader method fetchSelectTableNodes.
private Collection<CoreNode> fetchSelectTableNodes() {
selectTableNodesMap.clear();
try {
// 计算各个节点的副本数
ClusterState clusterState = this.getClusterState();
Set<String> liveNodes = clusterState.getLiveNodes();
Map<String, ClusterState.CollectionRef> collectionStates = clusterState.getCollectionStates();
Stream<Collection<Slice>> collectionStream = collectionStates.values().stream().map(ClusterState.CollectionRef::get).map(DocCollection::getSlices);
Stream<Replica> replicaStream = collectionStream.flatMap(Collection::stream).map(Slice::getReplicas).flatMap(Collection::stream);
Map<String, Integer> solrCoreCountMap = replicaStream.collect(Collectors.groupingBy((r) -> r.getNodeName(), Collectors.summingInt((r) -> 1)));
Integer coreCount = null;
for (String livenode : liveNodes) {
CoreNode node = new CoreNode();
String ip = getIP(livenode);
InetAddress address = InetAddress.getByName(ip);
String host = address.getHostName();
node.setHostName(host);
node.setNodeName(livenode);
coreCount = solrCoreCountMap.get(livenode);
if (coreCount != null) {
node.setSolrCoreCount(coreCount);
}
URL url = new URL(GET_LUCENE_VER_RUL_FORMAT.format(new String[] { ip }));
node.setLuceneSpecVersion(getLuceneVer(url));
selectTableNodesMap.put(ip, node);
}
} catch (Exception e) {
throw new RuntimeException("get select table node error", e);
}
return selectTableNodesMap.values();
}
Aggregations