diff --git a/src/main/java/org/elasticsearch/cloud/azure/blobstore/AbstractAzureBlobContainer.java b/src/main/java/org/elasticsearch/cloud/azure/blobstore/AbstractAzureBlobContainer.java index 2d6bac608b3..cc94510c36b 100644 --- a/src/main/java/org/elasticsearch/cloud/azure/blobstore/AbstractAzureBlobContainer.java +++ b/src/main/java/org/elasticsearch/cloud/azure/blobstore/AbstractAzureBlobContainer.java @@ -30,6 +30,7 @@ import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLoggerFactory; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; @@ -95,6 +96,12 @@ public class AbstractAzureBlobContainer extends AbstractBlobContainer { } is.close(); listener.onCompleted(); + } catch (ServiceException e) { + if (e.getHttpStatusCode() == 404) { + listener.onFailure(new FileNotFoundException(e.getMessage())); + } else { + listener.onFailure(e); + } } catch (Throwable e) { IOUtils.closeWhileHandlingException(is); listener.onFailure(e); diff --git a/src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreITest.java b/src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreITest.java index fe3dae5a2bb..18173cebf6d 100644 --- a/src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreITest.java +++ b/src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreITest.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.repositories.RepositoryException; import org.elasticsearch.repositories.RepositoryMissingException; +import org.elasticsearch.snapshots.SnapshotMissingException; import org.elasticsearch.snapshots.SnapshotState; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.store.MockDirectoryHelper; @@ -44,9 +45,7 @@ import org.junit.Test; import java.net.URISyntaxException; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.*; /** * This test needs Azure to run and -Dtests.azure=true to be set @@ -268,6 +267,30 @@ public class AzureSnapshotRestoreITest extends AbstractAzureTest { } } + /** + * Test case for issue #23: https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/23 + */ + @Test + public void testNonExistingRepo_23() { + Client client = client(); + logger.info("--> creating azure repository with path [{}]", basePath); + PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") + .setType("azure").setSettings(ImmutableSettings.settingsBuilder() + .put(AzureStorageService.Fields.CONTAINER, "elasticsearch-integration") + .put(AzureStorageService.Fields.BASE_PATH, basePath) + .put(AzureStorageService.Fields.CHUNK_SIZE, randomIntBetween(1000, 10000)) + ).get(); + assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); + + logger.info("--> restore non existing snapshot"); + try { + client.admin().cluster().prepareRestoreSnapshot("test-repo", "no-existing-snapshot").setWaitForCompletion(true).execute().actionGet(); + fail("Shouldn't be here"); + } catch (SnapshotMissingException ex) { + // Expected + } + } + /** * Deletes repositories, supports wildcard notation. */