Search in sources :

Example 1 with CleanupRepositoryRequest

use of org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest in project OpenSearch by opensearch-project.

the class SnapshotRequestConverters method cleanupRepository.

static Request cleanupRepository(CleanupRepositoryRequest cleanupRepositoryRequest) {
    String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot").addPathPart(cleanupRepositoryRequest.name()).addPathPartAsIs("_cleanup").build();
    Request request = new Request(HttpPost.METHOD_NAME, endpoint);
    RequestConverters.Params parameters = new RequestConverters.Params();
    parameters.withMasterTimeout(cleanupRepositoryRequest.masterNodeTimeout());
    parameters.withTimeout(cleanupRepositoryRequest.timeout());
    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 CleanupRepositoryRequest

use of org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest in project OpenSearch by opensearch-project.

the class SnapshotIT method testCleanupRepository.

public void testCleanupRepository() throws IOException {
    AcknowledgedResponse putRepositoryResponse = createTestRepository("test", FsRepository.TYPE, "{\"location\": \".\"}");
    assertTrue(putRepositoryResponse.isAcknowledged());
    CleanupRepositoryRequest request = new CleanupRepositoryRequest("test");
    CleanupRepositoryResponse response = execute(request, highLevelClient().snapshot()::cleanupRepository, highLevelClient().snapshot()::cleanupRepositoryAsync);
    assertThat(response.result().bytes(), equalTo(0L));
    assertThat(response.result().blobs(), equalTo(0L));
}
Also used : CleanupRepositoryResponse(org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryResponse) CleanupRepositoryRequest(org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse)

Example 3 with CleanupRepositoryRequest

use of org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest in project OpenSearch by opensearch-project.

the class SnapshotResiliencyTests method verifyReposThenStopServices.

@After
public void verifyReposThenStopServices() {
    try {
        clearDisruptionsAndAwaitSync();
        final StepListener<CleanupRepositoryResponse> cleanupResponse = new StepListener<>();
        final StepListener<CreateSnapshotResponse> createSnapshotResponse = new StepListener<>();
        // Create another snapshot and then clean up the repository to verify that the repository works correctly no matter the
        // failures seen during the previous test.
        client().admin().cluster().prepareCreateSnapshot("repo", "last-snapshot").setWaitForCompletion(true).setPartial(true).execute(createSnapshotResponse);
        continueOrDie(createSnapshotResponse, r -> {
            final SnapshotInfo snapshotInfo = r.getSnapshotInfo();
            // Snapshot can be partial because some tests leave indices in a red state because data nodes were stopped
            assertThat(snapshotInfo.state(), either(is(SnapshotState.SUCCESS)).or(is(SnapshotState.PARTIAL)));
            assertThat(snapshotInfo.shardFailures(), iterableWithSize(snapshotInfo.failedShards()));
            assertThat(snapshotInfo.successfulShards(), is(snapshotInfo.totalShards() - snapshotInfo.failedShards()));
            client().admin().cluster().cleanupRepository(new CleanupRepositoryRequest("repo"), cleanupResponse);
        });
        final AtomicBoolean cleanedUp = new AtomicBoolean(false);
        continueOrDie(cleanupResponse, r -> cleanedUp.set(true));
        runUntil(cleanedUp::get, TimeUnit.MINUTES.toMillis(1L));
        if (blobStoreContext != null) {
            blobStoreContext.forceConsistent();
        }
        BlobStoreTestUtil.assertConsistency((BlobStoreRepository) testClusterNodes.randomMasterNodeSafe().repositoriesService.repository("repo"), Runnable::run);
    } finally {
        testClusterNodes.nodes.values().forEach(TestClusterNodes.TestClusterNode::stop);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CleanupRepositoryResponse(org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryResponse) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) CleanupRepositoryRequest(org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest) AbstractRunnable(org.opensearch.common.util.concurrent.AbstractRunnable) StepListener(org.opensearch.action.StepListener) After(org.junit.After)

Example 4 with CleanupRepositoryRequest

use of org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest in project OpenSearch by opensearch-project.

the class RestCleanupRepositoryAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    CleanupRepositoryRequest cleanupRepositoryRequest = cleanupRepositoryRequest(request.param("repository"));
    cleanupRepositoryRequest.timeout(request.paramAsTime("timeout", cleanupRepositoryRequest.timeout()));
    cleanupRepositoryRequest.masterNodeTimeout(request.paramAsTime("master_timeout", cleanupRepositoryRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().cleanupRepository(cleanupRepositoryRequest, new RestToXContentListener<>(channel));
}
Also used : CleanupRepositoryRequest(org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest) POST(org.opensearch.rest.RestRequest.Method.POST) List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) BaseRestHandler(org.opensearch.rest.BaseRestHandler) Requests.cleanupRepositoryRequest(org.opensearch.client.Requests.cleanupRepositoryRequest) Collections.singletonList(java.util.Collections.singletonList) CleanupRepositoryRequest(org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest)

Aggregations

CleanupRepositoryRequest (org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest)4 CleanupRepositoryResponse (org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryResponse)2 IOException (java.io.IOException)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 After (org.junit.After)1 StepListener (org.opensearch.action.StepListener)1 DeleteRepositoryRequest (org.opensearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest)1 GetRepositoriesRequest (org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest)1 PutRepositoryRequest (org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest)1 VerifyRepositoryRequest (org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest)1 CloneSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.clone.CloneSnapshotRequest)1 CreateSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)1 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)1 DeleteSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest)1 GetSnapshotsRequest (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)1 RestoreSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)1 SnapshotsStatusRequest (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)1 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)1