use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest in project OpenSearch by opensearch-project.
the class SnapshotRequestConverters method snapshotsStatus.
static Request snapshotsStatus(SnapshotsStatusRequest snapshotsStatusRequest) {
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot").addPathPart(snapshotsStatusRequest.repository()).addCommaSeparatedPathParts(snapshotsStatusRequest.snapshots()).addPathPartAsIs("_status").build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withMasterTimeout(snapshotsStatusRequest.masterNodeTimeout());
parameters.withIgnoreUnavailable(snapshotsStatusRequest.ignoreUnavailable());
request.addParameters(parameters.asMap());
return request;
}
use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest in project OpenSearch by opensearch-project.
the class SnapshotRequestConvertersTests method testSnapshotsStatus.
public void testSnapshotsStatus() {
Map<String, String> expectedParams = new HashMap<>();
String repository = RequestConvertersTests.randomIndicesNames(1, 1)[0];
String[] snapshots = RequestConvertersTests.randomIndicesNames(1, 5);
StringBuilder snapshotNames = new StringBuilder(snapshots[0]);
for (int idx = 1; idx < snapshots.length; idx++) {
snapshotNames.append(",").append(snapshots[idx]);
}
boolean ignoreUnavailable = randomBoolean();
String endpoint = "/_snapshot/" + repository + "/" + snapshotNames.toString() + "/_status";
SnapshotsStatusRequest snapshotsStatusRequest = new SnapshotsStatusRequest(repository, snapshots);
RequestConvertersTests.setRandomMasterTimeout(snapshotsStatusRequest, expectedParams);
snapshotsStatusRequest.ignoreUnavailable(ignoreUnavailable);
expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable));
Request request = SnapshotRequestConverters.snapshotsStatus(snapshotsStatusRequest);
assertThat(request.getEndpoint(), equalTo(endpoint));
assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(request.getParameters(), equalTo(expectedParams));
assertThat(request.getEntity(), is(nullValue()));
}
use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest in project OpenSearch by opensearch-project.
the class SnapshotStatusApisIT method testStatusApiConsistency.
public void testStatusApiConsistency() {
createRepository("test-repo", "fs");
createIndex("test-idx-1", "test-idx-2", "test-idx-3");
ensureGreen();
logger.info("--> indexing some data");
for (int i = 0; i < 100; i++) {
index("test-idx-1", "_doc", Integer.toString(i), "foo", "bar" + i);
index("test-idx-2", "_doc", Integer.toString(i), "foo", "baz" + i);
index("test-idx-3", "_doc", Integer.toString(i), "foo", "baz" + i);
}
refresh();
createFullSnapshot("test-repo", "test-snap");
List<SnapshotInfo> snapshotInfos = clusterAdmin().prepareGetSnapshots("test-repo").get().getSnapshots();
assertThat(snapshotInfos.size(), equalTo(1));
SnapshotInfo snapshotInfo = snapshotInfos.get(0);
assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
assertThat(snapshotInfo.version(), equalTo(Version.CURRENT));
final List<SnapshotStatus> snapshotStatus = clusterAdmin().snapshotsStatus(new SnapshotsStatusRequest("test-repo", new String[] { "test-snap" })).actionGet().getSnapshots();
assertThat(snapshotStatus.size(), equalTo(1));
final SnapshotStatus snStatus = snapshotStatus.get(0);
assertEquals(snStatus.getStats().getStartTime(), snapshotInfo.startTime());
assertEquals(snStatus.getStats().getTime(), snapshotInfo.endTime() - snapshotInfo.startTime());
}
use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest in project OpenSearch by opensearch-project.
the class SnapshotIT method testSnapshotsStatus.
public void testSnapshotsStatus() throws IOException {
String testRepository = "test";
String testSnapshot = "snapshot";
String testIndex = "test_index";
AcknowledgedResponse putRepositoryResponse = createTestRepository(testRepository, FsRepository.TYPE, "{\"location\": \".\"}");
assertTrue(putRepositoryResponse.isAcknowledged());
createIndex(testIndex, Settings.EMPTY);
CreateSnapshotRequest createSnapshotRequest = new CreateSnapshotRequest(testRepository, testSnapshot);
createSnapshotRequest.indices(testIndex);
createSnapshotRequest.waitForCompletion(true);
CreateSnapshotResponse createSnapshotResponse = createTestSnapshot(createSnapshotRequest);
// check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
assertEquals(RestStatus.OK, createSnapshotResponse.status());
SnapshotsStatusRequest request = new SnapshotsStatusRequest();
request.repository(testRepository);
request.snapshots(new String[] { testSnapshot });
SnapshotsStatusResponse response = execute(request, highLevelClient().snapshot()::status, highLevelClient().snapshot()::statusAsync);
assertThat(response.getSnapshots().size(), equalTo(1));
assertThat(response.getSnapshots().get(0).getSnapshot().getRepository(), equalTo(testRepository));
assertThat(response.getSnapshots().get(0).getSnapshot().getSnapshotId().getName(), equalTo(testSnapshot));
assertThat(response.getSnapshots().get(0).getIndices().containsKey(testIndex), is(true));
}
use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest in project OpenSearch by opensearch-project.
the class SnapshotClientDocumentationIT method testSnapshotSnapshotsStatus.
public void testSnapshotSnapshotsStatus() throws IOException {
RestHighLevelClient client = highLevelClient();
createTestRepositories();
createTestIndex();
createTestSnapshots();
// tag::snapshots-status-request
SnapshotsStatusRequest request = new SnapshotsStatusRequest();
// end::snapshots-status-request
// tag::snapshots-status-request-repository
// <1>
request.repository(repositoryName);
// end::snapshots-status-request-repository
// tag::snapshots-status-request-snapshots
String[] snapshots = new String[] { snapshotName };
// <1>
request.snapshots(snapshots);
// end::snapshots-status-request-snapshots
// tag::snapshots-status-request-ignoreUnavailable
// <1>
request.ignoreUnavailable(true);
// end::snapshots-status-request-ignoreUnavailable
// tag::snapshots-status-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::snapshots-status-request-masterTimeout
// tag::snapshots-status-execute
SnapshotsStatusResponse response = client.snapshot().status(request, RequestOptions.DEFAULT);
// end::snapshots-status-execute
// tag::snapshots-status-response
List<SnapshotStatus> snapshotStatusesResponse = response.getSnapshots();
// <1>
SnapshotStatus snapshotStatus = snapshotStatusesResponse.get(0);
// <2>
SnapshotsInProgress.State snapshotState = snapshotStatus.getState();
// <3>
SnapshotStats shardStats = snapshotStatus.getIndices().get(indexName).getShards().get(0).getStats();
// end::snapshots-status-response
assertThat(snapshotStatusesResponse.size(), equalTo(1));
assertThat(snapshotStatusesResponse.get(0).getSnapshot().getRepository(), equalTo(SnapshotClientDocumentationIT.repositoryName));
assertThat(snapshotStatusesResponse.get(0).getSnapshot().getSnapshotId().getName(), equalTo(snapshotName));
assertThat(snapshotState.completed(), equalTo(true));
}
Aggregations