Provide the getAllServer query, but only completed es storage and non tps.
This commit is contained in:
parent
f177ebd909
commit
0ee4b1c30d
|
|
@ -36,5 +36,7 @@ public interface IInstanceUIDAO extends DAO {
|
|||
|
||||
Instance getInstance(int instanceId);
|
||||
|
||||
List<AppServerInfo> getInstances(String keyword, long start, long end);
|
||||
List<AppServerInfo> searchServer(String keyword, long start, long end);
|
||||
|
||||
List<AppServerInfo> getAllServer(int applicationId, long start, long end);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override public List<AppServerInfo> getInstances(String keyword, long start, long end) {
|
||||
@Override public List<AppServerInfo> searchServer(String keyword, long start, long end) {
|
||||
logger.debug("get instances info, keyword: {}, start: {}, end: {}", keyword, start, end);
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
|
||||
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
|
||||
|
|
@ -167,6 +167,29 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
|
|||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
SearchHit[] searchHits = searchResponse.getHits().getHits();
|
||||
|
||||
return buildAppServerInfo(searchHits);
|
||||
}
|
||||
|
||||
@Override public List<AppServerInfo> getAllServer(int applicationId, long start, long end) {
|
||||
logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, start, end);
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
|
||||
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
searchRequestBuilder.setSize(1000);
|
||||
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(start).lte(end));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE));
|
||||
searchRequestBuilder.setQuery(boolQuery);
|
||||
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
SearchHit[] searchHits = searchResponse.getHits().getHits();
|
||||
|
||||
return buildAppServerInfo(searchHits);
|
||||
}
|
||||
|
||||
private List<AppServerInfo> buildAppServerInfo(SearchHit[] searchHits) {
|
||||
List<AppServerInfo> appServerInfos = new LinkedList<>();
|
||||
for (SearchHit searchHit : searchHits) {
|
||||
AppServerInfo appServerInfo = new AppServerInfo();
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
|
|||
private static final String GET_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? limit 1";
|
||||
private static final String GET_INST_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? and {3} = ? limit 1";
|
||||
private static final String GET_INSTANCE_SQL = "select * from {0} where {1} = ?";
|
||||
private static final String GET_INSTANCES_SQL = "select * from {0} where {1} like ? and {2} >= ? and {2} <= ? and {3} = ?";
|
||||
private static final String GET_APPLICATIONS_SQL = "select {3}, count({0}) as cnt from {1} where {2} >= ? group by {3} limit 100";
|
||||
|
||||
@Override
|
||||
|
|
@ -132,12 +131,26 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override public List<AppServerInfo> getInstances(String keyword, long start, long end) {
|
||||
@Override public List<AppServerInfo> searchServer(String keyword, long start, long end) {
|
||||
logger.debug("get instances info, keyword: {}, start: {}, end: {}", keyword, start, end);
|
||||
List<AppServerInfo> appServerInfos = new LinkedList<>();
|
||||
H2Client client = getClient();
|
||||
String sql = SqlBuilder.buildSql(GET_INSTANCES_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_OS_INFO, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_IS_ADDRESS);
|
||||
String dynamicSql = "select * from {0} where {1} like ? and {2} >= ? and {2} <= ? and {3} = ?";
|
||||
String sql = SqlBuilder.buildSql(dynamicSql, InstanceTable.TABLE, InstanceTable.COLUMN_OS_INFO, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_IS_ADDRESS);
|
||||
Object[] params = new Object[] {keyword, start, end, BooleanUtils.FALSE};
|
||||
return buildAppServerInfo(sql, params);
|
||||
}
|
||||
|
||||
@Override public List<AppServerInfo> getAllServer(int applicationId, long start, long end) {
|
||||
logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, start, end);
|
||||
String dynamicSql = "select * from {0} where {1} = ? and {2} >= ? and {2} <= ? and {3} = ?";
|
||||
String sql = SqlBuilder.buildSql(dynamicSql, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_IS_ADDRESS);
|
||||
Object[] params = new Object[] {applicationId, start, end, BooleanUtils.FALSE};
|
||||
return buildAppServerInfo(sql, params);
|
||||
}
|
||||
|
||||
private List<AppServerInfo> buildAppServerInfo(String sql, Object[] params) {
|
||||
H2Client client = getClient();
|
||||
|
||||
List<AppServerInfo> appServerInfos = new LinkedList<>();
|
||||
try (ResultSet rs = client.executeQuery(sql, params)) {
|
||||
while (rs.next()) {
|
||||
AppServerInfo appServerInfo = new AppServerInfo();
|
||||
|
|
|
|||
|
|
@ -58,8 +58,10 @@ public class ServerQuery implements Query {
|
|||
return getServerService().searchServer(keyword, start, end);
|
||||
}
|
||||
|
||||
public List<AppServerInfo> getAllServer(String applicationId, Duration duration) {
|
||||
return null;
|
||||
public List<AppServerInfo> getAllServer(int applicationId, Duration duration) throws ParseException {
|
||||
long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
|
||||
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
|
||||
return getServerService().getAllServer(applicationId, start, end);
|
||||
}
|
||||
|
||||
public ResponseTimeTrend getServerResponseTimeTrend(int serverId, Duration duration) {
|
||||
|
|
|
|||
|
|
@ -43,13 +43,24 @@ public class ServerService {
|
|||
}
|
||||
|
||||
public List<AppServerInfo> searchServer(String keyword, long start, long end) {
|
||||
List<AppServerInfo> serverInfos = instanceDAO.getInstances(keyword, start, end);
|
||||
List<AppServerInfo> serverInfos = instanceDAO.searchServer(keyword, start, end);
|
||||
serverInfos.forEach(serverInfo -> {
|
||||
if (serverInfo.getId() == Const.NONE_INSTANCE_ID) {
|
||||
serverInfos.remove(serverInfo);
|
||||
}
|
||||
});
|
||||
|
||||
buildAppServerInfo(serverInfos);
|
||||
return serverInfos;
|
||||
}
|
||||
|
||||
public List<AppServerInfo> getAllServer(int applicationId, long start, long end) {
|
||||
List<AppServerInfo> serverInfos = instanceDAO.getAllServer(applicationId, start, end);
|
||||
buildAppServerInfo(serverInfos);
|
||||
return serverInfos;
|
||||
}
|
||||
|
||||
private void buildAppServerInfo(List<AppServerInfo> serverInfos) {
|
||||
serverInfos.forEach(serverInfo -> {
|
||||
if (StringUtils.isNotEmpty(serverInfo.getOsInfo())) {
|
||||
JsonObject osInfoJson = gson.fromJson(serverInfo.getOsInfo(), JsonObject.class);
|
||||
|
|
@ -74,7 +85,5 @@ public class ServerService {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
return serverInfos;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue