Search in sources :

Example 51 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project incubator-skywalking by apache.

the class ApplicationReferenceAlarmEsPersistenceDAO method get.

@Override
public ApplicationReferenceAlarm get(String id) {
    GetResponse getResponse = getClient().prepareGet(ApplicationReferenceAlarmTable.TABLE, id).get();
    if (getResponse.isExists()) {
        ApplicationReferenceAlarm applicationReferenceAlarm = new ApplicationReferenceAlarm();
        applicationReferenceAlarm.setId(id);
        Map<String, Object> source = getResponse.getSource();
        applicationReferenceAlarm.setFrontApplicationId(((Number) source.get(ApplicationReferenceAlarmTable.COLUMN_FRONT_APPLICATION_ID)).intValue());
        applicationReferenceAlarm.setBehindApplicationId(((Number) source.get(ApplicationReferenceAlarmTable.COLUMN_BEHIND_APPLICATION_ID)).intValue());
        applicationReferenceAlarm.setSourceValue(((Number) source.get(ApplicationReferenceAlarmTable.COLUMN_SOURCE_VALUE)).intValue());
        applicationReferenceAlarm.setAlarmType(((Number) source.get(ApplicationReferenceAlarmTable.COLUMN_ALARM_TYPE)).intValue());
        applicationReferenceAlarm.setAlarmContent((String) source.get(ApplicationReferenceAlarmTable.COLUMN_ALARM_CONTENT));
        applicationReferenceAlarm.setLastTimeBucket(((Number) source.get(ApplicationReferenceAlarmTable.COLUMN_LAST_TIME_BUCKET)).longValue());
        return applicationReferenceAlarm;
    } else {
        return null;
    }
}
Also used : GetResponse(org.elasticsearch.action.get.GetResponse) ApplicationReferenceAlarm(org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationReferenceAlarm)

Example 52 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project incubator-skywalking by apache.

the class InstanceEsUIDAO method getInstance.

