Search in sources :

Example 1 with CoreNode

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;
}
Also used : CoreNode(com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode)

Example 2 with CoreNode

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;
}
Also used : Matcher(java.util.regex.Matcher) CoreNode(com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode)

Example 3 with CoreNode

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()};
}
Also used : CoreNode(com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode)

Example 4 with CoreNode

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();
}
Also used : CreateMode(org.apache.zookeeper.CreateMode) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) URLDecoder(java.net.URLDecoder) Utils(org.apache.solr.common.util.Utils) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) Stat(org.apache.zookeeper.data.Stat) MessageFormat(java.text.MessageFormat) InetAddress(java.net.InetAddress) SolrException(org.apache.solr.common.SolrException) Arrays.asList(java.util.Arrays.asList) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) ErrorCode(org.apache.solr.common.SolrException.ErrorCode) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) CoreNode(com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode) Logger(org.slf4j.Logger) KeeperException(org.apache.zookeeper.KeeperException) Watcher(org.apache.zookeeper.Watcher) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) WatchedEvent(org.apache.zookeeper.WatchedEvent) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) IOUtils(org.apache.commons.io.IOUtils) Stream(java.util.stream.Stream) HttpUtils(com.qlangtech.tis.manage.common.HttpUtils) EventType(org.apache.zookeeper.Watcher.Event.EventType) Entry(java.util.Map.Entry) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Collections(java.util.Collections) ConfigFileContext(com.qlangtech.tis.manage.common.ConfigFileContext) InputStream(java.io.InputStream) URL(java.net.URL) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InetAddress(java.net.InetAddress) CoreNode(com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode)

Aggregations

CoreNode (com.qlangtech.tis.coredefine.module.control.SelectableServer.CoreNode)4 ConfigFileContext (com.qlangtech.tis.manage.common.ConfigFileContext)1 HttpUtils (com.qlangtech.tis.manage.common.HttpUtils)1 TisUTF8 (com.qlangtech.tis.manage.common.TisUTF8)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 URLDecoder (java.net.URLDecoder)1 MessageFormat (java.text.MessageFormat)1 java.util (java.util)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 Matcher (java.util.regex.Matcher)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1