Skip to content

Commit

Permalink
#24816 refactor and optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyDotcms committed Sep 19, 2023
1 parent 6b757f6 commit a1fc4c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,19 @@ public static void prepare() throws Exception {
contentletIndexAPI = APILocator.getContentletIndexAPI();
}


@Test
public void testCreate_100_SiteSearchIndex() throws IOException, DotDataException {
String timeStamp;
String indexName;
String aliasName;
public void test_createSiteSearchIndex_shouldBePossibleToAddMoreThan100() throws IOException, DotDataException {
String timeStamp, indexName, aliasName;
String lastCreatedIndex = "";

Set<String> data = indexAPI.listIndices();
// assertEquals(0, data.size());
int indicesAmount = 120;
//Set<String> data = indexAPI.listIndices();

final int indicesAmount = 115;
for (int i = 0; i < indicesAmount; i++) {
timeStamp = String.valueOf(new Date().getTime());
indexName = ES_SITE_SEARCH_NAME + "_" +i+ "_" + timeStamp;
aliasName = "indexAlias" + "_" + i + "_" + timeStamp;
aliasName = "indexAlias" + "_" +i+ "_" + timeStamp;

siteSearchAPI.createSiteSearchIndex(indexName, aliasName, 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,46 +859,42 @@ public Map<String,String> getIndexAlias(List<String> indexNames) {

public Map<String,String> getIndexAlias(String[] indexNames) {

String[] indexNamesWithPrefix = new String[indexNames.length];
final String[] indexNamesWithPrefix = new String[indexNames.length];
for (int i = 0; i < indexNames.length; i++){
indexNamesWithPrefix[i] = getNameWithClusterIDPrefix(indexNames[i]);
}
final int batchSize = 50;
int limit = 0;

//stores the offset to iterate
int currentOffset = 0;
int limit = Math.min(50, indexNamesWithPrefix.length);

//stores arrays of 50 elements or less
ArrayList<String[]> partitionLists = new ArrayList<String[]>();

//stores 50 elements or less
String[] partition = new String[limit];
final ArrayList<String[]> partitionLists = new ArrayList<String[]>();

//fill the partition list
while (currentOffset < indexNamesWithPrefix.length) {
//update the limit to the next iteration
limit = Math.min(batchSize, indexNamesWithPrefix.length - currentOffset);
final String[] partition = new String[limit];
//loop to fill the partition
//todo: validar que la cantidad de iteraciones sea correcta
for (int i = 0; i < limit; i++) {
partition[i] = indexNamesWithPrefix[currentOffset];
currentOffset++;
}
partitionLists.add(partition);

//update the limit to the next iteration
limit = Math.min(50, indexNamesWithPrefix.length - currentOffset);
}

Map<String,String> alias=new HashMap<>();
final Map<String,String> alias=new HashMap<>();

//iterates the partition list
for (String[] portionElement : partitionLists ) {
for (final String[] portionElement : partitionLists ) {

GetAliasesRequest request = new GetAliasesRequest();
final GetAliasesRequest request = new GetAliasesRequest();

//set the limited values of the stack
//set the limited values
request.indices(portionElement);

GetAliasesResponse response = Sneaky.sneak(()->
final GetAliasesResponse response = Sneaky.sneak(()->
RestHighLevelClientProvider.getInstance().getClient()
.indices().getAlias(request, RequestOptions.DEFAULT));

Expand Down

0 comments on commit a1fc4c2

Please sign in to comment.