use of org.opensearch.repositories.RepositoryException in project OpenSearch by opensearch-project.
the class URLRepository method checkURL.
/**
* Makes sure that the url is white listed or if it points to the local file system it matches one on of the root path in path.repo
*/
private URL checkURL(URL url) {
String protocol = url.getProtocol();
if (protocol == null) {
throw new RepositoryException(getMetadata().name(), "unknown url protocol from URL [" + url + "]");
}
for (String supportedProtocol : supportedProtocols) {
if (supportedProtocol.equals(protocol)) {
try {
if (URIPattern.match(urlAllowList, url.toURI())) {
// URL matches white list - no additional processing is needed
return url;
}
} catch (URISyntaxException ex) {
logger.warn("cannot parse the specified url [{}]", url);
throw new RepositoryException(getMetadata().name(), "cannot parse the specified url [" + url + "]");
}
// We didn't match white list - try to resolve against path.repo
URL normalizedUrl = environment.resolveRepoURL(url);
if (normalizedUrl == null) {
String logMessage = "The specified url [{}] doesn't start with any repository paths specified by the " + "path.repo setting or by {} setting: [{}] ";
logger.warn(logMessage, url, ALLOWED_URLS_SETTING.getKey(), environment.repoFiles());
String exceptionMessage = "file url [" + url + "] doesn't match any of the locations specified by path.repo or " + ALLOWED_URLS_SETTING.getKey();
throw new RepositoryException(getMetadata().name(), exceptionMessage);
}
return normalizedUrl;
}
}
throw new RepositoryException(getMetadata().name(), "unsupported url protocol [" + protocol + "] from URL [" + url + "]");
}
use of org.opensearch.repositories.RepositoryException in project OpenSearch by opensearch-project.
the class URLRepositoryTests method testNonNormalizedUrl.
public void testNonNormalizedUrl() throws IOException {
Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(URLRepository.ALLOWED_URLS_SETTING.getKey(), "file:/tmp/").put(URLRepository.REPOSITORIES_URL_SETTING.getKey(), "file:/var/").build();
RepositoryMetadata repositoryMetadata = new RepositoryMetadata("url", URLRepository.TYPE, baseSettings);
final URLRepository repository = createRepository(baseSettings, repositoryMetadata);
repository.start();
try {
repository.blobContainer();
fail("RepositoryException should have been thrown.");
} catch (RepositoryException e) {
assertEquals("[url] file url [file:/var/] doesn't match any of the locations " + "specified by path.repo or repositories.url.allowed_urls", e.getMessage());
}
}
use of org.opensearch.repositories.RepositoryException in project OpenSearch by opensearch-project.
the class SharedClusterSnapshotRestoreIT method testSnapshotSucceedsAfterSnapshotFailure.
public void testSnapshotSucceedsAfterSnapshotFailure() throws Exception {
// TODO: Fix repo cleanup logic to handle these leaked snap-file and only exclude test-repo (the mock repo) here.
disableRepoConsistencyCheck("This test uses a purposely broken repository implementation that results in leaking snap-{uuid}.dat files");
logger.info("--> creating repository");
final Path repoPath = randomRepoPath();
final Client client = client();
assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("mock").setVerify(false).setSettings(Settings.builder().put("location", repoPath).put("random_control_io_exception_rate", randomIntBetween(5, 20) / 100f).put("random", randomAlphaOfLength(10))));
assertAcked(prepareCreate("test-idx").setSettings(// that caused problems with writing subsequent snapshots if they happened to be lingering in the repository
indexSettingsNoReplicas(1)));
ensureGreen();
final int numDocs = randomIntBetween(1, 5);
indexRandomDocs("test-idx", numDocs);
logger.info("--> snapshot with potential I/O failures");
try {
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
if (createSnapshotResponse.getSnapshotInfo().totalShards() != createSnapshotResponse.getSnapshotInfo().successfulShards()) {
assertThat(getFailureCount("test-repo"), greaterThan(0L));
assertThat(createSnapshotResponse.getSnapshotInfo().shardFailures().size(), greaterThan(0));
for (SnapshotShardFailure shardFailure : createSnapshotResponse.getSnapshotInfo().shardFailures()) {
assertThat(shardFailure.reason(), endsWith("; nested: IOException[Random IOException]"));
}
}
} catch (SnapshotException | RepositoryException ex) {
// sometimes, the snapshot will fail with a top level I/O exception
assertThat(ExceptionsHelper.stackTrace(ex), containsString("Random IOException"));
}
logger.info("--> snapshot with no I/O failures");
createRepository("test-repo-2", "mock", repoPath);
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo-2", "test-snap-2").setWaitForCompletion(true).setIndices("test-idx").get();
assertEquals(0, createSnapshotResponse.getSnapshotInfo().failedShards());
assertEquals(SnapshotState.SUCCESS, getSnapshot("test-repo-2", "test-snap-2").state());
}
use of org.opensearch.repositories.RepositoryException in project OpenSearch by opensearch-project.
the class RepositoriesIT method testMisconfiguredRepository.
public void testMisconfiguredRepository() throws Exception {
Client client = client();
logger.info("--> trying creating repository with incorrect settings");
try {
client.admin().cluster().preparePutRepository("test-repo").setType("fs").get();
fail("Shouldn't be here");
} catch (RepositoryException ex) {
assertThat(ex.toString(), containsString("missing location"));
}
logger.info("--> trying creating fs repository with location that is not registered in path.repo setting");
Path invalidRepoPath = createTempDir().toAbsolutePath();
String location = invalidRepoPath.toString();
try {
client().admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", location)).get();
fail("Shouldn't be here");
} catch (RepositoryException ex) {
assertThat(ex.toString(), containsString("location [" + location + "] doesn't match any of the locations specified " + "by path.repo"));
}
}
use of org.opensearch.repositories.RepositoryException in project OpenSearch by opensearch-project.
the class CorruptedBlobStoreRepositoryIT method assertRepositoryBlocked.
private void assertRepositoryBlocked(Client client, String repo, String existingSnapshot) {
logger.info("--> try to delete snapshot");
final RepositoryException repositoryException3 = expectThrows(RepositoryException.class, () -> client.admin().cluster().prepareDeleteSnapshot(repo, existingSnapshot).execute().actionGet());
assertThat(repositoryException3.getMessage(), containsString("Could not read repository data because the contents of the repository do not match its expected state."));
logger.info("--> try to create snapshot");
final RepositoryException repositoryException4 = expectThrows(RepositoryException.class, () -> client.admin().cluster().prepareCreateSnapshot(repo, existingSnapshot).execute().actionGet());
assertThat(repositoryException4.getMessage(), containsString("Could not read repository data because the contents of the repository do not match its expected state."));
}
Aggregations