diff --git a/provider/partition-gc/docs/baremetal/README.md b/provider/partition-gc/docs/baremetal/README.md index 5d9d861315961609fefc2bbb952c075723e5aba8..3599352e9fff0d79bf2e4915349beb4360592de6 100644 --- a/provider/partition-gc/docs/baremetal/README.md +++ b/provider/partition-gc/docs/baremetal/README.md @@ -6,22 +6,24 @@ 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 | - | +| 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 | - | +| 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 | - | 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. @@ -48,17 +50,17 @@ CREATE INDEX PartitionProperty_dataGin ON partition."PartitionProperty" USING GI 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 | -- | +| 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: diff --git a/provider/partition-gc/docs/gc/README.md b/provider/partition-gc/docs/gc/README.md index 1ef39165b4e93673f0d49a00921103ca6f210711..49fee43c9030af2c8cd778614ef4890e5f7f3e0a 100644 --- a/provider/partition-gc/docs/gc/README.md +++ b/provider/partition-gc/docs/gc/README.md @@ -6,20 +6,21 @@ Define the following environment variables. Must have: -| name | value | description | sensitive? | source | -| --- | --- | --- | --- | --- | -| `SPRING_PROFILES_ACTIVE` | ex `gcp` | Spring profile that activate default configuration for Google Cloud environment | false | - | -| `GOOGLE_CLOUD_PROJECT` | ex `google` | Google Cloud Project Id| false | <https://console.cloud.google.com/> | +| name | value | description | sensitive? | source | +|--------------------------|-------------|---------------------------------------------------------------------------------|------------|-------------------------------------| +| `SPRING_PROFILES_ACTIVE` | ex `gcp` | Spring profile that activate default configuration for Google Cloud environment | false | - | +| `GOOGLE_CLOUD_PROJECT` | ex `google` | Google Cloud Project Id | false | <https://console.cloud.google.com/> | 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 | - | +| 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 | - | +| `SYSTEM_PARTITION_ID` | ex `syspartition` | Name of system partition. | yes | - | 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. @@ -31,14 +32,14 @@ Usage of spring profiles is preferred. 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 | | -| `INTEGRATION_TESTER` | `********` | Service account for API calls. Note: this user must be `PARTITION_ADMIN_ACCOUNT` | yes | <https://console.cloud.google.com/iam-admin/serviceaccounts> | -| `NO_DATA_ACCESS_TESTER` | `********` | Service account base64 encoded string without data access | yes | <https://console.cloud.google.com/iam-admin/serviceaccounts> | +| 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 | | +| `INTEGRATION_TESTER` | `********` | Service account for API calls. Note: this user must be `PARTITION_ADMIN_ACCOUNT` | yes | <https://console.cloud.google.com/iam-admin/serviceaccounts> | +| `NO_DATA_ACCESS_TESTER` | `********` | Service account base64 encoded string without data access | yes | <https://console.cloud.google.com/iam-admin/serviceaccounts> | Execute following command to build code and run all the integration tests: 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 index f8f8a445277acb1c30c6802548a929bbc12c1bf4..3afdd7ec8a2afdc7990d399d91ef62e4c20ee568 100644 --- 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 @@ -1,6 +1,6 @@ /* - Copyright 2002-2022 Google LLC - Copyright 2002-2022 EPAM Systems, Inc + 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. @@ -35,4 +35,6 @@ public class PropertiesConfiguration { private String partitionPropertyKind; private String partitionNamespace; + + private String systemPartitionId; } 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 index 3de5311794084efe2bf47d7a66dd4845ff30a714..d70ec577664e02ec59be0cd31ef2d795922a6669 100644 --- 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 @@ -1,6 +1,6 @@ /* - * Copyright 2020-2021 Google LLC - * Copyright 2020-2021 EPAM Systems, Inc + * 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. @@ -17,13 +17,6 @@ package org.opengroup.osdu.partition.provider.gcp.service; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.apache.http.HttpStatus; import org.opengroup.osdu.core.common.cache.ICache; @@ -31,12 +24,15 @@ 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 { @@ -52,6 +48,8 @@ public class PartitionServiceImpl implements IPartitionService { private final ICache<String, List<String>> partitionListCache; + private final PropertiesConfiguration propertiesConfiguration; + @Override public PartitionInfo createPartition(String partitionId, PartitionInfo partitionInfo) { if (partitionServiceCache.get(partitionId) != null) @@ -168,7 +166,10 @@ public class PartitionServiceImpl implements IPartitionService { List<String> partitions = partitionListCache.get(PARTITION_LIST_KEY); if (Objects.isNull(partitions)) { - List<String> allPartitions = this.partitionPropertyEntityRepository.getAllPartitions(); + List<String> allPartitions = this.partitionPropertyEntityRepository.getAllPartitions() + .stream() + .filter(partitionId -> !partitionId.equals(propertiesConfiguration.getSystemPartitionId())) + .toList(); partitions = (allPartitions.isEmpty() ? Collections.emptyList() : allPartitions); if (!CollectionUtils.isEmpty(partitions)) { 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 index 050af8c25924369c17433de19dad9c9a72389678..3392915521d015da83f5a6f8582759875f65dfa5 100644 --- 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 @@ -1,6 +1,6 @@ /* - Copyright 2002-2021 Google LLC - Copyright 2002-2021 EPAM Systems, Inc + 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. @@ -17,18 +17,6 @@ package org.opengroup.osdu.partition.provider.gcp.service; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.argThat; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -39,9 +27,19 @@ 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 { @@ -59,13 +57,18 @@ public class PartitionServiceImplCacheTest { private PartitionServiceImpl partitionServiceImpl; + @Mock + private PropertiesConfiguration propertiesConfiguration; + @BeforeEach public void setup() { partitionServiceImpl = new PartitionServiceImpl( partitionPropertyEntityRepository, auditLogger, partitionServiceCache, - partitionListCache + partitionListCache, + propertiesConfiguration + ); } 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 index 02481f56931fb547dfdb4c73dfb2b9db8acf1f72..1a645252f01935b402a725572fda85294e72e762 100644 --- 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 @@ -1,6 +1,6 @@ /* - Copyright 2002-2021 Google LLC - Copyright 2002-2021 EPAM Systems, Inc + 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. @@ -17,16 +17,6 @@ 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; @@ -37,9 +27,18 @@ 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.*; + +import static org.junit.Assert.assertTrue; +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; + @ExtendWith(MockitoExtension.class) public class PartitionServiceImplTest { @@ -47,6 +46,7 @@ public class PartitionServiceImplTest { private static final boolean SENSITIVE = false; private static final String NAME = "new-key"; private static final String VALUE = "new-value"; + public static final String SYSTEM_PARTITION_ID = "systemPartitionId"; @Mock private ICache<String, PartitionInfo> partitionServiceCache; @@ -67,13 +67,18 @@ public class PartitionServiceImplTest { private Optional<List<PartitionPropertyEntity>> partitionPropertyEntityList; private Optional<List<PartitionPropertyEntity>> emptyList; + @Mock + private PropertiesConfiguration propertiesConfiguration; + @BeforeEach public void setup() { partitionServiceImpl = new PartitionServiceImpl( partitionPropertyEntityRepository, auditLogger, partitionServiceCache, - partitionListCache + partitionListCache, + propertiesConfiguration + ); expectedPartitionInfo = new PartitionInfo(); @@ -190,4 +195,32 @@ public class PartitionServiceImplTest { assertEquals(expectedPartitions, actualPartitions); } + + @Test + public void should_getAllPartitionsExceptEmptySystemPartition() { + var expectedPartitions = new ArrayList<String>(); + expectedPartitions.add(PARTITION_ID); + expectedPartitions.add(SYSTEM_PARTITION_ID); + + when(propertiesConfiguration.getSystemPartitionId()).thenReturn(""); + when(partitionPropertyEntityRepository.getAllPartitions()).thenReturn(expectedPartitions); + + var actualPartitions = partitionServiceImpl.getAllPartitions(); + + assertEquals(expectedPartitions, actualPartitions); + } + + @Test + public void should_getAllPartitionsExceptSystemPartition() { + var expectedPartitions = new ArrayList<String>(); + expectedPartitions.add(PARTITION_ID); + expectedPartitions.add(SYSTEM_PARTITION_ID); + + when(propertiesConfiguration.getSystemPartitionId()).thenReturn(SYSTEM_PARTITION_ID); + when(partitionPropertyEntityRepository.getAllPartitions()).thenReturn(expectedPartitions); + + var actualPartitions= partitionServiceImpl.getAllPartitions(); + + assertTrue(!actualPartitions.contains(SYSTEM_PARTITION_ID)); + } } \ No newline at end of file