1
|
package com.yoho.search.consumer.restapi;
|
1
|
package com.yoho.search.consumer.restapi;
|
2
|
|
2
|
|
|
|
3
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
4
|
+import com.yoho.search.base.utils.ISearchConstants;
|
|
|
5
|
+import com.yoho.search.consumer.common.IYohoIndexService;
|
3
|
import com.yoho.search.consumer.service.logicService.personal.PersonalVectorVersionManager;
|
6
|
import com.yoho.search.consumer.service.logicService.personal.PersonalVectorVersionManager;
|
|
|
7
|
+import com.yoho.search.consumer.service.logicService.tbl.util.StringUtils;
|
|
|
8
|
+import com.yoho.search.core.es.IElasticsearchClient;
|
4
|
import com.yoho.search.core.personalized.service.BidataServiceCaller;
|
9
|
import com.yoho.search.core.personalized.service.BidataServiceCaller;
|
|
|
10
|
+import org.apache.commons.collections.MapUtils;
|
|
|
11
|
+import org.elasticsearch.cluster.ClusterState;
|
|
|
12
|
+import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|
|
13
|
+import org.elasticsearch.cluster.routing.ShardRouting;
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
import org.springframework.stereotype.Controller;
|
15
|
import org.springframework.stereotype.Controller;
|
7
|
import org.springframework.web.bind.annotation.RequestMapping;
|
16
|
import org.springframework.web.bind.annotation.RequestMapping;
|
8
|
import org.springframework.web.bind.annotation.ResponseBody;
|
17
|
import org.springframework.web.bind.annotation.ResponseBody;
|
9
|
|
18
|
|
10
|
-import java.util.HashMap;
|
|
|
11
|
-import java.util.Map;
|
19
|
+import java.util.*;
|
12
|
|
20
|
|
13
|
@Controller
|
21
|
@Controller
|
14
|
public class ToolsController {
|
22
|
public class ToolsController {
|
15
|
|
23
|
|
16
|
- @Autowired
|
|
|
17
|
- private PersonalVectorVersionManager personalVectorVersionManager;
|
|
|
18
|
- @Autowired
|
|
|
19
|
- private BidataServiceCaller bidataServiceCaller;
|
|
|
20
|
-
|
|
|
21
|
- @RequestMapping(value = "/vectorVersion")
|
|
|
22
|
- @ResponseBody
|
|
|
23
|
- public Map<String, Object> vectorVersion(){
|
|
|
24
|
- Map<String, Object> results = new HashMap<String, Object>();
|
|
|
25
|
- //大数据目前推荐的版本
|
|
|
26
|
- String bigDataRecomDateStr = personalVectorVersionManager.getBigDataRecomDateStr();
|
|
|
27
|
- results.put("bigDataRecomDateStr", bigDataRecomDateStr==null?"":bigDataRecomDateStr);
|
|
|
28
|
- //zk中目前的版本
|
|
|
29
|
- String currentVersionInZk = personalVectorVersionManager.getCurrentVersionInZk();
|
|
|
30
|
- results.put("currentVersionInZk", currentVersionInZk);
|
|
|
31
|
- //经过计算目前可以使用的版本
|
|
|
32
|
- String currentVersion = personalVectorVersionManager.getCurrentVersion();
|
|
|
33
|
- results.put("currentVersion", currentVersion);
|
|
|
34
|
- return results;
|
|
|
35
|
- }
|
|
|
36
|
-
|
|
|
37
|
- @RequestMapping(value = "/bigdataServiceTest")
|
|
|
38
|
- @ResponseBody
|
|
|
39
|
- public Map<String, Object> bigdataServiceTets(Integer uid){
|
|
|
40
|
- Map<String, Object> results = new HashMap<String, Object>();
|
|
|
41
|
- //大数据目前推荐的版本
|
|
|
42
|
- String bigDataRecomDateStr = bidataServiceCaller.getBigDataRecomDateStr();
|
|
|
43
|
- results.put("bigDataRecomDateStr", bigDataRecomDateStr==null?"":bigDataRecomDateStr);
|
|
|
44
|
- results.put("userFavoriteSizes",bidataServiceCaller.getUserFavoriteSizes(uid.toString()));
|
|
|
45
|
- results.put("userGenderFeature",bidataServiceCaller.getUserGenderFeature(uid.toString()));
|
|
|
46
|
- results.put("userFavoriteSizes",bidataServiceCaller.getUserFavoriteSizes(uid.toString()));
|
|
|
47
|
- results.put("userVectorFeature",bidataServiceCaller.getUserVectorFeature(uid.toString(),bigDataRecomDateStr));
|
|
|
48
|
- results.put("userPersionalFactor",bidataServiceCaller.queryUserPersionalFactor(uid,null,null));
|
|
|
49
|
- return results;
|
|
|
50
|
- }
|
24
|
+ @Autowired
|
|
|
25
|
+ private PersonalVectorVersionManager personalVectorVersionManager;
|
|
|
26
|
+ @Autowired
|
|
|
27
|
+ private BidataServiceCaller bidataServiceCaller;
|
|
|
28
|
+ @Autowired
|
|
|
29
|
+ private IYohoIndexService yohoIndexService;
|
|
|
30
|
+
|
|
|
31
|
+ @RequestMapping(value = "/vectorVersion")
|
|
|
32
|
+ @ResponseBody
|
|
|
33
|
+ public Map<String, Object> vectorVersion() {
|
|
|
34
|
+ Map<String, Object> results = new HashMap<String, Object>();
|
|
|
35
|
+ //大数据目前推荐的版本
|
|
|
36
|
+ String bigDataRecomDateStr = personalVectorVersionManager.getBigDataRecomDateStr();
|
|
|
37
|
+ results.put("bigDataRecomDateStr", bigDataRecomDateStr == null ? "" : bigDataRecomDateStr);
|
|
|
38
|
+ //zk中目前的版本
|
|
|
39
|
+ String currentVersionInZk = personalVectorVersionManager.getCurrentVersionInZk();
|
|
|
40
|
+ results.put("currentVersionInZk", currentVersionInZk);
|
|
|
41
|
+ //经过计算目前可以使用的版本
|
|
|
42
|
+ String currentVersion = personalVectorVersionManager.getCurrentVersion();
|
|
|
43
|
+ results.put("currentVersion", currentVersion);
|
|
|
44
|
+ return results;
|
|
|
45
|
+ }
|
|
|
46
|
+
|
|
|
47
|
+ @RequestMapping(value = "/bigdataServiceTest")
|
|
|
48
|
+ @ResponseBody
|
|
|
49
|
+ public Map<String, Object> bigdataServiceTets(Integer uid) {
|
|
|
50
|
+ Map<String, Object> results = new HashMap<String, Object>();
|
|
|
51
|
+ //大数据目前推荐的版本
|
|
|
52
|
+ String bigDataRecomDateStr = bidataServiceCaller.getBigDataRecomDateStr();
|
|
|
53
|
+ results.put("bigDataRecomDateStr", bigDataRecomDateStr == null ? "" : bigDataRecomDateStr);
|
|
|
54
|
+ results.put("userFavoriteSizes", bidataServiceCaller.getUserFavoriteSizes(uid.toString()));
|
|
|
55
|
+ results.put("userGenderFeature", bidataServiceCaller.getUserGenderFeature(uid.toString()));
|
|
|
56
|
+ results.put("userFavoriteSizes", bidataServiceCaller.getUserFavoriteSizes(uid.toString()));
|
|
|
57
|
+ results.put("userVectorFeature", bidataServiceCaller.getUserVectorFeature(uid.toString(), bigDataRecomDateStr));
|
|
|
58
|
+ results.put("userPersionalFactor", bidataServiceCaller.queryUserPersionalFactor(uid, null, null));
|
|
|
59
|
+ return results;
|
|
|
60
|
+ }
|
|
|
61
|
+
|
|
|
62
|
+ @RequestMapping(value = "/ip2IndexInfo")
|
|
|
63
|
+ @ResponseBody
|
|
|
64
|
+ public Map<String, Object> nodeAndShardInfo() {
|
|
|
65
|
+ IElasticsearchClient client = yohoIndexService.getElasticsearchClient(ISearchConstants.INDEX_NAME_PRODUCT_INDEX);
|
|
|
66
|
+ ClusterState clusterState = client.getClusterStateResponse().getState();
|
|
|
67
|
+ DiscoveryNodes discoveryNodes = clusterState.nodes();
|
|
|
68
|
+
|
|
|
69
|
+ Map<String, List<Map<String, Object>>> ip2IndexInfo = new HashMap<>();
|
|
|
70
|
+ Set<String> allIps = new HashSet<>();
|
|
|
71
|
+ Set<String> hasPrimaryIps = new HashSet<>();
|
|
|
72
|
+ for (ShardRouting shard : clusterState.routingTable().allShards()) {
|
|
|
73
|
+ String indexName = shard.getIndexName();
|
|
|
74
|
+ String hostAddress = discoveryNodes.get(shard.currentNodeId()).getHostAddress();
|
|
|
75
|
+ boolean isPrimary = shard.primary();
|
|
|
76
|
+ if(isPrimary){
|
|
|
77
|
+ hasPrimaryIps.add(hostAddress);
|
|
|
78
|
+ }
|
|
|
79
|
+ allIps.add(hostAddress);
|
|
|
80
|
+
|
|
|
81
|
+ List<Map<String, Object>> indexInfoList = ip2IndexInfo.computeIfAbsent(hostAddress,a->new ArrayList<>());
|
|
|
82
|
+ JSONObject indexInfo = new JSONObject();
|
|
|
83
|
+ indexInfo.put("index_name", indexName);
|
|
|
84
|
+ indexInfo.put("node_id", shard.currentNodeId());
|
|
|
85
|
+ indexInfo.put("is_primary", isPrimary);
|
|
|
86
|
+ indexInfo.put("host_address", hostAddress);
|
|
|
87
|
+ indexInfoList.add(indexInfo);
|
|
|
88
|
+ }
|
|
|
89
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
90
|
+ result.put("all",ip2IndexInfo);
|
|
|
91
|
+ result.put("hasPrimaryIps", StringUtils.join(hasPrimaryIps,","));
|
|
|
92
|
+ allIps.removeAll(hasPrimaryIps);
|
|
|
93
|
+ result.put("noPrimaryIps", StringUtils.join(allIps,","));
|
|
|
94
|
+ return result;
|
|
|
95
|
+ }
|
51
|
|
96
|
|
52
|
} |
97
|
} |