blob: 6fbec41aba19da5874ec82120f0d4c1dd63b568c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.restapi;
import com.yahoo.config.subscription.ConfigGetter;
import com.yahoo.vespa.config.content.core.BucketspacesConfig;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Class that based on BucketspacesConfig builds a mapping from document type to which bucket space it belongs to.
*/
class BucketSpaceEnumerator {
private final Map<String, String> doctypeToSpace;
private BucketSpaceEnumerator(String configId) {
doctypeToSpace = Collections.unmodifiableMap(buildMappingFromConfig(configId));
}
public static BucketSpaceEnumerator fromConfig(String configId) {
return new BucketSpaceEnumerator(configId);
}
public Map<String, String> getDoctypeToSpaceMapping() {
return doctypeToSpace;
}
private static Map<String, String> buildMappingFromConfig(String configId) {
BucketspacesConfig config = new ConfigGetter<>(BucketspacesConfig.class).getConfig(configId);
return config.documenttype().stream().collect(Collectors.toMap(dt -> dt.name(), dt -> dt.bucketspace()));
}
}
|