Search in sources :

Example 96 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class DanglingIndicesRestIT method testDanglingIndicesCanBeDeleted.

/**
 * Check that dangling indices can be deleted. Since this requires that
 * we add an entry to the index graveyard, the graveyard size must be
 * greater than 1. To test deletes, we set the index graveyard size to
 * 1, then create two indices and delete them both while one node in
 * the cluster is stopped. The deletion of the second pushes the deletion
 * of the first out of the graveyard. When the stopped node is resumed,
 * only the second index will be found into the graveyard and the the
 * other will be considered dangling, and can therefore be listed and
 * deleted through the API
 */
public void testDanglingIndicesCanBeDeleted() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(1);
    internalCluster().startNodes(3, buildSettings(1));
    createDanglingIndices(INDEX_NAME, OTHER_INDEX_NAME);
    final RestClient restClient = getRestClient();
    final List<String> danglingIndexIds = listDanglingIndexIds();
    assertThat(danglingIndexIds, hasSize(1));
    final Request deleteRequest = new Request("DELETE", "/_dangling/" + danglingIndexIds.get(0));
    deleteRequest.addParameter("accept_data_loss", "true");
    // Ensure these parameters is accepted
    deleteRequest.addParameter("timeout", "20s");
    deleteRequest.addParameter("master_timeout", "20s");
    final Response deleteResponse = restClient.performRequest(deleteRequest);
    assertThat(deleteResponse.getStatusLine().getStatusCode(), equalTo(ACCEPTED.getStatus()));
    final XContentTestUtils.JsonMapView mapView = createJsonMapView(deleteResponse.getEntity().getContent());
    assertThat(mapView.get("acknowledged"), equalTo(true));
    assertBusy(() -> assertThat("Expected dangling index to be deleted", listDanglingIndexIds(), hasSize(0)));
    // The dangling index that we deleted ought to have been removed from disk. Check by
    // creating and deleting another index, which creates a new tombstone entry, which should
    // not cause the deleted dangling index to be considered "live" again, just because its
    // tombstone has been pushed out of the graveyard.
    createIndex("additional");
    deleteIndex("additional");
    assertThat(listDanglingIndexIds(), is(empty()));
}
Also used : Response(org.opensearch.client.Response) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request) XContentTestUtils(org.opensearch.test.XContentTestUtils)

Example 97 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class DanglingIndicesRestIT method mapNodeNameToId.

/**
 * Given a node name, finds the corresponding node ID.
 */
private String mapNodeNameToId(String nodeName) throws IOException {
    final Response catResponse = getRestClient().performRequest(new Request("GET", "/_cat/nodes?full_id&h=id,name"));
    assertOK(catResponse);
    for (String nodeLine : Streams.readAllLines(catResponse.getEntity().getContent())) {
        String[] elements = nodeLine.split(" ");
        if (elements[1].equals(nodeName)) {
            return elements[0];
        }
    }
    throw new AssertionError("Failed to map node name [" + nodeName + "] to node ID");
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

Example 98 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class DanglingIndicesRestIT method testDanglingIndicesCanBeListed.

/**
 * Check that when dangling indices are discovered, then they can be listed via the REST API.
 */
public void testDanglingIndicesCanBeListed() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(1);
    internalCluster().startNodes(3, buildSettings(0));
    final DanglingIndexDetails danglingIndexDetails = createDanglingIndices(INDEX_NAME);
    final String stoppedNodeId = mapNodeNameToId(danglingIndexDetails.stoppedNodeName);
    final RestClient restClient = getRestClient();
    final Response listResponse = restClient.performRequest(new Request("GET", "/_dangling"));
    assertOK(listResponse);
    final XContentTestUtils.JsonMapView mapView = createJsonMapView(listResponse.getEntity().getContent());
    assertThat(mapView.get("_nodes.total"), equalTo(3));
    assertThat(mapView.get("_nodes.successful"), equalTo(3));
    assertThat(mapView.get("_nodes.failed"), equalTo(0));
    List<Object> indices = mapView.get("dangling_indices");
    assertThat(indices, hasSize(1));
    assertThat(mapView.get("dangling_indices.0.index_name"), equalTo(INDEX_NAME));
    assertThat(mapView.get("dangling_indices.0.index_uuid"), equalTo(danglingIndexDetails.indexToUUID.get(INDEX_NAME)));
    assertThat(mapView.get("dangling_indices.0.creation_date_millis"), instanceOf(Long.class));
    assertThat(mapView.get("dangling_indices.0.node_ids.0"), equalTo(stoppedNodeId));
}
Also used : Response(org.opensearch.client.Response) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request) XContentTestUtils(org.opensearch.test.XContentTestUtils)

Example 99 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class DanglingIndicesRestIT method testDanglingIndicesCanBeImported.

/**
 * Check that dangling indices can be imported.
 */
public void testDanglingIndicesCanBeImported() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(1);
    internalCluster().startNodes(3, buildSettings(0));
    createDanglingIndices(INDEX_NAME);
    final RestClient restClient = getRestClient();
    final List<String> danglingIndexIds = listDanglingIndexIds();
    assertThat(danglingIndexIds, hasSize(1));
    final Request importRequest = new Request("POST", "/_dangling/" + danglingIndexIds.get(0));
    importRequest.addParameter("accept_data_loss", "true");
    // Ensure this parameter is accepted
    importRequest.addParameter("timeout", "20s");
    importRequest.addParameter("master_timeout", "20s");
    final Response importResponse = restClient.performRequest(importRequest);
    assertThat(importResponse.getStatusLine().getStatusCode(), equalTo(ACCEPTED.getStatus()));
    final XContentTestUtils.JsonMapView mapView = createJsonMapView(importResponse.getEntity().getContent());
    assertThat(mapView.get("acknowledged"), equalTo(true));
    assertTrue("Expected dangling index " + INDEX_NAME + " to be recovered", indexExists(INDEX_NAME));
}
Also used : Response(org.opensearch.client.Response) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request) XContentTestUtils(org.opensearch.test.XContentTestUtils)

Example 100 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class DanglingIndicesRestIT method deleteIndex.

private void deleteIndex(String indexName) throws IOException {
    Response deleteResponse = getRestClient().performRequest(new Request("DELETE", "/" + indexName));
    assertOK(deleteResponse);
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

Aggregations

Response (org.opensearch.client.Response)134 Request (org.opensearch.client.Request)113 ResponseException (org.opensearch.client.ResponseException)24 Map (java.util.Map)23 Matchers.containsString (org.hamcrest.Matchers.containsString)20 ArrayList (java.util.ArrayList)17 PutRepositoryRequest (org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest)16 RestClient (org.opensearch.client.RestClient)15 HashMap (java.util.HashMap)14 RequestOptions (org.opensearch.client.RequestOptions)12 ObjectPath (org.opensearch.test.rest.yaml.ObjectPath)12 IndexRequest (org.opensearch.action.index.IndexRequest)11 IOException (java.io.IOException)10 List (java.util.List)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 Version (org.opensearch.Version)8 WriteRequest (org.opensearch.action.support.WriteRequest)8 ListTasksResponse (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse)7 IndexResponse (org.opensearch.action.index.IndexResponse)7 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)7