Commit e5b80f8e authored by Abhishek Kumar (SLB)'s avatar Abhishek Kumar (SLB)
Browse files

Decoupling shared partition name. Each vendor can use their own shared

partition name.
parent ee957a1b
Pipeline #13108 failed with stage
in 14 seconds
......@@ -13,8 +13,21 @@
// limitations under the License.
package org.opengroup.osdu.schema.provider.aws.impl.schemainfostore;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.joda.time.DateTime;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelper;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -35,13 +48,11 @@ import org.opengroup.osdu.schema.provider.interfaces.schemainfostore.ISchemaInfo
import org.opengroup.osdu.schema.provider.interfaces.schemastore.ISchemaStore;
import org.opengroup.osdu.schema.util.VersionHierarchyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.text.MessageFormat;
import java.util.*;
import java.util.stream.Collectors;
import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedQueryList;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
@Repository
public class AwsSchemaInfoStore implements ISchemaInfoStore {
......@@ -57,6 +68,10 @@ public class AwsSchemaInfoStore implements ISchemaInfoStore {
@Inject
private AwsServiceConfig serviceConfig;
@Value("${shared.tenant.name:common}")
private String sharedTenant;
@Inject
private ISchemaStore schemaStore;
......@@ -242,11 +257,11 @@ public class AwsSchemaInfoStore implements ISchemaInfoStore {
@Override
public boolean isUnique(String schemaId, String tenantId) throws ApplicationException {
Set<String> tenantList = new HashSet<>();
tenantList.add(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT);
tenantList.add(sharedTenant);
tenantList.add(tenantId);
// code to call check uniqueness
if (tenantId.equalsIgnoreCase(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT)) {
if (tenantId.equalsIgnoreCase(sharedTenant)) {
List<String> privateTenantList = tenantFactory.listTenantInfo().stream().map(TenantInfo::getDataPartitionId)
.collect(Collectors.toList());
tenantList.addAll(privateTenantList);
......
......@@ -36,3 +36,6 @@ aws.dynamodb.endpoint=dynamodb.${AWS_REGION}.amazonaws.com
# if this is turned on then the service tries to connect to elastic search
management.health.elasticsearch.enabled=false
# Use this property to reference your shared partition
shared.tenant.name=common
......@@ -15,12 +15,17 @@
package org.opengroup.osdu.schema.azure.impl.schemainfostore;
import java.text.MessageFormat;
import java.util.*;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import com.azure.cosmos.*;
import com.google.gson.Gson;
import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
......@@ -42,8 +47,15 @@ import org.opengroup.osdu.schema.model.SchemaRequest;
import org.opengroup.osdu.schema.provider.interfaces.schemainfostore.ISchemaInfoStore;
import org.opengroup.osdu.schema.util.VersionHierarchyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import com.azure.cosmos.FeedOptions;
import com.azure.cosmos.SqlParameter;
import com.azure.cosmos.SqlParameterList;
import com.azure.cosmos.SqlQuerySpec;
import com.google.gson.Gson;
import lombok.extern.java.Log;
/**
......@@ -70,6 +82,10 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
@Autowired
JaxRsDpsLog log;
@Value("${shared.tenant.name:common}")
private String sharedTenant;
/**
* Method to get schemaInfo from azure store
......@@ -327,10 +343,10 @@ public class AzureSchemaInfoStore implements ISchemaInfoStore {
@Override
public boolean isUnique(String schemaId, String tenantId) throws ApplicationException {
Set<String> tenantList = new HashSet<>();
tenantList.add(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT);
tenantList.add(sharedTenant);
tenantList.add(tenantId);
if (tenantId.equalsIgnoreCase(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT)) {
if (tenantId.equalsIgnoreCase(sharedTenant)) {
List<String> privateTenantList = tenantFactory.listTenantInfo().stream().map(TenantInfo::getName)
.collect(Collectors.toList());
tenantList.addAll(privateTenantList);
......
......@@ -47,3 +47,6 @@ server.port=${server.port}
#logging configuration
logging.transaction.enabled=true
logging.slf4jlogger.enabled=true
# Use this property to reference your shared partition
shared.tenant.name=common
......@@ -65,8 +65,8 @@ public class GoogleSchemaInfoStore implements ISchemaInfoStore {
@Autowired
JaxRsDpsLog log;
@Value("${account.id.common.project}")
private String commonAccountId;
@Value("${shared.tenant.name:common}")
private String sharedTenant;
/**
* Method to get schemaInfo from google store
......@@ -258,7 +258,7 @@ public class GoogleSchemaInfoStore implements ISchemaInfoStore {
@Override
public List<SchemaInfo> getSchemaInfoList(QueryParams queryParams, String tenantId) throws ApplicationException {
List<SchemaInfo> schemaList = new LinkedList<>();
if (SchemaConstants.ACCOUNT_ID_COMMON_PROJECT.equals(tenantId)) {
if (sharedTenant.equals(tenantId)) {
return schemaList;
}
Datastore datastore = dataStoreFactory.getDatastore(tenantId, SchemaConstants.NAMESPACE);
......@@ -311,11 +311,11 @@ public class GoogleSchemaInfoStore implements ISchemaInfoStore {
public boolean isUnique(String schemaId, String tenantId) throws ApplicationException {
Set<String> tenantList = new HashSet<>();
tenantList.add(commonAccountId);
tenantList.add(sharedTenant);
tenantList.add(tenantId);
// code to call check uniqueness
if (tenantId.equalsIgnoreCase(commonAccountId)) {
if (tenantId.equalsIgnoreCase(sharedTenant)) {
List<String> privateTenantList = tenantFactory.listTenantInfo().stream().map(TenantInfo::getDataPartitionId)
.collect(Collectors.toList());
tenantList.addAll(privateTenantList);
......@@ -335,11 +335,11 @@ public class GoogleSchemaInfoStore implements ISchemaInfoStore {
return true;
}
public String getCommonAccountId() {
return commonAccountId;
public String getsharedTenant() {
return sharedTenant;
}
public void setCommonAccountId(String commonAccountId) {
this.commonAccountId = commonAccountId;
public void setsharedTenant(String sharedTenant) {
this.sharedTenant = sharedTenant;
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.exceptions.NotFoundException;
import org.opengroup.osdu.schema.provider.interfaces.schemastore.ISchemaStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import com.google.cloud.storage.Blob;
......@@ -33,6 +34,10 @@ public class GoogleSchemaStore implements ISchemaStore {
@Autowired
TenantFactory tenantFactory;
@Value("${shared.tenant.name:common}")
private String sharedTenant;
@Autowired
JaxRsDpsLog log;
......@@ -49,7 +54,7 @@ public class GoogleSchemaStore implements ISchemaStore {
*/
@Override
public String getSchema(String dataPartitionId, String filePath) throws ApplicationException, NotFoundException {
if (SchemaConstants.ACCOUNT_ID_COMMON_PROJECT.equals(dataPartitionId)) {
if (sharedTenant.equals(dataPartitionId)) {
throw new NotFoundException(SchemaConstants.SCHEMA_NOT_PRESENT);
}
filePath = filePath + SchemaConstants.JSON_EXTENSION;
......
......@@ -7,4 +7,6 @@ management.health.elasticsearch.enabled=false
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=health
LOG_PREFIX=schema
account.id.common.project=common
# Use this property to reference your shared partition
shared.tenant.name=common
......@@ -172,7 +172,7 @@ public class GoogleSchemaInfoStoreTest {
KeyFactory storageKeyFactory = mock(KeyFactory.class);
String schemaId = "schemaId";
String tenantId = "tenant";
schemaInfoStore.setCommonAccountId(tenantId);
schemaInfoStore.setsharedTenant(tenantId);
Mockito.when(tenantFactory.getTenantInfo("tenant")).thenReturn(tenantInfo);
Mockito.when(tenantFactory.getTenantInfo("common")).thenReturn(tenantInfoCommon);
Mockito.when(tenantInfo.getName()).thenReturn("tenant");
......
......@@ -35,6 +35,7 @@ import org.opengroup.osdu.schema.provider.interfaces.schemainfostore.ISchemaInfo
import org.opengroup.osdu.schema.provider.interfaces.schemastore.ISchemaStore;
import org.opengroup.osdu.schema.util.VersionHierarchyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.web.context.annotation.RequestScope;
......@@ -43,7 +44,6 @@ import com.cloudant.client.api.query.Expression;
import com.cloudant.client.api.query.QueryBuilder;
import com.cloudant.client.api.query.QueryResult;
import com.cloudant.client.api.query.Selector;
import com.google.gson.Gson;
/**
* Repository class to to register Schema in IBM Document Store.
......@@ -67,6 +67,10 @@ public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoS
@Autowired
private ISchemaStore schemaStore;
@Value("${shared.tenant.name:common}")
private String sharedTenant;
@PostConstruct
......@@ -78,11 +82,11 @@ public class IbmSchemaInfoStore extends IbmDocumentStore implements ISchemaInfoS
@Override
public boolean isUnique(String schemaId, String tenantId) throws ApplicationException {
Set<String> tenantList = new HashSet<>();
tenantList.add(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT);
tenantList.add(sharedTenant);
tenantList.add(tenantId);
// code to call check uniqueness
if (tenantId.equalsIgnoreCase(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT)) {
if (tenantId.equalsIgnoreCase(sharedTenant)) {
List<String> privateTenantList = tenantFactory.listTenantInfo().stream().map(TenantInfo::getDataPartitionId)
.collect(Collectors.toList());
tenantList.addAll(privateTenantList);
......
......@@ -20,3 +20,6 @@ ibm.tenant.db.password=TODO
ibm.tenant.db.name=TODO
spring.main.allow-bean-definition-overriding=true
# Use this property to reference your shared partition
shared.tenant.name=common
......@@ -35,7 +35,6 @@ public class SchemaConstants {
// general
public static final String ALREADY_EXISTS = "ALREADY_EXISTS";
public static final String ACCOUNT_ID = "account-Id";
public static final String ACCOUNT_ID_COMMON_PROJECT = "common";
public static final String ON_BEHALF_OF = "on-Behalf-Of";
......
......@@ -9,6 +9,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -35,8 +36,10 @@ import org.opengroup.osdu.schema.service.ISourceService;
import org.opengroup.osdu.schema.util.SchemaResolver;
import org.opengroup.osdu.schema.util.SchemaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
......@@ -76,6 +79,10 @@ public class SchemaService implements ISchemaService {
@Autowired
DpsHeaders headers;
@Value("${shared.tenant.name:common}")
private String sharedTenant;
/**
* Method to get schema
*
......@@ -92,7 +99,7 @@ public class SchemaService implements ISchemaService {
try {
schema = schemaStore.getSchema(dataPartitionId, schemaId);
} catch (NotFoundException e) {
schema = schemaStore.getSchema(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT, schemaId);
schema = schemaStore.getSchema(sharedTenant, schemaId);
}
return schema;
......@@ -230,16 +237,16 @@ public class SchemaService implements ISchemaService {
if (queryParams.getScope() != null) {
if (queryParams.getScope().equalsIgnoreCase(SchemaScope.SHARED.toString())) {
getSchemaInfos(queryParams, schemaList, SchemaConstants.ACCOUNT_ID_COMMON_PROJECT);
getSchemaInfos(queryParams, schemaList, sharedTenant);
}
else if (queryParams.getScope().equalsIgnoreCase(SchemaScope.INTERNAL.toString())) {
getSchemaInfos(queryParams, schemaList, tenantId);
}
} else {
getSchemaInfos(queryParams, schemaList, SchemaConstants.ACCOUNT_ID_COMMON_PROJECT);
getSchemaInfos(queryParams, schemaList, sharedTenant);
if (!SchemaConstants.ACCOUNT_ID_COMMON_PROJECT.equalsIgnoreCase(tenantId)) {
if (!sharedTenant.equalsIgnoreCase(tenantId)) {
getSchemaInfos(queryParams, schemaList, tenantId);
}
}
......@@ -306,7 +313,7 @@ public class SchemaService implements ISchemaService {
* @param dataPartitionId
*/
private void setScope(SchemaRequest schemaRequest, String dataPartitionId) {
if (dataPartitionId.equalsIgnoreCase(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT)) {
if (dataPartitionId.equalsIgnoreCase(sharedTenant)) {
schemaRequest.getSchemaInfo().setScope(SchemaScope.SHARED);
} else {
schemaRequest.getSchemaInfo().setScope(SchemaScope.INTERNAL);
......
......@@ -39,6 +39,7 @@ import org.opengroup.osdu.schema.service.IEntityTypeService;
import org.opengroup.osdu.schema.service.ISourceService;
import org.opengroup.osdu.schema.util.SchemaResolver;
import org.opengroup.osdu.schema.util.SchemaUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
......@@ -78,6 +79,10 @@ public class SchemaServiceTest {
@Mock
JaxRsDpsLog log;
@Value("${shared.tenant.name:common}")
private String sharedTenant;
private Date currDate = new Date();
@Rule
......@@ -108,7 +113,7 @@ public class SchemaServiceTest {
Mockito.when(headers.getPartitionId()).thenReturn(dataPartitionId);
String schemaId = "os..wks..well.1.1";
Mockito.when(schemaStore.getSchema(dataPartitionId, schemaId)).thenThrow(NotFoundException.class);
Mockito.when(schemaStore.getSchema(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT, schemaId)).thenReturn("{}");
Mockito.when(schemaStore.getSchema(sharedTenant, schemaId)).thenReturn("{}");
assertNotNull(schemaService.getSchema(schemaId));
}
......@@ -120,7 +125,7 @@ public class SchemaServiceTest {
Mockito.when(headers.getPartitionId()).thenReturn(dataPartitionId);
String schemaId = "os..wks..well.1.1";
Mockito.when(schemaStore.getSchema(dataPartitionId, schemaId)).thenThrow(NotFoundException.class);
Mockito.when(schemaStore.getSchema(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT, schemaId))
Mockito.when(schemaStore.getSchema(sharedTenant, schemaId))
.thenThrow(new NotFoundException(SchemaConstants.SCHEMA_NOT_PRESENT));
schemaService.getSchema(schemaId);
}
......@@ -137,7 +142,7 @@ public class SchemaServiceTest {
when(schemaInfoStore.isUnique(schemaId, "common")).thenReturn(true);
when(schemaInfoStore.isUnique(schemaId, "tenant")).thenReturn(true);
when(headers.getPartitionId()).thenReturn(dataPartitionId);
Mockito.when(schemaStore.getSchema(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT, schemaId))
Mockito.when(schemaStore.getSchema(sharedTenant, schemaId))
.thenThrow(NotFoundException.class);
Mockito.when(schemaStore.getSchema(dataPartitionId, schemaId)).thenThrow(NotFoundException.class);
Mockito.when(authorityService.checkAndRegisterAuthorityIfNotPresent(
......@@ -225,7 +230,7 @@ public class SchemaServiceTest {
Mockito.when(headers.getPartitionId()).thenReturn(dataPartitionId);
when(schemaInfoStore.isUnique(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
Mockito.when(schemaStore.getSchema(SchemaConstants.ACCOUNT_ID_COMMON_PROJECT, schemaId))
Mockito.when(schemaStore.getSchema(sharedTenant, schemaId))
.thenThrow(NotFoundException.class);
Mockito.when(authorityService.checkAndRegisterAuthorityIfNotPresent(
schReqInt.getSchemaInfo().getSchemaIdentity().getAuthority()))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment