-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add repository-url module and move URLRepository #22752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
ad4f704
b32361f
563b616
54f6e6b
311d890
669c4ef
00b20f9
18fefbd
8f92848
abd7750
4e05efc
7bf6f4f
b263edc
983dc67
6c574e2
6ecf433
ee80d3b
ec750a9
6f661c8
fa40f2c
b8b6132
344eeb2
937ce94
63da34d
b49a346
1555ca0
e488f29
9ac5852
dd03e3a
12775b4
0880f6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| esplugin { | ||
| description 'Module for generic repositories' | ||
| classname 'org.elasticsearch.plugin.repositories.RepositoriesPlugin' | ||
| } | ||
|
|
||
| dependencies { | ||
|
||
| } | ||
|
|
||
| compileJava.options.compilerArgs << "-Xlint:-unchecked,-rawtypes" | ||
| compileTestJava.options.compilerArgs << "-Xlint:-unchecked,-rawtypes" | ||
|
|
||
| thirdPartyAudit.excludes = [ | ||
|
||
|
|
||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.plugin.repositories; | ||
|
|
||
| import org.elasticsearch.common.settings.Setting; | ||
| import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
| import org.elasticsearch.env.Environment; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.plugins.RepositoryPlugin; | ||
| import org.elasticsearch.repositories.Repository; | ||
| import org.elasticsearch.repositories.url.URLRepository; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class RepositoriesPlugin extends Plugin implements RepositoryPlugin { | ||
|
|
||
| @Override | ||
| public List<Setting<?>> getSettings() { | ||
| return Arrays.asList( | ||
| URLRepository.ALLOWED_URLS_SETTING, | ||
| URLRepository.REPOSITORIES_URL_SETTING, | ||
| URLRepository.SUPPORTED_PROTOCOLS_SETTING | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, Repository.Factory> getRepositories(Environment env, NamedXContentRegistry namedXContentRegistry) { | ||
| return Collections.singletonMap(URLRepository.TYPE, (metadata) -> new URLRepository(metadata, env, namedXContentRegistry)); | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.common.blobstore.url; | ||
|
|
||
| import com.sun.net.httpserver.HttpServer; | ||
| import org.elasticsearch.common.blobstore.BlobContainer; | ||
| import org.elasticsearch.common.blobstore.BlobPath; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.mocksocket.MockHttpServer; | ||
| import org.elasticsearch.test.ESTestCase; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import java.net.InetAddress; | ||
| import java.net.InetSocketAddress; | ||
| import java.net.MalformedURLException; | ||
| import java.net.URL; | ||
| import java.nio.file.NoSuchFileException; | ||
|
|
||
| public class URLBlobStoreTests extends ESTestCase { | ||
|
|
||
| private static HttpServer httpServer; | ||
| private static String blobName; | ||
| private static byte[] message = new byte[512]; | ||
| private URLBlobStore urlBlobStore; | ||
|
|
||
| @BeforeClass | ||
| public static void startHttp() throws Exception { | ||
| for (int i = 0; i < message.length; ++i) { | ||
| message[i] = randomByte(); | ||
| } | ||
| blobName = randomAsciiOfLength(8); | ||
|
|
||
| httpServer = MockHttpServer.createHttp(new InetSocketAddress(InetAddress.getLoopbackAddress().getHostAddress(), 6001), 0); | ||
|
|
||
| httpServer.createContext("/indices/" + blobName, (s) -> { | ||
| s.sendResponseHeaders(200, message.length); | ||
| OutputStream responseBody = s.getResponseBody(); | ||
| responseBody.write(message); | ||
| responseBody.close(); | ||
| }); | ||
|
|
||
| httpServer.start(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void stopHttp() throws IOException { | ||
| httpServer.stop(0); | ||
| httpServer = null; | ||
| } | ||
|
|
||
| @Before | ||
| public void storeSetup() throws MalformedURLException { | ||
| Settings settings = Settings.EMPTY; | ||
| String spec = "http://localhost:6001/"; | ||
| urlBlobStore = new URLBlobStore(settings, new URL(spec)); | ||
| } | ||
|
|
||
| public void testURLBlobStoreCanReadBlob() throws IOException { | ||
| BlobContainer container = urlBlobStore.blobContainer(BlobPath.cleanPath().add("indices")); | ||
| try (InputStream stream = container.readBlob(blobName)) { | ||
| byte[] bytes = new byte[message.length]; | ||
| int read = stream.read(bytes); | ||
| assertEquals(message.length, read); | ||
| assertArrayEquals(message, bytes); | ||
| } | ||
| } | ||
|
|
||
| public void testNoBlobFound() throws IOException { | ||
| BlobContainer container = urlBlobStore.blobContainer(BlobPath.cleanPath().add("indices")); | ||
| String incorrectBlobName = "incorrect_" + blobName; | ||
| try (InputStream ignored = container.readBlob(incorrectBlobName)) { | ||
| fail("Should have thrown NoSuchFileException exception"); | ||
| ignored.read(); | ||
| } catch (NoSuchFileException e) { | ||
| assertEquals(String.format("[%s] blob not found", incorrectBlobName), e.getMessage()); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? If you are going to move the continue to the next line (breaking with the convention of the other loop shortcut statements here...), please open a block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. I definitely did not intend that change. I'll revert that line.