Search in sources :

Example 1 with GetSnapshotsRequest

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.

the class SnapshotRequestConverters method getSnapshots.

static Request getSnapshots(GetSnapshotsRequest getSnapshotsRequest) {
    RequestConverters.EndpointBuilder endpointBuilder = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot").addPathPart(getSnapshotsRequest.repository());
    String endpoint;
    if (getSnapshotsRequest.snapshots().length == 0) {
        endpoint = endpointBuilder.addPathPart("_all").build();
    } else {
        endpoint = endpointBuilder.addCommaSeparatedPathParts(getSnapshotsRequest.snapshots()).build();
    }
    Request request = new Request(HttpGet.METHOD_NAME, endpoint);
    RequestConverters.Params parameters = new RequestConverters.Params();
    parameters.withMasterTimeout(getSnapshotsRequest.masterNodeTimeout());
    parameters.putParam("ignore_unavailable", Boolean.toString(getSnapshotsRequest.ignoreUnavailable()));
    parameters.putParam("verbose", Boolean.toString(getSnapshotsRequest.verbose()));
    request.addParameters(parameters.asMap());
    return request;
}
Also used : CleanupRepositoryRequest(org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest) DeleteRepositoryRequest(org.opensearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) VerifyRepositoryRequest(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest) CloneSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.clone.CloneSnapshotRequest) DeleteSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest) GetRepositoriesRequest(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) RestoreSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) PutRepositoryRequest(org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) SnapshotsStatusRequest(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)

Example 2 with GetSnapshotsRequest

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.

the class SnapshotRequestConvertersTests method testGetSnapshots.

public void testGetSnapshots() {
    Map<String, String> expectedParams = new HashMap<>();
    String repository = RequestConvertersTests.randomIndicesNames(1, 1)[0];
    String snapshot1 = "snapshot1-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT);
    String snapshot2 = "snapshot2-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT);
    String endpoint = String.format(Locale.ROOT, "/_snapshot/%s/%s,%s", repository, snapshot1, snapshot2);
    GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest();
    getSnapshotsRequest.repository(repository);
    getSnapshotsRequest.snapshots(Arrays.asList(snapshot1, snapshot2).toArray(new String[0]));
    RequestConvertersTests.setRandomMasterTimeout(getSnapshotsRequest, expectedParams);
    if (randomBoolean()) {
        boolean ignoreUnavailable = randomBoolean();
        getSnapshotsRequest.ignoreUnavailable(ignoreUnavailable);
        expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable));
    } else {
        expectedParams.put("ignore_unavailable", Boolean.FALSE.toString());
    }
    if (randomBoolean()) {
        boolean verbose = randomBoolean();
        getSnapshotsRequest.verbose(verbose);
        expectedParams.put("verbose", Boolean.toString(verbose));
    } else {
        expectedParams.put("verbose", Boolean.TRUE.toString());
    }
    Request request = SnapshotRequestConverters.getSnapshots(getSnapshotsRequest);
    assertThat(request.getEndpoint(), equalTo(endpoint));
    assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
    assertThat(request.getParameters(), equalTo(expectedParams));
    assertNull(request.getEntity());
}
Also used : GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) HashMap(java.util.HashMap) VerifyRepositoryRequest(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest) RestoreSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) SnapshotsStatusRequest(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest) DeleteRepositoryRequest(org.opensearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) DeleteSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest) GetRepositoriesRequest(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) PutRepositoryRequest(org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)

Example 3 with GetSnapshotsRequest

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.

the class SnapshotStatusApisIT method testExceptionOnMissingSnapBlob.

public void testExceptionOnMissingSnapBlob() throws IOException {
    disableRepoConsistencyCheck("This test intentionally corrupts the repository");
    final Path repoPath = randomRepoPath();
    createRepository("test-repo", "fs", repoPath);
    final SnapshotInfo snapshotInfo = createFullSnapshot("test-repo", "test-snap");
    logger.info("--> delete snap-${uuid}.dat file for this snapshot to simulate concurrent delete");
    IOUtils.rm(repoPath.resolve(BlobStoreRepository.SNAPSHOT_PREFIX + snapshotInfo.snapshotId().getUUID() + ".dat"));
    expectThrows(SnapshotMissingException.class, () -> client().admin().cluster().getSnapshots(new GetSnapshotsRequest("test-repo", new String[] { "test-snap" })).actionGet());
}
Also used : Path(java.nio.file.Path) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)

