Search in sources :

Example 1 with NodeStorageException

use of com.enonic.xp.node.NodeStorageException 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 2 with NodeStorageException

use of com.enonic.xp.node.NodeStorageException 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)

Example 3 with NodeStorageException

use of com.enonic.xp.node.NodeStorageException in project xp by enonic.

the class DeleteNodeByIdCommandTest_error_handling method delete_children_first.

@Test
public void delete_children_first() throws Exception {
    final Node n1 = createNode(NodePath.ROOT, "n1");
    final Node n2 = createNode(NodePath.ROOT, "n2");
    final Node n1_1 = createNode(n1.path(), "n1_1");
    final Node n1_1_1 = createNode(n1_1.path(), "n1_1_1");
    final Node n1_1_1_1 = createNode(n1_1_1.path(), "n1_1_1_1");
    refresh();
    this.storageDao.setClient(new FailDeleteOnIdsProxy(client, NodeIds.from(n1_1.id())));
    try {
        doDeleteNode(n1.id());
    } catch (NodeStorageException e) {
    // expected
    }
    assertNull(getNode(n1_1_1_1.id()));
    assertNull(getNode(n1_1_1.id()));
    assertNotNull(getNode(n1_1.id()));
    assertNotNull(getNode(n1.id()));
    assertNotNull(getNode(n2.id()));
}
Also used : Node(com.enonic.xp.node.Node) NodeStorageException(com.enonic.xp.node.NodeStorageException) Test(org.junit.jupiter.api.Test)

Aggregations

NodeStorageException (com.enonic.xp.node.NodeStorageException)3 StorageSource (com.enonic.xp.repo.impl.StorageSource)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 DeleteRequestBuilder (org.elasticsearch.action.delete.DeleteRequestBuilder)2 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)2 Node (com.enonic.xp.node.Node)1 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)1 Test (org.junit.jupiter.api.Test)1