Search in sources :

Example 6 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class ApplicationEsCacheDAO method getApplication.

@Override
public Application getApplication(int applicationId) {
    logger.debug("get application code, applicationId: {}", applicationId);
    ElasticSearchClient client = getClient();
    GetRequestBuilder getRequestBuilder = client.prepareGet(ApplicationTable.TABLE, String.valueOf(applicationId));
    GetResponse getResponse = getRequestBuilder.get();
    if (getResponse.isExists()) {
        Application application = new Application();
        application.setApplicationId(applicationId);
        application.setApplicationCode((String) getResponse.getSource().get(ApplicationTable.COLUMN_APPLICATION_CODE));
        application.setIsAddress(((Number) getResponse.getSource().get(ApplicationTable.COLUMN_IS_ADDRESS)).intValue());
        return application;
    }
    return null;
}
Also used : ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) GetResponse(org.elasticsearch.action.get.GetResponse) Application(org.apache.skywalking.apm.collector.storage.table.register.Application) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Example 7 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class ApplicationEsCacheDAO method getApplicationIdByCode.

@Override
public int getApplicationIdByCode(String applicationCode) {
    ElasticSearchClient client = getClient();
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(ApplicationTable.TABLE);
    searchRequestBuilder.setTypes(ApplicationTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH);
    BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    boolQueryBuilder.must().add(QueryBuilders.termQuery(ApplicationTable.COLUMN_APPLICATION_CODE, applicationCode));
    boolQueryBuilder.must().add(QueryBuilders.termQuery(ApplicationTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE));
    searchRequestBuilder.setQuery(boolQueryBuilder);
    searchRequestBuilder.setSize(1);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    if (searchResponse.getHits().totalHits > 0) {
        SearchHit searchHit = searchResponse.getHits().iterator().next();
        return (int) searchHit.getSource().get(ApplicationTable.COLUMN_APPLICATION_ID);
    }
    return 0;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 8 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class NetworkAddressEsCacheDAO method getAddressId.

@Override
public int getAddressId(String networkAddress) {
    ElasticSearchClient client = getClient();
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(NetworkAddressTable.TABLE);
    searchRequestBuilder.setTypes(NetworkAddressTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH);
    searchRequestBuilder.setQuery(QueryBuilders.termQuery(NetworkAddressTable.COLUMN_NETWORK_ADDRESS, networkAddress));
    searchRequestBuilder.setSize(1);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    if (searchResponse.getHits().totalHits > 0) {
        SearchHit searchHit = searchResponse.getHits().iterator().next();
        return ((Number) searchHit.getSource().get(NetworkAddressTable.COLUMN_ADDRESS_ID)).intValue();
    }
    return Const.NONE;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 9 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class NetworkAddressEsCacheDAO method getAddressById.

@Override
public String getAddressById(int addressId) {
    logger.debug("get network address, address id: {}", addressId);
    ElasticSearchClient client = getClient();
    GetRequestBuilder getRequestBuilder = client.prepareGet(NetworkAddressTable.TABLE, String.valueOf(addressId));
    GetResponse getResponse = getRequestBuilder.get();
    if (getResponse.isExists()) {
        return (String) getResponse.getSource().get(NetworkAddressTable.COLUMN_NETWORK_ADDRESS);
    }
    return Const.EMPTY_STRING;
}
Also used : ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) GetResponse(org.elasticsearch.action.get.GetResponse) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Example 10 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class NetworkAddressRegisterEsDAO method save.

@Override
public void save(NetworkAddress networkAddress) {
    logger.debug("save network address register info, address getApplicationId: {}, network address code: {}", networkAddress.getId(), networkAddress.getNetworkAddress());
    ElasticSearchClient client = getClient();
    Map<String, Object> source = new HashMap<>();
    source.put(NetworkAddressTable.COLUMN_NETWORK_ADDRESS, networkAddress.getNetworkAddress());
    source.put(NetworkAddressTable.COLUMN_ADDRESS_ID, networkAddress.getAddressId());
    source.put(NetworkAddressTable.COLUMN_SPAN_LAYER, networkAddress.getSpanLayer());
    source.put(NetworkAddressTable.COLUMN_SERVER_TYPE, networkAddress.getServerType());
    IndexResponse response = client.prepareIndex(NetworkAddressTable.TABLE, networkAddress.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    logger.debug("save network address register info, address getApplicationId: {}, network address code: {}, status: {}", networkAddress.getAddressId(), networkAddress.getNetworkAddress(), response.status().name());
}
Also used : HashMap(java.util.HashMap) IndexResponse(org.elasticsearch.action.index.IndexResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)

Aggregations

ElasticSearchClient (org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)17 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)7 SearchResponse (org.elasticsearch.action.search.SearchResponse)7 HashMap (java.util.HashMap)5 SearchHit (org.elasticsearch.search.SearchHit)5 IndexResponse (org.elasticsearch.action.index.IndexResponse)4 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)4 GetRequestBuilder (org.elasticsearch.action.get.GetRequestBuilder)3 GetResponse (org.elasticsearch.action.get.GetResponse)3 IOException (java.io.IOException)1 BatchEsDAO (org.apache.skywalking.apm.collector.storage.es.base.dao.BatchEsDAO)1 Application (org.apache.skywalking.apm.collector.storage.table.register.Application)1 NetworkAddress (org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress)1 Settings (org.elasticsearch.common.settings.Settings)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1 Max (org.elasticsearch.search.aggregations.metrics.max.Max)1 MaxAggregationBuilder (org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder)1 Min (org.elasticsearch.search.aggregations.metrics.min.Min)1 MinAggregationBuilder (org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder)1