Search in sources :

Example 11 with ElasticSearchClient

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

the class NetworkAddressRegisterEsDAO method update.

@Override
public void update(String id, int spanLayer, int serverType) {
    ElasticSearchClient client = getClient();
    Map<String, Object> source = new HashMap<>();
    source.put(NetworkAddressTable.COLUMN_SPAN_LAYER, spanLayer);
    source.put(NetworkAddressTable.COLUMN_SERVER_TYPE, serverType);
    client.prepareUpdate(NetworkAddressTable.TABLE, id).setDoc(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
}
Also used : HashMap(java.util.HashMap) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)

Example 12 with ElasticSearchClient

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

the class ApplicationEsCacheDAO method getApplicationIdByAddressId.

@Override
public int getApplicationIdByAddressId(int addressId) {
    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_ADDRESS_ID, addressId));
    boolQueryBuilder.must().add(QueryBuilders.termQuery(ApplicationTable.COLUMN_IS_ADDRESS, BooleanUtils.TRUE));
    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 13 with ElasticSearchClient

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

the class NetworkAddressEsCacheDAO method getAddress.

@Override
public NetworkAddress getAddress(int addressId) {
    ElasticSearchClient client = getClient();
    GetRequestBuilder getRequestBuilder = client.prepareGet(NetworkAddressTable.TABLE, String.valueOf(addressId));
    GetResponse getResponse = getRequestBuilder.get();
    if (getResponse.isExists()) {
        NetworkAddress address = new NetworkAddress();
        address.setId((String) getResponse.getSource().get(NetworkAddressTable.COLUMN_ID));
        address.setAddressId(((Number) getResponse.getSource().get(NetworkAddressTable.COLUMN_ADDRESS_ID)).intValue());
        address.setSpanLayer(((Number) getResponse.getSource().get(NetworkAddressTable.COLUMN_SPAN_LAYER)).intValue());
        address.setServerType(((Number) getResponse.getSource().get(NetworkAddressTable.COLUMN_SERVER_TYPE)).intValue());
        address.setNetworkAddress((String) getResponse.getSource().get(NetworkAddressTable.COLUMN_NETWORK_ADDRESS));
        return address;
    }
    return null;
}
Also used : NetworkAddress(org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) GetResponse(org.elasticsearch.action.get.GetResponse) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Example 14 with ElasticSearchClient

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

the class InstanceEsCacheDAO method getInstanceIdByAgentUUID.

@Override
public int getInstanceIdByAgentUUID(int applicationId, String agentUUID) {
    ElasticSearchClient client = getClient();
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(InstanceTable.TABLE);
    searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH);
    BoolQueryBuilder builder = QueryBuilders.boolQuery();
    builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
    builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_AGENT_UUID, agentUUID));
    builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE));
    searchRequestBuilder.setQuery(builder);
    searchRequestBuilder.setSize(1);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    if (searchResponse.getHits().totalHits > 0) {
        SearchHit searchHit = searchResponse.getHits().iterator().next();
        return (int) searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_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 15 with ElasticSearchClient

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

the class InstanceEsCacheDAO method getInstanceIdByAddressId.

@Override
public int getInstanceIdByAddressId(int applicationId, int addressId) {
    ElasticSearchClient client = getClient();
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(InstanceTable.TABLE);
    searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
    searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH);
    BoolQueryBuilder builder = QueryBuilders.boolQuery();
    builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
    builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_ADDRESS_ID, addressId));
    builder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.TRUE));
    searchRequestBuilder.setQuery(builder);
    searchRequestBuilder.setSize(1);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    if (searchResponse.getHits().totalHits > 0) {
        SearchHit searchHit = searchResponse.getHits().iterator().next();
        return (int) searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_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)

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