Example 4 with GetSnapshotsRequest

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.

the class RestSnapshotAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
    GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest().repository(request.param("repository")).snapshots(new String[] { GetSnapshotsRequest.ALL_SNAPSHOTS });
    getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
    getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestResponseListener<GetSnapshotsResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetSnapshotsResponse getSnapshotsResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, getSnapshotsResponse), channel);
        }
    });
}
Also used : TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) Table(org.opensearch.common.Table) SnapshotState(org.opensearch.snapshots.SnapshotState) Instant(java.time.Instant) RestResponse(org.opensearch.rest.RestResponse) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Arrays.asList(java.util.Arrays.asList) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) ZoneOffset(java.time.ZoneOffset) DateFormatter(org.opensearch.common.time.DateFormatter) RestResponseListener(org.opensearch.rest.action.RestResponseListener) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) RestResponse(org.opensearch.rest.RestResponse)

Example 5 with GetSnapshotsRequest

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.

the class SnapshotIT method testGetSnapshots.

public void testGetSnapshots() throws IOException {
    String repository = "test_repository";
    String snapshot1 = "test_snapshot1";
    String snapshot2 = "test_snapshot2";
    AcknowledgedResponse putRepositoryResponse = createTestRepository(repository, FsRepository.TYPE, "{\"location\": \".\"}");
    assertTrue(putRepositoryResponse.isAcknowledged());
    CreateSnapshotRequest createSnapshotRequest1 = new CreateSnapshotRequest(repository, snapshot1);
    createSnapshotRequest1.waitForCompletion(true);
    CreateSnapshotResponse putSnapshotResponse1 = createTestSnapshot(createSnapshotRequest1);
    CreateSnapshotRequest createSnapshotRequest2 = new CreateSnapshotRequest(repository, snapshot2);
    createSnapshotRequest2.waitForCompletion(true);
    Map<String, Object> originalMetadata = randomUserMetadata();
    createSnapshotRequest2.userMetadata(originalMetadata);
    CreateSnapshotResponse putSnapshotResponse2 = createTestSnapshot(createSnapshotRequest2);
    // check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
    assertEquals(RestStatus.OK, putSnapshotResponse1.status());
    assertEquals(RestStatus.OK, putSnapshotResponse2.status());
    GetSnapshotsRequest request;
    if (randomBoolean()) {
        request = new GetSnapshotsRequest(repository);
    } else if (randomBoolean()) {
        request = new GetSnapshotsRequest(repository, new String[] { "_all" });
    } else {
        request = new GetSnapshotsRequest(repository, new String[] { snapshot1, snapshot2 });
    }
    GetSnapshotsResponse response = execute(request, highLevelClient().snapshot()::get, highLevelClient().snapshot()::getAsync);
    assertEquals(2, response.getSnapshots().size());
    assertThat(response.getSnapshots().stream().map((s) -> s.snapshotId().getName()).collect(Collectors.toList()), contains("test_snapshot1", "test_snapshot2"));
    Optional<Map<String, Object>> returnedMetadata = response.getSnapshots().stream().filter(s -> s.snapshotId().getName().equals("test_snapshot2")).findFirst().map(SnapshotInfo::userMetadata);
    if (returnedMetadata.isPresent()) {
        assertEquals(originalMetadata, returnedMetadata.get());
    } else {
        assertNull("retrieved metadata is null, expected non-null metadata", originalMetadata);
    }
}
Also used : GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

GetSnapshotsRequest (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)8 CreateSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)4 HashMap (java.util.HashMap)3 DeleteRepositoryRequest (org.opensearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest)3 GetRepositoriesRequest (org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest)3 PutRepositoryRequest (org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest)3 VerifyRepositoryRequest (org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest)3 DeleteSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest)3 GetSnapshotsResponse (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)3 RestoreSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)3 SnapshotsStatusRequest (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)3 SnapshotInfo (org.opensearch.snapshots.SnapshotInfo)3 List (java.util.List)2 AcknowledgedRequest (org.opensearch.action.support.master.AcknowledgedRequest)2 NodeClient (org.opensearch.client.node.NodeClient)2 RestRequest (org.opensearch.rest.RestRequest)2 GET (org.opensearch.rest.RestRequest.Method.GET)2 SnapshotState (org.opensearch.snapshots.SnapshotState)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1