Search in sources :

Example 6 with RepositoryMetaData

use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project elasticsearch by elastic.

the class MockRepository method overrideSettings.

private static RepositoryMetaData overrideSettings(RepositoryMetaData metadata, Environment environment) {
    // this is super duper hacky
    if (metadata.settings().getAsBoolean("localize_location", false)) {
        Path location = PathUtils.get(metadata.settings().get("location"));
        location = location.resolve(Integer.toString(environment.hashCode()));
        return new RepositoryMetaData(metadata.name(), metadata.type(), Settings.builder().put(metadata.settings()).put("location", location.toAbsolutePath()).build());
    } else {
        return metadata;
    }
}
Also used : Path(java.nio.file.Path) BlobPath(org.elasticsearch.common.blobstore.BlobPath) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData)

Example 7 with RepositoryMetaData

use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project elasticsearch by elastic.

the class URLRepositoryTests method testWhiteListingRepoURL.

public void testWhiteListingRepoURL() throws IOException {
    String repoPath = createTempDir().resolve("repository").toUri().toURL().toString();
    Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(URLRepository.ALLOWED_URLS_SETTING.getKey(), repoPath).put(URLRepository.REPOSITORIES_URL_SETTING.getKey(), repoPath).build();
    RepositoryMetaData repositoryMetaData = new RepositoryMetaData("url", URLRepository.TYPE, baseSettings);
    new URLRepository(repositoryMetaData, new Environment(baseSettings), new NamedXContentRegistry(Collections.emptyList()));
}
Also used : RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) Environment(org.elasticsearch.env.Environment) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Settings(org.elasticsearch.common.settings.Settings)

Example 8 with RepositoryMetaData

use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project elasticsearch by elastic.

the class URLRepositoryTests method testIfNotWhiteListedMustSetRepoURL.

public void testIfNotWhiteListedMustSetRepoURL() throws IOException {
    String repoPath = createTempDir().resolve("repository").toUri().toURL().toString();
    Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(URLRepository.REPOSITORIES_URL_SETTING.getKey(), repoPath).build();
    RepositoryMetaData repositoryMetaData = new RepositoryMetaData("url", URLRepository.TYPE, baseSettings);
    try {
        new URLRepository(repositoryMetaData, new Environment(baseSettings), new NamedXContentRegistry(Collections.emptyList()));
        fail("RepositoryException should have been thrown.");
    } catch (RepositoryException e) {
        String msg = "[url] file url [" + repoPath + "] doesn't match any of the locations specified by path.repo or repositories.url.allowed_urls";
        assertEquals(msg, e.getMessage());
    }
}
Also used : RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) Environment(org.elasticsearch.env.Environment) RepositoryException(org.elasticsearch.repositories.RepositoryException) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Settings(org.elasticsearch.common.settings.Settings)

Example 9 with RepositoryMetaData

use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project elasticsearch by elastic.

the class GoogleCloudStorageBlobStoreRepositoryTests method testChunkSize.

public void testChunkSize() {
    // default chunk size
    RepositoryMetaData repositoryMetaData = new RepositoryMetaData("repo", GoogleCloudStorageRepository.TYPE, Settings.EMPTY);
    ByteSizeValue chunkSize = GoogleCloudStorageRepository.getSetting(GoogleCloudStorageRepository.CHUNK_SIZE, repositoryMetaData);
    assertEquals(GoogleCloudStorageRepository.MAX_CHUNK_SIZE, chunkSize);
    // chunk size in settings
    int size = randomIntBetween(1, 100);
    repositoryMetaData = new RepositoryMetaData("repo", GoogleCloudStorageRepository.TYPE, Settings.builder().put("chunk_size", size + "mb").build());
    chunkSize = GoogleCloudStorageRepository.getSetting(GoogleCloudStorageRepository.CHUNK_SIZE, repositoryMetaData);
    assertEquals(new ByteSizeValue(size, ByteSizeUnit.MB), chunkSize);
    // zero bytes is not allowed
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
        RepositoryMetaData repoMetaData = new RepositoryMetaData("repo", GoogleCloudStorageRepository.TYPE, Settings.builder().put("chunk_size", "0").build());
        GoogleCloudStorageRepository.getSetting(GoogleCloudStorageRepository.CHUNK_SIZE, repoMetaData);
    });
    assertEquals("Failed to parse value [0] for setting [chunk_size] must be >= 1b", e.getMessage());
    // negative bytes not allowed
    e = expectThrows(IllegalArgumentException.class, () -> {
        RepositoryMetaData repoMetaData = new RepositoryMetaData("repo", GoogleCloudStorageRepository.TYPE, Settings.builder().put("chunk_size", "-1").build());
        GoogleCloudStorageRepository.getSetting(GoogleCloudStorageRepository.CHUNK_SIZE, repoMetaData);
    });
    assertEquals("Failed to parse value [-1] for setting [chunk_size] must be >= 1b", e.getMessage());
    // greater than max chunk size not allowed
    e = expectThrows(IllegalArgumentException.class, () -> {
        RepositoryMetaData repoMetaData = new RepositoryMetaData("repo", GoogleCloudStorageRepository.TYPE, Settings.builder().put("chunk_size", "101mb").build());
        GoogleCloudStorageRepository.getSetting(GoogleCloudStorageRepository.CHUNK_SIZE, repoMetaData);
    });
    assertEquals("Failed to parse value [101mb] for setting [chunk_size] must be <= 100mb", e.getMessage());
}
Also used : RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue)

Example 10 with RepositoryMetaData

use of org.elasticsearch.cluster.metadata.RepositoryMetaData in project crate by crate.

the class SnapshotRestoreAnalyzerTest method before.

@Before
public void before() throws Exception {
    RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(new RepositoryMetaData("my_repo", "fs", Settings.builder().put("location", "/tmp/my_repo").build()));
    ClusterState clusterState = ClusterState.builder(new ClusterName("testing")).metaData(MetaData.builder().putCustom(RepositoriesMetaData.TYPE, repositoriesMetaData)).build();
    NoopClusterService clusterService = new NoopClusterService(clusterState);
    executor = SQLExecutor.builder(clusterService).addDocTable(USER_TABLE_INFO).addDocTable(TEST_DOC_LOCATIONS_TABLE_INFO).addDocTable(TEST_PARTITIONED_TABLE_INFO).build();
}
Also used : RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) ClusterState(org.elasticsearch.cluster.ClusterState) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Before(org.junit.Before)

Aggregations

RepositoryMetadata (org.elasticsearch.cluster.metadata.RepositoryMetadata)29 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)24 ClusterState (org.elasticsearch.cluster.ClusterState)13 RepositoriesMetadata (org.elasticsearch.cluster.metadata.RepositoriesMetadata)13 ArrayList (java.util.ArrayList)11 Settings (org.elasticsearch.common.settings.Settings)11 RepositoriesMetaData (org.elasticsearch.cluster.metadata.RepositoriesMetaData)10 IOException (java.io.IOException)8 ClusterName (org.elasticsearch.cluster.ClusterName)8 Before (org.junit.Before)7 HashMap (java.util.HashMap)6 BlobStoreRepository (org.elasticsearch.repositories.blobstore.BlobStoreRepository)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)5 ActionListener (org.elasticsearch.action.ActionListener)5 BlobContainer (org.elasticsearch.common.blobstore.BlobContainer)5 RepositoryException (org.elasticsearch.repositories.RepositoryException)5 Test (org.junit.Test)5 List (java.util.List)4 Map (java.util.Map)4