diff --git a/NOTICE b/NOTICE index 4604c32cb35f0b0f29c1123e4b4d6a8c6c3bd412..9eed33c5cd24486d5a990e1e52525d39e3e0b8dd 100644 --- a/NOTICE +++ b/NOTICE @@ -92,7 +92,7 @@ The following software have components provided under the terms of this license: - Byte Buddy (without dependencies) (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy) - Byte Buddy Java agent (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent) - ClassMate (from http://github.com/cowtowncoder/java-classmate) -- Cloud Key Management Service (KMS) API (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms) +- Cloud Key Management Service (KMS) API v1-rev20230407-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms) - Cloud Storage JSON API v1-rev20230301-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage) - Collections (from https://repo1.maven.org/maven2/commons-collections/commons-collections) - Commons Digester (from http://commons.apache.org/digester/) @@ -106,9 +106,9 @@ The following software have components provided under the terms of this license: - GSON extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-gson) - Google APIs Client Library for Java (from https://repo1.maven.org/maven2/com/google/api-client/google-api-client) - Google App Engine extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-appengine) -- Google Cloud Core (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core, https://github.com/googleapis/java-core) -- Google Cloud Core HTTP (from https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http, https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http, https://github.com/googleapis/java-core) -- Google Cloud Core gRPC (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc, https://github.com/googleapis/java-core) +- Google Cloud Core (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core, https://github.com/googleapis/java-core, https://repo1.maven.org/maven2/com/google/cloud/google-cloud-core) +- Google Cloud Core HTTP (from https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http, https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http, https://github.com/googleapis/java-core, https://repo1.maven.org/maven2/com/google/cloud/google-cloud-core-http) +- Google Cloud Core gRPC (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc, https://github.com/googleapis/java-core, https://repo1.maven.org/maven2/com/google/cloud/google-cloud-core-grpc) - Google Cloud Datastore (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-datastore, https://github.com/googleapis/java-datastore) - Google Cloud IAM Service Account Credentials (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/java-iamcredentials) - Google Cloud Logging (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-logging, https://github.com/googleapis/java-logging) @@ -607,7 +607,6 @@ The following software have components provided under the terms of this license: - JUnit Jupiter Params (from http://junit.org/junit5/, https://junit.org/junit5/) - JUnit Platform Commons (from http://junit.org/junit5/, https://junit.org/junit5/) - JUnit Platform Engine API (from http://junit.org/junit5/, https://junit.org/junit5/) -- Jakarta Activation (from https://repo1.maven.org/maven2/com/sun/activation/jakarta.activation) - Jakarta Activation API (from https://github.com/eclipse-ee4j/jaf, https://github.com/jakartaee/jaf-api, https://repo1.maven.org/maven2/jakarta/activation/jakarta.activation-api) - Jakarta Annotations API (from https://projects.eclipse.org/projects/ee4j.ca) - Jakarta Bean Validation API (from https://beanvalidation.org) @@ -741,6 +740,7 @@ GPL-3.0-only ======================================================================== The following software have components provided under the terms of this license: +- Jakarta Activation (from https://repo1.maven.org/maven2/com/sun/activation/jakarta.activation) - Jakarta Annotations API (from https://projects.eclipse.org/projects/ee4j.ca) - Java Architecture for XML Binding (from http://jaxb.java.net/, https://repo1.maven.org/maven2/javax/xml/bind/jaxb-api) - null (from https://github.com/fge/jackson-coreutils) @@ -932,6 +932,13 @@ The following software have components provided under the terms of this license: - RabbitMQ Java Client (from http://www.rabbitmq.com, https://www.rabbitmq.com) +======================================================================== +NCSA +======================================================================== +The following software have components provided under the terms of this license: + +- Spring Context Support (from https://github.com/spring-projects/spring-framework) + ======================================================================== RSA-MD ======================================================================== @@ -1015,6 +1022,5 @@ unknown ======================================================================== The following software have components provided under the terms of this license: -- Jakarta Activation (from https://repo1.maven.org/maven2/com/sun/activation/jakarta.activation) - Jakarta Activation API (from https://github.com/eclipse-ee4j/jaf, https://github.com/jakartaee/jaf-api, https://repo1.maven.org/maven2/jakarta/activation/jakarta.activation-api) - System Rules (from http://stefanbirkner.github.com/system-rules/, http://stefanbirkner.github.io/system-rules/) diff --git a/devops/gc/deploy/templates/deploy-redis.yaml b/devops/gc/deploy/templates/deploy-redis.yaml index 8ef61d75012b4ae2fa7f87b1b06709c978ce1fad..edca13796e69276fc8399bb1478c64205b363d2e 100644 --- a/devops/gc/deploy/templates/deploy-redis.yaml +++ b/devops/gc/deploy/templates/deploy-redis.yaml @@ -14,8 +14,8 @@ spec: labels: app: {{ printf "redis-%s" .Values.conf.appName | quote }} annotations: - sidecar.istio.io/proxyCPU: 10m - sidecar.istio.io/proxyMemory: 100Mi + sidecar.istio.io/proxyCPU: 6m + sidecar.istio.io/proxyMemory: 64Mi spec: containers: - args: @@ -32,6 +32,6 @@ spec: protocol: TCP resources: requests: - cpu: 10m - memory: 100Mi + cpu: 5m + memory: 20Mi {{ end }} diff --git a/devops/gc/deploy/values.yaml b/devops/gc/deploy/values.yaml index 74e6b179ca768aee9d052b18922784a46db05583..a805d3c7d38135902992124abe4d437980e9fab6 100644 --- a/devops/gc/deploy/values.yaml +++ b/devops/gc/deploy/values.yaml @@ -14,8 +14,8 @@ data: securityHttpsCertificateTrust: "true" servicePolicyEnabled: true # Deployments - requestsCpu: "20m" - requestsMemory: "550Mi" + requestsCpu: "15m" + requestsMemory: "400Mi" limitsCpu: "1" limitsMemory: "1G" serviceAccountName: "search" @@ -32,7 +32,7 @@ conf: searchRedisSecretName: "search-redis-secret" istio: - proxyCPU: "10m" + proxyCPU: "5m" proxyCPULimit: "200m" - proxyMemory: "100Mi" + proxyMemory: "50Mi" proxyMemoryLimit: "256Mi" diff --git a/docs/tutorial/SearchService.md b/docs/tutorial/SearchService.md index 7eea7ba2738ae6772c68ac52f6e1ac09eab6ba00..b071c5c9190b9faf0987d77204b591efe8a2b211 100644 --- a/docs/tutorial/SearchService.md +++ b/docs/tutorial/SearchService.md @@ -27,6 +27,7 @@ - [Query With Cursor](#query-with-cursor) - [Get indexing status](#get-indexing-status) - [Version info endpoint](#version-info-endpoint) +- [Known limitations](#known-limitations) ## Introduction <a name="introduction"></a> @@ -1001,4 +1002,8 @@ This endpoint takes information from files generated by `spring-boot-maven-plugi - `version.info.buildPropertiesPath` - `version.info.gitPropertiesPath` +## Known limitations <a name="known-limitations"></a> + +- The maximum content length of the elasticsearch response is 100Mb. If the response length exceeds 100Mb, a 413 status code will be returned without any search results. + [Back to table of contents](#TOC) diff --git a/pom.xml b/pom.xml index 7344b738d2474f7decbde86ae86592cb1038d82e..6627da23b55afceb739599314ebbdda848182d61 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,13 @@ </modules> <dependencyManagement> <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-dependencies</artifactId> + <version>2.7.10</version> + <type>pom</type> + <scope>import</scope> + </dependency> <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>os-core-common</artifactId> @@ -76,7 +83,6 @@ <artifactId>javassist</artifactId> <version>3.24.1-GA</version> </dependency> - <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-jaxrs</artifactId> diff --git a/provider/search-azure/src/main/java/org/opengroup/osdu/search/provider/azure/provider/impl/QueryBase.java b/provider/search-azure/src/main/java/org/opengroup/osdu/search/provider/azure/provider/impl/QueryBase.java index d32a195c4369921f511ab62db1be5ff48fd4af78..10b5b7f91ee27b51fda2c0ecccedc5e2bcd3cf5c 100644 --- a/provider/search-azure/src/main/java/org/opengroup/osdu/search/provider/azure/provider/impl/QueryBase.java +++ b/provider/search-azure/src/main/java/org/opengroup/osdu/search/provider/azure/provider/impl/QueryBase.java @@ -15,6 +15,7 @@ package org.opengroup.osdu.search.provider.azure.provider.impl; import com.google.common.base.Strings; +import org.apache.http.ContentTooLongException; import org.apache.http.HttpStatus; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.search.SearchRequest; @@ -302,6 +303,8 @@ abstract class QueryBase { } catch (IOException e) { if (e.getMessage().startsWith("listener timeout after waiting for")) { throw new AppException(HttpServletResponse.SC_GATEWAY_TIMEOUT, "Search error", String.format("Request timed out after waiting for %sm", REQUEST_TIMEOUT.getMinutes()), e); + } else if (e.getCause() instanceof ContentTooLongException) { + throw new AppException(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, "Response is too long", "Elasticsearch response is too long, max is 100Mb", e); } throw new AppException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e); } catch (Exception e) { diff --git a/provider/search-azure/src/main/java/org/opengroup/osdu/search/provider/azure/provider/impl/ScrollQueryServiceImpl.java b/provider/search-azure/src/main/java/org/opengroup/osdu/search/provider/azure/provider/impl/ScrollQueryServiceImpl.java index a341313984b97a317253181eb21cc7e905ac27ac..b08d94fba75b01ac7d6f2b36d5c3102d1ed9e9ea 100644 --- a/provider/search-azure/src/main/java/org/opengroup/osdu/search/provider/azure/provider/impl/ScrollQueryServiceImpl.java +++ b/provider/search-azure/src/main/java/org/opengroup/osdu/search/provider/azure/provider/impl/ScrollQueryServiceImpl.java @@ -16,6 +16,7 @@ package org.opengroup.osdu.search.provider.azure.provider.impl; import com.google.common.base.Strings; import com.google.common.collect.Lists; +import org.apache.http.ContentTooLongException; import org.apache.http.HttpStatus; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.search.SearchRequest; @@ -113,6 +114,11 @@ public class ScrollQueryServiceImpl extends QueryBase implements IScrollQuerySer && (e.getMessage().startsWith(invalidScrollMessage)) || this.exceptionParser.parseException(e).stream().anyMatch(r -> r.contains(invalidScrollMessage))) throw new AppException(HttpStatus.SC_BAD_REQUEST, "Can't find the given cursor", "The given cursor is invalid or expired", e); throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e); + } catch (IOException e) { + if (e.getCause() instanceof ContentTooLongException) { + throw new AppException(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, "Response is too long", "Elasticsearch response is too long, max is 100Mb", e); + } + throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e); } catch (Exception e) { throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e); } diff --git a/provider/search-azure/src/test/java/org/opengroup/osdu/search/provider/azure/provider.impl/QueryServiceImplTest.java b/provider/search-azure/src/test/java/org/opengroup/osdu/search/provider/azure/provider.impl/QueryServiceImplTest.java index 88d637e1135d1bdf6ee994a877faa58da4f28401..24a9cd9e0aee456b872cc3ceff9c12cd2a2fff56 100644 --- a/provider/search-azure/src/test/java/org/opengroup/osdu/search/provider/azure/provider.impl/QueryServiceImplTest.java +++ b/provider/search-azure/src/test/java/org/opengroup/osdu/search/provider/azure/provider.impl/QueryServiceImplTest.java @@ -17,6 +17,7 @@ package org.opengroup.osdu.search.provider.azure.provider.impl; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Lists; +import org.apache.http.ContentTooLongException; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.search.SearchRequest; @@ -533,6 +534,25 @@ public class QueryServiceImplTest { } } + @Test(expected = AppException.class) + public void testQueryBase_IOException_RespopnseTooLong_throwsException() throws IOException { + IOException exception = mock(IOException.class); + doReturn(new ContentTooLongException(null)).when(exception).getCause(); + doReturn("dummyMessage").when(exception).getMessage(); + + doThrow(exception).when(client).search(any(), any(RequestOptions.class)); + + try { + sut.queryIndex(searchRequest); + } catch (AppException e) { + int errorCode = 413; + String errorMessage = "Elasticsearch response is too long, max is 100Mb"; + + validateAppException(e, errorCode, errorMessage); + throw (e); + } + } + @Test public void should_searchAll_when_requestHas_noQueryString() throws IOException { diff --git a/provider/search-azure/src/test/java/org/opengroup/osdu/search/provider/azure/provider.impl/ScrollQueryServiceImplTest.java b/provider/search-azure/src/test/java/org/opengroup/osdu/search/provider/azure/provider.impl/ScrollQueryServiceImplTest.java index 83f2794c0f449604a1b6763d1dba6be54e18fb22..2bdf099453247161c5e99ced619c7d5dea2f2b1c 100644 --- a/provider/search-azure/src/test/java/org/opengroup/osdu/search/provider/azure/provider.impl/ScrollQueryServiceImplTest.java +++ b/provider/search-azure/src/test/java/org/opengroup/osdu/search/provider/azure/provider.impl/ScrollQueryServiceImplTest.java @@ -15,6 +15,8 @@ package org.opengroup.osdu.search.provider.azure.provider.impl; import com.google.common.collect.Lists; +import java.io.IOException; +import org.apache.http.ContentTooLongException; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchScrollRequest; @@ -324,6 +326,28 @@ public class ScrollQueryServiceImplTest { } } + @Test(expected = AppException.class) + public void testQueryIndex_whenResponseTooLong_thenThrowException() throws Exception { + CursorQueryRequest searchRequest = mock(CursorQueryRequest.class); + doReturn("cursor").when(searchRequest).getCursor(); + doReturn(userId).when(cursorSettings).getUserId(); + + IOException exception = mock(IOException.class); + doReturn(new ContentTooLongException(null)).when(exception).getCause(); + doThrow(exception).when(client).scroll(any(), any(RequestOptions.class)); + + try { + sut.queryIndex(searchRequest); + } catch (AppException e) { + int errorCode = 413; + AppError error = e.getError(); + assertEquals(error.getReason(), "Response is too long"); + assertEquals(error.getMessage(), "Elasticsearch response is too long, max is 100Mb"); + assertEquals(error.getCode(), errorCode); + throw (e); + } + } + private Map<String, HighlightField> getHighlightFields() { Text[] fragments = {new Text(text)}; HighlightField highlightField = new HighlightField(name, fragments); diff --git a/provider/search-gc/pom.xml b/provider/search-gc/pom.xml index 814165204a3a18ad00ff925271d55b5f6a3f46dc..122c34032a639298447b14a2af41c551c1dd0fbd 100644 --- a/provider/search-gc/pom.xml +++ b/provider/search-gc/pom.xml @@ -56,7 +56,7 @@ <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> - <version>5.7.3</version> + <version>5.7.5</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> diff --git a/search-core/src/main/java/org/opengroup/osdu/search/service/IndexAliasServiceImpl.java b/search-core/src/main/java/org/opengroup/osdu/search/service/IndexAliasServiceImpl.java index 92aa93a9a3275266a1e4b8b5bbf6680c677498d6..f1e9d18e50012cec0504be6a6f1855520e34f1d6 100644 --- a/search-core/src/main/java/org/opengroup/osdu/search/service/IndexAliasServiceImpl.java +++ b/search-core/src/main/java/org/opengroup/osdu/search/service/IndexAliasServiceImpl.java @@ -41,6 +41,8 @@ import java.util.stream.Collectors; @Component public class IndexAliasServiceImpl implements IndexAliasService { + private static final String KIND_COMPLETE_VERSION_PATTERN = "[\\w-\\.\\*]+:[\\w-\\.\\*]+:[\\w-\\.\\*]+:(\\d+\\.\\d+\\.\\d+)$"; + @Inject private ElasticClientHandler elasticClientHandler; @Inject @@ -107,8 +109,10 @@ public class IndexAliasServiceImpl implements IndexAliasService { private String createIndexAlias(RestHighLevelClient restClient, String kind) throws IOException { String index = elasticIndexNameResolver.getIndexNameFromKind(kind); String alias = elasticIndexNameResolver.getIndexAliasFromKind(kind); - // To create an alias for an index, the index name must the concrete index name, not alias - index = resolveConcreteIndexName(restClient, index); + if(isCompleteVersionKind(kind)) { + // To create an alias for an index, the index name must the concrete index name, not alias + index = resolveConcreteIndexName(restClient, index); + } if (!Strings.isNullOrEmpty(index)) { IndicesAliasesRequest addRequest = new IndicesAliasesRequest(); IndicesAliasesRequest.AliasActions aliasActions = new IndicesAliasesRequest.AliasActions(IndicesAliasesRequest.AliasActions.Type.ADD) @@ -124,6 +128,10 @@ public class IndexAliasServiceImpl implements IndexAliasService { return null; } + private boolean isCompleteVersionKind(String kind) { + return !Strings.isNullOrEmpty(kind) && kind.matches(KIND_COMPLETE_VERSION_PATTERN); + } + private String resolveConcreteIndexName(RestHighLevelClient restClient, String index) throws IOException { GetAliasesRequest request = new GetAliasesRequest(index); GetAliasesResponse response = restClient.indices().getAlias(request, RequestOptions.DEFAULT); @@ -158,6 +166,6 @@ public class IndexAliasServiceImpl implements IndexAliasService { return actualIndex; } } - return null; + return index; } } diff --git a/search-core/src/test/java/org/opengroup/osdu/search/service/IndexAliasServiceImplTest.java b/search-core/src/test/java/org/opengroup/osdu/search/service/IndexAliasServiceImplTest.java index e87bd48ba7ff4aac77d58844e623e64b96ad1a28..249c3b6c1983ac05e4fe4692f06f82fc6c7f5427 100644 --- a/search-core/src/test/java/org/opengroup/osdu/search/service/IndexAliasServiceImplTest.java +++ b/search-core/src/test/java/org/opengroup/osdu/search/service/IndexAliasServiceImplTest.java @@ -76,7 +76,10 @@ public class IndexAliasServiceImplTest { private static String kind = "common:welldb:wellbore:1.2.0"; private static String index = "common-welldb-wellbore-1.2.0"; - private static String alias = "a1234567890"; + private static String alias = "a-714731401"; + private static String kindWithMajor = "common:welldb:wellbore:1.*.*"; + private static String indexWithMajor = "common-welldb-wellbore-1.*.*"; + private static String aliasForKindWithMajor = "a-714739095"; @Before public void setup() { @@ -87,7 +90,7 @@ public class IndexAliasServiceImplTest { } @Test - public void getInDicesAliases_when_kind_is_not_supported_for_alias() throws IOException { + public void getIndicesAliases_when_kind_is_not_supported_for_alias() throws IOException { when(elasticIndexNameResolver.isIndexAliasSupported(any())).thenReturn(false); List<String> kinds = Arrays.asList(kind); Map<String, String> kindAliasMap = sut.getIndicesAliases(kinds); @@ -95,7 +98,7 @@ public class IndexAliasServiceImplTest { } @Test - public void getInDicesAliases_when_alias_exist() throws IOException { + public void getIndicesAliases_when_alias_exist() throws IOException { setup_when_alias_exist(); List<String> kinds = Arrays.asList(kind); @@ -106,7 +109,7 @@ public class IndexAliasServiceImplTest { } @Test - public void getInDicesAliases_when_alias_exist_with_cache_take_effect() throws IOException { + public void getIndicesAliases_when_alias_exist_with_cache_take_effect() throws IOException { setup_when_alias_exist(); List<String> kinds = Arrays.asList(kind); @@ -134,17 +137,29 @@ public class IndexAliasServiceImplTest { } @Test - public void getInDicesAliases_when_alias_not_exist_and_create_alias_successfully() throws IOException { + public void getIndicesAliases_when_alias_not_exist_and_create_alias_successfully() throws IOException { setup_when_alias_not_exist_and_try_create_alias(true); List<String> kinds = Arrays.asList(kind); Map<String, String> kindAliasMap = sut.getIndicesAliases(kinds); assertTrue(kindAliasMap.containsKey(kind)); assertEquals(alias, kindAliasMap.get(kind)); + verify(this.indicesClient, times(2)).getAlias(any(), any()); } @Test - public void getInDicesAliases_when_alias_not_exist_and_fail_create_alias() throws IOException { + public void getIndicesAliases_for_major_version_when_alias_not_exist_and_create_alias_successfully() throws IOException { + setup__for_major_version_when_alias_not_exist_and_try_create_alias(true); + + List<String> kinds = Arrays.asList(kindWithMajor); + Map<String, String> kindAliasMap = sut.getIndicesAliases(kinds); + assertTrue(kindAliasMap.containsKey(kindWithMajor)); + assertEquals(aliasForKindWithMajor, kindAliasMap.get(kindWithMajor)); + verify(this.indicesClient, times(1)).getAlias(any(), any()); + } + + @Test + public void getIndicesAliases_when_alias_not_exist_and_fail_create_alias() throws IOException { setup_when_alias_not_exist_and_try_create_alias(false); List<String> kinds = Arrays.asList(kind); @@ -193,4 +208,30 @@ public class IndexAliasServiceImplTest { when(getAliasesResponseWithAliasConstraint.status()).thenReturn(RestStatus.NOT_FOUND); when(indicesClient.updateAliases(any(IndicesAliasesRequest.class), any(RequestOptions.class))).thenReturn(updateAliasesResponse); } + + private void setup__for_major_version_when_alias_not_exist_and_try_create_alias(boolean create_ok) throws IOException { + GetAliasesResponse getAliasesResponseWithAliasConstraint = PowerMockito.mock(GetAliasesResponse.class); + Map<String, Set<AliasMetadata>> aliases = new HashMap<>(); + Set<AliasMetadata> aliasMetadataSet = new HashSet<>(); + aliasMetadataSet.add(AliasMetadata.builder("otherAlias").build()); + aliases.put("otherIndex", aliasMetadataSet); + AcknowledgedResponse updateAliasesResponse = new AcknowledgedResponse(create_ok); + when(elasticIndexNameResolver.getIndexNameFromKind(any())).thenReturn(indexWithMajor); + when(elasticIndexNameResolver.getIndexAliasFromKind(any())).thenReturn(aliasForKindWithMajor); + when(elasticIndexNameResolver.isIndexAliasSupported(any())).thenReturn(true); + when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); + when(restHighLevelClient.indices()).thenReturn(indicesClient); + when(indicesClient.getAlias(any(GetAliasesRequest.class), any(RequestOptions.class))) + .thenAnswer(invocation -> + { + GetAliasesRequest request = invocation.getArgument(0); + if (request.aliases().length == 0) + return getAliasesResponse; + else + return getAliasesResponseWithAliasConstraint; + }); + when(getAliasesResponse.status()).thenReturn(RestStatus.OK); + when(getAliasesResponse.getAliases()).thenReturn(aliases); + when(indicesClient.updateAliases(any(IndicesAliasesRequest.class), any(RequestOptions.class))).thenReturn(updateAliasesResponse); + } }