@Override
public Instance getInstance(int instanceId) {
    logger.debug("get instance info, instance id: {}", instanceId);
    GetRequestBuilder requestBuilder = getClient().prepareGet(InstanceTable.TABLE, String.valueOf(instanceId));
    GetResponse getResponse = requestBuilder.get();
    if (getResponse.isExists()) {
        Instance instance = new Instance();
        instance.setId(getResponse.getId());
        instance.setApplicationId(((Number) getResponse.getSource().get(InstanceTable.COLUMN_APPLICATION_ID)).intValue());
        instance.setAgentUUID((String) getResponse.getSource().get(InstanceTable.COLUMN_AGENT_UUID));
        instance.setRegisterTime(((Number) getResponse.getSource().get(InstanceTable.COLUMN_REGISTER_TIME)).longValue());
        instance.setHeartBeatTime(((Number) getResponse.getSource().get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue());
        instance.setOsInfo((String) getResponse.getSource().get(InstanceTable.COLUMN_OS_INFO));
        return instance;
    }
    return null;
}
Also used : Instance(org.apache.skywalking.apm.collector.storage.table.register.Instance) GetResponse(org.elasticsearch.action.get.GetResponse) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Example 53 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project incubator-skywalking by apache.

the class SegmentEsUIDAO method load.

@Override
public TraceSegmentObject load(String segmentId) {
    GetResponse response = getClient().prepareGet(SegmentTable.TABLE, segmentId).get();
    Map<String, Object> source = response.getSource();
    String dataBinaryBase64 = (String) source.get(SegmentTable.COLUMN_DATA_BINARY);
    if (StringUtils.isNotEmpty(dataBinaryBase64)) {
        byte[] dataBinary = Base64.getDecoder().decode(dataBinaryBase64);
        try {
            return TraceSegmentObject.parseFrom(dataBinary);
        } catch (InvalidProtocolBufferException e) {
            logger.error(e.getMessage(), e);
        }
    }
    return null;
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject) GetResponse(org.elasticsearch.action.get.GetResponse)

Example 54 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project incubator-skywalking by apache.

the class ServiceNameEsCacheDAO method get.

@Override
public ServiceName get(int serviceId) {
    GetRequestBuilder getRequestBuilder = getClient().prepareGet(ServiceNameTable.TABLE, String.valueOf(serviceId));
    GetResponse getResponse = getRequestBuilder.get();
    if (getResponse.isExists()) {
        ServiceName serviceName = new ServiceName();
        serviceName.setApplicationId(((Number) getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue());
        serviceName.setServiceId(serviceId);
        serviceName.setServiceName((String) getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME));
        return serviceName;
    }
    return null;
}
Also used : ServiceName(org.apache.skywalking.apm.collector.storage.table.register.ServiceName) GetResponse(org.elasticsearch.action.get.GetResponse) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Example 55 with GetResponse

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project opencast by opencast.

the class AbstractElasticsearchIndex method createIndex.

/**
 * Prepares Elasticsearch index to store data for the types (or mappings) as returned by {@link #getDocumenTypes()}.
 *
 * @param idx
 *          the index name
 *
 * @throws SearchIndexException
 *           if index and type creation fails
 * @throws IOException
 *           if loading of the type definitions fails
 */
private void createIndex(String idx) throws SearchIndexException, IOException {
    // Make sure the site index exists
    try {
        logger.debug("Trying to create index for '{}'", idx);
        CreateIndexRequest indexCreateRequest = new CreateIndexRequest(idx);
        String settings = getIndexSettings(idx);
        if (settings != null)
            indexCreateRequest.settings(settings);
        CreateIndexResponse siteidxResponse = nodeClient.admin().indices().create(indexCreateRequest).actionGet();
        if (!siteidxResponse.isAcknowledged()) {
            throw new SearchIndexException("Unable to create index for '" + idx + "'");
        }
    } catch (IndexAlreadyExistsException e) {
        logger.info("Detected existing index '{}'", idx);
    }
    // Store the correct mapping
    for (String type : getDocumenTypes()) {
        PutMappingRequest siteMappingRequest = new PutMappingRequest(idx);
        siteMappingRequest.source(getIndexTypeDefinition(idx, type));
        siteMappingRequest.type(type);
        PutMappingResponse siteMappingResponse = nodeClient.admin().indices().putMapping(siteMappingRequest).actionGet();
        if (!siteMappingResponse.isAcknowledged()) {
            throw new SearchIndexException("Unable to install '" + type + "' mapping for index '" + idx + "'");
        }
    }
    // See if the index version exists and check if it matches. The request will
    // fail if there is no version index
    boolean versionIndexExists = false;
    GetRequestBuilder getRequestBuilder = nodeClient.prepareGet(idx, VERSION_TYPE, ROOT_ID);
    try {
        GetResponse response = getRequestBuilder.execute().actionGet();
        if (response.isExists() && response.getField(VERSION) != null) {
            int actualIndexVersion = Integer.parseInt((String) response.getField(VERSION).getValue());
            if (indexVersion != actualIndexVersion)
                throw new SearchIndexException("Search index is at version " + actualIndexVersion + ", but codebase expects " + indexVersion);
            versionIndexExists = true;
            logger.debug("Search index version is {}", indexVersion);
        }
    } catch (ElasticsearchException e) {
        logger.debug("Version index has not been created");
    }
    // The index does not exist, let's create it
    if (!versionIndexExists) {
        logger.debug("Creating version index for site '{}'", idx);
        IndexRequestBuilder requestBuilder = nodeClient.prepareIndex(idx, VERSION_TYPE, ROOT_ID);
        logger.debug("Index version of site '{}' is {}", idx, indexVersion);
        requestBuilder = requestBuilder.setSource(VERSION, Integer.toString(indexVersion));
        requestBuilder.execute().actionGet();
    }
    preparedIndices.add(idx);
}
Also used : SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) GetResponse(org.elasticsearch.action.get.GetResponse) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) IndexAlreadyExistsException(org.elasticsearch.indices.IndexAlreadyExistsException) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Aggregations

GetResponse (org.elasticsearch.action.get.GetResponse)167 Test (org.junit.Test)50 GetRequest (org.elasticsearch.action.get.GetRequest)28 Map (java.util.Map)27 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)26 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)21 Date (java.util.Date)18 ESSyncConfig (com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig)17 Dml (com.alibaba.otter.canal.client.adapter.support.Dml)17 LinkedHashMap (java.util.LinkedHashMap)17 IOException (java.io.IOException)16 DataSource (javax.sql.DataSource)14 GetRequestBuilder (org.elasticsearch.action.get.GetRequestBuilder)14 SearchResponse (org.elasticsearch.action.search.SearchResponse)14 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)10 Settings (org.elasticsearch.common.settings.Settings)10 Alias (org.elasticsearch.action.admin.indices.alias.Alias)7 IndexResponse (org.elasticsearch.action.index.IndexResponse)7