Commit a4741d70 authored by David Diederich's avatar David Diederich
Browse files

Add IBM Integration Tests to the pipeline

Squashed commits from trusted-ibm to avoid clutter in the repository
parent 045b22ae
Pipeline #2353 passed with stages
in 98 minutes and 13 seconds
......@@ -32,3 +32,7 @@ analyze:
type: mvn
target: provider/search-azure/pom.xml
path: .
- name: search-ibm
type: mvn
target: provider/search-ibm/pom.xml
path: .
......@@ -13,6 +13,9 @@ variables:
GCP_DOMAIN: cloud.slb-ds.com
GCP_STORAGE_URL: https://osdu-search-dot-opendes.appspot.com/api/storage/v2/
IBM_BUILD_SUBDIR: provider/search-ibm
IBM_INT_TEST_SUBDIR: testing/integration-tests/search-test-ibm
include:
- project: "osdu/platform/ci-cd-pipelines"
file: "standard-setup.yml"
......@@ -22,17 +25,16 @@ include:
- project: "osdu/platform/ci-cd-pipelines"
file: "scanners/fossa.yml"
- project: "osdu/platform/ci-cd-pipelines"
file: "scanners/gitlab-ultimate.yml"
- project: "osdu/platform/ci-cd-pipelines"
file: "cloud-providers/aws.yml"
- project: "osdu/platform/ci-cd-pipelines"
file: "cloud-providers/aws.yml"
file: "cloud-providers/ibm.yml"
aws-test:
tags: ['aws-internal-test']
tags: ['aws-internal-test']
......@@ -2,11 +2,20 @@
Generated by fossa-cli (https://github.com/fossas/fossa-cli).
This software includes the following software and licenses:
========================================================================
Apache-1.1
========================================================================
The following software have components provided under the terms of this license:
- StAX (from http://stax.codehaus.org/)
========================================================================
Apache-2.0
========================================================================
The following software have components provided under the terms of this license:
- AMQP 1.0 JMS Spring Boot AutoConfiguration (from https://repo1.maven.org/maven2/org/amqphub/spring/amqp-10-jms-spring-boot-autoconfigure)
- AMQP 1.0 JMS Spring Boot Starter (from https://repo1.maven.org/maven2/org/amqphub/spring/amqp-10-jms-spring-boot-starter)
- ASM Core (from )
- ASM based accessors helper used by json-smart (from )
- AWS Java SDK for AWS Amplify (from https://aws.amazon.com/sdkforjava)
......@@ -205,6 +214,7 @@ The following software have components provided under the terms of this license:
- Apache Commons Logging (from http://commons.apache.org/proper/commons-logging/)
- Apache Commons Text (from http://commons.apache.org/proper/commons-text/)
- Apache Commons Validator (from http://commons.apache.org/proper/commons-validator/)
- Apache Geronimo JMS Spec 2.0 (from http://geronimo.apache.org/maven/${siteId}/${version})
- Apache HTTP transport for the Google HTTP Client Library for Java. (from )
- Apache HttpAsyncClient (from http://hc.apache.org/httpcomponents-asyncclient)
- Apache HttpClient (from http://hc.apache.org/httpcomponents-client)
......@@ -226,6 +236,7 @@ The following software have components provided under the terms of this license:
- Commons Digester (from http://commons.apache.org/digester/)
- Commons IO (from http://commons.apache.org/io/)
- Converter: Jackson (from )
- Data Mapper for Jackson (from http://jackson.codehaus.org)
- Elastic JNA Distribution (from https://github.com/java-native-access/jna)
- Elasticsearch: 5.0.0-alpha5 (from https://github.com/elastic/elasticsearch)
- Elasticsearch: 5.0.0-alpha5 (from https://github.com/elastic/elasticsearch)
......@@ -264,6 +275,7 @@ The following software have components provided under the terms of this license:
- JSON.simple (from http://code.google.com/p/json-simple/)
- JSONassert (from https://github.com/skyscreamer/JSONassert)
- Jackson (from http://jackson.codehaus.org)
- Jackson (from http://jackson.codehaus.org)
- Jackson 2 extensions to the Google HTTP Client Library for Java. (from https://github.com/google/google-http-java-client.git/google-http-client-jackson2)
- Jackson CoreUtils (from https://github.com/fge/jackson-coreutils)
- Jackson dataformat: CBOR (from http://github.com/FasterXML/jackson-dataformats-binary)
......@@ -329,6 +341,7 @@ The following software have components provided under the terms of this license:
- Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
- Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
- Netty Reactive Streams Implementation (from )
- Netty/Buffer (from http://netty.io/)
- Netty/Codec (from )
......@@ -350,21 +363,27 @@ The following software have components provided under the terms of this license:
- Non-Blocking Reactive Foundation for the JVM (from https://github.com/reactor/reactor)
- OAuth 2.0 SDK with OpenID Connect extensions (from https://bitbucket.org/connect2id/oauth-2.0-sdk-with-openid-connect-extensions)
- OAuth 2.0 SDK with OpenID Connect extensions (from https://bitbucket.org/connect2id/oauth-2.0-sdk-with-openid-connect-extensions)
- OAuth2 for Spring Security (from )
- Objenesis (from http://objenesis.org)
- OkHttp (from )
- OkHttp (from )
- OkHttp Logging Interceptor (from )
- OkHttp URLConnection (from )
- OkHttp URLConnection (from )
- Okio (from )
- Okio (from )
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- PowerMock (from http://www.powermock.org)
- Protocol Buffer extensions to the Google HTTP Client Library for Java. (from )
- QpidJMS Client (from )
- RESTEasy JAX-RS Implementation (from )
- RESTEasy Jackson 2 Provider (from )
- Reactive Streams Netty driver (from https://github.com/reactor/reactor-netty)
- Resteasy Validator Provider BV 1.1 (from http://maven.apache.org)
- Retrofit (from )
- Simple XML (from http://simple.sourceforge.net)
- SnakeYAML (from http://www.snakeyaml.org)
- Spatial4J (from http://www.locationtech.org/projects/locationtech.spatial4j)
- Spatial4J (from http://www.locationtech.org/projects/locationtech.spatial4j)
......@@ -398,13 +417,18 @@ The following software have components provided under the terms of this license:
- Spring Data KeyValue (from )
- Spring Data Redis (from )
- Spring Expression Language (SpEL) (from https://github.com/spring-projects/spring-framework)
- Spring JMS (from https://github.com/spring-projects/spring-framework)
- Spring Messaging (from https://github.com/spring-projects/spring-framework)
- Spring Object/XML Marshalling (from https://github.com/spring-projects/spring-framework)
- Spring Plugin - Core (from )
- Spring Plugin - Metadata Extension (from )
- Spring Security JWT Library (from http://github.com/spring-projects/spring-security-oauth)
- Spring TestContext Framework (from https://github.com/spring-projects/spring-framework)
- Spring Transaction (from https://github.com/spring-projects/spring-framework)
- Spring Web (from https://github.com/spring-projects/spring-framework)
- Spring Web MVC (from https://github.com/spring-projects/spring-framework)
- StAX (from http://stax.codehaus.org/)
- StAX API (from http://stax.codehaus.org/)
- T-Digest (from https://github.com/tdunning/t-digest)
- Woodstox (from https://github.com/FasterXML/woodstox)
- aggs-matrix-stats (from https://github.com/elastic/elasticsearch)
......@@ -434,6 +458,8 @@ The following software have components provided under the terms of this license:
- io.grpc:grpc-stub (from https://github.com/grpc/grpc-java)
- ion-java (from https://github.com/amznlabs/ion-java/)
- jackson-databind (from http://github.com/FasterXML/jackson)
- java-cloudant (from https://cloudant.com)
- java-cloudant (from https://cloudant.com)
- javatuples (from http://www.javatuples.org)
- javax.inject (from http://code.google.com/p/atinject/)
- javax.ws.rs-api (from http://jax-rs-spec.java.net)
......@@ -457,6 +483,7 @@ The following software have components provided under the terms of this license:
- lettuce (from http://github.com/mp911de/lettuce/wiki)
- micrometer-core (from https://github.com/micrometer-metrics/micrometer)
- micrometer-registry-azure-monitor (from https://github.com/micrometer-metrics/micrometer)
- minio (from https://github.com/minio/minio-java)
- org.xmlunit:xmlunit-core (from http://www.xmlunit.org/)
- parent-join (from https://github.com/elastic/elasticsearch)
- parent-join (from https://github.com/elastic/elasticsearch)
......@@ -470,6 +497,7 @@ The following software have components provided under the terms of this license:
- powermock-reflect (from )
- proto-google-cloud-datastore-v1 (from https://github.com/googleapis/api-client-staging)
- proton-j (from )
- proton-j (from )
- rank-eval (from https://github.com/elastic/elasticsearch)
- rank-eval (from https://github.com/elastic/elasticsearch)
- rest (from https://github.com/elastic/elasticsearch)
......@@ -485,6 +513,7 @@ The following software have components provided under the terms of this license:
- spring-security-oauth2-client (from http://spring.io/spring-security)
- spring-security-oauth2-core (from http://spring.io/spring-security)
- spring-security-oauth2-jose (from http://spring.io/spring-security)
- spring-security-oauth2-resource-server (from http://spring.io/spring-security)
- spring-security-test (from http://spring.io/spring-security)
- spring-security-web (from http://spring.io/spring-security)
- springfox-core (from https://github.com/springfox/springfox)
......@@ -518,6 +547,7 @@ The following software have components provided under the terms of this license:
- Hamcrest Core (from http://hamcrest.org/)
- Lucene Common Analyzers (from )
- Lucene Common Analyzers (from )
- StAX (from http://stax.codehaus.org/)
- jersey-ext-bean-validation (from )
- jersey-spring4 (from )
......@@ -819,6 +849,7 @@ The following software have components provided under the terms of this license:
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
- SpotBugs Annotations (from https://spotbugs.github.io/)
========================================================================
LGPL-2.1-or-later
......@@ -829,6 +860,7 @@ The following software have components provided under the terms of this license:
- Java Native Access Platform (from https://github.com/java-native-access/jna)
- Javassist (from http://www.javassist.org/)
- SnakeYAML (from http://www.snakeyaml.org)
- SpotBugs Annotations (from https://spotbugs.github.io/)
========================================================================
LGPL-3.0-only
......@@ -865,6 +897,7 @@ The following software have components provided under the terms of this license:
- Azure Service Bus Spring Boot Starter (from https://github.com/Microsoft/azure-spring-boot)
- Azure Spring Boot AutoConfigure (from https://github.com/Microsoft/azure-spring-boot)
- Azure Spring Boot Starter (from https://github.com/Microsoft/azure-spring-boot)
- Bouncy Castle Provider (from http://www.bouncycastle.org/java.html)
- Checker Qual (from https://checkerframework.org)
- Elasticsearch: 5.0.0-alpha5 (from https://github.com/elastic/elasticsearch)
- Extensions on Apache Proton-J library (from https://github.com/Azure/qpid-proton-j-extensions)
......@@ -890,6 +923,7 @@ The following software have components provided under the terms of this license:
- Microsoft Azure client library for Identity (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure client library for KeyVault Secrets (from https://github.com/Azure/azure-sdk-for-java)
- Microsoft Azure common module for Storage (from https://github.com/Azure/azure-sdk-for-java)
- Mockito (from http://mockito.org)
- Mockito (from http://www.mockito.org)
- Mockito (from http://www.mockito.org)
- Mockito (from http://mockito.org)
......@@ -951,6 +985,8 @@ The following software have components provided under the terms of this license:
- AWS SDK for Java - Models (from https://aws.amazon.com/sdkforjava)
- Asynchronous Http Client (from )
- Bouncy Castle PKIX, CMS, EAC, TSP, PKCS, OCSP, CMP, and CRMF APIs (from http://www.bouncycastle.org/java.html)
- Bouncy Castle Provider (from http://www.bouncycastle.org/java.html)
- Guava: Google Core Libraries for Java (from https://github.com/google/guava.git)
- HdrHistogram (from http://hdrhistogram.github.io/HdrHistogram/)
- Joda-Time (from http://www.joda.org/joda-time/)
......@@ -961,6 +997,7 @@ The following software have components provided under the terms of this license:
- Microsoft Azure client library for Blob Storage (from https://github.com/Azure/azure-sdk-for-java)
- Project Lombok (from https://projectlombok.org)
- RESTEasy JAX-RS Implementation (from )
- Spring Security JWT Library (from http://github.com/spring-projects/spring-security-oauth)
- Spring Web (from https://github.com/spring-projects/spring-framework)
========================================================================
......@@ -968,6 +1005,8 @@ unknown
========================================================================
The following software have components provided under the terms of this license:
- Bouncy Castle PKIX, CMS, EAC, TSP, PKCS, OCSP, CMP, and CRMF APIs (from http://www.bouncycastle.org/java.html)
- Bouncy Castle Provider (from http://www.bouncycastle.org/java.html)
- Byte Buddy (without dependencies) (from )
- System Rules (from http://stefanbirkner.github.io/system-rules/)
- jersey-container-servlet (from git://java.net/jersey~code/project/jersey-container-servlet)
......
......@@ -23,12 +23,12 @@
<name>search-ibm</name>
<description>Search Service IBM</description>
<packaging>jar</packaging>
<properties>
<osdu.ibmcore.version>0.0.13-SNAPSHOT</osdu.ibmcore.version>
<osdu.ibmcore.version>0.0.14-SNAPSHOT</osdu.ibmcore.version>
<start-class>org.opengroup.osdu.search.provider.ibm.app.SearchIBMApplication</start-class>
</properties>
<dependencies>
......@@ -68,7 +68,6 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
......@@ -86,18 +85,18 @@
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.6.2</version>
</dependency>
<dependency>
<groupId>org.locationtech.spatial4j</groupId>
<artifactId>spatial4j</artifactId>
<version>0.7</version>
</dependency>
<dependency>
<groupId>org.locationtech.jts.io</groupId>
<artifactId>jts-io-common</artifactId>
<version>1.15.0</version>
</dependency>
<groupId>org.locationtech.spatial4j</groupId>
<artifactId>spatial4j</artifactId>
<version>0.7</version>
</dependency>
<dependency>
<groupId>org.locationtech.jts.io</groupId>
<artifactId>jts-io-common</artifactId>
<version>1.15.0</version>
</dependency>
<dependency>
<groupId>pl.allegro.tech</groupId>
<artifactId>embedded-elasticsearch</artifactId>
......@@ -120,19 +119,16 @@
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2 -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
......@@ -140,7 +136,6 @@
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
......@@ -149,8 +144,6 @@
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<!-- <dependency> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version> <scope>test</scope> </dependency> -->
</dependencies>
......@@ -176,7 +169,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<threadCount>1</threadCount>
......@@ -185,5 +177,17 @@
</plugins>
</build>
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<build.profile.id>local</build.profile.id>
<profileActive>local</profileActive>
</properties>
</profile>
</profiles>
</project>
......@@ -13,33 +13,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.search.provider.ibm.provider.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.inject.Inject;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository;
import org.opengroup.osdu.core.common.search.Config;
import org.opengroup.osdu.core.common.model.search.CcsQueryRequest;
import org.opengroup.osdu.core.common.model.search.CcsQueryResponse;
import org.opengroup.osdu.core.common.model.search.QueryRequest;
import org.opengroup.osdu.core.common.model.search.QueryResponse;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.core.common.search.Config;
import org.opengroup.osdu.search.provider.interfaces.ICcsQueryService;
import org.opengroup.osdu.search.provider.interfaces.IQueryService;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.springframework.stereotype.Component;
// TODO: Remove this temporary implementation when ECE CCS is utilized
@Service
@Component
public class CcsQueryServiceImpl implements ICcsQueryService {
@Inject
private DpsHeaders dpsHeaders;
private DpsHeaders requestHeader;
@Inject
private ITenantFactory tenantStorageFactory;
......@@ -51,8 +57,8 @@ public class CcsQueryServiceImpl implements ICcsQueryService {
private IQueryService queryService;
@Override
public CcsQueryResponse makeRequest(final CcsQueryRequest ccsQueryRequest) throws Exception {
List<String> accounts = Arrays.asList(dpsHeaders.getPartitionIdWithFallbackToAccountId().trim().split("\\s*,\\s*"));
public CcsQueryResponse makeRequest(CcsQueryRequest ccsQueryRequest) throws Exception {
List<String> accounts = Arrays.asList(requestHeader.getPartitionIdWithFallbackToAccountId().trim().split("\\s*,\\s*"));
List<QueryResponse> tenantResponses = getTenantResponses(accounts, ccsQueryRequest);
return convertQueryResponseToCcsQueryResponse(getCompoundResponse(tenantResponses));
}
......@@ -60,7 +66,7 @@ public class CcsQueryServiceImpl implements ICcsQueryService {
private List<QueryResponse> getTenantResponses(final List<String> accounts, final CcsQueryRequest ccsQueryRequest) throws Exception {
List<QueryResponse> tenantResponses = new ArrayList<>();
if (Config.isSmartSearchCcsDisabled() || accounts.size() == 1) {
TenantInfo tenant = tenantStorageFactory.getTenantInfo(dpsHeaders.getPartitionIdWithFallbackToAccountId());
TenantInfo tenant = tenantStorageFactory.getTenantInfo(requestHeader.getPartitionIdWithFallbackToAccountId());
tenantResponses.add(queryService.queryIndex(convertCcsQueryRequestToQueryRequest(ccsQueryRequest),
elasticRepository.getElasticClusterSettings(tenant)));
} else {
......
......@@ -16,8 +16,26 @@
package org.opengroup.osdu.search.provider.ibm.provider.impl;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.geoBoundingBoxQuery;
import static org.elasticsearch.index.query.QueryBuilders.geoDistanceQuery;
import static org.elasticsearch.index.query.QueryBuilders.geoPolygonQuery;
import static org.elasticsearch.index.query.QueryBuilders.geoWithinQuery;
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.search.SearchRequest;
......@@ -45,18 +63,19 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.entitlements.AclRole;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.search.*;
import org.opengroup.osdu.core.common.model.search.AggregationResponse;
import org.opengroup.osdu.core.common.model.search.Point;
import org.opengroup.osdu.core.common.model.search.Query;
import org.opengroup.osdu.core.common.model.search.QueryUtils;
import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute;
import org.opengroup.osdu.core.common.model.search.SpatialFilter;
import org.opengroup.osdu.search.provider.ibm.service.FieldMappingTypeService;
import org.opengroup.osdu.search.provider.interfaces.IProviderHeaderService;
import org.opengroup.osdu.search.util.CrossTenantUtils;
import org.springframework.security.access.AccessDeniedException;
import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import static org.elasticsearch.index.query.QueryBuilders.*;
// TODO This class is a duplicate of byoc and gcp, should likely be moved to the core folder
abstract class QueryBase {
@Inject
......@@ -87,10 +106,10 @@ abstract class QueryBase {
QueryBuilder textQueryBuilder = null;
QueryBuilder spatialQueryBuilder = null;
QueryBuilder authorizationQueryBuilder;
QueryBuilder authorizationQueryBuilder = null;
QueryBuilder queryBuilder = null;
if (!Strings.isNullOrEmpty(simpleQuery)) {
if (StringUtils.isNotEmpty(simpleQuery)) {
textQueryBuilder = getSimpleQuery(simpleQuery);
}
......@@ -272,8 +291,8 @@ abstract class QueryBase {
includesArr = returnedFieldsSet.toArray(new String[returnedFieldsSet.size()]);
// remove all matching returnedField and queryable from excludes
Set<String> shouldNotExclude = Sets.intersection(returnedFieldsSet, queryableExcludes);
Set<String> shouldExclude = Sets.difference(queryableExcludes, shouldNotExclude);
Set<String> shouldNotExclude = returnedFieldsSet.stream().filter(queryableExcludes::contains).collect(Collectors.toSet());
Set<String> shouldExclude = queryableExcludes.stream().filter(n -> !shouldNotExclude.contains(n)).collect(Collectors.toSet());
excludes.addAll(shouldExclude);
excludesArr = excludes.toArray(new String[excludes.size()]);
......@@ -284,7 +303,7 @@ abstract class QueryBase {
SearchResponse makeSearchRequest(Query searchRequest, RestHighLevelClient client) {
Long startTime = 0L;
SearchRequest elasticSearchRequest = null;
try {
if (searchRequest.getSpatialFilter() != null) {
useGeoShapeQuery = this.useGeoShapeQuery(client, searchRequest, this.getIndex(searchRequest));
......@@ -324,6 +343,14 @@ abstract class QueryBase {
// fallback to geo_point search if mixed type found for spatialFilter.field
if (indexedTypes.isEmpty() || indexedTypes.size() > 1) return false;
return indexedTypes.contains(GEO_SHAPE_INDEXED_TYPE);
}
// validate tenant from kind with the partition id header
public void validateTenant(Query searchRequest) {
if (!this.getIndex(searchRequest).startsWith(this.dpsHeaders.getPartitionId())) {
throw new AccessDeniedException("query kind tenant is not that same at the data-partition-id header");
}
}
abstract SearchRequest createElasticRequest(Query request) throws AppException, IOException;
......
......@@ -15,12 +15,16 @@
*/
package org.opengroup.osdu.search.provider.ibm.provider.impl;
import static org.opengroup.osdu.core.common.search.Config.isPreDemo;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RestHighLevelClient;
......@@ -37,12 +41,8 @@ import org.opengroup.osdu.core.common.search.Config;
import org.opengroup.osdu.search.logging.AuditLogger;
import org.opengroup.osdu.search.provider.interfaces.IQueryService;
import org.opengroup.osdu.search.util.ElasticClientHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
@Service
public class QueryServiceImpl extends QueryBase implements IQueryService {
......@@ -51,14 +51,15 @@ public class QueryServiceImpl extends QueryBase implements IQueryService {
private ElasticClientHandler elasticClientHandler;
@Inject
private AuditLogger auditLogger;
@Value("${ENVIRONMENT}")
private String ENVIRONMENT;
@Override
public QueryResponse queryIndex(QueryRequest searchRequest) throws IOException {
validateTenant(searchRequest);
try (RestHighLevelClient client = this.elasticClientHandler.createRestClient()) {
QueryResponse queryResponse = this.executeQuery(searchRequest, client);
this.auditLogger.queryIndex(Lists.newArrayList(searchRequest.toString()));
List<String> resources = new ArrayList<>();
resources.add(searchRequest.toString());
this.auditLogger.queryIndex(resources);
return queryResponse;
}
}
......@@ -68,7 +69,9 @@ public class QueryServiceImpl extends QueryBase implements IQueryService {
public QueryResponse queryIndex(QueryRequest searchRequest, ClusterSettings clusterSettings) throws Exception {
try (RestHighLevelClient client = elasticClientHandler.createRestClient(clusterSettings)) {
QueryResponse queryResponse = executeQuery(searchRequest, client);
auditLogger.queryIndex(Lists.newArrayList(searchRequest.toString()));
List<String> resources = new ArrayList<>();
resources.add(searchRequest.toString());
auditLogger.queryIndex(resources);
return queryResponse;
}
}
......@@ -89,15 +92,14 @@ public class QueryServiceImpl extends QueryBase implements IQueryService {
SearchRequest createElasticRequest(Query request) throws AppException, IOException {
QueryRequest searchRequest = (QueryRequest) request;
// set the indexes to search against
// set the indexes to org.opengroup.osdu.search.search against
SearchRequest elasticSearchRequest = new SearchRequest(this.getIndex(request));
// build query
SearchSourceBuilder sourceBuilder = this.createSearchSourceBuilder(request);
sourceBuilder.from(searchRequest.getFrom());
// aggregation: only make it available in pre demo for now
if (isEnvironmentPreDemo() && !Strings.isNullOrEmpty(searchRequest.getAggregateBy())) {
if (StringUtils.isNotEmpty(searchRequest.getAggregateBy())) {
TermsAggregationBuilder termsAggregationBuilder = new TermsAggregationBuilder(AGGREGATION_NAME, ValueType.STRING);
termsAggregationBuilder.field(searchRequest.getAggregateBy());
termsAggregationBuilder.size(Config.getAggregationSize());
......@@ -108,16 +110,4 @@ public class QueryServiceImpl extends QueryBase implements IQueryService {
return elasticSearchRequest;
}
private boolean isEnvironmentLocal() {