Skip to content

Commit

Permalink
Remove alias dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Crawford <[email protected]>
  • Loading branch information
stephen-crawford committed Apr 24, 2023
1 parent 3575d98 commit cbfa154
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
package org.opensearch.test.framework.matcher;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;

Expand All @@ -41,7 +43,12 @@ public AliasExistsMatcher(String aliasName) {
protected boolean matchesSafely(Client client, Description mismatchDescription) {
try {
GetAliasesResponse response = client.admin().indices().getAliases(new GetAliasesRequest(aliasName)).get();
Map<String, List<AliasMetadata>> aliases = response.getAliases();

final Map<String, List<AliasMetadata>> aliases = new HashMap<>();
for (ObjectObjectCursor<String, List<AliasMetadata>> cursor : response.getAliases()) {
aliases.put(cursor.key, cursor.value);
}

Set<String> actualAliasNames = StreamSupport.stream(spliteratorUnknownSize(aliases.values().iterator(), IMMUTABLE), false)
.flatMap(Collection::stream)
.map(AliasMetadata::getAlias)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
*/
package org.opensearch.test.framework.matcher;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;

Expand Down Expand Up @@ -55,13 +57,21 @@ protected boolean matchesSafely(Client client, Description mismatchDescription)
private Set<String> getAliases(GetIndexTemplatesResponse response) {
return response.getIndexTemplates()
.stream()
.map(metadata -> metadata.getAliases())
.map(metadata -> {
Map<String, AliasMetadata> aliases = new HashMap<>();
for (ObjectObjectCursor<String, AliasMetadata> cursor : metadata.getAliases()) {
aliases.put(cursor.key, cursor.value);
}
return aliases;
})
.flatMap(aliasMap -> aliasNames(aliasMap))
.collect(Collectors.toSet());
}

private Stream<String> aliasNames(Map<String, AliasMetadata> aliasMap) {
return aliasMap.keySet().stream().map(key -> aliasMap.get(key).getAlias());
Iterable<Map.Entry<String, AliasMetadata>> iterable = () -> aliasMap.entrySet().iterator();
return StreamSupport.stream(iterable.spliterator(), false)
.map(entry -> entry.getValue().getAlias());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
*/
package org.opensearch.test.framework.matcher;

import java.util.HashMap;
import java.util.Map;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;

Expand All @@ -31,7 +34,11 @@ class GetSettingsResponseContainsIndicesMatcher extends TypeSafeDiagnosingMatche

@Override
protected boolean matchesSafely(GetSettingsResponse response, Description mismatchDescription) {
Map<String, Settings> indexToSettings = response.getIndexToSettings();

final Map<String, Settings> indexToSettings = new HashMap<>();
for (ObjectObjectCursor<String, Settings> cursor : response.getIndexToSettings()) {
indexToSettings.put(cursor.key, cursor.value);
}
for (String index : expectedIndices) {
if (!indexToSettings.containsKey(index)) {
mismatchDescription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.opensearch.test.framework.matcher;

import java.util.Map;

import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
Expand All @@ -37,6 +38,7 @@
import java.util.StringJoiner;
import java.util.regex.Pattern;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -377,8 +379,6 @@ public PrivilegesEvaluatorResponse evaluate(final User user, String action0, fin
presponse.allowed = true;
return presponse;
}


}
}

Expand Down Expand Up @@ -674,7 +674,10 @@ public Iterator<IndexMetadata> iterator() {

final List<AliasMetadata> filteredAliases = new ArrayList<AliasMetadata>();

final Map<String, AliasMetadata> aliases = indexMetaData.getAliases();
final Map<String, AliasMetadata> aliases = new HashMap<>();
for (ObjectObjectCursor<String, AliasMetadata> cursor : indexMetaData.getAliases()) {
aliases.put(cursor.key, cursor.value);
}

if(aliases != null && aliases.size() > 0) {
if (isDebugEnabled) {
Expand Down

0 comments on commit cbfa154

Please sign in to comment.