Skip to content

Commit d613f5f

Browse files
committed
Wrong exception thrown when snapshot doesn't exist
As for elastic/elasticsearch-cloud-aws#86, we should raise a `SnapshotMissingException`. Closes #23. (cherry picked from commit 61ddb60)
1 parent 976448e commit d613f5f

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/main/java/org/elasticsearch/cloud/azure/blobstore/AbstractAzureBlobContainer.java

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.common.logging.ESLogger;
3131
import org.elasticsearch.common.logging.ESLoggerFactory;
3232

33+
import java.io.FileNotFoundException;
3334
import java.io.IOException;
3435
import java.io.InputStream;
3536
import java.net.URISyntaxException;
@@ -95,6 +96,12 @@ public void run() {
9596
}
9697
is.close();
9798
listener.onCompleted();
99+
} catch (ServiceException e) {
100+
if (e.getHttpStatusCode() == 404) {
101+
listener.onFailure(new FileNotFoundException(e.getMessage()));
102+
} else {
103+
listener.onFailure(e);
104+
}
98105
} catch (Throwable e) {
99106
IOUtils.closeWhileHandlingException(is);
100107
listener.onFailure(e);

src/test/java/org/elasticsearch/repositories/azure/AzureSnapshotRestoreITest.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.elasticsearch.common.settings.Settings;
3636
import org.elasticsearch.repositories.RepositoryException;
3737
import org.elasticsearch.repositories.RepositoryMissingException;
38+
import org.elasticsearch.snapshots.SnapshotMissingException;
3839
import org.elasticsearch.snapshots.SnapshotState;
3940
import org.elasticsearch.test.ElasticsearchIntegrationTest;
4041
import org.elasticsearch.test.store.MockDirectoryHelper;
@@ -44,9 +45,7 @@
4445

4546
import java.net.URISyntaxException;
4647

47-
import static org.hamcrest.Matchers.equalTo;
48-
import static org.hamcrest.Matchers.greaterThan;
49-
import static org.hamcrest.Matchers.is;
48+
import static org.hamcrest.Matchers.*;
5049

5150
/**
5251
* This test needs Azure to run and -Dtests.azure=true to be set
@@ -268,6 +267,30 @@ private void checkContainerName(String container, boolean correct) {
268267
}
269268
}
270269

270+
/**
271+
* Test case for issue #23: https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/23
272+
*/
273+
@Test
274+
public void testNonExistingRepo_23() {
275+
Client client = client();
276+
logger.info("--> creating azure repository with path [{}]", basePath);
277+
PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo")
278+
.setType("azure").setSettings(ImmutableSettings.settingsBuilder()
279+
.put(AzureStorageService.Fields.CONTAINER, "elasticsearch-integration")
280+
.put(AzureStorageService.Fields.BASE_PATH, basePath)
281+
.put(AzureStorageService.Fields.CHUNK_SIZE, randomIntBetween(1000, 10000))
282+
).get();
283+
assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
284+
285+
logger.info("--> restore non existing snapshot");
286+
try {
287+
client.admin().cluster().prepareRestoreSnapshot("test-repo", "no-existing-snapshot").setWaitForCompletion(true).execute().actionGet();
288+
fail("Shouldn't be here");
289+
} catch (SnapshotMissingException ex) {
290+
// Expected
291+
}
292+
}
293+
271294
/**
272295
* Deletes repositories, supports wildcard notation.
273296
*/

0 commit comments

Comments
 (0)