Wrong exception thrown when snapshot doesn't exist
As for https://github.com/elasticsearch/elasticsearch-cloud-aws/issues/86, we should raise a `SnapshotMissingException`. Closes #23. (cherry picked from commit 61ddb60)
This commit is contained in:
parent
976448e339
commit
d613f5f097
|
@ -30,6 +30,7 @@ import org.elasticsearch.common.collect.ImmutableMap;
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
import org.elasticsearch.common.logging.ESLoggerFactory;
|
import org.elasticsearch.common.logging.ESLoggerFactory;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
@ -95,6 +96,12 @@ public class AbstractAzureBlobContainer extends AbstractBlobContainer {
|
||||||
}
|
}
|
||||||
is.close();
|
is.close();
|
||||||
listener.onCompleted();
|
listener.onCompleted();
|
||||||
|
} catch (ServiceException e) {
|
||||||
|
if (e.getHttpStatusCode() == 404) {
|
||||||
|
listener.onFailure(new FileNotFoundException(e.getMessage()));
|
||||||
|
} else {
|
||||||
|
listener.onFailure(e);
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
IOUtils.closeWhileHandlingException(is);
|
IOUtils.closeWhileHandlingException(is);
|
||||||
listener.onFailure(e);
|
listener.onFailure(e);
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.repositories.RepositoryException;
|
import org.elasticsearch.repositories.RepositoryException;
|
||||||
import org.elasticsearch.repositories.RepositoryMissingException;
|
import org.elasticsearch.repositories.RepositoryMissingException;
|
||||||
|
import org.elasticsearch.snapshots.SnapshotMissingException;
|
||||||
import org.elasticsearch.snapshots.SnapshotState;
|
import org.elasticsearch.snapshots.SnapshotState;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.elasticsearch.test.store.MockDirectoryHelper;
|
import org.elasticsearch.test.store.MockDirectoryHelper;
|
||||||
|
@ -44,9 +45,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test needs Azure to run and -Dtests.azure=true to be set
|
* 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.
|
* Deletes repositories, supports wildcard notation.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue