use of org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project OpenSearch by opensearch-project.
the class SnapshotIT method testVerifyRepository.
public void testVerifyRepository() throws IOException {
AcknowledgedResponse putRepositoryResponse = createTestRepository("test", FsRepository.TYPE, "{\"location\": \".\"}");
assertTrue(putRepositoryResponse.isAcknowledged());
VerifyRepositoryRequest request = new VerifyRepositoryRequest("test");
VerifyRepositoryResponse response = execute(request, highLevelClient().snapshot()::verifyRepository, highLevelClient().snapshot()::verifyRepositoryAsync);
assertThat(response.getNodes().size(), equalTo(1));
}
use of org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project OpenSearch by opensearch-project.
the class RepositoryBlocksIT method testVerifyRepositoryWithBlocks.
public void testVerifyRepositoryWithBlocks() {
assertAcked(client().admin().cluster().preparePutRepository("test-repo-blocks").setType("fs").setVerify(false).setSettings(Settings.builder().put("location", randomRepoPath())));
// This test checks that the Get Repository operation is never blocked, even if the cluster is read only.
try {
setClusterReadOnly(true);
VerifyRepositoryResponse response = client().admin().cluster().prepareVerifyRepository("test-repo-blocks").execute().actionGet();
assertThat(response.getNodes().size(), equalTo(cluster().numDataAndMasterNodes()));
} finally {
setClusterReadOnly(false);
}
}
use of org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project OpenSearch by opensearch-project.
the class RepositoriesIT method testRepositoryCreation.
public void testRepositoryCreation() throws Exception {
Client client = client();
Path location = randomRepoPath();
createRepository("test-repo-1", "fs", location);
logger.info("--> verify the repository");
int numberOfFiles = FileSystemUtils.files(location).length;
VerifyRepositoryResponse verifyRepositoryResponse = client.admin().cluster().prepareVerifyRepository("test-repo-1").get();
assertThat(verifyRepositoryResponse.getNodes().size(), equalTo(cluster().numDataAndMasterNodes()));
logger.info("--> verify that we didn't leave any files as a result of verification");
assertThat(FileSystemUtils.files(location).length, equalTo(numberOfFiles));
logger.info("--> check that repository is really there");
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().clear().setMetadata(true).get();
Metadata metadata = clusterStateResponse.getState().getMetadata();
RepositoriesMetadata repositoriesMetadata = metadata.custom(RepositoriesMetadata.TYPE);
assertThat(repositoriesMetadata, notNullValue());
assertThat(repositoriesMetadata.repository("test-repo-1"), notNullValue());
assertThat(repositoriesMetadata.repository("test-repo-1").type(), equalTo("fs"));
logger.info("--> creating another repository");
createRepository("test-repo-2", "fs");
logger.info("--> check that both repositories are in cluster state");
clusterStateResponse = client.admin().cluster().prepareState().clear().setMetadata(true).get();
metadata = clusterStateResponse.getState().getMetadata();
repositoriesMetadata = metadata.custom(RepositoriesMetadata.TYPE);
assertThat(repositoriesMetadata, notNullValue());
assertThat(repositoriesMetadata.repositories().size(), equalTo(2));
assertThat(repositoriesMetadata.repository("test-repo-1"), notNullValue());
assertThat(repositoriesMetadata.repository("test-repo-1").type(), equalTo("fs"));
assertThat(repositoriesMetadata.repository("test-repo-2"), notNullValue());
assertThat(repositoriesMetadata.repository("test-repo-2").type(), equalTo("fs"));
logger.info("--> check that both repositories can be retrieved by getRepositories query");
GetRepositoriesResponse repositoriesResponse = client.admin().cluster().prepareGetRepositories(randomFrom("_all", "*", "test-repo-*")).get();
assertThat(repositoriesResponse.repositories().size(), equalTo(2));
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-1"), notNullValue());
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-2"), notNullValue());
logger.info("--> check that trying to create a repository with the same settings repeatedly does not update cluster state");
String beforeStateUuid = clusterStateResponse.getState().stateUUID();
assertThat(client.admin().cluster().preparePutRepository("test-repo-1").setType("fs").setSettings(Settings.builder().put("location", location)).get().isAcknowledged(), equalTo(true));
assertEquals(beforeStateUuid, client.admin().cluster().prepareState().clear().get().getState().stateUUID());
logger.info("--> delete repository test-repo-1");
client.admin().cluster().prepareDeleteRepository("test-repo-1").get();
repositoriesResponse = client.admin().cluster().prepareGetRepositories().get();
assertThat(repositoriesResponse.repositories().size(), equalTo(1));
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-2"), notNullValue());
logger.info("--> delete repository test-repo-2");
client.admin().cluster().prepareDeleteRepository("test-repo-2").get();
repositoriesResponse = client.admin().cluster().prepareGetRepositories().get();
assertThat(repositoriesResponse.repositories().size(), equalTo(0));
}
use of org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project OpenSearch by opensearch-project.
the class SnapshotClientDocumentationIT method testSnapshotVerifyRepository.
public void testSnapshotVerifyRepository() throws IOException {
RestHighLevelClient client = highLevelClient();
createTestRepositories();
// tag::verify-repository-request
VerifyRepositoryRequest request = new VerifyRepositoryRequest(repositoryName);
// end::verify-repository-request
// tag::verify-repository-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::verify-repository-request-masterTimeout
// tag::verify-repository-request-timeout
// <1>
request.timeout(TimeValue.timeValueMinutes(1));
// <2>
request.timeout("1m");
// end::verify-repository-request-timeout
// tag::verify-repository-execute
VerifyRepositoryResponse response = client.snapshot().verifyRepository(request, RequestOptions.DEFAULT);
// end::verify-repository-execute
// tag::verify-repository-response
List<VerifyRepositoryResponse.NodeView> repositoryMetadataResponse = response.getNodes();
// end::verify-repository-response
assertThat(1, equalTo(repositoryMetadataResponse.size()));
final boolean async = Booleans.parseBoolean(System.getProperty("tests.rest.async", "false"));
if (async) {
assertThat("asyncIntegTest-0", equalTo(repositoryMetadataResponse.get(0).getName()));
} else {
assertThat("integTest-0", equalTo(repositoryMetadataResponse.get(0).getName()));
}
}
use of org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project OpenSearch by opensearch-project.
the class SnapshotBlocksIT method setUpRepository.
@Before
protected void setUpRepository() throws Exception {
createIndex(INDEX_NAME, OTHER_INDEX_NAME);
int docs = between(10, 100);
for (int i = 0; i < docs; i++) {
client().prepareIndex(INDEX_NAME).setSource("test", "init").execute().actionGet();
}
docs = between(10, 100);
for (int i = 0; i < docs; i++) {
client().prepareIndex(OTHER_INDEX_NAME).setSource("test", "init").execute().actionGet();
}
logger.info("--> register a repository");
assertAcked(client().admin().cluster().preparePutRepository(REPOSITORY_NAME).setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())));
logger.info("--> verify the repository");
VerifyRepositoryResponse verifyResponse = client().admin().cluster().prepareVerifyRepository(REPOSITORY_NAME).get();
assertThat(verifyResponse.getNodes().size(), equalTo(cluster().numDataAndMasterNodes()));
logger.info("--> create a snapshot");
CreateSnapshotResponse snapshotResponse = client().admin().cluster().prepareCreateSnapshot(REPOSITORY_NAME, SNAPSHOT_NAME).setIncludeGlobalState(true).setWaitForCompletion(true).execute().actionGet();
assertThat(snapshotResponse.status(), equalTo(RestStatus.OK));
ensureSearchable();
}
Aggregations