use of beans.response.QueryESClusterDetailResponse in project MSEC by Tencent.
the class QueryESClusterDetail method exec.
public QueryESClusterDetailResponse exec(QueryESClusterDetailRequest request) {
Logger logger = Logger.getLogger(QueryESClusterDetail.class);
QueryESClusterDetailResponse resp = new QueryESClusterDetailResponse();
String result = checkIdentity();
if (!result.equals("success")) {
resp.setStatus(99);
resp.setMessage(result);
return resp;
}
boolean all_ok = true;
int master_num = 0;
util = new DBUtil();
if (util.getConnection() == null) {
resp.setStatus(100);
resp.setMessage("db connect failed!");
return resp;
}
cluster_ips = new ArrayList<>();
HashMap<String, QueryESClusterDetailResponse.RTInfo> info_map = new HashMap<>();
try {
if (updatePlan(request.getFirst_level_service_name(), request.getSecond_level_service_name())) {
resp.setMessage("refresh");
resp.setStatus(101);
return resp;
}
getStatus(request.getFirst_level_service_name(), request.getSecond_level_service_name());
ESHelper helper = new ESHelper();
helper.ClusterStatus(cluster_ips, request.getFirst_level_service_name() + "." + request.getSecond_level_service_name(), resp);
if (resp.getHealth_status() != "INIT") {
for (Map.Entry<String, QueryESClusterDetailResponse.RTInfo> entry : resp.getInfo_map().entrySet()) {
if (!cluster_ips.contains(entry.getKey())) {
// add ip to service
addServer(request.getSecond_level_service_name(), request.getSecond_level_service_name(), entry.getKey(), resp.getServer_port());
resp.setMessage("refresh");
resp.setStatus(101);
return resp;
}
}
for (String ip : cluster_ips) {
QueryESClusterDetailResponse.RTInfo rt_info = resp.getInfo_map().get(ip);
if (rt_info != null) {
if (!rt_info.isOK()) {
logger.error(String.format("ip failed|%s", ip));
}
updateStatus(request.getFirst_level_service_name(), request.getSecond_level_service_name(), ip, rt_info.isOK());
} else {
resp.getInfo_map().put(ip, new QueryESClusterDetailResponse().new RTInfo());
updateStatus(request.getFirst_level_service_name(), request.getSecond_level_service_name(), ip, false);
}
}
}
} catch (Exception e) {
logger.error(e);
e.printStackTrace();
} finally {
util.releaseConn();
}
return resp;
}
use of beans.response.QueryESClusterDetailResponse in project MSEC by Tencent.
the class ESHelper method ClusterStatus.
public void ClusterStatus(ArrayList<String> ips, String cluster_name, QueryESClusterDetailResponse response) {
Logger logger = Logger.getLogger(ESHelper.class);
TransportClient client = null;
HashSet<String> total_ips = new HashSet<>(ips);
try {
Settings settings = Settings.builder().put("cluster.name", cluster_name).put("client.transport.sniff", true).build();
for (String ip : ips) {
if (client == null) {
client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), default_client_port));
} else
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ip), default_client_port));
}
ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setTimeout(TimeValue.timeValueSeconds(5)).execute().actionGet();
if (healthResponse != null && !healthResponse.isTimedOut()) {
response.setActive_shards(healthResponse.getActiveShards());
response.setTotal_shards(healthResponse.getActiveShards() + healthResponse.getUnassignedShards());
response.setHealth_status(healthResponse.getStatus().toString().toLowerCase());
response.setServer_port(default_port);
logger.info(healthResponse);
if (healthResponse.getNumberOfNodes() > 0) {
NodesStatsResponse nodeStats = client.admin().cluster().prepareNodesStats().all().get();
if (nodeStats != null) {
for (NodeStats stats : nodeStats.getNodes()) {
QueryESClusterDetailResponse.RTInfo info = new QueryESClusterDetailResponse().new RTInfo();
info.setOK(true);
info.setAvail_disk_size(stats.getFs().getTotal().getAvailable().getBytes());
info.setDoc_count(stats.getIndices().getDocs().getCount());
info.setDoc_disk_size(stats.getIndices().getStore().getSizeInBytes());
response.getInfo_map().put(stats.getNode().getAddress().getHost(), info);
total_ips.add(stats.getNode().getAddress().getHost());
}
}
}
}
// update Zen settings
client.admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder().put("discovery.zen.minimum_master_nodes", total_ips.size() / 2 + 1)).setTransientSettings(Settings.builder().put("discovery.zen.minimum_master_nodes", total_ips.size() / 2 + 1)).get();
// update template settings
PutIndexTemplateResponse tpl_resp = client.admin().indices().preparePutTemplate("template_msec").setTemplate("msec_*").setSettings(Settings.builder().put("number_of_replicas", 1).put("refresh_interval", "30s")).addMapping("logs", MAPPING).execute().get();
logger.info("Create mapping: " + tpl_resp.isAcknowledged());
} catch (UnknownHostException e) {
logger.error(e);
} catch (Exception e) {
logger.error(e);
} finally {
if (client != null)
client.close();
}
}
Aggregations