diff --git a/NOTICE b/NOTICE index f32383645a6dfc410c66b4447235d03c43044ef7..b3ffeee036495bdb48fd24b4c0ed9abeebe93a26 100644 --- a/NOTICE +++ b/NOTICE @@ -67,7 +67,6 @@ The following software have components provided under the terms of this license: - Byte Buddy (without dependencies) (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy) - Byte Buddy Java agent (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent) - ClassMate (from http://github.com/cowtowncoder/java-classmate) -- Cloud Key Management Service (KMS) API v1-rev20240903-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms) - Collections (from https://repo1.maven.org/maven2/commons-collections/commons-collections) - Commons Digester (from http://commons.apache.org/digester/) - Converter: Jackson (from https://github.com/square/retrofit, https://repo1.maven.org/maven2/com/squareup/retrofit2/converter-jackson) @@ -81,9 +80,7 @@ The following software have components provided under the terms of this license: - Google App Engine extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-appengine) - Google Cloud Core (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core, https://github.com/googleapis/java-core, https://repo1.maven.org/maven2/com/google/cloud/google-cloud-core) - Google Cloud Core HTTP (from https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http, https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http, https://github.com/googleapis/java-core, https://repo1.maven.org/maven2/com/google/cloud/google-cloud-core-http) -- Google Cloud Core gRPC (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc, https://github.com/googleapis/java-core, https://repo1.maven.org/maven2/com/google/cloud/google-cloud-core-grpc) - Google Cloud Datastore (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-datastore, https://github.com/googleapis/java-datastore) -- Google Cloud Logging (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-logging, https://github.com/googleapis/java-logging) - Google HTTP Client Library for Java (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client) - Google OAuth Client Library for Java (from https://repo1.maven.org/maven2/com/google/oauth-client/google-oauth-client) - Gson (from http://code.google.com/p/google-gson/, https://repo1.maven.org/maven2/com/google/code/gson/gson) @@ -92,7 +89,6 @@ The following software have components provided under the terms of this license: - Guava: Google Core Libraries for Java (from http://code.google.com/p/guava-libraries, https://github.com/google/guava, https://repo1.maven.org/maven2/com/google/guava/guava) - HTTP functionality for the Reactor Netty library (from https://github.com/reactor/reactor-netty) - Hibernate Validator (from https://hibernate.org/validator, https://repo1.maven.org/maven2/org/hibernate/hibernate-validator, https://repo1.maven.org/maven2/org/hibernate/validator/hibernate-validator) -- HikariCP (from https://github.com/brettwooldridge/HikariCP) - IBM COS Java SDK for Amazon S3 (from https://github.com/ibm/ibm-cos-sdk-java) - IBM COS Java SDK for COS KMS (from https://github.com/ibm/ibm-cos-sdk-java) - IBM COS SDK For Java (from https://github.com/ibm/ibm-cos-sdk-java) @@ -109,7 +105,6 @@ The following software have components provided under the terms of this license: - JSON library from Android SDK (from http://developer.android.com/sdk) - JSONassert (from http://github.com/skyscreamer/yoga, https://github.com/skyscreamer/JSONassert) - JSR107 API and SPI (from https://github.com/jsr107/jsr107spec) -- Jackson 2 extensions to the Google APIs Client Library for Java (from https://repo1.maven.org/maven2/com/google/api-client/google-api-client-jackson2) - Jackson 2 extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-jackson2) - Jackson dataformat: CBOR (from http://github.com/FasterXML/jackson-dataformats-binary) - Jackson datatype: JSR310 (from http://wiki.fasterxml.com/JacksonModuleJSR310, https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310) @@ -176,7 +171,6 @@ The following software have components provided under the terms of this license: - OpenTelemetry Java (from https://github.com/open-telemetry/opentelemetry-java) - OpenTelemetry Semantic Conventions Java (from https://github.com/open-telemetry/semantic-conventions-java) - Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils, https://codehaus-plexus.github.io/plexus-utils/, https://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils) -- PostgreSQL JDBC Driver - Protocol Buffer extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-protobuf) - Proton-J (from https://repo1.maven.org/maven2/org/apache/qpid/proton-j) - QpidJMS Client (from https://repo1.maven.org/maven2/org/apache/qpid/qpid-jms-client) @@ -192,7 +186,6 @@ The following software have components provided under the terms of this license: - Spring Boot Actuator AutoConfigure (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-actuator-autoconfigure, https://spring.io/projects/spring-boot) - Spring Boot Actuator Starter (from http://projects.spring.io/spring-boot/, https://spring.io/projects/spring-boot) - Spring Boot AutoConfigure (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-autoconfigure, https://spring.io/projects/spring-boot) -- Spring Boot JDBC Starter (from http://projects.spring.io/spring-boot/, https://spring.io/projects/spring-boot) - Spring Boot Json Starter (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-json, https://spring.io/projects/spring-boot) - Spring Boot Log4j 2 Starter (from http://projects.spring.io/spring-boot/, https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-log4j2, https://spring.io/projects/spring-boot) - Spring Boot Logging Starter (from http://projects.spring.io/spring-boot/, https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-logging, https://spring.io/projects/spring-boot) @@ -210,7 +203,6 @@ The following software have components provided under the terms of this license: - Spring Data Core (from https://spring.io/projects/spring-data) - Spring Data MongoDB - Core (from https://repo1.maven.org/maven2/org/springframework/data/spring-data-mongodb) - Spring Expression Language (SpEL) (from https://github.com/SpringSource/spring-framework, https://github.com/spring-projects/spring-framework, https://repo1.maven.org/maven2/org/springframework/spring-expression) -- Spring JDBC (from https://github.com/SpringSource/spring-framework, https://github.com/spring-projects/spring-framework, https://repo1.maven.org/maven2/org/springframework/spring-jdbc) - Spring JMS (from http://www.springframework.org, https://github.com/SpringSource/spring-framework, https://github.com/spring-projects/spring-framework, https://repo1.maven.org/maven2/org/springframework/spring-jms) - Spring Messaging (from https://github.com/spring-projects/spring-framework) - Spring Security - Core (from http://spring.io/spring-security, https://repo1.maven.org/maven2/org/springframework/security/spring-security-core, https://spring.io/projects/spring-security, https://spring.io/spring-security) @@ -261,10 +253,10 @@ The following software have components provided under the terms of this license: - perfmark:perfmark-api (from https://github.com/perfmark/perfmark) - proto-google-cloud-datastore-admin-v1 (from https://github.com/googleapis/java-datastore/proto-google-cloud-datastore-admin-v1) - proto-google-cloud-datastore-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-datastore/proto-google-cloud-datastore-v1) -- proto-google-cloud-logging-v2 (from https://github.com/googleapis/java-logging/proto-google-cloud-logging-v2, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-logging-v2) - proto-google-common-protos (from https://github.com/googleapis/api-client-staging, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-common-protos, https://github.com/googleapis/sdk-platform-java) - proto-google-iam-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-iam-v1, https://github.com/googleapis/sdk-platform-java) - resilience4j (from https://github.com/resilience4j/resilience4j, https://resilience4j.readme.io, ttps://resilience4j.readme.io) +- spring-boot-loader (from https://spring.io/projects/spring-boot) - spring-security-oauth2-client (from http://spring.io/spring-security, https://spring.io/projects/spring-security, https://spring.io/spring-security) - spring-security-oauth2-core (from http://spring.io/spring-security, https://spring.io/projects/spring-security, https://spring.io/spring-security) - spring-security-oauth2-jose (from http://spring.io/spring-security, https://spring.io/projects/spring-security, https://spring.io/spring-security) @@ -290,14 +282,12 @@ BSD-2-Clause The following software have components provided under the terms of this license: - Apache Log4j Core (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core) -- Hamcrest (from http://hamcrest.org/JavaHamcrest/) - Hamcrest Core (from http://hamcrest.org/, http://hamcrest.org/JavaHamcrest/, https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core) - HdrHistogram (from http://hdrhistogram.github.io/HdrHistogram/) - Jodd Util (from https://util.jodd.org) - LatencyUtils (from http://latencyutils.github.io/LatencyUtils/) - MinLog (from https://github.com/EsotericSoftware/minlog) - Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils, https://codehaus-plexus.github.io/plexus-utils/, https://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils) -- PostgreSQL JDBC Driver - ReflectASM (from https://github.com/EsotericSoftware/reflectasm) - Stax2 API (from http://github.com/FasterXML/stax2-api) @@ -330,7 +320,6 @@ The following software have components provided under the terms of this license: - Netty/Codec/HTTP (from https://repo1.maven.org/maven2/io/netty/netty-codec-http) - Old JAXB Core (from <https://eclipse-ee4j.github.io/jaxb-ri/>, https://eclipse-ee4j.github.io/jaxb-ri/, https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-impl) - Plexus Common Utilities (from http://plexus.codehaus.org/plexus-utils, https://codehaus-plexus.github.io/plexus-utils/, https://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils) -- PostgreSQL JDBC Driver - Protocol Buffer Java API (from http://code.google.com/p/protobuf, https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java) - Protocol Buffers [Util] (from https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java-util) - RE2/J (from http://github.com/google/re2j) @@ -427,6 +416,7 @@ The following software have components provided under the terms of this license: - JUnit Platform Engine API (from http://junit.org/junit5/, https://junit.org/junit5/) - Jakarta Activation API (from https://github.com/eclipse-ee4j/jaf, https://github.com/jakartaee/jaf-api, https://repo1.maven.org/maven2/jakarta/activation/jakarta.activation-api) - Jakarta Annotations API (from https://projects.eclipse.org/projects/ee4j.ca) +- Jakarta Dependency Injection (from https://github.com/eclipse-ee4j/injection-api) - Jakarta Messaging API (from https://projects.eclipse.org/projects/ee4j.jms) - Jakarta Validation API (from https://beanvalidation.org) - Jakarta XML Binding API (from https://repo1.maven.org/maven2/jakarta/xml/bind/jakarta.xml.bind-api, https://repo1.maven.org/maven2/org/jboss/spec/javax/xml/bind/jboss-jaxb-api_2.3_spec) @@ -447,6 +437,7 @@ The following software have components provided under the terms of this license: - Angus Activation Registries (from https://repo1.maven.org/maven2/org/eclipse/angus/angus-activation) - Jakarta Activation API (from https://github.com/eclipse-ee4j/jaf, https://github.com/jakartaee/jaf-api, https://repo1.maven.org/maven2/jakarta/activation/jakarta.activation-api) - Jakarta Annotations API (from https://projects.eclipse.org/projects/ee4j.ca) +- Jakarta Dependency Injection (from https://github.com/eclipse-ee4j/injection-api) - Jakarta Messaging API (from https://projects.eclipse.org/projects/ee4j.jms) - Jakarta Validation API (from https://beanvalidation.org) - Jakarta XML Binding API (from https://repo1.maven.org/maven2/jakarta/xml/bind/jakarta.xml.bind-api, https://repo1.maven.org/maven2/org/jboss/spec/javax/xml/bind/jboss-jaxb-api_2.3_spec) @@ -461,7 +452,6 @@ 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) - Spring Security - Core (from http://spring.io/spring-security, https://repo1.maven.org/maven2/org/springframework/security/spring-security-core, https://spring.io/projects/spring-security, https://spring.io/spring-security) ======================================================================== @@ -483,6 +473,7 @@ LGPL-2.1-or-later The following software have components provided under the terms of this license: - Java Native Access (from https://github.com/java-native-access/jna, https://github.com/twall/jna) +- Java Native Access Platform (from https://github.com/java-native-access/jna) - Javassist (from http://www.javassist.org/, https://www.javassist.org/) ======================================================================== @@ -582,7 +573,5 @@ public-domain ======================================================================== The following software have components provided under the terms of this license: -- HdrHistogram (from http://hdrhistogram.github.io/HdrHistogram/) - JBoss Logging 3 (from http://www.jboss.org) - JSON in Java (from https://github.com/douglascrockford/JSON-java) -- PostgreSQL JDBC Driver diff --git a/devops/gc/deploy/templates/configmap-bootstrap.yaml b/devops/gc/deploy/templates/configmap-bootstrap.yaml index 3e0c4075f751e074164072dc2fb001c578c13768..956eb8683a5ae18988e9429d77429bd600387dea 100644 --- a/devops/gc/deploy/templates/configmap-bootstrap.yaml +++ b/devops/gc/deploy/templates/configmap-bootstrap.yaml @@ -13,20 +13,6 @@ data: AUTOCOMPLETE_ENABLED: {{ .Values.data.autocompleteEnabled | quote }} PARTITION_SUFFIX: {{ .Values.data.partitionSuffix | quote }} DATA_PARTITION_ID: {{ .Values.global.dataPartitionId | quote }} - {{- if .Values.global.onPremEnabled }} - ENVIRONMENT: "anthos" - SERVICE_ACCOUNT: {{ printf "%s@service.local" .Values.data.datafierSa | quote }} - DOMAIN: "{{ .Values.global.domain }}" - BUCKET_PREFIX: {{ .Values.data.bucketPrefix | quote }} - MINIO_ENDPOINT: {{ default "http://minio:9000" .Values.data.minioExternalEndpoint | quote }} - MINIO_UI_ENDPOINT: {{ .Values.data.minioUIEndpoint | quote }} - {{- if .Values.global.useHttps }} - MINIO_EXTERNAL_ENDPOINT: {{ default (printf "https://s3.%s" .Values.global.domain) .Values.data.minioExternalEndpoint | quote }} - {{- else }} - MINIO_EXTERNAL_ENDPOINT: {{ default (printf "http://s3.%s" .Values.global.domain) .Values.data.minioExternalEndpoint | quote }} - {{- end }} - MINIO_IGNORE_CERT_CHECK: {{ .Values.data.minioIgnoreCertCheck | quote }} - {{- else }} ENVIRONMENT: "gcp" {{- if .Values.data.dataProjectId }} PROJECT_ID: "{{ .Values.data.dataProjectId }}" @@ -34,5 +20,3 @@ data: PROJECT_ID: "{{ .Values.data.projectId }}" {{- end }} SERVICE_ACCOUNT: {{ printf "%s@%s.iam.gserviceaccount.com" .Values.data.datafierSa .Values.data.projectId | quote }} - {{- end }} - diff --git a/devops/gc/deploy/templates/configmap.yaml b/devops/gc/deploy/templates/configmap.yaml index 3254bf46dec8113b59b1cf12d3d2e46f82041997..ade739aa29791bcdc8553d86400cbe5096937594 100644 --- a/devops/gc/deploy/templates/configmap.yaml +++ b/devops/gc/deploy/templates/configmap.yaml @@ -8,11 +8,7 @@ metadata: data: LOG_LEVEL: {{ .Values.data.logLevel | default .Values.global.logLevel | quote }} SYSTEM_TENANT_API: "true" - {{- if not .Values.global.onPremEnabled }} GOOGLE_CLOUD_PROJECT: {{ .Values.data.projectId | quote }} PARTITION_NAMESPACE: {{ .Values.data.partitionNamespace | quote }} SYSTEM_PARTITION_ID: "system" SPRING_PROFILES_ACTIVE: "gcp" - {{- else }} - SPRING_PROFILES_ACTIVE: "anthos" - {{- end }} diff --git a/devops/gc/deploy/templates/deploy.yaml b/devops/gc/deploy/templates/deploy.yaml index 8acccc3bd3aad160afd8d6d9959f2d8d8ea376e6..b3bfd128a57baa83a3b524ba58ef1987aa7f5232 100644 --- a/devops/gc/deploy/templates/deploy.yaml +++ b/devops/gc/deploy/templates/deploy.yaml @@ -31,10 +31,6 @@ spec: envFrom: - configMapRef: name: {{ .Values.conf.configmap | quote }} - {{- if .Values.global.onPremEnabled }} - - secretRef: - name: {{ .Values.conf.secret | quote }} - {{- end }} securityContext: allowPrivilegeEscalation: false runAsNonRoot: true diff --git a/devops/gc/deploy/templates/service-account.yaml b/devops/gc/deploy/templates/service-account.yaml index 55fe3b02880cc92c6d4bae4a224b4a00d6dc0529..522050914ad0be488336c39d50da7959d5098835 100644 --- a/devops/gc/deploy/templates/service-account.yaml +++ b/devops/gc/deploy/templates/service-account.yaml @@ -1,11 +1,3 @@ -{{- if .Values.global.onPremEnabled }} -apiVersion: v1 -kind: ServiceAccount -metadata: - name: {{ .Values.data.serviceAccountName | quote }} - namespace: {{ .Release.Namespace | quote }} -{{- end }} ---- apiVersion: v1 kind: ServiceAccount metadata: diff --git a/devops/gc/deploy/templates/service.yaml b/devops/gc/deploy/templates/service.yaml index 2677151507ee221e7d943b2f71722deb8753a929..bd34d85cd6124004b0275d8183a63cd8e884f3ab 100644 --- a/devops/gc/deploy/templates/service.yaml +++ b/devops/gc/deploy/templates/service.yaml @@ -3,10 +3,8 @@ kind: Service metadata: name: {{ .Values.conf.appName | quote }} namespace: {{ .Release.Namespace | quote }} - {{- if not .Values.global.onPremEnabled }} annotations: cloud.google.com/neg: '{"ingress": true}' - {{- end }} spec: ports: - port: 80 diff --git a/devops/gc/deploy/templates/virtual-service.yaml b/devops/gc/deploy/templates/virtual-service.yaml index 25e1cc6abdf1262e72738f8010ecf411ca8c9a79..f0f5cf5eeb07f389d474debb215432e3c9ae35b7 100644 --- a/devops/gc/deploy/templates/virtual-service.yaml +++ b/devops/gc/deploy/templates/virtual-service.yaml @@ -5,9 +5,7 @@ metadata: namespace: {{ .Release.Namespace | quote }} spec: hosts: - {{- if and .Values.global.domain .Values.global.onPremEnabled }} - - {{ printf "osdu.%s" .Values.global.domain | quote }} - {{- else if .Values.global.domain }} + {{- if .Values.global.domain }} - {{ .Values.global.domain | quote }} {{- else }} - "*" diff --git a/devops/gc/deploy/values.yaml b/devops/gc/deploy/values.yaml index fe3d4545c601f42f70aff2a1e2e014d75455d82c..d1f4c0a2cb7480fe7c11185df1550439c3d418e7 100644 --- a/devops/gc/deploy/values.yaml +++ b/devops/gc/deploy/values.yaml @@ -1,7 +1,6 @@ global: domain: "" useHttps: true - onPremEnabled: false limitsEnabled: true dataPartitionId: "" logLevel: "ERROR" @@ -16,12 +15,9 @@ data: partitionSuffix: "_SYSTEM" datafierSa: "datafier" bucketPrefix: "refi" - minioExternalEndpoint: "" # use only if external minio is configured - minioIgnoreCertCheck: "false" indexerAugmenterEnabled: "false" policyServiceEnabled: "true" edsEnabled: "false" - minioUIEndpoint: "http://minio:9001" autocompleteEnabled: "false" # deployments requestsCpu: "5m" @@ -32,7 +28,6 @@ data: imagePullPolicy: "IfNotPresent" image: "community.opengroup.org:5555/osdu/platform/system/partition/osdu-gcp-partition:latest" bootstrapImage: "community.opengroup.org:5555/osdu/platform/system/partition/osdu-gcp-bootstrap-partition:latest" - # bootstrap onprem conf: appName: "partition" @@ -40,9 +35,6 @@ conf: secret: "partition-postgres-secret" replicas: 2 -auth: - realm: "osdu" - istio: proxyCPU: "5m" proxyCPULimit: "500m" diff --git a/devops/gc/pipeline/override-stages.yml b/devops/gc/pipeline/override-stages.yml index 913ad84f06a24904d311479f329ab723b7342181..c296767d04734cd0f69173131f108914d68fdbfa 100644 --- a/devops/gc/pipeline/override-stages.yml +++ b/devops/gc/pipeline/override-stages.yml @@ -5,33 +5,46 @@ variables: GC_HELM_ENV_DIR: "devops/gc/tests/env" ENV_BUILD_PATH: "devops/gc/tests/build/Dockerfile" -gc-containerize-bootstrap-env-gitlab: +download_gc_plugins: + image: maven:3.8.3-openjdk-17-slim stage: build - image: docker:19.03.15 - tags: ["osdu-small"] - services: - - docker:20.10.7-dind variables: - BUILD_BOOTSTRAP_PATH: "devops/gc/tests/build/Dockerfile" + GC_OSM_PACKAGE_REGISTRY_URL: "https://community.opengroup.org/api/v4/projects/1476/packages/maven" + GC_OSM_VERSION: "0.27.0-rc7" + artifacts: + paths: + - ./tmp-gc/*.jar + when: always + expire_in: 1 days script: - - export EXTRA_DOCKER_TAG="" - - > - if [[ "$CI_COMMIT_TAG" != "" ]]; - then EXTRA_DOCKER_TAG="-t $CI_REGISTRY_IMAGE/$IMAGE_BOOTSTRAP_NAME-env:$CI_COMMIT_TAG"; - elif [[ "$CI_COMMIT_REF_NAME" = "$CI_DEFAULT_BRANCH" ]]; - then EXTRA_DOCKER_TAG="-t $CI_REGISTRY_IMAGE/$IMAGE_BOOTSTRAP_NAME-env:latest"; fi - - docker build -t $CI_REGISTRY_IMAGE/$IMAGE_BOOTSTRAP_NAME-env:$CI_COMMIT_SHORT_SHA $EXTRA_DOCKER_TAG -f $BUILD_BOOTSTRAP_PATH . - - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - - docker push $CI_REGISTRY_IMAGE/$IMAGE_BOOTSTRAP_NAME-env + - mvn dependency:copy -DrepoUrl=$GC_OSM_PACKAGE_REGISTRY_URL -Dartifact="org.opengroup.osdu:gc-osm-datastore:$GC_OSM_VERSION:jar:plugin" -Dtransitive=false -DoutputDirectory="./tmp-gc" + only: + variables: + - $GC == '1' + +gc-containerize-gitlab: + needs: ["compile-and-unit-test", "download_gc_plugins"] + +gc-containerize-gcr: + needs: ["compile-and-unit-test", "download_gc_plugins"] + +gc-baremetal-deploy: + rules: + - when: never + +gc-baremetal-test: + rules: + - when: never + +gc-baremetal-osdutest: rules: - - if: "$GC == '1' && $GC_ENABLE_BOOTSTRAP == 'true'" - when: on_success + - when: never gc-deploy: # reuse common deploy job for test deployment variables: GC_HELM_NAMESPACE: partition-int-test GC_HELM_SETS: >- - --set data.dataPartitionId=test + --set global.dataPartitionId=test --set data.partitionNamespace=partition-test --set istio.sidecarInject=false --set data.edsEnabled=true @@ -81,103 +94,12 @@ gc-verified-deploy: # verified deploy after tests GC_HELM_SETS: >- --set data.edsEnabled=true -# Baremetal jobs -gc-baremetal-deploy-test-env: #infra deploy for on-prem install - environment: - name: GC_Baremetal - extends: .gc-baremetal-variables - id_tokens: - GITLAB_OIDC_TOKEN: - aud: https://iam.googleapis.com/projects/${GC_PROJECT_NUMBER}/locations/global/workloadIdentityPools/${GC_POOL_ID}/providers/${GC_PROVIDER_ID} - tags: ["osdu-small"] - image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine - stage: deploy - needs: ["gc-containerize-bootstrap-env-gitlab", "compile-and-unit-test"] - retry: 1 - variables: - GC_HELM_NAMESPACE: partition-int-test - GC_SA_EMAIL: $GC_SA_GKE_EMAIL - script: - - !reference [.gc_obtain_credentials, script] - - !reference [.gc_common_config, script] - - export PASSWORD=$(</dev/urandom tr -dc _A-Z-a-z-0-9 | head -c10) - - cd $GC_HELM_ENV_DIR - - helm dependency update - - > - helm upgrade $GC_SERVICE-env . - --install - --create-namespace - --namespace=$GC_HELM_NAMESPACE - --wait - --history-max=3 - --set postgresql.global.postgresql.auth.postgresPassword=$PASSWORD - --set bootstrap.postgres.image=$CI_REGISTRY_IMAGE/gc-bootstrap-$GC_SERVICE-env:$CI_COMMIT_SHORT_SHA - $GC_HELM_TIMEOUT - rules: - - if: "$CI_COMMIT_BRANCH =~ /^release/" - when: never - - if: "$CI_COMMIT_TAG" - when: never - - if: '$GC == "1"' - when: on_success - -gc-baremetal-deploy: # reuse common deploy job for test deployment - needs: ["gc-baremetal-deploy-test-env", "gc-containerize-gitlab"] - variables: - GC_HELM_NAMESPACE: partition-int-test - GC_TENANT: test - GC_HELM_SETS: >- - --set istio.sidecarInject=false - GC_SA_EMAIL: $GC_SA_GKE_EMAIL - -gc-baremetal-test: - variables: - GC_VENDOR: baremetal - PARTITION_BASE_URL: https://test.ref.gcp.gnrg-osdu.projects.epam.com/ - -gc-baremetal-cleanup-env: # clean-up env after tests - environment: - name: GC_Baremetal - stage: cleanup - extends: .gc-baremetal-variables - id_tokens: - GITLAB_OIDC_TOKEN: - aud: https://iam.googleapis.com/projects/${GC_PROJECT_NUMBER}/locations/global/workloadIdentityPools/${GC_POOL_ID}/providers/${GC_PROVIDER_ID} - image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine - needs: ["gc-baremetal-test"] - tags: ["osdu-small"] - variables: - PARTITION_NAMESPACE: partition-test - GC_HELM_NAMESPACE: partition-int-test - GC_SA_EMAIL: $GC_SA_GKE_EMAIL - script: - - !reference [.gc_obtain_credentials, script] - - !reference [.gc_common_config, script] - - chmod +x devops/gc/tests/clean_up/clean_up.sh && devops/gc/tests/clean_up/clean_up.sh --cluster - rules: - - if: "$CI_COMMIT_BRANCH =~ /^release/" - when: never - - if: "$CI_COMMIT_TAG" - when: never - - if: '$GC == "1"' - when: always - -gc-baremetal-verified-deploy: # verified deploy after tests - extends: gc-baremetal-deploy - stage: verified-deploy - needs: ["gc-baremetal-test"] - variables: - GC_HELM_NAMESPACE: default - GC_TENANT: osdu - # if parameter is not necessary define the GC_HELM_SETS as blank - GC_HELM_SETS: "--set data.indexerAugmenterEnabled=true" - # Dev2 jobs gc-dev2-deploy: # reuse common deploy job for test deployment variables: GC_HELM_NAMESPACE: partition-int-test GC_HELM_SETS: >- - --set data.dataPartitionId=test + --set global.dataPartitionId=test --set data.partitionNamespace=partition-test --set istio.sidecarInject=false --set data.edsEnabled=true @@ -234,5 +156,5 @@ gc-preship-deploy: needs: ["gc-dev2-verified-deploy", "gc-dev2-test"] variables: GC_HELM_SETS: >- - --set data.dataPartitionId=m19 + --set global.dataPartitionId=m19 --set data.edsEnabled=true diff --git a/partition-core-plus/pom.xml b/partition-core-plus/pom.xml index 3c99789c9a55cfe538766a100c8ae184cc73b233..59fa6556ef8262012272b002b978b3997fda657b 100644 --- a/partition-core-plus/pom.xml +++ b/partition-core-plus/pom.xml @@ -54,11 +54,10 @@ <version>0.28.0-SNAPSHOT</version> <scope>compile</scope> </dependency> - <!-- Mapper\Driver core dependencies --> <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>os-osm-core</artifactId> - <version>0.26.0</version> + <version>0.27.0-rc2</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> diff --git a/pom.xml b/pom.xml index afb5d6eb113552e2a750b63c1ea7ef32800aea04..b4e67423d3006a5a871ff55b0ddc3789774ed4b4 100644 --- a/pom.xml +++ b/pom.xml @@ -116,7 +116,7 @@ <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> - <version>1.18.8</version> + <version>1.18.34</version> <scope>provided</scope> </dependency> </dependencies> diff --git a/provider/partition-gc/README.md b/provider/partition-gc/README.md index 00580fc34ecfbe95f2ec1cc4866d560bfffc15c1..5ae567004bffcface94e3f437c2b051e5deceba0 100644 --- a/provider/partition-gc/README.md +++ b/provider/partition-gc/README.md @@ -37,10 +37,6 @@ Pre-requisites * Lombok 1.18 or later * [Maven 3.8.0+](https://maven.apache.org/download.cgi) -### Baremetal Service Configuration - -[Baremetal service configuration](docs/baremetal/README.md) - ### Google Cloud Service Configuration [Google Cloud service configuration](docs/gc/README.md) @@ -134,9 +130,6 @@ $ (cd testing/partition-test-core/ && mvn clean install) This section describes how to run cloud OSDU E2E tests. -### Baremetal test configuration - -[Baremetal service configuration](docs/baremetal/README.md) ### Google Cloud test configuration @@ -144,7 +137,7 @@ This section describes how to run cloud OSDU E2E tests. ## Deployment -Partition Service is compatible with App Engine Flexible Environment and Cloud Run. +Partition Service is compatible with App Engine Flexible Environment, Cloud Run, K8s. * To deploy into Cloud run, please, use this documentation: <https://cloud.google.com/run/docs/quickstarts/build-and-deploy> diff --git a/provider/partition-gc/cloudbuild/Dockerfile.cloudbuild b/provider/partition-gc/cloudbuild/Dockerfile.cloudbuild index 211182e441577089d517bbb1bf994eef2755b09c..9672e045b59d6fce8e7889f4b98bc9b9902bd20c 100644 --- a/provider/partition-gc/cloudbuild/Dockerfile.cloudbuild +++ b/provider/partition-gc/cloudbuild/Dockerfile.cloudbuild @@ -4,6 +4,11 @@ ARG PROVIDER_NAME ENV PROVIDER_NAME $PROVIDER_NAME ARG PORT ENV PORT $PORT + +ENV LOADER_PATH="gc/" + +COPY tmp-gc/gc-osm-datastore-*.jar gc/osm-datastore.jar + # Copy the jar to the production image from the builder stage. COPY provider/partition-${PROVIDER_NAME}/target/partition-${PROVIDER_NAME}-*-spring-boot.jar partition-${PROVIDER_NAME}.jar # Add a non-root user @@ -12,4 +17,10 @@ RUN groupadd -g 10001 -r nonroot \ # Run as non-root user USER 10001:10001 # Run the web service on container startup. -CMD java -Djava.security.egd=file:/dev/./urandom -Dserver.port=${PORT} -Dlog4j.formatMsgNoLookups=true -jar /app/partition-${PROVIDER_NAME}.jar +CMD java --add-opens java.base/java.lang=ALL-UNNAMED \ + --add-opens java.base/java.lang.reflect=ALL-UNNAMED \ + -Djava.security.egd=file:/dev/./urandom \ + -Dserver.port=${PORT} \ + -Dlog4j.formatMsgNoLookups=true \ + -Dloader.main=org.opengroup.osdu.partition.provider.gcp.PartitionGcpApplication \ + -jar /app/partition-${PROVIDER_NAME}.jar diff --git a/provider/partition-gc/docs/baremetal/README.md b/provider/partition-gc/docs/baremetal/README.md deleted file mode 100644 index 07e409741396aa06b5ad35d0be65c18ad7728ae4..0000000000000000000000000000000000000000 --- a/provider/partition-gc/docs/baremetal/README.md +++ /dev/null @@ -1,89 +0,0 @@ -# Service Configuration for Baremetal - -## Environment variables - -Define the following environment variables. - -Must have: - -| name | value | description | sensitive? | source | -|--------------------------|------------------------------------------------|------------------------------------------------------------------------------|------------|--------| -| `SPRING_PROFILES_ACTIVE` | ex `anthos` | Spring profile that activate default configuration for Baremetal environment | false | - | -| `OSM_POSTGRES_URL` | ex `jdbc:postgresql://127.0.0.1:5432/postgres` | Postgres server URL | no | - | -| `OSM_POSTGRES_USERNAME` | ex `postgres` | Postgres admin username | no | - | -| `OSM_POSTGRES_PASSWORD` | ex `postgres` | Postgres admin password | yes | - | - -Defined in default application property file but possible to override: - -| name | value | description | sensitive? | source | -|-----------------------------|------------------------|------------------------------------|------------|--------| -| `LOG_LEVEL` | `****` | Logging level | no | - | -| `LOG_PREFIX` | `service` | Logging prefix | no | - | -| `SERVER_SERVLET_CONTEXPATH` | `/api/partition/v1` | Servlet context path | no | - | -| `PARTITION_PROPERTY_KIND` | ex `PartitionProperty` | Kind name to store the properties. | no | - | -| `PARTITION_NAMESPACE` | ex `partition` | Namespace for database. | no | - | -| `PARTITION_NAMESPACE` | ex `partition` | Namespace for database. | no | - | -| `SYSTEM_PARTITION_ID` | ex `syspartition` | Name of system partition. | yes | - | -| `SYSTEM_TENANT_API` | ex `true` | Enables system API | no | - | - -These variables define service behavior, and are used to switch between `baremetal` or `gcp` environments, their overriding and usage in mixed mode was not tested. -Usage of spring profiles is preferred. - -| `OSMDRIVER` | ex `postgres` or `datastore` | Osm driver mode that defines which storage will be used | no | - | -| `ENVIRONMENT` | `gcp` or `anthos` | If `anthos` then authorization is disabled | no | - | - -### for OSM - Postgres - -### Schema configuration - -```sql -CREATE TABLE partition."PartitionProperty"( -id text COLLATE pg_catalog."default" NOT NULL, -pk bigint NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY, -data jsonb NOT NULL, -CONSTRAINT PartitionProperty_id UNIQUE (id) -); -CREATE INDEX PartitionProperty_dataGin ON partition."PartitionProperty" USING GIN (data); - -``` - -### Running E2E Tests - -You will need to have the following environment variables defined. - -| name | value | description | sensitive? | source | -|------------------------------------------------|-----------------------------------------|-----------------------------------------------|---------------------------------------------------|--------| -| `ENVIRONMENT` | ex `dev` | | no | | -| `PARTITION_BASE_URL` | ex `http://localhost:8080/` | service base URL | yes | | -| `CLIENT_TENANT` | ex `opendes` | name of the client partition | yes | | -| `MY_TENANT` | ex `opendes` | name of the OSDU partition | yes | | -| `TEST_OPENID_PROVIDER_CLIENT_ID` | `********` | Client Id for `$INTEGRATION_TESTER` | yes | -- | -| `TEST_OPENID_PROVIDER_CLIENT_SECRET` | `********` | | Client secret for `$INTEGRATION_TESTER` | -- | -| `TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_ID` | `********` | Client Id for `$NO_ACCESS_INTEGRATION_TESTER` | yes | -- | -| `TEST_NO_ACCESS_OPENID_PROVIDER_CLIENT_SECRET` | `********` | | Client secret for `$NO_ACCESS_INTEGRATION_TESTER` | -- | -| `TEST_OPENID_PROVIDER_URL` | `https://keycloak.com/auth/realms/osdu` | OpenID provider url | yes | -- | - -Execute following command to build code and run all the integration tests: - -```bash -# Note: this assumes that the environment variables for integration tests as outlined -# above are already exported in your environment. -$ (cd testing/partition-test-baremetal/ && mvn clean test) -``` - -## License - -Copyright © Google LLC -Copyright © EPAM Systems - -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](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. diff --git a/provider/partition-gc/docs/gc/README.md b/provider/partition-gc/docs/gc/README.md index 75423ed9b86c7441139241ba29e0366f9409c4b1..85f302a5bb4194da1993e6c3319b33a73527f874 100644 --- a/provider/partition-gc/docs/gc/README.md +++ b/provider/partition-gc/docs/gc/README.md @@ -28,7 +28,6 @@ Defined in default application property file but possible to override: These variables define service behavior, and are used to switch between `baremetal` or `gc` environments, their overriding and usage in mixed mode was not tested. Usage of spring profiles is preferred. -| `OSMDRIVER` | ex `postgres` or `datastore` | Osm driver mode that defines which storage will be used | no | - | | `ENVIRONMENT` | `gcp` or `anthos` | If `anthos` then authorization is disabled | no | - | ### Running E2E Tests @@ -57,8 +56,8 @@ $ (cd testing/partition-test-gc/ && mvn clean test) TBD | Required roles | -| --- | -| - | +|----------------| +| - | ## License diff --git a/provider/partition-gc/pom.xml b/provider/partition-gc/pom.xml index 2bc68d3c8f5872d4c290d9e3f79634df62bbdeab..12b6a9c4a4269a8cd4ab917e626e9270837cda7e 100644 --- a/provider/partition-gc/pom.xml +++ b/provider/partition-gc/pom.xml @@ -42,69 +42,20 @@ </dependencyManagement> <dependencies> - <!-- Internal packages --> <dependency> <groupId>org.opengroup.osdu</groupId> - <artifactId>core-lib-gc</artifactId> - <version>0.27.0-rc7</version> - </dependency> - <dependency> - <groupId>org.opengroup.osdu</groupId> - <artifactId>partition-core</artifactId> + <artifactId>partition-core-plus</artifactId> <version>0.28.0-SNAPSHOT</version> </dependency> - - <!-- Mappers --> - <dependency> - <groupId>org.opengroup.osdu</groupId> - <artifactId>osm</artifactId> - <version>0.26.0</version> - </dependency> - - <!-- Third party Apache 2.0 license packages --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.security</groupId> - <artifactId>spring-security-oauth2-client</artifactId> - </dependency> - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - </dependency> <dependency> <groupId>ch.qos.logback.contrib</groupId> <artifactId>logback-json-classic</artifactId> <version>0.1.5</version> </dependency> <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>2.10.1</version> - </dependency> - - <!-- Testing packages --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.springframework.security</groupId> - <artifactId>spring-security-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.opengroup.osdu</groupId> - <artifactId>osm</artifactId> - <version>0.26.0</version> - </dependency> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> + <groupId>ch.qos.logback.contrib</groupId> + <artifactId>logback-jackson</artifactId> + <version>0.1.5</version> </dependency> </dependencies> @@ -121,7 +72,7 @@ </goals> <configuration> <classifier>spring-boot</classifier> - <mainClass>org.opengroup.osdu.partition.provider.gcp.PartitionGcpApplication + <mainClass>org.springframework.boot.loader.launch.PropertiesLauncher </mainClass> </configuration> </execution> diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/PartitionGcpApplication.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/PartitionGcpApplication.java index 4a0c9ad06b128852a86a2375f3cbc87e225d70a6..f5bf847f3652f1ecd3be647e21822b128b536699 100644 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/PartitionGcpApplication.java +++ b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/PartitionGcpApplication.java @@ -1,19 +1,19 @@ /* - Copyright 2002-2021 Google LLC - Copyright 2002-2021 EPAM Systems, Inc + Copyright 2002-2024 Google LLC + Copyright 2002-2024 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 + 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 + 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. - */ + 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.partition.provider.gcp; diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/cache/VmCacheConfiguration.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/cache/VmCacheConfiguration.java deleted file mode 100644 index 362dce796f8d4390c1f7117a1de027ea8ba33013..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/cache/VmCacheConfiguration.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright 2002-2021 Google LLC - Copyright 2002-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 - - 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.partition.provider.gcp.cache; - -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.opengroup.osdu.core.common.cache.VmCache; -import org.opengroup.osdu.partition.model.PartitionInfo; -import org.opengroup.osdu.partition.provider.gcp.config.PropertiesConfiguration; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -@RequiredArgsConstructor -public class VmCacheConfiguration { - - private final PropertiesConfiguration properties; - - @Bean(name = "partitionListCache") - public VmCache<String, List<String>> partitionListCache() { - return new VmCache<>(this.properties.getCacheExpiration() * 60, - this.properties.getCacheMaxSize()); - } - - @ConfigurationProperties - @Bean(name = "partitionServiceCache") - public VmCache<String, PartitionInfo> partitionServiceCache() { - return new VmCache<>(this.properties.getCacheExpiration() * 60, - this.properties.getCacheMaxSize()); - } -} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/DefaultApiConfiguration.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/DefaultApiConfiguration.java index bb328709fdbf1886e045fd74814faa797799cfab..81376aa258e55295d67f48b0cd663bd652ec27ca 100644 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/DefaultApiConfiguration.java +++ b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/DefaultApiConfiguration.java @@ -19,25 +19,17 @@ package org.opengroup.osdu.partition.provider.gcp.config; import static org.opengroup.osdu.partition.provider.gcp.config.SystemApiConfiguration.PARTITION_SYSTEM_TENANT_API; -import org.opengroup.osdu.core.di.GcpPartitionClientFactory; -import org.opengroup.osdu.core.gcp.osm.translate.datastore.DsTenantOsmDestinationResolver; -import org.opengroup.osdu.core.gcp.osm.translate.postgresql.PgTenantOsmDestinationResolver; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.FilterType; /** * Configuration that loads default PartitionController, used when SystemPartitionApi is disabled. */ @Configuration -@ConditionalOnProperty(name = PARTITION_SYSTEM_TENANT_API, havingValue = "false", matchIfMissing = true) -@ComponentScan(basePackages = {"org.opengroup.osdu"}, excludeFilters = -@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { - GcpPartitionClientFactory.class, - PgTenantOsmDestinationResolver.class, - DsTenantOsmDestinationResolver.class}) -) -public class DefaultApiConfiguration { - -} +@ConditionalOnProperty( + name = PARTITION_SYSTEM_TENANT_API, + havingValue = "false", + matchIfMissing = true) +@ComponentScan(basePackages = {"org.opengroup.osdu"}) +public class DefaultApiConfiguration {} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/IDTokenVerifierConfiguration.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/IDTokenVerifierConfiguration.java index 6098a82c6b3d54a2b57e4cf0b08340630defc001..1094dc8d8ae9ec62723c87685c3f1729f88087ca 100644 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/IDTokenVerifierConfiguration.java +++ b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/IDTokenVerifierConfiguration.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.security.GeneralSecurityException; import java.util.Collections; import lombok.RequiredArgsConstructor; +import org.opengroup.osdu.partition.coreplus.config.PropertiesConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/PostgresOsmConfiguration.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/PostgresOsmConfiguration.java deleted file mode 100644 index 755ceaba598d352540e4f8da0655ba49cc3077c2..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/PostgresOsmConfiguration.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2020-2021 Google LLC - * Copyright 2020-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 - * - * 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.partition.provider.gcp.config; - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -@Primary -@Configuration -@ConditionalOnProperty(name = "osmDriver", havingValue = "postgres") -@ConfigurationProperties(prefix = "osm.postgres") -@Getter -@Setter -public class PostgresOsmConfiguration { - - private String url; - private String username; - private String password; - - private Integer maximumPoolSize = 40; - private Integer minimumIdle = 0; - private Integer idleTimeout = 30000; - private Integer maxLifetime = 1800000; - private Integer connectionTimeout = 30000; - -} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/PropertiesConfiguration.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/PropertiesConfiguration.java deleted file mode 100644 index 6b19ee5a8b097ffff2418f75200ff64aadb50a42..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/PropertiesConfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright 2002-2023 Google LLC - Copyright 2002-2023 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 - - 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.partition.provider.gcp.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties -@Data -public class PropertiesConfiguration { - - private String googleCloudProject; - - private int cacheExpiration; - - private int cacheMaxSize; - - private String partitionPropertyKind; - - private String partitionNamespace; - -} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/SystemApiConfiguration.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/SystemApiConfiguration.java index 83ec283bc9825c7c262a31d1c70e1187a2455525..a1b5352b29ad34b95e1f4f2528ee974b7ce759c6 100644 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/SystemApiConfiguration.java +++ b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/config/SystemApiConfiguration.java @@ -19,48 +19,41 @@ package org.opengroup.osdu.partition.provider.gcp.config; import lombok.Getter; import lombok.Setter; -import org.opengroup.osdu.core.di.GcpPartitionClientFactory; -import org.opengroup.osdu.core.gcp.osm.translate.datastore.DsTenantOsmDestinationResolver; -import org.opengroup.osdu.core.gcp.osm.translate.postgresql.PgTenantOsmDestinationResolver; +import org.opengroup.osdu.partition.coreplus.PartitionApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.FilterType; -import org.springframework.context.annotation.PropertySource; +import org.springframework.context.annotation.*; /** - * Configuration that will not load original PartitionController into context, allowing its override in PartitionControllerV2 + * Configuration that will not load original PartitionController into context, allowing its override + * in PartitionControllerV2 */ @Getter @Setter @Configuration @ConfigurationProperties -@ConditionalOnProperty(name = SystemApiConfiguration.PARTITION_SYSTEM_TENANT_API, havingValue = "true") +@ConditionalOnProperty( + name = SystemApiConfiguration.PARTITION_SYSTEM_TENANT_API, + havingValue = "true") @PropertySource({"classpath:swaggerV2.properties"}) -@ComponentScan(basePackages = {"org.opengroup.osdu"}, excludeFilters = - {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { - GcpPartitionClientFactory.class, - PgTenantOsmDestinationResolver.class, - DsTenantOsmDestinationResolver.class, - }), - @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.opengroup.osdu.partition.controller.PartitionController")} -) +@ComponentScan( + basePackages = {"org.opengroup.osdu"}, + excludeFilters = { + @ComponentScan.Filter( + type = FilterType.ASSIGNABLE_TYPE, + classes = {PartitionApplication.class}), + @ComponentScan.Filter( + type = FilterType.REGEX, + pattern = "org.opengroup.osdu.partition.controller.PartitionController") + }) public class SystemApiConfiguration { - /** - * The name of the property to enable the partition system tenant API. - */ + /** The name of the property to enable the partition system tenant API. */ public static final String PARTITION_SYSTEM_TENANT_API = "system.tenant.api"; - /** - * The identifier of the system partition. - */ + /** The identifier of the system partition. */ private String systemPartitionId = "system"; - /** - * Indicates whether the system partition is listable and its resources are ready. - */ + /** Indicates whether the system partition is listable and its resources are ready. */ private boolean systemPartitionListableAndResourceReady = false; - } diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/formatter/GoogleJsonFormatter.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/formatter/GoogleJsonFormatter.java new file mode 100644 index 0000000000000000000000000000000000000000..ab99241c99cbe9a6adec2c27b46d99dcbaa0be64 --- /dev/null +++ b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/formatter/GoogleJsonFormatter.java @@ -0,0 +1,30 @@ +/* + * Copyright 2020-2024 Google LLC + * Copyright 2020-2024 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 + * + * 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.partition.provider.gcp.formatter; + +import ch.qos.logback.contrib.jackson.JacksonJsonFormatter; +import java.io.IOException; +import java.util.Map; + +public class GoogleJsonFormatter extends JacksonJsonFormatter { + @Override + public String toJsonString(Map map) throws IOException { + map.put("severity", map.remove("level")); + return super.toJsonString(map); + } +} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/model/PartitionPropertyEntity.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/model/PartitionPropertyEntity.java deleted file mode 100644 index 4514b3a7b4eb24546d384db7964f650417df54b8..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/model/PartitionPropertyEntity.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright 2002-2021 Google LLC - Copyright 2002-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 - - 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.partition.provider.gcp.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.opengroup.osdu.partition.model.Property; - -@Data -@AllArgsConstructor -@NoArgsConstructor -public class PartitionPropertyEntity { - - private String id; - - private String partitionId; - - private String name; - - private Boolean sensitive; - - private Object value; - - - public PartitionPropertyEntity(String partitionId, String name, Property property) { - this.id = name + "-" + partitionId; - this.partitionId = partitionId; - this.name = name; - this.sensitive = property.isSensitive(); - this.value = property.getValue(); - } -} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/mapper/TypeMapperImpl.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/mapper/TypeMapperImpl.java deleted file mode 100644 index 04d922610a28b171b86eacd488472171cfe19e19..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/mapper/TypeMapperImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2020-2021 Google LLC - * Copyright 2020-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 - * - * 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.partition.provider.gcp.osm.config.mapper; - -import com.google.cloud.datastore.Key; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import org.opengroup.osdu.core.gcp.osm.persistence.IdentityTranslator; -import org.opengroup.osdu.core.gcp.osm.translate.Instrumentation; -import org.opengroup.osdu.core.gcp.osm.translate.TypeMapper; -import org.opengroup.osdu.partition.provider.gcp.model.PartitionPropertyEntity; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -import java.util.Collections; -import java.util.HashMap; - -import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_SINGLETON; - -@Component -@Scope(SCOPE_SINGLETON) -@ConditionalOnProperty(name = "osmDriver") -public class TypeMapperImpl extends TypeMapper { - public TypeMapperImpl(){ - super(ImmutableList.of( - new Instrumentation<>(PartitionPropertyEntity.class, - new HashMap<String, String>() {{ - put("partitionId", "partition_id"); - }}, - ImmutableMap.of(), - new IdentityTranslator<>( - PartitionPropertyEntity::getId, - (p, o) -> p.setId(((Key)o).getName()) - ), - Collections.singletonList("id") - )) - ); - } -} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/provider/OsmPartitionDestinationProvider.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/provider/OsmPartitionDestinationProvider.java deleted file mode 100644 index 1f5fa5cb98c06668dc606ae561025eb293a87a0b..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/provider/OsmPartitionDestinationProvider.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2020-2021 Google LLC - * Copyright 2020-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 - * - * 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.partition.provider.gcp.osm.config.provider; - -import lombok.RequiredArgsConstructor; -import org.opengroup.osdu.core.gcp.osm.model.Destination; -import org.opengroup.osdu.core.gcp.osm.model.Kind; -import org.opengroup.osdu.core.gcp.osm.model.Namespace; -import org.opengroup.osdu.partition.provider.gcp.config.PropertiesConfiguration; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Service; - -@Primary -@Service -@RequiredArgsConstructor -public class OsmPartitionDestinationProvider { - - private final PropertiesConfiguration config; - - public Destination getDestination() { - return Destination.builder() - .partitionId(config.getGoogleCloudProject()) - .namespace(new Namespace(config.getPartitionNamespace())) - .kind(new Kind(config.getPartitionPropertyKind())) - .build(); - } -} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/resolver/OsmDatastoreDestinationResolver.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/resolver/OsmDatastoreDestinationResolver.java deleted file mode 100644 index 079c26fd426e51c020fb762892188631bed47268..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/resolver/OsmDatastoreDestinationResolver.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020-2021 Google LLC - * Copyright 2020-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 - * - * 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.partition.provider.gcp.osm.config.resolver; - -import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_SINGLETON; - -import com.google.api.gax.retrying.RetrySettings; -import com.google.cloud.TransportOptions; -import com.google.cloud.datastore.Datastore; -import com.google.cloud.datastore.DatastoreOptions; -import com.google.cloud.http.HttpTransportOptions; -import java.io.IOException; -import java.util.Map; -import lombok.RequiredArgsConstructor; -import org.opengroup.osdu.core.gcp.osm.model.Destination; -import org.opengroup.osdu.core.gcp.osm.translate.datastore.DsDestinationResolution; -import org.opengroup.osdu.core.gcp.osm.translate.datastore.DsDestinationResolver; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; -import org.threeten.bp.Duration; - -@Primary -@Component -@Scope(SCOPE_SINGLETON) -@ConditionalOnProperty(name = "osmDriver", havingValue = "datastore") -@RequiredArgsConstructor -public class OsmDatastoreDestinationResolver implements DsDestinationResolver { - - protected static final RetrySettings RETRY_SETTINGS = - RetrySettings.newBuilder().setMaxAttempts(6).setInitialRetryDelay(Duration.ofSeconds(10L)).setMaxRetryDelay(Duration.ofSeconds(32L)) - .setRetryDelayMultiplier(2.0D).setTotalTimeout(Duration.ofSeconds(50L)).setInitialRpcTimeout(Duration.ofSeconds(50L)).setRpcTimeoutMultiplier(1.0D) - .setMaxRpcTimeout(Duration.ofSeconds(50L)).build(); - protected static final TransportOptions TRANSPORT_OPTIONS = HttpTransportOptions.newBuilder().setReadTimeout(30000).build(); - private final Map<String, Datastore> datastoreCache; - - /** - * Takes provided Destination with partitionId set to needed tenantId, returns its TenantInfo.projectId. - * - * @param destination to resolve - * @return resolution results - */ - @Override - public DsDestinationResolution resolve(Destination destination) { - String projectId = destination.getPartitionId(); - Datastore datastore = datastoreCache.computeIfAbsent(projectId, key -> getDatastoreFor(destination, key, projectId)); - - return DsDestinationResolution.builder() - .projectId(datastore.getOptions().getProjectId()) - .datastore(datastore) - .build(); - } - - private Datastore getDatastoreFor(Destination destination, String key, String projectId) { - return DatastoreOptions.newBuilder() - .setRetrySettings(RETRY_SETTINGS) - .setTransportOptions(TRANSPORT_OPTIONS) - .setProjectId(projectId) - .setNamespace(destination.getNamespace().getName()) - .build() - .getService(); - } - - @Override - public void close() throws IOException { - //Method stub - } -} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/resolver/OsmPostgresDestinationResolver.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/resolver/OsmPostgresDestinationResolver.java deleted file mode 100644 index 45ec4e881d2d373cfc8659b2e9cbb4ee96d455d7..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/config/resolver/OsmPostgresDestinationResolver.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2020-2021 Google LLC - * Copyright 2020-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 - * - * 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.partition.provider.gcp.osm.config.resolver; - -import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_SINGLETON; - -import com.zaxxer.hikari.HikariDataSource; -import java.util.HashMap; -import java.util.Map; -import jakarta.annotation.PreDestroy; -import javax.sql.DataSource; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.opengroup.osdu.core.gcp.osm.model.Destination; -import org.opengroup.osdu.core.gcp.osm.translate.postgresql.PgDestinationResolution; -import org.opengroup.osdu.core.gcp.osm.translate.postgresql.PgDestinationResolver; -import org.opengroup.osdu.partition.provider.gcp.config.PostgresOsmConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -@Primary -@Component -@Scope(SCOPE_SINGLETON) -@ConditionalOnProperty(name = "osmDriver", havingValue = "postgres") -@RequiredArgsConstructor -@Slf4j -public class OsmPostgresDestinationResolver implements PgDestinationResolver { - - private final PostgresOsmConfiguration properties; - - private static final String DRIVER_CLASS_NAME = "org.postgresql.Driver"; - - private final Map<String, DataSource> dataSourceCache = new HashMap<>(); - - @Override - public PgDestinationResolution resolve(Destination destination) { - - String partitionId = destination.getPartitionId(); - - DataSource dataSource = dataSourceCache.get(partitionId); - if (dataSource == null || (dataSource instanceof HikariDataSource && ((HikariDataSource) dataSource).isClosed())) { - synchronized (dataSourceCache) { - dataSource = dataSourceCache.get(partitionId); - if (dataSource == null || (dataSource instanceof HikariDataSource && ((HikariDataSource) dataSource).isClosed())) { - dataSource = buildDataSourceFromProperties(partitionId); - } - } - } - - return PgDestinationResolution.builder() - .datasource(dataSource) - .build(); - } - - private DataSource buildDataSourceFromProperties(String partitionId) { - DataSource dataSource; - dataSource = DataSourceBuilder.create() - .driverClassName(DRIVER_CLASS_NAME) - .url(properties.getUrl()) - .username(properties.getUsername()) - .password(properties.getPassword()) - .build(); - - HikariDataSource hikariDataSource = (HikariDataSource) dataSource; - hikariDataSource.setMaximumPoolSize(properties.getMaximumPoolSize()); - hikariDataSource.setMinimumIdle(properties.getMinimumIdle()); - hikariDataSource.setIdleTimeout(properties.getIdleTimeout()); - hikariDataSource.setMaxLifetime(properties.getMaxLifetime()); - hikariDataSource.setConnectionTimeout(properties.getConnectionTimeout()); - - dataSourceCache.put(partitionId, dataSource); - return dataSource; - } - - @PreDestroy - @Override - public void close() { - log.info("On pre-destroy. {} DataSources to shutdown", dataSourceCache.size()); - for (DataSource dataSource : dataSourceCache.values()) { - if (dataSource instanceof HikariDataSource && !((HikariDataSource) dataSource).isClosed()) { - ((HikariDataSource) dataSource).close(); - } - } - } -} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/repository/OsmPartitionPropertyRepository.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/repository/OsmPartitionPropertyRepository.java deleted file mode 100644 index 5e6621293bcf0a08d08ab6639849484c428411c4..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/osm/repository/OsmPartitionPropertyRepository.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2020-2021 Google LLC - * Copyright 2020-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 - * - * 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.partition.provider.gcp.osm.repository; - - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.core.gcp.osm.model.Destination; -import org.opengroup.osdu.core.gcp.osm.model.query.GetQuery; -import org.opengroup.osdu.core.gcp.osm.model.where.Where; -import org.opengroup.osdu.core.gcp.osm.service.Context; -import org.opengroup.osdu.core.gcp.osm.service.Transaction; -import org.opengroup.osdu.core.gcp.osm.translate.TranslatorException; -import org.opengroup.osdu.partition.provider.gcp.model.PartitionPropertyEntity; -import org.opengroup.osdu.partition.provider.gcp.osm.config.provider.OsmPartitionDestinationProvider; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.opengroup.osdu.core.gcp.osm.model.where.predicate.Eq.eq; -import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; - -@Slf4j -@Service -@RequiredArgsConstructor -@ConditionalOnProperty("osmDriver") -public class OsmPartitionPropertyRepository { - - public static final String PARTITION_ID_FILED = "partition_id"; - public static final String PROPERTY_ID = "id"; - private final OsmPartitionDestinationProvider osmPartitionDestinationProvider; - private final Context context; - - - public Optional<List<PartitionPropertyEntity>> findByPartitionId(String partitionId) { - List<PartitionPropertyEntity> properties = - context.getResultsAsList(buildPartitionEntityQueryBy(eq(PARTITION_ID_FILED, partitionId))); - return (CollectionUtils.isEmpty(properties)) ? - Optional.empty(): - Optional.of(properties); - } - - public PartitionPropertyEntity findByPartitionIdAndName(String partitionId, String key) { - return context.getOne(buildPartitionEntityQueryBy(eq(PROPERTY_ID, partitionId + "-" + key))); - } - - public List<String> getAllPartitions() { - return context.getResultsAsList( - new GetQuery<>(PartitionPropertyEntity.class, osmPartitionDestinationProvider.getDestination())) - .stream() - .map(PartitionPropertyEntity::getPartitionId) - .distinct() - .collect(Collectors.toList()); - } - - public void deleteByPartitionId(String partitionId) { - Destination destination = osmPartitionDestinationProvider.getDestination(); - Transaction tx = null; - try{ - - tx = context.beginTransaction(destination); - - context.delete( - PartitionPropertyEntity.class, - osmPartitionDestinationProvider.getDestination(), - eq(PARTITION_ID_FILED, partitionId)); - - tx.commitIfActive(); - } catch (TranslatorException e) { - log.error("Error during partition delete", e); - throw new AppException( - INTERNAL_SERVER_ERROR.value(), - INTERNAL_SERVER_ERROR.getReasonPhrase(), - "Error during partition delete"); - } finally { - if (ObjectUtils.isNotEmpty(tx)){ - tx.rollbackIfActive(); - } - } - } - - public void saveAll(List<PartitionPropertyEntity> partitionProperties) { - Destination destination = osmPartitionDestinationProvider.getDestination(); - Transaction tx = null; - try{ - tx = context.beginTransaction(destination); - for (PartitionPropertyEntity entity : partitionProperties){ - context.upsert(entity, destination); - } - tx.commitIfActive(); - } - finally { - if (ObjectUtils.isNotEmpty(tx)){ - tx.rollbackIfActive(); - } - } - } - - private GetQuery<PartitionPropertyEntity> buildPartitionEntityQueryBy(Where where){ - return new GetQuery<>(PartitionPropertyEntity.class, osmPartitionDestinationProvider.getDestination(), where); - } -} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/SecurityConfigGcp.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/SecurityConfigGcp.java deleted file mode 100644 index e4753acf3667010b3371ca743697a9a60b62a595..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/security/SecurityConfigGcp.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright 2002-2021 Google LLC - Copyright 2002-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 - - 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.partition.provider.gcp.security; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; -import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; -import org.springframework.security.web.SecurityFilterChain; -import static org.springframework.security.config.Customizer.withDefaults; - -@EnableWebSecurity -@Configuration -@EnableMethodSecurity -public class SecurityConfigGcp { - - @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - http - .csrf(AbstractHttpConfigurer::disable) - .authorizeHttpRequests(authorize -> authorize.anyRequest().permitAll()) - .httpBasic(withDefaults()); - return http.build(); - } - - @Bean - public WebSecurityCustomizer webSecurityCustomizer() { - return (web) -> web.ignoring().requestMatchers("/index", "/swagger"); - } -} diff --git a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImpl.java b/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImpl.java deleted file mode 100644 index 80ea2b411e620b4ace400be6d82fafbdb91f376e..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImpl.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2020-2023 Google LLC - * Copyright 2020-2023 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 - * - * 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.partition.provider.gcp.service; - -import lombok.RequiredArgsConstructor; -import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.common.cache.ICache; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.partition.logging.AuditLogger; -import org.opengroup.osdu.partition.model.PartitionInfo; -import org.opengroup.osdu.partition.model.Property; -import org.opengroup.osdu.partition.provider.gcp.config.PropertiesConfiguration; -import org.opengroup.osdu.partition.provider.gcp.model.PartitionPropertyEntity; -import org.opengroup.osdu.partition.provider.gcp.osm.repository.OsmPartitionPropertyRepository; -import org.opengroup.osdu.partition.provider.interfaces.IPartitionService; -import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; - -import java.util.*; - -@Service -@RequiredArgsConstructor -public class PartitionServiceImpl implements IPartitionService { - - static final String UNKNOWN_ERROR_REASON = "unknown error"; - static final String PARTITION_LIST_KEY = "getAllPartitions"; - - private final OsmPartitionPropertyRepository partitionPropertyEntityRepository; - - private final AuditLogger auditLogger; - - private final ICache<String, PartitionInfo> partitionServiceCache; - - private final ICache<String, List<String>> partitionListCache; - - private final PropertiesConfiguration propertiesConfiguration; - - @Override - public PartitionInfo createPartition(String partitionId, PartitionInfo partitionInfo) { - if (partitionServiceCache.get(partitionId) != null) - throw new AppException(HttpStatus.SC_CONFLICT, "partition exist", "Partition with same id exist"); - - if (this.partitionPropertyEntityRepository.findByPartitionId(partitionId).isPresent()) { - this.auditLogger.createPartitionFailure(Collections.singletonList(partitionId)); - throw new AppException(HttpStatus.SC_CONFLICT, UNKNOWN_ERROR_REASON, - "Partition already exists."); - } - List<PartitionPropertyEntity> partitionProperties = new ArrayList<>(); - for (Map.Entry<String, Property> entry : partitionInfo.getProperties().entrySet()) { - PartitionPropertyEntity entity = new PartitionPropertyEntity(partitionId, - entry.getKey(), entry.getValue()); - partitionProperties.add(entity); - } - this.partitionPropertyEntityRepository.saveAll(partitionProperties); - PartitionInfo pi = getPartition(partitionId); - - if (Objects.nonNull(pi)) { - partitionListCache.clearAll(); - } - - return pi; - } - - @Override - public PartitionInfo updatePartition(String partitionId, PartitionInfo partitionInfo) { - if (partitionInfo.getProperties().containsKey("id")) { - this.auditLogger.updatePartitionSecretFailure(Collections.singletonList(partitionId)); - throw new AppException(HttpStatus.SC_BAD_REQUEST, "can not update id", - "the field id can not be updated"); - } - - if (!this.partitionPropertyEntityRepository.findByPartitionId(partitionId).isPresent()) { - this.auditLogger.updatePartitionSecretFailure(Collections.singletonList(partitionId)); - throw new AppException(HttpStatus.SC_NOT_FOUND, UNKNOWN_ERROR_REASON, - "An attempt to update not existing partition."); - } - - List<PartitionPropertyEntity> partitionProperties = new ArrayList<>(); - for (Map.Entry<String, Property> entry : partitionInfo.getProperties().entrySet()) { - PartitionPropertyEntity entity = this.partitionPropertyEntityRepository - .findByPartitionIdAndName(partitionId, entry.getKey()); - if (Objects.nonNull(entity)) { - entity.setSensitive(entry.getValue().isSensitive()); - entity.setValue(entry.getValue().getValue()); - } else { - entity = new PartitionPropertyEntity(partitionId, entry.getKey(), entry.getValue()); - } - partitionProperties.add(entity); - } - this.partitionPropertyEntityRepository.saveAll(partitionProperties); - if (Objects.nonNull(partitionServiceCache.get(partitionId))) { - partitionServiceCache.delete(partitionId); - } - - return getPartition(partitionId); - } - - @Override - public PartitionInfo getPartition(String partitionId) { - PartitionInfo pi = partitionServiceCache.get(partitionId); - - if (Objects.isNull(pi)) { - pi = getPartitionFromRepo(partitionId); - partitionServiceCache.put(partitionId, pi); - } - - return pi; - } - - private PartitionInfo getPartitionFromRepo(String partitionId) { - Optional<List<PartitionPropertyEntity>> partitionPropertyEntitiesOptional = partitionPropertyEntityRepository - .findByPartitionId(partitionId); - if (!partitionPropertyEntitiesOptional.isPresent()) { - this.auditLogger.readPartitionFailure(Collections.singletonList(partitionId)); - throw new AppException(HttpStatus.SC_NOT_FOUND, UNKNOWN_ERROR_REASON, - "Partition does not exist."); - } - List<PartitionPropertyEntity> partitionPropertiesList = partitionPropertyEntitiesOptional.get(); - PartitionInfo partitionInfo = new PartitionInfo(); - Map<String, Property> partitionInfoProperties = new HashMap<>(); - for (PartitionPropertyEntity entity : partitionPropertiesList) { - partitionInfoProperties - .put(entity.getName(), new Property(entity.getSensitive(), entity.getValue())); - } - partitionInfo.setProperties(partitionInfoProperties); - - return partitionInfo; - } - - @Override - public boolean deletePartition(String partitionId) { - if (!this.partitionPropertyEntityRepository.findByPartitionId(partitionId).isPresent()) { - this.auditLogger.deletePartitionFailure(Collections.singletonList(partitionId)); - throw new AppException(HttpStatus.SC_NOT_FOUND, UNKNOWN_ERROR_REASON, - "An attempt to delete not existing partition."); - } - this.partitionPropertyEntityRepository.deleteByPartitionId(partitionId); - - if (Objects.nonNull(partitionServiceCache.get(partitionId))) { - partitionServiceCache.delete(partitionId); - } - partitionListCache.clearAll(); - return true; - } - - @Override - public List<String> getAllPartitions() { - List<String> partitions = partitionListCache.get(PARTITION_LIST_KEY); - - if (Objects.isNull(partitions)) { - List<String> allPartitions = this.partitionPropertyEntityRepository.getAllPartitions(); - partitions = (allPartitions.isEmpty() ? Collections.emptyList() : allPartitions); - if (!CollectionUtils.isEmpty(partitions)) { - partitionListCache.put(PARTITION_LIST_KEY, partitions); - } - } - return partitions; - } -} diff --git a/provider/partition-gc/src/main/resources/application-anthos.properties b/provider/partition-gc/src/main/resources/application-anthos.properties deleted file mode 100644 index a102b17ee480f54095eb3047ba25285ad74a4032..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/main/resources/application-anthos.properties +++ /dev/null @@ -1,25 +0,0 @@ -# -# Copyright 2020-2022 Google LLC -# Copyright 2020-2022 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. -# - -osmDriver=postgres -environment=anthos -osm.postgres.url=jdbc:postgresql://127.0.0.1:5432/postgres -osm.postgres.username=postgres -osm.postgres.password=postgres -#stub value, not used on anthos, but will cause NPE if not set -google-cloud-project=anthos -system.tenant.api=${SYSTEM_TENANT_API:false} diff --git a/provider/partition-gc/src/main/resources/application-gcp.properties b/provider/partition-gc/src/main/resources/application-gcp.properties index c3264888cd42c34f50e316b4c868fbbcef9b087c..6f21abf1fe366d02705a9274dcd854359001f4f1 100644 --- a/provider/partition-gc/src/main/resources/application-gcp.properties +++ b/provider/partition-gc/src/main/resources/application-gcp.properties @@ -15,6 +15,5 @@ # limitations under the License. # -osmDriver=datastore environment=gcp google-cloud-project=${GOOGLE_CLOUD_PROJECT} diff --git a/provider/partition-gc/src/main/resources/application.properties b/provider/partition-gc/src/main/resources/application.properties index 8bbe714f5a02e1db63a40da3d571c5306f7f3427..b871a5f060923e8dde8ed415c92a86c297b0c2e9 100644 --- a/provider/partition-gc/src/main/resources/application.properties +++ b/provider/partition-gc/src/main/resources/application.properties @@ -1,6 +1,6 @@ # -# Copyright 2020-2022 Google LLC -# Copyright 2020-2022 EPAM Systems, Inc +# Copyright 2020-2024 Google LLC +# Copyright 2020-2024 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. @@ -32,8 +32,13 @@ cache-expiration=1 cache-maxSize=1000 #service config +destination.resolver=property partition-property-kind=PartitionProperty partition-namespace=partition +dataPartitionId = ${DATA_PARTITION_ID:test-partition} +environment=gcp + +#System endpoint system.tenant.api=${SYSTEM_TENANT_API:true} system-partition-id=${SYSTEM_PARTITION_ID:system} system-partition-listable-and-resource-ready=${SYSTEM_PARTITION_LISTABLE_AND_RESOURCE_READY:false} diff --git a/provider/partition-gc/src/main/resources/logback.xml b/provider/partition-gc/src/main/resources/logback.xml index a67f87124e3484f2eda2acc19da68e232cfbf6db..90b1856ddb0899bc8be01f3cc3c24e9f7e6be669 100644 --- a/provider/partition-gc/src/main/resources/logback.xml +++ b/provider/partition-gc/src/main/resources/logback.xml @@ -1,37 +1,39 @@ <?xml version="1.0" encoding="UTF-8"?> <configuration> - <include resource="org/springframework/boot/logging/logback/defaults.xml"/> - <logger name="org.opengroup.osdu" level="${LOG_LEVEL}"/> - <springProfile name="local"> - <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> - <encoder> - <pattern>%yellow([%thread]) %highlight(| %-5level |) %green(%d) %cyan(| %logger{15} |) %highlight(%msg) %n</pattern> - <charset>utf8</charset> - </encoder> - </appender> - <root level="info"> - <appender-ref ref="CONSOLE"/> - </root> - </springProfile> + <include resource="org/springframework/boot/logging/logback/defaults.xml"/> + <logger name="org.opengroup.osdu" level="${LOG_LEVEL}"/> + <springProfile name="local"> + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%yellow([%thread]) %highlight(| %-5level |) %green(%d) %cyan(| %logger{15} |) %highlight(%msg) + %n + </pattern> + <charset>utf8</charset> + </encoder> + </appender> + <root level="info"> + <appender-ref ref="CONSOLE"/> + </root> + </springProfile> - <springProfile name="!local"> - <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> - <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> - <layout class="ch.qos.logback.contrib.json.classic.JsonLayout"> - <timestampFormat>yyyy-MM-dd HH:mm:ss.SSS</timestampFormat> - <timestampFormatTimezoneId>Etc/UTC</timestampFormatTimezoneId> - <appendLineSeparator>true</appendLineSeparator> + <springProfile name="!local"> + <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> + <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> + <layout class="ch.qos.logback.contrib.json.classic.JsonLayout"> + <timestampFormat>yyyy-MM-dd HH:mm:ss.SSS</timestampFormat> + <timestampFormatTimezoneId>Etc/UTC</timestampFormatTimezoneId> + <appendLineSeparator>true</appendLineSeparator> - <jsonFormatter class="org.opengroup.osdu.core.gcp.logging.formatter.GoogleJsonFormatter"> - <prettyPrint>false</prettyPrint> - </jsonFormatter> - </layout> - </encoder> - </appender> + <jsonFormatter class="org.opengroup.osdu.partition.provider.gcp.formatter.GoogleJsonFormatter"> + <prettyPrint>false</prettyPrint> + </jsonFormatter> + </layout> + </encoder> + </appender> - <root level="info"> - <appender-ref ref="stdout"/> - </root> - </springProfile> + <root level="info"> + <appender-ref ref="stdout"/> + </root> + </springProfile> -</configuration> \ No newline at end of file +</configuration> diff --git a/provider/partition-gc/src/main/resources/type-mapper-config.json b/provider/partition-gc/src/main/resources/type-mapper-config.json new file mode 100644 index 0000000000000000000000000000000000000000..b668c6022ca9d48ac1def564191316184eb4b743 --- /dev/null +++ b/provider/partition-gc/src/main/resources/type-mapper-config.json @@ -0,0 +1,21 @@ +{ + "instrumentations": [ + { + "entityType": "org.opengroup.osdu.partition.coreplus.model.PartitionPropertyEntity", + "fieldNameCustomMapping": { + "partitionId": "partition_id", + "gcsVersionPaths": "bucket" + }, + "fieldTypeCustomMapping": { + }, + "identityTranslator": { + "getIdMethod": "getId", + "setIdMethod": "setId", + "keyClass": "java.lang.String" + }, + "keyFields": [ + "id" + ] + } + ] +} diff --git a/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/controller/PartitionControllerV2Test.java b/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/controller/PartitionControllerV2Test.java deleted file mode 100644 index b68354c14da5bcb158edc9c3ec54d8cb166d4bf2..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/controller/PartitionControllerV2Test.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright 2020-2024 Google LLC - * Copyright 2020-2024 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.partition.provider.gcp.controller; - -import static org.apache.http.HttpStatus.SC_FORBIDDEN; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.junit.jupiter.MockitoExtension; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.partition.logging.AuditLogger; -import org.opengroup.osdu.partition.model.PartitionInfo; -import org.opengroup.osdu.partition.model.Property; -import org.opengroup.osdu.partition.provider.gcp.config.SystemApiConfiguration; -import org.opengroup.osdu.partition.provider.interfaces.IPartitionService; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.servlet.support.ServletUriComponentsBuilder; - -@ExtendWith(MockitoExtension.class) -public class PartitionControllerV2Test { - - private static final String SYSTEM_TENANT_ID = "systemTenantId"; - private static final String PARTITION_ID_1 = "partition1"; - private static final String PARTITION_ID_2 = "partition2"; - private final AppException FORBIDDEN_EXCEPTION = new AppException(SC_FORBIDDEN, "Not allowed.", - "The system tenant should be managed via system tenant API."); - - @Mock - private SystemApiConfiguration properties; - - @Mock - private PartitionInfo partitionInfo; - - @Mock - private IPartitionService partitionService; - - @Mock - private AuditLogger auditLogger; - - @InjectMocks - private PartitionControllerV2 sut; - - @Test - public void should_throwAppException_when_createWithSystemTenantId() { - when(this.properties.getSystemPartitionId()).thenReturn(SYSTEM_TENANT_ID); - try { - ResponseEntity result = sut.create(SYSTEM_TENANT_ID, partitionInfo); - fail("Should have thrown an exception"); - } catch (AppException e) { - assertEquals(FORBIDDEN_EXCEPTION, e); - } - } - - @Test - public void should_return201AndPartitionId_when_givenValidPartitionId() { - try (MockedStatic<ServletUriComponentsBuilder> mockedSettings = mockStatic(ServletUriComponentsBuilder.class)) { - ServletUriComponentsBuilder builder = spy(ServletUriComponentsBuilder.class); - when(ServletUriComponentsBuilder.fromCurrentRequest()).thenReturn(builder); - - ResponseEntity result = this.sut.create(PARTITION_ID_1, partitionInfo); - assertEquals(HttpStatus.CREATED, result.getStatusCode()); - assertNull(result.getBody()); - assertNotNull(result.getHeaders().get(HttpHeaders.LOCATION)); - } - } - - @Test - public void should_throwAppException_when_patchWithSystemTenantId() { - when(this.properties.getSystemPartitionId()).thenReturn(SYSTEM_TENANT_ID); - try { - sut.patch(SYSTEM_TENANT_ID, partitionInfo); - fail("Should have thrown an exception"); - } catch (AppException e) { - assertEquals(FORBIDDEN_EXCEPTION, e); - } - } - - @Test - public void should_return204_when_givenUpdatingValidPartitionId() { - Map<String, Property> properties = new HashMap<>(); - - when(partitionService.getPartition(PARTITION_ID_1)).thenReturn(partitionInfo); - when(partitionInfo.getProperties()).thenReturn(properties); - - this.sut.patch(PARTITION_ID_1, partitionInfo); - - ResponseEntity<Map<String, Property>> result = this.sut.get(PARTITION_ID_1); - assertEquals(HttpStatus.OK, result.getStatusCode()); - } - - @Test - public void should_return200AndPartitionProperties_when_gettingPartitionIdSuccessfully() { - Map<String, Property> properties = new HashMap<>(); - - when(partitionService.getPartition(anyString())).thenReturn(partitionInfo); - when(partitionInfo.getProperties()).thenReturn(properties); - - ResponseEntity<Map<String, Property>> result = this.sut.get(PARTITION_ID_1); - assertEquals(HttpStatus.OK, result.getStatusCode()); - assertEquals(properties, result.getBody()); - } - - @Test - public void should_throwAppException_when_deleteWithSystemTenantId() { - when(this.properties.getSystemPartitionId()).thenReturn(SYSTEM_TENANT_ID); - try { - ResponseEntity result = sut.delete(SYSTEM_TENANT_ID); - fail("Should have thrown an exception"); - } catch (AppException e) { - assertEquals(FORBIDDEN_EXCEPTION, e); - } - } - - @Test - public void should_returnHttp204_when_deletingPartitionSuccessfully() { - ResponseEntity<?> result = this.sut.delete(PARTITION_ID_1); - assertEquals(HttpStatus.NO_CONTENT.value(), result.getStatusCode().value()); - } - - @Test - public void should_notContainSystemTenantId_when_list() { - when(this.properties.getSystemPartitionId()).thenReturn(SYSTEM_TENANT_ID); - when(properties.isSystemPartitionListableAndResourceReady()).thenReturn(false); - List<String> partitions = Arrays.asList(PARTITION_ID_1, PARTITION_ID_2, SYSTEM_TENANT_ID); - when(partitionService.getAllPartitions()).thenReturn(partitions); - assertFalse(sut.list().contains(SYSTEM_TENANT_ID)); - } - - @Test - public void should_ContainSystemTenantId_when_list_enabled() { - when(properties.isSystemPartitionListableAndResourceReady()).thenReturn(true); - List<String> partitions = Arrays.asList(PARTITION_ID_1, PARTITION_ID_2, SYSTEM_TENANT_ID); - when(partitionService.getAllPartitions()).thenReturn(partitions); - assertTrue(sut.list().contains(SYSTEM_TENANT_ID)); - } - - @Test - public void should_return200AndListAllPartition() { - List<String> partitions = List.of(PARTITION_ID_1, PARTITION_ID_2); - - when(partitionService.getAllPartitions()).thenReturn(partitions); - - List<String> result = this.sut.list(); - assertEquals(partitions.size(), result.size()); - } -} diff --git a/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/controller/SystemControllerTest.java b/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/controller/SystemControllerTest.java deleted file mode 100644 index a6c8fe8d6722b00e026ff7e58b961f79f7c6e1b7..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/controller/SystemControllerTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2020-2024 Google LLC - * Copyright 2020-2024 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.partition.provider.gcp.controller; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Collections; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.Mockito; -import org.mockito.junit.jupiter.MockitoExtension; -import org.opengroup.osdu.partition.logging.AuditLogger; -import org.opengroup.osdu.partition.model.PartitionInfo; -import org.opengroup.osdu.partition.provider.gcp.config.SystemApiConfiguration; -import org.opengroup.osdu.partition.provider.interfaces.IPartitionService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.servlet.support.ServletUriComponentsBuilder; - -@ExtendWith(MockitoExtension.class) -public class SystemControllerTest { - - private static final String SYSTEM_TENANT_ID = "systemTenantId"; - - @Mock - private IPartitionService partitionService; - - @Mock - private SystemApiConfiguration properties; - - @Mock - private AuditLogger auditLogger; - - @Mock - private PartitionInfo partitionInfo; - - @InjectMocks - private SystemController systemController; - - @Test - public void should_createPartition_and_logSuccess_when_createCalled() { - Mockito.when(properties.getSystemPartitionId()).thenReturn(SYSTEM_TENANT_ID); - - MockedStatic<ServletUriComponentsBuilder> mockedUriBuilder = Mockito.mockStatic(ServletUriComponentsBuilder.class); - ServletUriComponentsBuilder uriBuilder = Mockito.spy(ServletUriComponentsBuilder.class); - Mockito.when(ServletUriComponentsBuilder.fromCurrentRequest()).thenReturn(uriBuilder); - - ResponseEntity result = systemController.create(partitionInfo); - - Mockito.verify(partitionService).createPartition(Mockito.anyString(), Mockito.any(PartitionInfo.class)); - Mockito.verify(auditLogger).createPartitionSuccess(Collections.singletonList(SYSTEM_TENANT_ID)); - assertEquals(HttpStatus.CREATED, result.getStatusCode()); - - mockedUriBuilder.close(); - } - - @Test - public void should_updatePartition_and_logSuccess_when_patchCalled() { - Mockito.when(properties.getSystemPartitionId()).thenReturn(SYSTEM_TENANT_ID); - - systemController.patch(partitionInfo); - - Mockito.verify(partitionService).updatePartition(Mockito.anyString(), Mockito.any(PartitionInfo.class)); - Mockito.verify(auditLogger).updatePartitionSecretSuccess(Collections.singletonList(SYSTEM_TENANT_ID)); - } - - @Test - public void should_getPartition_and_logSuccess_when_getCalled() { - Mockito.when(properties.getSystemPartitionId()).thenReturn(SYSTEM_TENANT_ID); - Mockito.when(partitionService.getPartition(Mockito.anyString())).thenReturn(partitionInfo); - - ResponseEntity result = systemController.get(); - - Mockito.verify(partitionService).getPartition(Mockito.anyString()); - Mockito.verify(auditLogger).readPartitionSuccess(Collections.singletonList(SYSTEM_TENANT_ID)); - assertEquals(HttpStatus.OK, result.getStatusCode()); - } -} diff --git a/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImplCacheTest.java b/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImplCacheTest.java deleted file mode 100644 index 3392915521d015da83f5a6f8582759875f65dfa5..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImplCacheTest.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - Copyright 2002-2023 Google LLC - Copyright 2002-2023 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 - - 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.partition.provider.gcp.service; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.opengroup.osdu.core.common.cache.ICache; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.partition.logging.AuditLogger; -import org.opengroup.osdu.partition.model.PartitionInfo; -import org.opengroup.osdu.partition.model.Property; -import org.opengroup.osdu.partition.provider.gcp.config.PropertiesConfiguration; -import org.opengroup.osdu.partition.provider.gcp.model.PartitionPropertyEntity; -import org.opengroup.osdu.partition.provider.gcp.osm.repository.OsmPartitionPropertyRepository; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -public class PartitionServiceImplCacheTest { - - @Mock - private ICache<String, PartitionInfo> partitionServiceCache; - - @Mock - private ICache<String, List<String>> partitionListCache; - - @Mock - private OsmPartitionPropertyRepository partitionPropertyEntityRepository; - - @Mock - private AuditLogger auditLogger; - - private PartitionServiceImpl partitionServiceImpl; - - @Mock - private PropertiesConfiguration propertiesConfiguration; - - @BeforeEach - public void setup() { - partitionServiceImpl = new PartitionServiceImpl( - partitionPropertyEntityRepository, - auditLogger, - partitionServiceCache, - partitionListCache, - propertiesConfiguration - - ); - } - - private List<PartitionPropertyEntity> partitionInfoToEntity(String partitionId, PartitionInfo partitionInfo) { - return partitionInfo.getProperties().entrySet().stream() - .map(entry -> new PartitionPropertyEntity(partitionId, entry.getKey(), entry.getValue())) - .collect(Collectors.toList()); - } - - @Test - public void createPartitionSucceed() { - String partId = "key"; - - PartitionInfo newPi = PartitionInfo.builder().build(); - PartitionInfo retPi = PartitionInfo.builder().build(); - String propKey = "123987123498"; - retPi.getProperties().put(propKey, new Property()); - - doReturn(Optional.empty(), Optional.of(partitionInfoToEntity(partId, retPi))) - .when(partitionPropertyEntityRepository).findByPartitionId(partId); - partitionServiceImpl.createPartition(partId, newPi); - - verify(partitionServiceCache, times(1)) - .put(any(), argThat(argument -> argument.getProperties().containsKey(propKey))); - verify(partitionListCache).clearAll(); - } - - @Test - public void createPartitionFailed() { - String partId = "key"; - PartitionInfo newPi = PartitionInfo.builder().build(); - - when(partitionServiceCache.get(partId)).thenReturn(null); - doReturn(Optional.empty()) - .when(partitionPropertyEntityRepository).findByPartitionId(partId); - - assertThrows(AppException.class, () -> partitionServiceImpl.createPartition(partId, newPi)); - - verify(partitionServiceCache, times(0)).put(any(), any()); - verify(partitionListCache, times(0)).clearAll(); - verify(partitionServiceCache, times(2)).get(any()); - } - - @Test - public void updatePartitionSucceed() { - String partId = "key"; - - PartitionInfo newPi = PartitionInfo.builder().build(); - PartitionInfo retPi = PartitionInfo.builder().build(); - String propKey = "123987123498"; - retPi.getProperties().put(propKey, new Property()); - - doReturn(Optional.of(partitionInfoToEntity(partId, retPi))) - .when(partitionPropertyEntityRepository).findByPartitionId(partId); - - partitionServiceImpl.updatePartition(partId, newPi); - - verify(partitionServiceCache, times(1)) - .put(any(), argThat(argument -> argument.getProperties().containsKey(propKey))); - } - - @Test - public void updatePartitionFailed() { - String partId = "key"; - PartitionInfo newPi = PartitionInfo.builder().build(); - - doReturn(Optional.empty()) - .when(partitionPropertyEntityRepository).findByPartitionId(partId); - - assertThrows(AppException.class, () -> partitionServiceImpl.updatePartition(partId, newPi)); - - verify(partitionServiceCache, times(0)).put(any(), any()); - verify(partitionServiceCache, times(0)).get(any()); - } - - - @Test - public void getPartition() { - String partId = "key"; - - PartitionInfo retPi = PartitionInfo.builder().build(); - String propKey = "123987123498"; - retPi.getProperties().put(propKey, new Property()); - - doReturn(Optional.of(partitionInfoToEntity(partId, retPi))) - .when(partitionPropertyEntityRepository).findByPartitionId(partId); - - partitionServiceImpl.getPartition(partId); - - verify(partitionServiceCache, times(1)).get(partId); - verify(partitionPropertyEntityRepository, times(1)).findByPartitionId(partId); - verify(partitionServiceCache, times(1)).put(partId, retPi); - } - - @Test - public void deletePartition() { - String partId = "key"; - PartitionInfo retPi = PartitionInfo.builder().build(); - - doReturn(Optional.of(partitionInfoToEntity(partId, retPi))) - .when(partitionPropertyEntityRepository).findByPartitionId(partId); - when(partitionServiceCache.get(partId)).thenReturn(retPi); - - partitionServiceImpl.deletePartition(partId); - - verify(partitionPropertyEntityRepository, times(1)).deleteByPartitionId(partId); - verify(partitionServiceCache, times(1)).delete(partId); - verify(partitionServiceCache, times(1)).get(partId); - verify(partitionListCache, times(1)).clearAll(); - } - - @Test - public void getAllPartitions() { - List<String> partitions = new ArrayList<>(); - partitions.add("1"); - - doReturn(partitions) - .when(partitionPropertyEntityRepository).getAllPartitions(); - - partitionServiceImpl.getAllPartitions(); - - verify(partitionListCache, times(1)).get(PartitionServiceImpl.PARTITION_LIST_KEY); - verify(partitionPropertyEntityRepository, times(1)).getAllPartitions(); - verify(partitionListCache, times(1)).put(PartitionServiceImpl.PARTITION_LIST_KEY, partitions); - } -} \ No newline at end of file diff --git a/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImplTest.java b/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImplTest.java deleted file mode 100644 index e6b89ea2ec4c23c12c8184705dd2dedc6cf79da0..0000000000000000000000000000000000000000 --- a/provider/partition-gc/src/test/java/org/opengroup/osdu/partition/provider/gcp/service/PartitionServiceImplTest.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - Copyright 2002-2023 Google LLC - Copyright 2002-2023 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 - - 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.partition.provider.gcp.service; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.opengroup.osdu.core.common.cache.ICache; -import org.opengroup.osdu.core.common.model.http.AppException; -import org.opengroup.osdu.partition.logging.AuditLogger; -import org.opengroup.osdu.partition.model.PartitionInfo; -import org.opengroup.osdu.partition.model.Property; -import org.opengroup.osdu.partition.provider.gcp.config.PropertiesConfiguration; -import org.opengroup.osdu.partition.provider.gcp.model.PartitionPropertyEntity; -import org.opengroup.osdu.partition.provider.gcp.osm.repository.OsmPartitionPropertyRepository; - -@ExtendWith(MockitoExtension.class) -class PartitionServiceImplTest { - - private static final String PARTITION_ID = "newPartition"; - private static final boolean SENSITIVE = false; - private static final String NAME = "new-key"; - private static final String VALUE = "new-value"; - static final String SYSTEM_PARTITION_ID = "systemPartitionId"; - - @Mock - private ICache<String, PartitionInfo> partitionServiceCache; - - @Mock - private ICache<String, List<String>> partitionListCache; - - @Mock - private OsmPartitionPropertyRepository partitionPropertyEntityRepository; - - @Mock - private AuditLogger auditLogger; - - private PartitionServiceImpl partitionServiceImpl; - - private PartitionInfo expectedPartitionInfo; - private PartitionPropertyEntity partitionPropertyEntity; - private Optional<List<PartitionPropertyEntity>> partitionPropertyEntityList; - private Optional<List<PartitionPropertyEntity>> emptyList; - - @Mock - private PropertiesConfiguration propertiesConfiguration; - - @BeforeEach - void setup() { - partitionServiceImpl = new PartitionServiceImpl( - partitionPropertyEntityRepository, - auditLogger, - partitionServiceCache, - partitionListCache, - propertiesConfiguration - - ); - - expectedPartitionInfo = new PartitionInfo(); - - Property property = new Property(); - property.setSensitive(SENSITIVE); - property.setValue(VALUE); - - Map<String, Property> properties = new HashMap<>(); - properties.put(NAME, property); - - expectedPartitionInfo.setProperties(properties); - - partitionPropertyEntity = new PartitionPropertyEntity(PARTITION_ID, NAME, property); - - List<PartitionPropertyEntity> entities = new ArrayList<>(); - entities.add(partitionPropertyEntity); - partitionPropertyEntityList = Optional.of(entities); - - emptyList = Optional.empty(); - } - - @Test - void should_createPartition_when_partitionDoesNotExist() { - when(partitionPropertyEntityRepository.findByPartitionId(PARTITION_ID)) - .thenReturn(emptyList, partitionPropertyEntityList); - - PartitionInfo actualPartitionInfo = partitionServiceImpl - .createPartition(PARTITION_ID, expectedPartitionInfo); - - assertEquals(expectedPartitionInfo, actualPartitionInfo); - } - - @Test - void should_throwAnException_when_createPartitionWhichAlreadyExists() { - when(partitionPropertyEntityRepository.findByPartitionId(PARTITION_ID)).thenReturn(emptyList); - PartitionInfo partitionInfo = new PartitionInfo(); - assertThrows(AppException.class, () -> { - partitionServiceImpl.createPartition(PARTITION_ID, partitionInfo); - }); - } - - @Test - void should_updatePartition_when_partitionExists() { - when(partitionPropertyEntityRepository.findByPartitionId(PARTITION_ID)) - .thenReturn(partitionPropertyEntityList); - when(partitionPropertyEntityRepository.findByPartitionIdAndName(PARTITION_ID, NAME)) - .thenReturn(null); - - PartitionInfo actualPartitionInfo = partitionServiceImpl - .updatePartition(PARTITION_ID, expectedPartitionInfo); - - assertEquals(expectedPartitionInfo, actualPartitionInfo); - } - - @Test - void should_throwAnException_when_updatePartitionWhichDoesNotExist() { - when(partitionPropertyEntityRepository.findByPartitionId(PARTITION_ID)).thenReturn(emptyList); - PartitionInfo partitionInfo = new PartitionInfo(); - assertThrows(AppException.class, () -> { - partitionServiceImpl.createPartition(PARTITION_ID, partitionInfo); - }); - } - - @Test - void should_getPartition_when_partitionExists() { - when(partitionPropertyEntityRepository.findByPartitionId(PARTITION_ID)) - .thenReturn(partitionPropertyEntityList); - - PartitionInfo actualPartitionInfo = partitionServiceImpl.getPartition(PARTITION_ID); - - assertEquals(expectedPartitionInfo, actualPartitionInfo); - } - - @Test - void should_throwAnException_when_getPartitionWhichDoesNotExist() { - when(partitionPropertyEntityRepository.findByPartitionId(PARTITION_ID)).thenReturn(emptyList); - assertThrows(AppException.class, () -> { - partitionServiceImpl.getPartition(PARTITION_ID); - }); - } - - @Test - void should_deletePartition_when_partitionExists() { - when(partitionPropertyEntityRepository.findByPartitionId(PARTITION_ID)) - .thenReturn(partitionPropertyEntityList); - doNothing().when(partitionPropertyEntityRepository).deleteByPartitionId(PARTITION_ID); - - boolean expected = true; - boolean actual = partitionServiceImpl.deletePartition(PARTITION_ID); - - assertEquals(expected, actual); - } - - @Test - void should_throwAnException_when_deletePartitionWhichDoesNotExist() { - when(partitionPropertyEntityRepository.findByPartitionId(PARTITION_ID)).thenReturn(emptyList); - assertThrows(AppException.class, () -> { - partitionServiceImpl.deletePartition(PARTITION_ID); - }); - } - - @Test - void should_getAllPartitions() { - List<String> expectedPartitions = new ArrayList<>(); - expectedPartitions.add(PARTITION_ID); - - when(partitionPropertyEntityRepository.getAllPartitions()).thenReturn(expectedPartitions); - - List<String> actualPartitions = partitionServiceImpl.getAllPartitions(); - - assertEquals(expectedPartitions, actualPartitions); - } -}