use of org.elasticsearch.repositories.RepositoryVerificationException in project elasticsearch by elastic.
the class RepositoriesIT method testRepositoryVerification.
public void testRepositoryVerification() throws Exception {
Client client = client();
Settings settings = Settings.builder().put("location", randomRepoPath()).put("random_control_io_exception_rate", 1.0).build();
logger.info("--> creating repository that cannot write any files - should fail");
assertThrows(client.admin().cluster().preparePutRepository("test-repo-1").setType("mock").setSettings(settings), 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");
assertThrows(client.admin().cluster().prepareVerifyRepository("test-repo-1"), 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.elasticsearch.repositories.RepositoryVerificationException in project elasticsearch by elastic.
the class AzureSnapshotRestoreTests method testRemoveAndCreateContainer.
/**
* When a user remove a container you can not immediately create it again.
*/
public void testRemoveAndCreateContainer() throws Exception {
final String container = getContainerName().concat("-testremove");
final AzureStorageService storageService = new AzureStorageServiceImpl(internalCluster().getDefaultSettings());
// It could happen that we run this test really close to a previous one
// so we might need some time to be able to create the container
assertBusy(() -> {
try {
storageService.createContainer(null, LocationMode.PRIMARY_ONLY, container);
logger.debug(" -> container created...");
} catch (URISyntaxException e) {
// Incorrect URL. This should never happen.
fail();
} catch (StorageException e) {
// It could happen. Let's wait for a while.
logger.debug(" -> container is being removed. Let's wait a bit...");
fail();
}
}, 30, TimeUnit.SECONDS);
storageService.removeContainer(null, LocationMode.PRIMARY_ONLY, container);
ClusterAdminClient client = client().admin().cluster();
logger.info("--> creating azure repository while container is being removed");
try {
client.preparePutRepository("test-repo").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), container)).get();
fail("we should get a RepositoryVerificationException");
} catch (RepositoryVerificationException e) {
// Fine we expect that
}
}
use of org.elasticsearch.repositories.RepositoryVerificationException in project elasticsearch by elastic.
the class AzureSnapshotRestoreTests method checkContainerName.
/**
* Create repository with wrong or correct container name
* @param container Container name we want to create
* @param correct Is this container name correct
*/
private void checkContainerName(final String container, final boolean correct) throws Exception {
logger.info("--> creating azure repository with container name [{}]", container);
// It could happen that we just removed from a previous test the same container so
// we can not create it yet.
assertBusy(() -> {
try {
PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), container).put(Repository.BASE_PATH_SETTING.getKey(), getRepositoryPath()).put(Repository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(1000, 10000), ByteSizeUnit.BYTES)).get();
client().admin().cluster().prepareDeleteRepository("test-repo").get();
try {
logger.info("--> remove container [{}]", container);
cleanRepositoryFiles(container);
} catch (StorageException | URISyntaxException e) {
// We can ignore that as we just try to clean after the test
}
assertTrue(putRepositoryResponse.isAcknowledged() == correct);
} catch (RepositoryVerificationException e) {
if (correct) {
logger.debug(" -> container is being removed. Let's wait a bit...");
fail();
}
}
}, 5, TimeUnit.MINUTES);
}
use of org.elasticsearch.repositories.RepositoryVerificationException in project crate by crate.
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 = seed.getBytes(StandardCharsets.UTF_8);
BlobContainer testContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed)));
String blobName = "master.dat";
BytesArray bytes = new BytesArray(testBytes);
try (InputStream stream = bytes.streamInput()) {
testContainer.writeBlobAtomic(blobName, stream, bytes.length(), true);
}
return seed;
}
} catch (Exception e) {
Throwable cause = e.getCause();
Throwable errorInfo = cause == null ? e : cause;
throw new RepositoryVerificationException(metadata.name(), String.format(Locale.ENGLISH, "Unable to verify the repository, [%s] is not accessible on master node: %s '%s'", metadata.name(), errorInfo.getClass().getSimpleName(), errorInfo.getMessage()));
}
}
use of org.elasticsearch.repositories.RepositoryVerificationException in project crate by crate.
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 (IOException exp) {
throw new RepositoryVerificationException(metadata.name(), "cannot delete test data at " + basePath(), exp);
}
}
}
Aggregations