use of org.opensearch.repositories.RepositoryVerificationException in project OpenSearch by opensearch-project.
the class RepositoriesIT method testRepositoryVerification.
public void testRepositoryVerification() throws Exception {
disableRepoConsistencyCheck("This test does not create any data in the repository.");
Client client = client();
Settings settings = Settings.builder().put("location", randomRepoPath()).put("random_control_io_exception_rate", 1.0).build();
Settings readonlySettings = Settings.builder().put(settings).put("readonly", true).build();
logger.info("--> creating repository that cannot write any files - should fail");
assertRequestBuilderThrows(client.admin().cluster().preparePutRepository("test-repo-1").setType("mock").setSettings(settings), RepositoryVerificationException.class);
logger.info("--> creating read-only repository that cannot read any files - should fail");
assertRequestBuilderThrows(client.admin().cluster().preparePutRepository("test-repo-2").setType("mock").setSettings(readonlySettings), RepositoryVerificationException.class);
logger.info("--> creating repository that cannot write any files, but suppress verification - should be acked");
assertAcked(client.admin().cluster().preparePutRepository("test-repo-1").setType("mock").setSettings(settings).setVerify(false));
logger.info("--> verifying repository");
assertRequestBuilderThrows(client.admin().cluster().prepareVerifyRepository("test-repo-1"), RepositoryVerificationException.class);
logger.info("--> creating read-only repository that cannot read any files, but suppress verification - should be acked");
assertAcked(client.admin().cluster().preparePutRepository("test-repo-2").setType("mock").setSettings(readonlySettings).setVerify(false));
logger.info("--> verifying repository");
assertRequestBuilderThrows(client.admin().cluster().prepareVerifyRepository("test-repo-2"), RepositoryVerificationException.class);
Path location = randomRepoPath();
logger.info("--> creating repository");
try {
client.admin().cluster().preparePutRepository("test-repo-1").setType("mock").setSettings(Settings.builder().put("location", location).put("localize_location", true)).get();
fail("RepositoryVerificationException wasn't generated");
} catch (RepositoryVerificationException ex) {
assertThat(ex.getMessage(), containsString("is not shared"));
}
}
use of org.opensearch.repositories.RepositoryVerificationException in project OpenSearch by opensearch-project.
the class BlobStoreRepository method endVerification.
@Override
public void endVerification(String seed) {
if (isReadOnly() == false) {
try {
final String testPrefix = testBlobPrefix(seed);
blobStore().blobContainer(basePath().add(testPrefix)).delete();
} catch (Exception exp) {
throw new RepositoryVerificationException(metadata.name(), "cannot delete test data at " + basePath(), exp);
}
}
}
use of org.opensearch.repositories.RepositoryVerificationException in project OpenSearch by opensearch-project.
the class BlobStoreRepository method startVerification.
@Override
public String startVerification() {
try {
if (isReadOnly()) {
// It's readonly - so there is not much we can do here to verify it apart from reading the blob store metadata
latestIndexBlobId();
return "read-only";
} else {
String seed = UUIDs.randomBase64UUID();
byte[] testBytes = Strings.toUTF8Bytes(seed);
BlobContainer testContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed)));
BytesArray bytes = new BytesArray(testBytes);
try (InputStream stream = bytes.streamInput()) {
testContainer.writeBlobAtomic("master.dat", stream, bytes.length(), true);
}
return seed;
}
} catch (Exception exp) {
throw new RepositoryVerificationException(metadata.name(), "path " + basePath() + " is not accessible on master node", exp);
}
}
Aggregations