Skip to content

Commit

Permalink
adding remote_publication to the prefix list
Browse files Browse the repository at this point in the history
  • Loading branch information
rajiv-kv committed Oct 17, 2024
1 parent 30df32f commit f8b668c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class RemoteStoreNodeAttribute {

public static final List<String> REMOTE_STORE_NODE_ATTRIBUTE_KEY_PREFIX = List.of("remote_store");
public static final List<String> REMOTE_STORE_NODE_ATTRIBUTE_KEY_PREFIX = List.of("remote_store", "remote_publication");

static final Function<String, String> REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_FN = (prefix) -> prefix
+ ".state.repository";
Expand Down Expand Up @@ -71,8 +71,7 @@ public class RemoteStoreNodeAttribute {
public static final String REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX = "remote_store.repository.%s.settings.";

public static final String REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT = "%s.repository.%s.type";
public static final String REPOSITORY_CRYPTO_ATTRIBUTE_KEY_FORMAT = "%s.repository.%s."
+ CryptoMetadata.CRYPTO_METADATA_KEY;
public static final String REPOSITORY_CRYPTO_ATTRIBUTE_KEY_FORMAT = "%s.repository.%s." + CryptoMetadata.CRYPTO_METADATA_KEY;
public static final String REPOSITORY_CRYPTO_SETTINGS_PREFIX = REPOSITORY_CRYPTO_ATTRIBUTE_KEY_FORMAT
+ "."
+ CryptoMetadata.SETTINGS_KEY;
Expand Down Expand Up @@ -126,12 +125,7 @@ private CryptoMetadata buildCryptoMetadata(DiscoveryNode node, String repository
String keyProviderName = validateAttributeNonNull(node, metadataKey + "." + CryptoMetadata.KEY_PROVIDER_NAME_KEY);
String keyProviderType = validateAttributeNonNull(node, metadataKey + "." + CryptoMetadata.KEY_PROVIDER_TYPE_KEY);

String settingsAttributeKeyPrefix = String.format(
Locale.getDefault(),
REPOSITORY_CRYPTO_SETTINGS_PREFIX,
prefix,
repositoryName
);
String settingsAttributeKeyPrefix = String.format(Locale.getDefault(), REPOSITORY_CRYPTO_SETTINGS_PREFIX, prefix, repositoryName);

Map<String, String> settingsMap = node.getAttributes()
.keySet()
Expand Down Expand Up @@ -167,7 +161,7 @@ private Map<String, String> validateSettingsAttributesNonNull(DiscoveryNode node
return settingsMap;
}

private RepositoryMetadata buildRepositoryMetadata(DiscoveryNode node, String name, String prefix) {
private RepositoryMetadata buildRepositoryMetadata(DiscoveryNode node, String name, String prefix) {
String type = validateAttributeNonNull(
node,
String.format(Locale.getDefault(), REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT, prefix, name)
Expand Down Expand Up @@ -201,7 +195,7 @@ private static boolean containsKey(Map<String, String> attributes, List<String>

}

private static Tuple<String,String> getValue(Map<String, String> attributes, List<String> keys) {
private static Tuple<String, String> getValue(Map<String, String> attributes, List<String> keys) {
for (String key : keys) {
if (attributes.containsKey(key)) {
return new Tuple<>(attributes.get(key), key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_CRYPTO_SETTINGS_PREFIX;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REPOSITORY_CRYPTO_ATTRIBUTE_KEY_FORMAT;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REPOSITORY_CRYPTO_SETTINGS_PREFIX;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT;
import static org.opensearch.test.RemoteStoreAttributeConstants.REMOTE_PUBLICATION_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.test.RemoteStoreAttributeConstants.REMOTE_PUBLICATION_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.test.RemoteStoreAttributeConstants.REMOTE_PUBLICATION_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.test.RemoteStoreAttributeConstants.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.test.RemoteStoreAttributeConstants.REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY;
import static org.opensearch.test.RemoteStoreAttributeConstants.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY;
Expand All @@ -38,6 +45,53 @@ public class RemoteStoreNodeAttributeTests extends OpenSearchTestCase {
static private final String KEY_ARN = "arn:aws:kms:us-east-1:123456789:key/6e9aa906-2cc3-4924-8ded-f385c78d9dcf";
static private final String REGION = "us-east-1";

public void testCryptoMetadataForPublication() throws UnknownHostException {
String repoName = "remote-store-A";
String prefix = "remote_publication";
String repoTypeSettingKey = String.format(Locale.ROOT, REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT, prefix, repoName);
String repoSettingsKey = String.format(Locale.ROOT, REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX, prefix, repoName);
String repoCryptoMetadataKey = String.format(Locale.ROOT, REPOSITORY_CRYPTO_ATTRIBUTE_KEY_FORMAT, prefix, repoName);
String repoCryptoMetadataSettingsKey = String.format(Locale.ROOT, REPOSITORY_CRYPTO_SETTINGS_PREFIX, prefix, repoName);
Map<String, String> attr = Map.of(
REMOTE_PUBLICATION_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY,
repoName,
REMOTE_PUBLICATION_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY,
repoName,
REMOTE_PUBLICATION_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY,
repoName,
repoTypeSettingKey,
"s3",
repoSettingsKey,
"abc",
repoSettingsKey + "base_path",
"xyz",
repoCryptoMetadataKey + ".key_provider_name",
"store-test",
repoCryptoMetadataKey + ".key_provider_type",
"aws-kms",
repoCryptoMetadataSettingsKey + ".region",
REGION,
repoCryptoMetadataSettingsKey + ".key_arn",
KEY_ARN
);
DiscoveryNode node = new DiscoveryNode(
"C",
new TransportAddress(InetAddress.getByName("localhost"), 9876),
attr,
emptySet(),
Version.CURRENT
);

RemoteStoreNodeAttribute remoteStoreNodeAttribute = new RemoteStoreNodeAttribute(node);
assertEquals(remoteStoreNodeAttribute.getRepositoriesMetadata().repositories().size(), 1);
RepositoryMetadata repositoryMetadata = remoteStoreNodeAttribute.getRepositoriesMetadata().repositories().get(0);
Settings.Builder settings = Settings.builder();
settings.put("region", REGION);
settings.put("key_arn", KEY_ARN);
CryptoMetadata cryptoMetadata = new CryptoMetadata("store-test", "aws-kms", settings.build());
assertEquals(cryptoMetadata, repositoryMetadata.cryptoMetadata());
}

public void testCryptoMetadata() throws UnknownHostException {
String repoName = "remote-store-A";
String repoTypeSettingKey = String.format(Locale.ROOT, REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT, repoName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ public class RemoteStoreAttributeConstants {
public static final String REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY = "remote_store.segment.repository";
public static final String REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY = "remote_store.translog.repository";
public static final String REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY = "remote_store.routing_table.repository";

public static final String REMOTE_PUBLICATION_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY = "remote_publication.state.repository";
public static final String REMOTE_PUBLICATION_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY = "remote_publication.segment.repository";
public static final String REMOTE_PUBLICATION_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY = "remote_publication.translog.repository";
public static final String REMOTE_PUBLICATION_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY =
"remote_publication.routing_table.repository";

}

0 comments on commit f8b668c

Please sign in to comment.