Search in sources :

Example 1 with InstanceDirDesc

use of com.qlangtech.tis.coredefine.module.screen.Corenodemanage.InstanceDirDesc in project tis by qlangtech.

the class CoreAction method getInstanceDirDesc.

/**
 * 各个副本节点描述信息
 *
 * @return
 * @throws Exception
 */
private static InstanceDirDesc getInstanceDirDesc(BasicModule module) throws Exception {
    InstanceDirDesc dirDesc = new InstanceDirDesc();
    dirDesc.setValid(false);
    DocCollection collection = module.getIndex();
    final Set<String> instanceDir = new HashSet<String>();
    if (collection.getSlices().isEmpty()) {
        dirDesc.setDesc("实例尚未创建,未发现副本节点");
        return dirDesc;
    }
    boolean hasGetAllCount = false;
    URL url = null;
    for (Slice slice : collection.getSlices()) {
        for (final Replica replica : slice.getReplicas()) {
            if (!hasGetAllCount) {
                dirDesc.setAllcount(getAllRowsCount(collection.getName(), replica.getCoreUrl()));
                hasGetAllCount = true;
            }
            // ZkCoreNodeProps.getCoreUrl
            url = new URL(replica.getCoreUrl() + "admin/mbeans?stats=true&cat=CORE&key=core&wt=xml");
            // http://192.168.28.200:8080/solr/search4supplyGoods2_shard1_replica_n1/admin/mbeans?stats=true&cat=CORE&key=core&wt=xml
            ConfigFileContext.processContent(url, new StreamProcess<Object>() {

                @Override
                @SuppressWarnings("all")
                public Object p(int s, InputStream stream, Map<String, List<String>> headerFields) {
                    SimpleOrderedMap result = (SimpleOrderedMap) RESPONSE_PARSER.processResponse(stream, TisUTF8.getName());
                    final SimpleOrderedMap mbeans = (SimpleOrderedMap) result.get("solr-mbeans");
                    SimpleOrderedMap core = (SimpleOrderedMap) ((SimpleOrderedMap) mbeans.get("CORE")).get("core");
                    SimpleOrderedMap status = ((SimpleOrderedMap) core.get("stats"));
                    // core 节点刚创建status为空
                    if (status == null) {
                        return null;
                    }
                    String indexDir = StringUtils.substringAfterLast((String) status.get("CORE.indexDir"), "/");
                    instanceDir.add(indexDir);
                    ReplicState replicState = new ReplicState();
                    replicState.setIndexDir(indexDir);
                    replicState.setValid(StringUtils.isNotBlank(indexDir));
                    if (StringUtils.isBlank(indexDir)) {
                        replicState.setInvalidDesc("未完成全量构建");
                    }
                    replicState.setNodeName(StringUtils.substringBefore(replica.getNodeName(), ":"));
                    ;
                    replicState.setCoreName(StringUtils.substringAfter((String) core.get("class"), "_"));
                    replicState.setState(replica.getState().toString());
                    replicState.setLeader(replica.getBool("leader", false));
                    dirDesc.addReplicState(slice.getName(), replicState);
                    return null;
                }
            });
        }
    }
    final StringBuffer replicDirDesc = new StringBuffer();
    if (instanceDir.size() > 1) {
        replicDirDesc.append("(");
        int count = 0;
        for (String d : instanceDir) {
            replicDirDesc.append(d);
            if (++count < instanceDir.size()) {
                replicDirDesc.append(",");
            }
        }
        replicDirDesc.append(")");
        dirDesc.setDesc("副本目录不一致,分别为:" + replicDirDesc);
    } else if (instanceDir.size() == 1) {
        if (dirDesc.isAllReplicValid()) {
            dirDesc.setValid(true);
            for (String d : instanceDir) {
                dirDesc.setDesc("所有副本目录为:" + d);
                break;
            }
        } else {
            dirDesc.setValid(false);
            dirDesc.setDesc(dirDesc.invalidDesc().toString());
        }
    } else {
        dirDesc.setDesc("副本目录数异常,size:" + instanceDir.size());
    }
    return dirDesc;
}
Also used : InputStream(java.io.InputStream) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) URL(java.net.URL) InstanceDirDesc(com.qlangtech.tis.coredefine.module.screen.Corenodemanage.InstanceDirDesc) ReplicState(com.qlangtech.tis.coredefine.module.screen.Corenodemanage.ReplicState) JSONObject(org.json.JSONObject)

Aggregations

InstanceDirDesc (com.qlangtech.tis.coredefine.module.screen.Corenodemanage.InstanceDirDesc)1 ReplicState (com.qlangtech.tis.coredefine.module.screen.Corenodemanage.ReplicState)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)1 JSONObject (org.json.JSONObject)1