diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fd2f9b7c07fa09cc2624f1a47b56dcc43dfff7f8..0cb0a11b71331dab32e922335828866777d61fa9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,7 +22,7 @@ variables: OSDU_SECURITY_HTTPS_CERTIFICATE_TRUST: 'true' OSDU_GCP_STORAGE_RECORDS_BATCH_SIZE: 20 OSDU_GCP_DATA_GROUP: osdu - OSDU_GCP_ENV_VARS: AUTHORIZE_API=$OSDU_GCP_ENTITLEMENTS_URL,GOOGLE_CLOUD_PROJECT=$OSDU_GCP_PROJECT,REDIS_SEARCH_HOST=$REDIS_SEARCH_HOST,REDIS_GROUP_HOST=$REDIS_GROUP_HOST,SECURITY_HTTPS_CERTIFICATE_TRUST=$OSDU_SECURITY_HTTPS_CERTIFICATE_TRUST,INDEXER_HOST=$OSDU_GCP_INDEXER_HOST,STORAGE_QUERY_RECORD_HOST=$OSDU_GCP_STORAGE_QUERY_RECORD_HOST,STORAGE_SCHEMA_HOST=$OSDU_GCP_STORAGE_SCHEMA_HOST,STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=$OSDU_GCP_STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST,STORAGE_HOSTNAME=$OSDU_GCP_STORAGE_HOSTNAME,STORAGE_RECORDS_BATCH_SIZE=$OSDU_GCP_STORAGE_RECORDS_BATCH_SIZE,INDEXER_QUEUE_HOST=$OSDU_GCP_INDEXER_QUEUE_HOST,LEGALTAG_API=$OSDU_GCP_LEGALTAG_API,CRS_API=$OSDU_GCP_CRS_API,DATA_GROUP=$OSDU_GCP_DATA_GROUP,GOOGLE_AUDIENCES=$GOOGLE_AUDIENCE,PARTITION_API=$OSDU_GCP_PARTITION_API,INDEXER_QUE_SERVICE_MAIL=$OSDU_GCP_QUEUE_SA_EMAIL,SCHEMA_HOST=$OSDU_GCP_SCHEMA_URL/api/schema-service/v1/schema --vpc-connector=$OSDU_GCP_VPC_CONNECTOR + OSDU_GCP_ENV_VARS: AUTHORIZE_API=$OSDU_GCP_ENTITLEMENTS_V2_URL,GOOGLE_CLOUD_PROJECT=$OSDU_GCP_PROJECT,REDIS_SEARCH_HOST=$REDIS_SEARCH_HOST,REDIS_GROUP_HOST=$REDIS_GROUP_HOST,SECURITY_HTTPS_CERTIFICATE_TRUST=$OSDU_SECURITY_HTTPS_CERTIFICATE_TRUST,INDEXER_HOST=$OSDU_GCP_INDEXER_HOST,STORAGE_QUERY_RECORD_HOST=$OSDU_GCP_STORAGE_QUERY_RECORD_HOST,STORAGE_SCHEMA_HOST=$OSDU_GCP_STORAGE_SCHEMA_HOST,STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=$OSDU_GCP_STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST,STORAGE_HOSTNAME=$OSDU_GCP_STORAGE_HOSTNAME,STORAGE_RECORDS_BATCH_SIZE=$OSDU_GCP_STORAGE_RECORDS_BATCH_SIZE,INDEXER_QUEUE_HOST=$OSDU_GCP_INDEXER_QUEUE_HOST,LEGALTAG_API=$OSDU_GCP_LEGALTAG_API,CRS_API=$OSDU_GCP_CRS_API,DATA_GROUP=$OSDU_GCP_DATA_GROUP,GOOGLE_AUDIENCES=$GOOGLE_AUDIENCE,PARTITION_API=$OSDU_GCP_PARTITION_API,INDEXER_QUE_SERVICE_MAIL=$OSDU_GCP_QUEUE_SA_EMAIL,SCHEMA_HOST=$OSDU_GCP_SCHEMA_URL/api/schema-service/v1/schema --vpc-connector=$OSDU_GCP_VPC_CONNECTOR OSDU_GCP_TEST_SUBDIR: testing/$OSDU_GCP_SERVICE-test-$OSDU_GCP_VENDOR OSDU_GCP_HELM_PACKAGE_CHARTS: "devops/gcp/deploy devops/gcp/configmap" diff --git a/NOTICE b/NOTICE index 47902ddc92d244edd1a34e2e7cb0a5bf1acdd03e..03f7b6cf1121588f097aea3f81a883716588ff3e 100644 --- a/NOTICE +++ b/NOTICE @@ -180,6 +180,7 @@ The following software have components provided under the terms of this license: - Apache Ant Core (from http://ant.apache.org/) - Apache Ant Launcher (from http://ant.apache.org/) - Apache Commons BeanUtils (from http://commons.apache.org/proper/commons-beanutils/) +- Apache Commons CLI (from http://commons.apache.org/proper/commons-cli/) - Apache Commons Codec (from http://commons.apache.org/proper/commons-codec/) - Apache Commons Collections (from http://commons.apache.org/proper/commons-collections/) - Apache Commons Lang (from http://commons.apache.org/proper/commons-lang/) @@ -241,6 +242,7 @@ The following software have components provided under the terms of this license: - 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) +- Expression Language 3.0 (from http://uel.java.net) - FindBugs-jsr305 (from http://findbugs.sourceforge.net/) - GSON extensions to the Google HTTP Client Library for Java. (from ) - Google APIs Client Library for Java (from ) @@ -319,6 +321,7 @@ The following software have components provided under the terms of this license: - Java Libraries for Amazon Simple WorkFlow (from https://aws.amazon.com/sdkforjava) - Java Native Access (from https://github.com/java-native-access/jna) - Java Native Access Platform (from https://github.com/java-native-access/jna) +- Java Servlet API (from http://servlet-spec.java.net) - Java UUID Generator (from http://wiki.fasterxml.com/JugHome) - Javassist (from http://www.javassist.org/) - Javassist (from http://www.javassist.org/) @@ -650,6 +653,7 @@ BSD-2-Clause The following software have components provided under the terms of this license: - API Common (from https://github.com/googleapis) +- Apache Commons CLI (from http://commons.apache.org/proper/commons-cli/) - GAX (Google Api eXtensions) (from https://github.com/googleapis) - GAX (Google Api eXtensions) (from https://github.com/googleapis) - GAX (Google Api eXtensions) (from https://github.com/googleapis) @@ -659,6 +663,7 @@ The following software have components provided under the terms of this license: - Lucene Common Analyzers (from ) - Lucene Common Analyzers (from ) - Lucene Core (from ) +- Lucene Core (from ) - Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils) - Reflections (from http://github.com/ronmamo/reflections) - Stax2 API (from http://github.com/FasterXML/stax2-api) @@ -681,6 +686,7 @@ The following software have components provided under the terms of this license: - ASM Tree (from ) - ASM Util (from ) - ASM library repackaged as OSGi bundle (from ) +- Apache Commons Codec (from http://commons.apache.org/proper/commons-codec/) - GAX (Google Api eXtensions) (from https://github.com/googleapis) - GAX (Google Api eXtensions) (from https://github.com/googleapis) - GAX (Google Api eXtensions) (from https://github.com/googleapis) @@ -713,9 +719,12 @@ The following software have components provided under the terms of this license: - Protocol Buffer Java API (from https://developers.google.com/protocol-buffers/) - Protocol Buffers [Util] (from ) - Protocol Buffers [Util] (from ) +- Reflections (from http://github.com/ronmamo/reflections) +- SnakeYAML (from http://www.snakeyaml.org) - Spring Core (from https://github.com/spring-projects/spring-framework) - ThreeTen backport (from https://www.threeten.org/threetenbp) - ThreeTen backport (from https://www.threeten.org/threetenbp) +- classworlds (from http://classworlds.codehaus.org/) - jakarta.xml.bind-api (from ) - jaxen (from http://jaxen.codehaus.org/) - jersey-container-servlet (from git://java.net/jersey~code/project/jersey-container-servlet) @@ -749,13 +758,6 @@ CC0-1.0 ======================================================================== The following software have components provided under the terms of this license: -- Guava: Google Core Libraries for Java (from https://github.com/google/guava.git) -- Guava: Google Core Libraries for Java (from https://github.com/google/guava.git) -- HdrHistogram (from http://hdrhistogram.github.io/HdrHistogram/) -- LatencyUtils (from http://latencyutils.github.io/LatencyUtils/) -- MongoDB Java Driver Core (from http://www.mongodb.org) -- Netty/Common (from ) -- Netty/Common (from ) - reactive-streams (from http://www.reactive-streams.org/) ======================================================================== @@ -764,9 +766,7 @@ CDDL-1.0 The following software have components provided under the terms of this license: - ASM library repackaged as OSGi bundle (from ) -- Apache Log4j Core (from ) - Class Model for Hk2 (from ) -- HK2 API module (from git://java.net/hk2~git/hk2-api) - HK2 Implementation Utilities (from ) - HK2 Spring Bridge (from ) - HK2 config types (from ) @@ -774,7 +774,6 @@ The following software have components provided under the terms of this license: - HK2 core module (from ) - HK2 module of HK2 itself (from ) - JavaBeans Activation Framework API jar (from ) -- JavaBeans(TM) Activation Framework (from http://java.sun.com/javase/technologies/desktop/javabeans/jaf/index.jsp) - Run Level Service (from ) - ServiceLocator Default Implementation (from git://java.net/hk2~git/hk2-locator) - Servlet Specification 2.5 API (from ) @@ -795,9 +794,15 @@ CDDL-1.1 ======================================================================== The following software have components provided under the terms of this license: +- Expression Language 3.0 (from http://uel.java.net) - Java Architecture For XML Binding (from ) +- Java Servlet API (from http://servlet-spec.java.net) - JavaBeans Activation Framework (from ) - JavaBeans(TM) Activation Framework (from http://java.sun.com/javase/technologies/desktop/javabeans/jaf/index.jsp) +- JavaMail API (from ) +- OSGi resource locator (from ) +- Servlet Specification 2.5 API (from ) +- javax.annotation-api (from http://jcp.org/en/jsr/detail?id=250) - jersey-ext-bean-validation (from ) - jersey-spring4 (from ) - tomcat-embed-core (from http://tomcat.apache.org/) @@ -816,20 +821,24 @@ DOC The following software have components provided under the terms of this license: - JDOM (from http://www.jdom.org) -- Xerces2-j (from https://xerces.apache.org/xerces2-j/) -- aalto-xml (from ) +- Lucene Core (from ) +- Lucene Core (from ) +- Woodstox (from https://github.com/FasterXML/woodstox) ======================================================================== EPL-1.0 ======================================================================== The following software have components provided under the terms of this license: +- Logback Classic Module (from ) - Logback Contrib :: JSON :: Classic (from ) - Logback Contrib :: JSON :: Core (from ) - Logback Contrib :: Jackson (from ) +- Logback Core Module (from ) - 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) +- SnakeYAML (from http://www.snakeyaml.org) - jts-core (from ) - jts-io-common (from ) @@ -842,17 +851,19 @@ The following software have components provided under the terms of this license: - Class Model for Hk2 (from ) - Cobertura Limited Runtime (from http://cobertura.sourceforge.net) - Cobertura code coverage (from http://cobertura.sourceforge.net) +- Commons Lang (from http://commons.apache.org/lang/) - Expression Language 3.0 (from http://uel.java.net) -- HK2 API module (from git://java.net/hk2~git/hk2-api) - HK2 Implementation Utilities (from ) - HK2 Spring Bridge (from ) - HK2 config types (from ) - HK2 configuration module (from ) - HK2 core module (from ) - HK2 module of HK2 itself (from ) +- Java Architecture For XML Binding (from ) - Java Servlet API (from http://servlet-spec.java.net) - JavaBeans Activation Framework (from ) - Mojo's Maven plugin for Cobertura (from http://mojo.codehaus.org/cobertura-maven-plugin/) +- OSGi resource locator (from ) - RabbitMQ Java Client (from http://www.rabbitmq.com) - Run Level Service (from ) - ServiceLocator Default Implementation (from git://java.net/hk2~git/hk2-locator) @@ -872,6 +883,13 @@ The following software have components provided under the terms of this license: - jersey-spring4 (from ) - tomcat-embed-core (from http://tomcat.apache.org/) +======================================================================== +GPL-2.0-or-later +======================================================================== +The following software have components provided under the terms of this license: + +- SnakeYAML (from http://www.snakeyaml.org) + ======================================================================== GPL-2.0-with-classpath-exception ======================================================================== @@ -879,11 +897,16 @@ The following software have components provided under the terms of this license: - Checker Qual (from https://checkerframework.org) - Cobertura code coverage (from http://cobertura.sourceforge.net) +- Expression Language 3.0 (from http://uel.java.net) - HK2 Implementation Utilities (from ) - Java Architecture For XML Binding (from ) +- Java Servlet API (from http://servlet-spec.java.net) - JavaBeans Activation Framework (from ) +- OSGi resource locator (from ) +- RabbitMQ Java Client (from http://www.rabbitmq.com) - ServiceLocator Default Implementation (from git://java.net/hk2~git/hk2-locator) - aopalliance-repackaged (from ) +- javax.annotation-api (from http://jcp.org/en/jsr/detail?id=250) - javax.ws.rs-api (from http://jax-rs-spec.java.net) - jersey-container-servlet (from git://java.net/jersey~code/project/jersey-container-servlet) - jersey-container-servlet-core (from git://java.net/jersey~code/project/jersey-container-servlet-core) @@ -903,25 +926,16 @@ GPL-3.0-only ======================================================================== The following software have components provided under the terms of this license: +- Project Lombok (from https://projectlombok.org) - javax.ws.rs-api (from http://jax-rs-spec.java.net) -======================================================================== -ISC -======================================================================== -The following software have components provided under the terms of this license: - -- Java Native Access Platform (from https://github.com/java-native-access/jna) - ======================================================================== ImageMagick ======================================================================== The following software have components provided under the terms of this license: -- Data Mapper for Jackson (from http://jackson.codehaus.org) -- Jackson (from http://jackson.codehaus.org) -- Jackson (from http://jackson.codehaus.org) - Stax2 API (from http://github.com/FasterXML/stax2-api) -- aalto-xml (from ) +- Woodstox (from https://github.com/FasterXML/woodstox) ======================================================================== Info-ZIP @@ -943,19 +957,40 @@ LGPL-2.1-only The following software have components provided under the terms of this license: - Cobertura code coverage (from http://cobertura.sourceforge.net) +- Commons Lang (from http://commons.apache.org/lang/) - Elastic JNA Distribution (from https://github.com/java-native-access/jna) - Elastic JNA Distribution (from https://github.com/java-native-access/jna) - Java Native Access (from https://github.com/java-native-access/jna) - Java Native Access Platform (from https://github.com/java-native-access/jna) - Javassist (from http://www.javassist.org/) - Javassist (from http://www.javassist.org/) +- Logback Classic Module (from ) - Logback Contrib :: JSON :: Classic (from ) - Logback Contrib :: JSON :: Core (from ) - Logback Contrib :: Jackson (from ) +- Logback Core Module (from ) - 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) +======================================================================== +LGPL-2.1-or-later +======================================================================== +The following software have components provided under the terms of this license: + +- Javassist (from http://www.javassist.org/) +- Javassist (from http://www.javassist.org/) +- SnakeYAML (from http://www.snakeyaml.org) + +======================================================================== +LGPL-3.0-only +======================================================================== +The following software have components provided under the terms of this license: + +- Apache Log4j API (from ) +- Apache Log4j Core (from ) +- RabbitMQ Java Client (from http://www.rabbitmq.com) + ======================================================================== MIT ======================================================================== @@ -964,7 +999,6 @@ The following software have components provided under the terms of this license: - AWS Java SDK for AWS Lambda (from https://aws.amazon.com/sdkforjava) - Animal Sniffer Annotations (from ) - Animal Sniffer Annotations (from ) -- Apache Log4j SLF4J Binding (from ) - Azure Java Client Authentication Library for AutoRest (from https://github.com/Azure/autorest-clientruntime-for-java) - Azure Java Client Runtime for ARM (from https://github.com/Azure/autorest-clientruntime-for-java) - Azure Java Client Runtime for AutoRest (from https://github.com/Azure/autorest-clientruntime-for-java) @@ -977,7 +1011,6 @@ The following software have components provided under the terms of this license: - 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) - JOpt Simple (from http://pholser.github.io/jopt-simple) -- JTidy (from http://jtidy.sourceforge.net) - JUL to SLF4J bridge (from http://www.slf4j.org) - Java Client Runtime for AutoRest (from https://github.com/Azure/autorest-clientruntime-for-java) - Java JWT (from http://www.jwt.io) @@ -1001,10 +1034,10 @@ The following software have components provided under the terms of this license: - 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) - Microsoft Azure internal Avro module for Storage (from https://github.com/Azure/azure-sdk-for-java) -- Mockito (from http://www.mockito.org) - Mockito (from http://mockito.org) - Mockito (from http://mockito.org) - Mockito (from http://mockito.org) +- Mockito (from http://www.mockito.org) - Netty/Codec/HTTP (from ) - Netty/Codec/HTTP (from ) - Netty/Common (from ) @@ -1029,6 +1062,9 @@ MPL-1.1 The following software have components provided under the terms of this license: - Cobertura code coverage (from http://cobertura.sourceforge.net) +- Javassist (from http://www.javassist.org/) +- Javassist (from http://www.javassist.org/) +- RabbitMQ Java Client (from http://www.rabbitmq.com) ======================================================================== MPL-2.0 @@ -1037,6 +1073,7 @@ The following software have components provided under the terms of this license: - Javassist (from http://www.javassist.org/) - Javassist (from http://www.javassist.org/) +- OkHttp (from ) - RabbitMQ Java Client (from http://www.rabbitmq.com) ======================================================================== @@ -1047,18 +1084,12 @@ The following software have components provided under the terms of this license: - Microsoft Application Insights Java SDK Core (from https://github.com/Microsoft/ApplicationInsights-Java) ======================================================================== -NCSA -======================================================================== -The following software have components provided under the terms of this license: - -- Jetty Server (from ) - -======================================================================== -Plexus +PHP-3.01 ======================================================================== The following software have components provided under the terms of this license: -- classworlds (from http://classworlds.codehaus.org/) +- JavaBeans Activation Framework API jar (from ) +- jakarta.xml.bind-api (from ) ======================================================================== Public-Domain @@ -1076,28 +1107,41 @@ SAX-PD ======================================================================== The following software have components provided under the terms of this license: -- Apache Ant + JUnit (from http://ant.apache.org/) - Apache Ant Core (from http://ant.apache.org/) -- Apache Ant Launcher (from http://ant.apache.org/) -- xml-apis (from ) ======================================================================== -W3C +SPL-1.0 ======================================================================== The following software have components provided under the terms of this license: -- Apache Ant + JUnit (from http://ant.apache.org/) -- Apache Ant Core (from http://ant.apache.org/) -- Apache Ant Launcher (from http://ant.apache.org/) -- xml-apis (from ) +- Checker Qual (from https://checkerframework.org) +- Checker Qual (from https://checkerframework.org) +- Servlet Specification 2.5 API (from ) ======================================================================== -W3C-19980720 +SunPro ======================================================================== The following software have components provided under the terms of this license: +- Lucene Core (from ) +- Lucene Core (from ) + +======================================================================== +TCL +======================================================================== +The following software have components provided under the terms of this license: + +- HK2 API module (from git://java.net/hk2~git/hk2-api) + +======================================================================== +W3C +======================================================================== +The following software have components provided under the terms of this license: + +- Apache Ant Core (from http://ant.apache.org/) - JTidy (from http://jtidy.sourceforge.net) - Xerces2-j (from https://xerces.apache.org/xerces2-j/) +- jaxen (from http://jaxen.codehaus.org/) - xml-apis (from ) ======================================================================== @@ -1112,9 +1156,8 @@ X11 ======================================================================== The following software have components provided under the terms of this license: -- Guava: Google Core Libraries for Java (from https://github.com/google/guava.git) -- Guava: Google Core Libraries for Java (from https://github.com/google/guava.git) -- MongoDB Java Driver Core (from http://www.mongodb.org) +- Lucene Core (from ) +- Lucene Core (from ) ======================================================================== public-domain @@ -1124,18 +1167,29 @@ The following software have components provided under the terms of this license: - AWS Java SDK :: SDK Core (from https://aws.amazon.com/sdkforjava) - 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 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) +- Bouncy Castle Provider (from http://www.bouncycastle.org/java.html) +- Guava: Google Core Libraries for Java (from https://github.com/google/guava.git) +- Guava: Google Core Libraries for Java (from https://github.com/google/guava.git) - HdrHistogram (from http://hdrhistogram.github.io/HdrHistogram/) +- JTidy (from http://jtidy.sourceforge.net) - Joda-Time (from http://www.joda.org/joda-time/) - LatencyUtils (from http://latencyutils.github.io/LatencyUtils/) - Microsoft Application Insights Java SDK Core (from https://github.com/Microsoft/ApplicationInsights-Java) - Microsoft Azure SDK for EventGrid Management (from https://github.com/Azure/azure-sdk-for-java) - Microsoft Azure SDK for SQL API of Azure Cosmos DB Service (from https://github.com/Azure/azure-sdk-for-java) - Microsoft Azure client library for Blob Storage (from https://github.com/Azure/azure-sdk-for-java) +- Project Lombok (from https://projectlombok.org) +- RabbitMQ Java Client (from http://www.rabbitmq.com) - Spring Security JWT Library (from http://github.com/spring-projects/spring-security-oauth) - Spring Security JWT Library (from http://github.com/spring-projects/spring-security-oauth) - Spring Web (from https://github.com/spring-projects/spring-framework) - azure-documentdb (from https://azure.microsoft.com/en-us/services/cosmos-db/) - msal4j (from https://github.com/AzureAD/microsoft-authentication-library-for-java) +- reactive-streams (from http://www.reactive-streams.org/) +- xml-apis (from ) ======================================================================== unknown @@ -1147,11 +1201,14 @@ The following software have components provided under the terms of this license: - Bouncy Castle Provider (from http://www.bouncycastle.org/java.html) - Bouncy Castle Provider (from http://www.bouncycastle.org/java.html) - Byte Buddy (without dependencies) (from ) +- Checker Qual (from https://checkerframework.org) - JSON in Java (from https://github.com/douglascrockford/JSON-java) - JTidy (from http://jtidy.sourceforge.net) - JUnit (from http://junit.org) +- JavaBeans Activation Framework API jar (from ) - Spongy Castle (from http://rtyley.github.io/spongycastle/) - System Rules (from http://stefanbirkner.github.io/system-rules/) +- jakarta.xml.bind-api (from ) - jaxen (from http://jaxen.codehaus.org/) - jersey-container-servlet (from git://java.net/jersey~code/project/jersey-container-servlet) - jersey-container-servlet-core (from git://java.net/jersey~code/project/jersey-container-servlet-core) diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaService.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaService.java index 7e512ae7af32a70650372cfd2a2e48bed6093e27..9691ada93cdfc8b90c6650b99e8782768afcaad2 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaService.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaService.java @@ -20,15 +20,20 @@ import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.indexer.OperationType; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.util.List; import java.util.Map; public interface IndexSchemaService { - IndexSchema getIndexerInputSchema(String kind, boolean invalidateCached) throws AppException; + IndexSchema getIndexerInputSchema(String kind, List<String> errors) throws AppException, UnsupportedEncodingException, URISyntaxException; + + IndexSchema getIndexerInputSchema(String kind, boolean invalidateCached) throws AppException, UnsupportedEncodingException, URISyntaxException; void processSchemaMessages(Map<String, OperationType> schemaMsgs) throws IOException; - void syncIndexMappingWithStorageSchema(String kind) throws ElasticsearchException, IOException, AppException; + void syncIndexMappingWithStorageSchema(String kind) throws ElasticsearchException, IOException, AppException, URISyntaxException; boolean isStorageSchemaSyncRequired(String kind, boolean forceClean) throws IOException; } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java index fb0469356a95978325aa45d9f44b3dd186b308fa..a979c0868f074adc77c7bcaec6d51ed2ab1eac86 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java @@ -16,12 +16,6 @@ package org.opengroup.osdu.indexer.service; import com.google.common.base.Strings; import com.google.gson.Gson; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; -import javax.inject.Inject; import org.apache.http.HttpStatus; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchStatusException; @@ -38,18 +32,23 @@ import org.opengroup.osdu.core.common.model.storage.SchemaItem; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.core.common.search.IndicesService; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; +import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.opengroup.osdu.indexer.util.TypeMapper; import org.springframework.stereotype.Service; +import javax.inject.Inject; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + @Service public class IndexSchemaServiceImpl implements IndexSchemaService { private static final String FLATTENED_SCHEMA = "_flattened"; - private static final String WELLBORE_MARKER_SET = "WellboreMarkerSet"; - private static final String MARKERS = "Markers"; - private static final String WELL_LOG = "WellLog"; - private static final String CURVES = "Curves"; private final Gson gson = new Gson(); @@ -73,14 +72,14 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { schemaMsgs.entrySet().forEach(msg -> { try { processSchemaEvents(restClient, msg); - } catch (IOException | ElasticsearchStatusException e) { + } catch (IOException | ElasticsearchStatusException | URISyntaxException e) { throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "unable to process schema update", e.getMessage()); } }); } } - private void processSchemaEvents(RestHighLevelClient restClient, Map.Entry<String, OperationType> msg) throws IOException, ElasticsearchStatusException { + private void processSchemaEvents(RestHighLevelClient restClient, Map.Entry<String, OperationType> msg) throws IOException, ElasticsearchStatusException, URISyntaxException { String kind = msg.getKey(); String index = this.elasticIndexNameResolver.getIndexNameFromKind(kind); @@ -123,51 +122,59 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { } @Override - public IndexSchema getIndexerInputSchema(String kind, boolean invalidateCached) throws AppException { + public IndexSchema getIndexerInputSchema(String kind, List<String> errors) throws AppException, UnsupportedEncodingException, URISyntaxException { + try { + return getIndexerInputSchema(kind, false); + } catch (SchemaProcessingException ex) { + log.error(ex.getMessage(), ex); + errors.add(ex.getMessage()); + } catch (RuntimeException ex) { + String msg = String.format("Failed to get the schema from the Schema service, kind: %s | message: %s", kind, ex.getMessage()); + log.error(msg, ex); + errors.add(msg); + } + return this.getEmptySchema(kind); + } + + @Override + public IndexSchema getIndexerInputSchema(String kind, boolean invalidateCached) throws AppException, UnsupportedEncodingException, URISyntaxException { if (invalidateCached) { this.invalidateCache(kind); } - try { - String schema = (String) this.schemaCache.get(kind); + String schema = (String) this.schemaCache.get(kind); + if (Strings.isNullOrEmpty(schema)) { + // get from storage + schema = this.schemaProvider.getSchema(kind); if (Strings.isNullOrEmpty(schema)) { - // get from storage - schema = getSchema(kind); - if (Strings.isNullOrEmpty(schema)) { - Schema basicSchema = Schema.builder().kind(kind).build(); - return normalizeSchema(gson.toJson(basicSchema)); - } else { - // cache the schema - this.schemaCache.put(kind, schema); - // get flatten schema and cache it - IndexSchema flatSchemaObj = normalizeSchema(schema); - if (flatSchemaObj != null) { - this.schemaCache.put(kind + FLATTENED_SCHEMA, gson.toJson(flatSchemaObj)); - } - return flatSchemaObj; - } + return this.getEmptySchema(kind); } else { - // search flattened schema in memcache - String flattenedSchema = (String) this.schemaCache.get(kind + FLATTENED_SCHEMA); - if (Strings.isNullOrEmpty(flattenedSchema)) { - Schema basicSchema = Schema.builder().kind(kind).build(); - return normalizeSchema(gson.toJson(basicSchema)); + // cache the schema + this.schemaCache.put(kind, schema); + // get flatten schema and cache it + IndexSchema flatSchemaObj = normalizeSchema(schema); + if (flatSchemaObj != null) { + this.schemaCache.put(kind + FLATTENED_SCHEMA, gson.toJson(flatSchemaObj)); } - return this.gson.fromJson(flattenedSchema, IndexSchema.class); + return flatSchemaObj; } - } catch (AppException e) { - throw e; - } catch (Exception e) { - throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Schema parse/read error", "Error while reading schema via storage service.", e); + } else { + // search flattened schema in memcache + String flattenedSchema = (String) this.schemaCache.get(kind + FLATTENED_SCHEMA); + if (Strings.isNullOrEmpty(flattenedSchema)) { + return this.getEmptySchema(kind); + } + return this.gson.fromJson(flattenedSchema, IndexSchema.class); } } - private String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { - return this.schemaProvider.getSchema(kind); + private IndexSchema getEmptySchema(String kind) { + Schema basicSchema = Schema.builder().kind(kind).build(); + return normalizeSchema(gson.toJson(basicSchema)); } - public void syncIndexMappingWithStorageSchema(String kind) throws ElasticsearchException, IOException, AppException { + public void syncIndexMappingWithStorageSchema(String kind) throws ElasticsearchException, IOException, AppException, URISyntaxException { String index = this.elasticIndexNameResolver.getIndexNameFromKind(kind); try (RestHighLevelClient restClient = this.elasticClientHandler.createRestClient()) { if (this.indicesService.isIndexExist(restClient, index)) { @@ -209,7 +216,7 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { for (SchemaItem schemaItem : schemaObj.getSchema()) { String dataType = schemaItem.getKind(); Object elasticDataType = TypeMapper.getIndexerType(dataType, ElasticType.TEXT.getValue()); - if(schemaItem.getProperties() != null){ + if (schemaItem.getProperties() != null) { HashMap<String, Object> propertiesMap = normalizeInnerProperties(schemaItem); elasticDataType = TypeMapper.getObjectsArrayMapping(dataType, propertiesMap); } @@ -244,12 +251,12 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { HashMap<String, Object> propertiesMap = new HashMap<>(); for (SchemaItem propertiesItem : schemaItem.getProperties()) { String propertiesItemKind = propertiesItem.getKind(); - Object propertiesElasticType = TypeMapper.getIndexerType(propertiesItemKind,ElasticType.TEXT.getValue()); - if(propertiesItem.getProperties() != null){ + Object propertiesElasticType = TypeMapper.getIndexerType(propertiesItemKind, ElasticType.TEXT.getValue()); + if (propertiesItem.getProperties() != null) { HashMap<String, Object> innerProperties = normalizeInnerProperties(propertiesItem); propertiesElasticType = TypeMapper.getObjectsArrayMapping(propertiesItemKind, innerProperties); } - propertiesMap.put(propertiesItem.getPath(),propertiesElasticType); + propertiesMap.put(propertiesItem.getPath(), propertiesElasticType); } return propertiesMap; } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java index af1e5aea27f0b3846c68ba76a0514fa2ae714c22..6f796030f9d6ec73e8e6675c6c24882c86646a14 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java @@ -15,7 +15,6 @@ package org.opengroup.osdu.indexer.service; import com.google.gson.Gson; - import com.google.gson.GsonBuilder; import org.apache.http.HttpStatus; import org.elasticsearch.ElasticsearchStatusException; @@ -30,33 +29,34 @@ import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.RestStatus; -import org.opengroup.osdu.core.common.model.entitlements.Acl; import org.opengroup.osdu.core.common.Constants; -import org.opengroup.osdu.core.common.model.http.DpsHeaders; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.core.common.model.indexer.*; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; -import org.opengroup.osdu.indexer.logging.AuditLogger; -import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; +import org.opengroup.osdu.core.common.model.entitlements.Acl; +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.http.RequestStatus; +import org.opengroup.osdu.core.common.model.indexer.*; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.indexer.logging.AuditLogger; +import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; import org.opengroup.osdu.indexer.util.ElasticClientHandler; -import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.beanutils.NestedNullException; +import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Service; import javax.inject.Inject; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import java.util.function.Consumer; -import java.util.logging.Level; import java.util.stream.Collectors; @Service @@ -221,8 +221,11 @@ public class IndexerServiceImpl implements IndexerService { for (Map.Entry<String, Map<String, OperationType>> entry : upsertRecordMap.entrySet()) { String kind = entry.getKey(); - IndexSchema schemaObj = this.schemaService.getIndexerInputSchema(kind, false); - if (schemaObj.isDataSchemaMissing()) { + List<String> errors = new ArrayList<>(); + IndexSchema schemaObj = this.schemaService.getIndexerInputSchema(kind, errors); + if (!errors.isEmpty()) { + this.jobStatus.addOrUpdateRecordStatus(entry.getValue().keySet(), IndexingStatus.WARN, HttpStatus.SC_BAD_REQUEST, String.join("|", errors), String.format("error | kind: %s", kind)); + } else if (schemaObj.isDataSchemaMissing()) { this.jobStatus.addOrUpdateRecordStatus(entry.getValue().keySet(), IndexingStatus.WARN, HttpStatus.SC_NOT_FOUND, "schema not found", String.format("schema not found | kind: %s", kind)); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java index 6f2bf52cca0a5addf8c3c59a297cb548cd9171c6..164cf5fa4fac298e761ea2195246c591067c76b8 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java @@ -58,18 +58,7 @@ public class SchemaProviderImpl implements SchemaService { @Override public String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { - String schemaServiceSchema; - - try { - schemaServiceSchema = getFromSchemaService(kind); - } catch (SchemaProcessingException ex) { - log.error(ex.getMessage(), ex); - return null; - } catch (RuntimeException ex) { - log.error(String.format("Failed to get the schema from the Schema service, kind: %s | message: %s", kind, ex.getMessage()), ex); - return null; - } - + String schemaServiceSchema = getFromSchemaService(kind); return Objects.nonNull(schemaServiceSchema) ? schemaServiceSchema : getFromStorageService(kind); } diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java similarity index 86% rename from provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java rename to indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java index 9cc054aaaa67619bd8631e00b74fc4d330bad954..705f8e98ad4e733377abc03948fbe0fb22227c5c 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java @@ -12,13 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.opengroup.osdu.indexer.azure.service; +package org.opengroup.osdu.indexer.service; import org.apache.http.HttpStatus; import org.elasticsearch.client.RestHighLevelClient; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -31,26 +30,36 @@ import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.core.common.search.IndicesService; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; -import org.opengroup.osdu.indexer.service.IndexSchemaServiceImpl; -import org.opengroup.osdu.indexer.service.IndexerMappingService; -import org.opengroup.osdu.indexer.service.SchemaService; +import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.MockitoAnnotations.initMocks; import static org.powermock.api.mockito.PowerMockito.mock; import static org.powermock.api.mockito.PowerMockito.when; -@Ignore @RunWith(SpringRunner.class) @PrepareForTest({RestHighLevelClient.class}) public class IndexerSchemaServiceTest { @@ -128,7 +137,7 @@ public class IndexerSchemaServiceTest { } @Test - public void should_return_basic_schema_when_storage_returns_no_schema() { + public void should_return_basic_schema_when_storage_returns_no_schema() throws UnsupportedEncodingException, URISyntaxException { IndexSchema returnedSchema = this.sut.getIndexerInputSchema(kind, false); assertNotNull(returnedSchema.getDataSchema()); @@ -235,9 +244,9 @@ public class IndexerSchemaServiceTest { try { this.sut.processSchemaMessages(schemaMessages); } catch (AppException e){ - assertEquals(e.getError().getCode(), RequestStatus.SCHEMA_CONFLICT); - assertEquals(e.getError().getMessage(), "error creating or merging index mapping"); - assertEquals(e.getError().getReason(), reason); + assertEquals(RequestStatus.SCHEMA_CONFLICT, e.getError().getCode()); + assertEquals("error creating or merging index mapping", e.getError().getMessage()); + assertEquals(reason, e.getError().getReason()); } catch (Exception e) { fail("Should not throw this exception " + e.getMessage()); } @@ -268,9 +277,9 @@ public class IndexerSchemaServiceTest { try { this.sut.processSchemaMessages(schemaMessages); } catch (AppException e){ - assertEquals(e.getError().getCode(), HttpStatus.SC_FORBIDDEN); - assertEquals(e.getError().getMessage(), "blah"); - assertEquals(e.getError().getReason(), reason); + assertEquals(HttpStatus.SC_FORBIDDEN, e.getError().getCode()); + assertEquals("blah", e.getError().getMessage()); + assertEquals(reason, e.getError().getReason()); } catch (Exception e) { fail("Should not throw this exception " + e.getMessage()); } @@ -365,9 +374,9 @@ public class IndexerSchemaServiceTest { try { this.sut.syncIndexMappingWithStorageSchema(kind); } catch (AppException e) { - assertEquals(e.getError().getCode(), HttpStatus.SC_CONFLICT); - assertEquals(e.getError().getMessage(), "blah"); - assertEquals(e.getError().getReason(), "Index deletion error"); + assertEquals(HttpStatus.SC_CONFLICT, e.getError().getCode()); + assertEquals("blah", e.getError().getMessage()); + assertEquals("Index deletion error", e.getError().getReason()); } catch (Exception e) { fail("Should not throw this exception " + e.getMessage()); } @@ -404,4 +413,28 @@ public class IndexerSchemaServiceTest { assertFalse(this.sut.isStorageSchemaSyncRequired(kind, false)); } + + @Test + public void should_returnErrors_givenSchemaProcessingException_getIndexerInputSchemaSchemaTest() throws UnsupportedEncodingException, URISyntaxException { + SchemaProcessingException processingException = new SchemaProcessingException("error processing schema"); + when(schemaService.getSchema(any())).thenThrow(processingException); + + List<String> errors = new ArrayList<>(); + IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, errors); + + assertNotNull(indexSchema); + assertTrue(errors.get(0).contains("error processing schema")); + } + + @Test + public void should_returnErrors_givenRuntimeException_getIndexerInputSchemaSchemaTest() throws UnsupportedEncodingException, URISyntaxException { + RuntimeException exception = new RuntimeException("error processing schema, RuntimeException exception thrown"); + when(schemaService.getSchema(any())).thenThrow(exception); + + List<String> errors = new ArrayList<>(); + IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, errors); + + assertNotNull(indexSchema); + assertTrue(errors.get(0).contains("error processing schema, RuntimeException exception thrown")); + } } diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java deleted file mode 100644 index 631c840c22670a08200664c66aa8a0f82fc70ae6..0000000000000000000000000000000000000000 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java +++ /dev/null @@ -1,401 +0,0 @@ -// Copyright 2017-2019, Schlumberger -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.service; - -import org.apache.http.HttpStatus; -import org.elasticsearch.client.RestHighLevelClient; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.core.common.model.indexer.OperationType; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; -import org.opengroup.osdu.core.common.model.indexer.IndexSchema; -import org.opengroup.osdu.core.common.model.http.RequestStatus; -import org.opengroup.osdu.core.common.search.IndicesService; -import org.opengroup.osdu.indexer.service.SchemaProviderImpl; -import org.opengroup.osdu.indexer.util.ElasticClientHandler; -import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; - -@RunWith(SpringRunner.class) -@PrepareForTest({RestHighLevelClient.class}) -public class IndexerSchemaServiceTest { - - private final String kind = "tenant:test:test:1.0.0"; - private final String emptySchema = null; - private final String someSchema = "{\"kind\":\"tenant:test:test:1.0.0\", \"schema\":[{\"path\":\"test-path\", \"kind\":\"tenant:test:test:1.0.0\"}]}"; - - @Mock - private JaxRsDpsLog log; - @Mock - private SchemaProviderImpl schemaProvider; - @Mock - private ElasticClientHandler elasticClientHandler; - @Mock - private ElasticIndexNameResolver elasticIndexNameResolver; - @Mock - private IndexerMappingService mappingService; - @Mock - private IndicesService indicesService; - @Mock - private ISchemaCache schemaCache; - @InjectMocks - private IndexSchemaServiceImpl sut; - - @Before - public void setup() { - initMocks(this); - RestHighLevelClient restHighLevelClient = mock(RestHighLevelClient.class); - when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); - } - - @Test - public void should_returnNull_givenEmptySchema_getIndexerInputSchemaSchemaTest() throws Exception { - when(schemaProvider.getSchema(any())).thenReturn(emptySchema); - - IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); - - Assert.assertNotNull(indexSchema); - } - - @Test - public void should_returnValidResponse_givenValidSchema_getIndexerInputSchemaTest() throws Exception { - when(schemaProvider.getSchema(any())).thenReturn(someSchema); - - IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); - - Assert.assertEquals(kind, indexSchema.getKind()); - } - - @Test - public void should_returnValidResponse_givenValidSchemaWithCacheHit_getIndexerInputSchemaTest() throws Exception { - when(schemaProvider.getSchema(any())).thenReturn(someSchema); - when(this.schemaCache.get(kind + "_flattened")).thenReturn(someSchema); - - IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); - - Assert.assertEquals(kind, indexSchema.getKind()); - } - - @Test - public void should_throw500_givenInvalidSchemaCacheHit_getIndexerInputSchemaTest() { - try { - String invalidSchema = "{}}"; - when(schemaProvider.getSchema(any())).thenReturn(invalidSchema); - - this.sut.getIndexerInputSchema(kind, false); - fail("Should throw exception"); - } catch (AppException e) { - Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getError().getCode()); - Assert.assertEquals("An error has occurred while normalizing the schema.", e.getError().getMessage()); - } catch (Exception e) { - fail("Should not throw exception" + e.getMessage()); - } - } - - @Test - public void should_return_basic_schema_when_storage_returns_no_schema() { - IndexSchema returnedSchema = this.sut.getIndexerInputSchema(kind, false); - - assertNotNull(returnedSchema.getDataSchema()); - assertNotNull(returnedSchema); - assertEquals(kind, returnedSchema.getKind()); - } - - @Test - public void should_create_schema_when_storage_returns_valid_schema() throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"startDate\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"endDate\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"type \"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"itemguid\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.mappingService, times(1)).getIndexMappingFromRecordSchema(any()); - verify(this.indicesService, times(1)).createIndex(any(), any(), any(), any(), any()); - verifyNoMoreInteractions(this.mappingService); - } - - @Test - public void should_merge_mapping_when_storage_returns_valid_schema() throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"startDate\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.indicesService, times(0)).createIndex(any(), any(), any(), any(), any()); - verify(this.mappingService, times(1)).createMapping(any(), any(), any(), anyBoolean()); - verifyNoMoreInteractions(this.mappingService); - } - - @Test - public void should_throw_mapping_conflict_when_elastic_backend_cannot_process_schema_changes() throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String reason = String.format("Could not create type mapping %s/completion.", kind.replace(":", "-")); - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - when(this.mappingService.createMapping(any(), any(), any(), anyBoolean())).thenThrow(new AppException(HttpStatus.SC_BAD_REQUEST, reason, "")); - - try { - this.sut.processSchemaMessages(schemaMessages); - } catch (AppException e) { - assertEquals(RequestStatus.SCHEMA_CONFLICT, e.getError().getCode()); - assertEquals("error creating or merging index mapping", e.getError().getMessage()); - assertEquals(reason, e.getError().getReason()); - } catch (Exception e) { - fail("Should not throw this exception " + e.getMessage()); - } - } - - @Test - public void should_throw_genericAppException_when_elastic_backend_cannot_process_schema_changes() throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String reason = String.format("Could not create type mapping %s/completion.", kind.replace(":", "-")); - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - when(this.mappingService.createMapping(any(), any(), any(), anyBoolean())).thenThrow(new AppException(HttpStatus.SC_FORBIDDEN, reason, "blah")); - - try { - this.sut.processSchemaMessages(schemaMessages); - } catch (AppException e) { - assertEquals(HttpStatus.SC_FORBIDDEN, e.getError().getCode()); - assertEquals("blah", e.getError().getMessage()); - assertEquals(reason, e.getError().getReason()); - } catch (Exception e) { - fail("Should not throw this exception " + e.getMessage()); - } - } - - @Test - public void should_log_and_do_nothing_when_storage_returns_invalid_schema() throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.log).warning(eq("schema not found for kind: tenant1:avocet:completion:1.0.0")); - } - - @Test - public void should_invalidateCache_when_purge_schema_and_schema_found_in_cache() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.purge_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaCache.get(kind)).thenReturn("schema"); - when(this.schemaCache.get(kind + "_flattened")).thenReturn("flattened schema"); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.schemaCache, times(2)).get(anyString()); - verify(this.schemaCache, times(2)).delete(anyString()); - } - - @Test - public void should_log_warning_when_purge_schema_and_schema_not_found_in_cache() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.purge_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.log).warning(eq(String.format("Kind: %s not found", kind))); - } - - @Test - public void should_sync_schema_with_storage() throws Exception { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.indicesService.deleteIndex(any(), any())).thenReturn(true); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - - this.sut.syncIndexMappingWithStorageSchema(kind); - - verify(this.mappingService, times(1)).getIndexMappingFromRecordSchema(any()); - verify(this.indicesService, times(1)).isIndexExist(any(), any()); - verify(this.indicesService, times(1)).deleteIndex(any(), any()); - verify(this.indicesService, times(1)).createIndex(any(), any(), any(), any(), any()); - verifyNoMoreInteractions(this.mappingService); - } - - @Test - public void should_throw_exception_while_snapshot_running_sync_schema_with_storage() throws Exception { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.indicesService.deleteIndex(any(), any())).thenThrow(new AppException(HttpStatus.SC_CONFLICT, "Index deletion error", "blah")); - - try { - this.sut.syncIndexMappingWithStorageSchema(kind); - } catch (AppException e) { - assertEquals(HttpStatus.SC_CONFLICT, e.getError().getCode()); - assertEquals("blah", e.getError().getMessage()); - assertEquals("Index deletion error", e.getError().getReason()); - } catch (Exception e) { - fail("Should not throw this exception " + e.getMessage()); - } - - verify(this.indicesService, times(1)).isIndexExist(any(), any()); - verify(this.indicesService, times(1)).deleteIndex(any(), any()); - verify(this.mappingService, never()).getIndexMappingFromRecordSchema(any()); - verify(this.indicesService, never()).createIndex(any(), any(), any(), any(), any()); - } - - @Test - public void should_return_true_while_if_forceClean_requested() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - - assertTrue(this.sut.isStorageSchemaSyncRequired(kind, true)); - } - - @Test - public void should_return_true_while_if_forceClean_notRequested_and_indexNotFound() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - - assertTrue(this.sut.isStorageSchemaSyncRequired(kind, false)); - } - - @Test - public void should_return_false_while_if_forceClean_notRequested_and_indexExist() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - - assertFalse(this.sut.isStorageSchemaSyncRequired(kind, false)); - } -} diff --git a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/IndexerSchemaServiceTest.java b/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/IndexerSchemaServiceTest.java deleted file mode 100644 index d85ba30116235c96bb80d70fdf6c2f0065cfb94c..0000000000000000000000000000000000000000 --- a/provider/indexer-ibm/src/test/java/org/opengroup/osdu/indexer/ibm/service/IndexerSchemaServiceTest.java +++ /dev/null @@ -1,395 +0,0 @@ -/* Licensed Materials - Property of IBM */ -/* (c) Copyright IBM Corp. 2020. All Rights Reserved.*/ - -package org.opengroup.osdu.indexer.ibm.service; - -import org.apache.http.HttpStatus; -import org.elasticsearch.client.RestHighLevelClient; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.opengroup.osdu.core.common.model.indexer.IndexSchema; -import org.opengroup.osdu.core.common.model.indexer.OperationType; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; -import org.opengroup.osdu.indexer.service.IndexSchemaServiceImpl; -import org.opengroup.osdu.indexer.service.IndexerMappingService; -import org.opengroup.osdu.indexer.service.StorageService; -import org.opengroup.osdu.core.common.model.http.RequestStatus; -import org.opengroup.osdu.core.common.search.IndicesService; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.indexer.util.ElasticClientHandler; -import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; - -@Ignore -@RunWith(SpringRunner.class) -@PrepareForTest({RestHighLevelClient.class}) -public class IndexerSchemaServiceTest { - - private final String kind = "tenant:test:test:1.0.0"; - private final String emptySchema = null; - private final String someSchema = "{\"kind\":\"tenant:test:test:1.0.0\", \"schema\":[{\"path\":\"test-path\", \"kind\":\"tenant:test:test:1.0.0\"}]}"; - - @Mock - private JaxRsDpsLog log; - @Mock - private StorageService storageService; - @Mock - private ElasticClientHandler elasticClientHandler; - @Mock - private ElasticIndexNameResolver elasticIndexNameResolver; - @Mock - private IndexerMappingService mappingService; - @Mock - private IndicesService indicesService; - @Mock - private ISchemaCache schemaCache; - @InjectMocks - private IndexSchemaServiceImpl sut; - - @Before - public void setup() { - initMocks(this); - RestHighLevelClient restHighLevelClient = mock(RestHighLevelClient.class); - when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); - } - - @Test - public void should_returnNull_givenEmptySchema_getIndexerInputSchemaSchemaTest() throws Exception { - when(storageService.getStorageSchema(any())).thenReturn(emptySchema); - - IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); - - Assert.assertNotNull(indexSchema); - } - - @Test - public void should_returnValidResponse_givenValidSchema_getIndexerInputSchemaTest() throws Exception { - when(storageService.getStorageSchema(any())).thenReturn(someSchema); - - IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); - - Assert.assertEquals(kind, indexSchema.getKind()); - } - - @Test - public void should_returnValidResponse_givenValidSchemaWithCacheHit_getIndexerInputSchemaTest() throws Exception { - when(storageService.getStorageSchema(any())).thenReturn(someSchema); - when(this.schemaCache.get(kind + "_flattened")).thenReturn(someSchema); - - IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); - - Assert.assertEquals(kind, indexSchema.getKind()); - } - - @Test - public void should_throw500_givenInvalidSchemaCacheHit_getIndexerInputSchemaTest() { - try { - String invalidSchema = "{}}"; - when(storageService.getStorageSchema(any())).thenReturn(invalidSchema); - - this.sut.getIndexerInputSchema(kind, false); - fail("Should throw exception"); - } catch (AppException e) { - Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getError().getCode()); - Assert.assertEquals("An error has occurred while normalizing the schema.", e.getError().getMessage()); - } catch (Exception e) { - fail("Should not throw exception" + e.getMessage()); - } - } - - @Test - public void should_return_basic_schema_when_storage_returns_no_schema() { - IndexSchema returnedSchema = this.sut.getIndexerInputSchema(kind, false); - - assertNotNull(returnedSchema.getDataSchema()); - assertNotNull(returnedSchema); - assertEquals(kind, returnedSchema.getKind()); - } - - @Test - public void should_create_schema_when_storage_returns_valid_schema() throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"startDate\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"endDate\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"type \"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"itemguid\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.mappingService, times(1)).getIndexMappingFromRecordSchema(any()); - verify(this.indicesService, times(1)).createIndex(any(), any(), any(), any(), any()); - verifyNoMoreInteractions(this.mappingService); - } - - @Test - public void should_merge_mapping_when_storage_returns_valid_schema() throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"startDate\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.indicesService, times(0)).createIndex(any(), any(), any(), any(), any()); - verify(this.mappingService, times(1)).createMapping(any(), any(), any(), anyBoolean()); - verifyNoMoreInteractions(this.mappingService); - } - - @Test - public void should_throw_mapping_conflict_when_elastic_backend_cannot_process_schema_changes() throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String reason = String.format("Could not create type mapping %s/completion.", kind.replace(":", "-")); - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); - when(this.mappingService.createMapping(any(), any(), any(), anyBoolean())).thenThrow(new AppException(HttpStatus.SC_BAD_REQUEST, reason, "")); - - try { - this.sut.processSchemaMessages(schemaMessages); - } catch (AppException e) { - assertEquals(e.getError().getCode(), RequestStatus.SCHEMA_CONFLICT); - assertEquals(e.getError().getMessage(), "error creating or merging index mapping"); - assertEquals(e.getError().getReason(), reason); - } catch (Exception e) { - fail("Should not throw this exception " + e.getMessage()); - } - } - - @Test - public void should_throw_genericAppException_when_elastic_backend_cannot_process_schema_changes() throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String reason = String.format("Could not create type mapping %s/completion.", kind.replace(":", "-")); - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); - when(this.mappingService.createMapping(any(), any(), any(), anyBoolean())).thenThrow(new AppException(HttpStatus.SC_FORBIDDEN, reason, "blah")); - - try { - this.sut.processSchemaMessages(schemaMessages); - } catch (AppException e) { - assertEquals(e.getError().getCode(), HttpStatus.SC_FORBIDDEN); - assertEquals(e.getError().getMessage(), "blah"); - assertEquals(e.getError().getReason(), reason); - } catch (Exception e) { - fail("Should not throw this exception " + e.getMessage()); - } - } - - @Test - public void should_log_and_do_nothing_when_storage_returns_invalid_schema() throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.log).warning(eq("schema not found for kind: tenant1:avocet:completion:1.0.0")); - } - - @Test - public void should_invalidateCache_when_purge_schema_and_schema_found_in_cache() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.purge_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaCache.get(kind)).thenReturn("schema"); - when(this.schemaCache.get(kind + "_flattened")).thenReturn("flattened schema"); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.schemaCache, times(2)).get(anyString()); - verify(this.schemaCache, times(2)).delete(anyString()); - } - - @Test - public void should_log_warning_when_purge_schema_and_schema_not_found_in_cache() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.purge_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.log).warning(eq(String.format("Kind: %s not found", kind))); - } - - @Test - public void should_sync_schema_with_storage() throws Exception { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.indicesService.deleteIndex(any(), any())).thenReturn(true); - when(this.storageService.getStorageSchema(kind)).thenReturn(storageSchema); - - this.sut.syncIndexMappingWithStorageSchema(kind); - - verify(this.mappingService, times(1)).getIndexMappingFromRecordSchema(any()); - verify(this.indicesService, times(1)).isIndexExist(any(), any()); - verify(this.indicesService, times(1)).deleteIndex(any(), any()); - verify(this.indicesService, times(1)).createIndex(any(), any(), any(), any(), any()); - verifyNoMoreInteractions(this.mappingService); - } - - @Test - public void should_throw_exception_while_snapshot_running_sync_schema_with_storage() throws Exception { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.indicesService.deleteIndex(any(), any())).thenThrow(new AppException(HttpStatus.SC_CONFLICT, "Index deletion error", "blah")); - - try { - this.sut.syncIndexMappingWithStorageSchema(kind); - } catch (AppException e) { - assertEquals(e.getError().getCode(), HttpStatus.SC_CONFLICT); - assertEquals(e.getError().getMessage(), "blah"); - assertEquals(e.getError().getReason(), "Index deletion error"); - } catch (Exception e) { - fail("Should not throw this exception " + e.getMessage()); - } - - verify(this.indicesService, times(1)).isIndexExist(any(), any()); - verify(this.indicesService, times(1)).deleteIndex(any(), any()); - verify(this.mappingService, never()).getIndexMappingFromRecordSchema(any()); - verify(this.indicesService, never()).createIndex(any(), any(), any(), any(), any()); - } - - @Test - public void should_return_true_while_if_forceClean_requested() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - - assertTrue(this.sut.isStorageSchemaSyncRequired(kind, true)); - } - - @Test - public void should_return_true_while_if_forceClean_notRequested_and_indexNotFound() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - - assertTrue(this.sut.isStorageSchemaSyncRequired(kind, false)); - } - - @Test - public void should_return_false_while_if_forceClean_notRequested_and_indexExist() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - - assertFalse(this.sut.isStorageSchemaSyncRequired(kind, false)); - } -} diff --git a/provider/indexer-reference/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java b/provider/indexer-reference/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java deleted file mode 100644 index 3b59eb203d3c9bd4391b0a25325ec30e70d06257..0000000000000000000000000000000000000000 --- a/provider/indexer-reference/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java +++ /dev/null @@ -1,445 +0,0 @@ -/* - * Copyright 2021 Google LLC - * Copyright 2021 EPAM Systems, Inc - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.opengroup.osdu.indexer.service; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyBoolean; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; -import org.apache.http.HttpStatus; -import org.elasticsearch.client.RestHighLevelClient; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.core.common.model.http.RequestStatus; -import org.opengroup.osdu.core.common.model.indexer.IndexSchema; -import org.opengroup.osdu.core.common.model.indexer.OperationType; -import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; -import org.opengroup.osdu.core.common.search.IndicesService; -import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; -import org.opengroup.osdu.indexer.service.SchemaProviderImpl; -import org.opengroup.osdu.indexer.util.ElasticClientHandler; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@PrepareForTest({RestHighLevelClient.class}) -public class IndexerSchemaServiceTest { - - private final String kind = "tenant:test:test:1.0.0"; - private final String emptySchema = null; - private final String someSchema = "{\"kind\":\"tenant:test:test:1.0.0\", \"schema\":[{\"path\":\"test-path\", \"kind\":\"tenant:test:test:1.0.0\"}]}"; - - @Mock - private JaxRsDpsLog log; - @Mock - private SchemaProviderImpl schemaProvider; - @Mock - private ElasticClientHandler elasticClientHandler; - @Mock - private ElasticIndexNameResolver elasticIndexNameResolver; - @Mock - private IndexerMappingService mappingService; - @Mock - private IndicesService indicesService; - @Mock - private ISchemaCache schemaCache; - @InjectMocks - private IndexSchemaServiceImpl sut; - - @Before - public void setup() { - initMocks(this); - RestHighLevelClient restHighLevelClient = mock(RestHighLevelClient.class); - when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); - } - - @Test - public void should_returnNull_givenEmptySchema_getIndexerInputSchemaSchemaTest() - throws Exception { - when(schemaProvider.getSchema(any())).thenReturn(emptySchema); - - IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); - - Assert.assertNotNull(indexSchema); - } - - @Test - public void should_returnValidResponse_givenValidSchema_getIndexerInputSchemaTest() - throws Exception { - when(schemaProvider.getSchema(any())).thenReturn(someSchema); - - IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); - - Assert.assertEquals(kind, indexSchema.getKind()); - } - - @Test - public void should_returnValidResponse_givenValidSchemaWithCacheHit_getIndexerInputSchemaTest() - throws Exception { - when(schemaProvider.getSchema(any())).thenReturn(someSchema); - when(this.schemaCache.get(kind + "_flattened")).thenReturn(someSchema); - - IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); - - Assert.assertEquals(kind, indexSchema.getKind()); - } - - @Test - public void should_throw500_givenInvalidSchemaCacheHit_getIndexerInputSchemaTest() { - try { - String invalidSchema = "{}}"; - when(schemaProvider.getSchema(any())).thenReturn(invalidSchema); - - this.sut.getIndexerInputSchema(kind, false); - fail("Should throw exception"); - } catch (AppException e) { - Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getError().getCode()); - Assert.assertEquals("An error has occurred while normalizing the schema.", - e.getError().getMessage()); - } catch (Exception e) { - fail("Should not throw exception" + e.getMessage()); - } - } - - @Test - public void should_return_basic_schema_when_storage_returns_no_schema() { - IndexSchema returnedSchema = this.sut.getIndexerInputSchema(kind, false); - - assertNotNull(returnedSchema.getDataSchema()); - assertNotNull(returnedSchema); - assertEquals(kind, returnedSchema.getKind()); - } - - @Test - public void should_create_schema_when_storage_returns_valid_schema() - throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"startDate\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"endDate\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"type \"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"itemguid\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.mappingService, times(1)).getIndexMappingFromRecordSchema(any()); - verify(this.indicesService, times(1)).createIndex(any(), any(), any(), any(), any()); - verifyNoMoreInteractions(this.mappingService); - } - - @Test - public void should_merge_mapping_when_storage_returns_valid_schema() - throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }," + - " {" + - " \"path\": \"startDate\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.indicesService, times(0)).createIndex(any(), any(), any(), any(), any()); - verify(this.mappingService, times(1)).createMapping(any(), any(), any(), anyBoolean()); - verifyNoMoreInteractions(this.mappingService); - } - - @Test - public void should_throw_mapping_conflict_when_elastic_backend_cannot_process_schema_changes() - throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String reason = String - .format("Could not create type mapping %s/completion.", kind.replace(":", "-")); - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - when(this.mappingService.createMapping(any(), any(), any(), anyBoolean())) - .thenThrow(new AppException(HttpStatus.SC_BAD_REQUEST, reason, "")); - - try { - this.sut.processSchemaMessages(schemaMessages); - } catch (AppException e) { - assertEquals(RequestStatus.SCHEMA_CONFLICT, e.getError().getCode()); - assertEquals("error creating or merging index mapping", e.getError().getMessage()); - assertEquals(reason, e.getError().getReason()); - } catch (Exception e) { - fail("Should not throw this exception " + e.getMessage()); - } - } - - @Test - public void should_throw_genericAppException_when_elastic_backend_cannot_process_schema_changes() - throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String reason = String - .format("Could not create type mapping %s/completion.", kind.replace(":", "-")); - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - when(this.mappingService.createMapping(any(), any(), any(), anyBoolean())) - .thenThrow(new AppException(HttpStatus.SC_FORBIDDEN, reason, "blah")); - - try { - this.sut.processSchemaMessages(schemaMessages); - } catch (AppException e) { - assertEquals(HttpStatus.SC_FORBIDDEN, e.getError().getCode()); - assertEquals("blah", e.getError().getMessage()); - assertEquals(reason, e.getError().getReason()); - } catch (Exception e) { - fail("Should not throw this exception " + e.getMessage()); - } - } - - @Test - public void should_log_and_do_nothing_when_storage_returns_invalid_schema() - throws IOException, URISyntaxException { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"" + - "}"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.create_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.log).warning(eq("schema not found for kind: tenant1:avocet:completion:1.0.0")); - } - - @Test - public void should_invalidateCache_when_purge_schema_and_schema_found_in_cache() - throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.purge_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.schemaCache.get(kind)).thenReturn("schema"); - when(this.schemaCache.get(kind + "_flattened")).thenReturn("flattened schema"); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.schemaCache, times(2)).get(anyString()); - verify(this.schemaCache, times(2)).delete(anyString()); - } - - @Test - public void should_log_warning_when_purge_schema_and_schema_not_found_in_cache() - throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - Map<String, OperationType> schemaMessages = new HashMap<>(); - schemaMessages.put(kind, OperationType.purge_schema); - - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - - this.sut.processSchemaMessages(schemaMessages); - - verify(this.log).warning(eq(String.format("Kind: %s not found", kind))); - } - - @Test - public void should_sync_schema_with_storage() throws Exception { - String kind = "tenant1:avocet:completion:1.0.0"; - String storageSchema = "{" + - " \"kind\": \"tenant1:avocet:completion:1.0.0\"," + - " \"schema\": [" + - " {" + - " \"path\": \"status\"," + - " \"kind\": \"string\"" + - " }" + - " ]" + - "}"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.indicesService.deleteIndex(any(), any())).thenReturn(true); - when(this.schemaProvider.getSchema(kind)).thenReturn(storageSchema); - - this.sut.syncIndexMappingWithStorageSchema(kind); - - verify(this.mappingService, times(1)).getIndexMappingFromRecordSchema(any()); - verify(this.indicesService, times(1)).isIndexExist(any(), any()); - verify(this.indicesService, times(1)).deleteIndex(any(), any()); - verify(this.indicesService, times(1)).createIndex(any(), any(), any(), any(), any()); - verifyNoMoreInteractions(this.mappingService); - } - - @Test - public void should_throw_exception_while_snapshot_running_sync_schema_with_storage() - throws Exception { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.schemaCache.get(kind)).thenReturn(null); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - when(this.indicesService.deleteIndex(any(), any())) - .thenThrow(new AppException(HttpStatus.SC_CONFLICT, "Index deletion error", "blah")); - - try { - this.sut.syncIndexMappingWithStorageSchema(kind); - } catch (AppException e) { - assertEquals(HttpStatus.SC_CONFLICT, e.getError().getCode()); - assertEquals("blah", e.getError().getMessage()); - assertEquals("Index deletion error", e.getError().getReason()); - } catch (Exception e) { - fail("Should not throw this exception " + e.getMessage()); - } - - verify(this.indicesService, times(1)).isIndexExist(any(), any()); - verify(this.indicesService, times(1)).deleteIndex(any(), any()); - verify(this.mappingService, never()).getIndexMappingFromRecordSchema(any()); - verify(this.indicesService, never()).createIndex(any(), any(), any(), any(), any()); - } - - @Test - public void should_return_true_while_if_forceClean_requested() throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - - assertTrue(this.sut.isStorageSchemaSyncRequired(kind, true)); - } - - @Test - public void should_return_true_while_if_forceClean_notRequested_and_indexNotFound() - throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(false); - - assertTrue(this.sut.isStorageSchemaSyncRequired(kind, false)); - } - - @Test - public void should_return_false_while_if_forceClean_notRequested_and_indexExist() - throws IOException { - String kind = "tenant1:avocet:completion:1.0.0"; - when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)) - .thenReturn(kind.replace(":", "-")); - when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); - - assertFalse(this.sut.isStorageSchemaSyncRequired(kind, false)); - } -}