Search in sources :

Example 1 with StorageSource

use of com.enonic.xp.repo.impl.StorageSource in project xp by enonic.

the class StorageDaoImpl method store.

@Override
public String store(final StoreRequest request) {
    final StorageSource settings = request.getSettings();
    final IndexRequest indexRequest = Requests.indexRequest().index(settings.getStorageName().getName()).type(settings.getStorageType().getName()).source(XContentBuilderFactory.create(request)).id(request.getId()).refresh(request.isForceRefresh());
    if (request.getRouting() != null) {
        indexRequest.routing(request.getRouting());
    }
    if (request.getParent() != null) {
        indexRequest.parent(request.getParent());
    }
    return doStore(indexRequest, request.getTimeout());
}
Also used : IndexRequest(org.elasticsearch.action.index.IndexRequest) StorageSource(com.enonic.xp.repo.impl.StorageSource)

Example 2 with StorageSource

use of com.enonic.xp.repo.impl.StorageSource in project xp by enonic.

the class StorageDaoImpl method getByIds.

@Override
public GetResults getByIds(final GetByIdsRequest requests) {
    if (requests.getRequests().isEmpty()) {
        return new GetResults();
    }
    final MultiGetRequestBuilder multiGetRequestBuilder = new MultiGetRequestBuilder(this.client, MultiGetAction.INSTANCE).setPreference(SearchPreference.LOCAL.getName());
    for (final GetByIdRequest request : requests.getRequests()) {
        final StorageSource storageSource = request.getStorageSource();
        final MultiGetRequest.Item item = new MultiGetRequest.Item(storageSource.getStorageName().getName(), storageSource.getStorageType().getName(), request.getId());
        if (request.getReturnFields().isNotEmpty()) {
            item.fields(request.getReturnFields().getReturnFieldNames());
        }
        if (request.getRouting() != null) {
            item.routing(request.getRouting());
        }
        multiGetRequestBuilder.add(item);
    }
    final MultiGetResponse multiGetItemResponses = this.client.multiGet(multiGetRequestBuilder.request()).actionGet();
    return GetResultsFactory.create(multiGetItemResponses);
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) GetByIdRequest(com.enonic.xp.repo.impl.storage.GetByIdRequest) GetResults(com.enonic.xp.repo.impl.storage.GetResults) StorageSource(com.enonic.xp.repo.impl.StorageSource) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest)

Example 3 with StorageSource

use of com.enonic.xp.repo.impl.StorageSource in project xp by enonic.

the class StorageDaoImpl method delete.

@Override
public void delete(final DeleteRequests requests) {
    final StorageSource settings = requests.getSettings();
    for (final String id : requests.getIds()) {
        try {
            final org.elasticsearch.action.delete.DeleteRequest request = new DeleteRequestBuilder(this.client, DeleteAction.INSTANCE).setIndex(settings.getStorageName().getName()).setType(settings.getStorageType().getName()).setRefresh(requests.isForceRefresh()).setId(id).setRouting(// TODO Java10
            id).request();
            this.client.delete(request).actionGet(requests.getTimeoutAsString());
        } catch (ClusterBlockException e) {
            throw new NodeStorageException("Cannot delete node " + id + ", Repository in 'READ-ONLY mode'");
        } catch (Exception e) {
            throw new NodeStorageException("Cannot delete node " + id, e);
        }
    }
}
Also used : DeleteRequestBuilder(org.elasticsearch.action.delete.DeleteRequestBuilder) NodeStorageException(com.enonic.xp.node.NodeStorageException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) NodeStorageException(com.enonic.xp.node.NodeStorageException) StorageSource(com.enonic.xp.repo.impl.StorageSource)

Example 4 with StorageSource

use of com.enonic.xp.repo.impl.StorageSource in project xp by enonic.

the class StorageDaoImpl method getById.

@Override
public GetResult getById(final GetByIdRequest request) {
    final StorageSource storageSource = request.getStorageSource();
    final GetRequest getRequest = new GetRequest(storageSource.getStorageName().getName()).type(storageSource.getStorageType().getName()).preference(request.getSearchPreference().getName()).id(request.getId());
    if (request.getReturnFields().isNotEmpty()) {
        getRequest.fields(request.getReturnFields().getReturnFieldNames());
    }
    if (request.getRouting() != null) {
        getRequest.routing(request.getRouting());
    }
    final GetResponse getResponse = client.get(getRequest).actionGet(request.getTimeout());
    return GetResultFactory.create(getResponse);
}
Also used : MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) GetRequest(org.elasticsearch.action.get.GetRequest) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) StorageSource(com.enonic.xp.repo.impl.StorageSource)

Example 5 with StorageSource

use of com.enonic.xp.repo.impl.StorageSource in project xp by enonic.

the class StorageDaoImpl method delete.

@Override
public boolean delete(final DeleteRequest request) {
    final StorageSource settings = request.getSettings();
    final String id = request.getId();
    final DeleteRequestBuilder builder = new DeleteRequestBuilder(this.client, DeleteAction.INSTANCE).setId(id).setIndex(settings.getStorageName().getName()).setType(settings.getStorageType().getName()).setRefresh(request.isForceRefresh());
    final DeleteResponse deleteResponse;
    try {
        deleteResponse = this.client.delete(builder.request()).actionGet(request.getTimeoutAsString());
    } catch (ClusterBlockException e) {
        throw new NodeStorageException("Cannot delete node " + id + ", Repository in 'READ-ONLY mode'");
    } catch (Exception e) {
        throw new NodeStorageException("Cannot delete node " + id, e);
    }
    return deleteResponse.isFound();
}
Also used : DeleteRequestBuilder(org.elasticsearch.action.delete.DeleteRequestBuilder) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) NodeStorageException(com.enonic.xp.node.NodeStorageException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) NodeStorageException(com.enonic.xp.node.NodeStorageException) StorageSource(com.enonic.xp.repo.impl.StorageSource)

Aggregations

StorageSource (com.enonic.xp.repo.impl.StorageSource)5 NodeStorageException (com.enonic.xp.node.NodeStorageException)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 DeleteRequestBuilder (org.elasticsearch.action.delete.DeleteRequestBuilder)2 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)2 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)2 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)2 GetByIdRequest (com.enonic.xp.repo.impl.storage.GetByIdRequest)1 GetResults (com.enonic.xp.repo.impl.storage.GetResults)1 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)1 GetRequest (org.elasticsearch.action.get.GetRequest)1 GetResponse (org.elasticsearch.action.get.GetResponse)1 MultiGetRequestBuilder (org.elasticsearch.action.get.MultiGetRequestBuilder)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1