|
|
package com.yoho.search.consumer.restapi;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.consumer.common.IYohoIndexService;
|
|
|
import com.yoho.search.consumer.service.logicService.personal.PersonalVectorVersionManager;
|
|
|
import com.yoho.search.consumer.service.logicService.tbl.util.StringUtils;
|
|
|
import com.yoho.search.core.es.IElasticsearchClient;
|
|
|
import com.yoho.search.core.personalized.service.BidataServiceCaller;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Controller
|
|
|
public class ToolsController {
|
|
|
|
|
|
@Autowired
|
|
|
private PersonalVectorVersionManager personalVectorVersionManager;
|
|
|
@Autowired
|
|
|
private BidataServiceCaller bidataServiceCaller;
|
|
|
|
|
|
@RequestMapping(value = "/vectorVersion")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> vectorVersion(){
|
|
|
Map<String, Object> results = new HashMap<String, Object>();
|
|
|
//大数据目前推荐的版本
|
|
|
String bigDataRecomDateStr = personalVectorVersionManager.getBigDataRecomDateStr();
|
|
|
results.put("bigDataRecomDateStr", bigDataRecomDateStr==null?"":bigDataRecomDateStr);
|
|
|
//zk中目前的版本
|
|
|
String currentVersionInZk = personalVectorVersionManager.getCurrentVersionInZk();
|
|
|
results.put("currentVersionInZk", currentVersionInZk);
|
|
|
//经过计算目前可以使用的版本
|
|
|
String currentVersion = personalVectorVersionManager.getCurrentVersion();
|
|
|
results.put("currentVersion", currentVersion);
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/bigdataServiceTest")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> bigdataServiceTets(Integer uid){
|
|
|
Map<String, Object> results = new HashMap<String, Object>();
|
|
|
//大数据目前推荐的版本
|
|
|
String bigDataRecomDateStr = bidataServiceCaller.getBigDataRecomDateStr();
|
|
|
results.put("bigDataRecomDateStr", bigDataRecomDateStr==null?"":bigDataRecomDateStr);
|
|
|
results.put("userFavoriteSizes",bidataServiceCaller.getUserFavoriteSizes(uid.toString()));
|
|
|
results.put("userGenderFeature",bidataServiceCaller.getUserGenderFeature(uid.toString()));
|
|
|
results.put("userFavoriteSizes",bidataServiceCaller.getUserFavoriteSizes(uid.toString()));
|
|
|
results.put("userVectorFeature",bidataServiceCaller.getUserVectorFeature(uid.toString(),bigDataRecomDateStr));
|
|
|
results.put("userPersionalFactor",bidataServiceCaller.queryUserPersionalFactor(uid,null,null));
|
|
|
return results;
|
|
|
}
|
|
|
@Autowired
|
|
|
private PersonalVectorVersionManager personalVectorVersionManager;
|
|
|
@Autowired
|
|
|
private BidataServiceCaller bidataServiceCaller;
|
|
|
@Autowired
|
|
|
private IYohoIndexService yohoIndexService;
|
|
|
|
|
|
@RequestMapping(value = "/vectorVersion")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> vectorVersion() {
|
|
|
Map<String, Object> results = new HashMap<String, Object>();
|
|
|
//大数据目前推荐的版本
|
|
|
String bigDataRecomDateStr = personalVectorVersionManager.getBigDataRecomDateStr();
|
|
|
results.put("bigDataRecomDateStr", bigDataRecomDateStr == null ? "" : bigDataRecomDateStr);
|
|
|
//zk中目前的版本
|
|
|
String currentVersionInZk = personalVectorVersionManager.getCurrentVersionInZk();
|
|
|
results.put("currentVersionInZk", currentVersionInZk);
|
|
|
//经过计算目前可以使用的版本
|
|
|
String currentVersion = personalVectorVersionManager.getCurrentVersion();
|
|
|
results.put("currentVersion", currentVersion);
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/bigdataServiceTest")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> bigdataServiceTets(Integer uid) {
|
|
|
Map<String, Object> results = new HashMap<String, Object>();
|
|
|
//大数据目前推荐的版本
|
|
|
String bigDataRecomDateStr = bidataServiceCaller.getBigDataRecomDateStr();
|
|
|
results.put("bigDataRecomDateStr", bigDataRecomDateStr == null ? "" : bigDataRecomDateStr);
|
|
|
results.put("userFavoriteSizes", bidataServiceCaller.getUserFavoriteSizes(uid.toString()));
|
|
|
results.put("userGenderFeature", bidataServiceCaller.getUserGenderFeature(uid.toString()));
|
|
|
results.put("userFavoriteSizes", bidataServiceCaller.getUserFavoriteSizes(uid.toString()));
|
|
|
results.put("userVectorFeature", bidataServiceCaller.getUserVectorFeature(uid.toString(), bigDataRecomDateStr));
|
|
|
results.put("userPersionalFactor", bidataServiceCaller.queryUserPersionalFactor(uid, null, null));
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/ip2IndexInfo")
|
|
|
@ResponseBody
|
|
|
public Map<String, Object> nodeAndShardInfo() {
|
|
|
IElasticsearchClient client = yohoIndexService.getElasticsearchClient(ISearchConstants.INDEX_NAME_PRODUCT_INDEX);
|
|
|
ClusterState clusterState = client.getClusterStateResponse().getState();
|
|
|
DiscoveryNodes discoveryNodes = clusterState.nodes();
|
|
|
|
|
|
Map<String, List<Map<String, Object>>> ip2IndexInfo = new HashMap<>();
|
|
|
Set<String> allIps = new HashSet<>();
|
|
|
Set<String> hasPrimaryIps = new HashSet<>();
|
|
|
for (ShardRouting shard : clusterState.routingTable().allShards()) {
|
|
|
String indexName = shard.getIndexName();
|
|
|
String hostAddress = discoveryNodes.get(shard.currentNodeId()).getHostAddress();
|
|
|
boolean isPrimary = shard.primary();
|
|
|
if(isPrimary){
|
|
|
hasPrimaryIps.add(hostAddress);
|
|
|
}
|
|
|
allIps.add(hostAddress);
|
|
|
|
|
|
List<Map<String, Object>> indexInfoList = ip2IndexInfo.computeIfAbsent(hostAddress,a->new ArrayList<>());
|
|
|
JSONObject indexInfo = new JSONObject();
|
|
|
indexInfo.put("index_name", indexName);
|
|
|
indexInfo.put("node_id", shard.currentNodeId());
|
|
|
indexInfo.put("is_primary", isPrimary);
|
|
|
indexInfo.put("host_address", hostAddress);
|
|
|
indexInfoList.add(indexInfo);
|
|
|
}
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("all",ip2IndexInfo);
|
|
|
result.put("hasPrimaryIps", StringUtils.join(hasPrimaryIps,","));
|
|
|
allIps.removeAll(hasPrimaryIps);
|
|
|
result.put("noPrimaryIps", StringUtils.join(allIps,","));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|