Skip to content

Commit 28306b4

Browse files
authored
Take into account base_path setting during repository analysis execution. (#69690)
Relates #67247
1 parent 50926fd commit 28306b4

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

x-pack/plugin/snapshot-repo-test-kit/src/internalClusterTest/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalysisSuccessIT.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.common.blobstore.DeleteResult;
1818
import org.elasticsearch.common.blobstore.support.PlainBlobMetadata;
1919
import org.elasticsearch.common.bytes.BytesReference;
20+
import org.elasticsearch.common.settings.Settings;
2021
import org.elasticsearch.common.unit.ByteSizeValue;
2122
import org.elasticsearch.common.unit.TimeValue;
2223
import org.elasticsearch.common.util.BigArrays;
@@ -49,13 +50,16 @@
4950
import java.util.function.Consumer;
5051
import java.util.stream.Collectors;
5152

53+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
5254
import static org.hamcrest.Matchers.equalTo;
5355
import static org.hamcrest.Matchers.lessThanOrEqualTo;
5456
import static org.hamcrest.Matchers.nullValue;
5557
import static org.hamcrest.Matchers.startsWith;
5658

5759
public class RepositoryAnalysisSuccessIT extends AbstractSnapshotIntegTestCase {
5860

61+
private static final String BASE_PATH_SETTING_KEY = "base_path";
62+
5963
@Before
6064
public void suppressConsistencyChecks() {
6165
disableRepoConsistencyCheck("repository is not used for snapshots");
@@ -68,9 +72,16 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
6872

6973
public void testRepositoryAnalysis() {
7074

71-
createRepositoryNoVerify("test-repo", TestPlugin.ASSERTING_REPO_TYPE);
75+
final Settings.Builder settings = Settings.builder();
76+
if (randomBoolean()) {
77+
settings.put(BASE_PATH_SETTING_KEY, randomAlphaOfLength(10));
78+
}
7279

73-
final AssertingBlobStore blobStore = new AssertingBlobStore();
80+
assertAcked(
81+
clusterAdmin().preparePutRepository("test-repo").setVerify(false).setType(TestPlugin.ASSERTING_REPO_TYPE).setSettings(settings)
82+
);
83+
84+
final AssertingBlobStore blobStore = new AssertingBlobStore(settings.get(BASE_PATH_SETTING_KEY));
7485
for (final RepositoriesService repositoriesService : internalCluster().getInstances(RepositoriesService.class)) {
7586
try {
7687
((AssertingRepository) repositoriesService.repository("test-repo")).setBlobStore(blobStore);
@@ -133,12 +144,21 @@ public Map<String, Repository.Factory> getRepositories(
133144
clusterService,
134145
bigArrays,
135146
recoverySettings,
136-
new BlobPath()
147+
buildBlobPath(metadata.settings())
137148
)
138149
);
139150
}
140151
}
141152

153+
private static BlobPath buildBlobPath(Settings settings) {
154+
final String basePath = settings.get(BASE_PATH_SETTING_KEY);
155+
if (basePath == null) {
156+
return BlobPath.cleanPath();
157+
} else {
158+
return BlobPath.cleanPath().add(basePath);
159+
}
160+
}
161+
142162
static class AssertingRepository extends BlobStoreRepository {
143163

144164
private final AtomicReference<BlobStore> blobStoreRef = new AtomicReference<>();
@@ -167,6 +187,7 @@ protected BlobStore createBlobStore() {
167187
}
168188

169189
static class AssertingBlobStore implements BlobStore {
190+
private final String pathPrefix;
170191

171192
@Nullable // if no current blob container
172193
private String currentPath;
@@ -179,9 +200,13 @@ static class AssertingBlobStore implements BlobStore {
179200
private long maxBlobSize = new RepositoryAnalyzeAction.Request("dummy").getMaxBlobSize().getBytes();
180201
private long maxTotalBlobSize = new RepositoryAnalyzeAction.Request("dummy").getMaxTotalDataSize().getBytes();
181202

203+
AssertingBlobStore(@Nullable String basePath) {
204+
this.pathPrefix = basePath == null ? "" : basePath + "/";
205+
}
206+
182207
@Override
183208
public BlobContainer blobContainer(BlobPath path) {
184-
assertThat(path.buildAsString(), startsWith("temp-analysis-"));
209+
assertThat(path.buildAsString(), startsWith(pathPrefix + "temp-analysis-"));
185210

186211
synchronized (this) {
187212
if (currentPath == null) {

x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/BlobAnalyzeAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
178178
throw new IllegalArgumentException("repository [" + request.getRepositoryName() + "] is read-only");
179179
}
180180
final BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository;
181-
final BlobContainer blobContainer = blobStoreRepository.blobStore().blobContainer(new BlobPath().add(request.blobPath));
181+
final BlobPath path = blobStoreRepository.basePath().add(request.blobPath);
182+
final BlobContainer blobContainer = blobStoreRepository.blobStore().blobContainer(path);
182183

183184
logger.trace("handling [{}]", request);
184185

x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/GetBlobChecksumAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.action.support.ActionFilters;
1818
import org.elasticsearch.action.support.HandledTransportAction;
1919
import org.elasticsearch.common.blobstore.BlobContainer;
20-
import org.elasticsearch.common.blobstore.BlobPath;
2120
import org.elasticsearch.common.inject.Inject;
2221
import org.elasticsearch.common.io.stream.StreamInput;
2322
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -85,7 +84,8 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
8584
}
8685

8786
final BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository;
88-
final BlobContainer blobContainer = blobStoreRepository.blobStore().blobContainer(new BlobPath().add(request.getBlobPath()));
87+
final BlobContainer blobContainer = blobStoreRepository.blobStore()
88+
.blobContainer(blobStoreRepository.basePath().add(request.getBlobPath()));
8989

9090
logger.trace("handling [{}]", request);
9191

x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.elasticsearch.common.UUIDs;
3030
import org.elasticsearch.common.blobstore.BlobContainer;
3131
import org.elasticsearch.common.blobstore.BlobMetadata;
32-
import org.elasticsearch.common.blobstore.BlobPath;
3332
import org.elasticsearch.common.inject.Inject;
3433
import org.elasticsearch.common.io.stream.StreamInput;
3534
import org.elasticsearch.common.io.stream.StreamOutput;
@@ -525,7 +524,7 @@ public BlobAnalyzeAction.Response read(StreamInput in) throws IOException {
525524
}
526525

527526
private BlobContainer getBlobContainer() {
528-
return repository.blobStore().blobContainer(new BlobPath().add(blobPath));
527+
return repository.blobStore().blobContainer(repository.basePath().add(blobPath));
529528
}
530529

531530
private void onWorkerCompletion() {

0 commit comments

Comments
 (0)