Search in sources :

Example 1 with ServiceInfo

use of org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo in project incubator-skywalking by apache.

the class ServiceNameServiceH2UIDAO method searchService.

@Override
public List<ServiceInfo> searchService(String keyword, int topN) {
    String dynamicSql = "select {0},{1} from {2} where {3} like ? and {4} = ? limit ?";
    String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.COLUMN_SRC_SPAN_TYPE);
    Object[] params = new Object[] { keyword, SpanType.Entry_VALUE, topN };
    List<ServiceInfo> serviceInfos = new LinkedList<>();
    try (ResultSet rs = getClient().executeQuery(sql, params)) {
        while (rs.next()) {
            ServiceInfo serviceInfo = new ServiceInfo();
            serviceInfo.setId(rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID));
            serviceInfo.setName(rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME));
            serviceInfos.add(serviceInfo);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return serviceInfos;
}
Also used : ServiceInfo(org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) LinkedList(java.util.LinkedList)

Example 2 with ServiceInfo

use of org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo in project incubator-skywalking by apache.

the class ServiceNameServiceEsUIDAO method searchService.

@Override
public List<ServiceInfo> searchService(String keyword, int topN) {
    SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceNameTable.TABLE);
    searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
    searchRequestBuilder.setSize(topN);
    if (StringUtils.isNotEmpty(keyword)) {
        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
        boolQuery.must().add(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_SERVICE_NAME, keyword));
        boolQuery.must().add(QueryBuilders.termQuery(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, SpanType.Entry_VALUE));
        searchRequestBuilder.setQuery(boolQuery);
    } else {
        searchRequestBuilder.setQuery(QueryBuilders.termQuery(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, SpanType.Entry_VALUE));
    }
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    SearchHit[] searchHits = searchResponse.getHits().getHits();
    List<ServiceInfo> serviceInfos = new LinkedList<>();
    for (SearchHit searchHit : searchHits) {
        ServiceInfo serviceInfo = new ServiceInfo();
        serviceInfo.setId(((Number) searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_ID)).intValue());
        serviceInfo.setName((String) searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME));
        serviceInfos.add(serviceInfo);
    }
    return serviceInfos;
}
Also used : ServiceInfo(org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) LinkedList(java.util.LinkedList) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

LinkedList (java.util.LinkedList)2 ServiceInfo (org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 SearchHit (org.elasticsearch.search.SearchHit)1